From 2d6fce812ee3569179f278dea173c0b03542e830 Mon Sep 17 00:00:00 2001 From: tibbi Date: Tue, 31 Mar 2020 23:30:56 +0200 Subject: [PATCH] show a couple extra fields at the recordings --- app/build.gradle | 2 +- .../adapters/RecordingsAdapter.kt | 13 +++- .../voicerecorder/fragments/PlayerFragment.kt | 14 ++++- .../voicerecorder/models/Recording.kt | 2 +- app/src/main/res/layout/item_recording.xml | 63 ++++++++++++++++--- 5 files changed, 80 insertions(+), 14 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 99642cd..e855806 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -57,7 +57,7 @@ android { } dependencies { - implementation 'com.simplemobiletools:commons:5.24.5' + implementation 'com.simplemobiletools:commons:5.24.6' implementation 'org.greenrobot:eventbus:3.2.0' implementation 'com.github.Armen101:AudioRecordView:1.0.2' } diff --git a/app/src/main/kotlin/com/simplemobiletools/voicerecorder/adapters/RecordingsAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/voicerecorder/adapters/RecordingsAdapter.kt index e57fbc7..ca7bfff 100644 --- a/app/src/main/kotlin/com/simplemobiletools/voicerecorder/adapters/RecordingsAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/voicerecorder/adapters/RecordingsAdapter.kt @@ -3,7 +3,11 @@ package com.simplemobiletools.voicerecorder.adapters import android.view.Menu import android.view.View import android.view.ViewGroup +import android.widget.TextView import com.simplemobiletools.commons.adapters.MyRecyclerViewAdapter +import com.simplemobiletools.commons.extensions.formatDate +import com.simplemobiletools.commons.extensions.formatSize +import com.simplemobiletools.commons.extensions.getFormattedDuration import com.simplemobiletools.commons.views.FastScroller import com.simplemobiletools.commons.views.MyRecyclerView import com.simplemobiletools.voicerecorder.R @@ -53,7 +57,14 @@ class RecordingsAdapter(activity: SimpleActivity, var recordings: ArrayList(recording_title, recording_date, recording_duration, recording_size).forEach { + it.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 80618c5..0e894a0 100644 --- a/app/src/main/kotlin/com/simplemobiletools/voicerecorder/fragments/PlayerFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/voicerecorder/fragments/PlayerFragment.kt @@ -6,6 +6,7 @@ import android.database.Cursor import android.provider.MediaStore import android.util.AttributeSet import com.simplemobiletools.commons.extensions.getIntValue +import com.simplemobiletools.commons.extensions.getLongValue import com.simplemobiletools.commons.extensions.getStringValue import com.simplemobiletools.commons.extensions.showErrorToast import com.simplemobiletools.voicerecorder.activities.SimpleActivity @@ -44,8 +45,11 @@ class PlayerFragment(context: Context, attributeSet: AttributeSet) : MyViewPager val uri = MediaStore.Audio.Media.getContentUri(MediaStore.VOLUME_EXTERNAL_PRIMARY) val projection = arrayOf( + MediaStore.Audio.Media._ID, MediaStore.Audio.Media.TITLE, - MediaStore.Audio.Media._ID + MediaStore.Audio.Media.DATE_ADDED, + MediaStore.Audio.Media.DURATION, + MediaStore.Audio.Media.SIZE ) val selection = "${MediaStore.Audio.Media.OWNER_PACKAGE_NAME} = ?" @@ -57,9 +61,13 @@ class PlayerFragment(context: Context, attributeSet: AttributeSet) : MyViewPager cursor = context.contentResolver.query(uri, projection, selection, selectionArgs, sorting) if (cursor?.moveToFirst() == true) { do { - val title = cursor.getStringValue(MediaStore.Audio.Media.TITLE) val id = cursor.getIntValue(MediaStore.Audio.Media._ID) - val recording = Recording(id, title, "") + val title = cursor.getStringValue(MediaStore.Audio.Media.TITLE) + val path = "" + val timestamp = cursor.getIntValue(MediaStore.Audio.Media.DATE_ADDED) + val duration = cursor.getLongValue(MediaStore.Audio.Media.DURATION) / 1000 + val size = cursor.getIntValue(MediaStore.Audio.Media.SIZE) + val recording = Recording(id, title, "", timestamp, duration.toInt(), size) recordings.add(recording) } while (cursor.moveToNext()) } 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 fbad089..66f1f05 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 -data class Recording(val id: Int, val title: String, val path: String) +data class Recording(val id: Int, val title: String, val path: String, val timestamp: Int, val duration: Int, val size: Int) diff --git a/app/src/main/res/layout/item_recording.xml b/app/src/main/res/layout/item_recording.xml index 2925afa..ee625d1 100644 --- a/app/src/main/res/layout/item_recording.xml +++ b/app/src/main/res/layout/item_recording.xml @@ -9,15 +9,62 @@ android:focusable="true" android:foreground="@drawable/selector"> - + android:padding="@dimen/activity_margin"> + + + + + + + + +