feat: 引入共享会话状态与未登录占位组件
This commit is contained in:
@@ -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.FakeHomeRepository
|
||||||
import com.mingyuan.android_client.core.data.repository.FakePlanRepository
|
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.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.CheckinRepository
|
||||||
import com.mingyuan.android_client.core.domain.repository.HomeRepository
|
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.PlanRepository
|
||||||
import com.mingyuan.android_client.core.domain.repository.ProfileRepository
|
import com.mingyuan.android_client.core.domain.repository.ProfileRepository
|
||||||
|
import com.mingyuan.android_client.core.domain.repository.SessionRepository
|
||||||
import dagger.Binds
|
import dagger.Binds
|
||||||
import dagger.Module
|
import dagger.Module
|
||||||
import dagger.hilt.InstallIn
|
import dagger.hilt.InstallIn
|
||||||
@@ -33,4 +35,8 @@ abstract class DataModule {
|
|||||||
@Binds
|
@Binds
|
||||||
@Singleton
|
@Singleton
|
||||||
abstract fun bindProfileRepository(impl: FakeProfileRepository): ProfileRepository
|
abstract fun bindProfileRepository(impl: FakeProfileRepository): ProfileRepository
|
||||||
|
|
||||||
|
@Binds
|
||||||
|
@Singleton
|
||||||
|
abstract fun bindSessionRepository(impl: FakeSessionRepository): SessionRepository
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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<Boolean> = _isLoggedIn
|
||||||
|
|
||||||
|
override suspend fun login() {
|
||||||
|
delay(300)
|
||||||
|
_isLoggedIn.value = true
|
||||||
|
}
|
||||||
|
|
||||||
|
override suspend fun logout() {
|
||||||
|
delay(300)
|
||||||
|
_isLoggedIn.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,9 +1,11 @@
|
|||||||
package com.mingyuan.android_client.core.designsystem.component
|
package com.mingyuan.android_client.core.designsystem.component
|
||||||
|
|
||||||
import androidx.compose.foundation.background
|
import androidx.compose.foundation.background
|
||||||
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
import androidx.compose.foundation.layout.Box
|
import androidx.compose.foundation.layout.Box
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
import androidx.compose.foundation.layout.Spacer
|
import androidx.compose.foundation.layout.Spacer
|
||||||
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
import androidx.compose.foundation.layout.height
|
import androidx.compose.foundation.layout.height
|
||||||
import androidx.compose.foundation.layout.padding
|
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.FaintText
|
||||||
import com.mingyuan.android_client.core.designsystem.theme.MutedText
|
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.NeutralChip
|
||||||
|
import com.mingyuan.android_client.core.designsystem.theme.PrimaryText
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun EmptyState(
|
fun EmptyState(
|
||||||
@@ -65,3 +68,30 @@ fun ErrorState(
|
|||||||
MingyuanButton(text = "重新加载", onClick = onRetry)
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
package com.mingyuan.android_client.core.domain.repository
|
||||||
|
|
||||||
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
|
||||||
|
interface SessionRepository {
|
||||||
|
val isLoggedIn: Flow<Boolean>
|
||||||
|
|
||||||
|
suspend fun login()
|
||||||
|
|
||||||
|
suspend fun logout()
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user