Use switches with 2 way binding instead of custom ImageView

This commit is contained in:
topjohnwu 2020-08-09 14:50:16 -07:00
parent 2e5402d741
commit c944277e78
4 changed files with 23 additions and 27 deletions

View File

@ -48,21 +48,18 @@ sealed class RepoItem(val item: Repo) : ObservableItem<RepoItem>() {
var progress = 0
set(value) = set(value, field, { field = it }, BR.progress)
@get:Bindable
var isUpdate = false
set(value) = set(value, field, { field = it }, BR.update)
abstract val isUpdate: Boolean
override fun contentSameAs(other: RepoItem): Boolean = item == other.item
override fun itemSameAs(other: RepoItem): Boolean = item.id == other.item.id
class Update(item: Repo) : RepoItem(item) {
init {
isUpdate = true
}
override val isUpdate get() = true
}
class Remote(item: Repo) : RepoItem(item)
class Remote(item: Repo) : RepoItem(item) {
override val isUpdate get() = false
}
}
class ModuleItem(val item: Module) : ObservableItem<ModuleItem>(), Observable {

View File

@ -30,7 +30,7 @@
tools:layout_marginBottom="@dimen/l1"
tools:layout_marginEnd="@dimen/l1">
<androidx.appcompat.widget.AppCompatImageView
<ImageView
android:id="@+id/module_state_icon"
gone="@{!item.removed &amp;&amp; !item.updated}"
srcCompat="@{item.removed ? R.drawable.ic_delete_md2 : (item.updated ? R.drawable.ic_update_md2 : 0)}"
@ -51,7 +51,7 @@
android:layout_height="wrap_content"
android:animateLayoutChanges="true">
<androidx.appcompat.widget.AppCompatTextView
<TextView
android:id="@+id/module_title"
strikeThrough="@{item.removed}"
android:layout_width="0dp"
@ -67,7 +67,7 @@
app:layout_constraintTop_toTopOf="parent"
tools:text="@tools:sample/lorem" />
<androidx.appcompat.widget.AppCompatTextView
<TextView
android:id="@+id/module_version_author"
strikeThrough="@{item.removed}"
android:layout_width="0dp"
@ -79,10 +79,11 @@
app:layout_constraintTop_toBottomOf="@+id/module_title"
tools:text="v1 by topjohnwu" />
<androidx.appcompat.widget.AppCompatImageView
<com.google.android.material.switchmaterial.SwitchMaterial
android:id="@+id/module_indicator"
style="@style/WidgetFoundation.Switch"
isSelected="@{item.enabled}"
android:checked="@={item.enabled}"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/l_50"
app:layout_constraintBottom_toBottomOf="@+id/module_version_author"
app:layout_constraintEnd_toEndOf="parent"
@ -90,7 +91,7 @@
app:layout_constraintStart_toEndOf="@+id/module_info"
app:layout_constraintTop_toTopOf="@+id/module_title" />
<androidx.appcompat.widget.AppCompatTextView
<TextView
android:id="@+id/module_description"
gone="@{item.item.description.empty}"
strikeThrough="@{item.removed}"
@ -110,11 +111,10 @@
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="@dimen/l1"
android:layout_marginRight="6dp"
android:background="?colorSurfaceVariant"
android:background="?colorSurfaceSurfaceVariant"
app:layout_constraintTop_toBottomOf="@+id/module_description" />
<androidx.appcompat.widget.AppCompatImageView
<ImageView
android:id="@+id/module_info"
style="@style/WidgetFoundation.Icon"
gone="@{item.repo == null}"

View File

@ -29,7 +29,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.appcompat.widget.AppCompatTextView
<TextView
android:id="@+id/module_title"
android:layout_width="0dp"
android:layout_height="wrap_content"
@ -44,7 +44,7 @@
app:layout_constraintTop_toTopOf="parent"
tools:text="@tools:sample/lorem" />
<androidx.appcompat.widget.AppCompatTextView
<TextView
android:id="@+id/module_version_author"
android:layout_width="0dp"
android:layout_height="wrap_content"
@ -55,7 +55,7 @@
app:layout_constraintTop_toBottomOf="@+id/module_title"
tools:text="v1 by topjohnwu" />
<androidx.appcompat.widget.AppCompatTextView
<TextView
android:id="@+id/module_description"
gone="@{item.item.description.empty}"
android:layout_width="match_parent"
@ -74,10 +74,10 @@
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="@dimen/l1"
android:background="?colorSurfaceVariant"
android:background="?colorSurfaceSurfaceVariant"
app:layout_constraintTop_toBottomOf="@+id/module_description" />
<androidx.appcompat.widget.AppCompatTextView
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/l1"
@ -91,7 +91,7 @@
tools:ignore="SmallSp"
tools:text="@tools:sample/date/ddmmyy" />
<androidx.appcompat.widget.AppCompatImageView
<ImageView
android:id="@+id/module_info"
style="@style/WidgetFoundation.Icon"
android:layout_width="wrap_content"
@ -103,7 +103,7 @@
app:layout_constraintTop_toTopOf="@+id/module_download"
app:srcCompat="@drawable/ic_info" />
<androidx.appcompat.widget.AppCompatImageView
<ImageView
android:id="@+id/module_download"
android:layout_width="wrap_content"
style="@style/WidgetFoundation.Icon.Primary"

View File

@ -33,8 +33,7 @@
</style>
<style name="WidgetFoundation.Card.Variant">
<item name="cardBackgroundColor">?colorSurface</item>
<item name="strokeColor">?colorSurfaceVariant</item>
<item name="strokeColor">?colorSurfaceSurfaceVariant</item>
<item name="strokeWidth">1.5dp</item>
</style>