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..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 -> @@ -187,6 +189,7 @@ class MainActivity : SimpleActivity() { ) view_pager.adapter = ViewPagerAdapter(this, config.useRecycleBin) + view_pager.offscreenPageLimit = 2 view_pager.onPageChangeListener { main_tabs_holder.getTabAt(it)?.select() (view_pager.adapter as ViewPagerAdapter).finishActMode() 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..2792c2d 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 @@ -14,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_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 import org.greenrobot.eventbus.Subscribe import org.greenrobot.eventbus.ThreadMode @@ -63,34 +60,29 @@ 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) - } + trash_fastscroller.beVisibleIf(recordings.isNotEmpty()) + trash_placeholder.beVisibleIf(recordings.isEmpty()) + if (recordings.isEmpty()) { + val stringId = if (lastSearchQuery.isEmpty()) { + R.string.recycle_bin_empty + } else { + R.string.no_items_found } + + trash_placeholder.text = context.getString(stringId) + } + + val adapter = getRecordingsAdapter() + if (adapter == null) { + TrashAdapter(context as SimpleActivity, recordings, this, trash_list).apply { + trash_list.adapter = this + } + + if (context.areSystemAnimationsEnabled) { + trash_list.scheduleLayoutAnimation() + } + } else { + adapter.updateItems(recordings) } } @@ -106,7 +98,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 @@ -114,8 +106,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 @@