mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-12-31 04:58:50 +00:00
Added installing external modules from storage
This commit is contained in:
@@ -81,6 +81,13 @@ class RepoRvItem(val item: Repo) : ComparableRvItem<RepoRvItem>() {
|
||||
override fun itemSameAs(other: RepoRvItem): Boolean = item.id == other.item.id
|
||||
}
|
||||
|
||||
object InstallModule : ComparableRvItem<InstallModule>() {
|
||||
override val layoutRes = R.layout.item_module_download
|
||||
|
||||
override fun contentSameAs(other: InstallModule) = this == other
|
||||
override fun itemSameAs(other: InstallModule) = this === other
|
||||
}
|
||||
|
||||
class SectionTitle(
|
||||
val title: Int,
|
||||
val button: Int = 0,
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.topjohnwu.magisk.model.events
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import com.topjohnwu.magisk.Const
|
||||
import com.topjohnwu.magisk.base.BaseActivity
|
||||
import com.topjohnwu.magisk.intent
|
||||
import com.topjohnwu.magisk.ui.flash.FlashActivity
|
||||
|
||||
class InstallExternalModuleEvent : ViewEvent(), ActivityExecutor {
|
||||
|
||||
override fun invoke(activity: AppCompatActivity) {
|
||||
activity as BaseActivity<*, *>
|
||||
activity.withExternalRW {
|
||||
onSuccess {
|
||||
val intent = Intent(Intent.ACTION_GET_CONTENT)
|
||||
intent.type = "application/zip"
|
||||
activity.startActivityForResult(intent, Const.ID.FETCH_ZIP)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
fun onActivityResult(context: Context, requestCode: Int, resultCode: Int, data: Intent?) {
|
||||
if (requestCode == Const.ID.FETCH_ZIP && resultCode == Activity.RESULT_OK && data != null) {
|
||||
// Get the URI of the selected file
|
||||
val intent = context.intent(FlashActivity::class.java)
|
||||
intent.setData(data.data).putExtra(Const.Key.FLASH_ACTION, Const.Value.FLASH_ZIP)
|
||||
context.startActivity(intent)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.topjohnwu.magisk.redesign.module
|
||||
|
||||
import android.content.Intent
|
||||
import android.graphics.Insets
|
||||
import android.os.Bundle
|
||||
import android.view.Menu
|
||||
@@ -9,6 +10,7 @@ import android.view.View
|
||||
import androidx.recyclerview.widget.StaggeredGridLayoutManager
|
||||
import com.topjohnwu.magisk.R
|
||||
import com.topjohnwu.magisk.databinding.FragmentModuleMd2Binding
|
||||
import com.topjohnwu.magisk.model.events.InstallExternalModuleEvent
|
||||
import com.topjohnwu.magisk.redesign.MainActivity
|
||||
import com.topjohnwu.magisk.redesign.ReselectionTarget
|
||||
import com.topjohnwu.magisk.redesign.compat.CompatFragment
|
||||
@@ -27,6 +29,11 @@ class ModuleFragment : CompatFragment<ModuleViewModel, FragmentModuleMd2Binding>
|
||||
|
||||
override fun consumeSystemWindowInsets(insets: Insets) = insets
|
||||
|
||||
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
||||
super.onActivityResult(requestCode, resultCode, data)
|
||||
InstallExternalModuleEvent.onActivityResult(requireContext(), requestCode, resultCode, data)
|
||||
}
|
||||
|
||||
override fun onStart() {
|
||||
super.onStart()
|
||||
setHasOptionsMenu(true)
|
||||
|
||||
@@ -15,9 +15,11 @@ import com.topjohnwu.magisk.model.download.RemoteFileService
|
||||
import com.topjohnwu.magisk.model.entity.internal.DownloadSubject
|
||||
import com.topjohnwu.magisk.model.entity.module.Module
|
||||
import com.topjohnwu.magisk.model.entity.module.Repo
|
||||
import com.topjohnwu.magisk.model.entity.recycler.InstallModule
|
||||
import com.topjohnwu.magisk.model.entity.recycler.ModuleItem
|
||||
import com.topjohnwu.magisk.model.entity.recycler.RepoItem
|
||||
import com.topjohnwu.magisk.model.entity.recycler.SectionTitle
|
||||
import com.topjohnwu.magisk.model.events.InstallExternalModuleEvent
|
||||
import com.topjohnwu.magisk.model.events.dialog.ModuleInstallDialog
|
||||
import com.topjohnwu.magisk.redesign.compat.CompatViewModel
|
||||
import com.topjohnwu.magisk.redesign.compat.Queryable
|
||||
@@ -219,10 +221,12 @@ class ModuleViewModel(
|
||||
fun download(item: RepoItem) = ModuleInstallDialog(item.item).publish()
|
||||
|
||||
fun sectionPressed(item: SectionTitle) = when (item) {
|
||||
sectionActive -> reboot()
|
||||
sectionActive -> reboot() //TODO add reboot picker, regular reboot is not always preferred
|
||||
else -> Unit
|
||||
}
|
||||
|
||||
fun installPressed() = InstallExternalModuleEvent().publish()
|
||||
|
||||
// ---
|
||||
|
||||
/** Callable only from worker thread because of expensive list filtering */
|
||||
@@ -230,7 +234,7 @@ class ModuleViewModel(
|
||||
private fun build(
|
||||
active: List<ModuleItem> = itemsInstalled,
|
||||
remote: List<RepoItem> = itemsRemote
|
||||
) = active.prependIfNotEmpty { sectionActive } +
|
||||
) = (active + InstallModule).prependIfNotEmpty { sectionActive } +
|
||||
remote.prependIfNotEmpty { sectionRemote }
|
||||
|
||||
private fun <T> List<T>.prependIfNotEmpty(item: () -> T) =
|
||||
|
||||
Reference in New Issue
Block a user