add display names for UP subscriptions
This commit is contained in:
parent
79fe21566c
commit
b850378c0d
5 changed files with 69 additions and 17 deletions
|
@ -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<String> {
|
||||
return registerForActivityResult(ActivityResultContracts.GetContent()) { inputUri ->
|
||||
if (inputUri == null) {
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -358,6 +358,9 @@
|
|||
<string name="detail_settings_appearance_display_name_default_summary">%1$s (default)</string>
|
||||
<string name="detail_settings_global_setting_title">Use global setting</string>
|
||||
<string name="detail_settings_global_setting_suffix">using global setting</string>
|
||||
<string name="detail_settings_about_header">About</string>
|
||||
<string name="detail_settings_about_topic_url_title">Topic URL</string>
|
||||
<string name="detail_settings_about_topic_url_copied_to_clipboard_message">Copied to clipboard</string>
|
||||
|
||||
<!-- User add/edit dialog -->
|
||||
<string name="user_dialog_title_add">Add user</string>
|
||||
|
|
|
@ -30,13 +30,17 @@
|
|||
<string name="settings_about_version_key" translatable="false">Version</string>
|
||||
|
||||
<!-- Detail settings constants -->
|
||||
<string name="detail_settings_notifications_header_key" translatable="false">SubscriptionNotifications</string>
|
||||
<string name="detail_settings_notifications_instant_key" translatable="false">SubscriptionInstant</string>
|
||||
<string name="detail_settings_notifications_muted_until_key" translatable="false">SubscriptionMutedUntil</string>
|
||||
<string name="detail_settings_notifications_min_priority_key" translatable="false">SubscriptionMinPriority</string>
|
||||
<string name="detail_settings_notifications_auto_delete_key" translatable="false">SubscriptionAutoDelete</string>
|
||||
<string name="detail_settings_appearance_header_key" translatable="false">SubscriptionAppearance</string>
|
||||
<string name="detail_settings_appearance_icon_set_key" translatable="false">SubscriptionIconSet</string>
|
||||
<string name="detail_settings_appearance_icon_remove_key" translatable="false">SubscriptionIconRemove</string>
|
||||
<string name="detail_settings_appearance_display_name_key" translatable="false">SubscriptionDisplayName</string>
|
||||
<string name="detail_settings_about_header_key" translatable="false">SubscriptionAbout</string>
|
||||
<string name="detail_settings_about_topic_url_key" translatable="false">SubscriptionTopicURL</string>
|
||||
|
||||
<!-- Main settings -->
|
||||
<string-array name="settings_notifications_muted_until_entries">
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
<PreferenceScreen xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
app:title="@string/detail_settings_title">
|
||||
<PreferenceCategory app:title="@string/settings_notifications_header">
|
||||
<PreferenceCategory
|
||||
app:key="@string/detail_settings_notifications_header_key"
|
||||
app:title="@string/settings_notifications_header">
|
||||
<SwitchPreference
|
||||
app:key="@string/detail_settings_notifications_instant_key"
|
||||
app:title="@string/detail_settings_notifications_instant_title"
|
||||
|
@ -27,7 +29,9 @@
|
|||
app:defaultValue="-1"
|
||||
app:isPreferenceVisible="false"/> <!-- Same as Repository.AUTO_DELETE_USE_GLOBAL -->
|
||||
</PreferenceCategory>
|
||||
<PreferenceCategory app:title="@string/detail_settings_appearance_header">
|
||||
<PreferenceCategory
|
||||
app:key="@string/detail_settings_appearance_header_key"
|
||||
app:title="@string/detail_settings_appearance_header">
|
||||
<Preference
|
||||
app:key="@string/detail_settings_appearance_icon_set_key"
|
||||
app:title="@string/detail_settings_appearance_icon_set_title"
|
||||
|
@ -45,4 +49,11 @@
|
|||
app:dialogMessage="@string/detail_settings_appearance_display_name_message"
|
||||
app:isPreferenceVisible="false"/>
|
||||
</PreferenceCategory>
|
||||
<PreferenceCategory
|
||||
app:key="@string/detail_settings_about_header_key"
|
||||
app:title="@string/detail_settings_about_header">
|
||||
<Preference
|
||||
app:key="@string/detail_settings_about_topic_url_key"
|
||||
app:title="@string/detail_settings_about_topic_url_title"/>
|
||||
</PreferenceCategory>
|
||||
</PreferenceScreen>
|
||||
|
|
Loading…
Reference in a new issue