feat: 优化

pull/241/head
gedoor 5 years ago
parent aab5ee3724
commit 90ac85517d
  1. 22
      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<MainViewModel>(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<Int, Fragment>(
@ -105,8 +106,14 @@ class MainActivity : VMBaseActivity<MainViewModel>(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<MainViewModel>(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)

Loading…
Cancel
Save