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] 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) } }