aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYuutaW <17158086+Trumeet@users.noreply.github.com>2019-03-01 20:15:04 -0800
committerYuutaW <17158086+Trumeet@users.noreply.github.com>2019-03-01 20:15:04 -0800
commit3da1adf8a74a61044cc11501ef9677478311ec45 (patch)
tree4f641c4244493ffbbd11d33b450709250ba15060
parentf8d91a8664c3df2b267b4f800bba0929176ed8af (diff)
downloadWorkMode-3da1adf8a74a61044cc11501ef9677478311ec45.tar
WorkMode-3da1adf8a74a61044cc11501ef9677478311ec45.tar.gz
WorkMode-3da1adf8a74a61044cc11501ef9677478311ec45.tar.bz2
WorkMode-3da1adf8a74a61044cc11501ef9677478311ec45.zip
feat(app): check updates directly when user requests, but not open the browser
Signed-off-by: YuutaW <17158086+Trumeet@users.noreply.github.com>
-rw-r--r--app/src/main/java/moe/yuuta/workmode/MainActivity.kt8
-rw-r--r--app/src/main/java/moe/yuuta/workmode/update/LifecycleUpdateChecker.kt5
2 files changed, 9 insertions, 4 deletions
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<Update> {
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()
}