Added text switchers for descriptions

This commit is contained in:
Viktor De Pasquale 2019-10-04 17:56:30 +02:00
parent 1396faf433
commit cb2a1e57fe
6 changed files with 54 additions and 7 deletions

View File

@ -1,9 +1,13 @@
package com.topjohnwu.magisk.redesign.home
import com.skoumal.teanity.util.KObservableField
import com.topjohnwu.magisk.redesign.compat.CompatViewModel
class HomeViewModel : CompatViewModel() {
val stateTextMagisk = KObservableField("is up to date")
val stateTextManager = KObservableField("is up to date")
fun onDeletePressed() {}
}

View File

@ -1,7 +1,9 @@
package com.topjohnwu.magisk.utils
import android.view.View
import android.widget.TextSwitcher
import android.widget.TextView
import android.widget.ViewSwitcher
import androidx.annotation.ColorInt
import androidx.annotation.DrawableRes
import androidx.appcompat.widget.AppCompatImageView
@ -246,3 +248,21 @@ fun View.setOnSelectClickListener(listener: View.OnClickListener, resetTime: Lon
}
}
}
@BindingAdapter("textCaptionVariant")
fun TextSwitcher.setTextBinding(text: CharSequence) {
tag as? ViewSwitcher.ViewFactory ?: ViewSwitcher.ViewFactory {
View.inflate(context, R.layout.swicher_caption_variant, null)
}.also {
tag = it
setFactory(it)
setInAnimation(context, R.anim.switcher_bottom_up)
setOutAnimation(context, R.anim.switcher_center_up)
}
val currentText = (currentView as? TextView)?.text
if (currentText != text) {
setText(text)
}
}

View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="@android:integer/config_shortAnimTime">
<translate
android:fromYDelta="100%"
android:toYDelta="0%" />
<alpha
android:fromAlpha="0"
android:toAlpha="1" />
</set>

View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="@android:integer/config_shortAnimTime">
<translate
android:fromYDelta="0%"
android:toYDelta="-100%" />
<alpha
android:fromAlpha="1"
android:toAlpha="0" />
</set>

View File

@ -41,7 +41,7 @@
style="?styleIconPrimary"
onSelectClick="@{() -> viewModel.onDeletePressed()}"
onSelectReset="@{10000L}"
android:padding="@dimen/l_50"
android:padding="@dimen/l_25"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/ic_magisk_delete"
@ -60,12 +60,11 @@
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_chainStyle="packed" />
<androidx.appcompat.widget.AppCompatTextView
<TextSwitcher
android:id="@+id/status1"
textCaptionVariant="@{viewModel.stateTextMagisk}"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="is up to date"
android:textAppearance="?appearanceTextCaptionVariant"
app:layout_constraintBottom_toBottomOf="@+id/icon1"
app:layout_constraintEnd_toEndOf="@+id/title1"
app:layout_constraintStart_toStartOf="@+id/title1"
@ -135,12 +134,11 @@
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_chainStyle="packed" />
<androidx.appcompat.widget.AppCompatTextView
<TextSwitcher
android:id="@+id/status2"
textCaptionVariant="@{viewModel.stateTextManager}"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="has update available!"
android:textAppearance="?appearanceTextCaptionVariant"
app:layout_constraintBottom_toBottomOf="@+id/icon2"
app:layout_constraintEnd_toEndOf="@+id/title2"
app:layout_constraintStart_toStartOf="@+id/title2"

View File

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.appcompat.widget.AppCompatTextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textAppearance="?appearanceTextCaptionVariant" />