list the recordings at the RecordingsFragment
This commit is contained in:
parent
2274c84df3
commit
8c982c4f3b
|
@ -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<Recording>, 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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -3,24 +3,39 @@ package com.simplemobiletools.voicerecorder.fragments
|
||||||
import android.annotation.SuppressLint
|
import android.annotation.SuppressLint
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.database.Cursor
|
import android.database.Cursor
|
||||||
import android.os.Build
|
|
||||||
import android.provider.MediaStore
|
import android.provider.MediaStore
|
||||||
import android.util.AttributeSet
|
import android.util.AttributeSet
|
||||||
import androidx.annotation.RequiresApi
|
|
||||||
import com.simplemobiletools.commons.extensions.getIntValue
|
import com.simplemobiletools.commons.extensions.getIntValue
|
||||||
import com.simplemobiletools.commons.extensions.getStringValue
|
import com.simplemobiletools.commons.extensions.getStringValue
|
||||||
import com.simplemobiletools.commons.extensions.showErrorToast
|
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 com.simplemobiletools.voicerecorder.models.Recording
|
||||||
|
import kotlinx.android.synthetic.main.fragment_player.view.*
|
||||||
|
|
||||||
class PlayerFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerFragment(context, attributeSet) {
|
class PlayerFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerFragment(context, attributeSet) {
|
||||||
|
|
||||||
override fun onResume() {}
|
override fun onResume() {
|
||||||
|
setupColors()
|
||||||
|
}
|
||||||
|
|
||||||
override fun onDestroy() {}
|
override fun onDestroy() {}
|
||||||
|
|
||||||
override fun onAttachedToWindow() {
|
override fun onAttachedToWindow() {
|
||||||
super.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")
|
@SuppressLint("InlinedApi")
|
||||||
|
@ -56,4 +71,9 @@ class PlayerFragment(context: Context, attributeSet: AttributeSet) : MyViewPager
|
||||||
|
|
||||||
return recordings
|
return recordings
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun setupColors() {
|
||||||
|
recordings_fastscroller.updatePrimaryColor()
|
||||||
|
recordings_fastscroller.updateBubbleColors()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
package com.simplemobiletools.voicerecorder.models
|
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)
|
||||||
|
|
|
@ -1,7 +1,27 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<com.simplemobiletools.voicerecorder.fragments.PlayerFragment xmlns:android="http://schemas.android.com/apk/res/android"
|
<com.simplemobiletools.voicerecorder.fragments.PlayerFragment xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
android:id="@+id/player_holder"
|
android:id="@+id/player_holder"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent">
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
|
<com.simplemobiletools.commons.views.MyRecyclerView
|
||||||
|
android:id="@+id/recordings_list"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:layout_below="@+id/breadcrumbs"
|
||||||
|
android:clipToPadding="false"
|
||||||
|
android:scrollbars="none"
|
||||||
|
app:layoutManager="com.simplemobiletools.commons.views.MyLinearLayoutManager" />
|
||||||
|
|
||||||
|
<com.simplemobiletools.commons.views.FastScroller
|
||||||
|
android:id="@+id/recordings_fastscroller"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:layout_alignParentEnd="true"
|
||||||
|
android:paddingStart="@dimen/normal_margin">
|
||||||
|
|
||||||
|
<include layout="@layout/fastscroller_handle_vertical" />
|
||||||
|
|
||||||
|
</com.simplemobiletools.commons.views.FastScroller>
|
||||||
</com.simplemobiletools.voicerecorder.fragments.PlayerFragment>
|
</com.simplemobiletools.voicerecorder.fragments.PlayerFragment>
|
||||||
|
|
|
@ -0,0 +1,23 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:id="@+id/recording_frame"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:background="?attr/selectableItemBackground"
|
||||||
|
android:clickable="true"
|
||||||
|
android:focusable="true"
|
||||||
|
android:foreground="@drawable/selector">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/recording_title"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:ellipsize="end"
|
||||||
|
android:gravity="center_vertical"
|
||||||
|
android:maxLines="1"
|
||||||
|
android:padding="@dimen/activity_margin"
|
||||||
|
android:textSize="@dimen/big_text_size"
|
||||||
|
tools:text="2020_03_30_22_49_52.mp3" />
|
||||||
|
|
||||||
|
</FrameLayout>
|
|
@ -0,0 +1,4 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<menu>
|
||||||
|
|
||||||
|
</menu>
|
Loading…
Reference in New Issue