Added back safe mode notice

This commit is contained in:
Viktor De Pasquale 2019-11-19 16:07:19 +01:00
parent f72de687c5
commit f5342a09d3
3 changed files with 51 additions and 6 deletions

View File

@ -81,6 +81,19 @@ class RepoRvItem(val item: Repo) : ComparableRvItem<RepoRvItem>() {
override fun itemSameAs(other: RepoRvItem): Boolean = item.id == other.item.id
}
object SafeModeNotice : ComparableRvItem<SafeModeNotice>() {
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<InstallModule>() {
override val layoutRes = R.layout.item_module_download

View File

@ -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<ModuleItem> = itemsInstalled,
updatable: List<RepoItem.Update> = itemsUpdatable,
remote: List<RepoItem.Remote> = itemsRemote
) = (active + InstallModule).prependIfNotEmpty { sectionActive } +
) = (active + InstallModule)
.prependIfNotEmpty { sectionActive }
.prependIf(Config.coreOnly) { SafeModeNotice } +
updatable.prependIfNotEmpty { sectionUpdate } +
remote.prependIfNotEmpty { sectionRemote }
private fun <T> List<T>.prependIf(condition: Boolean, item: () -> T) =
if (condition) listOf(item()) + this else this
private fun <T> List<T>.prependIfNotEmpty(item: () -> T) =
if (isNotEmpty()) listOf(item()) + this else this
prependIf(isNotEmpty(), item)
}

View File

@ -0,0 +1,30 @@
<?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.model.entity.recycler.SafeModeNotice" />
</data>
<com.google.android.material.card.MaterialCardView
style="?styleCardNormal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardBackgroundColor="?colorError">
<androidx.appcompat.widget.AppCompatTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="@dimen/l1"
android:text="@string/module_safe_mode_message"
android:textAppearance="?appearanceTextCaptionOnPrimary"
android:textStyle="bold" />
</com.google.android.material.card.MaterialCardView>
</layout>