diff --git a/app/src/main/kotlin/com/simplemobiletools/voicerecorder/adapters/RecordingsAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/voicerecorder/adapters/RecordingsAdapter.kt new file mode 100644 index 0000000..e57fbc7 --- /dev/null +++ b/app/src/main/kotlin/com/simplemobiletools/voicerecorder/adapters/RecordingsAdapter.kt @@ -0,0 +1,59 @@ +package com.simplemobiletools.voicerecorder.adapters + +import android.view.Menu +import android.view.View +import android.view.ViewGroup +import com.simplemobiletools.commons.adapters.MyRecyclerViewAdapter +import com.simplemobiletools.commons.views.FastScroller +import com.simplemobiletools.commons.views.MyRecyclerView +import com.simplemobiletools.voicerecorder.R +import com.simplemobiletools.voicerecorder.activities.SimpleActivity +import com.simplemobiletools.voicerecorder.models.Recording +import kotlinx.android.synthetic.main.item_recording.view.* +import java.util.* + +class RecordingsAdapter(activity: SimpleActivity, var recordings: ArrayList, recyclerView: MyRecyclerView, fastScroller: FastScroller, + itemClick: (Any) -> Unit) : MyRecyclerViewAdapter(activity, recyclerView, fastScroller, itemClick) { + + init { + setupDragListener(true) + } + + override fun getActionMenuId() = R.menu.cab_recordings + + override fun prepareActionMode(menu: Menu) {} + + override fun actionItemPressed(id: Int) {} + + override fun getSelectableItemCount() = recordings.size + + override fun getIsItemSelectable(position: Int) = true + + override fun getItemSelectionKey(position: Int) = recordings.getOrNull(position)?.id + + override fun getItemKeyPosition(key: Int) = recordings.indexOfFirst { it.id == key } + + override fun onActionModeCreated() {} + + override fun onActionModeDestroyed() {} + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = createViewHolder(R.layout.item_recording, parent) + + override fun onBindViewHolder(holder: ViewHolder, position: Int) { + val group = recordings[position] + holder.bindView(group, true, true) { itemView, layoutPosition -> + setupView(itemView, group) + } + bindViewHolder(holder) + } + + override fun getItemCount() = recordings.size + + private fun setupView(view: View, recording: Recording) { + view.apply { + recording_frame?.isSelected = selectedKeys.contains(recording.id) + recording_title.text = recording.title + recording_title.setTextColor(textColor) + } + } +} 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 4573828..00e21b1 100644 --- a/app/src/main/kotlin/com/simplemobiletools/voicerecorder/fragments/PlayerFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/voicerecorder/fragments/PlayerFragment.kt @@ -3,24 +3,39 @@ package com.simplemobiletools.voicerecorder.fragments import android.annotation.SuppressLint import android.content.Context import android.database.Cursor -import android.os.Build import android.provider.MediaStore import android.util.AttributeSet -import androidx.annotation.RequiresApi import com.simplemobiletools.commons.extensions.getIntValue import com.simplemobiletools.commons.extensions.getStringValue import com.simplemobiletools.commons.extensions.showErrorToast +import com.simplemobiletools.voicerecorder.activities.SimpleActivity +import com.simplemobiletools.voicerecorder.adapters.RecordingsAdapter import com.simplemobiletools.voicerecorder.models.Recording +import kotlinx.android.synthetic.main.fragment_player.view.* class PlayerFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerFragment(context, attributeSet) { - override fun onResume() {} + override fun onResume() { + setupColors() + } override fun onDestroy() {} override fun onAttachedToWindow() { super.onAttachedToWindow() - getRecordings() + + val recordings = getRecordings() + RecordingsAdapter(context as SimpleActivity, recordings, recordings_list, recordings_fastscroller) { + + }.apply { + recordings_list.adapter = this + } + + recordings_fastscroller.setScrollToY(0) + recordings_fastscroller.setViews(recordings_list) { + val item = (recordings_list.adapter as RecordingsAdapter).recordings.getOrNull(it) + recordings_fastscroller.updateBubbleText(item?.title ?: "") + } } @SuppressLint("InlinedApi") @@ -56,4 +71,9 @@ class PlayerFragment(context: Context, attributeSet: AttributeSet) : MyViewPager return recordings } + + private fun setupColors() { + recordings_fastscroller.updatePrimaryColor() + recordings_fastscroller.updateBubbleColors() + } } diff --git a/app/src/main/kotlin/com/simplemobiletools/voicerecorder/models/Recording.kt b/app/src/main/kotlin/com/simplemobiletools/voicerecorder/models/Recording.kt index 3e3bcfb..fbad089 100644 --- a/app/src/main/kotlin/com/simplemobiletools/voicerecorder/models/Recording.kt +++ b/app/src/main/kotlin/com/simplemobiletools/voicerecorder/models/Recording.kt @@ -1,3 +1,3 @@ package com.simplemobiletools.voicerecorder.models -class Recording(id: Int, title: String, path: String) +data class Recording(val id: Int, val title: String, val path: String) diff --git a/app/src/main/res/layout/fragment_player.xml b/app/src/main/res/layout/fragment_player.xml index 9bfa085..d75e0ab 100644 --- a/app/src/main/res/layout/fragment_player.xml +++ b/app/src/main/res/layout/fragment_player.xml @@ -1,7 +1,27 @@ + + + + + + + diff --git a/app/src/main/res/layout/item_recording.xml b/app/src/main/res/layout/item_recording.xml new file mode 100644 index 0000000..2925afa --- /dev/null +++ b/app/src/main/res/layout/item_recording.xml @@ -0,0 +1,23 @@ + + + + + + diff --git a/app/src/main/res/menu/cab_recordings.xml b/app/src/main/res/menu/cab_recordings.xml new file mode 100644 index 0000000..61afe8a --- /dev/null +++ b/app/src/main/res/menu/cab_recordings.xml @@ -0,0 +1,4 @@ + + + +