allow changing the reminder notification sound, fix #27
This commit is contained in:
parent
91f0fe4955
commit
0fb73b12bf
|
@ -1,6 +1,11 @@
|
|||
package com.simplemobiletools.calendar.activities
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Intent
|
||||
import android.media.RingtoneManager
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import android.os.Parcelable
|
||||
import android.support.v4.app.TaskStackBuilder
|
||||
import android.view.View
|
||||
import android.widget.AdapterView
|
||||
|
@ -10,11 +15,12 @@ import com.simplemobiletools.calendar.extensions.hideKeyboard
|
|||
import com.simplemobiletools.calendar.extensions.showKeyboard
|
||||
import com.simplemobiletools.calendar.extensions.value
|
||||
import com.simplemobiletools.calendar.helpers.*
|
||||
import com.simplemobiletools.filepicker.extensions.getFilenameFromPath
|
||||
import com.simplemobiletools.filepicker.extensions.toast
|
||||
import kotlinx.android.synthetic.main.activity_settings.*
|
||||
|
||||
class SettingsActivity : SimpleActivity() {
|
||||
val GET_RINGTONE_URI = 1
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_settings)
|
||||
|
@ -53,9 +59,19 @@ class SettingsActivity : SimpleActivity() {
|
|||
}
|
||||
|
||||
private fun setupReminderSound() {
|
||||
settings_reminder_sound.text = mConfig.reminderSound.getFilenameFromPath()
|
||||
settings_reminder_sound.text = RingtoneManager.getRingtone(this, Uri.parse(mConfig.reminderSound)).getTitle(this)
|
||||
settings_reminder_sound_holder.setOnClickListener {
|
||||
Intent(RingtoneManager.ACTION_RINGTONE_PICKER).apply {
|
||||
putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_NOTIFICATION)
|
||||
putExtra(RingtoneManager.EXTRA_RINGTONE_TITLE, resources.getString(R.string.notification_sound))
|
||||
putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, Uri.parse(mConfig.reminderSound))
|
||||
|
||||
if (resolveActivity(packageManager) != null)
|
||||
startActivityForResult(this, GET_RINGTONE_URI)
|
||||
else {
|
||||
toast(R.string.no_ringtone_picker)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -132,6 +148,14 @@ class SettingsActivity : SimpleActivity() {
|
|||
custom_reminder_value.setText(value.toString())
|
||||
}
|
||||
|
||||
override fun onActivityResult(requestCode: Int, resultCode: Int, intent: Intent?) {
|
||||
if (resultCode == Activity.RESULT_OK && requestCode == GET_RINGTONE_URI) {
|
||||
val uri = intent?.getParcelableExtra<Parcelable>(RingtoneManager.EXTRA_RINGTONE_PICKED_URI) ?: return
|
||||
settings_reminder_sound.text = RingtoneManager.getRingtone(this, uri as Uri).getTitle(this)
|
||||
mConfig.reminderSound = uri.toString()
|
||||
}
|
||||
}
|
||||
|
||||
private fun restartActivity() {
|
||||
TaskStackBuilder.create(applicationContext).addNextIntentWithParentStack(intent).startActivities()
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ import android.content.SharedPreferences
|
|||
import android.media.RingtoneManager
|
||||
import java.util.*
|
||||
|
||||
class Config(context: Context) {
|
||||
class Config(val context: Context) {
|
||||
private val mPrefs: SharedPreferences
|
||||
|
||||
companion object {
|
||||
|
@ -40,7 +40,7 @@ class Config(context: Context) {
|
|||
set(vibrate) = mPrefs.edit().putBoolean(VIBRATE, vibrate).apply()
|
||||
|
||||
var reminderSound: String
|
||||
get() = mPrefs.getString(REMINDER_SOUND, RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION).toString())
|
||||
get() = mPrefs.getString(REMINDER_SOUND, RingtoneManager.getActualDefaultRingtoneUri(context, RingtoneManager.TYPE_NOTIFICATION).toString())
|
||||
set(path) = mPrefs.edit().putString(REMINDER_SOUND, path).apply()
|
||||
|
||||
var storedView: Int
|
||||
|
|
|
@ -6,7 +6,7 @@ import android.app.PendingIntent
|
|||
import android.content.BroadcastReceiver
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.media.RingtoneManager
|
||||
import android.net.Uri
|
||||
import com.simplemobiletools.calendar.R
|
||||
import com.simplemobiletools.calendar.activities.EventActivity
|
||||
import com.simplemobiletools.calendar.extensions.scheduleNextEvent
|
||||
|
@ -49,7 +49,7 @@ class NotificationReceiver : BroadcastReceiver() {
|
|||
}
|
||||
|
||||
private fun getNotification(context: Context, pendingIntent: PendingIntent, content: String): Notification {
|
||||
val soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)
|
||||
val soundUri = Uri.parse(Config.newInstance(context).reminderSound)
|
||||
val builder = Notification.Builder(context)
|
||||
.setContentTitle(context.resources.getString(R.string.app_name))
|
||||
.setContentText(content)
|
||||
|
|
|
@ -74,6 +74,8 @@
|
|||
<string name="reminder_sound">Reminder sound</string>
|
||||
<string name="default_event_reminder">Standard Termin Erinnerung</string>
|
||||
<string name="reminder_saved">Erinnerung gespeichert</string>
|
||||
<string name="notification_sound">Notification sound</string>
|
||||
<string name="no_ringtone_picker">No app capable of setting ringtone found</string>
|
||||
|
||||
<!-- License -->
|
||||
<string name="notice">Diese App nutzt die folgenden Drittanbieterbibliotheken, die mein Leben einfacher machen. Danke.</string>
|
||||
|
|
|
@ -74,6 +74,8 @@
|
|||
<string name="reminder_sound">Reminder sound</string>
|
||||
<string name="default_event_reminder">Recordatorio predeterminado de un evento</string>
|
||||
<string name="reminder_saved">Recordatorio guardado</string>
|
||||
<string name="notification_sound">Notification sound</string>
|
||||
<string name="no_ringtone_picker">No app capable of setting ringtone found</string>
|
||||
|
||||
<!-- License -->
|
||||
<string name="notice">Esta aplicación utiliza bibliotecas de terceros para hacer mi vida más fácil. Gracias.</string>
|
||||
|
|
|
@ -74,6 +74,8 @@
|
|||
<string name="reminder_sound">Reminder sound</string>
|
||||
<string name="default_event_reminder">Default event reminder</string>
|
||||
<string name="reminder_saved">Reminder saved</string>
|
||||
<string name="notification_sound">Notification sound</string>
|
||||
<string name="no_ringtone_picker">No app capable of setting ringtone found</string>
|
||||
|
||||
<!-- License -->
|
||||
<string name="notice">मेरा जीवन आसान करने के लिए यह एप्प तीसरे पक्ष की लाइब्रेरी का इस्तेमाल करती हैं। धन्यवाद।</string>
|
||||
|
|
|
@ -74,6 +74,8 @@
|
|||
<string name="reminder_sound">Reminder sound</string>
|
||||
<string name="default_event_reminder">Alapértelmezett emlékeztetés</string>
|
||||
<string name="reminder_saved">Emlékeztető elmentve</string>
|
||||
<string name="notification_sound">Notification sound</string>
|
||||
<string name="no_ringtone_picker">No app capable of setting ringtone found</string>
|
||||
|
||||
<!-- License -->
|
||||
<string name="notice">Ez az alkalmazás az alábbi könyvtárakat használja, hogy a munkám egyszerűbb legyen. Köszönöm szépen.</string>
|
||||
|
|
|
@ -74,6 +74,8 @@
|
|||
<string name="reminder_sound">Reminder sound</string>
|
||||
<string name="default_event_reminder">Default event reminder</string>
|
||||
<string name="reminder_saved">Reminder saved</string>
|
||||
<string name="notification_sound">Notification sound</string>
|
||||
<string name="no_ringtone_picker">No app capable of setting ringtone found</string>
|
||||
|
||||
<!-- License -->
|
||||
<string name="notice">Questa app usa le seguenti librerie di terze parti per semplificarmi la vita. Grazie.</string>
|
||||
|
|
|
@ -74,6 +74,8 @@
|
|||
<string name="reminder_sound">Reminder sound</string>
|
||||
<string name="default_event_reminder">デフォルトのイベント リマインダー</string>
|
||||
<string name="reminder_saved">リマインダーを保存しました</string>
|
||||
<string name="notification_sound">Notification sound</string>
|
||||
<string name="no_ringtone_picker">No app capable of setting ringtone found</string>
|
||||
|
||||
<!-- License -->
|
||||
<string name="notice">このアプリは、私の暮らしにゆとりを持たせるために、次のサードパーティのライブラリーを使用しています。 ありがとうございます。</string>
|
||||
|
|
|
@ -74,6 +74,8 @@
|
|||
<string name="reminder_sound">Reminder sound</string>
|
||||
<string name="default_event_reminder">Lembrete padrão</string>
|
||||
<string name="reminder_saved">Lembrete guardado</string>
|
||||
<string name="notification_sound">Notification sound</string>
|
||||
<string name="no_ringtone_picker">No app capable of setting ringtone found</string>
|
||||
|
||||
<!-- License -->
|
||||
<string name="notice">Esta aplicação usa as seguintes bibliotecas de terceiros para facilitar a minha vida. Obrigado.</string>
|
||||
|
|
|
@ -74,6 +74,8 @@
|
|||
<string name="reminder_sound">Reminder sound</string>
|
||||
<string name="default_event_reminder">Default event reminder</string>
|
||||
<string name="reminder_saved">Reminder saved</string>
|
||||
<string name="notification_sound">Notification sound</string>
|
||||
<string name="no_ringtone_picker">No app capable of setting ringtone found</string>
|
||||
|
||||
<!-- License -->
|
||||
<string name="notice">Denna app använder följande tredjepartsbibliotek för att göra mitt liv enklare. Tack.</string>
|
||||
|
|
|
@ -75,6 +75,8 @@
|
|||
<string name="reminder_sound">Reminder sound</string>
|
||||
<string name="default_event_reminder">Default event reminder</string>
|
||||
<string name="reminder_saved">Reminder saved</string>
|
||||
<string name="notification_sound">Notification sound</string>
|
||||
<string name="no_ringtone_picker">No app capable of setting ringtone found</string>
|
||||
|
||||
<!-- License -->
|
||||
<string name="notice">This app uses the following third party libraries to make my life easier. Thank you.</string>
|
||||
|
|
Loading…
Reference in New Issue