mirror of
https://github.com/topjohnwu/Magisk.git
synced 2024-12-25 10:57:39 +00:00
Added support section content
This commit is contained in:
parent
149d35c687
commit
823b121cc7
@ -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<HomeItem>() {
|
||||
|
||||
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
|
||||
}
|
@ -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<HomeItem> {
|
||||
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) {}
|
||||
|
||||
}
|
||||
|
||||
@ -67,3 +83,10 @@ val ManagerJson.isUpdateChannelCorrect
|
||||
get() = versionCode > 0
|
||||
val ManagerJson.isObsolete
|
||||
get() = BuildConfig.VERSION_CODE < versionCode
|
||||
|
||||
inline fun <T : ComparableRvItem<T>> itemBindingOf(
|
||||
crossinline body: (ItemBinding<*>) -> Unit = {}
|
||||
) = OnItemBind<T> { itemBinding, _, item ->
|
||||
item.bind(itemBinding)
|
||||
body(itemBinding)
|
||||
}
|
10
app/src/main/res/drawable-v21/bg_selectable.xml
Normal file
10
app/src/main/res/drawable-v21/bg_selectable.xml
Normal file
@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:color="?colorPrimary">
|
||||
<item android:id="@android:id/mask">
|
||||
<shape android:shape="rectangle">
|
||||
<corners android:radius="@dimen/r1" />
|
||||
<solid android:color="?colorPrimary" />
|
||||
</shape>
|
||||
</item>
|
||||
</ripple>
|
14
app/src/main/res/drawable/bg_selectable.xml
Normal file
14
app/src/main/res/drawable/bg_selectable.xml
Normal file
@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:state_pressed="true">
|
||||
<shape android:shape="rectangle">
|
||||
<corners android:radius="@dimen/r1" />
|
||||
<solid android:color="?colorPrimaryVariant" />
|
||||
</shape>
|
||||
</item>
|
||||
<item>
|
||||
<shape android:shape="rectangle">
|
||||
<solid android:color="@android:color/transparent" />
|
||||
</shape>
|
||||
</item>
|
||||
</selector>
|
@ -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 @@
|
||||
|
||||
<com.google.android.material.card.MaterialCardView
|
||||
style="?styleCardNormal"
|
||||
android:layout_width="0dp"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="@dimen/l1"
|
||||
app:layout_constrainedWidth="true"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintHorizontal_bias="0"
|
||||
app:layout_constraintStart_toEndOf="@+id/support_icon_john"
|
||||
app:layout_constraintTop_toTopOf="parent">
|
||||
|
||||
@ -246,16 +248,18 @@
|
||||
<androidx.appcompat.widget.AppCompatTextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:fontFamily="sans-serif-black"
|
||||
android:text="\@topjohnwu"
|
||||
android:textAppearance="?appearanceTextCaptionNormal"
|
||||
android:textStyle="bold"
|
||||
tools:text="\@topjohnwu" />
|
||||
tools:ignore="HardcodedText" />
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:layout_width="match_parent"
|
||||
itemBinding="@{viewModel.itemBinding}"
|
||||
android:layout_height="wrap_content"
|
||||
android:clipToPadding="false"
|
||||
android:fadingEdgeLength="@dimen/l1"
|
||||
items="@{viewModel.itemsMainline}"
|
||||
android:layout_width="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:paddingTop="@dimen/l1"
|
||||
android:requiresFadingEdge="horizontal"
|
||||
@ -271,8 +275,7 @@
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/l1"
|
||||
tools:visibility="gone">
|
||||
android:layout_marginTop="@dimen/l1">
|
||||
|
||||
<androidx.appcompat.widget.AppCompatImageView
|
||||
android:id="@+id/support_icon_dia"
|
||||
@ -286,8 +289,10 @@
|
||||
|
||||
<com.google.android.material.card.MaterialCardView
|
||||
style="?styleCardNormal"
|
||||
android:layout_width="0dp"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
app:layout_constrainedWidth="true"
|
||||
app:layout_constraintHorizontal_bias="1"
|
||||
android:layout_marginEnd="@dimen/l1"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toStartOf="@+id/support_icon_dia"
|
||||
@ -304,15 +309,17 @@
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="end"
|
||||
android:fontFamily="sans-serif-black"
|
||||
android:textAppearance="?appearanceTextCaptionNormal"
|
||||
android:textStyle="bold"
|
||||
tools:text="\@diareuse" />
|
||||
android:text="\@diareuse"
|
||||
tools:ignore="HardcodedText" />
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:layout_width="match_parent"
|
||||
itemBinding="@{viewModel.itemBinding}"
|
||||
android:layout_height="wrap_content"
|
||||
android:clipToPadding="false"
|
||||
items="@{viewModel.itemsApp}"
|
||||
android:layout_width="wrap_content"
|
||||
android:fadingEdgeLength="@dimen/l1"
|
||||
android:orientation="horizontal"
|
||||
android:paddingTop="@dimen/l1"
|
||||
@ -350,9 +357,11 @@
|
||||
|
||||
<com.google.android.material.card.MaterialCardView
|
||||
style="?styleCardNormal"
|
||||
android:layout_width="0dp"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="@dimen/l1"
|
||||
app:layout_constrainedWidth="true"
|
||||
app:layout_constraintHorizontal_bias="0"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toEndOf="@+id/support_icon_common"
|
||||
@ -370,13 +379,15 @@
|
||||
android:fontFamily="sans-serif-black"
|
||||
android:textAppearance="?appearanceTextCaptionNormal"
|
||||
android:textStyle="bold"
|
||||
tools:text="Project links" />
|
||||
android:text="@string/home_links_project" />
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:layout_width="match_parent"
|
||||
itemBinding="@{viewModel.itemBinding}"
|
||||
android:layout_height="wrap_content"
|
||||
android:clipToPadding="false"
|
||||
android:fadingEdgeLength="@dimen/l1"
|
||||
items="@{viewModel.itemsProject}"
|
||||
android:layout_width="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:paddingTop="@dimen/l1"
|
||||
android:requiresFadingEdge="horizontal"
|
||||
|
@ -3,13 +3,25 @@
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools">
|
||||
|
||||
<data></data>
|
||||
<data>
|
||||
|
||||
<variable
|
||||
name="item"
|
||||
type="com.topjohnwu.magisk.model.entity.recycler.HomeItem" />
|
||||
|
||||
<variable
|
||||
name="viewModel"
|
||||
type="com.topjohnwu.magisk.redesign.home.HomeViewModel" />
|
||||
|
||||
</data>
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="?selectableItemBackground"
|
||||
android:onClick="@{() -> viewModel.onLinkPressed(item.link)}"
|
||||
tools:layout_gravity="center"
|
||||
tools:paddingEnd="@dimen/l1">
|
||||
android:padding="@dimen/l_50">
|
||||
|
||||
<androidx.appcompat.widget.AppCompatImageView
|
||||
android:id="@+id/developer_link"
|
||||
@ -17,13 +29,15 @@
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:srcCompat="@drawable/ic_paypal" />
|
||||
app:srcCompat="@{item.icon}"
|
||||
tools:srcCompat="@drawable/ic_paypal" />
|
||||
|
||||
<androidx.appcompat.widget.AppCompatTextView
|
||||
android:id="@+id/developer_link_name"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/l_50"
|
||||
android:text="@{item.title}"
|
||||
android:textAppearance="?appearanceTextCaptionNormal"
|
||||
android:textStyle="bold"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
@ -33,6 +47,7 @@
|
||||
<androidx.appcompat.widget.AppCompatImageView
|
||||
style="?styleImageSmall"
|
||||
android:layout_marginStart="@dimen/l_50"
|
||||
android:layout_height="14sp"
|
||||
app:layout_constraintBottom_toBottomOf="@+id/developer_link_name"
|
||||
app:layout_constraintStart_toEndOf="@+id/developer_link_name"
|
||||
app:layout_constraintTop_toTopOf="@+id/developer_link_name"
|
||||
|
@ -14,4 +14,6 @@
|
||||
<dimen name="l_75">12dp</dimen>
|
||||
<dimen name="l1">16dp</dimen>
|
||||
<dimen name="l2">32dp</dimen>
|
||||
|
||||
<dimen name="r1">8dp</dimen>
|
||||
</resources>
|
@ -16,4 +16,11 @@
|
||||
<string name="obsolete_md2">can be updated!</string>
|
||||
<string name="loading_md2">is loading…</string>
|
||||
|
||||
<string name="home_links_project">Project links</string>
|
||||
<string name="home_item_paypal">PayPal</string>
|
||||
<string name="home_item_patreon">Patreon</string>
|
||||
<string name="home_item_twitter">Twitter</string>
|
||||
<string name="home_item_source">Source</string>
|
||||
<string name="home_item_xda">XDA</string>
|
||||
|
||||
</resources>
|
@ -22,6 +22,7 @@
|
||||
|
||||
<!--///-->
|
||||
|
||||
<item name="selectableItemBackground">@drawable/bg_selectable</item>
|
||||
<item name="actionBarSize">60dp</item>
|
||||
|
||||
<item name="styleAppbar">@style/WidgetFoundation.Appbar</item>
|
||||
|
@ -23,17 +23,17 @@ variant. Make sure to use style referenced by attribute defined it attrs.xml.
|
||||
|
||||
|
||||
<style name="WidgetFoundation.Card" parent="Widget.MaterialComponents.CardView">
|
||||
<item name="cardBackgroundColor">?attr/colorSurface</item>
|
||||
<item name="cardBackgroundColor">?colorSurfaceVariant</item>
|
||||
<item name="cardCornerRadius">@dimen/l_50</item>
|
||||
<item name="cardElevation">4dp</item>
|
||||
<item name="cardElevation">0dp</item>
|
||||
</style>
|
||||
|
||||
<style name="WidgetFoundation.Card.OnPrimary" parent="Widget.MaterialComponents.CardView">
|
||||
<item name="cardCornerRadius">@dimen/l_50</item>
|
||||
<item name="cardElevation">0dp</item>
|
||||
<item name="strokeColor">?attr/colorOnPrimaryVariant</item>
|
||||
<item name="strokeColor">?colorOnPrimaryVariant</item>
|
||||
<item name="strokeWidth">1dp</item>
|
||||
<item name="cardBackgroundColor">?attr/colorPrimary</item>
|
||||
<item name="cardBackgroundColor">?colorPrimary</item>
|
||||
</style>
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user