From f29cc26103ae6b6b6f5ae09c7cc9de8a7a14b8c2 Mon Sep 17 00:00:00 2001 From: LoveSy Date: Thu, 6 Apr 2023 16:15:32 +0800 Subject: [PATCH] Correctly get displayName of live uri --- .../com/topjohnwu/magisk/dialog/LocalModuleInstallDialog.kt | 6 +++--- .../java/com/topjohnwu/magisk/ui/module/ModuleFragment.kt | 4 +++- .../java/com/topjohnwu/magisk/ui/module/ModuleViewModel.kt | 4 ++-- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/com/topjohnwu/magisk/dialog/LocalModuleInstallDialog.kt b/app/src/main/java/com/topjohnwu/magisk/dialog/LocalModuleInstallDialog.kt index 1049e1710..cae990f52 100644 --- a/app/src/main/java/com/topjohnwu/magisk/dialog/LocalModuleInstallDialog.kt +++ b/app/src/main/java/com/topjohnwu/magisk/dialog/LocalModuleInstallDialog.kt @@ -4,19 +4,19 @@ import android.net.Uri import com.topjohnwu.magisk.MainDirections import com.topjohnwu.magisk.R import com.topjohnwu.magisk.core.Const -import com.topjohnwu.magisk.core.utils.MediaStoreUtils.displayName import com.topjohnwu.magisk.events.DialogBuilder import com.topjohnwu.magisk.ui.module.ModuleViewModel import com.topjohnwu.magisk.view.MagiskDialog class LocalModuleInstallDialog( private val viewModel: ModuleViewModel, - private val uri: Uri + private val uri: Uri, + private val displayName: String ) : DialogBuilder { override fun build(dialog: MagiskDialog) { dialog.apply { setTitle(R.string.confirm_install_title) - setMessage(context.getString(R.string.confirm_install, uri.displayName)) + setMessage(context.getString(R.string.confirm_install, displayName)) setButton(MagiskDialog.ButtonType.POSITIVE) { text = android.R.string.ok onClick { diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/module/ModuleFragment.kt b/app/src/main/java/com/topjohnwu/magisk/ui/module/ModuleFragment.kt index 86c9813f5..8c8ea9fdb 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/module/ModuleFragment.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/module/ModuleFragment.kt @@ -5,6 +5,7 @@ import android.view.View import com.topjohnwu.magisk.R import com.topjohnwu.magisk.arch.BaseFragment import com.topjohnwu.magisk.arch.viewModel +import com.topjohnwu.magisk.core.utils.MediaStoreUtils.displayName import com.topjohnwu.magisk.databinding.FragmentModuleMd2Binding import rikka.recyclerview.addEdgeSpacing import rikka.recyclerview.addInvalidateItemDecorationsObserver @@ -21,7 +22,8 @@ class ModuleFragment : BaseFragment() { activity?.title = resources.getString(R.string.modules) viewModel.data.observe(this) { it ?: return@observe - viewModel.requestInstallLocalModule(it) + val displayName = runCatching { it.displayName }.getOrNull() ?: return@observe + viewModel.requestInstallLocalModule(it, displayName) viewModel.data.value = null } } diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/module/ModuleViewModel.kt b/app/src/main/java/com/topjohnwu/magisk/ui/module/ModuleViewModel.kt index ec9cbb6b6..b2379d9a4 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/module/ModuleViewModel.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/module/ModuleViewModel.kt @@ -84,8 +84,8 @@ class ModuleViewModel : AsyncLoadViewModel() { GetContentEvent("application/zip", UriCallback()).publish() } - fun requestInstallLocalModule(uri: Uri) { - LocalModuleInstallDialog(this, uri).show() + fun requestInstallLocalModule(uri: Uri, displayName: String) { + LocalModuleInstallDialog(this, uri, displayName).show() } @Parcelize