Do not hardcode appcompat widget classes

They should be handled by the theme
This commit is contained in:
topjohnwu 2020-08-19 02:45:14 -07:00
parent 6d749a58c6
commit 1fcf35ebeb
23 changed files with 55 additions and 49 deletions

View File

@ -11,8 +11,9 @@ import androidx.databinding.DataBindingUtil
import androidx.databinding.OnRebindCallback
import androidx.databinding.ViewDataBinding
import androidx.lifecycle.MutableLiveData
import androidx.navigation.NavController
import androidx.navigation.NavDirections
import androidx.navigation.findNavController
import androidx.navigation.fragment.NavHostFragment
import com.topjohnwu.magisk.BR
import com.topjohnwu.magisk.core.Config
import com.topjohnwu.magisk.core.base.BaseActivity
@ -26,14 +27,14 @@ abstract class BaseUIActivity<VM : BaseViewModel, Binding : ViewDataBinding> :
protected abstract val layoutRes: Int
protected open val themeRes: Int = Theme.selected.themeRes
private val navHostFragment get() = supportFragmentManager.findFragmentById(navHost)
private val navHostFragment by lazy {
supportFragmentManager.findFragmentById(navHost) as? NavHostFragment
}
private val topFragment get() = navHostFragment?.childFragmentManager?.fragments?.getOrNull(0)
protected val currentFragment get() = topFragment as? BaseUIFragment<*, *>
override val viewRoot: View get() = binding.root
open val navigation by lazy {
runCatching { findNavController(navHost) }.getOrNull()
}
open val navigation: NavController? get() = navHostFragment?.navController
open val navHost: Int = 0
open val snackbarView get() = binding.root

View File

