From f69d1f5ee1ebfb9aa06f70eb2a1e5715839de9de Mon Sep 17 00:00:00 2001 From: Philipp Heckel Date: Sun, 14 Nov 2021 20:22:02 -0500 Subject: [PATCH] Instant delivery icon; multi-copy --- .../java/io/heckel/ntfy/data/Repository.kt | 4 ++ .../java/io/heckel/ntfy/ui/DetailActivity.kt | 25 +++++++++ .../drawable/ic_bolt_outline_white_24dp.xml | 9 ++++ .../main/res/drawable/ic_bolt_white_24dp.xml | 9 ++++ .../drawable/ic_content_copy_white_24dp.xml | 9 ++++ ...gray_20dp.xml => ic_delete_white_20dp.xml} | 0 .../main/res/menu/detail_action_bar_menu.xml | 7 +-- .../main/res/menu/detail_action_mode_menu.xml | 4 +- .../main/res/menu/main_action_mode_menu.xml | 2 +- app/src/main/res/values/strings.xml | 15 +++--- assets/bolt_outline_black_24dp.svg | 52 +++++++++++++++++++ assets/content_copy_black_24dp.svg | 1 + assets/ic_send_black_24dp.svg | 1 + 13 files changed, 126 insertions(+), 12 deletions(-) create mode 100644 app/src/main/res/drawable/ic_bolt_outline_white_24dp.xml create mode 100644 app/src/main/res/drawable/ic_bolt_white_24dp.xml create mode 100644 app/src/main/res/drawable/ic_content_copy_white_24dp.xml rename app/src/main/res/drawable/{ic_delete_gray_20dp.xml => ic_delete_white_20dp.xml} (100%) create mode 100644 assets/bolt_outline_black_24dp.svg create mode 100644 assets/content_copy_black_24dp.svg create mode 100644 assets/ic_send_black_24dp.svg 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 2ee5d87..e93dc3e 100644 --- a/app/src/main/java/io/heckel/ntfy/data/Repository.kt +++ b/app/src/main/java/io/heckel/ntfy/data/Repository.kt @@ -64,6 +64,10 @@ class Repository(private val subscriptionDao: SubscriptionDao, private val notif return notificationDao.list(subscriptionId).asLiveData() } + fun getNotification(notificationId: String): Notification? { + return notificationDao.get(notificationId) + } + fun onlyNewNotifications(subscriptionId: Long, notifications: List): List { val existingIds = notificationDao.listIds(subscriptionId) return notifications.filterNot { existingIds.contains(it.id) } 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 578ce3c..debe8ac 100644 --- a/app/src/main/java/io/heckel/ntfy/ui/DetailActivity.kt +++ b/app/src/main/java/io/heckel/ntfy/ui/DetailActivity.kt @@ -320,6 +320,10 @@ class DetailActivity : AppCompatActivity(), ActionMode.Callback { override fun onActionItemClicked(mode: ActionMode?, item: MenuItem?): Boolean { return when (item?.itemId) { + R.id.detail_action_mode_copy -> { + onMultiCopyClick() + true + } R.id.detail_action_mode_delete -> { onMultiDeleteClick() true @@ -328,6 +332,27 @@ class DetailActivity : AppCompatActivity(), ActionMode.Callback { } } + private fun onMultiCopyClick() { + Log.d(TAG, "Copying multiple notifications to clipboard") + + lifecycleScope.launch(Dispatchers.IO) { + val content = adapter.selected.joinToString("\n\n") { notificationId -> + val notification = repository.getNotification(notificationId) + notification?.let { + it.message + "\n" + Date(it.timestamp * 1000).toString() + }.orEmpty() + } + val clipboard: ClipboardManager = getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager + val clip = ClipData.newPlainText("notifications", content) + clipboard.setPrimaryClip(clip) + runOnUiThread { + Toast + .makeText(this@DetailActivity, getString(R.string.detail_copied_to_clipboard_message), Toast.LENGTH_LONG) + .show() + } + } + } + private fun onMultiDeleteClick() { Log.d(TAG, "Showing multi-delete dialog for selected items") diff --git a/app/src/main/res/drawable/ic_bolt_outline_white_24dp.xml b/app/src/main/res/drawable/ic_bolt_outline_white_24dp.xml new file mode 100644 index 0000000..9ecde1f --- /dev/null +++ b/app/src/main/res/drawable/ic_bolt_outline_white_24dp.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/ic_bolt_white_24dp.xml b/app/src/main/res/drawable/ic_bolt_white_24dp.xml new file mode 100644 index 0000000..04cf83c --- /dev/null +++ b/app/src/main/res/drawable/ic_bolt_white_24dp.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/ic_content_copy_white_24dp.xml b/app/src/main/res/drawable/ic_content_copy_white_24dp.xml new file mode 100644 index 0000000..9b89c49 --- /dev/null +++ b/app/src/main/res/drawable/ic_content_copy_white_24dp.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/ic_delete_gray_20dp.xml b/app/src/main/res/drawable/ic_delete_white_20dp.xml similarity index 100% rename from app/src/main/res/drawable/ic_delete_gray_20dp.xml rename to app/src/main/res/drawable/ic_delete_white_20dp.xml 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 7d66478..6ab8d25 100644 --- a/app/src/main/res/menu/detail_action_bar_menu.xml +++ b/app/src/main/res/menu/detail_action_bar_menu.xml @@ -1,8 +1,9 @@ - - + app:showAsAction="ifRoom|withText" android:icon="@drawable/ic_bolt_outline_white_24dp"/> + + diff --git a/app/src/main/res/menu/detail_action_mode_menu.xml b/app/src/main/res/menu/detail_action_mode_menu.xml index 4f13ef2..9da6be1 100644 --- a/app/src/main/res/menu/detail_action_mode_menu.xml +++ b/app/src/main/res/menu/detail_action_mode_menu.xml @@ -1,4 +1,6 @@ + + android:icon="@drawable/ic_delete_white_20dp"/> diff --git a/app/src/main/res/menu/main_action_mode_menu.xml b/app/src/main/res/menu/main_action_mode_menu.xml index 4017155..681733e 100644 --- a/app/src/main/res/menu/main_action_mode_menu.xml +++ b/app/src/main/res/menu/main_action_mode_menu.xml @@ -1,4 +1,4 @@ + android:icon="@drawable/ic_delete_white_20dp"/> diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index d22335f..9993a60 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -43,10 +43,10 @@ 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. - Fast delivery + Instant delivery even in doze mode - Enables instant notification delivery even in doze mode. Requires foreground service and consumes more - battery. + 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. Cancel Subscribe @@ -62,17 +62,18 @@ This is a test notification from the Ntfy Android app. It was sent at %1$s. Could not send test message: %1$s Copied to clipboard - Fast delivery enabled - Fast delivery disabled + Instant delivery enabled + Instant delivery disabled Send test notification Copy topic address - Enable fast delivery - Disable fast delivery + Enable instant delivery + Disable instant delivery Unsubscribe + Copy Delete Do you really want to permanently delete the selected message(s)? Permanently delete diff --git a/assets/bolt_outline_black_24dp.svg b/assets/bolt_outline_black_24dp.svg new file mode 100644 index 0000000..c1fdcf5 --- /dev/null +++ b/assets/bolt_outline_black_24dp.svg @@ -0,0 +1,52 @@ + + + + + + + + + + + diff --git a/assets/content_copy_black_24dp.svg b/assets/content_copy_black_24dp.svg new file mode 100644 index 0000000..5d2b365 --- /dev/null +++ b/assets/content_copy_black_24dp.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/assets/ic_send_black_24dp.svg b/assets/ic_send_black_24dp.svg new file mode 100644 index 0000000..3b621d0 --- /dev/null +++ b/assets/ic_send_black_24dp.svg @@ -0,0 +1 @@ + \ No newline at end of file