Add new settings and add animation of list
This commit is contained in:
parent
c61255f1ad
commit
8f88809e5f
12 changed files with 138 additions and 12 deletions
52
app/schemas/cn.super12138.todo.logic.dao.ToDoRoomDB/1.json
Normal file
52
app/schemas/cn.super12138.todo.logic.dao.ToDoRoomDB/1.json
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
{
|
||||
"formatVersion": 1,
|
||||
"database": {
|
||||
"version": 1,
|
||||
"identityHash": "bf23f9a3f857e7cfe28dce9eb1657534",
|
||||
"entities": [
|
||||
{
|
||||
"tableName": "todo",
|
||||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`uuid` TEXT NOT NULL, `state` INTEGER NOT NULL, `subject` TEXT NOT NULL, `content` TEXT NOT NULL, PRIMARY KEY(`uuid`))",
|
||||
"fields": [
|
||||
{
|
||||
"fieldPath": "uuid",
|
||||
"columnName": "uuid",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "state",
|
||||
"columnName": "state",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "subject",
|
||||
"columnName": "subject",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "content",
|
||||
"columnName": "content",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
}
|
||||
],
|
||||
"primaryKey": {
|
||||
"autoGenerate": false,
|
||||
"columnNames": [
|
||||
"uuid"
|
||||
]
|
||||
},
|
||||
"indices": [],
|
||||
"foreignKeys": []
|
||||
}
|
||||
],
|
||||
"views": [],
|
||||
"setupQueries": [
|
||||
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
|
||||
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, 'bf23f9a3f857e7cfe28dce9eb1657534')"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
@ -14,6 +14,13 @@ object Repository {
|
|||
fun getPreferenceString(context: Context, key: String, defaultValue: String) =
|
||||
SPHelper.getPreferenceString(context, key, defaultValue)
|
||||
|
||||
|
||||
/**
|
||||
* 获取应用设置的布尔值
|
||||
*/
|
||||
fun getPreferenceBoolean(context: Context, key: String, defaultValue: Boolean) =
|
||||
SPHelper.getPreferenceBoolean(context, key, defaultValue)
|
||||
|
||||
// Room
|
||||
private val db get() = ToDoApplication.db
|
||||
val todoDao = db.toDoRoomDao()
|
||||
|
|
|
|||
|
|
@ -9,4 +9,9 @@ object SPHelper {
|
|||
PreferenceManager.getDefaultSharedPreferences(context /* Activity context */)
|
||||
return sharedPreferences.getString(name, defaultValue)
|
||||
}
|
||||
fun getPreferenceBoolean(context: Context, name: String, defaultValue: Boolean): Boolean? {
|
||||
val sharedPreferences =
|
||||
PreferenceManager.getDefaultSharedPreferences(context /* Activity context */)
|
||||
return sharedPreferences.getBoolean(name, defaultValue)
|
||||
}
|
||||
}
|
||||
|
|
@ -1,3 +1,5 @@
|
|||
package cn.super12138.todo.logic.model
|
||||
|
||||
data class ToDo(val uuid: String, val content: String, val subject: String)
|
||||
data class ToDo(val uuid: String, val content: String, val subject: String){
|
||||
var isAnimated = false
|
||||
}
|
||||
|
|
@ -56,10 +56,11 @@ class AboutActivity : BaseActivity() {
|
|||
|
||||
binding.appVersion.setOnClickListener {
|
||||
clickCount++
|
||||
|
||||
if (clickCount == 5) {
|
||||
clickCount = 0
|
||||
"🧧".showToast()
|
||||
when (clickCount) {
|
||||
5 -> {
|
||||
clickCount = 0
|
||||
"🧧".showToast()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package cn.super12138.todo.views.main
|
|||
// 2023.11.18立项
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.view.WindowManager
|
||||
import androidx.appcompat.app.AppCompatDelegate
|
||||
import cn.super12138.todo.R
|
||||
import cn.super12138.todo.ToDoApplication
|
||||
|
|
@ -48,6 +49,7 @@ class MainActivity : BaseActivity() {
|
|||
}*/
|
||||
|
||||
val isDarkMode = Repository.getPreferenceString(this, "dark_mode", "0")
|
||||
val isSecureMode = Repository.getPreferenceBoolean(this, "secure_mode", false)
|
||||
when (isDarkMode) {
|
||||
"0" -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM)
|
||||
|
||||
|
|
@ -55,5 +57,14 @@ class MainActivity : BaseActivity() {
|
|||
|
||||
"2" -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO)
|
||||
}
|
||||
when (isSecureMode) {
|
||||
true -> window.setFlags(
|
||||
WindowManager.LayoutParams.FLAG_SECURE,
|
||||
WindowManager.LayoutParams.FLAG_SECURE
|
||||
)
|
||||
|
||||
false -> window.clearFlags(WindowManager.LayoutParams.FLAG_SECURE)
|
||||
else -> window.clearFlags(WindowManager.LayoutParams.FLAG_SECURE)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,12 +1,17 @@
|
|||
package cn.super12138.todo.views.settings
|
||||
|
||||
import android.os.Bundle
|
||||
import android.os.Process
|
||||
import android.view.WindowManager
|
||||
import androidx.appcompat.app.AppCompatDelegate
|
||||
import androidx.preference.ListPreference
|
||||
import androidx.preference.PreferenceFragmentCompat
|
||||
import androidx.preference.SwitchPreference
|
||||
import cn.super12138.todo.R
|
||||
import cn.super12138.todo.databinding.ActivitySettingsBinding
|
||||
import cn.super12138.todo.views.BaseActivity
|
||||
import com.google.android.material.snackbar.Snackbar
|
||||
import kotlin.system.exitProcess
|
||||
|
||||
class SettingsActivity : BaseActivity() {
|
||||
private lateinit var binding: ActivitySettingsBinding
|
||||
|
|
@ -48,6 +53,29 @@ class SettingsActivity : BaseActivity() {
|
|||
true
|
||||
}
|
||||
}
|
||||
|
||||
findPreference<SwitchPreference>("secure_mode")?.apply {
|
||||
setOnPreferenceChangeListener { preference, newValue ->
|
||||
when (newValue) {
|
||||
true -> activity?.window?.setFlags(
|
||||
WindowManager.LayoutParams.FLAG_SECURE,
|
||||
WindowManager.LayoutParams.FLAG_SECURE
|
||||
)
|
||||
|
||||
false -> activity?.window?.clearFlags(WindowManager.LayoutParams.FLAG_SECURE)
|
||||
}
|
||||
view?.let {
|
||||
Snackbar.make(it, R.string.need_restart_app, Snackbar.LENGTH_LONG)
|
||||
.setAction(R.string.restart_app_now) {
|
||||
Process.killProcess(Process.myPid())
|
||||
exitProcess(10)
|
||||
}
|
||||
.show()
|
||||
}
|
||||
|
||||
true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -116,6 +116,11 @@ class ToDoAdapter(val todoList: MutableList<ToDo>, val viewModelStoreOwner: View
|
|||
val todo = todoList[position]
|
||||
holder.todoContext.text = todo.content
|
||||
holder.todoSubject.text = todo.subject
|
||||
if (!todo.isAnimated) {
|
||||
holder.itemView.alpha = 0f
|
||||
holder.itemView.animate().alpha(1f).duration = 200
|
||||
todo.isAnimated = true
|
||||
}
|
||||
}
|
||||
|
||||
override fun getItemCount() = todoList.size
|
||||
|
|
|
|||
|
|
@ -11,14 +11,16 @@
|
|||
android:layout_marginLeft="15dp"
|
||||
android:layout_marginRight="15dp"
|
||||
android:max="100"
|
||||
app:indicatorSize="160dp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:indicatorSize="160dp"
|
||||
app:trackColor="?attr/colorSurfaceContainerHighest"
|
||||
app:trackCornerRadius="5dp"
|
||||
app:trackThickness="10dp" />
|
||||
app:trackCornerRadius="25dp"
|
||||
app:trackThickness="10dp"
|
||||
app:showDelay="150"
|
||||
app:indicatorTrackGapSize="10dp"/>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
|
|
|
|||
|
|
@ -41,4 +41,8 @@
|
|||
<string name="view_source">在 GitHub 上查看源代码</string>
|
||||
<string name="config">配置</string>
|
||||
<string name="others">其它</string>
|
||||
<string name="secure_mode">阻止截屏</string>
|
||||
<string name="secure_mode_summary">开启后任何人将不能对待办列表进行截屏</string>
|
||||
<string name="need_restart_app">重启应用后生效</string>
|
||||
<string name="restart_app_now">立即重启</string>
|
||||
</resources>
|
||||
|
|
@ -41,4 +41,8 @@
|
|||
<string name="dark_mode_summary">Enable or disable the dark mode for this app</string>
|
||||
<string name="config">Config</string>
|
||||
<string name="others">Others</string>
|
||||
<string name="secure_mode">Prevent screenshot</string>
|
||||
<string name="secure_mode_summary">When it opens anybody cannot take screenshot for to do list</string>
|
||||
<string name="need_restart_app">Effective after restarting the app</string>
|
||||
<string name="restart_app_now">Restart now</string>
|
||||
</resources>
|
||||
|
|
@ -10,16 +10,21 @@
|
|||
app:summary="@string/dark_mode_summary" />
|
||||
</PreferenceCategory>
|
||||
|
||||
<!--<PreferenceCategory app:title="@string/config">
|
||||
<EditTextPreference
|
||||
<PreferenceCategory app:title="@string/config">
|
||||
<!--<EditTextPreference
|
||||
android:defaultValue=""
|
||||
android:key="todo_predict_custom"
|
||||
android:selectAllOnFocus="true"
|
||||
android:singleLine="true"
|
||||
android:title="文本预测项目"
|
||||
app:dialogMessage="多个项目请使用英文逗号隔开"
|
||||
app:summary="自定义创建待办时文本框的预测项" />
|
||||
</PreferenceCategory>-->
|
||||
app:summary="自定义创建待办时文本框的预测项" />-->
|
||||
<SwitchPreference
|
||||
android:defaultValue="false"
|
||||
android:key="secure_mode"
|
||||
android:title="@string/secure_mode"
|
||||
app:summary="@string/secure_mode_summary" />
|
||||
</PreferenceCategory>
|
||||
|
||||
<PreferenceCategory android:title="@string/others">
|
||||
<Preference app:title="@string/about_label">
|
||||
|
|
|
|||
Loading…
Reference in a new issue