diff --git a/app/src/main/java/com/cniao5/cainiaowo/CnApplication.kt b/app/src/main/java/com/cniao5/cainiaowo/CnApplication.kt index ac28cbd..1139525 100644 --- a/app/src/main/java/com/cniao5/cainiaowo/CnApplication.kt +++ b/app/src/main/java/com/cniao5/cainiaowo/CnApplication.kt @@ -4,6 +4,7 @@ import com.alibaba.android.arouter.launcher.ARouter import com.cniao5.common.BaseApplication import com.cniao5.common.ktx.application import com.cniao5.course.moduleCourse +import com.cniao5.home.moduleHome import com.cniao5.mine.moduleMine import com.cniao5.study.moduleStudy import com.test.service.assistant.AssistantApp @@ -15,7 +16,7 @@ import org.koin.core.module.Module class CnApplication : BaseApplication() { private val modules = arrayListOf( - moduleService,/*moduleHome,*/ moduleLogin, moduleMine, moduleStudy, moduleCourse + moduleService, moduleHome, moduleLogin, moduleMine, moduleStudy, moduleCourse ) override fun initConfig() { diff --git a/app/src/main/java/com/cniao5/cainiaowo/MainActivity.kt b/app/src/main/java/com/cniao5/cainiaowo/MainActivity.kt index cc2426e..05d0dd7 100644 --- a/app/src/main/java/com/cniao5/cainiaowo/MainActivity.kt +++ b/app/src/main/java/com/cniao5/cainiaowo/MainActivity.kt @@ -7,7 +7,7 @@ import com.cniao5.cainiaowo.databinding.ActivityMainBinding import com.cniao5.common.base.BaseActivity import com.cniao5.common.widget.BnvVp2Mediator import com.cniao5.course.ui.CourseFragment -import com.cniao5.home.HomeFragment +import com.cniao5.home.ui.HomeFragment import com.cniao5.mine.MineContainerFragment import com.cniao5.study.ui.StudyFragment diff --git a/course/src/main/java/com/cniao5/course/ui/CourseViewModel.kt b/course/src/main/java/com/cniao5/course/CourseViewModel.kt similarity index 93% rename from course/src/main/java/com/cniao5/course/ui/CourseViewModel.kt rename to course/src/main/java/com/cniao5/course/CourseViewModel.kt index fde3066..3213433 100644 --- a/course/src/main/java/com/cniao5/course/ui/CourseViewModel.kt +++ b/course/src/main/java/com/cniao5/course/CourseViewModel.kt @@ -1,4 +1,4 @@ -package com.cniao5.course.ui +package com.cniao5.course import androidx.lifecycle.LiveData import androidx.lifecycle.viewModelScope @@ -7,6 +7,8 @@ import com.cniao5.common.base.BaseViewModel import com.cniao5.course.net.CourseListRsp import com.cniao5.course.net.CourseTypes import com.cniao5.course.repo.ICourseResource +import com.cniao5.course.ui.CoursePagingAdapter +import com.cniao5.course.ui.CourseRecycAdapter class CourseViewModel(val repo: ICourseResource) : BaseViewModel() { diff --git a/course/src/main/java/com/cniao5/course/libCourse.kt b/course/src/main/java/com/cniao5/course/libCourse.kt index 3fe2e0f..ab848f3 100644 --- a/course/src/main/java/com/cniao5/course/libCourse.kt +++ b/course/src/main/java/com/cniao5/course/libCourse.kt @@ -5,7 +5,6 @@ import com.cniao5.common.utils.getBaseHost import com.cniao5.course.net.CourseService import com.cniao5.course.repo.CourseResource import com.cniao5.course.repo.ICourseResource -import com.cniao5.course.ui.CourseViewModel import org.koin.androidx.viewmodel.dsl.viewModel import org.koin.core.parameter.parametersOf import org.koin.dsl.bind diff --git a/course/src/main/java/com/cniao5/course/ui/CourseFragment.kt b/course/src/main/java/com/cniao5/course/ui/CourseFragment.kt index 1165072..ac2f342 100644 --- a/course/src/main/java/com/cniao5/course/ui/CourseFragment.kt +++ b/course/src/main/java/com/cniao5/course/ui/CourseFragment.kt @@ -3,7 +3,6 @@ package com.cniao5.course.ui import android.graphics.Color import android.graphics.drawable.ColorDrawable import android.os.Bundle -import android.util.Log import android.view.LayoutInflater import android.view.View import android.view.ViewGroup @@ -14,9 +13,9 @@ import androidx.lifecycle.lifecycleScope import androidx.paging.LoadState import com.blankj.utilcode.util.ToastUtils import com.cniao5.common.base.BaseFragment +import com.cniao5.course.CourseViewModel import com.cniao5.course.R import com.cniao5.course.databinding.* -import com.cniao5.course.net.CourseListRsp import com.google.android.material.tabs.TabLayout import kotlinx.coroutines.flow.collectLatest import org.koin.androidx.viewmodel.ext.android.viewModel @@ -51,11 +50,33 @@ class CourseFragment: BaseFragment() { mBinding = FragmentCourseBinding.bind(view) return mBinding.apply { + + vm = viewModel + val adapter = viewModel.coursePagingAdapter //下方的load Header头部load rvCourse.adapter = adapter.withLoadStateFooter(CourseLoadAdapter(adapter)) - vm = viewModel + //Load上滑进度条监听 + adapter.addLoadStateListener { loadState -> + if (loadState.refresh is LoadState.Loading) { + pbFragmentCourse.visibility = View.VISIBLE + } else { + pbFragmentCourse.visibility = View.GONE + + //获取加载错误事件 + val error = when { + loadState.prepend is LoadState.Error -> loadState.prepend as LoadState.Error + loadState.append is LoadState.Error -> loadState.append as LoadState.Error + loadState.refresh is LoadState.Error -> loadState.refresh as LoadState.Error + else -> null + } + + error?.let { + ToastUtils.showShort(it.error.message) + } + } + } viewModel.apply { @@ -118,27 +139,6 @@ class CourseFragment: BaseFragment() { courseRecycAdapter.submitClear(it?.datas ?: emptyList()) } - //Load上滑进度条监听 - adapter.addLoadStateListener { loadState -> - if (loadState.refresh is LoadState.Loading) { - pbFragmentCourse.visibility = View.VISIBLE - } else { - pbFragmentCourse.visibility = View.GONE - - //获取加载错误事件 - val error = when { - loadState.prepend is LoadState.Error -> loadState.prepend as LoadState.Error - loadState.append is LoadState.Error -> loadState.append as LoadState.Error - loadState.refresh is LoadState.Error -> loadState.refresh as LoadState.Error - else -> null - } - - error?.let { - ToastUtils.showShort(it.error.message) - } - } - } - //全部类型按钮点击事件 spinnerTypeCourse.setOnClickListener { popupWindow_type.showAsDropDown(it) diff --git a/course/src/main/res/layout/fragment_course.xml b/course/src/main/res/layout/fragment_course.xml index f62ce3c..a0a26a4 100644 --- a/course/src/main/res/layout/fragment_course.xml +++ b/course/src/main/res/layout/fragment_course.xml @@ -6,7 +6,7 @@ + type="com.cniao5.course.CourseViewModel" /> diff --git a/course/src/main/res/layout/item_course_recyc.xml b/course/src/main/res/layout/item_course_recyc.xml index c0a44ec..f134803 100644 --- a/course/src/main/res/layout/item_course_recyc.xml +++ b/course/src/main/res/layout/item_course_recyc.xml @@ -102,7 +102,7 @@ android:gravity="center" android:paddingVertical="2dp" android:text="免费学" - android:textColor="@color/colorAccent" + android:textColor="@color/lightseagreen" android:textSize="12sp" android:visibility="@{(info.isFree()==1)?View.VISIBLE:View.GONE}" app:layout_constraintBottom_toBottomOf="parent" diff --git a/home/build.gradle b/home/build.gradle index 7024922..76c536a 100644 --- a/home/build.gradle +++ b/home/build.gradle @@ -17,5 +17,9 @@ android { } dependencies { implementation project(path:':service') + //第三方banner + implementation 'com.youth.banner:banner:2.1.0' + //from dependencies.gradle + } \ No newline at end of file diff --git a/home/src/main/AndroidManifest.xml b/home/src/main/AndroidManifest.xml index 668a732..86c21a6 100644 --- a/home/src/main/AndroidManifest.xml +++ b/home/src/main/AndroidManifest.xml @@ -2,4 +2,7 @@ + + + \ No newline at end of file diff --git a/home/src/main/java/com/cniao5/home/HomeFragment.kt b/home/src/main/java/com/cniao5/home/HomeFragment.kt deleted file mode 100644 index 280a699..0000000 --- a/home/src/main/java/com/cniao5/home/HomeFragment.kt +++ /dev/null @@ -1,23 +0,0 @@ -package com.cniao5.home - -import android.os.Bundle -import android.view.View -import androidx.databinding.ViewDataBinding -import com.cniao5.common.base.BaseFragment -import com.cniao5.home.databinding.FragmentHomeBinding - -/* -* 主页的Fragment -* 传入了R.layout.fragment_course之后就不用写onCreateView,因为布局已经被关联到fragment里了 -* */ -class HomeFragment: BaseFragment() { - - //传入布局资源,将布局和view绑定到一起 - override fun getLayoutRes() = R.layout.fragment_home - - //传入view,将view和databinding绑定到一起 - override fun bindView(view: View, savedInstanceState: Bundle?): ViewDataBinding { - return FragmentHomeBinding.bind(view) - } - -} \ No newline at end of file diff --git a/home/src/main/java/com/cniao5/home/LibHome.kt b/home/src/main/java/com/cniao5/home/LibHome.kt new file mode 100644 index 0000000..3375686 --- /dev/null +++ b/home/src/main/java/com/cniao5/home/LibHome.kt @@ -0,0 +1,36 @@ +package com.cniao5.home + +import com.cniao5.common.network.KtRetrofit +import com.cniao5.common.utils.getBaseHost +import com.cniao5.home.net.HomeService +import com.cniao5.home.repo.HomeResource +import com.cniao5.home.repo.IHomeResource +import com.cniao5.home.ui.HomeViewModel +import org.koin.core.parameter.parametersOf +import org.koin.androidx.viewmodel.dsl.viewModel +import org.koin.dsl.bind +import org.koin.dsl.module + + +/* +* 依赖注入管理 Home的module +* */ +val moduleHome = module { + + //service retrofit + //single声明单例对象 + // single { + // KtRetrofit.initConfig("http://yapi.54yct.com/mock/24/") //baseurl + // .getService(MineService::class.java) + // } + + single { + get { parametersOf(getBaseHost()) }.getService(HomeService::class.java) + } + + //repo IMineResource + single { HomeResource(get()) } bind IHomeResource::class + + viewModel { HomeViewModel(get()) } + +} \ No newline at end of file diff --git a/home/src/main/java/com/cniao5/home/net/HomeRsp.kt b/home/src/main/java/com/cniao5/home/net/HomeRsp.kt new file mode 100644 index 0000000..e897144 --- /dev/null +++ b/home/src/main/java/com/cniao5/home/net/HomeRsp.kt @@ -0,0 +1,30 @@ +package com.cniao5.home.net +import androidx.annotation.Keep + +import com.google.gson.annotations.SerializedName + + +/* +* 首页上方banner图数据 +* */ +class BannerList : ArrayList(){ + @Keep + data class BannerListItem( + @SerializedName("client_url") + val clientUrl: Any?, + @SerializedName("created_time") + val createdTime: String?, + val id: Int, + @SerializedName("img_url") + val imgUrl: String?, + val name: Any?, + @SerializedName("order_num") + val orderNum: Int, + @SerializedName("page_show") + val pageShow: Int, + @SerializedName("redirect_url") + val redirectUrl: String?, + val state: Int, + val type: String? + ) +} \ No newline at end of file diff --git a/home/src/main/java/com/cniao5/home/net/HomeService.kt b/home/src/main/java/com/cniao5/home/net/HomeService.kt new file mode 100644 index 0000000..4fe95de --- /dev/null +++ b/home/src/main/java/com/cniao5/home/net/HomeService.kt @@ -0,0 +1,23 @@ +package com.cniao5.home.net + +import com.test.service.net.BaseResponse +import retrofit2.Call +import retrofit2.http.GET +import retrofit2.http.Query + + +/* +* 主页模块的接口 +* */ +interface HomeService { + + /* + * 首页上方banner + * */ + @GET("ad/new/banner/list") + fun getBanner( + @Query("type")type: Int = 2, //类型 1:小程序 2:web 3:h5 4:ios 5:android 如: 2表示web 默认2 + @Query("page_show") pageshow:Int = 1 //页面显示 1 首页 2 课程 3 大数据学院 4 机器人学院 5 人工智能学院 6 推广员 默认1 + ) : Call + +} \ No newline at end of file diff --git a/home/src/main/java/com/cniao5/home/repo/HomeResource.kt b/home/src/main/java/com/cniao5/home/repo/HomeResource.kt new file mode 100644 index 0000000..da125b4 --- /dev/null +++ b/home/src/main/java/com/cniao5/home/repo/HomeResource.kt @@ -0,0 +1,41 @@ +package com.cniao5.home.repo + +import androidx.lifecycle.LiveData +import androidx.lifecycle.MutableLiveData +import com.blankj.utilcode.util.LogUtils +import com.cniao5.common.network.support.serverData +import com.cniao5.home.net.BannerList +import com.cniao5.home.net.HomeService +import com.test.service.net.onBizError +import com.test.service.net.onBizOK +import com.test.service.net.onFailure +import com.test.service.net.onSuccess + +class HomeResource (val service: HomeService) : IHomeResource { + + private val _liveBanner = MutableLiveData() + + override val liveBanner: LiveData + get() = _liveBanner + + /* + * 获取首页上方banner图数据 + * */ + override suspend fun getBanner() { + service.getBanner() + .serverData() + .onSuccess { + onBizError { code, message -> + LogUtils.w("获取banner信息 onBizzError $code$message") + } + onBizOK { code, data, message -> + _liveBanner.value = data + LogUtils.i("获取banner信息 onBizzOK $data") + } + } + .onFailure { + LogUtils.e("获取banner信息 接口异常 ${it.message}") + } + } + +} \ No newline at end of file diff --git a/home/src/main/java/com/cniao5/home/repo/IHomeResource.kt b/home/src/main/java/com/cniao5/home/repo/IHomeResource.kt new file mode 100644 index 0000000..73fbbdc --- /dev/null +++ b/home/src/main/java/com/cniao5/home/repo/IHomeResource.kt @@ -0,0 +1,15 @@ +package com.cniao5.home.repo + +import androidx.lifecycle.LiveData +import com.cniao5.home.net.BannerList +/* +* 抽象接口 +* */ +interface IHomeResource { + + //首页上方banner图 + val liveBanner: LiveData + + suspend fun getBanner() + +} \ No newline at end of file diff --git a/home/src/main/java/com/cniao5/home/ui/HomeFragment.kt b/home/src/main/java/com/cniao5/home/ui/HomeFragment.kt new file mode 100644 index 0000000..ca0946b --- /dev/null +++ b/home/src/main/java/com/cniao5/home/ui/HomeFragment.kt @@ -0,0 +1,59 @@ +package com.cniao5.home.ui + +import android.os.Bundle +import android.util.Log +import android.view.View +import androidx.databinding.ViewDataBinding +import com.cniao5.common.base.BaseFragment +import com.cniao5.home.R +import com.cniao5.home.databinding.FragmentHomeBinding +import com.cniao5.home.net.BannerList +import com.cniao5.home.ui.adapter.BannerAdapter +import com.youth.banner.indicator.CircleIndicator +import org.koin.androidx.viewmodel.ext.android.viewModel + +/* +* 主页的Fragment +* 传入了R.layout.fragment_course之后就不用写onCreateView,因为布局已经被关联到fragment里了 +* */ +class HomeFragment: BaseFragment() { + + private val viewmodel: HomeViewModel by viewModel() + + private val bannerList = BannerList() + + private val bannerAdapter by lazy { BannerAdapter(bannerList) } + + //传入布局资源,将布局和view绑定到一起 + override fun getLayoutRes() = R.layout.fragment_home + + //传入view,将view和databinding绑定到一起 + override fun bindView(view: View, savedInstanceState: Bundle?): ViewDataBinding { + return FragmentHomeBinding.bind(view).apply { + + bannerHome.addBannerLifecycleObserver(viewLifecycleOwner) //生命周期观察者 + .setAdapter(bannerAdapter).indicator = CircleIndicator(requireContext()) //轮播图上的小点 + } + } + + override fun initConfig() { + super.initConfig() + + } + + override fun initData() { + super.initData() + + //上方banner + viewmodel.getBanner() + viewmodel.liveBanner.observeKt { + it ?: return@observeKt + bannerList.clear() + bannerList.addAll(it) //todo 添加多一次,因为返回的只有一个数据 + bannerList.addAll(it) + bannerAdapter.notifyDataSetChanged() + } + + + } +} \ No newline at end of file diff --git a/home/src/main/java/com/cniao5/home/ui/HomeViewModel.kt b/home/src/main/java/com/cniao5/home/ui/HomeViewModel.kt new file mode 100644 index 0000000..250256c --- /dev/null +++ b/home/src/main/java/com/cniao5/home/ui/HomeViewModel.kt @@ -0,0 +1,22 @@ +package com.cniao5.home.ui + +import androidx.lifecycle.MutableLiveData +import androidx.lifecycle.ViewModel +import com.cniao5.common.base.BaseViewModel +import com.cniao5.home.net.BannerList +import com.cniao5.home.repo.IHomeResource + +/* +* 首页的viewmodel +* */ +class HomeViewModel(private val resource: IHomeResource) : BaseViewModel() { + + //首页上方的banner图 + val liveBanner = resource.liveBanner + val liveBannerMu = MutableLiveData() + + fun getBanner() = serverAwait { + resource.getBanner() + } + +} \ No newline at end of file diff --git a/home/src/main/java/com/cniao5/home/ui/adapter/BannerAdapter.kt b/home/src/main/java/com/cniao5/home/ui/adapter/BannerAdapter.kt new file mode 100644 index 0000000..94307d8 --- /dev/null +++ b/home/src/main/java/com/cniao5/home/ui/adapter/BannerAdapter.kt @@ -0,0 +1,41 @@ +package com.cniao5.home.ui.adapter + +import com.bumptech.glide.Glide +import com.bumptech.glide.load.resource.bitmap.RoundedCorners +import com.bumptech.glide.request.RequestOptions +import com.cniao5.home.R +import com.cniao5.home.net.BannerList +import com.youth.banner.adapter.BannerImageAdapter +import com.youth.banner.holder.BannerImageHolder + +/* +* 首页上方banner的适配器,传入bannerList解析的数据格式 +* */ +class BannerAdapter(val bannerList: BannerList) : BannerImageAdapter(bannerList) { + override fun onBindView( + holder: BannerImageHolder?, + data: BannerList.BannerListItem?, + position: Int, + size: Int + ) { + holder ?: return //如果为空的话直接返回 + + //有的相片地址没有https: + val src = data?.imgUrl + val imageUrl = when(src) { + is String -> { + when { + src.startsWith("//img.cniao5.com") -> "https:$src" + else -> src + } + } + else -> src ?: R.drawable.img_course + } + + //不为空时加载图片 + Glide.with(holder.itemView) + .load(imageUrl) + .apply(RequestOptions.bitmapTransform(RoundedCorners(30))) + .into(holder.imageView) + } +} \ No newline at end of file diff --git a/home/src/main/res/drawable/ic_mine_small.xml b/home/src/main/res/drawable/ic_mine_small.xml new file mode 100644 index 0000000..f73e13f --- /dev/null +++ b/home/src/main/res/drawable/ic_mine_small.xml @@ -0,0 +1,21 @@ + + + + + + + diff --git a/home/src/main/res/drawable/img_course.png b/home/src/main/res/drawable/img_course.png new file mode 100644 index 0000000..a8ddceb Binary files /dev/null and b/home/src/main/res/drawable/img_course.png differ diff --git a/home/src/main/res/layout/fragment_home.xml b/home/src/main/res/layout/fragment_home.xml index 868e51d..a34f41e 100644 --- a/home/src/main/res/layout/fragment_home.xml +++ b/home/src/main/res/layout/fragment_home.xml @@ -1,24 +1,22 @@ - + - diff --git a/login/src/debug/AndroidManifest.xml b/login/src/debug/AndroidManifest.xml index 7583558..24dcc92 100644 --- a/login/src/debug/AndroidManifest.xml +++ b/login/src/debug/AndroidManifest.xml @@ -11,7 +11,7 @@ android:roundIcon="@mipmap/ic_launcher_round" android:theme="@style/CommonTheme"> diff --git a/login/src/debug/java/login/LoginActivity.kt b/login/src/debug/java/login/ui/LoginActivity.kt similarity index 95% rename from login/src/debug/java/login/LoginActivity.kt rename to login/src/debug/java/login/ui/LoginActivity.kt index 949f596..55198ec 100644 --- a/login/src/debug/java/login/LoginActivity.kt +++ b/login/src/debug/java/login/ui/LoginActivity.kt @@ -1,15 +1,15 @@ -package login +package login.ui import com.alibaba.android.arouter.facade.annotation.Route -import com.alibaba.android.arouter.launcher.ARouter import com.blankj.utilcode.util.ToastUtils import com.cniao5.common.base.BaseActivity import com.cniao5.common.ktx.context import com.cniao5.common.network.config.SP_KEY_USER_TOKEN import com.cniao5.common.utils.MySpUtils import com.test.service.repo.DbHelper +import login.LoginViewModel +import login.R import login.databinding.ActivityLoginBinding -import login.net.LoginRsp import login.net.RegisterRsp import org.koin.androidx.viewmodel.ext.android.viewModel diff --git a/login/src/main/AndroidManifest.xml b/login/src/main/AndroidManifest.xml index e95d59f..961de1d 100644 --- a/login/src/main/AndroidManifest.xml +++ b/login/src/main/AndroidManifest.xml @@ -3,7 +3,7 @@ package="login"> - diff --git a/mine/src/main/java/com/cniao5/mine/LibMine.kt b/mine/src/main/java/com/cniao5/mine/LibMine.kt index 4061acc..e140482 100644 --- a/mine/src/main/java/com/cniao5/mine/LibMine.kt +++ b/mine/src/main/java/com/cniao5/mine/LibMine.kt @@ -5,7 +5,6 @@ import com.cniao5.common.utils.getBaseHost import com.cniao5.mine.net.MineService import com.cniao5.mine.repo.IMineResource import com.cniao5.mine.repo.MineRepo -import com.cniao5.mine.ui.MineViewModel import org.koin.androidx.viewmodel.dsl.viewModel import org.koin.core.parameter.parametersOf import org.koin.dsl.bind diff --git a/mine/src/main/java/com/cniao5/mine/ui/MineViewModel.kt b/mine/src/main/java/com/cniao5/mine/MineViewModel.kt similarity index 97% rename from mine/src/main/java/com/cniao5/mine/ui/MineViewModel.kt rename to mine/src/main/java/com/cniao5/mine/MineViewModel.kt index 7ef562e..b975686 100644 --- a/mine/src/main/java/com/cniao5/mine/ui/MineViewModel.kt +++ b/mine/src/main/java/com/cniao5/mine/MineViewModel.kt @@ -1,4 +1,4 @@ -package com.cniao5.mine.ui +package com.cniao5.mine import androidx.lifecycle.LiveData import androidx.lifecycle.MutableLiveData diff --git a/mine/src/main/java/com/cniao5/mine/ui/MineFragment.kt b/mine/src/main/java/com/cniao5/mine/ui/MineFragment.kt index bfaab7f..9abf636 100644 --- a/mine/src/main/java/com/cniao5/mine/ui/MineFragment.kt +++ b/mine/src/main/java/com/cniao5/mine/ui/MineFragment.kt @@ -1,20 +1,16 @@ package com.cniao5.mine.ui import android.os.Bundle -import android.util.Log import android.view.View import androidx.databinding.ViewDataBinding import androidx.navigation.fragment.findNavController import com.alibaba.android.arouter.launcher.ARouter -import com.blankj.utilcode.util.LogUtils -import com.blankj.utilcode.util.ToastUtils import com.cniao5.common.base.BaseFragment import com.cniao5.common.network.config.SP_KEY_USER_TOKEN import com.cniao5.common.utils.MySpUtils +import com.cniao5.mine.MineViewModel import com.cniao5.mine.R import com.cniao5.mine.databinding.FragmentMineBinding -import com.cniao5.mine.net.UserInfoRsp -import com.cniao5.mine.repo.UserInfoRspDB import com.cniao5.mine.repo.UserInfoRspDBHelper import com.test.service.repo.DbHelper import org.koin.androidx.viewmodel.ext.android.viewModel diff --git a/mine/src/main/res/layout/fragment_mine.xml b/mine/src/main/res/layout/fragment_mine.xml index 0192636..9893f9f 100644 --- a/mine/src/main/res/layout/fragment_mine.xml +++ b/mine/src/main/res/layout/fragment_mine.xml @@ -7,7 +7,7 @@ + type="com.cniao5.mine.MineViewModel" /> diff --git a/service/src/main/res/values/colors.xml b/service/src/main/res/values/colors.xml index ef143d7..abbdda4 100644 --- a/service/src/main/res/values/colors.xml +++ b/service/src/main/res/values/colors.xml @@ -137,4 +137,142 @@ #e6ffffff #ffffffff + #fffafa + #fffaf0 + #ffebcd + #f8f8ff + #f5f5f5 + #faebd7 + #ffdead + #808080 + #dcdcdc + #d3d3d3 + #a9a9a9 + #696969 + #708090 + #778899 + #2f4f4f + #c0c0c0 + + #ff0000 + #8b0000 + #dc143c + #8b008b + #ff00ff + #ff6347 + #f08080 + #e9967a + #ffdab9 + #dda0dd + #ffc0cb + #ffb6c1 + #ff1493 + #ff69b4 + #fff0f5 + #cd5c5c + #bc8f8f + #b22222 + #800000 + #f0fff0 + #ff4500 + #ffa500 + #32cd32 + #00ff00 + #ffff00 + #f5deb3 + #f0e68c + #deb887 + #ffe4c4 + #ffffe0 + #b8860b + #ff8c00 + #fafad2 + #fffacd + #fff8dc + #fff5ee + #ffefd5 + #ffe4e1 + #ffe4b5 + #fffff0 + #ffd700 + #daa520 + #ffa07a + #ff7f50 + #f5fffa + #f5f5dc + #f4a460 + #fdf5e6 + #faf0e6 + #fa8072 + #d8bfd8 + #d2b48c + #d2691e + #cd853f + #bdb76b + #eee8aa + #a52a2a + #8b4513 + #a0522d + #808000 + #7fff00 + #adff2f + #008000 + #006400 + #556b2f + #6b8e23 + #7cfc00 + #228b22 + #7fffd4 + #afeeee + #98fb98 + #48d1cc + #66cdaa + #00ffff + #00ff7f + #00fa9a + #00ced1 + #2e8b57 + #90ee90 + #8fbc8f + #40e0d0 + #00ffff + #008b8b + #e0ffff + #008080 + #4b0082 + #0000ff + #00008b + #0000cd + #191970 + #000080 + #4169e1 + #f0ffff + #87ceeb + #00bfff + #87cefa + #20b2aa + #add8e6 + #b0e0e6 + #f0f8ff + #7b68ee + #6a5acd + #483d8b + #3cb371 + #4682b4 + #b0c4de + #6495ed + #1e90ff + #5f9ea0 + #8a2be2 + #800080 + #e6e6fa + #da70d6 + #9370db + #9932cc + #ee82ee + #c71585 + #db7093 + #9400d3 + #ba55d3 + \ No newline at end of file diff --git a/study/src/main/java/com/cniao5/study/LibStudy.kt b/study/src/main/java/com/cniao5/study/LibStudy.kt index a9009d1..9099297 100644 --- a/study/src/main/java/com/cniao5/study/LibStudy.kt +++ b/study/src/main/java/com/cniao5/study/LibStudy.kt @@ -2,11 +2,9 @@ package com.cniao5.study import com.cniao5.common.network.KtRetrofit import com.cniao5.common.utils.getBaseHost -import com.cniao5.study.net.StudyInfoRsp import com.cniao5.study.net.StudyService import com.cniao5.study.repo.IStudyResource import com.cniao5.study.repo.StudyResource -import com.cniao5.study.ui.StudyViewModel import org.koin.androidx.viewmodel.dsl.viewModel import org.koin.core.parameter.parametersOf import org.koin.dsl.bind diff --git a/study/src/main/java/com/cniao5/study/ui/StudyViewModel.kt b/study/src/main/java/com/cniao5/study/StudyViewModel.kt similarity index 95% rename from study/src/main/java/com/cniao5/study/ui/StudyViewModel.kt rename to study/src/main/java/com/cniao5/study/StudyViewModel.kt index 109b699..69125a8 100644 --- a/study/src/main/java/com/cniao5/study/ui/StudyViewModel.kt +++ b/study/src/main/java/com/cniao5/study/StudyViewModel.kt @@ -1,4 +1,4 @@ -package com.cniao5.study.ui +package com.cniao5.study import androidx.databinding.ObservableField import androidx.lifecycle.LiveData @@ -9,6 +9,7 @@ import com.cniao5.study.net.BoughtRsp import com.cniao5.study.net.StudiedRsp import com.cniao5.study.net.StudyInfoRsp import com.cniao5.study.repo.StudyResource +import com.cniao5.study.ui.StudiedAdapter import com.test.service.repo.UserInfo class StudyViewModel(private val resource: StudyResource) : BaseViewModel() { diff --git a/study/src/main/java/com/cniao5/study/ui/StudyFragment.kt b/study/src/main/java/com/cniao5/study/ui/StudyFragment.kt index 4def484..0fa9473 100644 --- a/study/src/main/java/com/cniao5/study/ui/StudyFragment.kt +++ b/study/src/main/java/com/cniao5/study/ui/StudyFragment.kt @@ -1,11 +1,12 @@ package com.cniao5.study.ui import android.os.Bundle +import android.util.Log import android.view.View import androidx.databinding.ViewDataBinding -import androidx.lifecycle.lifecycleScope import com.cniao5.common.base.BaseFragment import com.cniao5.study.R +import com.cniao5.study.StudyViewModel import com.cniao5.study.databinding.FragmentStudyBinding import com.cniao5.study.repo.StudyInfoDbHelper import com.google.android.material.tabs.TabLayout @@ -17,7 +18,7 @@ import org.koin.androidx.viewmodel.ext.android.viewModel * 学习中心的Fragmennt * 传入了R.layout.fragment_course之后就不用写onCreateView,因为布局已经被关联到fragment里了 * */ -class StudyFragment: BaseFragment() { +class StudyFragment : BaseFragment() { private val viewModel: StudyViewModel by viewModel() @@ -38,10 +39,12 @@ class StudyFragment: BaseFragment() { //页面position从0开始 // Log.d("yyy","${tab!!.position}") } + //tab未被选择时回调 override fun onTabUnselected(tab: TabLayout.Tab?) { } + //tab重新选择时回调 override fun onTabReselected(tab: TabLayout.Tab?) { @@ -65,6 +68,7 @@ class StudyFragment: BaseFragment() { //清空界面上的数据 StudyInfoDbHelper.deleteStudyInfo(requireContext()) viewModel.obUserInfo.set(it) //数据库发生变化的时候拿到Userinfo的值 + viewModel.adapter.submit(emptyList()) //清空recyclerview的数据 } else { viewModel.obUserInfo.set(it) //数据库发生变化的时候拿到Userinfo的值 viewModel.getStudyData() @@ -80,7 +84,7 @@ class StudyFragment: BaseFragment() { } //已经学习过的课程列表 使用传统加载数据的方式实现 liveStudyList.observeKt { - adapter.submit(it?.datas?: emptyList()) + adapter.submit(it?.datas ?: emptyList()) } //paging分页库加载数据方式实现 挂起函数需要在协程里启动 @@ -96,11 +100,9 @@ class StudyFragment: BaseFragment() { } - //studyinfo数据库的数据有变化时触发 + //studyinfo数据库的数据有变化时触发 用户信息 StudyInfoDbHelper.getLiveStudyInfo(requireContext()).observeKt { info -> - info.let { - viewModel.liveStudyInfoR.value = info //清空liveStudyInfoR的数据 - } + viewModel.liveStudyInfoR.value = info //清空liveStudyInfoR的数据 } } diff --git a/study/src/main/java/com/cniao5/study/utils/StudyUtils.kt b/study/src/main/java/com/cniao5/study/utils/StudyUtils.kt index 253af37..940a88e 100644 --- a/study/src/main/java/com/cniao5/study/utils/StudyUtils.kt +++ b/study/src/main/java/com/cniao5/study/utils/StudyUtils.kt @@ -5,7 +5,7 @@ import com.cniao5.study.net.StudiedRsp import com.daimajia.numberprogressbar.NumberProgressBar /** - * + * DataBinding数据解析 */ object StudyUtils { @JvmStatic diff --git a/study/src/main/res/layout/fragment_study.xml b/study/src/main/res/layout/fragment_study.xml index c613677..ca3a75a 100644 --- a/study/src/main/res/layout/fragment_study.xml +++ b/study/src/main/res/layout/fragment_study.xml @@ -7,7 +7,7 @@ + type="com.cniao5.study.StudyViewModel" />