WIP Subscription settings
This commit is contained in:
parent
c67af7f958
commit
80570eb323
7 changed files with 140 additions and 4 deletions
|
@ -57,6 +57,15 @@
|
|||
android:value=".ui.MainActivity"/>
|
||||
</activity>
|
||||
|
||||
<!-- Detail settings activity -->
|
||||
<activity
|
||||
android:name=".ui.DetailSettingsActivity"
|
||||
android:parentActivityName=".ui.DetailActivity">
|
||||
<meta-data
|
||||
android:name="android.support.PARENT_ACTIVITY"
|
||||
android:value=".ui.DetailActivity"/>
|
||||
</activity>
|
||||
|
||||
<!-- Subscriber foreground service for hosts other than ntfy.sh -->
|
||||
<service android:name=".service.SubscriberService"/>
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ import android.app.AlertDialog
|
|||
import android.content.ClipData
|
||||
import android.content.ClipboardManager
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.text.Html
|
||||
import android.view.ActionMode
|
||||
|
@ -220,15 +221,15 @@ class DetailActivity : AppCompatActivity(), ActionMode.Callback, NotificationFra
|
|||
true
|
||||
}
|
||||
R.id.detail_menu_notifications_enabled -> {
|
||||
onNotificationSettingsClick(enable = false)
|
||||
onMutedUntilClick(enable = false)
|
||||
true
|
||||
}
|
||||
R.id.detail_menu_notifications_disabled_until -> {
|
||||
onNotificationSettingsClick(enable = true)
|
||||
onMutedUntilClick(enable = true)
|
||||
true
|
||||
}
|
||||
R.id.detail_menu_notifications_disabled_forever -> {
|
||||
onNotificationSettingsClick(enable = true)
|
||||
onMutedUntilClick(enable = true)
|
||||
true
|
||||
}
|
||||
R.id.detail_menu_enable_instant -> {
|
||||
|
@ -251,6 +252,10 @@ class DetailActivity : AppCompatActivity(), ActionMode.Callback, NotificationFra
|
|||
onClearClick()
|
||||
true
|
||||
}
|
||||
R.id.detail_menu_settings -> {
|
||||
onSettingsClick()
|
||||
true
|
||||
}
|
||||
R.id.detail_menu_unsubscribe -> {
|
||||
onDeleteClick()
|
||||
true
|
||||
|
@ -283,7 +288,7 @@ class DetailActivity : AppCompatActivity(), ActionMode.Callback, NotificationFra
|
|||
}
|
||||
}
|
||||
|
||||
private fun onNotificationSettingsClick(enable: Boolean) {
|
||||
private fun onMutedUntilClick(enable: Boolean) {
|
||||
if (!enable) {
|
||||
Log.d(TAG, "Showing notification settings dialog for ${topicShortUrl(subscriptionBaseUrl, subscriptionTopic)}")
|
||||
val notificationFragment = NotificationFragment()
|
||||
|
@ -441,6 +446,11 @@ class DetailActivity : AppCompatActivity(), ActionMode.Callback, NotificationFra
|
|||
dialog.show()
|
||||
}
|
||||
|
||||
private fun onSettingsClick() {
|
||||
Log.d(TAG, "Opening subscription settings for ${topicShortUrl(subscriptionBaseUrl, subscriptionTopic)}")
|
||||
startActivity(Intent(this, DetailSettingsActivity::class.java))
|
||||
}
|
||||
|
||||
private fun onDeleteClick() {
|
||||
Log.d(TAG, "Deleting subscription ${topicShortUrl(subscriptionBaseUrl, subscriptionTopic)}")
|
||||
|
||||
|
|
|
@ -0,0 +1,93 @@
|
|||
package io.heckel.ntfy.ui
|
||||
|
||||
import android.Manifest
|
||||
import android.content.ClipData
|
||||
import android.content.ClipboardManager
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.pm.PackageManager
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.text.TextUtils
|
||||
import android.widget.Toast
|
||||
import androidx.annotation.Keep
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.appcompat.app.AppCompatDelegate
|
||||
import androidx.core.app.ActivityCompat
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.fragment.app.DialogFragment
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.preference.*
|
||||
import androidx.preference.Preference.OnPreferenceClickListener
|
||||
import com.google.gson.Gson
|
||||
import io.heckel.ntfy.BuildConfig
|
||||
import io.heckel.ntfy.R
|
||||
import io.heckel.ntfy.db.Repository
|
||||
import io.heckel.ntfy.db.User
|
||||
import io.heckel.ntfy.log.Log
|
||||
import io.heckel.ntfy.service.SubscriberService
|
||||
import io.heckel.ntfy.service.SubscriberServiceManager
|
||||
import io.heckel.ntfy.util.formatBytes
|
||||
import io.heckel.ntfy.util.formatDateShort
|
||||
import io.heckel.ntfy.util.shortUrl
|
||||
import io.heckel.ntfy.util.toPriorityString
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import okhttp3.OkHttpClient
|
||||
import okhttp3.Request
|
||||
import okhttp3.RequestBody.Companion.toRequestBody
|
||||
import java.util.*
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
/**
|
||||
* Subscription settings
|
||||
*/
|
||||
class DetailSettingsActivity : AppCompatActivity() {
|
||||
private lateinit var repository: Repository
|
||||
private lateinit var serviceManager: SubscriberServiceManager
|
||||
private lateinit var settingsFragment: SettingsFragment
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_settings)
|
||||
|
||||
Log.d(TAG, "Create $this")
|
||||
|
||||
repository = Repository.getInstance(this)
|
||||
serviceManager = SubscriberServiceManager(this)
|
||||
|
||||
if (savedInstanceState == null) {
|
||||
settingsFragment = SettingsFragment() // Empty constructor!
|
||||
supportFragmentManager
|
||||
.beginTransaction()
|
||||
.replace(R.id.settings_layout, settingsFragment)
|
||||
.commit()
|
||||
}
|
||||
|
||||
title = getString(R.string.detail_settings_title)
|
||||
|
||||
// Show 'Back' button
|
||||
supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
||||
}
|
||||
|
||||
class SettingsFragment : PreferenceFragmentCompat() {
|
||||
private lateinit var repository: Repository
|
||||
private lateinit var serviceManager: SubscriberServiceManager
|
||||
|
||||
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
|
||||
setPreferencesFromResource(R.xml.detail_preferences, rootKey)
|
||||
|
||||
// Dependencies (Fragments need a default constructor)
|
||||
repository = Repository.getInstance(requireActivity())
|
||||
serviceManager = SubscriberServiceManager(requireActivity())
|
||||
|
||||
|
||||
// xxxxxxxxxxxxxxx
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val TAG = "NtfyDetailSettingsActiv"
|
||||
}
|
||||
}
|
|
@ -14,5 +14,6 @@
|
|||
<item android:id="@+id/detail_menu_test" android:title="@string/detail_menu_test"/>
|
||||
<item android:id="@+id/detail_menu_copy_url" android:title="@string/detail_menu_copy_url"/>
|
||||
<item android:id="@+id/detail_menu_clear" android:title="@string/detail_menu_clear"/>
|
||||
<item android:id="@+id/detail_menu_settings" android:title="@string/detail_menu_settings"/>
|
||||
<item android:id="@+id/detail_menu_unsubscribe" android:title="@string/detail_menu_unsubscribe"/>
|
||||
</menu>
|
||||
|
|
|
@ -162,6 +162,7 @@
|
|||
<string name="detail_menu_test">Send test notification</string>
|
||||
<string name="detail_menu_copy_url">Copy topic address</string>
|
||||
<string name="detail_menu_clear">Clear all notifications</string>
|
||||
<string name="detail_menu_settings">Subscription settings</string>
|
||||
<string name="detail_menu_unsubscribe">Unsubscribe</string>
|
||||
|
||||
<!-- Detail activity: Action mode -->
|
||||
|
@ -173,6 +174,15 @@
|
|||
<string name="detail_action_mode_delete_dialog_permanently_delete">Permanently delete</string>
|
||||
<string name="detail_action_mode_delete_dialog_cancel">Cancel</string>
|
||||
|
||||
<!-- Detail settings -->
|
||||
<string name="detail_settings_title">Subscription settings</string>
|
||||
<string name="detail_settings_auth_header">Login</string>
|
||||
<string name="detail_settings_auth_header_summary">For topics that require a login, you may pick the login user here. You can add/edit users in the main settings.</string>
|
||||
<string name="detail_settings_auth_user_key">SubscriptionAuthUserKey</string>
|
||||
<string name="detail_settings_auth_user_title">Login user</string>
|
||||
<string name="detail_settings_auth_user_summary_none">No user selected to log in to the topic</string>
|
||||
<string name="detail_settings_auth_user_summary_user_x">User %1$s selected as a login user</string>
|
||||
|
||||
<!-- Notification dialog -->
|
||||
<string name="notification_dialog_title">Pause notifications</string>
|
||||
<string name="notification_dialog_cancel">Cancel</string>
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<!-- Main settings -->
|
||||
<string-array name="settings_notifications_muted_until_entries">
|
||||
<item>@string/notification_dialog_show_all</item>
|
||||
<item>@string/notification_dialog_30min</item>
|
||||
|
|
12
app/src/main/res/xml/detail_preferences.xml
Normal file
12
app/src/main/res/xml/detail_preferences.xml
Normal file
|
@ -0,0 +1,12 @@
|
|||
<PreferenceScreen xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
app:title="@string/detail_settings_title">
|
||||
<PreferenceCategory
|
||||
app:title="@string/detail_settings_auth_header"
|
||||
app:summary="@string/detail_settings_auth_header_summary"
|
||||
app:layout="@layout/preference_category_material_edited">
|
||||
<Preference
|
||||
app:key="@string/detail_settings_auth_user_key"
|
||||
app:title="@string/detail_settings_auth_user_title"
|
||||
app:summary="@string/detail_settings_auth_user_summary_none"/>
|
||||
</PreferenceCategory>
|
||||
</PreferenceScreen>
|
Loading…
Reference in a new issue