@ -199,6 +199,11 @@ fun Button.setIconRes(res: Int) {
(this as MaterialButton).setIconResource(res)
}
@BindingAdapter("app:icon")
fun Button.setIcon(drawable: Drawable) {
(this as MaterialButton).icon = drawable
}
@BindingAdapter("strokeWidth")
fun MaterialCardView.setCardStrokeWidthBound(stroke: Float) {
strokeWidth = stroke.roundToInt()

View File

@ -19,7 +19,7 @@
android:paddingRight="@{viewModel.insets.right}"
tools:ignore="RtlHardcoded">
<fragment
<androidx.fragment.app.FragmentContainerView
android:id="@+id/main_nav_host"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
@ -89,7 +89,7 @@
app:labelVisibilityMode="unlabeled"
app:menu="@menu/menu_bottom_nav" />
<androidx.appcompat.widget.AppCompatTextView
<TextView
gone="@{viewModel.isConnected}"
android:layout_width="match_parent"
android:layout_height="wrap_content"

View File

@ -124,7 +124,7 @@
android:paddingStart="@dimen/l2"
android:paddingEnd="@dimen/l2">
<com.google.android.material.button.MaterialButton
<Button
android:id="@+id/deny_btn"
style="@style/WidgetFoundation.Button.Text"
android:layout_width="0dp"
@ -135,7 +135,7 @@
android:textColor="?colorOnSurfaceVariant"
tools:text="@string/deny" />
<com.google.android.material.button.MaterialButton
<Button
android:id="@+id/grant_btn"
style="@style/WidgetFoundation.Button.Text"
android:layout_width="0dp"

View File

@ -64,7 +64,7 @@
android:layout_gravity="center"
app:contentPadding="@dimen/l1">
<androidx.appcompat.widget.AppCompatTextView
<TextView
movieBehavior="@{viewModel.loading}"
movieBehaviorText="@{viewModel.behaviorText}"
android:layout_width="wrap_content"

View File

@ -33,7 +33,7 @@
android:orientation="vertical"
android:paddingTop="@dimen/l1">
<com.google.android.material.button.MaterialButton
<Button
android:layout_gravity="center"
style="@style/WidgetFoundation.Button"
gone="@{!viewModel.showTest}"
@ -68,7 +68,7 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<com.google.android.material.button.MaterialButton
<Button
android:id="@+id/home_notice_hide"
style="@style/WidgetFoundation.Button.Text.OnPrimary"
android:layout_width="wrap_content"
@ -110,7 +110,7 @@
android:layout_height="@dimen/l1"
gone="@{!Info.hasGMS &amp;&amp; !viewModel.showUninstall}" />
<com.google.android.material.button.MaterialButton
<Button
style="@style/WidgetFoundation.Button.Outlined"
android:layout_marginStart="@dimen/l1"
android:layout_marginEnd="@dimen/l1"
@ -124,7 +124,7 @@
app:cornerRadius="@dimen/r1"
app:icon="@drawable/ic_safetynet_md2" />
<com.google.android.material.button.MaterialButton
<Button
style="@style/WidgetFoundation.Button.Outlined.Error"
android:layout_marginStart="@dimen/l1"
android:layout_marginEnd="@dimen/l1"

View File

@ -74,7 +74,7 @@
app:layout_constraintStart_toEndOf="@+id/install_step_options_icon"
app:layout_constraintTop_toTopOf="parent" />
<com.google.android.material.button.MaterialButton
<Button
android:id="@+id/install_step_options_button"
style="@style/WidgetFoundation.Button.Text"
gone="@{viewModel.step != 0}"
@ -153,7 +153,7 @@
app:layout_constraintStart_toEndOf="@+id/install_step_method_icon"
app:layout_constraintTop_toTopOf="parent" />
<com.google.android.material.button.MaterialButton
<Button
android:id="@+id/install_step_method_button"
style="@style/WidgetFoundation.Button.Text"
gone="@{viewModel.step != 1}"
@ -238,7 +238,7 @@
</com.google.android.material.card.MaterialCardView>
<com.google.android.material.button.MaterialButton
<Button
style="@style/WidgetFoundation.Button.Text"
gone="@{viewModel.step != 2}"
android:layout_width="wrap_content"

View File

@ -86,7 +86,7 @@
android:gravity="center"
android:orientation="vertical">
<androidx.appcompat.widget.AppCompatTextView
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/safetynet_attest_loading"

View File

@ -214,7 +214,7 @@
</com.google.android.material.card.MaterialCardView>
<com.google.android.material.button.MaterialButton
<Button
style="@style/WidgetFoundation.Button.Text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"

View File

@ -25,7 +25,7 @@
tools:layout_gravity="bottom"
tools:paddingBottom="64dp">
<androidx.appcompat.widget.AppCompatTextView
<TextView
android:id="@+id/hide_filter_title_filter"
android:layout_width="match_parent"
android:layout_height="wrap_content"
@ -70,7 +70,7 @@
</com.google.android.material.chip.ChipGroup>
<androidx.appcompat.widget.AppCompatTextView
<TextView
android:id="@+id/hide_filter_title_search"
android:layout_width="match_parent"
android:layout_height="wrap_content"
@ -96,7 +96,7 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/hide_filter_title_search">
<androidx.appcompat.widget.AppCompatImageView
<ImageView
style="@style/WidgetFoundation.Icon"
android:layout_width="48dp"
android:layout_height="36dp"
@ -105,7 +105,7 @@
app:srcCompat="@drawable/ic_search_md2"
app:tint="?colorDisabled" />
<androidx.appcompat.widget.AppCompatEditText
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="48dp"

View File

@ -59,7 +59,7 @@
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="@+id/home_magisk_title">
<com.google.android.material.button.MaterialButton
<Button
style="@style/WidgetFoundation.Button"
gone="@{viewModel.stateMagisk != MagiskState.OBSOLETE}"
android:layout_width="wrap_content"
@ -69,7 +69,7 @@
android:textAllCaps="false"
app:icon="@drawable/ic_update_md2" />
<com.google.android.material.button.MaterialButton
<Button
style="@style/WidgetFoundation.Button.Text"
gone="@{viewModel.stateMagisk == MagiskState.OBSOLETE}"
android:layout_width="wrap_content"

View File

@ -62,7 +62,7 @@
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="@+id/home_manager_title">
<com.google.android.material.button.MaterialButton
<Button
style="@style/WidgetFoundation.Button"
gone="@{viewModel.stateManager != MagiskState.OBSOLETE}"
android:layout_width="wrap_content"
@ -72,7 +72,7 @@
android:textAllCaps="false"
app:icon="@drawable/ic_update_md2" />
<com.google.android.material.button.MaterialButton
<Button
style="@style/WidgetFoundation.Button.Text"
gone="@{viewModel.stateManager == MagiskState.OBSOLETE}"
android:layout_width="wrap_content"

View File

@ -54,7 +54,7 @@
android:background="@drawable/bg_shadow"
app:layout_constraintBottom_toBottomOf="@+id/module_filter_list" />
<androidx.appcompat.widget.AppCompatTextView
<TextView
android:id="@+id/module_filter_title_search"
android:layout_width="match_parent"
android:layout_height="wrap_content"
@ -81,7 +81,7 @@
app:layout_constraintEnd_toStartOf="@+id/module_filter_done"
app:layout_constraintStart_toStartOf="parent">
<androidx.appcompat.widget.AppCompatImageView
<ImageView
style="@style/WidgetFoundation.Icon"
android:layout_width="48dp"
android:layout_height="36dp"
@ -90,7 +90,7 @@
app:srcCompat="@drawable/ic_search_md2"
app:tint="?colorDisabled" />
<androidx.appcompat.widget.AppCompatEditText
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="48dp"

View File

@ -47,7 +47,7 @@
app:layout_constraintStart_toEndOf="@+id/log_track_container"
app:layout_constraintTop_toTopOf="parent">
<androidx.appcompat.widget.AppCompatTextView
<TextView
android:id="@+id/log_app_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
@ -60,7 +60,7 @@
app:layout_constraintTop_toTopOf="parent"
tools:text="@string/app_name" />
<androidx.appcompat.widget.AppCompatTextView
<TextView
android:id="@+id/log_date"
android:layout_width="match_parent"
android:layout_height="wrap_content"
@ -71,7 +71,7 @@
app:layout_constraintTop_toBottomOf="@+id/log_app_name"
tools:text="06:00 PM, 10 Oct 2019" />
<androidx.appcompat.widget.AppCompatTextView
<TextView
android:id="@+id/log_app_details"
android:layout_width="0dp"
android:layout_height="wrap_content"
@ -84,7 +84,7 @@
app:layout_constraintTop_toBottomOf="@+id/log_date"
tools:text="PID: 7196 Target UID: 0" />
<androidx.appcompat.widget.AppCompatTextView
<TextView
android:id="@+id/log_command"
android:layout_width="0dp"
android:layout_height="wrap_content"

View File

@ -42,7 +42,7 @@
app:layout_constraintStart_toStartOf="@+id/track_bullet"
app:layout_constraintTop_toTopOf="parent" />
<androidx.appcompat.widget.AppCompatImageView
<ImageView
android:id="@+id/track_bullet"
style="@style/WidgetFoundation.Image.Small"
isSelected="@{isSelected}"
@ -69,4 +69,4 @@
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
</layout>

View File

@ -14,7 +14,7 @@
</data>
<com.google.android.material.button.MaterialButton
<Button
style="@style/WidgetFoundation.Button.Outlined"
android:layout_width="match_parent"
android:layout_height="wrap_content"

View File

@ -129,7 +129,7 @@
app:layout_constraintTop_toTopOf="@+id/module_remove"
app:srcCompat="@drawable/ic_info" />
<com.google.android.material.button.MaterialButton
<Button
android:id="@+id/module_remove"
style="@style/WidgetFoundation.Button.Text"
android:layout_width="wrap_content"

View File

@ -103,7 +103,7 @@
android:background="?colorSurfaceVariant"
tools:visibility="visible">
<com.google.android.material.button.MaterialButton
<Button
android:id="@+id/policy_notify"
style="@style/WidgetFoundation.Button.Text"
isSelected="@{item.shouldNotify}"
@ -127,7 +127,7 @@
android:layout_marginBottom="@dimen/l_50"
android:background="?colorSurfaceSurfaceVariant" />
<com.google.android.material.button.MaterialButton
<Button
android:id="@+id/policy_log"
style="@style/WidgetFoundation.Button.Text"
isSelected="@{item.shouldLog}"
@ -151,7 +151,7 @@
android:layout_marginBottom="@dimen/l_50"
android:background="?colorSurfaceSurfaceVariant" />
<com.google.android.material.button.MaterialButton
<Button
android:id="@+id/policy_delete"
style="@style/WidgetFoundation.Button.Text"
android:layout_weight="1"

View File

@ -32,7 +32,7 @@
android:textStyle="bold"
tools:text="Installed" />
<com.google.android.material.button.MaterialButton
<Button
android:id="@+id/module_button"
style="@style/WidgetFoundation.Button.Text.Secondary"
invisible="@{!item.hasButton}"

View File

@ -10,7 +10,7 @@
</data>
<androidx.appcompat.widget.AppCompatTextView
<TextView
android:id="@android:id/text1"
style="?android:attr/spinnerItemStyle"
android:layout_width="match_parent"

View File

@ -26,7 +26,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.appcompat.widget.AppCompatImageView
<ImageView
android:id="@+id/tappable_icon"
style="@style/WidgetFoundation.Icon"
android:background="@null"
@ -36,7 +36,7 @@
app:srcCompat="@{item.icon}"
tools:srcCompat="@drawable/ic_hide_md2" />
<androidx.appcompat.widget.AppCompatTextView
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:requiresFadingEdge="horizontal"
@ -50,7 +50,7 @@
app:layout_constraintTop_toTopOf="parent"
tools:text="@string/magiskhide" />
<androidx.appcompat.widget.AppCompatImageView
<ImageView
android:id="@+id/headline_icon_pointer"
style="@style/WidgetFoundation.Icon"
android:background="@null"

View File

@ -10,7 +10,7 @@
</data>
<androidx.appcompat.widget.AppCompatTextView
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"

View File

@ -114,7 +114,7 @@
android:padding="@dimen/l1"
app:layout_constraintTop_toBottomOf="@+id/theme_card_bottom">
<androidx.appcompat.widget.AppCompatTextView
<TextView
android:layout_width="125dp"
android:layout_height="wrap_content"
android:text="@{theme.themeName}"
@ -168,7 +168,7 @@
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.appcompat.widget.AppCompatImageView
<ImageView
style="@style/WidgetFoundation.Icon.OnPrimary"
gone="@{!theme.isSelected}"
android:layout_gravity="end|top"