From a4cb80de14658dc869f9a1591b94609b92f2dd45 Mon Sep 17 00:00:00 2001 From: tuancoltech Date: Wed, 3 Jul 2024 22:13:37 +0700 Subject: [PATCH] Update Voice Record layout when soft keyboard is opened to avoid overlapping issues --- .../ui/fragments/ArkRecorderFragment.kt | 22 +++++++++++++++++++ .../res/layout/fragment_edit_notes_v2.xml | 7 +++--- .../main/res/layout/layout_audio_record.xml | 10 ++++++++- 3 files changed, 35 insertions(+), 4 deletions(-) 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 a78bf056..24393bd4 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 @@ -12,6 +12,8 @@ import android.widget.TextView import androidx.activity.result.contract.ActivityResultContracts import androidx.core.content.ContextCompat import androidx.core.content.res.ResourcesCompat +import androidx.core.view.ViewCompat +import androidx.core.view.WindowInsetsCompat import androidx.core.widget.addTextChangedListener import androidx.fragment.app.viewModels import androidx.lifecycle.Lifecycle @@ -95,6 +97,20 @@ class ArkRecorderFragment: BaseEditNoteFragment() { initUI() initExistingNoteUI() observeViewModel() + observeKeyboardVisibility() + } + + private fun observeKeyboardVisibility() { + val view = activity.window?.decorView ?: return + ViewCompat.setOnApplyWindowInsetsListener(view) { v, insets -> + val showingKeyboard = insets.isVisible(WindowInsetsCompat.Type.ime()) + if (showingKeyboard) { + binding.layoutAudioRecord.groupRecordingViews.gone() + } else { + binding.layoutAudioRecord.groupRecordingViews.visible() + } + insets + } } private fun initUI() { @@ -393,6 +409,12 @@ class ArkRecorderFragment: BaseEditNoteFragment() { } } + override fun onDestroy() { + super.onDestroy() + val view = activity.window?.decorView ?: return + ViewCompat.setOnApplyWindowInsetsListener(view, null) + } + companion object { const val TAG = "voice-notes-fragment" diff --git a/app/src/main/res/layout/fragment_edit_notes_v2.xml b/app/src/main/res/layout/fragment_edit_notes_v2.xml index 54a3efb9..dec6198b 100644 --- a/app/src/main/res/layout/fragment_edit_notes_v2.xml +++ b/app/src/main/res/layout/fragment_edit_notes_v2.xml @@ -54,7 +54,8 @@ app:layout_constraintTop_toBottomOf="@+id/edt_title" android:id="@+id/rv_tags" android:visibility="gone" - android:layout_marginTop="12dp"/> + android:layout_marginTop="12dp" + app:layout_goneMarginBottom="0dp"/> @@ -170,7 +172,7 @@ app:layout_constraintEnd_toEndOf="parent" app:layout_constraintBottom_toBottomOf="parent" android:visibility="gone" - tools:visibility="gone"/> + tools:visibility="visible"/> + android:layout_marginBottom="12dp" + app:layout_goneMarginBottom="0dp"/> + + \ No newline at end of file