-
Notifications
You must be signed in to change notification settings - Fork 245
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
236 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package luyao.wanandroid | ||
|
||
import android.app.Application | ||
import androidx.appcompat.app.AppCompatDelegate | ||
import dagger.hilt.android.HiltAndroidApp | ||
import luyao.ktx.app.AppInit | ||
import luyao.wanandroid.model.MMKVConstants | ||
import javax.inject.Inject | ||
|
||
@HiltAndroidApp | ||
class WanApplication : Application() { | ||
|
||
companion object { | ||
lateinit var App: Application | ||
} | ||
|
||
override fun onCreate() { | ||
super.onCreate() | ||
App = this | ||
AppInit.init(this) | ||
AppCompatDelegate.setDefaultNightMode(MMKVConstants.nightMode) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package luyao.wanandroid.model | ||
|
||
/** | ||
* Description: | ||
* Author: luyao | ||
* Date: 2023/11/15 13:37 | ||
*/ | ||
data class AppConfig( | ||
val darkThemeConfig: DarkThemeConfig | ||
) |
10 changes: 10 additions & 0 deletions
10
app/src/main/java/luyao/wanandroid/model/DarkThemeConfig.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package luyao.wanandroid.model | ||
|
||
/** | ||
* Description: | ||
* Author: luyao | ||
* Date: 2023/11/15 13:37 | ||
*/ | ||
enum class DarkThemeConfig { | ||
FOLLOW_SYSTEM, LIGHT, DARK | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package luyao.wanandroid.model | ||
|
||
import androidx.appcompat.app.AppCompatDelegate | ||
import luyao.ktx.util.MMKVDelegate | ||
|
||
/** | ||
* Description: | ||
* Author: luyao | ||
* Date: 2023/11/15 11:08 | ||
*/ | ||
|
||
object MMKVConstants { | ||
|
||
var nightMode by MMKVDelegate("night_mode", AppCompatDelegate.MODE_NIGHT_NO) // 夜间模式 | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package luyao.wanandroid.ui | ||
|
||
import androidx.compose.foundation.background | ||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.tooling.preview.Preview | ||
import com.airbnb.lottie.compose.LottieAnimation | ||
import com.airbnb.lottie.compose.LottieCompositionSpec | ||
import com.airbnb.lottie.compose.animateLottieCompositionAsState | ||
import com.airbnb.lottie.compose.rememberLottieComposition | ||
import luyao.wanandroid.R | ||
|
||
/** | ||
* Description: | ||
* Author: luyao | ||
* Date: 2023/11/15 13:24 | ||
*/ | ||
@Composable | ||
fun SplashPage(onFinish: () -> Unit) { | ||
Box( | ||
modifier = Modifier | ||
.fillMaxSize() | ||
.background(Color.White) | ||
) { | ||
val composition by rememberLottieComposition(spec = LottieCompositionSpec.RawRes(R.raw.android_logo)) | ||
val animationState = animateLottieCompositionAsState(composition = composition) | ||
LottieAnimation(composition = composition, progress = { animationState.progress }) | ||
if (animationState.isAtEnd && animationState.isPlaying) { | ||
onFinish() | ||
} | ||
} | ||
} | ||
|
||
@Preview | ||
@Composable | ||
fun SplashPagePreview() { | ||
SplashPage {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package luyao.wanandroid.vm | ||
|
||
import androidx.appcompat.app.AppCompatDelegate | ||
import androidx.lifecycle.viewModelScope | ||
import kotlinx.coroutines.flow.SharingStarted | ||
import kotlinx.coroutines.flow.StateFlow | ||
import kotlinx.coroutines.flow.flow | ||
import kotlinx.coroutines.flow.stateIn | ||
import luyao.ktx.base.BaseVM | ||
import luyao.ktx.model.UiState | ||
import luyao.wanandroid.model.AppConfig | ||
import luyao.wanandroid.model.DarkThemeConfig | ||
import luyao.wanandroid.model.MMKVConstants | ||
|
||
/** | ||
* Description: | ||
* Author: luyao | ||
* Date: 2023/11/15 13:35 | ||
*/ | ||
class SplashVM : BaseVM() { | ||
|
||
val appState: StateFlow<UiState<AppConfig>> = flow<UiState<AppConfig>> { | ||
val config = AppConfig(getDarkThemeConfig()) | ||
emit(UiState.Success(config)) | ||
}.stateIn( | ||
scope = viewModelScope, | ||
initialValue = UiState.Loading, | ||
started = SharingStarted.WhileSubscribed(5000) | ||
) | ||
|
||
|
||
private fun getDarkThemeConfig() = | ||
when (MMKVConstants.nightMode) { | ||
AppCompatDelegate.MODE_NIGHT_NO -> DarkThemeConfig.LIGHT | ||
AppCompatDelegate.MODE_NIGHT_YES -> DarkThemeConfig.DARK | ||
AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM -> DarkThemeConfig.FOLLOW_SYSTEM | ||
else -> DarkThemeConfig.FOLLOW_SYSTEM | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package luyao.wanandroid.vm | ||
|
||
import luyao.ktx.base.BaseVM | ||
|
||
/** | ||
* Description: | ||
* Author: luyao | ||
* Date: 2023/11/15 11:14 | ||
*/ | ||
class WanVM : BaseVM() { | ||
|
||
|
||
} |
Oops, something went wrong.