From 3da1adf8a74a61044cc11501ef9677478311ec45 Mon Sep 17 00:00:00 2001 From: YuutaW <17158086+Trumeet@users.noreply.github.com> Date: Fri, 1 Mar 2019 20:15:04 -0800 Subject: feat(app): check updates directly when user requests, but not open the browser Signed-off-by: YuutaW <17158086+Trumeet@users.noreply.github.com> --- app/src/main/java/moe/yuuta/workmode/MainActivity.kt | 8 ++++++-- .../main/java/moe/yuuta/workmode/update/LifecycleUpdateChecker.kt | 5 +++-- 2 files changed, 9 insertions(+), 4 deletions(-) (limited to 'app/src/main/java') diff --git a/app/src/main/java/moe/yuuta/workmode/MainActivity.kt b/app/src/main/java/moe/yuuta/workmode/MainActivity.kt index 72f1050..e2ff1e1 100644 --- a/app/src/main/java/moe/yuuta/workmode/MainActivity.kt +++ b/app/src/main/java/moe/yuuta/workmode/MainActivity.kt @@ -54,6 +54,8 @@ class MainActivity : AppCompatActivity(), SwitchBar.OnSwitchChangeListener, View private lateinit var tabLayout: TabLayout private lateinit var welcomeTip: TextView + private lateinit var mCheckUpdateObserver: LifecycleUpdateChecker + private val mStoppableGroup: StoppableGroup = StoppableGroup() private var mSortDisplayStoppable: Stoppable? = null @@ -74,8 +76,9 @@ class MainActivity : AppCompatActivity(), SwitchBar.OnSwitchChangeListener, View mAdapter = Adapter() recyclerView.adapter = mAdapter displayUI() + mCheckUpdateObserver = LifecycleUpdateChecker(this, this) lifecycle.addObserver(LifecycleUIUpdateReceiver(this, this)) - lifecycle.addObserver(LifecycleUpdateChecker(this, this)) + lifecycle.addObserver(mCheckUpdateObserver) lifecycle.addObserver(GPL(this, lifecycle, this)) setProgressUI(false) } @@ -286,7 +289,7 @@ class MainActivity : AppCompatActivity(), SwitchBar.OnSwitchChangeListener, View return true } R.id.action_check_update -> { - startActivity(Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=${BuildConfig.APPLICATION_ID}"))) + mCheckUpdateObserver.start() return true } R.id.action_oss -> { @@ -338,6 +341,7 @@ class MainActivity : AppCompatActivity(), SwitchBar.OnSwitchChangeListener, View val manager = getSystemService(NotificationManager::class.java) manager.createNotificationChannel(NotificationChannel("update", getString(R.string.notification_channel_update), NotificationManager.IMPORTANCE_HIGH)) + manager.cancel(0) manager.notify(0, Notification.Builder(this, "update") .setContentTitle(getString(R.string.notification_title_update, name)) .setContentText(getString(R.string.notification_text_update_summary)) diff --git a/app/src/main/java/moe/yuuta/workmode/update/LifecycleUpdateChecker.kt b/app/src/main/java/moe/yuuta/workmode/update/LifecycleUpdateChecker.kt index 9e2cd89..7c523f4 100644 --- a/app/src/main/java/moe/yuuta/workmode/update/LifecycleUpdateChecker.kt +++ b/app/src/main/java/moe/yuuta/workmode/update/LifecycleUpdateChecker.kt @@ -13,7 +13,8 @@ class LifecycleUpdateChecker(val context: Context, val callback: moe.yuuta.workm private lateinit var mStoppable: Stoppable @OnLifecycleEvent(Lifecycle.Event.ON_CREATE) - fun onCreate() { + fun start() { + stop() mStoppable = Async.beginTask(UpdateChecker(), object : Callback { override fun onStop(success: Boolean, result: Update?, e: Throwable?) { if (result == null) return @@ -32,7 +33,7 @@ class LifecycleUpdateChecker(val context: Context, val callback: moe.yuuta.workm } @OnLifecycleEvent(Lifecycle.Event.ON_DESTROY) - fun onDestroy() { + fun stop() { if (::mStoppable.isInitialized) { mStoppable.stop() } -- cgit v1.2.3