fix #21, allow choosing between m4a and mp3 file extension

This commit is contained in:
tibbi 2020-09-28 22:31:57 +02:00
parent 60f03ee281
commit c8d3c97d10
7 changed files with 72 additions and 2 deletions

View File

@ -56,7 +56,7 @@ android {
}
dependencies {
implementation 'com.simplemobiletools:commons:5.30.12'
implementation 'com.simplemobiletools:commons:5.30.24'
implementation 'org.greenrobot:eventbus:3.2.0'
implementation 'com.github.Armen101:AudioRecordView:1.0.2'
implementation 'androidx.documentfile:documentfile:1.0.1'

View File

@ -3,10 +3,14 @@ package com.simplemobiletools.voicerecorder.activities
import android.os.Bundle
import com.simplemobiletools.commons.dialogs.ChangeDateTimeFormatDialog
import com.simplemobiletools.commons.dialogs.FilePickerDialog
import com.simplemobiletools.commons.dialogs.RadioGroupDialog
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.isQPlus
import com.simplemobiletools.commons.models.RadioItem
import com.simplemobiletools.voicerecorder.R
import com.simplemobiletools.voicerecorder.extensions.config
import com.simplemobiletools.voicerecorder.helpers.EXTENSION_M4A
import com.simplemobiletools.voicerecorder.helpers.EXTENSION_MP3
import kotlinx.android.synthetic.main.activity_settings.*
import java.util.*
@ -26,6 +30,7 @@ class SettingsActivity : SimpleActivity() {
setupChangeDateTimeFormat()
setupHideNotification()
setupSaveRecordingsFolder()
setupExtension()
updateTextColors(settings_scrollview)
}
@ -81,4 +86,18 @@ class SettingsActivity : SimpleActivity() {
}
}
}
private fun setupExtension() {
settings_extension.text = config.getExtensionText()
settings_extension_holder.setOnClickListener {
val items = arrayListOf(
RadioItem(EXTENSION_M4A, getString(R.string.m4a)),
RadioItem(EXTENSION_MP3, getString(R.string.mp3)))
RadioGroupDialog(this@SettingsActivity, items, config.extension) {
config.extension = it as Int
settings_extension.text = config.getExtensionText()
}
}
}
}

View File

@ -16,4 +16,13 @@ class Config(context: Context) : BaseConfig(context) {
var saveRecordingsFolder: String
get() = prefs.getString(SAVE_RECORDINGS, "$internalStoragePath/${context.getString(R.string.app_name)}")!!
set(saveRecordingsFolder) = prefs.edit().putString(SAVE_RECORDINGS, saveRecordingsFolder).apply()
var extension: Int
get() = prefs.getInt(EXTENSION, EXTENSION_M4A)
set(extension) = prefs.edit().putInt(EXTENSION, extension).apply()
fun getExtensionText() = context.getString(when (extension) {
EXTENSION_M4A -> R.string.m4a
else -> R.string.mp3
})
}

View File

@ -12,10 +12,13 @@ const val RECORDER_RUNNING_NOTIF_ID = 10000
private const val PATH = "com.simplemobiletools.voicerecorder.action."
const val GET_RECORDER_INFO = PATH + "GET_RECORDER_INFO"
const val STOP_AMPLITUDE_UPDATE = PATH + "STOP_AMPLITUDE_UPDATE"
const val EXTENSION_M4A = 0
const val EXTENSION_MP3 = 1
// shared preferences
const val HIDE_NOTIFICATION = "hide_notification"
const val SAVE_RECORDINGS = "save_recordings"
const val EXTENSION = "extension"
@SuppressLint("InlinedApi")
fun getAudioFileContentUri(id: Long): Uri {

View File

@ -71,7 +71,7 @@ class RecorderService : Service() {
defaultFolder.absolutePath
}
currFilePath = "$baseFolder/${getCurrentFormattedDateTime()}.m4a"
currFilePath = "$baseFolder/${getCurrentFormattedDateTime()}.${config.getExtensionText()}"
recorder = MediaRecorder().apply {
setAudioSource(MediaRecorder.AudioSource.CAMCORDER)
setOutputFormat(MediaRecorder.OutputFormat.MPEG_4)

View File

@ -153,5 +153,37 @@
android:maxLines="3" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/settings_extension_holder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/medium_margin"
android:background="?attr/selectableItemBackground"
android:paddingLeft="@dimen/normal_margin"
android:paddingTop="@dimen/bigger_margin"
android:paddingRight="@dimen/normal_margin"
android:paddingBottom="@dimen/bigger_margin">
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/settings_extension_label"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toStartOf="@+id/settings_extension"
android:paddingLeft="@dimen/medium_margin"
android:paddingRight="@dimen/medium_margin"
android:text="@string/extension" />
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/settings_extension"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_marginEnd="@dimen/small_margin"
android:background="@null"
android:clickable="false" />
</RelativeLayout>
</LinearLayout>
</ScrollView>

View File

@ -0,0 +1,7 @@
<resources>
<string name="package_name">com.simplemobiletools.voicerecorder</string>
<string name="m4a">m4a</string>
<string name="mp3">mp3</string>
</resources>