mirror of
https://github.com/SimpleMobileTools/Simple-Voice-Recorder.git
synced 2025-04-17 11:37:29 +02:00
fetch player recordings on a background thread
This commit is contained in:
parent
f8f3313574
commit
c8451ae9b8
@ -62,7 +62,7 @@ android {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'com.github.SimpleMobileTools:Simple-Commons:e0671f01ce'
|
||||
implementation 'com.github.SimpleMobileTools:Simple-Commons:d100d21180'
|
||||
implementation 'org.greenrobot:eventbus:3.3.1'
|
||||
implementation 'com.github.Armen101:AudioRecordView:1.0.4'
|
||||
implementation 'androidx.documentfile:documentfile:1.0.1'
|
||||
|
@ -16,6 +16,7 @@ import android.provider.MediaStore.Audio.Media
|
||||
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.commons.helpers.isRPlus
|
||||
import com.simplemobiletools.voicerecorder.R
|
||||
@ -32,7 +33,6 @@ import org.greenrobot.eventbus.Subscribe
|
||||
import org.greenrobot.eventbus.ThreadMode
|
||||
import java.io.File
|
||||
import java.util.*
|
||||
import kotlin.collections.ArrayList
|
||||
import kotlin.math.roundToLong
|
||||
|
||||
class PlayerFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerFragment(context, attributeSet), RefreshRecordingsListener {
|
||||
@ -136,33 +136,37 @@ class PlayerFragment(context: Context, attributeSet: AttributeSet) : MyViewPager
|
||||
}
|
||||
|
||||
private fun setupAdapter() {
|
||||
val recordings = getRecordings()
|
||||
ensureBackgroundThread {
|
||||
val recordings = getRecordings()
|
||||
|
||||
recordings_fastscroller.beVisibleIf(recordings.isNotEmpty())
|
||||
recordings_placeholder.beVisibleIf(recordings.isEmpty())
|
||||
if (recordings.isEmpty()) {
|
||||
val stringId = if (isQPlus()) R.string.no_recordings_found else R.string.no_recordings_in_folder_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)
|
||||
Handler(Looper.getMainLooper()).post {
|
||||
recordings_fastscroller.beVisibleIf(recordings.isNotEmpty())
|
||||
recordings_placeholder.beVisibleIf(recordings.isEmpty())
|
||||
if (recordings.isEmpty()) {
|
||||
val stringId = if (isQPlus()) R.string.no_recordings_found else R.string.no_recordings_in_folder_found
|
||||
recordings_placeholder.text = context.getString(stringId)
|
||||
resetProgress(null)
|
||||
player?.stop()
|
||||
}
|
||||
}.apply {
|
||||
recordings_list.adapter = this
|
||||
}
|
||||
|
||||
if (context.areSystemAnimationsEnabled) {
|
||||
recordings_list.scheduleLayoutAnimation()
|
||||
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)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
adapter.updateItems(recordings)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -13,9 +13,7 @@ import android.provider.MediaStore
|
||||
import android.provider.MediaStore.Audio.Media
|
||||
import androidx.core.app.NotificationCompat
|
||||
import com.simplemobiletools.commons.extensions.*
|
||||
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
|
||||
import com.simplemobiletools.commons.helpers.isOreoPlus
|
||||
import com.simplemobiletools.commons.helpers.isRPlus
|
||||
import com.simplemobiletools.commons.helpers.*
|
||||
import com.simplemobiletools.voicerecorder.R
|
||||
import com.simplemobiletools.voicerecorder.activities.SplashActivity
|
||||
import com.simplemobiletools.voicerecorder.extensions.config
|
||||
|
Loading…
x
Reference in New Issue
Block a user