Featured tab in profiles

This commit is contained in:
Grishka
2023-03-22 02:30:42 +03:00
parent 09ffda2605
commit 955b9a4b2b
21 changed files with 498 additions and 80 deletions

View File

@@ -37,12 +37,15 @@ public class HashtagStatusDisplayItem extends StatusDisplayItem{
public void onBind(HashtagStatusDisplayItem _item){
Hashtag item=_item.tag;
title.setText('#'+item.name);
int numPeople=item.history.get(0).accounts;
if(item.history.size()>1)
numPeople+=item.history.get(1).accounts;
subtitle.setText(_item.parentFragment.getResources().getQuantityString(R.plurals.x_people_talking, numPeople, numPeople));
chart.setData(item.history);
if(item.history!=null && !item.history.isEmpty()){
int numPeople=item.history.get(0).accounts;
if(item.history.size()>1)
numPeople+=item.history.get(1).accounts;
subtitle.setText(itemView.getResources().getQuantityString(R.plurals.x_people_talking, numPeople, numPeople));
chart.setData(item.history);
}else{
subtitle.setText(itemView.getResources().getQuantityString(R.plurals.x_posts, item.statusesCount, item.statusesCount));
}
}
}
}

View File

@@ -0,0 +1,55 @@
package org.joinmastodon.android.ui.displayitems;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;
import org.joinmastodon.android.R;
import org.joinmastodon.android.fragments.BaseStatusListFragment;
public class SectionHeaderStatusDisplayItem extends StatusDisplayItem{
public final String title, buttonText;
public final Runnable onButtonClick;
public SectionHeaderStatusDisplayItem(BaseStatusListFragment parentFragment, String title, String buttonText, Runnable onButtonClick){
super("", parentFragment);
this.title=title;
this.buttonText=buttonText;
this.onButtonClick=onButtonClick;
}
@Override
public Type getType(){
return Type.SECTION_HEADER;
}
public static class Holder extends StatusDisplayItem.Holder<SectionHeaderStatusDisplayItem>{
private final TextView title;
private final Button actionBtn;
public Holder(Context context, ViewGroup parent){
super(context, R.layout.display_item_section_header, parent);
title=findViewById(R.id.title);
actionBtn=findViewById(R.id.action_btn);
actionBtn.setOnClickListener(v->item.onButtonClick.run());
}
@Override
public void onBind(SectionHeaderStatusDisplayItem item){
title.setText(item.title);
if(item.onButtonClick!=null){
actionBtn.setVisibility(View.VISIBLE);
actionBtn.setText(item.buttonText);
}else{
actionBtn.setVisibility(View.GONE);
}
}
@Override
public boolean isEnabled(){
return false;
}
}
}

View File

