diff --git a/app/src/main/java/com/topjohnwu/magisk/model/entity/recycler/ModuleRvItem.kt b/app/src/main/java/com/topjohnwu/magisk/model/entity/recycler/ModuleRvItem.kt index 87ee8eaf3..5e170bc8b 100644 --- a/app/src/main/java/com/topjohnwu/magisk/model/entity/recycler/ModuleRvItem.kt +++ b/app/src/main/java/com/topjohnwu/magisk/model/entity/recycler/ModuleRvItem.kt @@ -81,6 +81,19 @@ class RepoRvItem(val item: Repo) : ComparableRvItem() { override fun itemSameAs(other: RepoRvItem): Boolean = item.id == other.item.id } +object SafeModeNotice : ComparableRvItem() { + override val layoutRes = R.layout.item_safe_mode_notice + + override fun onBindingBound(binding: ViewDataBinding) { + super.onBindingBound(binding) + val params = binding.root.layoutParams as? StaggeredGridLayoutManager.LayoutParams + params?.isFullSpan = true + } + + override fun contentSameAs(other: SafeModeNotice) = this == other + override fun itemSameAs(other: SafeModeNotice) = this === other +} + object InstallModule : ComparableRvItem() { override val layoutRes = R.layout.item_module_download diff --git a/app/src/main/java/com/topjohnwu/magisk/redesign/module/ModuleViewModel.kt b/app/src/main/java/com/topjohnwu/magisk/redesign/module/ModuleViewModel.kt index d4c306604..6fdb66661 100644 --- a/app/src/main/java/com/topjohnwu/magisk/redesign/module/ModuleViewModel.kt +++ b/app/src/main/java/com/topjohnwu/magisk/redesign/module/ModuleViewModel.kt @@ -15,10 +15,7 @@ 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.entity.recycler.* import com.topjohnwu.magisk.model.events.InstallExternalModuleEvent import com.topjohnwu.magisk.model.events.OpenChangelogEvent import com.topjohnwu.magisk.model.events.dialog.ModuleInstallDialog @@ -284,12 +281,17 @@ class ModuleViewModel( active: List = itemsInstalled, updatable: List = itemsUpdatable, remote: List = itemsRemote - ) = (active + InstallModule).prependIfNotEmpty { sectionActive } + + ) = (active + InstallModule) + .prependIfNotEmpty { sectionActive } + .prependIf(Config.coreOnly) { SafeModeNotice } + updatable.prependIfNotEmpty { sectionUpdate } + remote.prependIfNotEmpty { sectionRemote } + private fun List.prependIf(condition: Boolean, item: () -> T) = + if (condition) listOf(item()) + this else this + private fun List.prependIfNotEmpty(item: () -> T) = - if (isNotEmpty()) listOf(item()) + this else this + prependIf(isNotEmpty(), item) } diff --git a/app/src/main/res/layout/item_safe_mode_notice.xml b/app/src/main/res/layout/item_safe_mode_notice.xml new file mode 100644 index 000000000..48d778eed --- /dev/null +++ b/app/src/main/res/layout/item_safe_mode_notice.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + \ No newline at end of file