Fix state save/restore and move colors to attrs
This commit is contained in:
@@ -14,6 +14,7 @@ import android.widget.TextView;
|
||||
import org.joinmastodon.android.R;
|
||||
import org.joinmastodon.android.model.Emoji;
|
||||
import org.joinmastodon.android.model.EmojiCategory;
|
||||
import org.joinmastodon.android.ui.utils.UiUtils;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
@@ -91,7 +92,7 @@ public class CustomEmojiPopupKeyboard extends PopupKeyboard{
|
||||
}
|
||||
}
|
||||
});
|
||||
list.setBackgroundResource(R.color.gray_100);
|
||||
list.setBackgroundColor(UiUtils.getThemeColor(activity, android.R.attr.colorBackground));
|
||||
list.setSelector(null);
|
||||
|
||||
return list;
|
||||
|
||||
@@ -50,9 +50,9 @@ public class FooterStatusDisplayItem extends StatusDisplayItem{
|
||||
favorite=findViewById(R.id.favorite);
|
||||
share=findViewById(R.id.share);
|
||||
if(Build.VERSION.SDK_INT<Build.VERSION_CODES.N){
|
||||
UiUtils.fixCompoundDrawableTintOnAndroid6(reply, R.color.text_secondary);
|
||||
UiUtils.fixCompoundDrawableTintOnAndroid6(boost, R.color.boost_icon);
|
||||
UiUtils.fixCompoundDrawableTintOnAndroid6(favorite, R.color.favorite_icon);
|
||||
UiUtils.fixCompoundDrawableTintOnAndroid6(reply);
|
||||
UiUtils.fixCompoundDrawableTintOnAndroid6(boost);
|
||||
UiUtils.fixCompoundDrawableTintOnAndroid6(favorite);
|
||||
}
|
||||
findViewById(R.id.reply_btn).setOnClickListener(this::onReplyClick);
|
||||
findViewById(R.id.boost_btn).setOnClickListener(this::onBoostClick);
|
||||
|
||||
@@ -54,14 +54,14 @@ public class ReblogOrReplyLineStatusDisplayItem extends StatusDisplayItem{
|
||||
public Holder(Activity activity, ViewGroup parent){
|
||||
super(activity, R.layout.display_item_reblog_or_reply_line, parent);
|
||||
text=findViewById(R.id.text);
|
||||
if(Build.VERSION.SDK_INT<Build.VERSION_CODES.N)
|
||||
UiUtils.fixCompoundDrawableTintOnAndroid6(text, R.color.text_secondary);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBind(ReblogOrReplyLineStatusDisplayItem item){
|
||||
text.setText(item.text);
|
||||
text.setCompoundDrawablesRelativeWithIntrinsicBounds(item.icon, 0, 0, 0);
|
||||
if(Build.VERSION.SDK_INT<Build.VERSION_CODES.N)
|
||||
UiUtils.fixCompoundDrawableTintOnAndroid6(text);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -2,6 +2,7 @@ package org.joinmastodon.android.ui.utils;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.content.res.TypedArray;
|
||||
import android.database.Cursor;
|
||||
import android.graphics.drawable.Animatable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
@@ -25,6 +26,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import androidx.annotation.AttrRes;
|
||||
import androidx.annotation.ColorRes;
|
||||
import androidx.browser.customtabs.CustomTabsIntent;
|
||||
import me.grishka.appkit.imageloader.ViewImageLoader;
|
||||
@@ -91,14 +93,13 @@ public class UiUtils{
|
||||
* Android 6.0 has a bug where start and end compound drawables don't get tinted.
|
||||
* This works around it by setting the tint colors directly to the drawables.
|
||||
* @param textView
|
||||
* @param color
|
||||
*/
|
||||
public static void fixCompoundDrawableTintOnAndroid6(TextView textView, @ColorRes int color){
|
||||
public static void fixCompoundDrawableTintOnAndroid6(TextView textView){
|
||||
Drawable[] drawables=textView.getCompoundDrawablesRelative();
|
||||
for(int i=0;i<drawables.length;i++){
|
||||
if(drawables[i]!=null){
|
||||
Drawable tinted=drawables[i].mutate();
|
||||
tinted.setTintList(textView.getContext().getColorStateList(color));
|
||||
tinted.setTintList(textView.getTextColors());
|
||||
drawables[i]=tinted;
|
||||
}
|
||||
}
|
||||
@@ -153,4 +154,11 @@ public class UiUtils{
|
||||
}, null, new UrlImageLoaderRequest(emoji.getKey().url, emojiSize, emojiSize), null, false, true);
|
||||
}
|
||||
}
|
||||
|
||||
public static int getThemeColor(Context context, @AttrRes int attr){
|
||||
TypedArray ta=context.obtainStyledAttributes(new int[]{attr});
|
||||
int color=ta.getColor(0, 0xff00ff00);
|
||||
ta.recycle();
|
||||
return color;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package org.joinmastodon.android.ui.views;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Parcelable;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
import android.widget.LinearLayout;
|
||||
@@ -10,6 +11,7 @@ import org.joinmastodon.android.R;
|
||||
import java.util.function.IntConsumer;
|
||||
|
||||
import androidx.annotation.IdRes;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
public class TabBar extends LinearLayout{
|
||||
@IdRes
|
||||
@@ -52,4 +54,10 @@ public class TabBar extends LinearLayout{
|
||||
public void setListener(IntConsumer listener){
|
||||
this.listener=listener;
|
||||
}
|
||||
|
||||
public void selectTab(int id){
|
||||
findViewById(selectedTabID).setSelected(false);
|
||||
selectedTabID=id;
|
||||
findViewById(selectedTabID).setSelected(true);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user