Fix MagiskDialog
This commit is contained in:
parent
6c8fe46590
commit
feb0f4b7b5
@ -6,10 +6,7 @@ import android.graphics.drawable.Drawable
|
|||||||
import android.view.ContextThemeWrapper
|
import android.view.ContextThemeWrapper
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.widget.ImageView
|
import android.widget.*
|
||||||
import android.widget.PopupMenu
|
|
||||||
import android.widget.ProgressBar
|
|
||||||
import android.widget.TextView
|
|
||||||
import androidx.annotation.DrawableRes
|
import androidx.annotation.DrawableRes
|
||||||
import androidx.appcompat.widget.Toolbar
|
import androidx.appcompat.widget.Toolbar
|
||||||
import androidx.core.view.updateLayoutParams
|
import androidx.core.view.updateLayoutParams
|
||||||
@ -166,8 +163,8 @@ fun RecyclerView.setDividers(dividerVertical: Drawable?, dividerHorizontal: Draw
|
|||||||
}
|
}
|
||||||
|
|
||||||
@BindingAdapter("app:icon")
|
@BindingAdapter("app:icon")
|
||||||
fun MaterialButton.setIconRes(res: Int) {
|
fun Button.setIconRes(res: Int) {
|
||||||
setIconResource(res)
|
(this as MaterialButton).setIconResource(res)
|
||||||
}
|
}
|
||||||
|
|
||||||
@BindingAdapter("strokeWidth")
|
@BindingAdapter("strokeWidth")
|
||||||
|
@ -13,6 +13,7 @@ import android.view.WindowManager
|
|||||||
import androidx.annotation.DrawableRes
|
import androidx.annotation.DrawableRes
|
||||||
import androidx.annotation.StringRes
|
import androidx.annotation.StringRes
|
||||||
import androidx.appcompat.app.AppCompatDialog
|
import androidx.appcompat.app.AppCompatDialog
|
||||||
|
import androidx.appcompat.content.res.AppCompatResources
|
||||||
import androidx.core.view.ViewCompat
|
import androidx.core.view.ViewCompat
|
||||||
import androidx.core.view.updatePadding
|
import androidx.core.view.updatePadding
|
||||||
import androidx.databinding.Bindable
|
import androidx.databinding.Bindable
|
||||||
@ -77,13 +78,9 @@ class MagiskDialog(
|
|||||||
override var callbacks: PropertyChangeRegistry? = null
|
override var callbacks: PropertyChangeRegistry? = null
|
||||||
|
|
||||||
@get:Bindable
|
@get:Bindable
|
||||||
var icon = 0
|
var icon: Drawable? = null
|
||||||
set(value) = set(value, field, { field = it }, BR.icon)
|
set(value) = set(value, field, { field = it }, BR.icon)
|
||||||
|
|
||||||
@get:Bindable
|
|
||||||
var iconRaw: Drawable? = null
|
|
||||||
set(value) = set(value, field, { field = it }, BR.iconRaw)
|
|
||||||
|
|
||||||
@get:Bindable
|
@get:Bindable
|
||||||
var title: CharSequence = ""
|
var title: CharSequence = ""
|
||||||
set(value) = set(value, field, { field = it }, BR.title)
|
set(value) = set(value, field, { field = it }, BR.title)
|
||||||
@ -185,10 +182,12 @@ class MagiskDialog(
|
|||||||
apply { data.message = message }
|
apply { data.message = message }
|
||||||
|
|
||||||
fun applyIcon(@DrawableRes drawableRes: Int) =
|
fun applyIcon(@DrawableRes drawableRes: Int) =
|
||||||
apply { data.icon = drawableRes }
|
apply {
|
||||||
|
data.icon = AppCompatResources.getDrawable(context, drawableRes)
|
||||||
|
}
|
||||||
|
|
||||||
fun applyIcon(drawable: Drawable) =
|
fun applyIcon(drawable: Drawable) =
|
||||||
apply { data.iconRaw = drawable }
|
apply { data.icon = drawable }
|
||||||
|
|
||||||
fun applyButton(buttonType: ButtonType, builder: ButtonBuilder.() -> Unit) = apply {
|
fun applyButton(buttonType: ButtonType, builder: ButtonBuilder.() -> Unit) = apply {
|
||||||
val button = when (buttonType) {
|
val button = when (buttonType) {
|
||||||
@ -269,7 +268,7 @@ class MagiskDialog(
|
|||||||
|
|
||||||
fun resetTitle() = applyTitle("")
|
fun resetTitle() = applyTitle("")
|
||||||
fun resetMessage() = applyMessage("")
|
fun resetMessage() = applyMessage("")
|
||||||
fun resetIcon() = applyIcon(0)
|
fun resetIcon() = apply { data.icon = null }
|
||||||
|
|
||||||
fun resetButtons() = apply {
|
fun resetButtons() = apply {
|
||||||
ButtonType.values().forEach {
|
ButtonType.values().forEach {
|
||||||
|
@ -52,35 +52,21 @@
|
|||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
app:layout_constraintGuide_end="16dp" />
|
app:layout_constraintGuide_end="16dp" />
|
||||||
|
|
||||||
<FrameLayout
|
<ImageView
|
||||||
|
style="@style/WidgetFoundation.Image.Big"
|
||||||
|
gone="@{data.icon == null}"
|
||||||
android:id="@+id/dialog_base_icon"
|
android:id="@+id/dialog_base_icon"
|
||||||
android:layout_width="wrap_content"
|
android:layout_gravity="center"
|
||||||
android:layout_height="wrap_content"
|
android:layout_marginTop="@dimen/l1"
|
||||||
|
android:src="@{data.icon}"
|
||||||
app:layout_constraintBottom_toTopOf="@+id/dialog_base_title"
|
app:layout_constraintBottom_toTopOf="@+id/dialog_base_title"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toTopOf="parent">
|
app:layout_constraintTop_toTopOf="parent"
|
||||||
|
|
||||||
<androidx.appcompat.widget.AppCompatImageView
|
|
||||||
style="@style/WidgetFoundation.Icon.Primary"
|
|
||||||
gone="@{data.icon == 0}"
|
|
||||||
srcCompat="@{data.icon}"
|
|
||||||
android:layout_gravity="center"
|
|
||||||
android:layout_marginTop="@dimen/l1"
|
|
||||||
android:padding="0dp"
|
|
||||||
tools:src="@drawable/ic_delete_md2" />
|
tools:src="@drawable/ic_delete_md2" />
|
||||||
|
|
||||||
<androidx.appcompat.widget.AppCompatImageView
|
<TextView
|
||||||
style="@style/WidgetFoundation.Image.Big"
|
gone="@{data.title.length == 0}"
|
||||||
gone="@{data.iconRaw == null}"
|
|
||||||
android:layout_gravity="center"
|
|
||||||
android:layout_marginTop="@dimen/l1"
|
|
||||||
android:src="@{data.iconRaw}"
|
|
||||||
tools:src="@drawable/ic_delete_md2" />
|
|
||||||
|
|
||||||
</FrameLayout>
|
|
||||||
|
|
||||||
<androidx.appcompat.widget.AppCompatTextView
|
|
||||||
android:id="@+id/dialog_base_title"
|
android:id="@+id/dialog_base_title"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
@ -94,34 +80,31 @@
|
|||||||
tools:lines="1"
|
tools:lines="1"
|
||||||
tools:text="@tools:sample/lorem/random" />
|
tools:text="@tools:sample/lorem/random" />
|
||||||
|
|
||||||
<FrameLayout
|
<androidx.core.widget.NestedScrollView
|
||||||
android:id="@+id/dialog_base_scroll"
|
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginTop="@dimen/l_50"
|
android:layout_marginTop="@dimen/l_50"
|
||||||
|
android:overScrollMode="ifContentScrolls"
|
||||||
app:layout_constrainedHeight="true"
|
app:layout_constrainedHeight="true"
|
||||||
app:layout_constraintBottom_toTopOf="@+id/dialog_base_space"
|
app:layout_constraintBottom_toTopOf="@+id/dialog_base_space"
|
||||||
app:layout_constraintEnd_toEndOf="@+id/dialog_base_end"
|
app:layout_constraintEnd_toEndOf="@+id/dialog_base_end"
|
||||||
app:layout_constraintStart_toStartOf="@+id/dialog_base_start"
|
app:layout_constraintStart_toStartOf="@+id/dialog_base_start"
|
||||||
app:layout_constraintTop_toBottomOf="@+id/dialog_base_title">
|
app:layout_constraintTop_toBottomOf="@+id/dialog_base_title">
|
||||||
|
|
||||||
<androidx.core.widget.NestedScrollView
|
<FrameLayout
|
||||||
gone="@{data.message.length == 0}"
|
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content">
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
<androidx.appcompat.widget.AppCompatTextView
|
<TextView
|
||||||
|
gone="@{data.message.length == 0}"
|
||||||
android:id="@+id/dialog_base_message"
|
android:id="@+id/dialog_base_message"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:gravity="center"
|
|
||||||
android:text="@{data.message}"
|
android:text="@{data.message}"
|
||||||
android:textAppearance="@style/AppearanceFoundation.Body"
|
android:textAppearance="@style/AppearanceFoundation.Body"
|
||||||
tools:lines="3"
|
tools:lines="3"
|
||||||
tools:text="@tools:sample/lorem/random" />
|
tools:text="@tools:sample/lorem/random" />
|
||||||
|
|
||||||
</androidx.core.widget.NestedScrollView>
|
|
||||||
|
|
||||||
<FrameLayout
|
<FrameLayout
|
||||||
android:id="@+id/dialog_base_container"
|
android:id="@+id/dialog_base_container"
|
||||||
gone="@{data.message.length != 0}"
|
gone="@{data.message.length != 0}"
|
||||||
@ -130,26 +113,23 @@
|
|||||||
|
|
||||||
</FrameLayout>
|
</FrameLayout>
|
||||||
|
|
||||||
|
</androidx.core.widget.NestedScrollView>
|
||||||
|
|
||||||
<Space
|
<Space
|
||||||
android:id="@+id/dialog_base_space"
|
android:id="@+id/dialog_base_space"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="@dimen/l1"
|
android:layout_height="@dimen/l_50"
|
||||||
app:layout_constraintBottom_toTopOf="@+id/dialog_base_buttons"
|
app:layout_constraintBottom_toTopOf="@+id/dialog_base_buttons"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
app:layout_constraintStart_toStartOf="parent" />
|
app:layout_constraintStart_toStartOf="parent" />
|
||||||
|
|
||||||
<FrameLayout
|
<androidx.appcompat.widget.ButtonBarLayout
|
||||||
android:id="@+id/dialog_base_buttons"
|
android:id="@+id/dialog_base_buttons"
|
||||||
style="?attr/buttonBarStyle"
|
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
app:layout_constraintStart_toStartOf="parent">
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
|
||||||
<androidx.appcompat.widget.ButtonBarLayout
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:gravity="bottom|center_horizontal"
|
android:gravity="bottom|center_horizontal"
|
||||||
android:layoutDirection="locale"
|
android:layoutDirection="locale"
|
||||||
android:orientation="horizontal"
|
android:orientation="horizontal"
|
||||||
@ -158,7 +138,7 @@
|
|||||||
android:paddingEnd="12dp"
|
android:paddingEnd="12dp"
|
||||||
android:paddingBottom="4dp">
|
android:paddingBottom="4dp">
|
||||||
|
|
||||||
<com.google.android.material.button.MaterialButton
|
<Button
|
||||||
android:id="@+id/dialog_base_button_4"
|
android:id="@+id/dialog_base_button_4"
|
||||||
style="@style/WidgetFoundation.Button.Text"
|
style="@style/WidgetFoundation.Button.Text"
|
||||||
gone="@{data.buttonIDGAF.icon == 0 && data.buttonIDGAF.title.length == 0}"
|
gone="@{data.buttonIDGAF.icon == 0 && data.buttonIDGAF.title.length == 0}"
|
||||||
@ -173,7 +153,7 @@
|
|||||||
tools:icon="@drawable/ic_bug_md2"
|
tools:icon="@drawable/ic_bug_md2"
|
||||||
tools:text="Button 1" />
|
tools:text="Button 1" />
|
||||||
|
|
||||||
<com.google.android.material.button.MaterialButton
|
<Button
|
||||||
android:id="@+id/dialog_base_button_2"
|
android:id="@+id/dialog_base_button_2"
|
||||||
style="@style/WidgetFoundation.Button.Text"
|
style="@style/WidgetFoundation.Button.Text"
|
||||||
gone="@{data.buttonNeutral.icon == 0 && data.buttonNeutral.title.length == 0}"
|
gone="@{data.buttonNeutral.icon == 0 && data.buttonNeutral.title.length == 0}"
|
||||||
@ -196,7 +176,7 @@
|
|||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
android:visibility="invisible" />
|
android:visibility="invisible" />
|
||||||
|
|
||||||
<com.google.android.material.button.MaterialButton
|
<Button
|
||||||
android:id="@+id/dialog_base_button_3"
|
android:id="@+id/dialog_base_button_3"
|
||||||
style="@style/WidgetFoundation.Button.Text"
|
style="@style/WidgetFoundation.Button.Text"
|
||||||
gone="@{data.buttonNegative.icon == 0 && data.buttonNegative.title.length == 0}"
|
gone="@{data.buttonNegative.icon == 0 && data.buttonNegative.title.length == 0}"
|
||||||
@ -211,7 +191,7 @@
|
|||||||
tools:icon="@drawable/ic_bug_md2"
|
tools:icon="@drawable/ic_bug_md2"
|
||||||
tools:text="Button 1" />
|
tools:text="Button 1" />
|
||||||
|
|
||||||
<com.google.android.material.button.MaterialButton
|
<Button
|
||||||
android:id="@+id/dialog_base_button_1"
|
android:id="@+id/dialog_base_button_1"
|
||||||
style="@style/WidgetFoundation.Button.Text"
|
style="@style/WidgetFoundation.Button.Text"
|
||||||
gone="@{data.buttonPositive.icon == 0 && data.buttonPositive.title.length == 0}"
|
gone="@{data.buttonPositive.icon == 0 && data.buttonPositive.title.length == 0}"
|
||||||
@ -229,8 +209,6 @@
|
|||||||
|
|
||||||
</androidx.appcompat.widget.ButtonBarLayout>
|
</androidx.appcompat.widget.ButtonBarLayout>
|
||||||
|
|
||||||
</FrameLayout>
|
|
||||||
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
|
|
||||||
</com.google.android.material.card.MaterialCardView>
|
</com.google.android.material.card.MaterialCardView>
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
|
|
||||||
</data>
|
</data>
|
||||||
|
|
||||||
<androidx.appcompat.widget.AppCompatTextView
|
<TextView
|
||||||
android:id="@android:id/text1"
|
android:id="@android:id/text1"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user