Merge pull request #15 from wukaicheng/main

优化体验
pull/16/head
Milk 4 years ago committed by GitHub
commit 095ad946e2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 36
      app/src/main/java/top/niunaijun/blackdex/view/main/MainActivity.kt

@ -27,6 +27,7 @@ import top.niunaijun.blackdex.util.LoadingUtil
import top.niunaijun.blackdex.util.inflate import top.niunaijun.blackdex.util.inflate
import top.niunaijun.blackdex.view.base.PermissionActivity import top.niunaijun.blackdex.view.base.PermissionActivity
import top.niunaijun.blackdex.view.setting.SettingActivity import top.niunaijun.blackdex.view.setting.SettingActivity
import java.io.File
class MainActivity : PermissionActivity() { class MainActivity : PermissionActivity() {
@ -39,6 +40,8 @@ class MainActivity : PermissionActivity() {
private lateinit var loadingView: CatLoadingView private lateinit var loadingView: CatLoadingView
private var initialDir: File? = null
private var appList: List<AppInfo> = ArrayList() private var appList: List<AppInfo> = ArrayList()
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
@ -72,7 +75,9 @@ class MainActivity : PermissionActivity() {
this.requestPermissionCallback = { this.requestPermissionCallback = {
if (it) { if (it) {
this.requestPermissionCallback = null this.requestPermissionCallback = null
val initialDir = Environment.getExternalStorageDirectory() if (initialDir == null) {
initialDir = Environment.getExternalStorageDirectory()
}
MaterialDialog(this).show { MaterialDialog(this).show {
fileChooser( fileChooser(
this@MainActivity, this@MainActivity,
@ -80,9 +85,10 @@ class MainActivity : PermissionActivity() {
filter = FileUtil::filterApk, filter = FileUtil::filterApk,
) { _, file -> ) { _, file ->
viewModel.startDexDump(file.absolutePath) viewModel.startDexDump(file.absolutePath)
this@MainActivity.initialDir = file.parentFile
} }
negativeButton(res = R.string.cancel) negativeButton(R.string.cancel)
} }
} }
@ -117,12 +123,11 @@ class MainActivity : PermissionActivity() {
showLoading() showLoading()
} }
DumpInfo.TIMEOUT -> { DumpInfo.TIMEOUT -> {
loadingView.dismiss() hideLoading()
MaterialDialog(this).show { MaterialDialog(this).show {
title(res = R.string.unpack_fail) title(R.string.unpack_fail)
message(res = R.string.jump_issue) message(R.string.jump_issue)
negativeButton(res = R.string.github) { negativeButton(R.string.github) {
negativeButton(text = "Github") {
val intent = Intent( val intent = Intent(
Intent.ACTION_VIEW, Intent.ACTION_VIEW,
Uri.parse("https://github.com/CodingGay/BlackDex/issues") Uri.parse("https://github.com/CodingGay/BlackDex/issues")
@ -133,19 +138,18 @@ class MainActivity : PermissionActivity() {
} }
} }
}
else -> { else -> {
viewModel.dexDumpSuccess() viewModel.dexDumpSuccess()
hideLoading()
val title = if (it.state == DumpInfo.SUCCESS) { val title = if (it.state == DumpInfo.SUCCESS) {
getString(R.string.unpack_success) R.string.unpack_success
} else { } else {
getString(R.string.unpack_fail) R.string.unpack_fail
} }
loadingView.dismiss()
MaterialDialog(this).show { MaterialDialog(this).show {
title(text = title) title(title)
message(text = it.msg) message(text = it.msg)
positiveButton(res = R.string.confirm) positiveButton(R.string.confirm)
} }
} }
} }
@ -212,6 +216,12 @@ class MainActivity : PermissionActivity() {
LoadingUtil.showLoading(loadingView, supportFragmentManager) LoadingUtil.showLoading(loadingView, supportFragmentManager)
} }
private fun hideLoading() {
if (this::loadingView.isInitialized) {
loadingView.dismiss()
}
}
private fun hideKeyboard() { private fun hideKeyboard() {
val imm: InputMethodManager = getSystemService(INPUT_METHOD_SERVICE) as InputMethodManager val imm: InputMethodManager = getSystemService(INPUT_METHOD_SERVICE) as InputMethodManager
window.peekDecorView()?.run { window.peekDecorView()?.run {

Loading…
Cancel
Save