From 18fa69a190b85a4ad19e3f3a6eb23aad51ebe2b0 Mon Sep 17 00:00:00 2001 From: kai-city <1830170041@qq.com> Date: Sat, 5 Jun 2021 22:22:21 +0800 Subject: [PATCH] =?UTF-8?q?1.=E4=BF=AE=E5=A4=8Ddialog=E6=9C=89=E6=97=B6?= =?UTF-8?q?=E4=B8=BA=E7=A9=BA=E7=9A=84=E9=97=AE=E9=A2=98=202.=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E9=80=89=E6=8B=A9=E5=99=A8=E9=80=89=E6=8B=A9apk?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E5=90=8E=EF=BC=8C=E4=B8=8B=E6=AC=A1=E9=BB=98?= =?UTF-8?q?=E8=AE=A4=E6=89=93=E5=BC=80=E4=B8=8A=E6=AC=A1=E6=89=93=E5=BC=80?= =?UTF-8?q?=E7=9A=84=E7=9B=AE=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../blackdex/view/main/MainActivity.kt | 50 +++++++++++-------- 1 file changed, 30 insertions(+), 20 deletions(-) diff --git a/app/src/main/java/top/niunaijun/blackdex/view/main/MainActivity.kt b/app/src/main/java/top/niunaijun/blackdex/view/main/MainActivity.kt index 75f3108..ba08713 100644 --- a/app/src/main/java/top/niunaijun/blackdex/view/main/MainActivity.kt +++ b/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.view.base.PermissionActivity import top.niunaijun.blackdex.view.setting.SettingActivity +import java.io.File class MainActivity : PermissionActivity() { @@ -39,6 +40,8 @@ class MainActivity : PermissionActivity() { private lateinit var loadingView: CatLoadingView + private var initialDir: File? = null + private var appList: List = ArrayList() override fun onCreate(savedInstanceState: Bundle?) { @@ -72,7 +75,9 @@ class MainActivity : PermissionActivity() { this.requestPermissionCallback = { if (it) { this.requestPermissionCallback = null - val initialDir = Environment.getExternalStorageDirectory() + if (initialDir == null) { + initialDir = Environment.getExternalStorageDirectory() + } MaterialDialog(this).show { fileChooser( this@MainActivity, @@ -80,9 +85,10 @@ class MainActivity : PermissionActivity() { filter = FileUtil::filterApk, ) { _, file -> viewModel.startDexDump(file.absolutePath) + this@MainActivity.initialDir = file.parentFile } - negativeButton(res = R.string.cancel) + negativeButton(R.string.cancel) } } @@ -117,35 +123,33 @@ class MainActivity : PermissionActivity() { showLoading() } DumpInfo.TIMEOUT -> { - loadingView.dismiss() + hideLoading() MaterialDialog(this).show { - title(res = R.string.unpack_fail) - message(res = R.string.jump_issue) - negativeButton(res = R.string.github) { - negativeButton(text = "Github") { - val intent = Intent( - Intent.ACTION_VIEW, - Uri.parse("https://github.com/CodingGay/BlackDex/issues") - ) - startActivity(intent) - } - positiveButton(res = R.string.confirm) - + title(R.string.unpack_fail) + message(R.string.jump_issue) + negativeButton(R.string.github) { + val intent = Intent( + Intent.ACTION_VIEW, + Uri.parse("https://github.com/CodingGay/BlackDex/issues") + ) + startActivity(intent) } + positiveButton(res = R.string.confirm) + } } else -> { viewModel.dexDumpSuccess() + hideLoading() val title = if (it.state == DumpInfo.SUCCESS) { - getString(R.string.unpack_success) + R.string.unpack_success } else { - getString(R.string.unpack_fail) + R.string.unpack_fail } - loadingView.dismiss() MaterialDialog(this).show { - title(text = title) + title(title) message(text = it.msg) - positiveButton(res = R.string.confirm) + positiveButton(R.string.confirm) } } } @@ -212,6 +216,12 @@ class MainActivity : PermissionActivity() { LoadingUtil.showLoading(loadingView, supportFragmentManager) } + private fun hideLoading() { + if (this::loadingView.isInitialized) { + loadingView.dismiss() + } + } + private fun hideKeyboard() { val imm: InputMethodManager = getSystemService(INPUT_METHOD_SERVICE) as InputMethodManager window.peekDecorView()?.run {