@@ -65,6 +65,7 @@ public abstract class StatusDisplayItem{
case EXTENDED_FOOTER -> new ExtendedFooterStatusDisplayItem.Holder(activity, parent);
case MEDIA_GRID -> new MediaGridStatusDisplayItem.Holder(activity, parent);
case SPOILER -> new SpoilerStatusDisplayItem.Holder(activity, parent);
case SECTION_HEADER -> new SectionHeaderStatusDisplayItem.Holder(activity, parent);
};
}
@@ -154,7 +155,8 @@ public abstract class StatusDisplayItem{
GAP,
EXTENDED_FOOTER,
MEDIA_GRID,
SPOILER
SPOILER,
SECTION_HEADER
}
public static abstract class Holder<T extends StatusDisplayItem> extends BindableViewHolder<T> implements UsableRecyclerView.DisableableClickable{

View File

@@ -14,12 +14,12 @@ import org.joinmastodon.android.ui.utils.UiUtils;
import java.util.List;
import me.grishka.appkit.utils.V;
import me.grishka.appkit.utils.CustomViewHelper;
public class HashtagChartView extends View{
public class HashtagChartView extends View implements CustomViewHelper{
private Paint paint=new Paint(Paint.ANTI_ALIAS_FLAG);
private Path strokePath=new Path(), fillPath=new Path();
private CornerPathEffect pathEffect=new CornerPathEffect(V.dp(3));
private final CornerPathEffect pathEffect=new CornerPathEffect(dp(3));
private float[] relativeOffsets=new float[7];
public HashtagChartView(Context context){
@@ -32,7 +32,7 @@ public class HashtagChartView extends View{
public HashtagChartView(Context context, AttributeSet attrs, int defStyle){
super(context, attrs, defStyle);
paint.setStrokeWidth(V.dp(1.71f));
paint.setStrokeWidth(dp(1.71f));
paint.setStrokeCap(Paint.Cap.ROUND);
paint.setStrokeJoin(Paint.Join.ROUND);
}
@@ -57,20 +57,20 @@ public class HashtagChartView extends View{
return;
strokePath.rewind();
fillPath.rewind();
float step=(getWidth()-V.dp(2))/(float)(relativeOffsets.length-1);
float maxH=getHeight()-V.dp(2);
float x=getWidth()-V.dp(1);
strokePath.moveTo(x, maxH-maxH*relativeOffsets[0]+V.dp(1));
fillPath.moveTo(getWidth(), getHeight()-V.dp(1));
fillPath.lineTo(x, maxH-maxH*relativeOffsets[0]+V.dp(1));
float step=(getWidth()-dp(2))/(float)(relativeOffsets.length-1);
float maxH=getHeight()-dp(2);
float x=getWidth()-dp(1);
strokePath.moveTo(x, maxH-maxH*relativeOffsets[0]+dp(1));
fillPath.moveTo(getWidth(), getHeight()-dp(1));
fillPath.lineTo(x, maxH-maxH*relativeOffsets[0]+dp(1));
for(int i=1;i<relativeOffsets.length;i++){
float offset=relativeOffsets[i];
x-=step;
float y=maxH-maxH*offset+V.dp(1);
float y=maxH-maxH*offset+dp(1);
strokePath.lineTo(x, y);
fillPath.lineTo(x, y);
}
fillPath.lineTo(V.dp(1), getHeight()-V.dp(1));
fillPath.lineTo(dp(1), getHeight()-dp(1));
fillPath.close();
}
@@ -83,11 +83,11 @@ public class HashtagChartView extends View{
@Override
protected void onDraw(Canvas canvas){
paint.setStyle(Paint.Style.FILL);
paint.setColor(UiUtils.getThemeColor(getContext(), R.attr.colorAccentLightest));
paint.setColor(UiUtils.getThemeColor(getContext(), R.attr.colorM3PrimaryInverse));
paint.setPathEffect(null);
canvas.drawPath(fillPath, paint);
paint.setStyle(Paint.Style.STROKE);
paint.setColor(UiUtils.getThemeColor(getContext(), android.R.attr.colorAccent));
paint.setColor(UiUtils.getThemeColor(getContext(), R.attr.colorM3Primary));
paint.setPathEffect(pathEffect);
canvas.drawPath(strokePath, paint);
}

View File

@@ -26,8 +26,7 @@ public class NestedRecyclerScrollView extends CustomScrollView{
@Override
public void onNestedPreScroll(View target, int dx, int dy, int[] consumed) {
final RecyclerView rv = (RecyclerView) target;
if ((dy < 0 && isScrolledToTop(rv)) || (dy > 0 && !isScrolledToBottom())) {
if(target instanceof RecyclerView rv && ((dy < 0 && isScrolledToTop(rv)) || (dy > 0 && !isScrolledToBottom()))){
scrollBy(0, dy);
consumed[1] = dy;
return;
@@ -37,8 +36,7 @@ public class NestedRecyclerScrollView extends CustomScrollView{
@Override
public boolean onNestedPreFling(View target, float velX, float velY) {
final RecyclerView rv = (RecyclerView) target;
if ((velY < 0 && isScrolledToTop(rv)) || (velY > 0 && !isScrolledToBottom())) {
if (target instanceof RecyclerView rv && ((velY < 0 && isScrolledToTop(rv)) || (velY > 0 && !isScrolledToBottom()))){
fling((int) velY);
return true;
}