Skip to content

Commit

Permalink
Update Voice Record layout when soft keyboard is opened to avoid over…
Browse files Browse the repository at this point in the history
…lapping issues
  • Loading branch information
tuancoltech committed Jul 3, 2024
1 parent ef07cf4 commit a4cb80d
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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"
Expand Down
7 changes: 4 additions & 3 deletions app/src/main/res/layout/fragment_edit_notes_v2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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"/>

<TextView
android:layout_width="wrap_content"
Expand Down Expand Up @@ -105,6 +106,7 @@
android:layout_marginHorizontal="@dimen/common_padding"
android:paddingTop="10dp"
android:paddingBottom="80dp"
app:layout_goneMarginTop="0dp"
android:textColorHint="#757575"
android:visibility="gone"
tools:visibility="visible" />
Expand Down Expand Up @@ -170,7 +172,7 @@
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:visibility="gone"
tools:visibility="gone"/>
tools:visibility="visible"/>

<include layout="@layout/layout_audio_record"
android:layout_width="match_parent"
Expand Down Expand Up @@ -227,7 +229,6 @@
android:layout_height="wrap_content"
app:constraint_referenced_ids="bottom_control_divider,tv_save,tv_paste"
android:id="@+id/group_text_controls"
tools:visibility="visible"
android:visibility="gone"/>

<androidx.constraintlayout.widget.Barrier
Expand Down
10 changes: 9 additions & 1 deletion app/src/main/res/layout/layout_audio_record.xml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toTopOf="@+id/tv_duration"
android:layout_marginBottom="12dp"/>
android:layout_marginBottom="12dp"
app:layout_goneMarginBottom="0dp"/>

<TextView
android:id="@+id/tv_save_recording"
Expand All @@ -94,6 +95,7 @@
android:background="?attr/selectableItemBackgroundBorderless"
android:layout_marginEnd="@dimen/common_padding"
android:layout_marginBottom="12dp"
app:layout_goneMarginBottom="0dp"
android:textStyle="bold"/>

<View
Expand Down Expand Up @@ -139,4 +141,10 @@
android:background="?attr/selectableItemBackgroundBorderless"
android:src="@drawable/ic_record_start_over"/>

<androidx.constraintlayout.widget.Group
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/group_recording_views"
app:constraint_referenced_ids="iv_start_over,iv_pause_resume,tv_duration,tv_record_guide,iv_record,divider_top_duration"/>

</androidx.constraintlayout.widget.ConstraintLayout>

0 comments on commit a4cb80d

Please sign in to comment.