refactor: 优化分类默认值展示 & 国际化资源 & 移除无用代码
This commit is contained in:
parent
e8ac66c5ae
commit
199bb8bbff
9 changed files with 57 additions and 48 deletions
|
|
@ -35,7 +35,7 @@ android {
|
|||
applicationId = "cn.super12138.todo"
|
||||
minSdk = 24
|
||||
targetSdk = 36
|
||||
versionCode = 742
|
||||
versionCode = 748
|
||||
versionName = "2.1.2"
|
||||
|
||||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
||||
|
|
|
|||
|
|
@ -5,8 +5,8 @@ object Constants {
|
|||
const val GITHUB_REPO = "https://github.com/Super12138/ToDo/"
|
||||
|
||||
const val KEY_TODO_FAB_TRANSITION = "todo_fab"
|
||||
const val KEY_TODO_CONTENT_TRANSITION = "todo_content"
|
||||
const val KEY_TODO_CATEGORY_TRANSITION = "todo_category"
|
||||
// const val KEY_TODO_CONTENT_TRANSITION = "todo_content"
|
||||
// const val KEY_TODO_CATEGORY_TRANSITION = "todo_category"
|
||||
|
||||
const val DB_NAME = "todo"
|
||||
const val DB_TABLE_NAME = "todo"
|
||||
|
|
|
|||
|
|
@ -41,9 +41,9 @@ abstract class TodoDatabase : RoomDatabase() {
|
|||
private val MIGRATION_3_4 = object : Migration(3, 4) {
|
||||
override fun migrate(db: SupportSQLiteDatabase) {
|
||||
// 创建一个新表,其中不含有subject,并且有一个新的category字段(由custom_subject迁移而来)
|
||||
db.execSQL("CREATE TABLE IF NOT EXISTS todo_new (content TEXT NOT NULL, category TEXT NOT NULL DEFAULT 'Default Value', completed INTEGER NOT NULL, priority REAL NOT NULL, id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL)")
|
||||
db.execSQL("CREATE TABLE IF NOT EXISTS todo_new (content TEXT NOT NULL, category TEXT NOT NULL DEFAULT '', completed INTEGER NOT NULL, priority REAL NOT NULL, id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL)")
|
||||
// 将旧表中的数据迁移到新表中
|
||||
db.execSQL("INSERT INTO todo_new (content, category, completed, priority, id) SELECT content, COALESCE(NULLIF(custom_subject, ''), 'Default Value') AS category, completed, priority, id FROM todo")
|
||||
db.execSQL("INSERT INTO todo_new (content, category, completed, priority, id) SELECT content, COALESCE(NULLIF(custom_subject, ''), '') AS category, completed, priority, id FROM todo")
|
||||
// 删除旧表
|
||||
db.execSQL("DROP TABLE todo")
|
||||
// 重命名新表
|
||||
|
|
|
|||
|
|
@ -78,7 +78,7 @@ fun TodoEditorPage(
|
|||
id = index,
|
||||
name = category
|
||||
)
|
||||
} + ChipItem(id = -1, name = "自定义")
|
||||
} + ChipItem(id = -1, name = stringResource(R.string.label_customization))
|
||||
|
||||
var defaultIndex by remember { mutableIntStateOf(-1) }
|
||||
LaunchedEffect(originalCategories, toDo) {
|
||||
|
|
@ -167,14 +167,19 @@ fun TodoEditorPage(
|
|||
.fillMaxSize()
|
||||
) {
|
||||
item {
|
||||
with(sharedTransitionScope) {
|
||||
TodoContentTextField(
|
||||
value = uiState.toDoContent,
|
||||
onValueChange = { uiState.toDoContent = it },
|
||||
isError = uiState.isErrorContent,
|
||||
modifier = Modifier.fillMaxWidth()
|
||||
)
|
||||
}
|
||||
// with(sharedTransitionScope) {
|
||||
TodoContentTextField(
|
||||
value = uiState.toDoContent,
|
||||
onValueChange = { uiState.toDoContent = it },
|
||||
isError = uiState.isErrorContent,
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
/*.sharedBounds(
|
||||
sharedContentState = rememberSharedContentState("${Constants.KEY_TODO_CONTENT_TRANSITION}_${toDo?.id}"),
|
||||
animatedVisibilityScope = animatedVisibilityScope
|
||||
)*/
|
||||
)
|
||||
// }
|
||||
}
|
||||
|
||||
item {
|
||||
|
|
@ -196,14 +201,19 @@ fun TodoEditorPage(
|
|||
enter = fadeIn() + expandVertically(),
|
||||
exit = fadeOut() + shrinkVertically()
|
||||
) {
|
||||
with(sharedTransitionScope) {
|
||||
TodoCategoryTextField(
|
||||
value = uiState.categoryContent,
|
||||
onValueChange = { uiState.categoryContent = it },
|
||||
isError = uiState.isErrorCategory,
|
||||
modifier = Modifier.fillMaxWidth()
|
||||
)
|
||||
}
|
||||
// with(sharedTransitionScope) {
|
||||
TodoCategoryTextField(
|
||||
value = uiState.categoryContent,
|
||||
onValueChange = { uiState.categoryContent = it },
|
||||
isError = uiState.isErrorCategory,
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
/*.sharedBounds(
|
||||
sharedContentState = rememberSharedContentState("${Constants.KEY_TODO_CATEGORY_TRANSITION}_${toDo?.id}"),
|
||||
animatedVisibilityScope = animatedVisibilityScope
|
||||
)*/
|
||||
)
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -160,8 +160,8 @@ fun MainPage(
|
|||
}
|
||||
},
|
||||
selectedTodoIds = selectedTodoIds,
|
||||
sharedTransitionScope = sharedTransitionScope,
|
||||
animatedVisibilityScope = animatedVisibilityScope,
|
||||
// sharedTransitionScope = sharedTransitionScope,
|
||||
// animatedVisibilityScope = animatedVisibilityScope,
|
||||
modifier = Modifier
|
||||
.weight(3f)
|
||||
.fillMaxSize()
|
||||
|
|
@ -203,8 +203,8 @@ fun MainPage(
|
|||
}
|
||||
},
|
||||
selectedTodoIds = selectedTodoIds,
|
||||
sharedTransitionScope = sharedTransitionScope,
|
||||
animatedVisibilityScope = animatedVisibilityScope,
|
||||
// sharedTransitionScope = sharedTransitionScope,
|
||||
// animatedVisibilityScope = animatedVisibilityScope,
|
||||
modifier = Modifier
|
||||
.weight(3f)
|
||||
.fillMaxSize()
|
||||
|
|
|
|||
|
|
@ -1,8 +1,6 @@
|
|||
package cn.super12138.todo.ui.pages.main
|
||||
|
||||
import androidx.compose.animation.AnimatedVisibilityScope
|
||||
import androidx.compose.animation.ExperimentalSharedTransitionApi
|
||||
import androidx.compose.animation.SharedTransitionScope
|
||||
import androidx.compose.foundation.layout.PaddingValues
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
|
|
@ -33,8 +31,8 @@ fun ManagerFragment(
|
|||
onItemLongClick: (TodoEntity) -> Unit = {},
|
||||
onItemChecked: (TodoEntity) -> Unit = {},
|
||||
selectedTodoIds: List<Int>,
|
||||
sharedTransitionScope: SharedTransitionScope,
|
||||
animatedVisibilityScope: AnimatedVisibilityScope
|
||||
// sharedTransitionScope: SharedTransitionScope,
|
||||
// animatedVisibilityScope: AnimatedVisibilityScope
|
||||
) {
|
||||
LazyColumnCustomScrollBar(
|
||||
state = state,
|
||||
|
|
@ -64,7 +62,7 @@ fun ManagerFragment(
|
|||
key = { it.id }
|
||||
) { item ->
|
||||
TodoCard(
|
||||
id = item.id,
|
||||
// id = item.id,
|
||||
content = item.content,
|
||||
category = item.category,
|
||||
completed = item.isCompleted,
|
||||
|
|
@ -73,8 +71,8 @@ fun ManagerFragment(
|
|||
onCardClick = { onItemClick(item) },
|
||||
onCardLongClick = { onItemLongClick(item) },
|
||||
onChecked = { onItemChecked(item) },
|
||||
sharedTransitionScope = sharedTransitionScope,
|
||||
animatedVisibilityScope = animatedVisibilityScope,
|
||||
// sharedTransitionScope = sharedTransitionScope,
|
||||
// animatedVisibilityScope = animatedVisibilityScope,
|
||||
modifier = Modifier
|
||||
.padding(vertical = 5.dp)
|
||||
.animateItem() // TODO: 设置动画时间
|
||||
|
|
|
|||
|
|
@ -1,9 +1,7 @@
|
|||
package cn.super12138.todo.ui.pages.main.components
|
||||
|
||||
import androidx.compose.animation.AnimatedVisibility
|
||||
import androidx.compose.animation.AnimatedVisibilityScope
|
||||
import androidx.compose.animation.ExperimentalSharedTransitionApi
|
||||
import androidx.compose.animation.SharedTransitionScope
|
||||
import androidx.compose.foundation.ExperimentalFoundationApi
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.basicMarquee
|
||||
|
|
@ -38,7 +36,6 @@ import androidx.compose.ui.text.style.TextDecoration
|
|||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.unit.dp
|
||||
import cn.super12138.todo.R
|
||||
import cn.super12138.todo.constants.Constants
|
||||
import cn.super12138.todo.logic.model.Priority
|
||||
import cn.super12138.todo.ui.TodoDefaults
|
||||
import cn.super12138.todo.utils.VibrationUtils
|
||||
|
|
@ -47,7 +44,7 @@ import cn.super12138.todo.utils.VibrationUtils
|
|||
@Composable
|
||||
fun TodoCard(
|
||||
modifier: Modifier = Modifier,
|
||||
id: Int,
|
||||
// id: Int,
|
||||
content: String,
|
||||
category: String,
|
||||
completed: Boolean,
|
||||
|
|
@ -56,8 +53,8 @@ fun TodoCard(
|
|||
onCardClick: () -> Unit = {},
|
||||
onCardLongClick: () -> Unit = {},
|
||||
onChecked: () -> Unit = {},
|
||||
sharedTransitionScope: SharedTransitionScope,
|
||||
animatedVisibilityScope: AnimatedVisibilityScope
|
||||
// sharedTransitionScope: SharedTransitionScope,
|
||||
// animatedVisibilityScope: AnimatedVisibilityScope
|
||||
) {
|
||||
val view = LocalView.current
|
||||
val context = LocalContext.current
|
||||
|
|
@ -122,7 +119,7 @@ fun TodoCard(
|
|||
}
|
||||
}
|
||||
) {
|
||||
with(sharedTransitionScope) {
|
||||
// with(sharedTransitionScope) {
|
||||
Text(
|
||||
text = content,
|
||||
style = MaterialTheme.typography.titleLarge,
|
||||
|
|
@ -130,27 +127,27 @@ fun TodoCard(
|
|||
overflow = TextOverflow.Ellipsis,
|
||||
textDecoration = if (completed) TextDecoration.LineThrough else TextDecoration.None,
|
||||
modifier = Modifier
|
||||
.sharedBounds(
|
||||
/*.sharedBounds(
|
||||
sharedContentState = rememberSharedContentState("${Constants.KEY_TODO_CONTENT_TRANSITION}_$id"),
|
||||
animatedVisibilityScope = animatedVisibilityScope
|
||||
)
|
||||
)*/
|
||||
.basicMarquee() // TODO: 后续评估性能影响
|
||||
)
|
||||
}
|
||||
// }
|
||||
}
|
||||
|
||||
with(sharedTransitionScope) {
|
||||
// with(sharedTransitionScope) {
|
||||
Text(
|
||||
text = category,
|
||||
text = category.ifEmpty { stringResource(R.string.tip_default_category) },
|
||||
style = MaterialTheme.typography.labelMedium,
|
||||
textDecoration = if (completed) TextDecoration.LineThrough else TextDecoration.None,
|
||||
maxLines = 1,
|
||||
modifier = Modifier.sharedBounds(
|
||||
/*modifier = Modifier.sharedBounds(
|
||||
sharedContentState = rememberSharedContentState("${Constants.KEY_TODO_CATEGORY_TRANSITION}_$id"),
|
||||
animatedVisibilityScope = animatedVisibilityScope
|
||||
)
|
||||
)*/
|
||||
)
|
||||
}
|
||||
// }
|
||||
}
|
||||
|
||||
AnimatedVisibility(!selected && !completed) {
|
||||
|
|
|
|||
|
|
@ -110,4 +110,6 @@
|
|||
<!--<string name="error_category_duplicate">该分类已经存在</string>-->
|
||||
<string name="tip_no_category_chip">当前暂无自定义分类,你可以在设置中添加分类</string>
|
||||
<string name="tip_no_category_page">当前暂无自定义分类</string>
|
||||
<string name="tip_default_category">默认分类,请修改</string>
|
||||
<string name="label_customization">自定义</string>
|
||||
</resources>
|
||||
|
|
@ -111,4 +111,6 @@
|
|||
<!--<string name="error_category_duplicate">The category is duplicate</string>-->
|
||||
<string name="tip_no_category_chip">There are currently no custom categories. You can add categories in the settings.</string>
|
||||
<string name="tip_no_category_page">There are no custom categories at the moment.</string>
|
||||
<string name="tip_default_category">Default Category, please modify</string>
|
||||
<string name="label_customization">Customization</string>
|
||||
</resources>
|
||||
Loading…
Reference in a new issue