remove deep links
This commit is contained in:
parent
459e1ff84b
commit
56665c8cc0
4 changed files with 10 additions and 68 deletions
|
@ -41,16 +41,6 @@
|
||||||
<meta-data
|
<meta-data
|
||||||
android:name="android.support.PARENT_ACTIVITY"
|
android:name="android.support.PARENT_ACTIVITY"
|
||||||
android:value=".ui.MainActivity"/>
|
android:value=".ui.MainActivity"/>
|
||||||
|
|
||||||
<!-- Open https://ntfy.sh links with the app -->
|
|
||||||
<intent-filter android:label="@string/app_name">
|
|
||||||
<action android:name="android.intent.action.VIEW" />
|
|
||||||
<category android:name="android.intent.category.DEFAULT" />
|
|
||||||
<category android:name="android.intent.category.BROWSABLE" />
|
|
||||||
<data android:scheme="@string/app_base_scheme"
|
|
||||||
android:host="@string/app_base_host"
|
|
||||||
android:pathPattern="/..*" /> <!-- This is awful, but it's the only way in Android -->
|
|
||||||
</intent-filter>
|
|
||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
<!-- Subscriber foreground service for hosts other than ntfy.sh -->
|
<!-- Subscriber foreground service for hosts other than ntfy.sh -->
|
||||||
|
|
|
@ -12,6 +12,10 @@ import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.GlobalScope
|
import kotlinx.coroutines.GlobalScope
|
||||||
import kotlinx.coroutines.launch
|
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) {
|
class BroadcastService(private val ctx: Context) {
|
||||||
fun send(subscription: Subscription, notification: Notification, muted: Boolean) {
|
fun send(subscription: Subscription, notification: Notification, muted: Boolean) {
|
||||||
val intent = Intent()
|
val intent = Intent()
|
||||||
|
@ -19,12 +23,14 @@ class BroadcastService(private val ctx: Context) {
|
||||||
intent.putExtra("id", notification.id)
|
intent.putExtra("id", notification.id)
|
||||||
intent.putExtra("base_url", subscription.baseUrl)
|
intent.putExtra("base_url", subscription.baseUrl)
|
||||||
intent.putExtra("topic", subscription.topic)
|
intent.putExtra("topic", subscription.topic)
|
||||||
|
intent.putExtra("time", notification.timestamp.toInt())
|
||||||
intent.putExtra("title", notification.title)
|
intent.putExtra("title", notification.title)
|
||||||
intent.putExtra("message", notification.message)
|
intent.putExtra("message", notification.message)
|
||||||
intent.putExtra("tags", notification.tags)
|
intent.putExtra("tags", notification.tags)
|
||||||
intent.putExtra("tags_map", joinTagsMap(splitTags(notification.tags)))
|
intent.putExtra("tags_map", joinTagsMap(splitTags(notification.tags)))
|
||||||
intent.putExtra("priority", notification.priority)
|
intent.putExtra("priority", notification.priority)
|
||||||
intent.putExtra("muted", muted)
|
intent.putExtra("muted", muted)
|
||||||
|
intent.putExtra("muted_str", muted.toString())
|
||||||
|
|
||||||
Log.d(TAG, "Sending intent broadcast: $intent")
|
Log.d(TAG, "Sending intent broadcast: $intent")
|
||||||
ctx.sendBroadcast(intent)
|
ctx.sendBroadcast(intent)
|
||||||
|
@ -40,9 +46,9 @@ class BroadcastService(private val ctx: Context) {
|
||||||
|
|
||||||
private fun send(ctx: Context, intent: Intent) {
|
private fun send(ctx: Context, intent: Intent) {
|
||||||
val api = ApiService()
|
val api = ApiService()
|
||||||
|
val baseUrl = intent.getStringExtra("base_url") ?: ctx.getString(R.string.app_base_url)
|
||||||
val topic = intent.getStringExtra("topic") ?: return
|
val topic = intent.getStringExtra("topic") ?: return
|
||||||
val message = intent.getStringExtra("message") ?: 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 title = intent.getStringExtra("title") ?: ""
|
||||||
val tags = intent.getStringExtra("tags") ?: ""
|
val tags = intent.getStringExtra("tags") ?: ""
|
||||||
val priority = if (intent.getStringExtra("priority") != null) {
|
val priority = if (intent.getStringExtra("priority") != null) {
|
||||||
|
|
|
@ -201,7 +201,7 @@ class AddFragment : DialogFragment() {
|
||||||
|
|
||||||
activity?.let {
|
activity?.let {
|
||||||
it.runOnUiThread {
|
it.runOnUiThread {
|
||||||
if (subscription != null) {
|
if (subscription != null || DISALLOWED_TOPICS.contains(topic)) {
|
||||||
subscribeButton.isEnabled = false
|
subscribeButton.isEnabled = false
|
||||||
} else if (useAnotherServerCheckbox.isChecked) {
|
} else if (useAnotherServerCheckbox.isChecked) {
|
||||||
subscribeButton.isEnabled = topic.isNotBlank()
|
subscribeButton.isEnabled = topic.isNotBlank()
|
||||||
|
@ -226,5 +226,6 @@ class AddFragment : DialogFragment() {
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
const val TAG = "NtfyAddFragment"
|
const val TAG = "NtfyAddFragment"
|
||||||
|
private val DISALLOWED_TOPICS = listOf("docs", "static")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -79,62 +79,7 @@ class DetailActivity : AppCompatActivity(), ActionMode.Callback, NotificationFra
|
||||||
// Show 'Back' button
|
// Show 'Back' button
|
||||||
supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
||||||
|
|
||||||
// Handle direct deep links to topic "https://ntfy.sh/..."
|
loadView()
|
||||||
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()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun loadView() {
|
private fun loadView() {
|
||||||
|
|
Loading…
Reference in a new issue