Start implement splash UI
This commit is contained in:
57
feature/splash/build.gradle.kts
Normal file
57
feature/splash/build.gradle.kts
Normal file
@@ -0,0 +1,57 @@
|
||||
plugins {
|
||||
alias(libs.plugins.android.library)
|
||||
alias(libs.plugins.kotlin.android)
|
||||
|
||||
alias(libs.plugins.kotlin.kapt)
|
||||
alias(libs.plugins.hilt)
|
||||
}
|
||||
|
||||
android {
|
||||
namespace = "ru.fincode.tsudesk.feature.splash"
|
||||
buildFeatures { compose = true }
|
||||
|
||||
compileSdk = libs.versions.compileSdk.get().toInt()
|
||||
defaultConfig {
|
||||
minSdk = libs.versions.minSdk.get().toInt()
|
||||
consumerProguardFiles("consumer-rules.pro")
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
release {
|
||||
isMinifyEnabled = false
|
||||
proguardFiles(
|
||||
getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro"
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
val jvm = JavaVersion.toVersion(libs.versions.jvmTarget.get())
|
||||
compileOptions {
|
||||
sourceCompatibility = jvm
|
||||
targetCompatibility = jvm
|
||||
}
|
||||
kotlinOptions {
|
||||
jvmTarget = jvm.toString()
|
||||
}
|
||||
}
|
||||
kapt {
|
||||
correctErrorTypes = true
|
||||
}
|
||||
dependencies {
|
||||
implementation(libs.androidx.appcompat)
|
||||
implementation(libs.material)
|
||||
|
||||
implementation(platform(libs.compose.bom))
|
||||
implementation(libs.compose.ui)
|
||||
implementation(libs.compose.foundation)
|
||||
implementation(libs.compose.material3)
|
||||
|
||||
kapt(libs.hilt.compiler)
|
||||
implementation(libs.hilt.android)
|
||||
implementation(libs.hilt.navigation.compose)
|
||||
|
||||
implementation(project(":core:network"))
|
||||
implementation(project(":core:common"))
|
||||
implementation(project(":core:config"))
|
||||
implementation(project(":core:ui"))
|
||||
}
|
||||
0
feature/splash/consumer-rules.pro
Normal file
0
feature/splash/consumer-rules.pro
Normal file
21
feature/splash/proguard-rules.pro
vendored
Normal file
21
feature/splash/proguard-rules.pro
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
# Add project specific ProGuard rules here.
|
||||
# You can control the set of applied configuration files using the
|
||||
# proguardFiles setting in build.gradle.
|
||||
#
|
||||
# For more details, see
|
||||
# http://developer.android.com/guide/developing/tools/proguard.html
|
||||
|
||||
# If your project uses WebView with JS, uncomment the following
|
||||
# and specify the fully qualified class name to the JavaScript interface
|
||||
# class:
|
||||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
|
||||
# public *;
|
||||
#}
|
||||
|
||||
# Uncomment this to preserve the line number information for
|
||||
# debugging stack traces.
|
||||
#-keepattributes SourceFile,LineNumberTable
|
||||
|
||||
# If you keep the line number information, uncomment this to
|
||||
# hide the original source file name.
|
||||
#-renamesourcefileattribute SourceFile
|
||||
@@ -0,0 +1,24 @@
|
||||
package ru.fincode.tsudesk.feature.splash
|
||||
|
||||
import androidx.test.platform.app.InstrumentationRegistry
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
|
||||
import org.junit.Assert.*
|
||||
|
||||
/**
|
||||
* Instrumented test, which will execute on an Android device.
|
||||
*
|
||||
* See [testing documentation](http://d.android.com/tools/testing).
|
||||
*/
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
class ExampleInstrumentedTest {
|
||||
@Test
|
||||
fun useAppContext() {
|
||||
// Context of the app under test.
|
||||
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
|
||||
assertEquals("ru.fincode.tsudesk.feature.splash.test", appContext.packageName)
|
||||
}
|
||||
}
|
||||
4
feature/splash/src/main/AndroidManifest.xml
Normal file
4
feature/splash/src/main/AndroidManifest.xml
Normal file
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
</manifest>
|
||||
@@ -0,0 +1,5 @@
|
||||
package ru.fincode.tsudesk.feature.splash.ui
|
||||
|
||||
sealed interface SplashEffect {
|
||||
data object OpenMain : SplashEffect
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package ru.fincode.tsudesk.feature.splash.ui
|
||||
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.hilt.navigation.compose.hiltViewModel
|
||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
|
||||
@Composable
|
||||
fun SplashRoute(
|
||||
onOpenMain: () -> Unit, vm: SplashViewModel = hiltViewModel()
|
||||
) {
|
||||
val state = vm.state.collectAsStateWithLifecycle().value
|
||||
SplashScreen(state)
|
||||
LaunchedEffect(vm) {
|
||||
vm.effects.collect { effect ->
|
||||
when (effect) {
|
||||
SplashEffect.OpenMain -> onOpenMain()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package ru.fincode.tsudesk.feature.splash.ui
|
||||
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.material3.CircularProgressIndicator
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.unit.dp
|
||||
|
||||
@Composable
|
||||
fun SplashScreen(state: SplashUiState) {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.background(Color.Black),
|
||||
contentAlignment = Alignment.Center
|
||||
) {
|
||||
Column(horizontalAlignment = Alignment.CenterHorizontally) {
|
||||
if (state.isLoading) {
|
||||
Spacer(Modifier.height(16.dp))
|
||||
CircularProgressIndicator()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package ru.fincode.tsudesk.feature.splash.ui
|
||||
|
||||
data class SplashUiState(
|
||||
val isLoading: Boolean = true,
|
||||
val errorMessage: String? = null
|
||||
)
|
||||
@@ -0,0 +1,44 @@
|
||||
package ru.fincode.tsudesk.feature.splash.ui
|
||||
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import kotlinx.coroutines.flow.MutableSharedFlow
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.SharedFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.launch
|
||||
import ru.fincode.tsudesk.core.common.model.DataResult
|
||||
import ru.fincode.tsudesk.core.config.domain.usecase.GetConfigUseCase
|
||||
import javax.inject.Inject
|
||||
|
||||
@HiltViewModel
|
||||
class SplashViewModel @Inject constructor(
|
||||
private val getConfigUseCase: GetConfigUseCase
|
||||
) : ViewModel() {
|
||||
|
||||
private val _state = MutableStateFlow(SplashUiState(isLoading = true))
|
||||
val state: StateFlow<SplashUiState> = _state
|
||||
|
||||
private val _effects = MutableSharedFlow<SplashEffect>(extraBufferCapacity = 1)
|
||||
val effects: SharedFlow<SplashEffect> = _effects
|
||||
|
||||
init {
|
||||
viewModelScope.launch {
|
||||
when (val result = getConfigUseCase()) {
|
||||
is DataResult.Data -> {
|
||||
_state.value = SplashUiState(isLoading = false)
|
||||
_effects.tryEmit(SplashEffect.OpenMain)
|
||||
}
|
||||
|
||||
is DataResult.Error -> {
|
||||
_state.value = SplashUiState(
|
||||
isLoading = false,
|
||||
errorMessage = result.error.toString()
|
||||
)
|
||||
_effects.tryEmit(SplashEffect.OpenMain)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package ru.fincode.tsudesk.feature.splash
|
||||
|
||||
import org.junit.Test
|
||||
|
||||
import org.junit.Assert.*
|
||||
|
||||
/**
|
||||
* Example local unit test, which will execute on the development machine (host).
|
||||
*
|
||||
* See [testing documentation](http://d.android.com/tools/testing).
|
||||
*/
|
||||
class ExampleUnitTest {
|
||||
@Test
|
||||
fun addition_isCorrect() {
|
||||
assertEquals(4, 2 + 2)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user