Skip to content

Commit

Permalink
Bring back onLatestUpdateInstalled() notification (#451)
Browse files Browse the repository at this point in the history
At some point we stopped calling onLatestUpdateInstalled(), making
in-app update UX quite confusing. This change restores it, but only for
manual update checks.
  • Loading branch information
luk1337 authored Oct 26, 2021
1 parent 0e6eef6 commit f502647
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/java/com/mxt/anitrend/util/JobSchedulerUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand All @@ -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()
Expand Down
1 change: 1 addition & 0 deletions app/src/main/java/com/mxt/anitrend/util/KeyUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ class MainActivity : ActivityBase<User, BasePresenter>(), View.OnClickListener,
this@MainActivity,
versionBase
)
else presenter.checkForUpdates()
else presenter.checkForUpdates(false)
}

override fun onNegativeButton() {
Expand Down Expand Up @@ -453,7 +453,9 @@ class MainActivity : ActivityBase<User, BasePresenter>(), View.OnClickListener,
workInfo.state == WorkInfo.State.SUCCEEDED
}
if (workInfo != null)
onUpdateChecked()
onUpdateChecked(
workInfo.outputData.getBoolean(KeyUtil.WorkUpdaterSilentId, false)
)
}
}

Expand All @@ -478,7 +480,7 @@ class MainActivity : ActivityBase<User, BasePresenter>(), View.OnClickListener,
)
}

private fun onUpdateChecked() {
private fun onUpdateChecked(silent: Boolean) {
val remoteVersion = presenter.database.remoteVersion

if (remoteVersion != null) {
Expand All @@ -488,6 +490,8 @@ class MainActivity : ActivityBase<User, BasePresenter>(), View.OnClickListener,
.actionView.findViewById<TextView>(R.id.app_update_info)
mAppUpdateWidget.text = getString(R.string.app_update, remoteVersion.version)
mAppUpdateWidget.visibility = View.VISIBLE
} else if (!silent) {
onLatestUpdateInstalled()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class SplashActivity : ActivityBase<Nothing, BasePresenter>() {
*/
override fun onActivityReady() {
lifecycleScope.launchWhenResumed {
presenter.checkForUpdates()
presenter.checkForUpdates(true)
presenter.checkValidAuth()
delay(500)
makeRequest()
Expand Down
8 changes: 6 additions & 2 deletions app/src/main/java/com/mxt/anitrend/worker/UpdateWorker.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
}

0 comments on commit f502647

Please sign in to comment.