diff --git a/core/data/src/main/kotlin/com/mingyuan/android_client/core/data/di/DataModule.kt b/core/data/src/main/kotlin/com/mingyuan/android_client/core/data/di/DataModule.kt index 319a5bc..7e8b81f 100644 --- a/core/data/src/main/kotlin/com/mingyuan/android_client/core/data/di/DataModule.kt +++ b/core/data/src/main/kotlin/com/mingyuan/android_client/core/data/di/DataModule.kt @@ -4,10 +4,12 @@ import com.mingyuan.android_client.core.data.repository.FakeCheckinRepository import com.mingyuan.android_client.core.data.repository.FakeHomeRepository import com.mingyuan.android_client.core.data.repository.FakePlanRepository import com.mingyuan.android_client.core.data.repository.FakeProfileRepository +import com.mingyuan.android_client.core.data.repository.FakeSessionRepository import com.mingyuan.android_client.core.domain.repository.CheckinRepository import com.mingyuan.android_client.core.domain.repository.HomeRepository import com.mingyuan.android_client.core.domain.repository.PlanRepository import com.mingyuan.android_client.core.domain.repository.ProfileRepository +import com.mingyuan.android_client.core.domain.repository.SessionRepository import dagger.Binds import dagger.Module import dagger.hilt.InstallIn @@ -33,4 +35,8 @@ abstract class DataModule { @Binds @Singleton abstract fun bindProfileRepository(impl: FakeProfileRepository): ProfileRepository + + @Binds + @Singleton + abstract fun bindSessionRepository(impl: FakeSessionRepository): SessionRepository } diff --git a/core/data/src/main/kotlin/com/mingyuan/android_client/core/data/repository/FakeSessionRepository.kt b/core/data/src/main/kotlin/com/mingyuan/android_client/core/data/repository/FakeSessionRepository.kt new file mode 100644 index 0000000..61fc6da --- /dev/null +++ b/core/data/src/main/kotlin/com/mingyuan/android_client/core/data/repository/FakeSessionRepository.kt @@ -0,0 +1,25 @@ +package com.mingyuan.android_client.core.data.repository + +import com.mingyuan.android_client.core.domain.repository.SessionRepository +import kotlinx.coroutines.delay +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.MutableStateFlow +import javax.inject.Inject +import javax.inject.Singleton + +@Singleton +class FakeSessionRepository @Inject constructor() : SessionRepository { + + private val _isLoggedIn = MutableStateFlow(true) + override val isLoggedIn: Flow = _isLoggedIn + + override suspend fun login() { + delay(300) + _isLoggedIn.value = true + } + + override suspend fun logout() { + delay(300) + _isLoggedIn.value = false + } +} diff --git a/core/designsystem/src/main/kotlin/com/mingyuan/android_client/core/designsystem/component/StateViews.kt b/core/designsystem/src/main/kotlin/com/mingyuan/android_client/core/designsystem/component/StateViews.kt index 227966b..e837e88 100644 --- a/core/designsystem/src/main/kotlin/com/mingyuan/android_client/core/designsystem/component/StateViews.kt +++ b/core/designsystem/src/main/kotlin/com/mingyuan/android_client/core/designsystem/component/StateViews.kt @@ -1,9 +1,11 @@ package com.mingyuan.android_client.core.designsystem.component import androidx.compose.foundation.background +import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Spacer +import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding @@ -21,6 +23,7 @@ import com.mingyuan.android_client.core.designsystem.theme.ErrorBackground import com.mingyuan.android_client.core.designsystem.theme.FaintText import com.mingyuan.android_client.core.designsystem.theme.MutedText import com.mingyuan.android_client.core.designsystem.theme.NeutralChip +import com.mingyuan.android_client.core.designsystem.theme.PrimaryText @Composable fun EmptyState( @@ -65,3 +68,30 @@ fun ErrorState( MingyuanButton(text = "重新加载", onClick = onRetry) } } + +@Composable +fun LoggedOutState( + onLogin: (() -> Unit)? = null, + modifier: Modifier = Modifier, +) { + Column( + modifier = modifier.fillMaxSize(), + verticalArrangement = Arrangement.Center, + horizontalAlignment = Alignment.CenterHorizontally, + ) { + Box( + modifier = Modifier.size(72.dp).background(NeutralChip, CircleShape), + contentAlignment = Alignment.Center, + ) { + Text("🔒", fontSize = 32.sp) + } + Spacer(Modifier.height(12.dp)) + Text("未登录", color = PrimaryText, fontSize = 15.sp, fontWeight = FontWeight.SemiBold) + Spacer(Modifier.height(4.dp)) + Text("登录后即可查看", color = FaintText, fontSize = 13.sp) + if (onLogin != null) { + Spacer(Modifier.height(16.dp)) + MingyuanButton(text = "登录", onClick = onLogin) + } + } +} diff --git a/core/domain/src/main/kotlin/com/mingyuan/android_client/core/domain/repository/SessionRepository.kt b/core/domain/src/main/kotlin/com/mingyuan/android_client/core/domain/repository/SessionRepository.kt new file mode 100644 index 0000000..6a56a86 --- /dev/null +++ b/core/domain/src/main/kotlin/com/mingyuan/android_client/core/domain/repository/SessionRepository.kt @@ -0,0 +1,11 @@ +package com.mingyuan.android_client.core.domain.repository + +import kotlinx.coroutines.flow.Flow + +interface SessionRepository { + val isLoggedIn: Flow + + suspend fun login() + + suspend fun logout() +}