diff --git a/app/src/main/java/io/heckel/ntfy/data/Database.kt b/app/src/main/java/io/heckel/ntfy/data/Database.kt index ae43662..a7d6cae 100644 --- a/app/src/main/java/io/heckel/ntfy/data/Database.kt +++ b/app/src/main/java/io/heckel/ntfy/data/Database.kt @@ -70,7 +70,7 @@ interface NotificationDao { @Query("SELECT id FROM notification WHERE subscriptionId = :subscriptionId") fun listIds(subscriptionId: Long): List - @Insert + @Insert(onConflict = OnConflictStrategy.IGNORE) fun add(notification: Notification) @Query("DELETE FROM notification WHERE id = :notificationId") 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 efe9558..48427a4 100644 --- a/app/src/main/java/io/heckel/ntfy/ui/DetailActivity.kt +++ b/app/src/main/java/io/heckel/ntfy/ui/DetailActivity.kt @@ -1,6 +1,5 @@ package io.heckel.ntfy.ui -import android.R.attr.label import android.app.AlertDialog import android.content.ClipData import android.content.ClipboardManager @@ -30,7 +29,6 @@ import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch import java.util.* - class DetailActivity : AppCompatActivity(), ActionMode.Callback { private val viewModel by viewModels { DetailViewModelFactory((application as Application).repository) @@ -115,10 +113,6 @@ class DetailActivity : AppCompatActivity(), ActionMode.Callback { onRefreshClick() true } - R.id.detail_menu_clear -> { - onClearClick() - true - } R.id.detail_menu_unsubscribe -> { onDeleteClick() true @@ -166,18 +160,6 @@ class DetailActivity : AppCompatActivity(), ActionMode.Callback { api.poll(subscriptionId, subscriptionBaseUrl, subscriptionTopic, successFn, failureFn) } - private fun onClearClick() { - val builder = AlertDialog.Builder(this) - builder - .setMessage(R.string.detail_clear_dialog_message) - .setPositiveButton(R.string.detail_clear_dialog_permanently_delete) { _, _ -> - viewModel.removeAll(subscriptionId) - } - .setNegativeButton(R.string.detail_clear_dialog_cancel) { _, _ -> /* Do nothing */ } - .create() - .show() - } - private fun onDeleteClick() { Log.d(TAG, "Deleting subscription ${topicShortUrl(subscriptionBaseUrl, subscriptionTopic)}") 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 5efe727..bd3a404 100644 --- a/app/src/main/java/io/heckel/ntfy/ui/MainActivity.kt +++ b/app/src/main/java/io/heckel/ntfy/ui/MainActivity.kt @@ -12,6 +12,7 @@ import android.widget.Toast import androidx.activity.viewModels import androidx.appcompat.app.AppCompatActivity import androidx.core.content.ContextCompat +import androidx.lifecycle.asFlow import androidx.lifecycle.lifecycleScope import androidx.recyclerview.widget.RecyclerView import com.google.firebase.messaging.FirebaseMessaging @@ -22,6 +23,7 @@ import io.heckel.ntfy.data.Subscription import io.heckel.ntfy.data.topicShortUrl import io.heckel.ntfy.msg.ApiService import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.flow.collect import kotlinx.coroutines.launch import java.util.* import kotlin.random.Random @@ -83,6 +85,10 @@ class MainActivity : AppCompatActivity(), ActionMode.Callback { override fun onOptionsItemSelected(item: MenuItem): Boolean { return when (item.itemId) { + R.id.main_menu_refresh -> { + refreshAllSubscriptions() + true + } R.id.main_menu_source -> { startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(getString(R.string.main_menu_source_url)))) true @@ -152,6 +158,24 @@ class MainActivity : AppCompatActivity(), ActionMode.Callback { } } + private fun refreshAllSubscriptions() { + lifecycleScope.launch(Dispatchers.IO) { + val successFn = { notifications: List -> + lifecycleScope.launch(Dispatchers.IO) { + notifications.forEach { + repository.addNotification(it) + } + } + Unit + } + repository.getAllSubscriptions().asFlow().collect { subscriptions -> + subscriptions.forEach { subscription -> + api.poll(subscription.id, subscription.baseUrl, subscription.topic, successFn, { _ -> }) + } + } + } + } + private fun startDetailView(subscription: Subscription) { Log.d(TAG, "Entering detail view for subscription $subscription") diff --git a/app/src/main/res/menu/detail_action_bar_menu.xml b/app/src/main/res/menu/detail_action_bar_menu.xml index 3f3e160..852ef14 100644 --- a/app/src/main/res/menu/detail_action_bar_menu.xml +++ b/app/src/main/res/menu/detail_action_bar_menu.xml @@ -1,6 +1,5 @@ - diff --git a/app/src/main/res/menu/main_action_bar_menu.xml b/app/src/main/res/menu/main_action_bar_menu.xml index a6e655f..72debe7 100644 --- a/app/src/main/res/menu/main_action_bar_menu.xml +++ b/app/src/main/res/menu/main_action_bar_menu.xml @@ -1,4 +1,5 @@ + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 6d5e71b..d2e8aa4 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -9,6 +9,7 @@ Subscribed topics + Force refresh Show source & license https://heckel.io/ntfy-android Visit ntfy.sh @@ -20,8 +21,6 @@ Cancel - connecting … - reconnecting … %1$d notification received %1$d notifications received Add subscription @@ -42,9 +41,6 @@ To send notifications to this topic, simply PUT or POST to the topic URL. $ curl -d \"Hi\" %1$s ]]> For more detailed instructions, check out the ntfy.sh website and documentation. - Do you really want to delete all of the messages you received? - Permanently delete - Cancel Do you really want to unsubscribe from this topic and delete all of the messages you received? Permanently delete Cancel @@ -57,8 +53,7 @@ Send test notification - Fetch cached notifications - Clear notifications + Force refresh Unsubscribe diff --git a/assets/screenshot-main.jpg b/assets/screenshot-main.jpg index ed5ce17..5caeee1 100644 Binary files a/assets/screenshot-main.jpg and b/assets/screenshot-main.jpg differ diff --git a/assets/screenshot-notification.jpg b/assets/screenshot-notification.jpg index 6b04675..7924c6f 100644 Binary files a/assets/screenshot-notification.jpg and b/assets/screenshot-notification.jpg differ