更新
This commit is contained in:
@@ -8,6 +8,7 @@ import com.taskttl.data.viewmodel.CategoryViewModel
|
||||
import com.taskttl.data.viewmodel.CountdownViewModel
|
||||
import com.taskttl.data.viewmodel.FeedbackViewModel
|
||||
import com.taskttl.data.viewmodel.OnboardingViewModel
|
||||
import com.taskttl.data.viewmodel.SettingsViewModel
|
||||
import com.taskttl.data.viewmodel.SplashViewModel
|
||||
import com.taskttl.data.viewmodel.TaskViewModel
|
||||
import org.koin.core.KoinApplication
|
||||
@@ -44,5 +45,6 @@ val viewModelModule = module {
|
||||
viewModelOf(::TaskViewModel)
|
||||
viewModelOf(::CategoryViewModel)
|
||||
viewModelOf(::CountdownViewModel)
|
||||
viewModelOf(::SettingsViewModel)
|
||||
viewModelOf(::FeedbackViewModel)
|
||||
}
|
||||
@@ -3,18 +3,28 @@ package com.taskttl.data.repository.impl
|
||||
import com.taskttl.data.local.dao.CategoryDao
|
||||
import com.taskttl.data.local.dao.CountdownDao
|
||||
import com.taskttl.data.local.dao.TaskDao
|
||||
import com.taskttl.data.mapper.CategoryMapper
|
||||
import com.taskttl.data.local.model.Category
|
||||
import com.taskttl.data.local.model.CategoryColor
|
||||
import com.taskttl.data.local.model.CategoryIcon
|
||||
import com.taskttl.data.local.model.CategoryStatistics
|
||||
import com.taskttl.data.local.model.CategoryType
|
||||
import com.taskttl.data.mapper.CategoryMapper
|
||||
import com.taskttl.data.repository.CategoryRepository
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.combine
|
||||
import kotlinx.coroutines.flow.map
|
||||
import kotlinx.datetime.TimeZone
|
||||
import kotlinx.datetime.toLocalDateTime
|
||||
import org.jetbrains.compose.resources.getString
|
||||
import taskttl.composeapp.generated.resources.Res
|
||||
import taskttl.composeapp.generated.resources.category_birthday
|
||||
import taskttl.composeapp.generated.resources.category_book
|
||||
import taskttl.composeapp.generated.resources.category_briefcase
|
||||
import taskttl.composeapp.generated.resources.category_exam
|
||||
import taskttl.composeapp.generated.resources.category_festival
|
||||
import taskttl.composeapp.generated.resources.category_goal
|
||||
import taskttl.composeapp.generated.resources.category_heart
|
||||
import taskttl.composeapp.generated.resources.category_home
|
||||
import kotlin.time.Clock
|
||||
import kotlin.time.ExperimentalTime
|
||||
import kotlin.uuid.ExperimentalUuidApi
|
||||
@@ -123,7 +133,7 @@ class CategoryRepositoryImpl(
|
||||
val defaultTaskCategories = listOf(
|
||||
Category(
|
||||
id = Uuid.random().toString(),
|
||||
name = "工作",
|
||||
name = getString(Res.string.category_briefcase),
|
||||
color = CategoryColor.BLUE,
|
||||
icon = CategoryIcon.BRIEFCASE,
|
||||
type = CategoryType.TASK,
|
||||
@@ -132,7 +142,7 @@ class CategoryRepositoryImpl(
|
||||
),
|
||||
Category(
|
||||
id = Uuid.random().toString(),
|
||||
name = "生活",
|
||||
name = getString(Res.string.category_home),
|
||||
color = CategoryColor.GREEN,
|
||||
icon = CategoryIcon.HOME,
|
||||
type = CategoryType.TASK,
|
||||
@@ -141,7 +151,7 @@ class CategoryRepositoryImpl(
|
||||
),
|
||||
Category(
|
||||
id = Uuid.random().toString(),
|
||||
name = "健康",
|
||||
name = getString(Res.string.category_heart),
|
||||
color = CategoryColor.ORANGE,
|
||||
icon = CategoryIcon.HEART,
|
||||
type = CategoryType.TASK,
|
||||
@@ -150,7 +160,7 @@ class CategoryRepositoryImpl(
|
||||
),
|
||||
Category(
|
||||
id = Uuid.random().toString(),
|
||||
name = "学习",
|
||||
name = getString(Res.string.category_book),
|
||||
color = CategoryColor.PURPLE,
|
||||
icon = CategoryIcon.BOOK,
|
||||
type = CategoryType.TASK,
|
||||
@@ -163,7 +173,7 @@ class CategoryRepositoryImpl(
|
||||
val defaultCountdownCategories = listOf(
|
||||
Category(
|
||||
id = Uuid.random().toString(),
|
||||
name = "生日",
|
||||
name = getString(Res.string.category_birthday),
|
||||
color = CategoryColor.PINK,
|
||||
icon = CategoryIcon.BIRTHDAY,
|
||||
type = CategoryType.COUNTDOWN,
|
||||
@@ -172,7 +182,7 @@ class CategoryRepositoryImpl(
|
||||
),
|
||||
Category(
|
||||
id = Uuid.random().toString(),
|
||||
name = "节日",
|
||||
name = getString(Res.string.category_festival),
|
||||
color = CategoryColor.CYAN,
|
||||
icon = CategoryIcon.FESTIVAL,
|
||||
type = CategoryType.COUNTDOWN,
|
||||
@@ -181,7 +191,7 @@ class CategoryRepositoryImpl(
|
||||
),
|
||||
Category(
|
||||
id = Uuid.random().toString(),
|
||||
name = "目标",
|
||||
name = getString(Res.string.category_goal),
|
||||
color = CategoryColor.YELLOW,
|
||||
icon = CategoryIcon.GOAL,
|
||||
type = CategoryType.COUNTDOWN,
|
||||
@@ -190,7 +200,7 @@ class CategoryRepositoryImpl(
|
||||
),
|
||||
Category(
|
||||
id = Uuid.random().toString(),
|
||||
name = "考试",
|
||||
name = getString(Res.string.category_exam),
|
||||
color = CategoryColor.GREEN,
|
||||
icon = CategoryIcon.EXAM,
|
||||
type = CategoryType.COUNTDOWN,
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
package com.taskttl.data.state
|
||||
|
||||
/**
|
||||
* 设置状态
|
||||
* @author DevTTL
|
||||
* @date 2025/10/14
|
||||
* @constructor 创建[SettingsState]
|
||||
* @param [isLoading] 正在加载
|
||||
* @param [error] 错误
|
||||
*/
|
||||
data class SettingsState(
|
||||
val isLoading: Boolean = false,
|
||||
val error: String? = null,
|
||||
)
|
||||
|
||||
/**
|
||||
* 设置意图
|
||||
* @author DevTTL
|
||||
* @date 2025/10/14
|
||||
* @constructor 创建[SettingsIntent]
|
||||
*/
|
||||
sealed class SettingsIntent {
|
||||
/**
|
||||
* 打开应用评分
|
||||
* @author DevTTL
|
||||
* @date 2025/10/14
|
||||
*/
|
||||
object OpenAppRating: SettingsIntent()
|
||||
|
||||
/**
|
||||
* 打开网址
|
||||
* @author DevTTL
|
||||
* @date 2025/10/14
|
||||
* @constructor 创建[OpenUrl]
|
||||
* @param [url] 网址
|
||||
*/
|
||||
class OpenUrl(val url:String): SettingsIntent()
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 设置效果
|
||||
* @author DevTTL
|
||||
* @date 2025/10/14
|
||||
* @constructor 创建[SettingsEffect]
|
||||
*/
|
||||
sealed class SettingsEffect {
|
||||
/**
|
||||
* 导航返回
|
||||
* @author admin
|
||||
* @date 2025/10/12
|
||||
*/
|
||||
object NavigateBack : SettingsEffect()
|
||||
|
||||
/**
|
||||
* 显示消息
|
||||
* @author admin
|
||||
* @date 2025/10/12
|
||||
* @constructor 创建[ShowMessage]
|
||||
* @param [message] 消息
|
||||
*/
|
||||
data class ShowMessage(val message: String) : SettingsEffect()
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package com.taskttl.data.viewmodel
|
||||
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.taskttl.core.utils.ExternalAppLauncher
|
||||
import com.taskttl.data.state.SettingsEffect
|
||||
import com.taskttl.data.state.SettingsIntent
|
||||
import com.taskttl.data.state.SettingsState
|
||||
import kotlinx.coroutines.flow.MutableSharedFlow
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.SharedFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.asSharedFlow
|
||||
import kotlinx.coroutines.flow.asStateFlow
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
/**
|
||||
* 反馈视图模型
|
||||
* @author admin
|
||||
* @date 2025/10/12
|
||||
* @constructor 创建[SettingsViewModel]
|
||||
*/
|
||||
class SettingsViewModel() : ViewModel() {
|
||||
|
||||
private val _state = MutableStateFlow(SettingsState())
|
||||
val state: StateFlow<SettingsState> = _state.asStateFlow()
|
||||
|
||||
private val _effects = MutableSharedFlow<SettingsEffect>()
|
||||
val effects: SharedFlow<SettingsEffect> = _effects.asSharedFlow()
|
||||
|
||||
|
||||
fun handleIntent(intent: SettingsIntent) {
|
||||
when (intent) {
|
||||
is SettingsIntent.OpenAppRating -> openAppRating()
|
||||
is SettingsIntent.OpenUrl -> openUrl(intent.url)
|
||||
}
|
||||
}
|
||||
|
||||
private fun openAppRating() {
|
||||
viewModelScope.launch {
|
||||
ExternalAppLauncher.openAppRating()
|
||||
}
|
||||
}
|
||||
|
||||
private fun openUrl(url:String) {
|
||||
viewModelScope.launch {
|
||||
ExternalAppLauncher.openUrl(url)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 清除错误
|
||||
*/
|
||||
private fun clearError() {
|
||||
_state.value = _state.value.copy(error = null)
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user