Refine code
This commit is contained in:
parent
5a15826a62
commit
ef5818673c
10 changed files with 42 additions and 45 deletions
|
|
@ -0,0 +1,13 @@
|
|||
package cn.super12138.todo.utils
|
||||
|
||||
import android.view.HapticFeedbackConstants
|
||||
import android.view.View
|
||||
import cn.super12138.todo.constant.GlobalValues
|
||||
|
||||
object VibrationUtils {
|
||||
fun performHapticFeedback(view: View, hapticFeedbackConstants: Int=HapticFeedbackConstants.CONTEXT_CLICK) {
|
||||
if (GlobalValues.hapticFeedback) {
|
||||
view.performHapticFeedback(hapticFeedbackConstants)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -8,6 +8,7 @@ import cn.super12138.todo.constant.Constants
|
|||
import cn.super12138.todo.constant.GlobalValues
|
||||
import cn.super12138.todo.databinding.ActivityAboutBinding
|
||||
import cn.super12138.todo.utils.VersionUtils
|
||||
import cn.super12138.todo.utils.VibrationUtils
|
||||
import cn.super12138.todo.utils.showToast
|
||||
import cn.super12138.todo.views.BaseActivity
|
||||
|
||||
|
|
@ -20,17 +21,13 @@ class AboutActivity : BaseActivity<ActivityAboutBinding>() {
|
|||
binding.appVersion.text = VersionUtils.getAppVersion(this)
|
||||
|
||||
binding.toolBar.setNavigationOnClickListener {
|
||||
if (GlobalValues.hapticFeedback) {
|
||||
it.performHapticFeedback(HapticFeedbackConstants.CONTEXT_CLICK)
|
||||
}
|
||||
VibrationUtils.performHapticFeedback(it)
|
||||
|
||||
finish()
|
||||
}
|
||||
|
||||
binding.checkUpdate.setOnClickListener {
|
||||
if (GlobalValues.hapticFeedback) {
|
||||
it.performHapticFeedback(HapticFeedbackConstants.CONTEXT_CLICK)
|
||||
}
|
||||
VibrationUtils.performHapticFeedback(it)
|
||||
|
||||
val intent = Intent(Intent.ACTION_VIEW).apply {
|
||||
data = Uri.parse(Constants.UPDATE_URL)
|
||||
|
|
@ -39,9 +36,7 @@ class AboutActivity : BaseActivity<ActivityAboutBinding>() {
|
|||
}
|
||||
|
||||
binding.openSource.setOnClickListener {
|
||||
if (GlobalValues.hapticFeedback) {
|
||||
it.performHapticFeedback(HapticFeedbackConstants.CONTEXT_CLICK)
|
||||
}
|
||||
VibrationUtils.performHapticFeedback(it)
|
||||
|
||||
val intent = Intent(Intent.ACTION_VIEW).apply {
|
||||
data = Uri.parse(Constants.REPO_GITHUB_URL)
|
||||
|
|
@ -51,9 +46,7 @@ class AboutActivity : BaseActivity<ActivityAboutBinding>() {
|
|||
|
||||
|
||||
binding.developerInfo.setOnClickListener {
|
||||
if (GlobalValues.hapticFeedback) {
|
||||
it.performHapticFeedback(HapticFeedbackConstants.CONTEXT_CLICK)
|
||||
}
|
||||
VibrationUtils.performHapticFeedback(it)
|
||||
|
||||
val intent = Intent(Intent.ACTION_VIEW).apply {
|
||||
data = Uri.parse(Constants.AUTHOR_GITHUB_URL)
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import androidx.recyclerview.widget.LinearLayoutManager
|
|||
import cn.super12138.todo.ToDoApp
|
||||
import cn.super12138.todo.constant.GlobalValues
|
||||
import cn.super12138.todo.databinding.ActivityAllTasksBinding
|
||||
import cn.super12138.todo.utils.VibrationUtils
|
||||
import cn.super12138.todo.views.BaseActivity
|
||||
import me.zhanghai.android.fastscroll.FastScrollerBuilder
|
||||
|
||||
|
|
@ -38,9 +39,7 @@ class AllTasksActivity : BaseActivity<ActivityAllTasksBinding>() {
|
|||
}
|
||||
|
||||
binding.toolBar.setNavigationOnClickListener {
|
||||
if (GlobalValues.hapticFeedback) {
|
||||
it.performHapticFeedback(HapticFeedbackConstants.CONTEXT_CLICK)
|
||||
}
|
||||
VibrationUtils.performHapticFeedback(it)
|
||||
|
||||
finish()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import androidx.recyclerview.widget.RecyclerView
|
|||
import cn.super12138.todo.R
|
||||
import cn.super12138.todo.constant.GlobalValues
|
||||
import cn.super12138.todo.logic.model.ToDo
|
||||
import cn.super12138.todo.utils.VibrationUtils
|
||||
|
||||
class AllTasksAdapter(
|
||||
private val todoList: MutableList<ToDo>,
|
||||
|
|
@ -35,9 +36,7 @@ class AllTasksAdapter(
|
|||
holder.todoSubject.text = todo.subject
|
||||
|
||||
holder.itemView.setOnClickListener {
|
||||
if (GlobalValues.hapticFeedback) {
|
||||
it.performHapticFeedback(HapticFeedbackConstants.CONTEXT_CLICK)
|
||||
}
|
||||
VibrationUtils.performHapticFeedback(it)
|
||||
|
||||
val infoBottomSheet = InfoBottomSheet.newInstance(
|
||||
todo.content,
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package cn.super12138.todo.views.bottomsheet
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.HapticFeedbackConstants
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
|
|
@ -13,6 +12,7 @@ import cn.super12138.todo.databinding.BottomSheetTodoBinding
|
|||
import cn.super12138.todo.logic.dao.ToDoRoom
|
||||
import cn.super12138.todo.logic.model.ToDo
|
||||
import cn.super12138.todo.utils.TextUtils
|
||||
import cn.super12138.todo.utils.VibrationUtils
|
||||
import cn.super12138.todo.utils.showToast
|
||||
import cn.super12138.todo.utils.toEditable
|
||||
import cn.super12138.todo.views.progress.ProgressFragmentViewModel
|
||||
|
|
@ -104,9 +104,7 @@ class ToDoBottomSheet : BottomSheetDialogFragment() {
|
|||
}
|
||||
|
||||
binding.btnSave.setOnClickListener {
|
||||
if (GlobalValues.hapticFeedback) {
|
||||
it.performHapticFeedback(HapticFeedbackConstants.CONTEXT_CLICK)
|
||||
}
|
||||
VibrationUtils.performHapticFeedback(it)
|
||||
|
||||
val todoContent = binding.todoContent.editText?.text.toString()
|
||||
// 内容判空
|
||||
|
|
@ -168,17 +166,13 @@ class ToDoBottomSheet : BottomSheetDialogFragment() {
|
|||
}
|
||||
|
||||
binding.btnCancel.setOnClickListener {
|
||||
if (GlobalValues.hapticFeedback) {
|
||||
it.performHapticFeedback(HapticFeedbackConstants.CONTEXT_CLICK)
|
||||
}
|
||||
VibrationUtils.performHapticFeedback(it)
|
||||
|
||||
dismiss()
|
||||
}
|
||||
|
||||
binding.btnDelete.setOnClickListener {
|
||||
if (GlobalValues.hapticFeedback) {
|
||||
it.performHapticFeedback(HapticFeedbackConstants.CONTEXT_CLICK)
|
||||
}
|
||||
VibrationUtils.performHapticFeedback(it)
|
||||
|
||||
todoViewModel.deleteTask(todoPosition, todoUUID)
|
||||
progressViewModel.updateProgress()
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import androidx.core.view.updateLayoutParams
|
|||
import cn.super12138.todo.constant.GlobalValues
|
||||
import cn.super12138.todo.databinding.ActivityCrashBinding
|
||||
import cn.super12138.todo.utils.VersionUtils
|
||||
import cn.super12138.todo.utils.VibrationUtils
|
||||
import cn.super12138.todo.views.BaseActivity
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.Calendar
|
||||
|
|
@ -18,7 +19,6 @@ import java.util.Locale
|
|||
|
||||
class CrashActivity : BaseActivity<ActivityCrashBinding>() {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
enableEdgeToEdge()
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
ViewCompat.setOnApplyWindowInsetsListener(binding.exitApp) { view, windowInsets ->
|
||||
|
|
@ -56,9 +56,8 @@ class CrashActivity : BaseActivity<ActivityCrashBinding>() {
|
|||
}
|
||||
|
||||
binding.exitApp.setOnClickListener {
|
||||
if (GlobalValues.hapticFeedback) {
|
||||
it.performHapticFeedback(HapticFeedbackConstants.CONTEXT_CLICK)
|
||||
}
|
||||
VibrationUtils.performHapticFeedback(it)
|
||||
|
||||
this.finishAffinity()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import cn.super12138.todo.R
|
|||
import cn.super12138.todo.ToDoApp
|
||||
import cn.super12138.todo.constant.GlobalValues
|
||||
import cn.super12138.todo.databinding.ActivityMainBinding
|
||||
import cn.super12138.todo.utils.VibrationUtils
|
||||
import cn.super12138.todo.views.BaseActivity
|
||||
import cn.super12138.todo.views.settings.SettingsActivity
|
||||
|
||||
|
|
@ -19,9 +20,9 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
|
|||
R.id.item_settings -> {
|
||||
val intent = Intent(ToDoApp.context, SettingsActivity::class.java)
|
||||
startActivity(intent)
|
||||
if (GlobalValues.hapticFeedback) {
|
||||
binding.toolBar.performHapticFeedback(HapticFeedbackConstants.CONTEXT_CLICK)
|
||||
}
|
||||
|
||||
VibrationUtils.performHapticFeedback(binding.toolBar)
|
||||
|
||||
true
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,10 +1,9 @@
|
|||
package cn.super12138.todo.views.settings
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.HapticFeedbackConstants
|
||||
import cn.super12138.todo.R
|
||||
import cn.super12138.todo.constant.GlobalValues
|
||||
import cn.super12138.todo.databinding.ActivitySettingsBinding
|
||||
import cn.super12138.todo.utils.VibrationUtils
|
||||
import cn.super12138.todo.views.BaseActivity
|
||||
|
||||
class SettingsActivity : BaseActivity<ActivitySettingsBinding>() {
|
||||
|
|
@ -20,9 +19,7 @@ class SettingsActivity : BaseActivity<ActivitySettingsBinding>() {
|
|||
supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
||||
|
||||
binding.toolBar.setNavigationOnClickListener {
|
||||
if (GlobalValues.hapticFeedback) {
|
||||
it.performHapticFeedback(HapticFeedbackConstants.CONTEXT_CLICK)
|
||||
}
|
||||
VibrationUtils.performHapticFeedback(it)
|
||||
|
||||
finish()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ import androidx.recyclerview.widget.RecyclerView
|
|||
import cn.super12138.todo.R
|
||||
import cn.super12138.todo.constant.GlobalValues
|
||||
import cn.super12138.todo.logic.model.ToDo
|
||||
import cn.super12138.todo.utils.VibrationUtils
|
||||
import cn.super12138.todo.utils.showToast
|
||||
import cn.super12138.todo.views.bottomsheet.ToDoBottomSheet
|
||||
import cn.super12138.todo.views.progress.ProgressFragmentViewModel
|
||||
|
|
@ -78,6 +79,7 @@ class ToDoAdapter(
|
|||
|
||||
holder.itemView.setOnClickListener {
|
||||
if (GlobalValues.devMode) {
|
||||
VibrationUtils.performHapticFeedback(it)
|
||||
"Current position: $position".showToast()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package cn.super12138.todo.views.todo
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.HapticFeedbackConstants
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
|
|
@ -13,9 +12,9 @@ import androidx.recyclerview.widget.LinearLayoutManager
|
|||
import androidx.recyclerview.widget.RecyclerView
|
||||
import cn.super12138.todo.R
|
||||
import cn.super12138.todo.ToDoApp
|
||||
import cn.super12138.todo.constant.GlobalValues
|
||||
import cn.super12138.todo.databinding.FragmentTodoBinding
|
||||
import cn.super12138.todo.logic.Repository
|
||||
import cn.super12138.todo.utils.VibrationUtils
|
||||
import cn.super12138.todo.views.bottomsheet.ToDoBottomSheet
|
||||
import cn.super12138.todo.views.progress.ProgressFragmentViewModel
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
|
|
@ -66,9 +65,8 @@ class ToDoFragment : Fragment() {
|
|||
}
|
||||
|
||||
binding.addItem.setOnClickListener {
|
||||
if (GlobalValues.hapticFeedback) {
|
||||
it.performHapticFeedback(HapticFeedbackConstants.CONTEXT_CLICK)
|
||||
}
|
||||
VibrationUtils.performHapticFeedback(it)
|
||||
|
||||
val toDoBottomSheet = ToDoBottomSheet()
|
||||
toDoBottomSheet.show(parentFragmentManager, ToDoBottomSheet.TAG)
|
||||
}
|
||||
|
|
@ -79,6 +77,8 @@ class ToDoFragment : Fragment() {
|
|||
.setTitle(R.string.warning)
|
||||
.setMessage(R.string.delete_confirm)
|
||||
.setPositiveButton(R.string.ok) { _, _ ->
|
||||
VibrationUtils.performHapticFeedback(it)
|
||||
|
||||
// 清除 Recycler View
|
||||
todoList.clear()
|
||||
// 清除数据库
|
||||
|
|
|
|||
Loading…
Reference in a new issue