Skip to content

Commit

Permalink
学习中心
Browse files Browse the repository at this point in the history
  • Loading branch information
linxiangcheer committed Mar 15, 2021
1 parent 3b3b412 commit ed8ba41
Show file tree
Hide file tree
Showing 29 changed files with 1,111 additions and 61 deletions.
3 changes: 2 additions & 1 deletion app/src/main/java/com/cniao5/cainiaowo/CnApplication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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.mine.moduleMine
import com.cniao5.study.moduleStudy
import com.test.service.assistant.AssistantApp
import com.test.service.moduleService
import login.moduleLogin
Expand All @@ -13,7 +14,7 @@ import org.koin.core.module.Module
class CnApplication : BaseApplication() {

private val modules = arrayListOf<Module>(
moduleService,/*moduleHome,*/ moduleLogin, moduleMine
moduleService,/*moduleHome,*/ moduleLogin, moduleMine, moduleStudy
)

override fun initConfig() {
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/java/com/cniao5/cainiaowo/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ import com.cniao5.common.widget.BnvVp2Mediator
import com.cniao5.course.CourseFragment
import com.cniao5.home.HomeFragment
import com.cniao5.mine.MineContainerFragment
import com.cniao5.mine.ui.MineFragment
import com.cniao5.study.StudyFragment
import com.cniao5.study.ui.StudyFragment

/*
* App主工程的入口界面
Expand Down Expand Up @@ -69,8 +68,9 @@ class MainViewPagerAdapter(fragmentActivity: FragmentActivity, private val fragm

//创建fragment invoke回调函数,让它实例化创建新的对象
override fun createFragment(position: Int) = fragments[position]?.invoke() ?: error("请确保fragment数据源和viewPager2的index匹配设置")

}


//类型别名定义 传入的是一个代码块,每次都是一个新的Fragment
typealias ReFragment = () -> Fragment

1 change: 1 addition & 0 deletions common/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
<string name="title_course">课程</string>
<string name="title_study">学习中心</string>
<string name="title_mine">我的</string>
<string name="study_name">未登录</string>
</resources>
9 changes: 5 additions & 4 deletions dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,9 @@ dependencies {
kapt "androidx.room:room-compiler:2.2.6"

//region jetpack组件分页,上拉加载平滑过渡效果
implementation "androidx.paging:paging-runtime:2.1.2"
testImplementation "androidx.paging:paging-common:2.1.2"
def paging_version = "3.0.0-beta01"
implementation "androidx.paging:paging-runtime:$paging_version"
testImplementation "androidx.paging:paging-common:$paging_version"
//endregion

//region Description 注意配置navigetion版本号的时候,project下的build.gradle的class path也需要同步navigation的版本号配置
Expand Down Expand Up @@ -133,7 +134,7 @@ dependencies {

//region test libs
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
//endregion
}
8 changes: 2 additions & 6 deletions login/src/debug/java/login/repo/LoginRepo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ import androidx.lifecycle.LiveData
import com.blankj.utilcode.util.LogUtils
import com.cniao5.common.model.SingleLiveData
import com.cniao5.common.network.support.serverData
import com.test.service.net.onBizError
import com.test.service.net.onBizOK
import com.test.service.net.onFailure
import com.test.service.net.onSuccess
import com.test.service.net.*
import login.net.LoginService
import login.net.LoginReqBody
import login.net.LoginRsp
Expand Down Expand Up @@ -37,7 +34,7 @@ class LoginRepo(private val service: LoginService) : ILoginResource{
}
onBizOK<RegisterRsp> { code, data, message ->
_registerRsp.value = data
LogUtils.i("是否注册 BizOK $data")
// LogUtils.i("是否注册 BizOK $data")
return@onBizOK
}
}
Expand All @@ -57,7 +54,6 @@ class LoginRepo(private val service: LoginService) : ILoginResource{
onBizOK<LoginRsp> { code, data, message ->
_loginRsp.value = data
//同步到room数据库 登录状态

LogUtils.i("登录接口 BizOK $data")
return@onBizOK
}
Expand Down
1 change: 1 addition & 0 deletions mine/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ android {
defaultConfig{
//只要独立运行时候才需要applicationId
if (singleModule.toBoolean()){
//唯一的身份标记
applicationId "com.cniao5.cainiaowo.mine"
}
}
Expand Down
5 changes: 1 addition & 4 deletions mine/src/main/java/com/cniao5/mine/repo/MineRepo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ import com.blankj.utilcode.util.LogUtils
import com.cniao5.common.network.support.serverData
import com.cniao5.mine.net.MineService
import com.cniao5.mine.net.UserInfoRsp
import com.test.service.net.onFailure
import com.test.service.net.onSuccess
import com.test.service.net.onBizError
import com.test.service.net.onBizOK
import com.test.service.net.*


/*
Expand Down
3 changes: 2 additions & 1 deletion mine/src/main/java/com/cniao5/mine/ui/MineFragment.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
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
Expand Down Expand Up @@ -90,7 +91,7 @@ class MineFragment : BaseFragment() {

viewModel.apply {
//如果Liveinfo数据更新不为空的话就存储到数据库中
liveInfo.observeKt {
liveInforep.observeKt {
it?.let {
UserInfoRspDBHelper.insertUserInfoRsp(requireContext(), it)
//将数据给到布局的livedata
Expand Down
2 changes: 1 addition & 1 deletion mine/src/main/java/com/cniao5/mine/ui/MineViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class MineViewModel(private val repo: IMineResource): BaseViewModel() {
// val liveUser = MutableLiveData<UserInfo>()

//用在userInfoRspFragment中
val liveInfo: LiveData<UserInfoRsp> = repo.liveUserInfo
val liveInforep: LiveData<UserInfoRsp> = repo.liveUserInfo

//用于布局的Livedata
val liveInfoRsp = MutableLiveData<UserInfoRsp>()
Expand Down
9 changes: 5 additions & 4 deletions service/src/main/java/com/test/service/net/NetRspKtx.kt
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,21 @@ inline fun <reified T> BaseResponse.toEntity(): T? {
}

/**
* 接口成功,但是业务返回code不是1的情况
* 接口成功,但是业务返回code不是1或1001的情况
*/
@OptIn(ExperimentalContracts::class)
inline fun BaseResponse.onBizError(crossinline block: (code: Int, message: String) -> Unit): BaseResponse {
inline fun BaseResponse.onBizError(crossinline block: (code: Int, message: String?) -> Unit): BaseResponse {
contract {
callsInPlace(block, InvocationKind.AT_MOST_ONCE)
}
if (code != BaseResponse.SERVER_CODE_SUCCESS || code != BaseResponse.SERVER_CODE_SUCCESS1) { //code == 除了1001和1之外的其他,不成功
if (code != BaseResponse.SERVER_CODE_SUCCESS1 && code != BaseResponse.SERVER_CODE_SUCCESS) { //同时不等于1和1001的时候执行if
block.invoke(code, message ?: "Error Message Null") //返回错误码和错误信息
}
return this
}



/**
* 接口成功且业务成功code==1的情况
* crossinline关键字 只要标志了就不能进入return true函数快
Expand All @@ -60,7 +62,6 @@ inline fun <reified T> BaseResponse.onBizOK(crossinline action: (code: Int, data
contract {
callsInPlace(action, InvocationKind.AT_MOST_ONCE)
}
com.blankj.utilcode.util.LogUtils.i("获取data成功 $data")
if (code == BaseResponse.SERVER_CODE_SUCCESS || code == BaseResponse.SERVER_CODE_SUCCESS1) { //code == 1001或code == 1,成功
action.invoke(code, this.toEntity<T>(), message) //返回成功码和解密之后的序列化对象
}
Expand Down
1 change: 1 addition & 0 deletions service/src/main/java/com/test/service/utils/BindingApt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ fun imgSrcCompat(iv: ImageView, src: Any?) {
val imgRes = when(src) {
is String -> {
when {
//如果开头是//img.cniao5.com就添加前缀https:
src.startsWith("//img.cniao5.com") -> "https:$src"
else -> src
}
Expand Down
127 changes: 127 additions & 0 deletions service/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,131 @@
<color name="colorDivider">#BDBDBD</color>
<color name="colorWindowBackGround">#F6F6F6</color>
<color name="colorTitleBlack">#333333</color>

<color name="abc_decor_view_status_guard">#ff000000</color>
<color name="abc_decor_view_status_guard_light">#ffffffff</color>
<color name="abc_search_url_text_normal">#ff7fa87f</color>
<color name="abc_search_url_text_pressed">@android:color/black</color>
<color name="abc_search_url_text_selected">@android:color/black</color>
<color name="accent_material_dark">@color/material_deep_teal_200</color>
<color name="accent_material_light">@color/material_deep_teal_500</color>
<color name="androidx_core_ripple_material_light">#1f000000</color>
<color name="androidx_core_secondary_text_default_material_light">#8a000000</color>
<color name="background_floating_material_dark">@color/material_grey_800</color>
<color name="background_floating_material_light">@android:color/white</color>
<color name="background_material_dark">@color/material_grey_850</color>
<color name="background_material_light">@color/material_grey_50</color>
<color name="black">#ff000000</color>
<color name="bright_foreground_disabled_material_dark">#80ffffff</color>
<color name="bright_foreground_disabled_material_light">#80000000</color>
<color name="bright_foreground_inverse_material_dark">@color/bright_foreground_material_light
</color>
<color name="bright_foreground_inverse_material_light">@color/bright_foreground_material_dark
</color>
<color name="bright_foreground_material_dark">@android:color/white</color>
<color name="bright_foreground_material_light">@android:color/black</color>
<color name="button_material_dark">#ff5a595b</color>
<color name="button_material_light">#ffd6d7d7</color>
<color name="cardview_dark_background">#ff424242</color>
<color name="cardview_light_background">#ffffffff</color>
<color name="cardview_shadow_end_color">#03000000</color>
<color name="cardview_shadow_start_color">#37000000</color>
<color name="colorBlack">#ff000000</color>
<color name="colorPrice">#fff56c6c</color>
<color name="colorSecondaryText">#ff757575</color>
<color name="colorWhite">#ffffffff</color>
<color name="design_bottom_navigation_shadow_color">#14000000</color>
<color name="design_dark_default_color_background">#ff121212</color>
<color name="design_dark_default_color_error">#ffcf6679</color>
<color name="design_dark_default_color_on_background">#ffffffff</color>
<color name="design_dark_default_color_on_error">#ff000000</color>
<color name="design_dark_default_color_on_primary">#ff000000</color>
<color name="design_dark_default_color_on_secondary">#ff000000</color>
<color name="design_dark_default_color_on_surface">#ffffffff</color>
<color name="design_dark_default_color_primary">#ffba86fc</color>
<color name="design_dark_default_color_primary_dark">#ff000000</color>
<color name="design_dark_default_color_primary_variant">#ff3700b3</color>
<color name="design_dark_default_color_secondary">#ff03dac6</color>
<color name="design_dark_default_color_secondary_variant">#ff03dac6</color>
<color name="design_dark_default_color_surface">#ff121212</color>
<color name="design_default_color_background">#ffffffff</color>
<color name="design_default_color_error">#ffb00020</color>
<color name="design_default_color_on_background">#ff000000</color>
<color name="design_default_color_on_error">#ffffffff</color>
<color name="design_default_color_on_primary">#ffffffff</color>
<color name="design_default_color_on_secondary">#ff000000</color>
<color name="design_default_color_on_surface">#ff000000</color>
<color name="design_default_color_primary">#ff6200ee</color>
<color name="design_default_color_primary_dark">#ff3700b3</color>
<color name="design_default_color_primary_variant">#ff3700b3</color>
<color name="design_default_color_secondary">#ff03dac6</color>
<color name="design_default_color_secondary_variant">#ff018786</color>
<color name="design_default_color_surface">#ffffffff</color>
<color name="design_fab_shadow_end_color">@android:color/transparent</color>
<color name="design_fab_shadow_mid_color">#14000000</color>
<color name="design_fab_shadow_start_color">#44000000</color>
<color name="design_fab_stroke_end_inner_color">#0a000000</color>
<color name="design_fab_stroke_end_outer_color">#0f000000</color>
<color name="design_fab_stroke_top_inner_color">#1affffff</color>
<color name="design_fab_stroke_top_outer_color">#2effffff</color>
<color name="design_snackbar_background_color">#ff323232</color>
<color name="dim_foreground_disabled_material_dark">#80bebebe</color>
<color name="dim_foreground_disabled_material_light">#80323232</color>
<color name="dim_foreground_material_dark">#ffbebebe</color>
<color name="dim_foreground_material_light">#ff323232</color>
<color name="error_color_material_dark">#ffff7043</color>
<color name="error_color_material_light">#ffff5722</color>
<color name="foreground_material_dark">@android:color/white</color>
<color name="foreground_material_light">@android:color/black</color>
<color name="highlighted_text_material_dark">#6680cbc4</color>
<color name="highlighted_text_material_light">#66009688</color>
<color name="ic_launcher_background">#ffffffff</color>
<color name="material_blue_grey_800">#ff37474f</color>
<color name="material_blue_grey_900">#ff263238</color>
<color name="material_blue_grey_950">#ff21272b</color>
<color name="material_deep_teal_200">#ff80cbc4</color>
<color name="material_deep_teal_500">#ff008577</color>
<color name="material_grey_100">#fff5f5f5</color>
<color name="material_grey_300">#ffe0e0e0</color>
<color name="material_grey_50">#fffafafa</color>
<color name="material_grey_600">#ff757575</color>
<color name="material_grey_800">#ff424242</color>
<color name="material_grey_850">#ff303030</color>
<color name="material_grey_900">#ff212121</color>
<color name="mtrl_btn_text_color_disabled">#61000000</color>
<color name="mtrl_btn_transparent_bg_color">#00ffffff</color>
<color name="mtrl_scrim_color">#52000000</color>
<color name="mtrl_textinput_default_box_stroke_color">#6b000000</color>
<color name="mtrl_textinput_disabled_color">#1f000000</color>
<color name="mtrl_textinput_filled_box_default_background_color">#0a000000</color>
<color name="mtrl_textinput_focused_box_stroke_color">#00000000</color>
<color name="mtrl_textinput_hovered_box_stroke_color">#de000000</color>
<color name="notification_action_color_filter">
@color/androidx_core_secondary_text_default_material_light
</color>
<color name="notification_icon_bg_color">#ff9e9e9e</color>
<color name="notification_material_background_media_default_color">#ff424242</color>
<color name="primary_dark_material_dark">@android:color/black</color>
<color name="primary_dark_material_light">@color/material_grey_600</color>
<color name="primary_material_dark">@color/material_grey_900</color>
<color name="primary_material_light">@color/material_grey_100</color>
<color name="primary_text_default_material_dark">#ffffffff</color>
<color name="primary_text_default_material_light">#de000000</color>
<color name="primary_text_disabled_material_dark">#4dffffff</color>
<color name="primary_text_disabled_material_light">#39000000</color>
<color name="ripple_material_dark">#33ffffff</color>
<color name="ripple_material_light">#1f000000</color>
<color name="secondary_text_default_material_dark">#b3ffffff</color>
<color name="secondary_text_default_material_light">#8a000000</color>
<color name="secondary_text_disabled_material_dark">#36ffffff</color>
<color name="secondary_text_disabled_material_light">#24000000</color>
<color name="select_color">#ff2e2e32</color>
<color name="switch_thumb_disabled_material_dark">#ff616161</color>
<color name="switch_thumb_disabled_material_light">#ffbdbdbd</color>
<color name="switch_thumb_normal_material_dark">#ffbdbdbd</color>
<color name="switch_thumb_normal_material_light">#fff1f1f1</color>
<color name="tooltip_background_dark">#e6616161</color>
<color name="tooltip_background_light">#e6ffffff</color>
<color name="white">#ffffffff</color>

</resources>
3 changes: 3 additions & 0 deletions study/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,8 @@ android {
}
dependencies {
implementation project(path:':service')
//numberprogressbar进度条
implementation 'com.daimajia.numberprogressbar:library:1.4@aar'

//from dependencies.gradle
}
3 changes: 3 additions & 0 deletions study/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.cniao5.study">

<!--网络权限-->
<uses-permission android:name="android.permission.INTERNET"/>

</manifest>
36 changes: 36 additions & 0 deletions study/src/main/java/com/cniao5/study/LibStudy.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
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
import org.koin.dsl.module

/*
* 依赖注入管理 study的module
* */
val moduleStudy = module {

//service retrofit
//single声明单例对象
// single {
// KtRetrofit.initConfig("http://yapi.54yct.com/mock/24/") //baseurl
// .getService(MineService::class.java)
// }

single {
get<KtRetrofit> { parametersOf(getBaseHost()) }.getService(StudyService::class.java)
}

//repo IMineResource
single { StudyResource(get()) } bind IStudyResource::class

viewModel { StudyViewModel(get()) }

}
24 changes: 0 additions & 24 deletions study/src/main/java/com/cniao5/study/StudyFragment.kt

This file was deleted.

Loading

0 comments on commit ed8ba41

Please sign in to comment.