Add "error" M3 button style

This commit is contained in:
Grishka 2023-03-23 01:09:03 +03:00
parent 6b5e5b0f25
commit 8afad21113
4 changed files with 36 additions and 8 deletions

View File

@ -448,26 +448,25 @@ public class UiUtils{
}
public static void setRelationshipToActionButtonM3(Relationship relationship, Button button){
boolean secondaryStyle;
int styleRes;
if(relationship.blocking){
button.setText(R.string.button_blocked);
secondaryStyle=true;
styleRes=R.style.Widget_Mastodon_M3_Button_Tonal_Error;
}else if(relationship.blockedBy){
button.setText(R.string.button_follow);
secondaryStyle=false;
styleRes=R.style.Widget_Mastodon_M3_Button_Filled;
}else if(relationship.requested){
button.setText(R.string.button_follow_pending);
secondaryStyle=true;
styleRes=R.style.Widget_Mastodon_M3_Button_Tonal;
}else if(!relationship.following){
button.setText(relationship.followedBy ? R.string.follow_back : R.string.button_follow);
secondaryStyle=false;
styleRes=R.style.Widget_Mastodon_M3_Button_Filled;
}else{
button.setText(R.string.button_following);
secondaryStyle=true;
styleRes=R.style.Widget_Mastodon_M3_Button_Tonal;
}
button.setEnabled(!relationship.blockedBy);
int styleRes=secondaryStyle ? R.style.Widget_Mastodon_M3_Button_Tonal : R.style.Widget_Mastodon_M3_Button_Filled;
TypedArray ta=button.getContext().obtainStyledAttributes(styleRes, new int[]{android.R.attr.background});
button.setBackground(ta.getDrawable(0));
ta.recycle();

View File

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="?colorM3OnErrorContainer" android:state_enabled="true"/>
<item android:color="?colorM3OnSurface" android:alpha="0.38"/>
</selector>

View File

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="true">
<ripple android:color="@color/m3_on_secondary_container_overlay">
<item>
<shape>
<solid android:color="?colorM3ErrorContainer"/>
<corners android:radius="20dp"/>
</shape>
</item>
</ripple>
</item>
<item>
<shape>
<solid android:color="?colorM3DisabledBackground"/>
<corners android:radius="20dp"/>
</shape>
</item>
</selector>

View File

@ -316,11 +316,16 @@
<style name="Widget.Mastodon.M3.Button.Tonal">
<item name="android:background">@drawable/bg_button_m3_tonal</item>
<item name="android:textColor">@color/button_text_m3_text</item>
<item name="android:textColor">@color/button_text_m3_tonal</item>
<item name="android:paddingLeft">24dp</item>
<item name="android:paddingRight">24dp</item>
</style>
<style name="Widget.Mastodon.M3.Button.Tonal.Error">
<item name="android:background">@drawable/bg_button_m3_tonal_error</item>
<item name="android:textColor">@color/button_text_m3_tonal_error</item>
</style>
<style name="Widget.Mastodon.M3.EditText" parent="android:Widget.Material.EditText">
<item name="android:background">@drawable/bg_m3_outlined_text_field_nopad</item>
<item name="android:textAppearance">@style/m3_body_large</item>