Refine code
This commit is contained in:
parent
eade595899
commit
25220b716e
18 changed files with 137 additions and 128 deletions
|
|
@ -3,7 +3,7 @@
|
||||||
xmlns:tools="http://schemas.android.com/tools">
|
xmlns:tools="http://schemas.android.com/tools">
|
||||||
|
|
||||||
<application
|
<application
|
||||||
android:name=".ToDoApplication"
|
android:name=".ToDoApp"
|
||||||
android:allowBackup="true"
|
android:allowBackup="true"
|
||||||
android:dataExtractionRules="@xml/data_extraction_rules"
|
android:dataExtractionRules="@xml/data_extraction_rules"
|
||||||
android:enableOnBackInvokedCallback="true"
|
android:enableOnBackInvokedCallback="true"
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ import cn.super12138.todo.logic.dao.ToDoRoomDB
|
||||||
import cn.super12138.todo.views.crash.CrashHandler
|
import cn.super12138.todo.views.crash.CrashHandler
|
||||||
import com.google.android.material.color.DynamicColors
|
import com.google.android.material.color.DynamicColors
|
||||||
|
|
||||||
class ToDoApplication : Application() {
|
class ToDoApp : Application() {
|
||||||
private val database by lazy { ToDoRoomDB.getDatabase(this) }
|
private val database by lazy { ToDoRoomDB.getDatabase(this) }
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
@ -4,4 +4,22 @@ object Constants {
|
||||||
const val AUTHOR_GITHUB_URL = "https://github.com/Super12138/"
|
const val AUTHOR_GITHUB_URL = "https://github.com/Super12138/"
|
||||||
const val REPO_GITHUB_URL = "https://github.com/Super12138/ToDo"
|
const val REPO_GITHUB_URL = "https://github.com/Super12138/ToDo"
|
||||||
const val UPDATE_URL = "https://github.com/Super12138/ToDo/releases"
|
const val UPDATE_URL = "https://github.com/Super12138/ToDo/releases"
|
||||||
|
|
||||||
|
const val SP_NAME = "cn.super12138.todo_preferences"
|
||||||
|
|
||||||
|
const val PREF_DARK_MODE = "dark_mode"
|
||||||
|
const val PREF_SECURE_MODE = "secure_mode"
|
||||||
|
const val PREF_DEV_MODE = "dev_mode"
|
||||||
|
const val PREF_SPRING_FESTIVAL_THEME = "spring_festival_theme"
|
||||||
|
const val PREF_BACKUP_DB = "backup_db"
|
||||||
|
const val PREF_RESTORE_DB = "restore_db"
|
||||||
|
|
||||||
|
const val STRING_DEV_MODE = "/DEV_MODE"
|
||||||
|
|
||||||
|
const val TAG_INFO_BOTTOM_SHEET = "InfoBottomSheet"
|
||||||
|
|
||||||
|
const val BUNDLE_TODO_CONTENT = "todoContent"
|
||||||
|
const val BUNDLE_TODO_SUBJECT = "todoSubject"
|
||||||
|
const val BUNDLE_TODO_STATE = "todoState"
|
||||||
|
const val BUNDLE_TODO_UUID = "todoUUID"
|
||||||
}
|
}
|
||||||
|
|
@ -0,0 +1,11 @@
|
||||||
|
package cn.super12138.todo.constant
|
||||||
|
|
||||||
|
import cn.super12138.todo.logic.database.SPDelegates
|
||||||
|
|
||||||
|
object GlobalValues {
|
||||||
|
var darkMode: String by SPDelegates(Constants.PREF_DARK_MODE, "0")
|
||||||
|
var devMode: Boolean by SPDelegates(Constants.PREF_DEV_MODE, false)
|
||||||
|
var springFestivalTheme: Boolean by SPDelegates(Constants.PREF_SPRING_FESTIVAL_THEME, false)
|
||||||
|
var secureMode: Boolean by SPDelegates(Constants.PREF_SECURE_MODE, false)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -1,33 +1,14 @@
|
||||||
package cn.super12138.todo.logic
|
package cn.super12138.todo.logic
|
||||||
|
|
||||||
import android.content.Context
|
import cn.super12138.todo.ToDoApp
|
||||||
import cn.super12138.todo.ToDoApplication
|
|
||||||
import cn.super12138.todo.logic.dao.ToDoRoom
|
import cn.super12138.todo.logic.dao.ToDoRoom
|
||||||
import cn.super12138.todo.logic.database.SPHelper
|
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
|
|
||||||
object Repository {
|
object Repository {
|
||||||
/**
|
|
||||||
* 设置数据到应用设置中
|
|
||||||
*/
|
|
||||||
fun setPreference(context: Context, key: String, value: Any) =
|
|
||||||
SPHelper.setPreference(context, key, value)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取应用设置里的数据
|
|
||||||
*/
|
|
||||||
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
|
// Room
|
||||||
private val db get() = ToDoApplication.db
|
private val db get() = ToDoApp.db
|
||||||
val todoDao = db.toDoRoomDao()
|
val todoDao = db.toDoRoomDao()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,14 @@
|
||||||
|
package cn.super12138.todo.logic.database
|
||||||
|
|
||||||
|
import cn.super12138.todo.utils.SPUtils
|
||||||
|
import kotlin.properties.ReadWriteProperty
|
||||||
|
import kotlin.reflect.KProperty
|
||||||
|
|
||||||
|
class SPDelegates<T>(private val key: String, private val default: T) : ReadWriteProperty<Any?, T> {
|
||||||
|
override fun getValue(thisRef: Any?, property: KProperty<*>): T {
|
||||||
|
return SPUtils.getValue(key, default)
|
||||||
|
}
|
||||||
|
override fun setValue(thisRef: Any?, property: KProperty<*>, value: T) {
|
||||||
|
SPUtils.putValue(key, value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,34 +0,0 @@
|
||||||
package cn.super12138.todo.logic.database
|
|
||||||
|
|
||||||
import android.content.Context
|
|
||||||
import androidx.preference.PreferenceManager
|
|
||||||
|
|
||||||
object SPHelper {
|
|
||||||
fun getPreferenceString(context: Context, name: String, defaultValue: String): String? {
|
|
||||||
val sharedPreferences =
|
|
||||||
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)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun setPreference(context: Context, name: String, value: Any) {
|
|
||||||
val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context)
|
|
||||||
val editor = sharedPreferences.edit()
|
|
||||||
|
|
||||||
when (value) {
|
|
||||||
is String -> editor.putString(name, value)
|
|
||||||
is Boolean -> editor.putBoolean(name, value)
|
|
||||||
is Int -> editor.putInt(name, value)
|
|
||||||
is Float -> editor.putFloat(name, value)
|
|
||||||
is Long -> editor.putLong(name, value)
|
|
||||||
else -> throw IllegalArgumentException("Unsupported data type")
|
|
||||||
}
|
|
||||||
|
|
||||||
editor.apply()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
36
app/src/main/kotlin/cn/super12138/todo/utils/SPUtils.kt
Normal file
36
app/src/main/kotlin/cn/super12138/todo/utils/SPUtils.kt
Normal file
|
|
@ -0,0 +1,36 @@
|
||||||
|
package cn.super12138.todo.utils
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.SharedPreferences
|
||||||
|
import cn.super12138.todo.ToDoApp
|
||||||
|
import cn.super12138.todo.constant.Constants
|
||||||
|
|
||||||
|
object SPUtils {
|
||||||
|
private val sp: SharedPreferences by lazy {
|
||||||
|
ToDoApp.context.getSharedPreferences(Constants.SP_NAME, Context.MODE_PRIVATE)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun <T> getValue(name: String, default: T): T = with(sp) {
|
||||||
|
val res: Any = when (default) {
|
||||||
|
is Long -> getLong(name, default)
|
||||||
|
is String -> getString(name, default).orEmpty()
|
||||||
|
is Int -> getInt(name, default)
|
||||||
|
is Boolean -> getBoolean(name, default)
|
||||||
|
is Float -> getFloat(name, default)
|
||||||
|
else -> throw java.lang.IllegalArgumentException()
|
||||||
|
}
|
||||||
|
@Suppress("UNCHECKED_CAST")
|
||||||
|
res as T
|
||||||
|
}
|
||||||
|
|
||||||
|
fun <T> putValue(name: String, value: T) = with(sp.edit()) {
|
||||||
|
when (value) {
|
||||||
|
is Long -> putLong(name, value)
|
||||||
|
is String -> putString(name, value)
|
||||||
|
is Int -> putInt(name, value)
|
||||||
|
is Boolean -> putBoolean(name, value)
|
||||||
|
is Float -> putFloat(name, value)
|
||||||
|
else -> throw IllegalArgumentException("This type can't be saved into Preferences")
|
||||||
|
}.apply()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,14 +1,16 @@
|
||||||
|
package cn.super12138.todo.utils
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import cn.super12138.todo.ToDoApplication
|
import cn.super12138.todo.ToDoApp
|
||||||
|
|
||||||
fun String.showToast(
|
fun String.showToast(
|
||||||
context: Context = ToDoApplication.context,
|
context: Context = ToDoApp.context,
|
||||||
duration: Int = Toast.LENGTH_SHORT
|
duration: Int = Toast.LENGTH_SHORT
|
||||||
) {
|
) {
|
||||||
Toast.makeText(context, this, duration).show()
|
Toast.makeText(context, this, duration).show()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Int.showToast(context: Context = ToDoApplication.context, duration: Int = Toast.LENGTH_SHORT) {
|
fun Int.showToast(context: Context = ToDoApp.context, duration: Int = Toast.LENGTH_SHORT) {
|
||||||
Toast.makeText(context, this, duration).show()
|
Toast.makeText(context, this, duration).show()
|
||||||
}
|
}
|
||||||
|
|
@ -6,22 +6,21 @@ import android.view.WindowManager
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import androidx.appcompat.app.AppCompatDelegate
|
import androidx.appcompat.app.AppCompatDelegate
|
||||||
import cn.super12138.todo.R
|
import cn.super12138.todo.R
|
||||||
import cn.super12138.todo.ToDoApplication
|
import cn.super12138.todo.ToDoApp
|
||||||
|
import cn.super12138.todo.constant.Constants
|
||||||
|
import cn.super12138.todo.constant.GlobalValues
|
||||||
import cn.super12138.todo.logic.Repository
|
import cn.super12138.todo.logic.Repository
|
||||||
|
|
||||||
open class BaseActivity : AppCompatActivity() {
|
open class BaseActivity : AppCompatActivity() {
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
val springFestivalTheme =
|
if (GlobalValues.springFestivalTheme) {
|
||||||
Repository.getPreferenceBoolean(ToDoApplication.context, "spring_festival_theme", false)
|
|
||||||
if (springFestivalTheme) {
|
|
||||||
setTheme(R.style.Theme_SpringFestival)
|
setTheme(R.style.Theme_SpringFestival)
|
||||||
}
|
}
|
||||||
// enableEdgeToEdge()
|
// enableEdgeToEdge()
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
|
|
||||||
// 深色模式
|
// 深色模式
|
||||||
val isDarkMode = Repository.getPreferenceString(this, "dark_mode", "0")
|
when (GlobalValues.darkMode) {
|
||||||
when (isDarkMode) {
|
|
||||||
"0" -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM)
|
"0" -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM)
|
||||||
|
|
||||||
"1" -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES)
|
"1" -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES)
|
||||||
|
|
|
||||||
|
|
@ -4,12 +4,11 @@ import android.content.Intent
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import cn.super12138.todo.ToDoApplication
|
|
||||||
import cn.super12138.todo.constant.Constants
|
import cn.super12138.todo.constant.Constants
|
||||||
|
import cn.super12138.todo.constant.GlobalValues
|
||||||
import cn.super12138.todo.databinding.ActivityAboutBinding
|
import cn.super12138.todo.databinding.ActivityAboutBinding
|
||||||
import cn.super12138.todo.logic.Repository
|
import cn.super12138.todo.utils.showToast
|
||||||
import cn.super12138.todo.views.BaseActivity
|
import cn.super12138.todo.views.BaseActivity
|
||||||
import showToast
|
|
||||||
|
|
||||||
class AboutActivity : BaseActivity() {
|
class AboutActivity : BaseActivity() {
|
||||||
private lateinit var binding: ActivityAboutBinding
|
private lateinit var binding: ActivityAboutBinding
|
||||||
|
|
@ -61,24 +60,7 @@ class AboutActivity : BaseActivity() {
|
||||||
when (clickCount) {
|
when (clickCount) {
|
||||||
5 -> {
|
5 -> {
|
||||||
clickCount = 0
|
clickCount = 0
|
||||||
val isSpringFestivalTheme = Repository.getPreferenceBoolean(
|
GlobalValues.springFestivalTheme = !GlobalValues.springFestivalTheme
|
||||||
ToDoApplication.context,
|
|
||||||
"spring_festival_theme",
|
|
||||||
false
|
|
||||||
)
|
|
||||||
if (isSpringFestivalTheme) {
|
|
||||||
Repository.setPreference(
|
|
||||||
ToDoApplication.context,
|
|
||||||
"spring_festival_theme",
|
|
||||||
false
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
Repository.setPreference(
|
|
||||||
ToDoApplication.context,
|
|
||||||
"spring_festival_theme",
|
|
||||||
true
|
|
||||||
)
|
|
||||||
}
|
|
||||||
"🧧".showToast()
|
"🧧".showToast()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,9 @@ import android.view.WindowManager
|
||||||
import androidx.lifecycle.Observer
|
import androidx.lifecycle.Observer
|
||||||
import androidx.lifecycle.ViewModelProvider
|
import androidx.lifecycle.ViewModelProvider
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
import cn.super12138.todo.ToDoApplication
|
import cn.super12138.todo.ToDoApp
|
||||||
|
import cn.super12138.todo.constant.Constants
|
||||||
|
import cn.super12138.todo.constant.GlobalValues
|
||||||
import cn.super12138.todo.databinding.ActivityAllTasksBinding
|
import cn.super12138.todo.databinding.ActivityAllTasksBinding
|
||||||
import cn.super12138.todo.logic.Repository
|
import cn.super12138.todo.logic.Repository
|
||||||
import cn.super12138.todo.views.BaseActivity
|
import cn.super12138.todo.views.BaseActivity
|
||||||
|
|
@ -17,8 +19,7 @@ class AllTasksActivity : BaseActivity() {
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
|
|
||||||
val isSecureMode = Repository.getPreferenceBoolean(this, "secure_mode", false)
|
when (GlobalValues.secureMode) {
|
||||||
when (isSecureMode) {
|
|
||||||
true -> window.setFlags(
|
true -> window.setFlags(
|
||||||
WindowManager.LayoutParams.FLAG_SECURE,
|
WindowManager.LayoutParams.FLAG_SECURE,
|
||||||
WindowManager.LayoutParams.FLAG_SECURE
|
WindowManager.LayoutParams.FLAG_SECURE
|
||||||
|
|
@ -32,7 +33,7 @@ class AllTasksActivity : BaseActivity() {
|
||||||
|
|
||||||
val viewModel = ViewModelProvider(this)[AllTasksViewModel::class.java]
|
val viewModel = ViewModelProvider(this)[AllTasksViewModel::class.java]
|
||||||
|
|
||||||
val layoutManager = LinearLayoutManager(ToDoApplication.context)
|
val layoutManager = LinearLayoutManager(ToDoApp.context)
|
||||||
binding.allTasksList.layoutManager = layoutManager
|
binding.allTasksList.layoutManager = layoutManager
|
||||||
val adapter = AllTasksAdapter(viewModel.todoListAll, supportFragmentManager)
|
val adapter = AllTasksAdapter(viewModel.todoListAll, supportFragmentManager)
|
||||||
binding.allTasksList.adapter = adapter
|
binding.allTasksList.adapter = adapter
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,9 @@ import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import cn.super12138.todo.R
|
import cn.super12138.todo.R
|
||||||
import cn.super12138.todo.ToDoApplication
|
import cn.super12138.todo.ToDoApp
|
||||||
|
import cn.super12138.todo.constant.Constants
|
||||||
|
import cn.super12138.todo.constant.GlobalValues
|
||||||
import cn.super12138.todo.databinding.BottomSheetInfoBinding
|
import cn.super12138.todo.databinding.BottomSheetInfoBinding
|
||||||
import cn.super12138.todo.logic.Repository
|
import cn.super12138.todo.logic.Repository
|
||||||
import com.google.android.material.bottomsheet.BottomSheetBehavior
|
import com.google.android.material.bottomsheet.BottomSheetBehavior
|
||||||
|
|
@ -21,7 +23,7 @@ class InfoBottomSheet : BottomSheetDialogFragment() {
|
||||||
private lateinit var todoUUID: String
|
private lateinit var todoUUID: String
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
const val TAG = "InfoBtmSheet"
|
const val TAG = Constants.TAG_INFO_BOTTOM_SHEET
|
||||||
fun newInstance(
|
fun newInstance(
|
||||||
todoContent: String,
|
todoContent: String,
|
||||||
todoSubject: String,
|
todoSubject: String,
|
||||||
|
|
@ -29,10 +31,10 @@ class InfoBottomSheet : BottomSheetDialogFragment() {
|
||||||
todoUUID: String
|
todoUUID: String
|
||||||
) = InfoBottomSheet().apply {
|
) = InfoBottomSheet().apply {
|
||||||
arguments = Bundle().apply {
|
arguments = Bundle().apply {
|
||||||
putString("todoContent", todoContent)
|
putString(Constants.BUNDLE_TODO_CONTENT, todoContent)
|
||||||
putString("todoSubject", todoSubject)
|
putString(Constants.BUNDLE_TODO_SUBJECT, todoSubject)
|
||||||
putInt("todoState", todoState)
|
putInt(Constants.BUNDLE_TODO_STATE, todoState)
|
||||||
putString("todoUUID", todoUUID)
|
putString(Constants.BUNDLE_TODO_UUID, todoUUID)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -40,10 +42,10 @@ class InfoBottomSheet : BottomSheetDialogFragment() {
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
arguments?.let {
|
arguments?.let {
|
||||||
todoContent = it.getString("todoContent", "")
|
todoContent = it.getString(Constants.BUNDLE_TODO_CONTENT, "")
|
||||||
todoSubject = it.getString("todoSubject", "")
|
todoSubject = it.getString(Constants.BUNDLE_TODO_SUBJECT, "")
|
||||||
todoState = it.getInt("todoState", 0)
|
todoState = it.getInt(Constants.BUNDLE_TODO_STATE, 0)
|
||||||
todoUUID = it.getString("todoUUID", "")
|
todoUUID = it.getString(Constants.BUNDLE_TODO_UUID, "")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -57,7 +59,6 @@ class InfoBottomSheet : BottomSheetDialogFragment() {
|
||||||
return binding.root
|
return binding.root
|
||||||
}
|
}
|
||||||
|
|
||||||
@androidx.annotation.OptIn(com.google.android.material.badge.ExperimentalBadgeUtils::class)
|
|
||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
super.onViewCreated(view, savedInstanceState)
|
super.onViewCreated(view, savedInstanceState)
|
||||||
|
|
||||||
|
|
@ -72,7 +73,7 @@ class InfoBottomSheet : BottomSheetDialogFragment() {
|
||||||
} else {
|
} else {
|
||||||
binding.todoState.text = getString(R.string.info_state_incomplete)
|
binding.todoState.text = getString(R.string.info_state_incomplete)
|
||||||
}
|
}
|
||||||
if (Repository.getPreferenceBoolean(ToDoApplication.context, "dev_mode", false)) {
|
if (GlobalValues.devMode) {
|
||||||
binding.todoUuid.apply {
|
binding.todoUuid.apply {
|
||||||
visibility = View.VISIBLE
|
visibility = View.VISIBLE
|
||||||
text = String.format(getString(R.string.info_uuid), todoUUID)
|
text = String.format(getString(R.string.info_uuid), todoUUID)
|
||||||
|
|
|
||||||
|
|
@ -3,9 +3,10 @@ package cn.super12138.todo.views.main
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.view.WindowManager
|
import android.view.WindowManager
|
||||||
import androidx.appcompat.app.AppCompatDelegate
|
|
||||||
import cn.super12138.todo.R
|
import cn.super12138.todo.R
|
||||||
import cn.super12138.todo.ToDoApplication
|
import cn.super12138.todo.ToDoApp
|
||||||
|
import cn.super12138.todo.constant.Constants
|
||||||
|
import cn.super12138.todo.constant.GlobalValues
|
||||||
import cn.super12138.todo.databinding.ActivityMainBinding
|
import cn.super12138.todo.databinding.ActivityMainBinding
|
||||||
import cn.super12138.todo.logic.Repository
|
import cn.super12138.todo.logic.Repository
|
||||||
import cn.super12138.todo.views.BaseActivity
|
import cn.super12138.todo.views.BaseActivity
|
||||||
|
|
@ -23,7 +24,7 @@ class MainActivity : BaseActivity() {
|
||||||
binding.toolbar.setOnMenuItemClickListener { menuItem ->
|
binding.toolbar.setOnMenuItemClickListener { menuItem ->
|
||||||
when (menuItem.itemId) {
|
when (menuItem.itemId) {
|
||||||
R.id.item_settings -> {
|
R.id.item_settings -> {
|
||||||
val intent = Intent(ToDoApplication.context, SettingsActivity::class.java)
|
val intent = Intent(ToDoApp.context, SettingsActivity::class.java)
|
||||||
startActivity(intent)
|
startActivity(intent)
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
@ -47,8 +48,7 @@ class MainActivity : BaseActivity() {
|
||||||
}
|
}
|
||||||
.show()
|
.show()
|
||||||
}*/
|
}*/
|
||||||
val isSecureMode = Repository.getPreferenceBoolean(this, "secure_mode", false)
|
when (GlobalValues.secureMode) {
|
||||||
when (isSecureMode) {
|
|
||||||
true -> window.setFlags(
|
true -> window.setFlags(
|
||||||
WindowManager.LayoutParams.FLAG_SECURE,
|
WindowManager.LayoutParams.FLAG_SECURE,
|
||||||
WindowManager.LayoutParams.FLAG_SECURE
|
WindowManager.LayoutParams.FLAG_SECURE
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,6 @@ package cn.super12138.todo.views.settings
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.os.Process
|
|
||||||
import androidx.appcompat.app.AlertDialog
|
import androidx.appcompat.app.AlertDialog
|
||||||
import androidx.appcompat.app.AppCompatDelegate
|
import androidx.appcompat.app.AppCompatDelegate
|
||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
|
|
@ -12,7 +11,8 @@ import androidx.preference.Preference
|
||||||
import androidx.preference.PreferenceFragmentCompat
|
import androidx.preference.PreferenceFragmentCompat
|
||||||
import androidx.preference.SwitchPreferenceCompat
|
import androidx.preference.SwitchPreferenceCompat
|
||||||
import cn.super12138.todo.R
|
import cn.super12138.todo.R
|
||||||
import cn.super12138.todo.ToDoApplication
|
import cn.super12138.todo.constant.Constants
|
||||||
|
import cn.super12138.todo.constant.GlobalValues
|
||||||
import cn.super12138.todo.databinding.ActivitySettingsBinding
|
import cn.super12138.todo.databinding.ActivitySettingsBinding
|
||||||
import cn.super12138.todo.databinding.DialogBackupBinding
|
import cn.super12138.todo.databinding.DialogBackupBinding
|
||||||
import cn.super12138.todo.databinding.DialogRestoreBinding
|
import cn.super12138.todo.databinding.DialogRestoreBinding
|
||||||
|
|
@ -56,10 +56,8 @@ class SettingsActivity : BaseActivity() {
|
||||||
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
|
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
|
||||||
setPreferencesFromResource(R.xml.preferences, rootKey)
|
setPreferencesFromResource(R.xml.preferences, rootKey)
|
||||||
val gson = Gson()
|
val gson = Gson()
|
||||||
val isDevMode =
|
|
||||||
Repository.getPreferenceBoolean(ToDoApplication.context, "dev_mode", false)
|
|
||||||
|
|
||||||
findPreference<ListPreference>("dark_mode")?.apply {
|
findPreference<ListPreference>(Constants.PREF_DARK_MODE)?.apply {
|
||||||
setOnPreferenceChangeListener { _, newValue ->
|
setOnPreferenceChangeListener { _, newValue ->
|
||||||
when (newValue) {
|
when (newValue) {
|
||||||
"0" -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM)
|
"0" -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM)
|
||||||
|
|
@ -73,7 +71,7 @@ class SettingsActivity : BaseActivity() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
findPreference<SwitchPreferenceCompat>("secure_mode")?.apply {
|
findPreference<SwitchPreferenceCompat>(Constants.PREF_SECURE_MODE)?.apply {
|
||||||
setOnPreferenceChangeListener { _, _ ->
|
setOnPreferenceChangeListener { _, _ ->
|
||||||
view?.let {
|
view?.let {
|
||||||
Snackbar.make(it, R.string.need_restart_app, Snackbar.LENGTH_LONG)
|
Snackbar.make(it, R.string.need_restart_app, Snackbar.LENGTH_LONG)
|
||||||
|
|
@ -87,7 +85,7 @@ class SettingsActivity : BaseActivity() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
findPreference<Preference>("backupDB")?.apply {
|
findPreference<Preference>(Constants.PREF_BACKUP_DB)?.apply {
|
||||||
setOnPreferenceClickListener {
|
setOnPreferenceClickListener {
|
||||||
lifecycleScope.launch {
|
lifecycleScope.launch {
|
||||||
val data = Repository.getAll()
|
val data = Repository.getAll()
|
||||||
|
|
@ -107,7 +105,7 @@ class SettingsActivity : BaseActivity() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
findPreference<Preference>("restoreDB")?.apply {
|
findPreference<Preference>(Constants.PREF_RESTORE_DB)?.apply {
|
||||||
setOnPreferenceClickListener {
|
setOnPreferenceClickListener {
|
||||||
restoreBinding = DialogRestoreBinding.inflate(layoutInflater)
|
restoreBinding = DialogRestoreBinding.inflate(layoutInflater)
|
||||||
activity?.let { it1 ->
|
activity?.let { it1 ->
|
||||||
|
|
@ -149,7 +147,7 @@ class SettingsActivity : BaseActivity() {
|
||||||
restoreBinding.jsonInput.error =
|
restoreBinding.jsonInput.error =
|
||||||
getString(R.string.json_data_incorrect)
|
getString(R.string.json_data_incorrect)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
if (isDevMode) {
|
if (GlobalValues.devMode) {
|
||||||
restoreBinding.jsonInput.error = e.toString()
|
restoreBinding.jsonInput.error = e.toString()
|
||||||
} else {
|
} else {
|
||||||
restoreBinding.jsonInput.error =
|
restoreBinding.jsonInput.error =
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,8 @@ import androidx.lifecycle.lifecycleScope
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import cn.super12138.todo.R
|
import cn.super12138.todo.R
|
||||||
import cn.super12138.todo.ToDoApplication
|
import cn.super12138.todo.ToDoApp
|
||||||
|
import cn.super12138.todo.constant.Constants
|
||||||
import cn.super12138.todo.databinding.DialogAddTodoBinding
|
import cn.super12138.todo.databinding.DialogAddTodoBinding
|
||||||
import cn.super12138.todo.databinding.FragmentTodoBinding
|
import cn.super12138.todo.databinding.FragmentTodoBinding
|
||||||
import cn.super12138.todo.logic.Repository
|
import cn.super12138.todo.logic.Repository
|
||||||
|
|
@ -22,7 +23,7 @@ import cn.super12138.todo.views.progress.ProgressFragmentViewModel
|
||||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import me.zhanghai.android.fastscroll.FastScrollerBuilder
|
import me.zhanghai.android.fastscroll.FastScrollerBuilder
|
||||||
import showToast
|
import cn.super12138.todo.utils.showToast
|
||||||
import java.util.UUID
|
import java.util.UUID
|
||||||
|
|
||||||
class ToDoFragment : Fragment() {
|
class ToDoFragment : Fragment() {
|
||||||
|
|
@ -59,7 +60,7 @@ class ToDoFragment : Fragment() {
|
||||||
|
|
||||||
val todoList = todoViewModel.todoList
|
val todoList = todoViewModel.todoList
|
||||||
|
|
||||||
val layoutManager = LinearLayoutManager(ToDoApplication.context)
|
val layoutManager = LinearLayoutManager(ToDoApp.context)
|
||||||
binding.todoList.layoutManager = layoutManager
|
binding.todoList.layoutManager = layoutManager
|
||||||
val adapter = ToDoAdapter(todoList, requireActivity())
|
val adapter = ToDoAdapter(todoList, requireActivity())
|
||||||
binding.todoList.adapter = adapter
|
binding.todoList.adapter = adapter
|
||||||
|
|
@ -89,16 +90,16 @@ class ToDoFragment : Fragment() {
|
||||||
toDoDialogBinding.todoContent.error =
|
toDoDialogBinding.todoContent.error =
|
||||||
getString(R.string.content_cannot_be_empty)
|
getString(R.string.content_cannot_be_empty)
|
||||||
} else {
|
} else {
|
||||||
if (todoContent == "/DEV_MODE") {
|
if (todoContent == Constants.STRING_DEV_MODE) {
|
||||||
if (Repository.getPreferenceBoolean(
|
if (Repository.getPreferenceBoolean(
|
||||||
ToDoApplication.context,
|
ToDoApp.context,
|
||||||
"dev_mode",
|
Constants.PREF_DEV_MODE,
|
||||||
true
|
true
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
Repository.setPreference(ToDoApplication.context, "dev_mode", false)
|
Repository.setPreference(ToDoApp.context, Constants.PREF_DEV_MODE, false)
|
||||||
} else {
|
} else {
|
||||||
Repository.setPreference(ToDoApplication.context, "dev_mode", true)
|
Repository.setPreference(ToDoApp.context, Constants.PREF_DEV_MODE, true)
|
||||||
"Dev Mode".showToast()
|
"Dev Mode".showToast()
|
||||||
}
|
}
|
||||||
dialog.dismiss()
|
dialog.dismiss()
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,6 @@
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:visibility="gone" />
|
android:visibility="gone" />
|
||||||
|
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/empty_tip"
|
android:id="@+id/empty_tip"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
|
|
||||||
|
|
@ -28,12 +28,12 @@
|
||||||
app:title="@string/secure_mode" />
|
app:title="@string/secure_mode" />
|
||||||
<Preference
|
<Preference
|
||||||
android:icon="@drawable/ic_backup"
|
android:icon="@drawable/ic_backup"
|
||||||
app:key="backupDB"
|
app:key="backup_db"
|
||||||
app:summary="@string/backup_summary"
|
app:summary="@string/backup_summary"
|
||||||
app:title="@string/backup" />
|
app:title="@string/backup" />
|
||||||
<Preference
|
<Preference
|
||||||
app:icon="@drawable/ic_restore"
|
app:icon="@drawable/ic_restore"
|
||||||
app:key="restoreDB"
|
app:key="restore_db"
|
||||||
app:summary="@string/restore_summary"
|
app:summary="@string/restore_summary"
|
||||||
app:title="@string/restore" />
|
app:title="@string/restore" />
|
||||||
</PreferenceCategory>
|
</PreferenceCategory>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue