From 03e414f15ee2c7072b53fc1897721b5ae44481f1 Mon Sep 17 00:00:00 2001 From: tuancoltech Date: Wed, 31 Jul 2024 22:30:50 +0700 Subject: [PATCH] Hide Delete option when creating a new Text/Voice note --- .../arkmemo/ui/fragments/ArkRecorderFragment.kt | 2 ++ .../arkmemo/ui/fragments/EditTextNotesFragment.kt | 11 +++++------ .../java/dev/arkbuilders/arkmemo/utils/BundleExt.kt | 13 +++++++++++++ 3 files changed, 20 insertions(+), 6 deletions(-) create mode 100644 app/src/main/java/dev/arkbuilders/arkmemo/utils/BundleExt.kt diff --git a/app/src/main/java/dev/arkbuilders/arkmemo/ui/fragments/ArkRecorderFragment.kt b/app/src/main/java/dev/arkbuilders/arkmemo/ui/fragments/ArkRecorderFragment.kt index 0b86a31e..c3dfc44a 100644 --- a/app/src/main/java/dev/arkbuilders/arkmemo/ui/fragments/ArkRecorderFragment.kt +++ b/app/src/main/java/dev/arkbuilders/arkmemo/ui/fragments/ArkRecorderFragment.kt @@ -212,6 +212,8 @@ class ArkRecorderFragment: BaseEditNoteFragment() { }, onNegativeClicked = { }).show(parentFragmentManager, CommonActionDialog.TAG) } + + note ?: binding.toolbar.ivRightActionIcon.gone() } private fun handleSideEffect(effect: RecorderSideEffect) { diff --git a/app/src/main/java/dev/arkbuilders/arkmemo/ui/fragments/EditTextNotesFragment.kt b/app/src/main/java/dev/arkbuilders/arkmemo/ui/fragments/EditTextNotesFragment.kt index 37afe15c..a46537a5 100644 --- a/app/src/main/java/dev/arkbuilders/arkmemo/ui/fragments/EditTextNotesFragment.kt +++ b/app/src/main/java/dev/arkbuilders/arkmemo/ui/fragments/EditTextNotesFragment.kt @@ -1,6 +1,5 @@ package dev.arkbuilders.arkmemo.ui.fragments -import android.os.Build import android.os.Bundle import android.text.Editable import android.text.TextWatcher @@ -13,7 +12,9 @@ import dagger.hilt.android.AndroidEntryPoint import dev.arkbuilders.arkmemo.R import dev.arkbuilders.arkmemo.models.Note import dev.arkbuilders.arkmemo.models.TextNote +import dev.arkbuilders.arkmemo.utils.getParcelableCompat import dev.arkbuilders.arkmemo.utils.getTextFromClipBoard +import dev.arkbuilders.arkmemo.utils.gone import dev.arkbuilders.arkmemo.utils.observeSaveResult import java.lang.StringBuilder @@ -47,11 +48,7 @@ class EditTextNotesFragment: BaseEditNoteFragment() { notesViewModel.init {} observeSaveResult(notesViewModel.getSaveNoteResultLiveData()) if(arguments != null) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) - requireArguments().getParcelable(NOTE_KEY, TextNote::class.java)?.let { - note = it - } - else requireArguments().getParcelable(NOTE_KEY)?.let { + requireArguments().getParcelableCompat(NOTE_KEY, TextNote::class.java)?.let { note = it } noteStr = requireArguments().getString(NOTE_STRING_KEY) @@ -107,6 +104,8 @@ class EditTextNotesFragment: BaseEditNoteFragment() { binding.toolbar.ivRightActionIcon.setOnClickListener { showDeleteNoteDialog(note) } + arguments?.getParcelableCompat(NOTE_KEY, TextNote::class.java) + ?: binding.toolbar.ivRightActionIcon.gone() view.viewTreeObserver.addOnWindowFocusChangeListener(windowFocusedListener) } diff --git a/app/src/main/java/dev/arkbuilders/arkmemo/utils/BundleExt.kt b/app/src/main/java/dev/arkbuilders/arkmemo/utils/BundleExt.kt new file mode 100644 index 00000000..2176cfa7 --- /dev/null +++ b/app/src/main/java/dev/arkbuilders/arkmemo/utils/BundleExt.kt @@ -0,0 +1,13 @@ +package dev.arkbuilders.arkmemo.utils + +import android.os.Build +import android.os.Bundle + +fun Bundle?.getParcelableCompat(key: String, clazz: Class): T? { + return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { + this?.getParcelable(key, clazz) + } else { + @Suppress("DEPRECATION") + this?.getParcelable(key) + } +} \ No newline at end of file