From 68166c318c8fd6e7d566bf42eb4538159f5d543a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ensar=20Saraj=C4=8Di=C4=87?= Date: Thu, 27 Jul 2023 10:46:06 +0200 Subject: [PATCH 1/6] Increase offscreenPageLimit when recycle bin is used --- .../voicerecorder/activities/MainActivity.kt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/src/main/kotlin/com/simplemobiletools/voicerecorder/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/voicerecorder/activities/MainActivity.kt index a80ac09..5d61234 100644 --- a/app/src/main/kotlin/com/simplemobiletools/voicerecorder/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/voicerecorder/activities/MainActivity.kt @@ -187,6 +187,11 @@ class MainActivity : SimpleActivity() { ) view_pager.adapter = ViewPagerAdapter(this, config.useRecycleBin) + view_pager.offscreenPageLimit = if (config.useRecycleBin) { + 2 + } else { + 1 + } view_pager.onPageChangeListener { main_tabs_holder.getTabAt(it)?.select() (view_pager.adapter as ViewPagerAdapter).finishActMode() From a0278914ee5e73c2e646ca9060394e81011610d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ensar=20Saraj=C4=8Di=C4=87?= Date: Thu, 27 Jul 2023 10:50:04 +0200 Subject: [PATCH 2/6] Remove needless background thread and main thread wrappers in setupAdapter --- .../voicerecorder/fragments/PlayerFragment.kt | 67 +++++++++---------- .../voicerecorder/fragments/TrashFragment.kt | 53 +++++++-------- 2 files changed, 54 insertions(+), 66 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/voicerecorder/fragments/PlayerFragment.kt b/app/src/main/kotlin/com/simplemobiletools/voicerecorder/fragments/PlayerFragment.kt index 34ad7c2..9044c05 100644 --- a/app/src/main/kotlin/com/simplemobiletools/voicerecorder/fragments/PlayerFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/voicerecorder/fragments/PlayerFragment.kt @@ -12,7 +12,6 @@ import android.provider.DocumentsContract import android.util.AttributeSet import android.widget.SeekBar import com.simplemobiletools.commons.extensions.* -import com.simplemobiletools.commons.helpers.ensureBackgroundThread import com.simplemobiletools.commons.helpers.isQPlus import com.simplemobiletools.voicerecorder.R import com.simplemobiletools.voicerecorder.activities.SimpleActivity @@ -138,44 +137,40 @@ class PlayerFragment(context: Context, attributeSet: AttributeSet) : MyViewPager } private fun setupAdapter(recordings: ArrayList) { - ensureBackgroundThread { - Handler(Looper.getMainLooper()).post { - recordings_fastscroller.beVisibleIf(recordings.isNotEmpty()) - recordings_placeholder.beVisibleIf(recordings.isEmpty()) - if (recordings.isEmpty()) { - val stringId = if (lastSearchQuery.isEmpty()) { - if (isQPlus()) { - R.string.no_recordings_found - } else { - R.string.no_recordings_in_folder_found - } - } else { - R.string.no_items_found - } - - recordings_placeholder.text = context.getString(stringId) - resetProgress(null) - player?.stop() - } - - val adapter = getRecordingsAdapter() - if (adapter == null) { - RecordingsAdapter(context as SimpleActivity, recordings, this, recordings_list) { - playRecording(it as Recording, true) - if (playedRecordingIDs.isEmpty() || playedRecordingIDs.peek() != it.id) { - playedRecordingIDs.push(it.id) - } - }.apply { - recordings_list.adapter = this - } - - if (context.areSystemAnimationsEnabled) { - recordings_list.scheduleLayoutAnimation() - } + recordings_fastscroller.beVisibleIf(recordings.isNotEmpty()) + recordings_placeholder.beVisibleIf(recordings.isEmpty()) + if (recordings.isEmpty()) { + val stringId = if (lastSearchQuery.isEmpty()) { + if (isQPlus()) { + R.string.no_recordings_found } else { - adapter.updateItems(recordings) + R.string.no_recordings_in_folder_found } + } else { + R.string.no_items_found } + + recordings_placeholder.text = context.getString(stringId) + resetProgress(null) + player?.stop() + } + + val adapter = getRecordingsAdapter() + if (adapter == null) { + RecordingsAdapter(context as SimpleActivity, recordings, this, recordings_list) { + playRecording(it as Recording, true) + if (playedRecordingIDs.isEmpty() || playedRecordingIDs.peek() != it.id) { + playedRecordingIDs.push(it.id) + } + }.apply { + recordings_list.adapter = this + } + + if (context.areSystemAnimationsEnabled) { + recordings_list.scheduleLayoutAnimation() + } + } else { + adapter.updateItems(recordings) } } diff --git a/app/src/main/kotlin/com/simplemobiletools/voicerecorder/fragments/TrashFragment.kt b/app/src/main/kotlin/com/simplemobiletools/voicerecorder/fragments/TrashFragment.kt index faa0972..de7fa5e 100644 --- a/app/src/main/kotlin/com/simplemobiletools/voicerecorder/fragments/TrashFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/voicerecorder/fragments/TrashFragment.kt @@ -1,11 +1,8 @@ package com.simplemobiletools.voicerecorder.fragments import android.content.Context -import android.os.Handler -import android.os.Looper import android.util.AttributeSet import com.simplemobiletools.commons.extensions.* -import com.simplemobiletools.commons.helpers.ensureBackgroundThread import com.simplemobiletools.voicerecorder.R import com.simplemobiletools.voicerecorder.activities.SimpleActivity import com.simplemobiletools.voicerecorder.adapters.TrashAdapter @@ -63,34 +60,30 @@ class TrashFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerF override fun playRecording(recording: Recording, playOnPrepared: Boolean) {} private fun setupAdapter(recordings: ArrayList) { - ensureBackgroundThread { - Handler(Looper.getMainLooper()).post { - recordings_fastscroller.beVisibleIf(recordings.isNotEmpty()) - recordings_placeholder.beVisibleIf(recordings.isEmpty()) - if (recordings.isEmpty()) { - val stringId = if (lastSearchQuery.isEmpty()) { - R.string.recycle_bin_empty - } else { - R.string.no_items_found - } - - recordings_placeholder.text = context.getString(stringId) - } - - val adapter = getRecordingsAdapter() - if (adapter == null) { - TrashAdapter(context as SimpleActivity, recordings, this, recordings_list) - .apply { - recordings_list.adapter = this - } - - if (context.areSystemAnimationsEnabled) { - recordings_list.scheduleLayoutAnimation() - } - } else { - adapter.updateItems(recordings) - } + recordings_fastscroller.beVisibleIf(recordings.isNotEmpty()) + recordings_placeholder.beVisibleIf(recordings.isEmpty()) + if (recordings.isEmpty()) { + val stringId = if (lastSearchQuery.isEmpty()) { + R.string.recycle_bin_empty + } else { + R.string.no_items_found } + + recordings_placeholder.text = context.getString(stringId) + } + + val adapter = getRecordingsAdapter() + if (adapter == null) { + TrashAdapter(context as SimpleActivity, recordings, this, recordings_list) + .apply { + recordings_list.adapter = this + } + + if (context.areSystemAnimationsEnabled) { + recordings_list.scheduleLayoutAnimation() + } + } else { + adapter.updateItems(recordings) } } From f0db5d72aabcb6c12e2d68f212e6d6c0f705a14c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ensar=20Saraj=C4=8Di=C4=87?= Date: Thu, 27 Jul 2023 10:56:15 +0200 Subject: [PATCH 3/6] Clean up IDs in TrashFragment for clarity --- .../voicerecorder/fragments/TrashFragment.kt | 26 +++++++++---------- app/src/main/res/layout/fragment_trash.xml | 9 +++---- 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/voicerecorder/fragments/TrashFragment.kt b/app/src/main/kotlin/com/simplemobiletools/voicerecorder/fragments/TrashFragment.kt index de7fa5e..0d9d27b 100644 --- a/app/src/main/kotlin/com/simplemobiletools/voicerecorder/fragments/TrashFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/voicerecorder/fragments/TrashFragment.kt @@ -11,10 +11,10 @@ import com.simplemobiletools.voicerecorder.extensions.getAllRecordings import com.simplemobiletools.voicerecorder.interfaces.RefreshRecordingsListener import com.simplemobiletools.voicerecorder.models.Events import com.simplemobiletools.voicerecorder.models.Recording -import kotlinx.android.synthetic.main.fragment_trash.view.player_holder -import kotlinx.android.synthetic.main.fragment_trash.view.recordings_fastscroller -import kotlinx.android.synthetic.main.fragment_trash.view.recordings_list -import kotlinx.android.synthetic.main.fragment_trash.view.recordings_placeholder +import kotlinx.android.synthetic.main.fragment_trash.view.trash_holder +import kotlinx.android.synthetic.main.fragment_trash.view.trash_fastscroller +import kotlinx.android.synthetic.main.fragment_trash.view.trash_list +import kotlinx.android.synthetic.main.fragment_trash.view.trash_placeholder import org.greenrobot.eventbus.EventBus import org.greenrobot.eventbus.Subscribe import org.greenrobot.eventbus.ThreadMode @@ -60,8 +60,8 @@ class TrashFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerF override fun playRecording(recording: Recording, playOnPrepared: Boolean) {} private fun setupAdapter(recordings: ArrayList) { - recordings_fastscroller.beVisibleIf(recordings.isNotEmpty()) - recordings_placeholder.beVisibleIf(recordings.isEmpty()) + trash_fastscroller.beVisibleIf(recordings.isNotEmpty()) + trash_placeholder.beVisibleIf(recordings.isEmpty()) if (recordings.isEmpty()) { val stringId = if (lastSearchQuery.isEmpty()) { R.string.recycle_bin_empty @@ -69,18 +69,18 @@ class TrashFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerF R.string.no_items_found } - recordings_placeholder.text = context.getString(stringId) + trash_placeholder.text = context.getString(stringId) } val adapter = getRecordingsAdapter() if (adapter == null) { - TrashAdapter(context as SimpleActivity, recordings, this, recordings_list) + TrashAdapter(context as SimpleActivity, recordings, this, trash_list) .apply { - recordings_list.adapter = this + trash_list.adapter = this } if (context.areSystemAnimationsEnabled) { - recordings_list.scheduleLayoutAnimation() + trash_list.scheduleLayoutAnimation() } } else { adapter.updateItems(recordings) @@ -99,7 +99,7 @@ class TrashFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerF setupAdapter(filtered) } - private fun getRecordingsAdapter() = recordings_list.adapter as? TrashAdapter + private fun getRecordingsAdapter() = trash_list.adapter as? TrashAdapter private fun storePrevPath() { prevSavePath = context!!.config.saveRecordingsFolder @@ -107,8 +107,8 @@ class TrashFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerF private fun setupColors() { val properPrimaryColor = context.getProperPrimaryColor() - recordings_fastscroller.updateColors(properPrimaryColor) - context.updateTextColors(player_holder) + trash_fastscroller.updateColors(properPrimaryColor) + context.updateTextColors(trash_holder) } fun finishActMode() = getRecordingsAdapter()?.finishActMode() diff --git a/app/src/main/res/layout/fragment_trash.xml b/app/src/main/res/layout/fragment_trash.xml index b82de55..cecbd7d 100644 --- a/app/src/main/res/layout/fragment_trash.xml +++ b/app/src/main/res/layout/fragment_trash.xml @@ -1,12 +1,12 @@ Date: Thu, 27 Jul 2023 12:22:18 +0200 Subject: [PATCH 4/6] Always use offscreenPageLimit of 2 --- .../voicerecorder/activities/MainActivity.kt | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/voicerecorder/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/voicerecorder/activities/MainActivity.kt index 5d61234..5ee67a0 100644 --- a/app/src/main/kotlin/com/simplemobiletools/voicerecorder/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/voicerecorder/activities/MainActivity.kt @@ -187,11 +187,7 @@ class MainActivity : SimpleActivity() { ) view_pager.adapter = ViewPagerAdapter(this, config.useRecycleBin) - view_pager.offscreenPageLimit = if (config.useRecycleBin) { - 2 - } else { - 1 - } + view_pager.offscreenPageLimit = 2 view_pager.onPageChangeListener { main_tabs_holder.getTabAt(it)?.select() (view_pager.adapter as ViewPagerAdapter).finishActMode() From f5079dd8bff5af67e3a1380de4c7bc8e02fd5c7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ensar=20Saraj=C4=8Di=C4=87?= Date: Thu, 27 Jul 2023 12:32:21 +0200 Subject: [PATCH 5/6] Fix formatting in TrashFragment --- .../voicerecorder/fragments/TrashFragment.kt | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/voicerecorder/fragments/TrashFragment.kt b/app/src/main/kotlin/com/simplemobiletools/voicerecorder/fragments/TrashFragment.kt index 0d9d27b..2792c2d 100644 --- a/app/src/main/kotlin/com/simplemobiletools/voicerecorder/fragments/TrashFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/voicerecorder/fragments/TrashFragment.kt @@ -11,8 +11,8 @@ import com.simplemobiletools.voicerecorder.extensions.getAllRecordings import com.simplemobiletools.voicerecorder.interfaces.RefreshRecordingsListener import com.simplemobiletools.voicerecorder.models.Events import com.simplemobiletools.voicerecorder.models.Recording -import kotlinx.android.synthetic.main.fragment_trash.view.trash_holder import kotlinx.android.synthetic.main.fragment_trash.view.trash_fastscroller +import kotlinx.android.synthetic.main.fragment_trash.view.trash_holder import kotlinx.android.synthetic.main.fragment_trash.view.trash_list import kotlinx.android.synthetic.main.fragment_trash.view.trash_placeholder import org.greenrobot.eventbus.EventBus @@ -74,10 +74,9 @@ class TrashFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerF val adapter = getRecordingsAdapter() if (adapter == null) { - TrashAdapter(context as SimpleActivity, recordings, this, trash_list) - .apply { - trash_list.adapter = this - } + TrashAdapter(context as SimpleActivity, recordings, this, trash_list).apply { + trash_list.adapter = this + } if (context.areSystemAnimationsEnabled) { trash_list.scheduleLayoutAnimation() From dda0a9aa872615496f3d0da408ae1f71ff58f2ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ensar=20Saraj=C4=8Di=C4=87?= Date: Thu, 27 Jul 2023 15:25:45 +0200 Subject: [PATCH 6/6] Prevent navigating to player tab when searching recycle bin --- .../voicerecorder/activities/MainActivity.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/voicerecorder/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/voicerecorder/activities/MainActivity.kt index 5ee67a0..dbdc55a 100644 --- a/app/src/main/kotlin/com/simplemobiletools/voicerecorder/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/voicerecorder/activities/MainActivity.kt @@ -118,7 +118,9 @@ class MainActivity : SimpleActivity() { main_menu.setupMenu() main_menu.onSearchOpenListener = { - view_pager.currentItem = 1 + if (view_pager.currentItem == 0) { + view_pager.currentItem = 1 + } } main_menu.onSearchTextChangedListener = { text ->