MutedUntil setting in Settings dialog
This commit is contained in:
parent
1c6dd84543
commit
1ce42048b5
5 changed files with 64 additions and 11 deletions
app/src/main
java/io/heckel/ntfy/ui
res
|
@ -169,7 +169,7 @@ class MainActivity : AppCompatActivity(), ActionMode.Callback, AddFragment.Subsc
|
||||||
|
|
||||||
private fun startNotificationMutedChecker() {
|
private fun startNotificationMutedChecker() {
|
||||||
lifecycleScope.launch(Dispatchers.IO) {
|
lifecycleScope.launch(Dispatchers.IO) {
|
||||||
delay(1000) // Just to be sure we've initialized all the things, we wait a bit ...
|
delay(5000) // Just to be sure we've initialized all the things, we wait a bit ...
|
||||||
while (isActive) {
|
while (isActive) {
|
||||||
Log.d(DetailActivity.TAG, "Checking global and subscription-specific 'muted until' timestamp")
|
Log.d(DetailActivity.TAG, "Checking global and subscription-specific 'muted until' timestamp")
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@ import android.app.AlertDialog
|
||||||
import android.app.Dialog
|
import android.app.Dialog
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import android.util.Log
|
||||||
import android.widget.RadioButton
|
import android.widget.RadioButton
|
||||||
import androidx.fragment.app.DialogFragment
|
import androidx.fragment.app.DialogFragment
|
||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
|
@ -16,8 +17,9 @@ import kotlinx.coroutines.launch
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
class NotificationFragment : DialogFragment() {
|
class NotificationFragment : DialogFragment() {
|
||||||
|
var settingsListener: NotificationSettingsListener? = null
|
||||||
|
|
||||||
private lateinit var repository: Repository
|
private lateinit var repository: Repository
|
||||||
private lateinit var settingsListener: NotificationSettingsListener
|
|
||||||
private lateinit var muteFor30minButton: RadioButton
|
private lateinit var muteFor30minButton: RadioButton
|
||||||
private lateinit var muteFor1hButton: RadioButton
|
private lateinit var muteFor1hButton: RadioButton
|
||||||
private lateinit var muteFor2hButton: RadioButton
|
private lateinit var muteFor2hButton: RadioButton
|
||||||
|
@ -31,7 +33,9 @@ class NotificationFragment : DialogFragment() {
|
||||||
|
|
||||||
override fun onAttach(context: Context) {
|
override fun onAttach(context: Context) {
|
||||||
super.onAttach(context)
|
super.onAttach(context)
|
||||||
settingsListener = activity as NotificationSettingsListener
|
if (settingsListener == null) {
|
||||||
|
settingsListener = activity as NotificationSettingsListener
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
||||||
|
@ -85,7 +89,7 @@ class NotificationFragment : DialogFragment() {
|
||||||
private fun onClick(mutedUntilTimestamp: Long) {
|
private fun onClick(mutedUntilTimestamp: Long) {
|
||||||
lifecycleScope.launch(Dispatchers.Main) {
|
lifecycleScope.launch(Dispatchers.Main) {
|
||||||
delay(150) // Another hack: Let the animation finish before dismissing the window
|
delay(150) // Another hack: Let the animation finish before dismissing the window
|
||||||
settingsListener.onNotificationMutedUntilChanged(mutedUntilTimestamp)
|
settingsListener?.onNotificationMutedUntilChanged(mutedUntilTimestamp)
|
||||||
dismiss()
|
dismiss()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,12 +8,14 @@ import android.text.TextUtils
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
|
import androidx.fragment.app.FragmentManager
|
||||||
import androidx.preference.*
|
import androidx.preference.*
|
||||||
import androidx.preference.Preference.OnPreferenceClickListener
|
import androidx.preference.Preference.OnPreferenceClickListener
|
||||||
import io.heckel.ntfy.BuildConfig
|
import io.heckel.ntfy.BuildConfig
|
||||||
import io.heckel.ntfy.R
|
import io.heckel.ntfy.R
|
||||||
import io.heckel.ntfy.app.Application
|
import io.heckel.ntfy.app.Application
|
||||||
import io.heckel.ntfy.data.Repository
|
import io.heckel.ntfy.data.Repository
|
||||||
|
import io.heckel.ntfy.util.formatDateShort
|
||||||
|
|
||||||
class SettingsActivity : AppCompatActivity() {
|
class SettingsActivity : AppCompatActivity() {
|
||||||
private val repository by lazy { (application as Application).repository }
|
private val repository by lazy { (application as Application).repository }
|
||||||
|
@ -27,7 +29,7 @@ class SettingsActivity : AppCompatActivity() {
|
||||||
if (savedInstanceState == null) {
|
if (savedInstanceState == null) {
|
||||||
supportFragmentManager
|
supportFragmentManager
|
||||||
.beginTransaction()
|
.beginTransaction()
|
||||||
.replace(R.id.settings_layout, SettingsFragment(repository))
|
.replace(R.id.settings_layout, SettingsFragment(repository, supportFragmentManager))
|
||||||
.commit()
|
.commit()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,7 +40,7 @@ class SettingsActivity : AppCompatActivity() {
|
||||||
supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
class SettingsFragment(val repository: Repository) : PreferenceFragmentCompat() {
|
class SettingsFragment(val repository: Repository, private val supportFragmentManager: FragmentManager) : PreferenceFragmentCompat() {
|
||||||
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
|
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
|
||||||
setPreferencesFromResource(R.xml.main_preferences, rootKey)
|
setPreferencesFromResource(R.xml.main_preferences, rootKey)
|
||||||
|
|
||||||
|
@ -46,6 +48,38 @@ class SettingsActivity : AppCompatActivity() {
|
||||||
// preferenceDataStore is overridden to use the repository. This is convenient, because
|
// preferenceDataStore is overridden to use the repository. This is convenient, because
|
||||||
// everybody has access to the repository.
|
// everybody has access to the repository.
|
||||||
|
|
||||||
|
// Notifications muted until (global)
|
||||||
|
val mutedUntilPrefId = context?.getString(R.string.pref_notifications_muted_until) ?: return
|
||||||
|
val mutedUntilSummary = { s: Long ->
|
||||||
|
when (s) {
|
||||||
|
0L -> getString(R.string.settings_notifications_muted_until_enabled)
|
||||||
|
1L -> getString(R.string.settings_notifications_muted_until_disabled_forever)
|
||||||
|
else -> {
|
||||||
|
val formattedDate = formatDateShort(s)
|
||||||
|
getString(R.string.settings_notifications_muted_until_disabled_until, formattedDate)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
val mutedUntil: Preference? = findPreference(mutedUntilPrefId)
|
||||||
|
mutedUntil?.preferenceDataStore = object : PreferenceDataStore() { } // Dummy store to protect from accidentally overwriting
|
||||||
|
mutedUntil?.summary = mutedUntilSummary(repository.getGlobalMutedUntil())
|
||||||
|
mutedUntil?.onPreferenceClickListener = OnPreferenceClickListener {
|
||||||
|
if (repository.getGlobalMutedUntil() > 0) {
|
||||||
|
repository.setGlobalMutedUntil(0)
|
||||||
|
mutedUntil?.summary = mutedUntilSummary(0)
|
||||||
|
} else {
|
||||||
|
val notificationFragment = NotificationFragment()
|
||||||
|
notificationFragment.settingsListener = object : NotificationFragment.NotificationSettingsListener {
|
||||||
|
override fun onNotificationMutedUntilChanged(mutedUntilTimestamp: Long) {
|
||||||
|
repository.setGlobalMutedUntil(mutedUntilTimestamp)
|
||||||
|
mutedUntil?.summary = mutedUntilSummary(mutedUntilTimestamp)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
notificationFragment.show(supportFragmentManager, NotificationFragment.TAG)
|
||||||
|
}
|
||||||
|
true
|
||||||
|
}
|
||||||
|
|
||||||
// UnifiedPush Enabled
|
// UnifiedPush Enabled
|
||||||
val upEnabledPrefId = context?.getString(R.string.pref_unified_push_enabled) ?: return
|
val upEnabledPrefId = context?.getString(R.string.pref_unified_push_enabled) ?: return
|
||||||
val upEnabled: SwitchPreference? = findPreference(upEnabledPrefId)
|
val upEnabled: SwitchPreference? = findPreference(upEnabledPrefId)
|
||||||
|
|
|
@ -16,8 +16,7 @@
|
||||||
<string name="channel_subscriber_notification_text">You are subscribed to instant delivery topics</string>
|
<string name="channel_subscriber_notification_text">You are subscribed to instant delivery topics</string>
|
||||||
<string name="channel_subscriber_notification_text_one">You are subscribed to one instant delivery topic</string>
|
<string name="channel_subscriber_notification_text_one">You are subscribed to one instant delivery topic</string>
|
||||||
<string name="channel_subscriber_notification_text_two">You are subscribed to two instant delivery topics</string>
|
<string name="channel_subscriber_notification_text_two">You are subscribed to two instant delivery topics</string>
|
||||||
<string name="channel_subscriber_notification_text_three">You are subscribed to three instant delivery topics
|
<string name="channel_subscriber_notification_text_three">You are subscribed to three instant delivery topics</string>
|
||||||
</string>
|
|
||||||
<string name="channel_subscriber_notification_text_four">You are subscribed to four instant delivery topics</string>
|
<string name="channel_subscriber_notification_text_four">You are subscribed to four instant delivery topics</string>
|
||||||
<string name="channel_subscriber_notification_text_more">You are subscribed to %1$d instant delivery topics</string>
|
<string name="channel_subscriber_notification_text_more">You are subscribed to %1$d instant delivery topics</string>
|
||||||
|
|
||||||
|
@ -147,19 +146,26 @@
|
||||||
|
|
||||||
<!-- Settings -->
|
<!-- Settings -->
|
||||||
<string name="settings_title">Settings</string>
|
<string name="settings_title">Settings</string>
|
||||||
|
<string name="settings_notifications_header">Notifications</string>
|
||||||
|
<string name="settings_notifications_header_summary">General settings for all subscribed topics</string>
|
||||||
|
<string name="settings_notifications_muted_until_title">Pause notifications</string>
|
||||||
|
<string name="settings_notifications_muted_until_enabled">All notifications will be displayed</string>
|
||||||
|
<string name="settings_notifications_muted_until_disabled_forever">Notifications muted until re-enabled</string>
|
||||||
|
<string name="settings_notifications_muted_until_disabled_until">Notifications muted until %1$s</string>
|
||||||
<string name="settings_unified_push_header">UnifiedPush</string>
|
<string name="settings_unified_push_header">UnifiedPush</string>
|
||||||
<string name="settings_unified_push_header_summary">Allows other apps to use ntfy as a message distributor. Find out more at unifiedpush.org.</string>
|
<string name="settings_unified_push_header_summary">Allows other apps to use ntfy as a message distributor. Find out more at unifiedpush.org.</string>
|
||||||
<string name="settings_unified_push_enabled_title">Enabled</string>
|
<string name="settings_unified_push_enabled_title">Enable distributor</string>
|
||||||
<string name="settings_unified_push_enabled_summary_on">Apps can use ntfy as distributor</string>
|
<string name="settings_unified_push_enabled_summary_on">Apps can use ntfy as distributor</string>
|
||||||
<string name="settings_unified_push_enabled_summary_off">Apps cannot use ntfy as distributor</string>
|
<string name="settings_unified_push_enabled_summary_off">Apps cannot use ntfy as distributor</string>
|
||||||
<string name="settings_unified_push_base_url_title">Server URL</string>
|
<string name="settings_unified_push_base_url_title">Server URL</string>
|
||||||
<string name="settings_unified_push_base_url_default_summary">%1$s (default)</string>
|
<string name="settings_unified_push_base_url_default_summary">%1$s (default)</string>
|
||||||
<string name="settings_about_header">About</string>
|
<string name="settings_about_header">About</string>
|
||||||
<string name="settings_about_version">Version</string>
|
<string name="settings_about_version_title">Version</string>
|
||||||
<string name="settings_about_version_format">ntfy %1$s (%2$s)</string>
|
<string name="settings_about_version_format">ntfy %1$s (%2$s)</string>
|
||||||
<string name="settings_about_version_copied_to_clipboard_message">Copied to clipboard</string>
|
<string name="settings_about_version_copied_to_clipboard_message">Copied to clipboard</string>
|
||||||
|
|
||||||
<!-- Preferences IDs -->
|
<!-- Preferences IDs -->
|
||||||
|
<string name="pref_notifications_muted_until">MutedUntil</string>
|
||||||
<string name="pref_unified_push_enabled">UnifiedPushEnabled</string>
|
<string name="pref_unified_push_enabled">UnifiedPushEnabled</string>
|
||||||
<string name="pref_unified_push_base_url">UnifiedPushBaseURL</string>
|
<string name="pref_unified_push_base_url">UnifiedPushBaseURL</string>
|
||||||
<string name="pref_version">Version</string>
|
<string name="pref_version">Version</string>
|
||||||
|
|
|
@ -1,5 +1,14 @@
|
||||||
<PreferenceScreen xmlns:app="http://schemas.android.com/apk/res-auto"
|
<PreferenceScreen xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
app:title="@string/settings_title">
|
app:title="@string/settings_title">
|
||||||
|
<PreferenceCategory
|
||||||
|
app:title="@string/settings_notifications_header"
|
||||||
|
app:summary="@string/settings_notifications_header_summary"
|
||||||
|
app:layout="@layout/preference_category_material_edited">
|
||||||
|
<Preference
|
||||||
|
app:key="@string/pref_notifications_muted_until"
|
||||||
|
app:title="@string/settings_notifications_muted_until_title"/>
|
||||||
|
</PreferenceCategory>
|
||||||
<PreferenceCategory
|
<PreferenceCategory
|
||||||
app:title="@string/settings_unified_push_header"
|
app:title="@string/settings_unified_push_header"
|
||||||
app:summary="@string/settings_unified_push_header_summary"
|
app:summary="@string/settings_unified_push_header_summary"
|
||||||
|
@ -16,6 +25,6 @@
|
||||||
<PreferenceCategory app:title="@string/settings_about_header">
|
<PreferenceCategory app:title="@string/settings_about_header">
|
||||||
<Preference
|
<Preference
|
||||||
app:key="@string/pref_version"
|
app:key="@string/pref_version"
|
||||||
app:title="@string/settings_about_version"/>
|
app:title="@string/settings_about_version_title"/>
|
||||||
</PreferenceCategory>
|
</PreferenceCategory>
|
||||||
</PreferenceScreen>
|
</PreferenceScreen>
|
||||||
|
|
Loading…
Add table
Reference in a new issue