From 90ac85517d24d5b1dcbefef36b012f8a288603fa Mon Sep 17 00:00:00 2001 From: gedoor Date: Thu, 11 Jun 2020 21:55:03 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/ui/main/MainActivity.kt | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/main/MainActivity.kt b/app/src/main/java/io/legado/app/ui/main/MainActivity.kt index 181ec0330..8664d2eab 100644 --- a/app/src/main/java/io/legado/app/ui/main/MainActivity.kt +++ b/app/src/main/java/io/legado/app/ui/main/MainActivity.kt @@ -26,13 +26,14 @@ import io.legado.app.ui.main.rss.RssFragment import io.legado.app.ui.widget.dialog.TextDialog import io.legado.app.utils.* import kotlinx.android.synthetic.main.activity_main.* +import org.jetbrains.anko.toast class MainActivity : VMBaseActivity(R.layout.activity_main), BottomNavigationView.OnNavigationItemSelectedListener, ViewPager.OnPageChangeListener by ViewPager.SimpleOnPageChangeListener() { override val viewModel: MainViewModel get() = getViewModel(MainViewModel::class.java) - + private var exitTime: Long = 0 private var pagePosition = 0 private val fragmentId = arrayOf(0, 1, 2, 3) private val fragmentMap = mapOf( @@ -105,8 +106,14 @@ class MainActivity : VMBaseActivity(R.layout.activity_main), return true } if (!BaseReadAloudService.pause) { - moveTaskToBack(true) - return true + if (System.currentTimeMillis() - exitTime > 2000) { + toast(R.string.double_click_exit) + exitTime = System.currentTimeMillis() + } else { + moveTaskToBack(true) + return true + } + return false } } } @@ -121,6 +128,15 @@ class MainActivity : VMBaseActivity(R.layout.activity_main), } } + override fun finish() { + if (System.currentTimeMillis() - exitTime > 2000) { + toast(R.string.double_click_exit) + exitTime = System.currentTimeMillis() + } else { + super.finish() + } + } + override fun onDestroy() { super.onDestroy() ReadAloud.stop(this)