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"
|
applicationId = "cn.super12138.todo"
|
||||||
minSdk = 24
|
minSdk = 24
|
||||||
targetSdk = 36
|
targetSdk = 36
|
||||||
versionCode = 742
|
versionCode = 748
|
||||||
versionName = "2.1.2"
|
versionName = "2.1.2"
|
||||||
|
|
||||||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
||||||
|
|
|
||||||
|
|
@ -5,8 +5,8 @@ object Constants {
|
||||||
const val GITHUB_REPO = "https://github.com/Super12138/ToDo/"
|
const val GITHUB_REPO = "https://github.com/Super12138/ToDo/"
|
||||||
|
|
||||||
const val KEY_TODO_FAB_TRANSITION = "todo_fab"
|
const val KEY_TODO_FAB_TRANSITION = "todo_fab"
|
||||||
const val KEY_TODO_CONTENT_TRANSITION = "todo_content"
|
// const val KEY_TODO_CONTENT_TRANSITION = "todo_content"
|
||||||
const val KEY_TODO_CATEGORY_TRANSITION = "todo_category"
|
// const val KEY_TODO_CATEGORY_TRANSITION = "todo_category"
|
||||||
|
|
||||||
const val DB_NAME = "todo"
|
const val DB_NAME = "todo"
|
||||||
const val DB_TABLE_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) {
|
private val MIGRATION_3_4 = object : Migration(3, 4) {
|
||||||
override fun migrate(db: SupportSQLiteDatabase) {
|
override fun migrate(db: SupportSQLiteDatabase) {
|
||||||
// 创建一个新表,其中不含有subject,并且有一个新的category字段(由custom_subject迁移而来)
|
// 创建一个新表,其中不含有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")
|
db.execSQL("DROP TABLE todo")
|
||||||
// 重命名新表
|
// 重命名新表
|
||||||
|
|
|
||||||
|
|
@ -78,7 +78,7 @@ fun TodoEditorPage(
|
||||||
id = index,
|
id = index,
|
||||||
name = category
|
name = category
|
||||||
)
|
)
|
||||||
} + ChipItem(id = -1, name = "自定义")
|
} + ChipItem(id = -1, name = stringResource(R.string.label_customization))
|
||||||
|
|
||||||
var defaultIndex by remember { mutableIntStateOf(-1) }
|
var defaultIndex by remember { mutableIntStateOf(-1) }
|
||||||
LaunchedEffect(originalCategories, toDo) {
|
LaunchedEffect(originalCategories, toDo) {
|
||||||
|
|
@ -167,14 +167,19 @@ fun TodoEditorPage(
|
||||||
.fillMaxSize()
|
.fillMaxSize()
|
||||||
) {
|
) {
|
||||||
item {
|
item {
|
||||||
with(sharedTransitionScope) {
|
// with(sharedTransitionScope) {
|
||||||
TodoContentTextField(
|
TodoContentTextField(
|
||||||
value = uiState.toDoContent,
|
value = uiState.toDoContent,
|
||||||
onValueChange = { uiState.toDoContent = it },
|
onValueChange = { uiState.toDoContent = it },
|
||||||
isError = uiState.isErrorContent,
|
isError = uiState.isErrorContent,
|
||||||
modifier = Modifier.fillMaxWidth()
|
modifier = Modifier
|
||||||
)
|
.fillMaxWidth()
|
||||||
}
|
/*.sharedBounds(
|
||||||
|
sharedContentState = rememberSharedContentState("${Constants.KEY_TODO_CONTENT_TRANSITION}_${toDo?.id}"),
|
||||||
|
animatedVisibilityScope = animatedVisibilityScope
|
||||||
|
)*/
|
||||||
|
)
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
item {
|
item {
|
||||||
|
|
@ -196,14 +201,19 @@ fun TodoEditorPage(
|
||||||
enter = fadeIn() + expandVertically(),
|
enter = fadeIn() + expandVertically(),
|
||||||
exit = fadeOut() + shrinkVertically()
|
exit = fadeOut() + shrinkVertically()
|
||||||
) {
|
) {
|
||||||
with(sharedTransitionScope) {
|
// with(sharedTransitionScope) {
|
||||||
TodoCategoryTextField(
|
TodoCategoryTextField(
|
||||||
value = uiState.categoryContent,
|
value = uiState.categoryContent,
|
||||||
onValueChange = { uiState.categoryContent = it },
|
onValueChange = { uiState.categoryContent = it },
|
||||||
isError = uiState.isErrorCategory,
|
isError = uiState.isErrorCategory,
|
||||||
modifier = Modifier.fillMaxWidth()
|
modifier = Modifier
|
||||||
)
|
.fillMaxWidth()
|
||||||
}
|
/*.sharedBounds(
|
||||||
|
sharedContentState = rememberSharedContentState("${Constants.KEY_TODO_CATEGORY_TRANSITION}_${toDo?.id}"),
|
||||||
|
animatedVisibilityScope = animatedVisibilityScope
|
||||||
|
)*/
|
||||||
|
)
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -160,8 +160,8 @@ fun MainPage(
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
selectedTodoIds = selectedTodoIds,
|
selectedTodoIds = selectedTodoIds,
|
||||||
sharedTransitionScope = sharedTransitionScope,
|
// sharedTransitionScope = sharedTransitionScope,
|
||||||
animatedVisibilityScope = animatedVisibilityScope,
|
// animatedVisibilityScope = animatedVisibilityScope,
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.weight(3f)
|
.weight(3f)
|
||||||
.fillMaxSize()
|
.fillMaxSize()
|
||||||
|
|
@ -203,8 +203,8 @@ fun MainPage(
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
selectedTodoIds = selectedTodoIds,
|
selectedTodoIds = selectedTodoIds,
|
||||||
sharedTransitionScope = sharedTransitionScope,
|
// sharedTransitionScope = sharedTransitionScope,
|
||||||
animatedVisibilityScope = animatedVisibilityScope,
|
// animatedVisibilityScope = animatedVisibilityScope,
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.weight(3f)
|
.weight(3f)
|
||||||
.fillMaxSize()
|
.fillMaxSize()
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,6 @@
|
||||||
package cn.super12138.todo.ui.pages.main
|
package cn.super12138.todo.ui.pages.main
|
||||||
|
|
||||||
import androidx.compose.animation.AnimatedVisibilityScope
|
|
||||||
import androidx.compose.animation.ExperimentalSharedTransitionApi
|
import androidx.compose.animation.ExperimentalSharedTransitionApi
|
||||||
import androidx.compose.animation.SharedTransitionScope
|
|
||||||
import androidx.compose.foundation.layout.PaddingValues
|
import androidx.compose.foundation.layout.PaddingValues
|
||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
|
|
@ -33,8 +31,8 @@ fun ManagerFragment(
|
||||||
onItemLongClick: (TodoEntity) -> Unit = {},
|
onItemLongClick: (TodoEntity) -> Unit = {},
|
||||||
onItemChecked: (TodoEntity) -> Unit = {},
|
onItemChecked: (TodoEntity) -> Unit = {},
|
||||||
selectedTodoIds: List<Int>,
|
selectedTodoIds: List<Int>,
|
||||||
sharedTransitionScope: SharedTransitionScope,
|
// sharedTransitionScope: SharedTransitionScope,
|
||||||
animatedVisibilityScope: AnimatedVisibilityScope
|
// animatedVisibilityScope: AnimatedVisibilityScope
|
||||||
) {
|
) {
|
||||||
LazyColumnCustomScrollBar(
|
LazyColumnCustomScrollBar(
|
||||||
state = state,
|
state = state,
|
||||||
|
|
@ -64,7 +62,7 @@ fun ManagerFragment(
|
||||||
key = { it.id }
|
key = { it.id }
|
||||||
) { item ->
|
) { item ->
|
||||||
TodoCard(
|
TodoCard(
|
||||||
id = item.id,
|
// id = item.id,
|
||||||
content = item.content,
|
content = item.content,
|
||||||
category = item.category,
|
category = item.category,
|
||||||
completed = item.isCompleted,
|
completed = item.isCompleted,
|
||||||
|
|
@ -73,8 +71,8 @@ fun ManagerFragment(
|
||||||
onCardClick = { onItemClick(item) },
|
onCardClick = { onItemClick(item) },
|
||||||
onCardLongClick = { onItemLongClick(item) },
|
onCardLongClick = { onItemLongClick(item) },
|
||||||
onChecked = { onItemChecked(item) },
|
onChecked = { onItemChecked(item) },
|
||||||
sharedTransitionScope = sharedTransitionScope,
|
// sharedTransitionScope = sharedTransitionScope,
|
||||||
animatedVisibilityScope = animatedVisibilityScope,
|
// animatedVisibilityScope = animatedVisibilityScope,
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.padding(vertical = 5.dp)
|
.padding(vertical = 5.dp)
|
||||||
.animateItem() // TODO: 设置动画时间
|
.animateItem() // TODO: 设置动画时间
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,7 @@
|
||||||
package cn.super12138.todo.ui.pages.main.components
|
package cn.super12138.todo.ui.pages.main.components
|
||||||
|
|
||||||
import androidx.compose.animation.AnimatedVisibility
|
import androidx.compose.animation.AnimatedVisibility
|
||||||
import androidx.compose.animation.AnimatedVisibilityScope
|
|
||||||
import androidx.compose.animation.ExperimentalSharedTransitionApi
|
import androidx.compose.animation.ExperimentalSharedTransitionApi
|
||||||
import androidx.compose.animation.SharedTransitionScope
|
|
||||||
import androidx.compose.foundation.ExperimentalFoundationApi
|
import androidx.compose.foundation.ExperimentalFoundationApi
|
||||||
import androidx.compose.foundation.background
|
import androidx.compose.foundation.background
|
||||||
import androidx.compose.foundation.basicMarquee
|
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.text.style.TextOverflow
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import cn.super12138.todo.R
|
import cn.super12138.todo.R
|
||||||
import cn.super12138.todo.constants.Constants
|
|
||||||
import cn.super12138.todo.logic.model.Priority
|
import cn.super12138.todo.logic.model.Priority
|
||||||
import cn.super12138.todo.ui.TodoDefaults
|
import cn.super12138.todo.ui.TodoDefaults
|
||||||
import cn.super12138.todo.utils.VibrationUtils
|
import cn.super12138.todo.utils.VibrationUtils
|
||||||
|
|
@ -47,7 +44,7 @@ import cn.super12138.todo.utils.VibrationUtils
|
||||||
@Composable
|
@Composable
|
||||||
fun TodoCard(
|
fun TodoCard(
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
id: Int,
|
// id: Int,
|
||||||
content: String,
|
content: String,
|
||||||
category: String,
|
category: String,
|
||||||
completed: Boolean,
|
completed: Boolean,
|
||||||
|
|
@ -56,8 +53,8 @@ fun TodoCard(
|
||||||
onCardClick: () -> Unit = {},
|
onCardClick: () -> Unit = {},
|
||||||
onCardLongClick: () -> Unit = {},
|
onCardLongClick: () -> Unit = {},
|
||||||
onChecked: () -> Unit = {},
|
onChecked: () -> Unit = {},
|
||||||
sharedTransitionScope: SharedTransitionScope,
|
// sharedTransitionScope: SharedTransitionScope,
|
||||||
animatedVisibilityScope: AnimatedVisibilityScope
|
// animatedVisibilityScope: AnimatedVisibilityScope
|
||||||
) {
|
) {
|
||||||
val view = LocalView.current
|
val view = LocalView.current
|
||||||
val context = LocalContext.current
|
val context = LocalContext.current
|
||||||
|
|
@ -122,7 +119,7 @@ fun TodoCard(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
) {
|
) {
|
||||||
with(sharedTransitionScope) {
|
// with(sharedTransitionScope) {
|
||||||
Text(
|
Text(
|
||||||
text = content,
|
text = content,
|
||||||
style = MaterialTheme.typography.titleLarge,
|
style = MaterialTheme.typography.titleLarge,
|
||||||
|
|
@ -130,27 +127,27 @@ fun TodoCard(
|
||||||
overflow = TextOverflow.Ellipsis,
|
overflow = TextOverflow.Ellipsis,
|
||||||
textDecoration = if (completed) TextDecoration.LineThrough else TextDecoration.None,
|
textDecoration = if (completed) TextDecoration.LineThrough else TextDecoration.None,
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.sharedBounds(
|
/*.sharedBounds(
|
||||||
sharedContentState = rememberSharedContentState("${Constants.KEY_TODO_CONTENT_TRANSITION}_$id"),
|
sharedContentState = rememberSharedContentState("${Constants.KEY_TODO_CONTENT_TRANSITION}_$id"),
|
||||||
animatedVisibilityScope = animatedVisibilityScope
|
animatedVisibilityScope = animatedVisibilityScope
|
||||||
)
|
)*/
|
||||||
.basicMarquee() // TODO: 后续评估性能影响
|
.basicMarquee() // TODO: 后续评估性能影响
|
||||||
)
|
)
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
with(sharedTransitionScope) {
|
// with(sharedTransitionScope) {
|
||||||
Text(
|
Text(
|
||||||
text = category,
|
text = category.ifEmpty { stringResource(R.string.tip_default_category) },
|
||||||
style = MaterialTheme.typography.labelMedium,
|
style = MaterialTheme.typography.labelMedium,
|
||||||
textDecoration = if (completed) TextDecoration.LineThrough else TextDecoration.None,
|
textDecoration = if (completed) TextDecoration.LineThrough else TextDecoration.None,
|
||||||
maxLines = 1,
|
maxLines = 1,
|
||||||
modifier = Modifier.sharedBounds(
|
/*modifier = Modifier.sharedBounds(
|
||||||
sharedContentState = rememberSharedContentState("${Constants.KEY_TODO_CATEGORY_TRANSITION}_$id"),
|
sharedContentState = rememberSharedContentState("${Constants.KEY_TODO_CATEGORY_TRANSITION}_$id"),
|
||||||
animatedVisibilityScope = animatedVisibilityScope
|
animatedVisibilityScope = animatedVisibilityScope
|
||||||
)
|
)*/
|
||||||
)
|
)
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
AnimatedVisibility(!selected && !completed) {
|
AnimatedVisibility(!selected && !completed) {
|
||||||
|
|
|
||||||
|
|
@ -110,4 +110,6 @@
|
||||||
<!--<string name="error_category_duplicate">该分类已经存在</string>-->
|
<!--<string name="error_category_duplicate">该分类已经存在</string>-->
|
||||||
<string name="tip_no_category_chip">当前暂无自定义分类,你可以在设置中添加分类</string>
|
<string name="tip_no_category_chip">当前暂无自定义分类,你可以在设置中添加分类</string>
|
||||||
<string name="tip_no_category_page">当前暂无自定义分类</string>
|
<string name="tip_no_category_page">当前暂无自定义分类</string>
|
||||||
|
<string name="tip_default_category">默认分类,请修改</string>
|
||||||
|
<string name="label_customization">自定义</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
@ -111,4 +111,6 @@
|
||||||
<!--<string name="error_category_duplicate">The category is duplicate</string>-->
|
<!--<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_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_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>
|
</resources>
|
||||||
Loading…
Reference in a new issue