mark the currently playing recording at the list

This commit is contained in:
tibbi 2020-04-01 19:23:29 +02:00
parent b189a12361
commit d13d87eb18
2 changed files with 19 additions and 7 deletions

View File

@ -7,6 +7,7 @@ import android.widget.TextView
import com.simplemobiletools.commons.adapters.MyRecyclerViewAdapter import com.simplemobiletools.commons.adapters.MyRecyclerViewAdapter
import com.simplemobiletools.commons.extensions.formatDate import com.simplemobiletools.commons.extensions.formatDate
import com.simplemobiletools.commons.extensions.formatSize import com.simplemobiletools.commons.extensions.formatSize
import com.simplemobiletools.commons.extensions.getAdjustedPrimaryColor
import com.simplemobiletools.commons.extensions.getFormattedDuration import com.simplemobiletools.commons.extensions.getFormattedDuration
import com.simplemobiletools.commons.views.FastScroller import com.simplemobiletools.commons.views.FastScroller
import com.simplemobiletools.commons.views.MyRecyclerView import com.simplemobiletools.commons.views.MyRecyclerView
@ -18,6 +19,7 @@ import java.util.*
class RecordingsAdapter(activity: SimpleActivity, var recordings: ArrayList<Recording>, recyclerView: MyRecyclerView, fastScroller: FastScroller, class RecordingsAdapter(activity: SimpleActivity, var recordings: ArrayList<Recording>, recyclerView: MyRecyclerView, fastScroller: FastScroller,
itemClick: (Any) -> Unit) : MyRecyclerViewAdapter(activity, recyclerView, fastScroller, itemClick) { itemClick: (Any) -> Unit) : MyRecyclerViewAdapter(activity, recyclerView, fastScroller, itemClick) {
var currRecordingId = 0
init { init {
setupDragListener(true) setupDragListener(true)
@ -53,18 +55,29 @@ class RecordingsAdapter(activity: SimpleActivity, var recordings: ArrayList<Reco
override fun getItemCount() = recordings.size override fun getItemCount() = recordings.size
fun updateCurrentRecording(newId: Int) {
val oldId = currRecordingId
currRecordingId = newId
notifyItemChanged(recordings.indexOfFirst { it.id == oldId })
notifyItemChanged(recordings.indexOfFirst { it.id == newId })
}
private fun setupView(view: View, recording: Recording) { private fun setupView(view: View, recording: Recording) {
view.apply { view.apply {
recording_frame?.isSelected = selectedKeys.contains(recording.id) recording_frame?.isSelected = selectedKeys.contains(recording.id)
recording_title.text = recording.title
recording_date.text = recording.timestamp.formatDate(context)
recording_duration.text = recording.duration.getFormattedDuration()
recording_size.text = recording.size.formatSize()
arrayListOf<TextView>(recording_title, recording_date, recording_duration, recording_size).forEach { arrayListOf<TextView>(recording_title, recording_date, recording_duration, recording_size).forEach {
it.setTextColor(textColor) it.setTextColor(textColor)
} }
if (recording.id == currRecordingId) {
recording_title.setTextColor(context.getAdjustedPrimaryColor())
}
recording_title.text = recording.title
recording_date.text = recording.timestamp.formatDate(context)
recording_duration.text = recording.duration.getFormattedDuration()
recording_size.text = recording.size.formatSize()
} }
} }
} }

View File

@ -11,10 +11,8 @@ import android.os.Looper
import android.os.PowerManager import android.os.PowerManager
import android.provider.MediaStore import android.provider.MediaStore
import android.util.AttributeSet import android.util.AttributeSet
import android.util.Log
import android.widget.SeekBar import android.widget.SeekBar
import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.isOnMainThread
import com.simplemobiletools.voicerecorder.R import com.simplemobiletools.voicerecorder.R
import com.simplemobiletools.voicerecorder.activities.SimpleActivity import com.simplemobiletools.voicerecorder.activities.SimpleActivity
import com.simplemobiletools.voicerecorder.adapters.RecordingsAdapter import com.simplemobiletools.voicerecorder.adapters.RecordingsAdapter
@ -144,6 +142,7 @@ class PlayerFragment(context: Context, attributeSet: AttributeSet) : MyViewPager
player_progressbar.max = recording.duration player_progressbar.max = recording.duration
player_title.text = recording.title player_title.text = recording.title
player_progress_max.text = recording.duration.getFormattedDuration() player_progress_max.text = recording.duration.getFormattedDuration()
(recordings_list.adapter as RecordingsAdapter).updateCurrentRecording(recording.id)
player!!.apply { player!!.apply {
reset() reset()