Skip to content

Commit

Permalink
Merge pull request #512 from RedrockMobile/guoxiangrui/feature/projec…
Browse files Browse the repository at this point in the history
…t_hierarchy_opt

🎨 模块层级遗留问题整理
  • Loading branch information
985892345 authored Dec 28, 2024
2 parents 21a2624 + 4f7b776 commit ed59814
Show file tree
Hide file tree
Showing 61 changed files with 222 additions and 1,252 deletions.
63 changes: 0 additions & 63 deletions .github/scripts/generate_release_json.py

This file was deleted.

26 changes: 0 additions & 26 deletions .github/scripts/push_release.py

This file was deleted.

4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ jobs:
- name: Archive production artifacts
uses: actions/upload-artifact@v3
with:
name: result_apk
path: module_app/build/outputs/apk/release/module_app-release.apk
name: CyxbsMobile-test.apk
path: cyxbs-applications/test/build/outputs/apk/release/test-release-unsigned.apk
retention-days: 15

send_message:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.cyxbs.components.account.api

import com.cyxbs.components.account.api.utils.Value
import io.reactivex.rxjava3.core.Observable

interface IUserService {
Expand Down Expand Up @@ -35,18 +34,13 @@ interface IUserService {
*
* 旧模块中推荐转换为 Flow 然后配合生命周期
* ```
* // build.gradle.kts 需要先依赖
* dependCoroutinesRx3()
*
* // 使用例子如下
* IAccountService::class.impl
* .getUserService()
* .observeStuNumEvent()
* .asFlow() // asFlow() 将 Observable 装换为 Flow
* .onEach {
* it.nullUnless {
* initFragment()
* }
* // ...
* }.launchIn(lifecycleScope)
* ```
*
Expand All @@ -62,25 +56,21 @@ interface IUserService {
* .observeOn(Schedulers.io()) // 注意:你需要使用 observeOn 才能切换线程,subscribeOn 无法切换发送源的线程
* .switchMap { value ->
* // switchMap 可以在上游发送新的数据时自动关闭上一次数据生成的 Observable
* value.nullUnless(Observable.never()) {
* if (stuNum.isEmpty()) Observable.never()
* else LessonDataBase.INSTANCE.getStuLessonDao() // 数据库
* .observeAllLesson(stuNum) // 观察数据库的数据变动,这是 Room 的响应式编程
* .distinctUntilChanged() // 必加,因为 Room 每次修改都会回调,所以需要加这个去重
* if (it.isEmpty()) Observable.just(emptyList()) else {
* LessonDataBase.INSTANCE.getStuLessonDao() // 数据库
* .observeAllLesson(stuNum) // 观察数据库的数据变动,这是 Room 的响应式编程
* .distinctUntilChanged() // 必加,因为 Room 每次修改都会回调,所以需要加这个去重
* .doOnSubscribe {
* getLesson(stuNum, isNeedOldList).safeSubscribeBy() // 在开始订阅时请求一次云端数据
* getLesson(stuNum, isNeedOldList).safeSubscribeBy()
* }.map { StuResult(stuNum, it) }
* .subscribeOn(Schedulers.io())
* }
* }
* ```
*
* ### 3、为什么使用 Value 包裹 ?
* 因为 Rxjava 不允许数据为空值,所以使用 Value 包裹了一层
*
* - 更多注意事项请看 [observeStuNumEvent]
*/
fun observeStuNumState(): Observable<Value<String>>
fun observeStuNumState(): Observable<String>

/**
* 观察学号的改变(事件)
Expand All @@ -89,5 +79,5 @@ interface IUserService {
*
* ## 更多注意事项请看 [observeStuNumState]
*/
fun observeStuNumEvent(): Observable<Value<String>>
fun observeStuNumEvent(): Observable<String>
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ interface IUserStateService {

fun loginByTourist()

@WorkerThread
@Throws(Exception::class)
fun refresh()

Expand Down Expand Up @@ -59,18 +60,13 @@ interface IUserStateService {
*
* 旧模块中推荐转换为 Flow 然后配合生命周期,旧模块的使用方式:
* ```
* // build.gradle.kts 需要先依赖
* dependCoroutinesRx3()
*
* // 使用例子如下
* IAccountService::class.impl
* .getUserService()
* .observeStuNumEvent()
* .asFlow() // asFlow() 将 Observable 装换为 Flow
* .onEach {
* it.nullUnless {
* initFragment()
* }
* // ...
* }.launchIn(lifecycleScope) // 这里请注意 Fragment 中要使用 viewLifecycleOwner.lifecycleScope
* ```
*
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import com.cyxbs.components.account.api.IUserTokenService
import com.cyxbs.components.account.bean.LoginParams
import com.cyxbs.components.account.bean.RefreshParams
import com.cyxbs.components.account.bean.TokenWrapper
import com.cyxbs.components.account.utils.UserInfoEncryption
import com.cyxbs.components.account.api.utils.Value
import com.cyxbs.components.utils.utils.secret.Secret
import com.cyxbs.components.utils.extensions.Value
import com.cyxbs.components.account.bean.ErrorMsg
import com.cyxbs.components.account.bean.UserInfo
import com.cyxbs.pages.login.api.ILoginService
Expand Down Expand Up @@ -43,7 +43,7 @@ internal class AccountService : IAccountService {
private val mUserService: IUserService = UserService()
private val mUserStateService: IUserStateService = UserStateService()
private val mUserTokenSerVice: IUserTokenService = UserTokenSerVice()
private val mUserInfoEncryption = UserInfoEncryption()
private val mUserInfoEncryption = Secret()

private var user: UserInfo? = null
@Volatile
Expand Down Expand Up @@ -85,7 +85,7 @@ internal class AccountService : IAccountService {
) {
val userInfo = response.body()?.data //如果为空就不更新
userInfo?.let {
defaultSp.edit {
defaultSp.edit(commit = true) {
putString(SP_KEY_USER_INFO, mUserInfoEncryption.encrypt(GsonDefault.toJson(userInfo)))
}
this@AccountService.user = userInfo
Expand Down Expand Up @@ -118,21 +118,19 @@ internal class AccountService : IAccountService {

// 发送学号给下游
fun emitStuNum(stuNum: String?) {
val value = Value(
if (stuNum == null || stuNum.isBlank()) null else stuNum
)
val value = stuNum ?: ""
stuNumState.onNext(value)
stuNumEvent.onNext(value)
}

private val stuNumState = BehaviorSubject.create<Value<String>>()
private val stuNumEvent = PublishSubject.create<Value<String>>()
private val stuNumState = BehaviorSubject.create<String>()
private val stuNumEvent = PublishSubject.create<String>()

override fun observeStuNumState(): Observable<Value<String>> {
override fun observeStuNumState(): Observable<String> {
return stuNumState.distinctUntilChanged()
}

override fun observeStuNumEvent(): Observable<Value<String>> {
override fun observeStuNumEvent(): Observable<String> {
return stuNumEvent.distinctUntilChanged()
}
}
Expand Down Expand Up @@ -196,6 +194,8 @@ internal class AccountService : IAccountService {
}
notifyAllStateListeners(state)
}

@WorkerThread
override fun refresh() {
val refreshToken = tokenWrapper?.refreshToken ?: error("refreshToken初始值为空,请尝试重新登录")
val response = ApiGenerator.getCommonApiService(ApiService::class)
Expand All @@ -206,17 +206,17 @@ internal class AccountService : IAccountService {
if (body.status == 20004) {
toast("用户认证刷新失败,请重新登录")
// 直接将 refreshToken 过期时间清零,用户下次打开就会直接跳转至重新登录
defaultSp.edit { putLong(SP_KEY_REFRESH_TOKEN_EXPIRED, 0) }
defaultSp.edit(commit = true) { putLong(SP_KEY_REFRESH_TOKEN_EXPIRED, 0) }
error("用户认证刷新失败,请重新登录!")
}
} else error("用户认证刷新失败,请尝试重新登录\nhttp code = ${response.code()}")
body.data.let { data ->
bind(data)
isTouristMode = false
defaultSp.edit {
defaultSp.edit(commit = true) {
putBoolean(SP_IS_TOURIST, isTouristMode)
}
defaultSp.edit {
defaultSp.edit(commit = true) {
putLong(
SP_KEY_REFRESH_TOKEN_EXPIRED,
System.currentTimeMillis() + SP_REFRESH_DAY
Expand Down Expand Up @@ -288,10 +288,10 @@ internal class AccountService : IAccountService {
if (apiWrapper?.data != null) {
bind(apiWrapper.data)
isTouristMode = false
defaultSp.edit {
defaultSp.edit(commit = true) {
putBoolean(SP_IS_TOURIST, isTouristMode)
}
defaultSp.edit {
defaultSp.edit(commit = true) {
putString(
SP_KEY_USER_V2,
mUserInfoEncryption.encrypt(GsonDefault.toJson(apiWrapper.data))
Expand All @@ -314,7 +314,7 @@ internal class AccountService : IAccountService {
}

override fun logout(context: Context) {
defaultSp.edit {
defaultSp.edit(commit = true) {
putString(SP_KEY_USER_V2, "")
putString(SP_KEY_USER_INFO, "")
putLong(SP_KEY_REFRESH_TOKEN_EXPIRED, 0)
Expand All @@ -330,7 +330,7 @@ internal class AccountService : IAccountService {
//游客模式
override fun loginByTourist() {
isTouristMode = true
defaultSp.edit {
defaultSp.edit(commit = true) {
putBoolean(SP_IS_TOURIST, isTouristMode)
}
notifyAllStateListeners(IUserStateService.UserState.TOURIST)
Expand All @@ -347,13 +347,13 @@ internal class AccountService : IAccountService {
}

override fun refreshTokenExpired() {
defaultSp.edit {
defaultSp.edit(commit = true) {
putLong(SP_KEY_REFRESH_TOKEN_EXPIRED, 0)
}
}

override fun tokenExpired() {
defaultSp.edit {
defaultSp.edit(commit = true) {
putLong(SP_KEY_TOKEN_EXPIRED, 0)
}
}
Expand Down
4 changes: 2 additions & 2 deletions cyxbs-components/base/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ plugins {
id("manager.composeLib")
}

useARouter(false) // lib_base 模块不包含实现类,不需要处理注解
useDataBinding(false) // lib_base 模块只依赖 DataBinding 但不开启 DataBinding
useARouter(false) // base 模块不包含实现类,不需要处理注解
useDataBinding(false) // base 模块只依赖 DataBinding 但不开启 DataBinding

dependencies {
implementation(projects.cyxbsComponents.init)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ import com.cyxbs.components.utils.service.impl
/**
* 如果没有登录则会引导去登录界面
*/
fun BaseUi.doIfLogin(msg: String? = "此功能", next: () -> Unit) {
fun BaseUi.doIfLogin(msg: String? = "此功能", next: (() -> Unit)? = null) {
val verifyService = IAccountService::class.impl.getVerifyService()
if (verifyService.isLogin()) {
next()
next?.invoke()
} else {
verifyService.askLogin(rootView.context, "请先登录才能使用${msg}哦~")
}
Expand Down
Loading

0 comments on commit ed59814

Please sign in to comment.