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 42b554c..afb2640 100644
--- a/app/src/main/java/io/heckel/ntfy/data/Database.kt
+++ b/app/src/main/java/io/heckel/ntfy/data/Database.kt
@@ -174,11 +174,11 @@ interface NotificationDao {
@Query("UPDATE notification SET notificationId = 0 WHERE subscriptionId = :subscriptionId")
fun clearAllNotificationIds(subscriptionId: Long)
- @Update
- fun update(notification: Notification)
-
@Query("UPDATE notification SET deleted = 1 WHERE id = :notificationId")
- fun remove(notificationId: String)
+ fun markAsDeleted(notificationId: String)
+
+ @Query("UPDATE notification SET deleted = 1 WHERE subscriptionId = :subscriptionId")
+ fun markAllAsDeleted(subscriptionId: Long)
@Query("DELETE FROM notification WHERE subscriptionId = :subscriptionId")
fun removeAll(subscriptionId: Long)
diff --git a/app/src/main/java/io/heckel/ntfy/data/Repository.kt b/app/src/main/java/io/heckel/ntfy/data/Repository.kt
index 6bb0f87..b4c50de 100644
--- a/app/src/main/java/io/heckel/ntfy/data/Repository.kt
+++ b/app/src/main/java/io/heckel/ntfy/data/Repository.kt
@@ -100,14 +100,14 @@ class Repository(private val sharedPrefs: SharedPreferences, private val subscri
return !detailViewOpen && !muted
}
- fun updateNotification(notification: Notification) {
- notificationDao.update(notification)
- }
-
@Suppress("RedundantSuspendModifier")
@WorkerThread
- suspend fun removeNotification(notificationId: String) {
- notificationDao.remove(notificationId)
+ suspend fun markAsDeleted(notificationId: String) {
+ notificationDao.markAsDeleted(notificationId)
+ }
+
+ fun markAllAsDeleted(subscriptionId: Long) {
+ notificationDao.markAllAsDeleted(subscriptionId)
}
@Suppress("RedundantSuspendModifier")
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 6d0ecd4..79177bc 100644
--- a/app/src/main/java/io/heckel/ntfy/ui/DetailActivity.kt
+++ b/app/src/main/java/io/heckel/ntfy/ui/DetailActivity.kt
@@ -29,7 +29,6 @@ import io.heckel.ntfy.data.topicUrl
import io.heckel.ntfy.msg.ApiService
import io.heckel.ntfy.msg.NotificationService
import kotlinx.coroutines.*
-import java.text.DateFormat
import java.util.*
class DetailActivity : AppCompatActivity(), ActionMode.Callback, NotificationFragment.NotificationSettingsListener {
@@ -241,6 +240,10 @@ class DetailActivity : AppCompatActivity(), ActionMode.Callback, NotificationFra
onCopyUrlClick()
true
}
+ R.id.detail_menu_clear -> {
+ onClearClick()
+ true
+ }
R.id.detail_menu_unsubscribe -> {
onDeleteClick()
true
@@ -403,11 +406,32 @@ class DetailActivity : AppCompatActivity(), ActionMode.Callback, NotificationFra
}
}
+ private fun onClearClick() {
+ Log.d(TAG, "Clearing all notifications for ${topicShortUrl(subscriptionBaseUrl, subscriptionTopic)}")
+
+ val builder = AlertDialog.Builder(this)
+ val dialog = builder
+ .setMessage(R.string.detail_clear_dialog_message)
+ .setPositiveButton(R.string.detail_clear_dialog_permanently_delete) { _, _ ->
+ lifecycleScope.launch(Dispatchers.IO) {
+ repository.markAllAsDeleted(subscriptionId)
+ }
+ }
+ .setNegativeButton(R.string.detail_clear_dialog_cancel) { _, _ -> /* Do nothing */ }
+ .create()
+ dialog.setOnShowListener {
+ dialog
+ .getButton(AlertDialog.BUTTON_POSITIVE)
+ .setTextColor(ContextCompat.getColor(this, R.color.primaryDangerButtonColor))
+ }
+ dialog.show()
+ }
+
private fun onDeleteClick() {
Log.d(TAG, "Deleting subscription ${topicShortUrl(subscriptionBaseUrl, subscriptionTopic)}")
val builder = AlertDialog.Builder(this)
- builder
+ val dialog = builder
.setMessage(R.string.detail_delete_dialog_message)
.setPositiveButton(R.string.detail_delete_dialog_permanently_delete) { _, _ ->
// Return to main activity
@@ -424,7 +448,12 @@ class DetailActivity : AppCompatActivity(), ActionMode.Callback, NotificationFra
}
.setNegativeButton(R.string.detail_delete_dialog_cancel) { _, _ -> /* Do nothing */ }
.create()
- .show()
+ dialog.setOnShowListener {
+ dialog
+ .getButton(AlertDialog.BUTTON_POSITIVE)
+ .setTextColor(ContextCompat.getColor(this, R.color.primaryDangerButtonColor))
+ }
+ dialog.show()
}
private fun onNotificationClick(notification: Notification) {
@@ -516,17 +545,22 @@ class DetailActivity : AppCompatActivity(), ActionMode.Callback, NotificationFra
Log.d(TAG, "Showing multi-delete dialog for selected items")
val builder = AlertDialog.Builder(this)
- builder
+ val dialog = builder
.setMessage(R.string.detail_action_mode_delete_dialog_message)
.setPositiveButton(R.string.detail_action_mode_delete_dialog_permanently_delete) { _, _ ->
- adapter.selected.map { notificationId -> viewModel.remove(notificationId) }
+ adapter.selected.map { notificationId -> viewModel.markAsDeleted(notificationId) }
finishActionMode()
}
.setNegativeButton(R.string.detail_action_mode_delete_dialog_cancel) { _, _ ->
finishActionMode()
}
.create()
- .show()
+ dialog.setOnShowListener {
+ dialog
+ .getButton(AlertDialog.BUTTON_POSITIVE)
+ .setTextColor(ContextCompat.getColor(this, R.color.primaryDangerButtonColor))
+ }
+ dialog.show()
}
override fun onDestroyActionMode(mode: ActionMode?) {
diff --git a/app/src/main/java/io/heckel/ntfy/ui/DetailViewModel.kt b/app/src/main/java/io/heckel/ntfy/ui/DetailViewModel.kt
index 643d900..effdcd6 100644
--- a/app/src/main/java/io/heckel/ntfy/ui/DetailViewModel.kt
+++ b/app/src/main/java/io/heckel/ntfy/ui/DetailViewModel.kt
@@ -14,8 +14,8 @@ class DetailViewModel(private val repository: Repository) : ViewModel() {
return repository.getNotificationsLiveData(subscriptionId)
}
- fun remove(notificationId: String) = viewModelScope.launch(Dispatchers.IO) {
- repository.removeNotification(notificationId)
+ fun markAsDeleted(notificationId: String) = viewModelScope.launch(Dispatchers.IO) {
+ repository.markAsDeleted(notificationId)
}
}
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 5f3de63..989ab7f 100644
--- a/app/src/main/java/io/heckel/ntfy/ui/MainActivity.kt
+++ b/app/src/main/java/io/heckel/ntfy/ui/MainActivity.kt
@@ -405,7 +405,7 @@ class MainActivity : AppCompatActivity(), ActionMode.Callback, AddFragment.Subsc
Log.d(DetailActivity.TAG, "Showing multi-delete dialog for selected items")
val builder = AlertDialog.Builder(this)
- builder
+ val dialog = builder
.setMessage(R.string.main_action_mode_delete_dialog_message)
.setPositiveButton(R.string.main_action_mode_delete_dialog_permanently_delete) { _, _ ->
adapter.selected.map { viewModel.remove(it) }
@@ -415,7 +415,12 @@ class MainActivity : AppCompatActivity(), ActionMode.Callback, AddFragment.Subsc
finishActionMode()
}
.create()
- .show()
+ dialog.setOnShowListener {
+ dialog
+ .getButton(AlertDialog.BUTTON_POSITIVE)
+ .setTextColor(ContextCompat.getColor(this, R.color.primaryDangerButtonColor))
+ }
+ dialog.show()
}
override fun onDestroyActionMode(mode: ActionMode?) {
diff --git a/app/src/main/res/menu/menu_detail_action_bar.xml b/app/src/main/res/menu/menu_detail_action_bar.xml
index 0a40d57..95af4ae 100644
--- a/app/src/main/res/menu/menu_detail_action_bar.xml
+++ b/app/src/main/res/menu/menu_detail_action_bar.xml
@@ -13,5 +13,6 @@
android:icon="@drawable/ic_bolt_white_24dp" app:showAsAction="ifRoom"/>
+
diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml
index a10c7ab..2f1e5cb 100644
--- a/app/src/main/res/values/colors.xml
+++ b/app/src/main/res/values/colors.xml
@@ -8,5 +8,6 @@
#FFFFFF
#EEEEEE
+ #C30000
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 072a1e6..c28582e 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -31,8 +31,8 @@
Unsubscribe
- Do you really want to unsubscribe from selected topic(s) and
- permanently delete all the messages you received?
+ Do you really want to unsubscribe from the selected topic(s) and
+ permanently delete all the notifications you received?
Permanently delete
Cancel
@@ -76,8 +76,12 @@
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 unsubscribe from this topic and delete all of the
- messages you received?
+ Do you really want to delete all of the notifications in this topic?
+ Permanently delete
+ Cancel
+
+ Do you really want to unsubscribe from this topic and delete all of the
+ notifications you received?
Permanently delete
Cancel
@@ -94,15 +98,17 @@
Notifications disabled until %1$s
Enable instant delivery
Disable instant delivery
+ Instant delivery enabled
Send test notification
Copy topic address
- Instant delivery enabled
+ Clear all notifications
Unsubscribe
Copy
Delete
- Do you really want to permanently delete the selected message(s)?
+
+ Do you really want to permanently delete the selected notification(s)?
Permanently delete
Cancel