diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 8c808ad..5b35ee8 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -41,16 +41,6 @@ - - - - - - - - diff --git a/app/src/main/java/io/heckel/ntfy/msg/BroadcastService.kt b/app/src/main/java/io/heckel/ntfy/msg/BroadcastService.kt index a45b4a4..bc32d28 100644 --- a/app/src/main/java/io/heckel/ntfy/msg/BroadcastService.kt +++ b/app/src/main/java/io/heckel/ntfy/msg/BroadcastService.kt @@ -12,6 +12,10 @@ import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.launch +/** + * The broadcast service is responsible for sending and receiving broadcasted intents + * in order to facilitate taks app integrations. + */ class BroadcastService(private val ctx: Context) { fun send(subscription: Subscription, notification: Notification, muted: Boolean) { val intent = Intent() @@ -19,12 +23,14 @@ class BroadcastService(private val ctx: Context) { intent.putExtra("id", notification.id) intent.putExtra("base_url", subscription.baseUrl) intent.putExtra("topic", subscription.topic) + intent.putExtra("time", notification.timestamp.toInt()) intent.putExtra("title", notification.title) intent.putExtra("message", notification.message) intent.putExtra("tags", notification.tags) intent.putExtra("tags_map", joinTagsMap(splitTags(notification.tags))) intent.putExtra("priority", notification.priority) intent.putExtra("muted", muted) + intent.putExtra("muted_str", muted.toString()) Log.d(TAG, "Sending intent broadcast: $intent") ctx.sendBroadcast(intent) @@ -40,9 +46,9 @@ class BroadcastService(private val ctx: Context) { private fun send(ctx: Context, intent: Intent) { val api = ApiService() + val baseUrl = intent.getStringExtra("base_url") ?: ctx.getString(R.string.app_base_url) val topic = intent.getStringExtra("topic") ?: return val message = intent.getStringExtra("message") ?: return - val baseUrl = intent.getStringExtra("base_url") ?: ctx.getString(R.string.app_base_url) val title = intent.getStringExtra("title") ?: "" val tags = intent.getStringExtra("tags") ?: "" val priority = if (intent.getStringExtra("priority") != null) { 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 36f80db..594e757 100644 --- a/app/src/main/java/io/heckel/ntfy/ui/AddFragment.kt +++ b/app/src/main/java/io/heckel/ntfy/ui/AddFragment.kt @@ -201,7 +201,7 @@ class AddFragment : DialogFragment() { activity?.let { it.runOnUiThread { - if (subscription != null) { + if (subscription != null || DISALLOWED_TOPICS.contains(topic)) { subscribeButton.isEnabled = false } else if (useAnotherServerCheckbox.isChecked) { subscribeButton.isEnabled = topic.isNotBlank() @@ -226,5 +226,6 @@ class AddFragment : DialogFragment() { companion object { const val TAG = "NtfyAddFragment" + private val DISALLOWED_TOPICS = listOf("docs", "static") } } 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 2e29981..9757c1f 100644 --- a/app/src/main/java/io/heckel/ntfy/ui/DetailActivity.kt +++ b/app/src/main/java/io/heckel/ntfy/ui/DetailActivity.kt @@ -79,62 +79,7 @@ class DetailActivity : AppCompatActivity(), ActionMode.Callback, NotificationFra // Show 'Back' button supportActionBar?.setDisplayHomeAsUpEnabled(true) - // Handle direct deep links to topic "https://ntfy.sh/..." - val url = intent?.data - if (intent?.action == ACTION_VIEW && url != null) { - val topic = url.pathSegments.first() - title = topicShortUrl(appBaseUrl!!, topic) // We assume the app base URL - maybeSubscribeAndLoadView(topic) - } else { - loadView() - } - } - - private fun maybeSubscribeAndLoadView(topic: String) { - lifecycleScope.launch(Dispatchers.IO) { - val baseUrl = appBaseUrl!! - var subscription = repository.getSubscription(baseUrl, topic) - if (subscription == null) { - subscription = Subscription( - id = Random.nextLong(), - baseUrl = baseUrl, - topic = topic, - instant = false, - mutedUntil = 0, - totalCount = 0, - newCount = 0, - lastActive = Date().time/1000 - ) - repository.addSubscription(subscription) - - // Subscribe to Firebase topic if ntfy.sh (even if instant, just to be sure!) - Log.d(MainActivity.TAG, "Subscribing to Firebase") - messenger.subscribe(topic) - - // Fetch cached messages - try { - val notifications = api.poll(subscription.id, subscription.baseUrl, subscription.topic) - notifications.forEach { notification -> repository.addNotification(notification) } - } catch (e: Exception) { - Log.e(MainActivity.TAG, "Unable to fetch notifications: ${e.stackTrace}") - } - - runOnUiThread { - val message = getString(R.string.detail_deep_link_subscribed_toast_message, topicShortUrl(baseUrl, topic)) - Toast.makeText(this@DetailActivity, message, Toast.LENGTH_LONG).show() - } - } - - intent.putExtra(MainActivity.EXTRA_SUBSCRIPTION_ID, subscription.id) - intent.putExtra(MainActivity.EXTRA_SUBSCRIPTION_BASE_URL, subscription.baseUrl) - intent.putExtra(MainActivity.EXTRA_SUBSCRIPTION_TOPIC, subscription.topic) - intent.putExtra(MainActivity.EXTRA_SUBSCRIPTION_INSTANT, subscription.instant) - intent.putExtra(MainActivity.EXTRA_SUBSCRIPTION_MUTED_UNTIL, subscription.mutedUntil) - - runOnUiThread { - loadView() - } - } + loadView() } private fun loadView() {