diff --git a/app/src/main/java/io/heckel/ntfy/msg/SubscriberService.kt b/app/src/main/java/io/heckel/ntfy/msg/SubscriberService.kt index 2539a22..9466221 100644 --- a/app/src/main/java/io/heckel/ntfy/msg/SubscriberService.kt +++ b/app/src/main/java/io/heckel/ntfy/msg/SubscriberService.kt @@ -131,6 +131,18 @@ class SubscriberService : Service() { cancelJob(subscriptionId) } } + if (jobs.size > 0) { + synchronized(this) { + val title = getString(R.string.channel_subscriber_notification_title) + val text = if (jobs.size == 1) { + getString(R.string.channel_subscriber_notification_text_one) + } else { + getString(R.string.channel_subscriber_notification_text_more, jobs.size) + } + notification = createNotification(title, text) + notificationManager?.notify(NOTIFICATION_SERVICE_ID, notification) + } + } } private fun cancelJob(subscriptionId: Long?) { diff --git a/app/src/main/java/io/heckel/ntfy/ui/AddFragment.kt b/app/src/main/java/io/heckel/ntfy/ui/AddFragment.kt index b04eb25..83d7d40 100644 --- a/app/src/main/java/io/heckel/ntfy/ui/AddFragment.kt +++ b/app/src/main/java/io/heckel/ntfy/ui/AddFragment.kt @@ -1,6 +1,5 @@ package io.heckel.ntfy.ui -import android.app.Activity import android.app.AlertDialog import android.app.Dialog import android.os.Bundle @@ -9,14 +8,10 @@ import android.text.TextWatcher import android.view.View import android.widget.Button import android.widget.CheckBox -import androidx.activity.viewModels import androidx.fragment.app.DialogFragment import androidx.lifecycle.lifecycleScope -import androidx.lifecycle.viewModelScope import com.google.android.material.textfield.TextInputEditText import io.heckel.ntfy.R -import io.heckel.ntfy.app.Application -import io.heckel.ntfy.data.Repository import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch @@ -25,6 +20,7 @@ class AddFragment(private val viewModel: SubscriptionsViewModel, private val onS private lateinit var baseUrlText: TextInputEditText private lateinit var useAnotherServerCheckbox: CheckBox private lateinit var useAnotherServerDescription: View + private lateinit var instantDeliveryBox: View private lateinit var instantDeliveryCheckbox: CheckBox private lateinit var instantDeliveryDescription: View private lateinit var subscribeButton: Button @@ -35,6 +31,7 @@ class AddFragment(private val viewModel: SubscriptionsViewModel, private val onS val view = requireActivity().layoutInflater.inflate(R.layout.add_dialog_fragment, null) topicNameText = view.findViewById(R.id.add_dialog_topic_text) as TextInputEditText baseUrlText = view.findViewById(R.id.add_dialog_base_url_text) as TextInputEditText + instantDeliveryBox = view.findViewById(R.id.add_dialog_instant_delivery_box) instantDeliveryCheckbox = view.findViewById(R.id.add_dialog_instant_delivery_checkbox) as CheckBox instantDeliveryDescription = view.findViewById(R.id.add_dialog_instant_delivery_description) useAnotherServerCheckbox = view.findViewById(R.id.add_dialog_use_another_server_checkbox) as CheckBox @@ -82,12 +79,12 @@ class AddFragment(private val viewModel: SubscriptionsViewModel, private val onS if (isChecked) { useAnotherServerDescription.visibility = View.VISIBLE baseUrlText.visibility = View.VISIBLE - instantDeliveryCheckbox.visibility = View.GONE + instantDeliveryBox.visibility = View.GONE instantDeliveryDescription.visibility = View.GONE } else { useAnotherServerDescription.visibility = View.GONE baseUrlText.visibility = View.GONE - instantDeliveryCheckbox.visibility = View.VISIBLE + instantDeliveryBox.visibility = View.VISIBLE if (instantDeliveryCheckbox.isChecked) instantDeliveryDescription.visibility = View.VISIBLE else instantDeliveryDescription.visibility = View.GONE } diff --git a/app/src/main/java/io/heckel/ntfy/ui/DetailActivity.kt b/app/src/main/java/io/heckel/ntfy/ui/DetailActivity.kt index debe8ac..90de1a2 100644 --- a/app/src/main/java/io/heckel/ntfy/ui/DetailActivity.kt +++ b/app/src/main/java/io/heckel/ntfy/ui/DetailActivity.kt @@ -143,6 +143,10 @@ class DetailActivity : AppCompatActivity(), ActionMode.Callback { onInstantEnableClick(enable = false) true } + R.id.detail_menu_instant_info -> { + onInstantInfoClick() + true + } R.id.detail_menu_copy_url -> { onCopyUrlClick() true @@ -232,18 +236,27 @@ class DetailActivity : AppCompatActivity(), ActionMode.Callback { } } + private fun onInstantInfoClick() { + Log.d(TAG, "Showing instant info toast") + Toast.makeText(this@DetailActivity, getString(R.string.detail_instant_info), Toast.LENGTH_LONG) + .show() + } + private fun showHideInstantMenuItems(enable: Boolean) { subscriptionInstant = enable runOnUiThread { val appBaseUrl = getString(R.string.app_base_url) val enableInstantItem = menu.findItem(R.id.detail_menu_enable_instant) val disableInstantItem = menu.findItem(R.id.detail_menu_disable_instant) + val instantInfoItem = menu.findItem(R.id.detail_menu_instant_info) if (subscriptionBaseUrl == appBaseUrl) { enableInstantItem?.isVisible = !subscriptionInstant disableInstantItem?.isVisible = subscriptionInstant + instantInfoItem?.isVisible = false } else { enableInstantItem?.isVisible = false disableInstantItem?.isVisible = false + instantInfoItem?.isVisible = true } } } @@ -349,6 +362,7 @@ class DetailActivity : AppCompatActivity(), ActionMode.Callback { Toast .makeText(this@DetailActivity, getString(R.string.detail_copied_to_clipboard_message), Toast.LENGTH_LONG) .show() + finishActionMode() } } } diff --git a/app/src/main/res/layout/add_dialog_fragment.xml b/app/src/main/res/layout/add_dialog_fragment.xml index b196dac..9b671cf 100644 --- a/app/src/main/res/layout/add_dialog_fragment.xml +++ b/app/src/main/res/layout/add_dialog_fragment.xml @@ -1,6 +1,6 @@ - + android:layout_height="wrap_content" android:id="@+id/add_dialog_instant_delivery_box"> + + + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 3ceb8ba..097a8e6 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -6,8 +6,10 @@ Notifications Subscription Service - Subscribed topics - Listening for incoming notifications + Listening for incoming notifications + You are subscribed to instant delivery topics + You are subscribed to one instant delivery topic + You are subscribed to %1$d instant delivery topics %1$d notification(s) received @@ -16,7 +18,7 @@ Subscribed topics - View source & report bugs + Report a bug https://heckel.io/ntfy-android Visit ntfy.sh @@ -42,12 +44,12 @@ Use another server You can subscribe to topics from your own server. Due to platform limitations, this option requires a foreground - service and consumes more battery, but delivers notifications faster. + service and consumes more power, but also delivers notifications faster (even in doze mode). - Instant delivery even in doze mode + Instant delivery in doze mode - Android doze mode may delay message delivery. With this open, notifications are immediately delivered even in doze mode. - Requires foreground service and consumes more battery. + Doze mode sometimes causes delayed message delivery to conserve power. With instant delivery, notifications are + always immediately delivered. This requires a foreground service and consumes a little more power. Cancel Subscribe @@ -65,12 +67,14 @@ Copied to clipboard Instant delivery enabled Instant delivery disabled + Instant delivery is always enabled for subscriptions with other servers Send test notification Copy topic address Enable instant delivery Disable instant delivery + Instant delivery enabled Unsubscribe