-
Notifications
You must be signed in to change notification settings - Fork 286
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Settings] Replace “Remove all rules” with a button
Signed-off-by: Muntashir Al-Islam <[email protected]>
- Loading branch information
1 parent
5b167b2
commit a7fbcff
Showing
6 changed files
with
100 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
libcore/ui/src/main/java/io/github/muntashirakon/preference/PrimaryButtonPreference.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// SPDX-License-Identifier: GPL-3.0-or-later | ||
|
||
package io.github.muntashirakon.preference; | ||
|
||
import android.content.Context; | ||
import android.util.AttributeSet; | ||
import android.view.View; | ||
|
||
import androidx.annotation.NonNull; | ||
import androidx.annotation.Nullable; | ||
import androidx.preference.Preference; | ||
import androidx.preference.PreferenceViewHolder; | ||
|
||
import com.google.android.material.button.MaterialButton; | ||
|
||
import io.github.muntashirakon.ui.R; | ||
|
||
public class PrimaryButtonPreference extends Preference { | ||
public PrimaryButtonPreference(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) { | ||
super(context, attrs, defStyleAttr, defStyleRes); | ||
} | ||
|
||
public PrimaryButtonPreference(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) { | ||
this(context, attrs, defStyleAttr, R.style.Preference_M3_ButtonPreference_Primary); | ||
} | ||
|
||
public PrimaryButtonPreference(@NonNull Context context, @Nullable AttributeSet attrs) { | ||
this(context, attrs, R.attr.primaryButtonPreferenceStyle); | ||
} | ||
|
||
public PrimaryButtonPreference(@NonNull Context context) { | ||
this(context, null); | ||
} | ||
|
||
@Override | ||
public void onBindViewHolder(@NonNull PreferenceViewHolder holder) { | ||
super.onBindViewHolder(holder); | ||
View itemView = holder.itemView; | ||
MaterialButton button = (MaterialButton) holder.findViewById(android.R.id.button1); | ||
button.setText(getTitle()); | ||
button.setIcon(getIcon()); | ||
if (itemView.hasOnClickListeners()) { | ||
// Proxy listeners | ||
button.setOnClickListener(v -> itemView.callOnClick()); | ||
} | ||
// Selectable | ||
boolean isSelectable = isSelectable(); | ||
itemView.setClickable(false); | ||
itemView.setFocusable(false); | ||
button.setClickable(isSelectable); | ||
button.setFocusable(isSelectable); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<!-- SPDX-License-Identifier: Apache-2.0 AND GPL-3.0-or-later --> | ||
<androidx.appcompat.widget.LinearLayoutCompat xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
android:gravity="center_vertical" | ||
android:minHeight="?android:attr/listPreferredItemHeightSmall" | ||
android:paddingStart="?android:attr/listPreferredItemPaddingStart" | ||
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd" | ||
android:layout_marginHorizontal="?attr/listItemMarginHorizontal" | ||
android:paddingVertical="16dp" | ||
android:clipToPadding="false" | ||
android:baselineAligned="false" | ||
android:orientation="vertical"> | ||
|
||
<com.google.android.material.button.MaterialButton | ||
android:id="@android:id/button1" | ||
style="@style/Widget.AppTheme.Button.FilledButton.Dense" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_gravity="start|center_vertical" | ||
android:textAppearance="?attr/textAppearanceTitleMedium" | ||
app:iconSize="18dp" | ||
android:paddingHorizontal="16dp" | ||
tools:text="Button" /> | ||
|
||
</androidx.appcompat.widget.LinearLayoutCompat> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters