mirror of
https://github.com/Aviortheking/Neo-Store.git
synced 2025-04-23 19:32:16 +00:00
Update: Improve notifications on empty sync results
This commit is contained in:
parent
8c88b8e6da
commit
717d653644
@ -35,19 +35,25 @@ import com.machiav3lli.fdroid.utility.extension.resources.getColorFromAttr
|
|||||||
*
|
*
|
||||||
* @param productItems list of apps pending updates
|
* @param productItems list of apps pending updates
|
||||||
*/
|
*/
|
||||||
fun Context.displayUpdatesNotification(productItems: List<ProductItem>) {
|
fun Context.displayUpdatesNotification(
|
||||||
|
productItems: List<ProductItem>,
|
||||||
|
enforceNotify: Boolean = false
|
||||||
|
) {
|
||||||
val maxUpdates = 5
|
val maxUpdates = 5
|
||||||
fun <T> T.applyHack(callback: T.() -> Unit): T = apply(callback)
|
fun <T> T.applyHack(callback: T.() -> Unit): T = apply(callback)
|
||||||
|
if (productItems.isNotEmpty() || enforceNotify)
|
||||||
notificationManager.notify(
|
notificationManager.notify(
|
||||||
NOTIFICATION_ID_UPDATES, NotificationCompat
|
NOTIFICATION_ID_UPDATES, NotificationCompat
|
||||||
.Builder(this, NOTIFICATION_CHANNEL_UPDATES)
|
.Builder(this, NOTIFICATION_CHANNEL_UPDATES)
|
||||||
.setSmallIcon(R.drawable.ic_new_releases)
|
.setSmallIcon(R.drawable.ic_new_releases)
|
||||||
.setContentTitle(getString(R.string.new_updates_available))
|
.setContentTitle(getString(if (productItems.isNotEmpty()) R.string.new_updates_available else R.string.no_updates_available))
|
||||||
.setContentText(
|
.setContentText(
|
||||||
|
if (productItems.isNotEmpty())
|
||||||
resources.getQuantityString(
|
resources.getQuantityString(
|
||||||
R.plurals.new_updates_DESC_FORMAT,
|
R.plurals.new_updates_DESC_FORMAT,
|
||||||
productItems.size, productItems.size
|
productItems.size, productItems.size
|
||||||
)
|
)
|
||||||
|
else null
|
||||||
)
|
)
|
||||||
.setColor(
|
.setColor(
|
||||||
ContextThemeWrapper(this, R.style.Theme_Main_Light)
|
ContextThemeWrapper(this, R.style.Theme_Main_Light)
|
||||||
@ -91,6 +97,7 @@ fun Context.displayUpdatesNotification(productItems: List<ProductItem>) {
|
|||||||
})
|
})
|
||||||
.build()
|
.build()
|
||||||
)
|
)
|
||||||
|
else notificationManager.cancel(NOTIFICATION_ID_UPDATES)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Context.showNotificationError(repository: Repository, exception: Exception) {
|
fun Context.showNotificationError(repository: Repository, exception: Exception) {
|
||||||
|
@ -206,4 +206,5 @@
|
|||||||
<string name="open">Open</string>
|
<string name="open">Open</string>
|
||||||
<string name="loading_list">Loading list…</string>
|
<string name="loading_list">Loading list…</string>
|
||||||
<string name="releases">Releases</string>
|
<string name="releases">Releases</string>
|
||||||
|
<string name="no_updates_available">No versions available</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user