From 823b121cc70714f75cf8b4abd62987788360b16a Mon Sep 17 00:00:00 2001 From: Viktor De Pasquale Date: Sat, 5 Oct 2019 12:42:27 +0200 Subject: [PATCH] Added support section content --- .../magisk/model/entity/recycler/HomeItems.kt | 74 +++++++++++++++++++ .../magisk/redesign/home/HomeViewModel.kt | 25 ++++++- .../main/res/drawable-v21/bg_selectable.xml | 10 +++ app/src/main/res/drawable/bg_selectable.xml | 14 ++++ app/src/main/res/layout/fragment_home_md2.xml | 39 ++++++---- app/src/main/res/layout/item_developer.xml | 21 +++++- app/src/main/res/values/dimens.xml | 2 + app/src/main/res/values/strings_md2.xml | 7 ++ app/src/main/res/values/styles_md2.xml | 1 + app/src/main/res/values/styles_md2_impl.xml | 8 +- 10 files changed, 179 insertions(+), 22 deletions(-) create mode 100644 app/src/main/java/com/topjohnwu/magisk/model/entity/recycler/HomeItems.kt create mode 100644 app/src/main/res/drawable-v21/bg_selectable.xml create mode 100644 app/src/main/res/drawable/bg_selectable.xml diff --git a/app/src/main/java/com/topjohnwu/magisk/model/entity/recycler/HomeItems.kt b/app/src/main/java/com/topjohnwu/magisk/model/entity/recycler/HomeItems.kt new file mode 100644 index 000000000..088e95cc8 --- /dev/null +++ b/app/src/main/java/com/topjohnwu/magisk/model/entity/recycler/HomeItems.kt @@ -0,0 +1,74 @@ +package com.topjohnwu.magisk.model.entity.recycler + +import com.skoumal.teanity.databinding.ComparableRvItem +import com.topjohnwu.magisk.Const +import com.topjohnwu.magisk.R + +sealed class HomeItem : ComparableRvItem() { + + abstract val icon: Int + abstract val title: Int + abstract val link: String + + override val layoutRes = R.layout.item_developer + + override fun contentSameAs(other: HomeItem) = itemSameAs(other) + override fun itemSameAs(other: HomeItem) = this == other + + override fun equals(other: Any?): Boolean { + if (other !is HomeItem) return false + return icon == other.icon && title == other.title && link == other.link + } + + // region Children + sealed class PayPal : HomeItem() { + override val icon = R.drawable.ic_paypal + override val title = R.string.home_item_paypal + override val link = "https://paypal.me/%s" + + // region Children + object App : PayPal() { + override val link = super.link.format("diareuse") + } + + object Mainline : PayPal() { + override val link = super.link.format("topjohnwu") + } + // endregion + } + + object Patreon : HomeItem() { + override val icon = R.drawable.ic_patreon + override val title = R.string.home_item_patreon + override val link = Const.Url.PATREON_URL + } + + sealed class Twitter : HomeItem() { + override val icon = R.drawable.ic_twitter + override val title = R.string.home_item_twitter + override val link = "https://twitter.com/%s" + + // region Children + object App : Twitter() { + override val link = super.link.format("diareuse") + } + + object Mainline : Twitter() { + override val link = super.link.format("topjohnwu") + } + // endregion + } + + object Github : HomeItem() { + override val icon = R.drawable.ic_github + override val title = R.string.home_item_source + override val link = Const.Url.SOURCE_CODE_URL + } + + object Xda : HomeItem() { + override val icon = R.drawable.ic_xda + override val title = R.string.home_item_xda + override val link = Const.Url.XDA_THREAD + } + // endregion +} diff --git a/app/src/main/java/com/topjohnwu/magisk/redesign/home/HomeViewModel.kt b/app/src/main/java/com/topjohnwu/magisk/redesign/home/HomeViewModel.kt index 7f6b0f9e0..6bd373ea9 100644 --- a/app/src/main/java/com/topjohnwu/magisk/redesign/home/HomeViewModel.kt +++ b/app/src/main/java/com/topjohnwu/magisk/redesign/home/HomeViewModel.kt @@ -1,5 +1,6 @@ package com.topjohnwu.magisk.redesign.home +import com.skoumal.teanity.databinding.ComparableRvItem import com.skoumal.teanity.extensions.subscribeK import com.skoumal.teanity.util.KObservableField import com.topjohnwu.magisk.BuildConfig @@ -10,9 +11,13 @@ import com.topjohnwu.magisk.extensions.res import com.topjohnwu.magisk.model.entity.MagiskJson import com.topjohnwu.magisk.model.entity.ManagerJson import com.topjohnwu.magisk.model.entity.UpdateInfo +import com.topjohnwu.magisk.model.entity.recycler.HomeItem import com.topjohnwu.magisk.model.observer.Observer import com.topjohnwu.magisk.redesign.compat.CompatViewModel import com.topjohnwu.magisk.ui.home.MagiskState +import me.tatarka.bindingcollectionadapter2.BR +import me.tatarka.bindingcollectionadapter2.ItemBinding +import me.tatarka.bindingcollectionadapter2.OnItemBind class HomeViewModel( private val repoMagisk: MagiskRepository @@ -37,6 +42,16 @@ class HomeViewModel( } } + val itemsMainline = + listOf(HomeItem.PayPal.Mainline, HomeItem.Patreon, HomeItem.Twitter.Mainline) + val itemsApp = + listOf(HomeItem.PayPal.App, HomeItem.Twitter.App) + val itemsProject = + listOf(HomeItem.Github, HomeItem.Xda) + val itemBinding = itemBindingOf { + it.bindExtra(BR.viewModel, this) + } + override fun refresh() = repoMagisk.fetchUpdate() .subscribeK { updateBy(it) } @@ -55,6 +70,7 @@ class HomeViewModel( } fun onDeletePressed() {} + fun onLinkPressed(link: String) {} } @@ -66,4 +82,11 @@ val MagiskJson.isObsolete val ManagerJson.isUpdateChannelCorrect get() = versionCode > 0 val ManagerJson.isObsolete - get() = BuildConfig.VERSION_CODE < versionCode \ No newline at end of file + get() = BuildConfig.VERSION_CODE < versionCode + +inline fun > itemBindingOf( + crossinline body: (ItemBinding<*>) -> Unit = {} +) = OnItemBind { itemBinding, _, item -> + item.bind(itemBinding) + body(itemBinding) +} \ No newline at end of file diff --git a/app/src/main/res/drawable-v21/bg_selectable.xml b/app/src/main/res/drawable-v21/bg_selectable.xml new file mode 100644 index 000000000..3fbf0d437 --- /dev/null +++ b/app/src/main/res/drawable-v21/bg_selectable.xml @@ -0,0 +1,10 @@ + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/bg_selectable.xml b/app/src/main/res/drawable/bg_selectable.xml new file mode 100644 index 000000000..c7bb35a7f --- /dev/null +++ b/app/src/main/res/drawable/bg_selectable.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_home_md2.xml b/app/src/main/res/layout/fragment_home_md2.xml index 7a1cc7cf4..141d18422 100644 --- a/app/src/main/res/layout/fragment_home_md2.xml +++ b/app/src/main/res/layout/fragment_home_md2.xml @@ -208,8 +208,8 @@ android:layout_width="match_parent" android:layout_height="1dp" android:layout_marginStart="@dimen/l1" - android:layout_marginEnd="@dimen/l1" android:layout_marginTop="@dimen/l2" + android:layout_marginEnd="@dimen/l1" android:layout_marginBottom="@dimen/l2" android:background="?colorSurfaceVariant" /> @@ -229,11 +229,13 @@ @@ -246,16 +248,18 @@ + tools:ignore="HardcodedText" /> + android:layout_marginTop="@dimen/l1"> + android:text="\@diareuse" + tools:ignore="HardcodedText" /> + android:text="@string/home_links_project" /> - + + + + + + + + android:padding="@dimen/l_50"> + app:srcCompat="@{item.icon}" + tools:srcCompat="@drawable/ic_paypal" /> 12dp 16dp 32dp + + 8dp \ No newline at end of file diff --git a/app/src/main/res/values/strings_md2.xml b/app/src/main/res/values/strings_md2.xml index 61f4a4cd8..49174d582 100644 --- a/app/src/main/res/values/strings_md2.xml +++ b/app/src/main/res/values/strings_md2.xml @@ -16,4 +16,11 @@ can be updated! is loading… + Project links + PayPal + Patreon + Twitter + Source + XDA + \ No newline at end of file diff --git a/app/src/main/res/values/styles_md2.xml b/app/src/main/res/values/styles_md2.xml index 570e9c0e8..8b68efc48 100644 --- a/app/src/main/res/values/styles_md2.xml +++ b/app/src/main/res/values/styles_md2.xml @@ -22,6 +22,7 @@ + @drawable/bg_selectable 60dp @style/WidgetFoundation.Appbar diff --git a/app/src/main/res/values/styles_md2_impl.xml b/app/src/main/res/values/styles_md2_impl.xml index 433aded1c..4439d6dbf 100644 --- a/app/src/main/res/values/styles_md2_impl.xml +++ b/app/src/main/res/values/styles_md2_impl.xml @@ -23,17 +23,17 @@ variant. Make sure to use style referenced by attribute defined it attrs.xml.