From b850378c0de6bcd694e138510ca1020f842501f2 Mon Sep 17 00:00:00 2001 From: Hunter Kehoe Date: Fri, 1 Jul 2022 20:30:30 -0700 Subject: [PATCH] add display names for UP subscriptions --- .../heckel/ntfy/ui/DetailSettingsActivity.kt | 42 ++++++++++++++++--- .../java/io/heckel/ntfy/ui/MainActivity.kt | 22 ++++++---- app/src/main/res/values/strings.xml | 3 ++ app/src/main/res/values/values.xml | 4 ++ app/src/main/res/xml/detail_preferences.xml | 15 ++++++- 5 files changed, 69 insertions(+), 17 deletions(-) diff --git a/app/src/main/java/io/heckel/ntfy/ui/DetailSettingsActivity.kt b/app/src/main/java/io/heckel/ntfy/ui/DetailSettingsActivity.kt index 0025251..5082708 100644 --- a/app/src/main/java/io/heckel/ntfy/ui/DetailSettingsActivity.kt +++ b/app/src/main/java/io/heckel/ntfy/ui/DetailSettingsActivity.kt @@ -1,6 +1,9 @@ package io.heckel.ntfy.ui import android.content.ContentResolver +import android.content.ClipData +import android.content.ClipboardManager +import android.content.Context import android.graphics.BitmapFactory import android.net.Uri import android.os.Bundle @@ -13,6 +16,7 @@ import androidx.core.content.FileProvider import androidx.core.graphics.drawable.toDrawable import androidx.lifecycle.lifecycleScope import androidx.preference.* +import androidx.preference.Preference.OnPreferenceClickListener import io.heckel.ntfy.BuildConfig import io.heckel.ntfy.R import io.heckel.ntfy.db.Repository @@ -102,13 +106,21 @@ class DetailSettingsActivity : AppCompatActivity() { } private fun loadView() { - loadInstantPref() - loadMutedUntilPref() - loadMinPriorityPref() - loadAutoDeletePref() - loadIconSetPref() - loadIconRemovePref() + if (subscription.upAppId == null) { + loadInstantPref() + loadMutedUntilPref() + loadMinPriorityPref() + loadAutoDeletePref() + loadIconSetPref() + loadIconRemovePref() + } else { + val notificationsHeaderId = context?.getString(R.string.detail_settings_notifications_header_key) ?: return + val notificationsHeader: PreferenceCategory? = findPreference(notificationsHeaderId) + notificationsHeader?.isVisible = false + } + loadDisplayNamePref() + loadTopicUrlPref() } private fun loadInstantPref() { @@ -312,6 +324,24 @@ class DetailSettingsActivity : AppCompatActivity() { } } + private fun loadTopicUrlPref() { + // Topic URL + val topicUrlPrefId = context?.getString(R.string.detail_settings_about_topic_url_key) ?: return + val topicUrlPref: Preference? = findPreference(topicUrlPrefId) + val topicUrl = topicShortUrl(subscription.baseUrl, subscription.topic) + topicUrlPref?.summary = topicUrl + topicUrlPref?.onPreferenceClickListener = OnPreferenceClickListener { + val context = context ?: return@OnPreferenceClickListener false + val clipboard = context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager + val clip = ClipData.newPlainText("topic url", topicUrl) + clipboard.setPrimaryClip(clip) + Toast + .makeText(context, getString(R.string.detail_settings_about_topic_url_copied_to_clipboard_message), Toast.LENGTH_LONG) + .show() + true + } + } + private fun createIconPickLauncher(): ActivityResultLauncher { return registerForActivityResult(ActivityResultContracts.GetContent()) { inputUri -> if (inputUri == null) { diff --git a/app/src/main/java/io/heckel/ntfy/ui/MainActivity.kt b/app/src/main/java/io/heckel/ntfy/ui/MainActivity.kt index 10b7228..36ac290 100644 --- a/app/src/main/java/io/heckel/ntfy/ui/MainActivity.kt +++ b/app/src/main/java/io/heckel/ntfy/ui/MainActivity.kt @@ -470,20 +470,12 @@ class MainActivity : AppCompatActivity(), ActionMode.Callback, AddFragment.Subsc if (actionMode != null) { handleActionModeClick(subscription) } else if (subscription.upAppId != null) { // Not UnifiedPush - displayUnifiedPushToast(subscription) + startDetailSettingsView(subscription) } else { startDetailView(subscription) } } - private fun displayUnifiedPushToast(subscription: Subscription) { - runOnUiThread { - val appId = subscription.upAppId ?: return@runOnUiThread - val toastMessage = getString(R.string.main_unified_push_toast, appId) - Toast.makeText(this@MainActivity, toastMessage, Toast.LENGTH_LONG).show() - } - } - private fun onSubscriptionItemLongClick(subscription: Subscription) { if (actionMode == null) { beginActionMode(subscription) @@ -543,6 +535,18 @@ class MainActivity : AppCompatActivity(), ActionMode.Callback, AddFragment.Subsc startActivity(intent) } + private fun startDetailSettingsView(subscription: Subscription) { + Log.d(TAG, "Opening subscription settings for ${topicShortUrl(subscription.baseUrl, subscription.topic)}") + + val intent = Intent(this, DetailSettingsActivity::class.java) + intent.putExtra(DetailActivity.EXTRA_SUBSCRIPTION_ID, subscription.id) + intent.putExtra(DetailActivity.EXTRA_SUBSCRIPTION_BASE_URL, subscription.baseUrl) + intent.putExtra(DetailActivity.EXTRA_SUBSCRIPTION_TOPIC, subscription.topic) + intent.putExtra(DetailActivity.EXTRA_SUBSCRIPTION_DISPLAY_NAME, displayName(subscription)) + startActivity(intent) + } + + private fun handleActionModeClick(subscription: Subscription) { adapter.toggleSelection(subscription.id) if (adapter.selected.size == 0) { diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 41271e1..466cd40 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -358,6 +358,9 @@ %1$s (default) Use global setting using global setting + About + Topic URL + Copied to clipboard Add user diff --git a/app/src/main/res/values/values.xml b/app/src/main/res/values/values.xml index d5b4859..93f8c70 100644 --- a/app/src/main/res/values/values.xml +++ b/app/src/main/res/values/values.xml @@ -30,13 +30,17 @@ Version + SubscriptionNotifications SubscriptionInstant SubscriptionMutedUntil SubscriptionMinPriority SubscriptionAutoDelete + SubscriptionAppearance SubscriptionIconSet SubscriptionIconRemove SubscriptionDisplayName + SubscriptionAbout + SubscriptionTopicURL diff --git a/app/src/main/res/xml/detail_preferences.xml b/app/src/main/res/xml/detail_preferences.xml index 184bdb4..e209f16 100644 --- a/app/src/main/res/xml/detail_preferences.xml +++ b/app/src/main/res/xml/detail_preferences.xml @@ -1,6 +1,8 @@ - + - + + + +