From f50264742c4fbc99251cf6588c2c17fcee4a24c8 Mon Sep 17 00:00:00 2001 From: luk1337 Date: Tue, 26 Oct 2021 08:36:51 +0200 Subject: [PATCH] Bring back onLatestUpdateInstalled() notification (#451) At some point we stopped calling onLatestUpdateInstalled(), making in-app update UX quite confusing. This change restores it, but only for manual update checks. --- .../com/mxt/anitrend/presenter/base/BasePresenter.kt | 4 ++-- .../java/com/mxt/anitrend/util/JobSchedulerUtil.kt | 3 ++- app/src/main/java/com/mxt/anitrend/util/KeyUtil.java | 1 + .../mxt/anitrend/view/activity/index/MainActivity.kt | 10 +++++++--- .../mxt/anitrend/view/activity/index/SplashActivity.kt | 2 +- .../main/java/com/mxt/anitrend/worker/UpdateWorker.kt | 8 ++++++-- 6 files changed, 19 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/com/mxt/anitrend/presenter/base/BasePresenter.kt b/app/src/main/java/com/mxt/anitrend/presenter/base/BasePresenter.kt index de49caa9c..f7d2011f5 100644 --- a/app/src/main/java/com/mxt/anitrend/presenter/base/BasePresenter.kt +++ b/app/src/main/java/com/mxt/anitrend/presenter/base/BasePresenter.kt @@ -190,9 +190,9 @@ open class BasePresenter(context: Context?) : CommonPresenter(context) { /** * Runs worker to check for updates */ - fun checkForUpdates() { + fun checkForUpdates(silent: Boolean) { val scheduler = JobSchedulerUtil(settings) - scheduler.startUpdateJob(context) + scheduler.startUpdateJob(context, silent) } companion object { diff --git a/app/src/main/java/com/mxt/anitrend/util/JobSchedulerUtil.kt b/app/src/main/java/com/mxt/anitrend/util/JobSchedulerUtil.kt index 2ea322b9e..bfaa5bc3e 100644 --- a/app/src/main/java/com/mxt/anitrend/util/JobSchedulerUtil.kt +++ b/app/src/main/java/com/mxt/anitrend/util/JobSchedulerUtil.kt @@ -105,7 +105,7 @@ class JobSchedulerUtil(private val settings: Settings) { } } - fun startUpdateJob(context: Context) { + fun startUpdateJob(context: Context, silent: Boolean) { val workRequest = OneTimeWorkRequest.Builder( UpdateWorker::class.java ) @@ -114,6 +114,7 @@ class JobSchedulerUtil(private val settings: Settings) { 5, TimeUnit.MINUTES ) + .setInputData(workDataOf(KeyUtil.WorkUpdaterSilentId to silent)) .addTag(KeyUtil.WorkUpdaterId) .setConstraints(getConstraints()) .build() diff --git a/app/src/main/java/com/mxt/anitrend/util/KeyUtil.java b/app/src/main/java/com/mxt/anitrend/util/KeyUtil.java index b03018f5d..ec00a49ac 100644 --- a/app/src/main/java/com/mxt/anitrend/util/KeyUtil.java +++ b/app/src/main/java/com/mxt/anitrend/util/KeyUtil.java @@ -35,6 +35,7 @@ public interface KeyUtil { String WorkTagSyncId = "periodic_tag_sync"; String WorkGenreSyncId = "periodic_genre_sync"; String WorkUpdaterId = "one_time_updater"; + String WorkUpdaterSilentId = "silent"; String WorkClearNotificationTag = "anitrend_clear_notification_job"; String WorkClearNotificationId = "clear_notification_sync"; diff --git a/app/src/main/java/com/mxt/anitrend/view/activity/index/MainActivity.kt b/app/src/main/java/com/mxt/anitrend/view/activity/index/MainActivity.kt index f3dde3a15..3a14f5ba0 100644 --- a/app/src/main/java/com/mxt/anitrend/view/activity/index/MainActivity.kt +++ b/app/src/main/java/com/mxt/anitrend/view/activity/index/MainActivity.kt @@ -371,7 +371,7 @@ class MainActivity : ActivityBase(), View.OnClickListener, this@MainActivity, versionBase ) - else presenter.checkForUpdates() + else presenter.checkForUpdates(false) } override fun onNegativeButton() { @@ -453,7 +453,9 @@ class MainActivity : ActivityBase(), View.OnClickListener, workInfo.state == WorkInfo.State.SUCCEEDED } if (workInfo != null) - onUpdateChecked() + onUpdateChecked( + workInfo.outputData.getBoolean(KeyUtil.WorkUpdaterSilentId, false) + ) } } @@ -478,7 +480,7 @@ class MainActivity : ActivityBase(), View.OnClickListener, ) } - private fun onUpdateChecked() { + private fun onUpdateChecked(silent: Boolean) { val remoteVersion = presenter.database.remoteVersion if (remoteVersion != null) { @@ -488,6 +490,8 @@ class MainActivity : ActivityBase(), View.OnClickListener, .actionView.findViewById(R.id.app_update_info) mAppUpdateWidget.text = getString(R.string.app_update, remoteVersion.version) mAppUpdateWidget.visibility = View.VISIBLE + } else if (!silent) { + onLatestUpdateInstalled() } } } diff --git a/app/src/main/java/com/mxt/anitrend/view/activity/index/SplashActivity.kt b/app/src/main/java/com/mxt/anitrend/view/activity/index/SplashActivity.kt index 2dd2510f3..549c1a45b 100644 --- a/app/src/main/java/com/mxt/anitrend/view/activity/index/SplashActivity.kt +++ b/app/src/main/java/com/mxt/anitrend/view/activity/index/SplashActivity.kt @@ -53,7 +53,7 @@ class SplashActivity : ActivityBase() { */ override fun onActivityReady() { lifecycleScope.launchWhenResumed { - presenter.checkForUpdates() + presenter.checkForUpdates(true) presenter.checkValidAuth() delay(500) makeRequest() diff --git a/app/src/main/java/com/mxt/anitrend/worker/UpdateWorker.kt b/app/src/main/java/com/mxt/anitrend/worker/UpdateWorker.kt index c5c610d79..35497a17a 100644 --- a/app/src/main/java/com/mxt/anitrend/worker/UpdateWorker.kt +++ b/app/src/main/java/com/mxt/anitrend/worker/UpdateWorker.kt @@ -4,6 +4,7 @@ import android.content.Context import androidx.work.CoroutineWorker import androidx.work.Data import androidx.work.WorkerParameters +import androidx.work.workDataOf import com.mxt.anitrend.model.api.retro.WebFactory import com.mxt.anitrend.model.entity.base.VersionBase import com.mxt.anitrend.presenter.widget.WidgetPresenter @@ -68,8 +69,11 @@ class UpdateWorker( Timber.e(it) } + val silent = inputData.getBoolean(KeyUtil.WorkUpdaterSilentId, false) + val output = workDataOf(KeyUtil.WorkUpdaterSilentId to silent) + return if (result.isSuccess) - Result.success() - else Result.failure() + Result.success(output) + else Result.failure(output) } } \ No newline at end of file