mirror of
https://github.com/Aviortheking/Neo-Store.git
synced 2025-04-23 19:32:16 +00:00
Improve SyncService post-sync behaviour, rewrite new preference.
Moved the update query disposable to before the post-sync if-else block so that the debug flag can be removed and everything can operate as normal. Rewrote the title of the new preference for auto updates to reduce the use of jargon and to be a bit clearer.
This commit is contained in:
parent
3ea8cd8c66
commit
5fbb6dcb61
@ -373,40 +373,45 @@ class SyncService : ConnectionService<SyncService.Binder>() {
|
|||||||
if (throwable != null && task.manual) {
|
if (throwable != null && task.manual) {
|
||||||
showNotificationError(repository, throwable as Exception)
|
showNotificationError(repository, throwable as Exception)
|
||||||
}
|
}
|
||||||
handleNextTask(BuildConfig.DEBUG || result == true || hasUpdates)
|
handleNextTask(result == true || hasUpdates)
|
||||||
}
|
}
|
||||||
currentTask = CurrentTask(task, disposable, hasUpdates, initialState)
|
currentTask = CurrentTask(task, disposable, hasUpdates, initialState)
|
||||||
} else {
|
} else {
|
||||||
handleNextTask(hasUpdates)
|
handleNextTask(hasUpdates)
|
||||||
}
|
}
|
||||||
} else if (started != Started.NO) {
|
} else if (started != Started.NO) {
|
||||||
if (hasUpdates) {
|
val disposable = RxUtils
|
||||||
val disposable = RxUtils
|
.querySingle { it ->
|
||||||
.querySingle { it ->
|
Database.ProductAdapter
|
||||||
Database.ProductAdapter
|
.query(
|
||||||
.query(
|
installed = true,
|
||||||
installed = true,
|
updates = true,
|
||||||
updates = true,
|
searchQuery = "",
|
||||||
searchQuery = "",
|
section = ProductItem.Section.All,
|
||||||
section = ProductItem.Section.All,
|
order = ProductItem.Order.NAME,
|
||||||
order = ProductItem.Order.NAME,
|
signal = it
|
||||||
signal = it
|
)
|
||||||
)
|
.use {
|
||||||
.use {
|
it.asSequence().map(Database.ProductAdapter::transformItem)
|
||||||
it.asSequence().map(Database.ProductAdapter::transformItem)
|
.toList()
|
||||||
.toList()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.subscribeOn(Schedulers.io())
|
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
|
||||||
.subscribe { result, throwable ->
|
|
||||||
throwable?.printStackTrace()
|
|
||||||
currentTask = null
|
|
||||||
handleNextTask(false)
|
|
||||||
if (result.isNotEmpty()) {
|
|
||||||
runAutoUpdate(result)
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
.subscribeOn(Schedulers.io())
|
||||||
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
|
.subscribe { result, throwable ->
|
||||||
|
throwable?.printStackTrace()
|
||||||
|
currentTask = null
|
||||||
|
handleNextTask(false)
|
||||||
|
if (result.isNotEmpty()) {
|
||||||
|
if (Preferences[Preferences.Key.AutoSyncInstall])
|
||||||
|
runAutoUpdate(result)
|
||||||
|
if (hasUpdates && Preferences[Preferences.Key.UpdateNotify] &&
|
||||||
|
updateNotificationBlockerFragment?.get()?.isAdded == true
|
||||||
|
)
|
||||||
|
displayUpdatesNotification(result)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if (hasUpdates) {
|
||||||
currentTask = CurrentTask(null, disposable, true, State.Finishing)
|
currentTask = CurrentTask(null, disposable, true, State.Finishing)
|
||||||
} else {
|
} else {
|
||||||
scope.launch { mutableFinishState.emit(Unit) }
|
scope.launch { mutableFinishState.emit(Unit) }
|
||||||
@ -461,8 +466,6 @@ class SyncService : ConnectionService<SyncService.Binder>() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
displayUpdatesNotification(productItems)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -472,59 +475,57 @@ class SyncService : ConnectionService<SyncService.Binder>() {
|
|||||||
* @param productItems list of apps pending updates
|
* @param productItems list of apps pending updates
|
||||||
*/
|
*/
|
||||||
private fun displayUpdatesNotification(productItems: List<ProductItem>) {
|
private fun displayUpdatesNotification(productItems: List<ProductItem>) {
|
||||||
if (updateNotificationBlockerFragment?.get()?.isAdded == true && Preferences[Preferences.Key.UpdateNotify]) {
|
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)
|
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(R.string.new_updates_available))
|
.setContentText(
|
||||||
.setContentText(
|
resources.getQuantityString(
|
||||||
resources.getQuantityString(
|
R.plurals.new_updates_DESC_FORMAT,
|
||||||
R.plurals.new_updates_DESC_FORMAT,
|
productItems.size, productItems.size
|
||||||
productItems.size, productItems.size
|
)
|
||||||
|
)
|
||||||
|
.setColor(
|
||||||
|
ContextThemeWrapper(this, R.style.Theme_Main_Light)
|
||||||
|
.getColorFromAttr(android.R.attr.colorPrimary).defaultColor
|
||||||
|
)
|
||||||
|
.setContentIntent(
|
||||||
|
PendingIntent.getActivity(
|
||||||
|
this,
|
||||||
|
0,
|
||||||
|
Intent(this, MainActivity::class.java)
|
||||||
|
.setAction(MainActivity.ACTION_UPDATES),
|
||||||
|
if (Android.sdk(23))
|
||||||
|
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
|
||||||
|
else
|
||||||
|
PendingIntent.FLAG_UPDATE_CURRENT
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.setStyle(NotificationCompat.InboxStyle().applyHack {
|
||||||
|
for (productItem in productItems.take(maxUpdates)) {
|
||||||
|
val builder = SpannableStringBuilder(productItem.name)
|
||||||
|
builder.setSpan(
|
||||||
|
ForegroundColorSpan(Color.BLACK), 0, builder.length,
|
||||||
|
SpannableStringBuilder.SPAN_EXCLUSIVE_EXCLUSIVE
|
||||||
)
|
)
|
||||||
)
|
builder.append(' ').append(productItem.version)
|
||||||
.setColor(
|
addLine(builder)
|
||||||
ContextThemeWrapper(this, R.style.Theme_Main_Light)
|
}
|
||||||
.getColorFromAttr(android.R.attr.colorPrimary).defaultColor
|
if (productItems.size > maxUpdates) {
|
||||||
)
|
val summary =
|
||||||
.setContentIntent(
|
getString(R.string.plus_more_FORMAT, productItems.size - maxUpdates)
|
||||||
PendingIntent.getActivity(
|
if (Android.sdk(24)) {
|
||||||
this,
|
addLine(summary)
|
||||||
0,
|
} else {
|
||||||
Intent(this, MainActivity::class.java)
|
setSummaryText(summary)
|
||||||
.setAction(MainActivity.ACTION_UPDATES),
|
|
||||||
if (Android.sdk(23))
|
|
||||||
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
|
|
||||||
else
|
|
||||||
PendingIntent.FLAG_UPDATE_CURRENT
|
|
||||||
)
|
|
||||||
)
|
|
||||||
.setStyle(NotificationCompat.InboxStyle().applyHack {
|
|
||||||
for (productItem in productItems.take(maxUpdates)) {
|
|
||||||
val builder = SpannableStringBuilder(productItem.name)
|
|
||||||
builder.setSpan(
|
|
||||||
ForegroundColorSpan(Color.BLACK), 0, builder.length,
|
|
||||||
SpannableStringBuilder.SPAN_EXCLUSIVE_EXCLUSIVE
|
|
||||||
)
|
|
||||||
builder.append(' ').append(productItem.version)
|
|
||||||
addLine(builder)
|
|
||||||
}
|
}
|
||||||
if (productItems.size > maxUpdates) {
|
}
|
||||||
val summary =
|
})
|
||||||
getString(R.string.plus_more_FORMAT, productItems.size - maxUpdates)
|
.build()
|
||||||
if (Android.sdk(24)) {
|
)
|
||||||
addLine(summary)
|
|
||||||
} else {
|
|
||||||
setSummaryText(summary)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.build()
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class Job : JobService() {
|
class Job : JobService() {
|
||||||
|
@ -180,6 +180,6 @@
|
|||||||
<string name="installed_applications">Installed applications</string>
|
<string name="installed_applications">Installed applications</string>
|
||||||
<string name="sort_filter">Sort & Filter</string>
|
<string name="sort_filter">Sort & Filter</string>
|
||||||
<string name="new_applications">New applications</string>
|
<string name="new_applications">New applications</string>
|
||||||
<string name="sync_auto_install">Update apps after sync</string>
|
<string name="sync_auto_install">Install updates automatically</string>
|
||||||
<string name="sync_auto_install_summary">Automatically install app updates after syncing repositories</string>
|
<string name="sync_auto_install_summary">Automatically install app updates after syncing repositories</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user