mirror of
https://github.com/kvorschk/Magisk.git
synced 2026-12-04 19:10:47 -05:00
Migrate Modules screen to Jetpack Compose with miuix
Replace Fragment data-binding UI with a Compose-based ModuleScreen using miuix Card, Switch, and TextButton components. ModuleViewModel now uses StateFlow<UiState> and Compose-friendly ModuleItem with mutableStateOf for enable/remove/update state. Each module card shows name, version/author, description, enable toggle, and action/update/ remove buttons. Remove old ModuleRvItem, XML layouts, and stale navigation reference. Made-with: Cursor
This commit is contained in:
@@ -1,45 +1,71 @@
|
||||
package com.topjohnwu.magisk.ui.module
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import com.topjohnwu.magisk.R
|
||||
import com.topjohnwu.magisk.arch.BaseFragment
|
||||
import com.topjohnwu.magisk.arch.viewModel
|
||||
import android.view.ViewGroup
|
||||
import androidx.compose.ui.platform.ComposeView
|
||||
import androidx.compose.ui.platform.ViewCompositionStrategy
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import com.topjohnwu.magisk.arch.ActivityExecutor
|
||||
import com.topjohnwu.magisk.arch.ContextExecutor
|
||||
import com.topjohnwu.magisk.arch.NavigationActivity
|
||||
import com.topjohnwu.magisk.arch.UIActivity
|
||||
import com.topjohnwu.magisk.arch.VMFactory
|
||||
import com.topjohnwu.magisk.arch.ViewEvent
|
||||
import com.topjohnwu.magisk.arch.ViewModelHolder
|
||||
import com.topjohnwu.magisk.core.utils.MediaStoreUtils.displayName
|
||||
import com.topjohnwu.magisk.databinding.FragmentModuleMd2Binding
|
||||
import rikka.recyclerview.addEdgeSpacing
|
||||
import rikka.recyclerview.addInvalidateItemDecorationsObserver
|
||||
import rikka.recyclerview.addItemSpacing
|
||||
import rikka.recyclerview.fixEdgeEffect
|
||||
import com.topjohnwu.magisk.ui.theme.MagiskTheme
|
||||
import com.topjohnwu.magisk.core.R as CoreR
|
||||
|
||||
class ModuleFragment : BaseFragment<FragmentModuleMd2Binding>() {
|
||||
class ModuleFragment : Fragment(), ViewModelHolder {
|
||||
|
||||
override val layoutRes = R.layout.fragment_module_md2
|
||||
override val viewModel by viewModel<ModuleViewModel>()
|
||||
override val viewModel by lazy {
|
||||
ViewModelProvider(this, VMFactory)[ModuleViewModel::class.java]
|
||||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
startObserveLiveData()
|
||||
}
|
||||
|
||||
override fun onStart() {
|
||||
super.onStart()
|
||||
activity?.title = resources.getString(CoreR.string.modules)
|
||||
viewModel.data.observe(this) {
|
||||
(activity as? NavigationActivity<*>)?.setTitle(CoreR.string.modules)
|
||||
(viewModel as ModuleViewModel).data.observe(this) {
|
||||
it ?: return@observe
|
||||
val vm = viewModel as ModuleViewModel
|
||||
val displayName = runCatching { it.displayName }.getOrNull() ?: return@observe
|
||||
viewModel.requestInstallLocalModule(it, displayName)
|
||||
viewModel.data.value = null
|
||||
vm.requestInstallLocalModule(it, displayName)
|
||||
vm.data.value = null
|
||||
}
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
binding.moduleList.apply {
|
||||
addEdgeSpacing(top = R.dimen.l_50, bottom = R.dimen.l1)
|
||||
addItemSpacing(R.dimen.l1, R.dimen.l_50, R.dimen.l1)
|
||||
fixEdgeEffect()
|
||||
post { addInvalidateItemDecorationsObserver() }
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View {
|
||||
return ComposeView(requireContext()).apply {
|
||||
setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed)
|
||||
setContent {
|
||||
MagiskTheme {
|
||||
ModuleScreen(viewModel = viewModel as ModuleViewModel)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onPreBind(binding: FragmentModuleMd2Binding) = Unit
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
(viewModel as ModuleViewModel).startLoading()
|
||||
}
|
||||
|
||||
override fun onEventDispatched(event: ViewEvent) {
|
||||
when (event) {
|
||||
is ContextExecutor -> event(requireContext())
|
||||
is ActivityExecutor -> (activity as? UIActivity<*>)?.let { event(it) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,78 +0,0 @@
|
||||
package com.topjohnwu.magisk.ui.module
|
||||
|
||||
import androidx.databinding.Bindable
|
||||
import com.topjohnwu.magisk.BR
|
||||
import com.topjohnwu.magisk.R
|
||||
import com.topjohnwu.magisk.core.Info
|
||||
import com.topjohnwu.magisk.core.model.module.LocalModule
|
||||
import com.topjohnwu.magisk.databinding.DiffItem
|
||||
import com.topjohnwu.magisk.databinding.ItemWrapper
|
||||
import com.topjohnwu.magisk.databinding.ObservableRvItem
|
||||
import com.topjohnwu.magisk.databinding.RvItem
|
||||
import com.topjohnwu.magisk.databinding.set
|
||||
import com.topjohnwu.magisk.utils.TextHolder
|
||||
import com.topjohnwu.magisk.utils.asText
|
||||
import com.topjohnwu.magisk.core.R as CoreR
|
||||
|
||||
object InstallModule : RvItem(), DiffItem<InstallModule> {
|
||||
override val layoutRes = R.layout.item_module_download
|
||||
}
|
||||
|
||||
class LocalModuleRvItem(
|
||||
override val item: LocalModule
|
||||
) : ObservableRvItem(), DiffItem<LocalModuleRvItem>, ItemWrapper<LocalModule> {
|
||||
|
||||
override val layoutRes = R.layout.item_module_md2
|
||||
|
||||
val showNotice: Boolean
|
||||
val showAction: Boolean
|
||||
val noticeText: TextHolder
|
||||
|
||||
init {
|
||||
val isZygisk = item.isZygisk
|
||||
val isRiru = item.isRiru
|
||||
val zygiskUnloaded = isZygisk && item.zygiskUnloaded
|
||||
|
||||
showNotice = zygiskUnloaded ||
|
||||
(Info.isZygiskEnabled && isRiru) ||
|
||||
(!Info.isZygiskEnabled && isZygisk)
|
||||
showAction = item.hasAction && !showNotice
|
||||
noticeText =
|
||||
when {
|
||||
zygiskUnloaded -> CoreR.string.zygisk_module_unloaded.asText()
|
||||
isRiru -> CoreR.string.suspend_text_riru.asText(CoreR.string.zygisk.asText())
|
||||
else -> CoreR.string.suspend_text_zygisk.asText(CoreR.string.zygisk.asText())
|
||||
}
|
||||
}
|
||||
|
||||
@get:Bindable
|
||||
var isEnabled = item.enable
|
||||
set(value) = set(value, field, { field = it }, BR.enabled, BR.updateReady) {
|
||||
item.enable = value
|
||||
}
|
||||
|
||||
@get:Bindable
|
||||
var isRemoved = item.remove
|
||||
set(value) = set(value, field, { field = it }, BR.removed, BR.updateReady) {
|
||||
item.remove = value
|
||||
}
|
||||
|
||||
@get:Bindable
|
||||
val showUpdate get() = item.updateInfo != null
|
||||
|
||||
@get:Bindable
|
||||
val updateReady get() = item.outdated && !isRemoved && isEnabled
|
||||
|
||||
val isUpdated = item.updated
|
||||
|
||||
fun fetchedUpdateInfo() {
|
||||
notifyPropertyChanged(BR.showUpdate)
|
||||
notifyPropertyChanged(BR.updateReady)
|
||||
}
|
||||
|
||||
fun delete() {
|
||||
isRemoved = !isRemoved
|
||||
}
|
||||
|
||||
override fun itemSameAs(other: LocalModuleRvItem): Boolean = item.id == other.item.id
|
||||
}
|
||||
@@ -0,0 +1,179 @@
|
||||
package com.topjohnwu.magisk.ui.module
|
||||
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.lazy.LazyColumn
|
||||
import androidx.compose.foundation.lazy.items
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.collectAsState
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.alpha
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.style.TextDecoration
|
||||
import androidx.compose.ui.unit.dp
|
||||
import top.yukonga.miuix.kmp.basic.Card
|
||||
import top.yukonga.miuix.kmp.basic.CircularProgressIndicator
|
||||
import top.yukonga.miuix.kmp.basic.Switch
|
||||
import top.yukonga.miuix.kmp.basic.Text
|
||||
import top.yukonga.miuix.kmp.basic.TextButton
|
||||
import top.yukonga.miuix.kmp.theme.MiuixTheme
|
||||
import com.topjohnwu.magisk.core.R as CoreR
|
||||
|
||||
@Composable
|
||||
fun ModuleScreen(viewModel: ModuleViewModel) {
|
||||
val uiState by viewModel.uiState.collectAsState()
|
||||
|
||||
if (uiState.loading) {
|
||||
Box(
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
contentAlignment = Alignment.Center
|
||||
) {
|
||||
CircularProgressIndicator()
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
LazyColumn(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.padding(horizontal = 12.dp),
|
||||
verticalArrangement = Arrangement.spacedBy(8.dp)
|
||||
) {
|
||||
item { Spacer(Modifier.height(4.dp)) }
|
||||
|
||||
item {
|
||||
TextButton(
|
||||
text = stringResource(CoreR.string.module_action_install_external),
|
||||
onClick = { viewModel.installPressed() },
|
||||
modifier = Modifier.fillMaxWidth()
|
||||
)
|
||||
}
|
||||
|
||||
if (uiState.modules.isEmpty()) {
|
||||
item {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(vertical = 32.dp),
|
||||
contentAlignment = Alignment.Center
|
||||
) {
|
||||
Text(
|
||||
text = stringResource(CoreR.string.module_empty),
|
||||
style = MiuixTheme.textStyles.body1,
|
||||
color = MiuixTheme.colorScheme.onSurfaceVariantSummary
|
||||
)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
items(uiState.modules, key = { it.module.id }) { item ->
|
||||
ModuleCard(item = item, viewModel = viewModel)
|
||||
}
|
||||
}
|
||||
|
||||
item { Spacer(Modifier.height(4.dp)) }
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun ModuleCard(item: ModuleItem, viewModel: ModuleViewModel) {
|
||||
val cardAlpha = if (!item.isRemoved && item.isEnabled && !item.showNotice) 1f else 0.5f
|
||||
val strikeThrough = if (item.isRemoved) TextDecoration.LineThrough else TextDecoration.None
|
||||
|
||||
Card(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.alpha(cardAlpha)
|
||||
) {
|
||||
Column(modifier = Modifier.padding(16.dp)) {
|
||||
Row(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
Column(modifier = Modifier.weight(1f)) {
|
||||
Text(
|
||||
text = item.module.name,
|
||||
style = MiuixTheme.textStyles.body1,
|
||||
textDecoration = strikeThrough,
|
||||
)
|
||||
Text(
|
||||
text = stringResource(
|
||||
CoreR.string.module_version_author,
|
||||
item.module.version,
|
||||
item.module.author
|
||||
),
|
||||
style = MiuixTheme.textStyles.body2,
|
||||
color = MiuixTheme.colorScheme.onSurfaceVariantSummary,
|
||||
textDecoration = strikeThrough,
|
||||
)
|
||||
}
|
||||
Switch(
|
||||
checked = item.isEnabled,
|
||||
onCheckedChange = { viewModel.toggleEnabled(item) }
|
||||
)
|
||||
}
|
||||
|
||||
if (item.module.description.isNotEmpty()) {
|
||||
Spacer(Modifier.height(8.dp))
|
||||
Text(
|
||||
text = item.module.description,
|
||||
style = MiuixTheme.textStyles.body2,
|
||||
color = MiuixTheme.colorScheme.onSurfaceVariantSummary,
|
||||
textDecoration = strikeThrough,
|
||||
maxLines = 5,
|
||||
)
|
||||
}
|
||||
|
||||
if (item.showNotice) {
|
||||
Spacer(Modifier.height(8.dp))
|
||||
Text(
|
||||
text = item.noticeText,
|
||||
style = MiuixTheme.textStyles.body2,
|
||||
color = MiuixTheme.colorScheme.primary,
|
||||
)
|
||||
}
|
||||
|
||||
Spacer(Modifier.height(8.dp))
|
||||
|
||||
Row(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
horizontalArrangement = Arrangement.spacedBy(8.dp)
|
||||
) {
|
||||
if (item.showAction) {
|
||||
TextButton(
|
||||
text = stringResource(CoreR.string.module_action),
|
||||
onClick = { viewModel.runAction(item.module.id, item.module.name) },
|
||||
enabled = item.isEnabled
|
||||
)
|
||||
}
|
||||
|
||||
if (item.showUpdate) {
|
||||
TextButton(
|
||||
text = stringResource(CoreR.string.update),
|
||||
onClick = { viewModel.downloadPressed(item.module.updateInfo) },
|
||||
enabled = item.updateReady
|
||||
)
|
||||
}
|
||||
|
||||
Spacer(Modifier.weight(1f))
|
||||
|
||||
TextButton(
|
||||
text = stringResource(
|
||||
if (item.isRemoved) CoreR.string.module_state_restore
|
||||
else CoreR.string.module_state_remove
|
||||
),
|
||||
onClick = { viewModel.toggleRemove(item) },
|
||||
enabled = !item.isUpdated
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,77 +1,93 @@
|
||||
package com.topjohnwu.magisk.ui.module
|
||||
|
||||
import android.net.Uri
|
||||
import androidx.databinding.Bindable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import com.topjohnwu.magisk.BR
|
||||
import com.topjohnwu.magisk.MainDirections
|
||||
import com.topjohnwu.magisk.R
|
||||
import com.topjohnwu.magisk.arch.AsyncLoadViewModel
|
||||
import com.topjohnwu.magisk.core.Const
|
||||
import com.topjohnwu.magisk.core.Info
|
||||
import com.topjohnwu.magisk.core.base.ContentResultCallback
|
||||
import com.topjohnwu.magisk.core.model.module.LocalModule
|
||||
import com.topjohnwu.magisk.core.model.module.OnlineModule
|
||||
import com.topjohnwu.magisk.databinding.MergeObservableList
|
||||
import com.topjohnwu.magisk.databinding.RvItem
|
||||
import com.topjohnwu.magisk.databinding.bindExtra
|
||||
import com.topjohnwu.magisk.databinding.diffList
|
||||
import com.topjohnwu.magisk.databinding.set
|
||||
import com.topjohnwu.magisk.dialog.LocalModuleInstallDialog
|
||||
import com.topjohnwu.magisk.dialog.OnlineModuleInstallDialog
|
||||
import com.topjohnwu.magisk.events.GetContentEvent
|
||||
import com.topjohnwu.magisk.events.SnackbarEvent
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.asStateFlow
|
||||
import kotlinx.coroutines.flow.update
|
||||
import kotlinx.coroutines.withContext
|
||||
import kotlinx.parcelize.Parcelize
|
||||
import com.topjohnwu.magisk.core.R as CoreR
|
||||
|
||||
class ModuleItem(val module: LocalModule) {
|
||||
val showNotice: Boolean
|
||||
val showAction: Boolean
|
||||
val noticeText: String
|
||||
|
||||
init {
|
||||
val isZygisk = module.isZygisk
|
||||
val isRiru = module.isRiru
|
||||
val zygiskUnloaded = isZygisk && module.zygiskUnloaded
|
||||
|
||||
showNotice = zygiskUnloaded ||
|
||||
(Info.isZygiskEnabled && isRiru) ||
|
||||
(!Info.isZygiskEnabled && isZygisk)
|
||||
showAction = module.hasAction && !showNotice
|
||||
noticeText = when {
|
||||
zygiskUnloaded -> "Zygisk module not loaded due to incompatibility"
|
||||
isRiru -> "Module suspended because Zygisk is enabled"
|
||||
else -> "Module suspended because Zygisk isn't enabled"
|
||||
}
|
||||
}
|
||||
|
||||
var isEnabled by mutableStateOf(module.enable)
|
||||
var isRemoved by mutableStateOf(module.remove)
|
||||
var showUpdate by mutableStateOf(module.updateInfo != null)
|
||||
val isUpdated = module.updated
|
||||
val updateReady get() = module.outdated && !isRemoved && isEnabled
|
||||
}
|
||||
|
||||
class ModuleViewModel : AsyncLoadViewModel() {
|
||||
|
||||
val bottomBarBarrierIds = intArrayOf(R.id.module_update, R.id.module_remove)
|
||||
data class UiState(
|
||||
val loading: Boolean = true,
|
||||
val modules: List<ModuleItem> = emptyList(),
|
||||
)
|
||||
|
||||
private val itemsInstalled = diffList<LocalModuleRvItem>()
|
||||
|
||||
val items = MergeObservableList<RvItem>()
|
||||
val extraBindings = bindExtra {
|
||||
it.put(BR.viewModel, this)
|
||||
}
|
||||
private val _uiState = MutableStateFlow(UiState())
|
||||
val uiState: StateFlow<UiState> = _uiState.asStateFlow()
|
||||
|
||||
val data get() = uri
|
||||
|
||||
@get:Bindable
|
||||
var loading = true
|
||||
private set(value) = set(value, field, { field = it }, BR.loading)
|
||||
|
||||
override suspend fun doLoadWork() {
|
||||
loading = true
|
||||
_uiState.update { it.copy(loading = true) }
|
||||
val moduleLoaded = Info.env.isActive &&
|
||||
withContext(Dispatchers.IO) { LocalModule.loaded() }
|
||||
withContext(Dispatchers.IO) { LocalModule.loaded() }
|
||||
if (moduleLoaded) {
|
||||
loadInstalled()
|
||||
if (items.isEmpty()) {
|
||||
items.insertItem(InstallModule)
|
||||
.insertList(itemsInstalled)
|
||||
val modules = withContext(Dispatchers.Default) {
|
||||
LocalModule.installed().map { ModuleItem(it) }
|
||||
}
|
||||
_uiState.update { it.copy(loading = false, modules = modules) }
|
||||
loadUpdateInfo()
|
||||
} else {
|
||||
_uiState.update { it.copy(loading = false) }
|
||||
}
|
||||
loading = false
|
||||
loadUpdateInfo()
|
||||
}
|
||||
|
||||
override fun onNetworkChanged(network: Boolean) = startLoading()
|
||||
|
||||
private suspend fun loadInstalled() {
|
||||
withContext(Dispatchers.Default) {
|
||||
val installed = LocalModule.installed().map { LocalModuleRvItem(it) }
|
||||
itemsInstalled.update(installed)
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun loadUpdateInfo() {
|
||||
withContext(Dispatchers.IO) {
|
||||
itemsInstalled.forEach {
|
||||
if (it.item.fetch())
|
||||
it.fetchedUpdateInfo()
|
||||
_uiState.value.modules.forEach { item ->
|
||||
if (item.module.fetch()) {
|
||||
item.showUpdate = item.module.updateInfo != null
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -102,6 +118,16 @@ class ModuleViewModel : AsyncLoadViewModel() {
|
||||
MainDirections.actionActionFragment(id, name).navigate()
|
||||
}
|
||||
|
||||
fun toggleEnabled(item: ModuleItem) {
|
||||
item.isEnabled = !item.isEnabled
|
||||
item.module.enable = item.isEnabled
|
||||
}
|
||||
|
||||
fun toggleRemove(item: ModuleItem) {
|
||||
item.isRemoved = !item.isRemoved
|
||||
item.module.remove = item.isRemoved
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val uri = MutableLiveData<Uri?>()
|
||||
}
|
||||
|
||||
@@ -1,65 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<layout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools">
|
||||
|
||||
<data>
|
||||
|
||||
<variable
|
||||
name="viewModel"
|
||||
type="com.topjohnwu.magisk.ui.module.ModuleViewModel" />
|
||||
|
||||
</data>
|
||||
|
||||
<FrameLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/module_list"
|
||||
gone="@{viewModel.loading}"
|
||||
app:items="@{viewModel.items}"
|
||||
app:extraBindings="@{viewModel.extraBindings}"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:clipToPadding="false"
|
||||
android:orientation="vertical"
|
||||
android:paddingTop="@dimen/internal_action_bar_size"
|
||||
android:paddingBottom="@dimen/internal_action_bar_size"
|
||||
app:fitsSystemWindowsInsets="top|bottom"
|
||||
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
|
||||
tools:listitem="@layout/item_module_md2" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:gravity="center"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
goneUnless="@{viewModel.loading}"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/loading"
|
||||
android:textAppearance="@style/AppearanceFoundation.Title"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<ProgressBar
|
||||
style="@style/WidgetFoundation.ProgressBar.Indeterminate"
|
||||
goneUnless="@{viewModel.loading}"
|
||||
android:layout_marginTop="@dimen/l1" />
|
||||
|
||||
<TextView
|
||||
gone="@{viewModel.loading || viewModel.items.size() != 1 }"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/module_empty"
|
||||
android:textAppearance="@style/AppearanceFoundation.Title"
|
||||
android:textStyle="bold" />
|
||||
</LinearLayout>
|
||||
|
||||
</FrameLayout>
|
||||
|
||||
|
||||
</layout>
|
||||
@@ -1,29 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<layout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
|
||||
<data>
|
||||
|
||||
<variable
|
||||
name="item"
|
||||
type="com.topjohnwu.magisk.ui.module.InstallModule" />
|
||||
|
||||
<variable
|
||||
name="viewModel"
|
||||
type="com.topjohnwu.magisk.ui.module.ModuleViewModel" />
|
||||
|
||||
</data>
|
||||
|
||||
<Button
|
||||
style="@style/WidgetFoundation.Button.Outlined"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="@dimen/l_50"
|
||||
android:onClick="@{() -> viewModel.installPressed()}"
|
||||
android:text="@string/module_action_install_external"
|
||||
android:textAllCaps="false"
|
||||
android:textSize="12sp"
|
||||
app:cornerRadius="@dimen/r1"
|
||||
app:icon="@drawable/ic_module_storage_md2" />
|
||||
|
||||
</layout>
|
||||
@@ -1,222 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<layout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools">
|
||||
|
||||
<data>
|
||||
|
||||
<import type="com.topjohnwu.magisk.R" />
|
||||
|
||||
<variable
|
||||
name="item"
|
||||
type="com.topjohnwu.magisk.ui.module.LocalModuleRvItem" />
|
||||
|
||||
<variable
|
||||
name="viewModel"
|
||||
type="com.topjohnwu.magisk.ui.module.ModuleViewModel" />
|
||||
|
||||
</data>
|
||||
|
||||
<FrameLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<com.google.android.material.card.MaterialCardView
|
||||
android:id="@+id/module"
|
||||
style="@style/WidgetFoundation.Card"
|
||||
isEnabled="@{!item.removed && item.enabled && !item.showNotice}"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:focusable="@{!item.removed && item.enabled && !item.showNotice}"
|
||||
android:nextFocusRight="@id/module_indicator"
|
||||
app:cardBackgroundColor="@color/color_card_background_color_selector"
|
||||
tools:isEnabled="false"
|
||||
tools:layout_gravity="center"
|
||||
tools:layout_margin="@dimen/l1">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/module_state_icon"
|
||||
gone="@{!item.removed && !item.updated}"
|
||||
srcCompat="@{item.removed ? R.drawable.ic_delete_md2 : (item.updated ? R.drawable.ic_update_md2 : 0)}"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_gravity="center"
|
||||
android:adjustViewBounds="true"
|
||||
android:alpha=".05"
|
||||
android:background="@null"
|
||||
android:duplicateParentState="true"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintLeft_toLeftOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:tint="?colorOnSurface"
|
||||
tools:srcCompat="@drawable/ic_update_md2" />
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:animateLayoutChanges="true"
|
||||
android:duplicateParentState="true">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/module_title"
|
||||
strikeThrough="@{item.removed}"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="@dimen/l1"
|
||||
android:layout_marginTop="@dimen/l1"
|
||||
android:layout_marginEnd="@dimen/l_50"
|
||||
android:duplicateParentState="true"
|
||||
android:text="@{item.item.name}"
|
||||
android:textAppearance="@style/AppearanceFoundation.Body"
|
||||
android:textColor="?android:textColorPrimary"
|
||||
android:textStyle="bold"
|
||||
app:layout_constraintEnd_toStartOf="@+id/module_indicator"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
tools:text="@tools:sample/lorem" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/module_version_author"
|
||||
strikeThrough="@{item.removed}"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:duplicateParentState="true"
|
||||
android:text="@{@string/module_version_author(item.item.version, item.item.author)}"
|
||||
android:textAppearance="@style/AppearanceFoundation.Caption.Variant"
|
||||
android:textColor="?android:textColorSecondary"
|
||||
app:layout_constraintEnd_toEndOf="@+id/module_title"
|
||||
app:layout_constraintStart_toStartOf="@+id/module_title"
|
||||
app:layout_constraintTop_toBottomOf="@+id/module_title"
|
||||
tools:text="@tools:sample/lorem" />
|
||||
|
||||
<com.google.android.material.switchmaterial.SwitchMaterial
|
||||
android:id="@+id/module_indicator"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="@dimen/l_50"
|
||||
android:checked="@={item.enabled}"
|
||||
android:nextFocusLeft="@id/module"
|
||||
app:layout_constraintBottom_toBottomOf="@+id/module_version_author"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintHorizontal_bias="1"
|
||||
app:layout_constraintStart_toEndOf="@+id/module_update"
|
||||
app:layout_constraintTop_toTopOf="@+id/module_title" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/module_description"
|
||||
gone="@{item.item.description.empty}"
|
||||
strikeThrough="@{item.removed}"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="@dimen/l1"
|
||||
android:layout_marginTop="@dimen/l1"
|
||||
android:layout_marginEnd="@dimen/l1"
|
||||
android:duplicateParentState="true"
|
||||
android:maxLines="5"
|
||||
android:text="@{item.item.description}"
|
||||
android:textAppearance="@style/AppearanceFoundation.Caption.Variant"
|
||||
android:textColor="?android:textColorSecondary"
|
||||
app:layout_constraintTop_toBottomOf="@+id/module_version_author"
|
||||
tools:lines="4"
|
||||
tools:text="@tools:sample/lorem/random" />
|
||||
|
||||
<View
|
||||
android:id="@+id/module_divider"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"
|
||||
android:layout_marginTop="@dimen/l1"
|
||||
android:background="?colorSurfaceSurfaceVariant"
|
||||
app:layout_constraintTop_toBottomOf="@+id/module_description" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/module_update"
|
||||
style="@style/WidgetFoundation.Button.Text"
|
||||
goneUnless="@{item.showUpdate}"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:clickable="true"
|
||||
android:enabled="@{item.updateReady}"
|
||||
android:focusable="true"
|
||||
android:onClick="@{() -> viewModel.downloadPressed(item.item.updateInfo)}"
|
||||
android:text="@string/update"
|
||||
android:textAllCaps="false"
|
||||
app:icon="@drawable/ic_update_md2"
|
||||
app:iconGravity="textEnd"
|
||||
app:layout_constraintBottom_toBottomOf="@+id/module_remove"
|
||||
app:layout_constraintEnd_toStartOf="@+id/module_remove"
|
||||
app:layout_constraintTop_toTopOf="@+id/module_remove"
|
||||
app:srcCompat="@drawable/ic_download_md2" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/module_remove"
|
||||
style="@style/WidgetFoundation.Button.Text"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:clickable="true"
|
||||
android:enabled="@{!item.updated}"
|
||||
android:focusable="true"
|
||||
android:onClick="@{() -> item.delete()}"
|
||||
android:text="@{item.removed ? @string/module_state_restore : @string/module_state_remove}"
|
||||
android:textAllCaps="false"
|
||||
android:theme="@style/ThemeOverlay.Button.Text.Secondary"
|
||||
app:icon="@{item.removed ? @drawable/ic_restart : @drawable/ic_delete_md2}"
|
||||
app:iconGravity="textEnd"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/module_divider"
|
||||
tools:icon="@drawable/ic_delete_md2"
|
||||
tools:text="Remove" />
|
||||
|
||||
<androidx.constraintlayout.widget.Barrier
|
||||
android:id="@+id/bottom_bar_barrier"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
app:barrierDirection="start"
|
||||
app:referencedIds="@{viewModel.bottomBarBarrierIds}"
|
||||
tools:constraint_referenced_ids="module_update,module_remove" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/module_notice_text"
|
||||
goneUnless="@{item.showNotice}"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="@dimen/l1"
|
||||
android:layout_marginEnd="@dimen/l_50"
|
||||
android:fontFamily="sans-serif-medium"
|
||||
android:text="@{item.noticeText}"
|
||||
android:textAppearance="@style/AppearanceFoundation.Caption.Primary"
|
||||
android:textColor="?colorError"
|
||||
app:layout_constraintBottom_toBottomOf="@+id/module_remove"
|
||||
app:layout_constraintEnd_toStartOf="@+id/bottom_bar_barrier"
|
||||
app:layout_constraintStart_toEndOf="@id/module_config"
|
||||
app:layout_constraintTop_toTopOf="@+id/module_remove"
|
||||
tools:lines="2"
|
||||
tools:text="@tools:sample/lorem/random"
|
||||
tools:visibility="visible" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/module_config"
|
||||
style="@style/WidgetFoundation.Button.Text"
|
||||
goneUnless="@{item.showAction}"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:clickable="true"
|
||||
android:enabled="@{item.enabled}"
|
||||
android:focusable="true"
|
||||
android:onClick="@{() -> viewModel.runAction(item.item.id, item.item.name)}"
|
||||
android:text="@string/module_action"
|
||||
android:textAllCaps="false"
|
||||
android:visibility="gone"
|
||||
app:icon="@drawable/ic_action_md2"
|
||||
app:iconGravity="textStart"
|
||||
app:layout_constraintBottom_toBottomOf="@+id/module_remove"
|
||||
app:layout_constraintTop_toTopOf="@+id/module_remove"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:srcCompat="@drawable/ic_download_md2" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
</com.google.android.material.card.MaterialCardView>
|
||||
|
||||
</FrameLayout>
|
||||
|
||||
</layout>
|
||||
@@ -72,8 +72,7 @@
|
||||
<fragment
|
||||
android:id="@+id/modulesFragment"
|
||||
android:name="com.topjohnwu.magisk.ui.module.ModuleFragment"
|
||||
android:label="ModuleFragment"
|
||||
tools:layout="@layout/fragment_module_md2" />
|
||||
android:label="ModuleFragment" />
|
||||
|
||||
<fragment
|
||||
android:id="@+id/settingsFragment"
|
||||
|
||||
Reference in New Issue
Block a user