Unified account row

This commit is contained in:
Grishka 2023-06-25 01:18:38 +03:00
parent e1db5f15ca
commit 0952d97557
18 changed files with 275 additions and 565 deletions

View File

@ -24,8 +24,10 @@ import org.joinmastodon.android.model.Poll;
import org.joinmastodon.android.model.Relationship;
import org.joinmastodon.android.model.Status;
import org.joinmastodon.android.ui.BetterItemAnimator;
import org.joinmastodon.android.ui.displayitems.AccountStatusDisplayItem;
import org.joinmastodon.android.ui.displayitems.ExtendedFooterStatusDisplayItem;
import org.joinmastodon.android.ui.displayitems.GapStatusDisplayItem;
import org.joinmastodon.android.ui.displayitems.HashtagStatusDisplayItem;
import org.joinmastodon.android.ui.displayitems.MediaGridStatusDisplayItem;
import org.joinmastodon.android.ui.displayitems.PollFooterStatusDisplayItem;
import org.joinmastodon.android.ui.displayitems.PollOptionStatusDisplayItem;
@ -577,7 +579,7 @@ public abstract class BaseStatusListFragment<T extends DisplayItemsParent> exten
@NonNull
@Override
public BindableViewHolder<StatusDisplayItem> onCreateViewHolder(@NonNull ViewGroup parent, int viewType){
BindableViewHolder<StatusDisplayItem> holder=(BindableViewHolder<StatusDisplayItem>) StatusDisplayItem.createViewHolder(StatusDisplayItem.Type.values()[viewType & (~0x80000000)], getActivity(), parent);
BindableViewHolder<StatusDisplayItem> holder=(BindableViewHolder<StatusDisplayItem>) StatusDisplayItem.createViewHolder(StatusDisplayItem.Type.values()[viewType & (~0x80000000)], getActivity(), parent, BaseStatusListFragment.this);
onModifyItemViewHolder(holder);
return holder;
}
@ -625,12 +627,22 @@ public abstract class BaseStatusListFragment<T extends DisplayItemsParent> exten
View bottomSibling=parent.getChildAt(i+1);
RecyclerView.ViewHolder holder=parent.getChildViewHolder(child);
RecyclerView.ViewHolder siblingHolder=parent.getChildViewHolder(bottomSibling);
if((holder instanceof StatusDisplayItem.Holder<?> ih && siblingHolder instanceof StatusDisplayItem.Holder<?> sh
&& (!ih.getItemID().equals(sh.getItemID()) || sh instanceof ExtendedFooterStatusDisplayItem.Holder) && ih.getItem().getType()!=StatusDisplayItem.Type.GAP)
|| needDividerForExtraItem(child, bottomSibling, holder, siblingHolder)){
if(needDrawDivider(holder, siblingHolder)){
drawDivider(child, bottomSibling, holder, siblingHolder, parent, c, dividerPaint);
}
}
}
private boolean needDrawDivider(RecyclerView.ViewHolder holder, RecyclerView.ViewHolder siblingHolder){
if(needDividerForExtraItem(holder.itemView, siblingHolder.itemView, holder, siblingHolder))
return true;
if(holder instanceof StatusDisplayItem.Holder<?> ih && siblingHolder instanceof StatusDisplayItem.Holder<?> sh){
// Do not draw dividers between hashtag and/or account rows
if((ih instanceof HashtagStatusDisplayItem.Holder || ih instanceof AccountStatusDisplayItem.Holder) && (sh instanceof HashtagStatusDisplayItem.Holder || sh instanceof AccountStatusDisplayItem.Holder))
return false;
return (!ih.getItemID().equals(sh.getItemID()) || sh instanceof ExtendedFooterStatusDisplayItem.Holder) && ih.getItem().getType()!=StatusDisplayItem.Type.GAP;
}
return false;
}
}
}

View File

@ -43,6 +43,10 @@ public abstract class BaseAccountListFragment extends MastodonRecyclerFragment<A
super(40);
}
public BaseAccountListFragment(int layout, int perPage){
super(layout, perPage);
}
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);

View File

@ -73,6 +73,7 @@ public class ComposeAccountSearchFragment extends BaseAccountListFragment{
protected void onConfigureViewHolder(AccountViewHolder holder){
super.onConfigureViewHolder(holder);
holder.setOnClickListener(this::onItemClick);
holder.setStyle(AccountViewHolder.AccessoryType.NONE, false);
}
private void onItemClick(AccountViewHolder holder){

View File

@ -543,6 +543,7 @@ public class SearchQueryFragment extends MastodonRecyclerFragment<SearchResultVi
public CustomAccountViewHolder(Fragment fragment, ViewGroup list, HashMap<String, Relationship> relationships){
super(fragment, list, relationships);
setStyle(AccessoryType.NONE, false);
}
@Override

View File

@ -1,61 +1,33 @@
package org.joinmastodon.android.fragments.onboarding;
import android.app.ProgressDialog;
import android.graphics.drawable.Animatable;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowInsets;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;
import org.joinmastodon.android.R;
import org.joinmastodon.android.api.requests.accounts.GetAccountRelationships;
import org.joinmastodon.android.api.requests.accounts.GetFollowSuggestions;
import org.joinmastodon.android.api.requests.accounts.SetAccountFollowed;
import org.joinmastodon.android.fragments.HomeFragment;
import org.joinmastodon.android.fragments.ProfileFragment;
import org.joinmastodon.android.fragments.account_list.BaseAccountListFragment;
import org.joinmastodon.android.model.FollowSuggestion;
import org.joinmastodon.android.model.Relationship;
import org.joinmastodon.android.model.viewmodel.AccountViewModel;
import org.joinmastodon.android.ui.OutlineProviders;
import org.joinmastodon.android.ui.utils.UiUtils;
import org.joinmastodon.android.ui.views.ProgressBarButton;
import org.joinmastodon.android.ui.viewholders.AccountViewHolder;
import org.joinmastodon.android.utils.ElevationOnScrollListener;
import org.parceler.Parcels;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import me.grishka.appkit.Nav;
import me.grishka.appkit.api.Callback;
import me.grishka.appkit.api.ErrorResponse;
import me.grishka.appkit.api.SimpleCallback;
import me.grishka.appkit.fragments.BaseRecyclerFragment;
import me.grishka.appkit.imageloader.ImageLoaderRecyclerAdapter;
import me.grishka.appkit.imageloader.ImageLoaderViewHolder;
import me.grishka.appkit.imageloader.requests.ImageLoaderRequest;
import me.grishka.appkit.utils.BindableViewHolder;
import me.grishka.appkit.utils.V;
import me.grishka.appkit.views.FragmentRootLinearLayout;
import me.grishka.appkit.views.UsableRecyclerView;
public class OnboardingFollowSuggestionsFragment extends BaseRecyclerFragment<AccountViewModel>{
public class OnboardingFollowSuggestionsFragment extends BaseAccountListFragment{
private String accountID;
private Map<String, Relationship> relationships=Collections.emptyMap();
private GetAccountRelationships relationshipsRequest;
private View buttonBar;
private ElevationOnScrollListener onScrollListener;
private int numRunningFollowRequests=0;
@ -98,46 +70,16 @@ public class OnboardingFollowSuggestionsFragment extends BaseRecyclerFragment<Ac
@Override
public void onSuccess(List<FollowSuggestion> result){
onDataLoaded(result.stream().map(fs->new AccountViewModel(fs.account, accountID)).collect(Collectors.toList()), false);
loadRelationships();
}
})
.exec(accountID);
}
private void loadRelationships(){
relationships=Collections.emptyMap();
relationshipsRequest=new GetAccountRelationships(data.stream().map(fs->fs.account.id).collect(Collectors.toList()));
relationshipsRequest.setCallback(new Callback<>(){
@Override
public void onSuccess(List<Relationship> result){
relationshipsRequest=null;
relationships=result.stream().collect(Collectors.toMap(rel->rel.id, Function.identity()));
if(list==null)
return;
for(int i=0;i<list.getChildCount();i++){
RecyclerView.ViewHolder holder=list.getChildViewHolder(list.getChildAt(i));
if(holder instanceof SuggestionViewHolder svh)
svh.rebind();
}
}
@Override
public void onError(ErrorResponse error){
relationshipsRequest=null;
}
}).exec(accountID);
}
@Override
public void onApplyWindowInsets(WindowInsets insets){
super.onApplyWindowInsets(UiUtils.applyBottomInsetToFixedView(buttonBar, insets));
}
@Override
protected RecyclerView.Adapter getAdapter(){
return new SuggestionsAdapter();
}
private void onFollowAllClick(View v){
if(!loaded || relationships.isEmpty())
return;
@ -183,7 +125,7 @@ public class OnboardingFollowSuggestionsFragment extends BaseRecyclerFragment<Ac
public void onSuccess(Relationship result){
relationships.put(id, result);
for(int i=0;i<list.getChildCount();i++){
if(list.getChildViewHolder(list.getChildAt(i)) instanceof SuggestionViewHolder svh && svh.getItem().account.id.equals(id)){
if(list.getChildViewHolder(list.getChildAt(i)) instanceof AccountViewHolder svh && svh.getItem().account.id.equals(id)){
svh.rebind();
break;
}
@ -209,128 +151,9 @@ public class OnboardingFollowSuggestionsFragment extends BaseRecyclerFragment<Ac
Nav.go(getActivity(), OnboardingProfileSetupFragment.class, args);
}
private class SuggestionsAdapter extends UsableRecyclerView.Adapter<SuggestionViewHolder> implements ImageLoaderRecyclerAdapter{
public SuggestionsAdapter(){
super(imgLoader);
}
@NonNull
@Override
public SuggestionViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType){
return new SuggestionViewHolder();
}
@Override
public int getItemCount(){
return data.size();
}
@Override
public void onBindViewHolder(SuggestionViewHolder holder, int position){
holder.bind(data.get(position));
super.onBindViewHolder(holder, position);
}
@Override
public int getImageCountForItem(int position){
return data.get(position).emojiHelper.getImageCount()+1;
}
@Override
public ImageLoaderRequest getImageRequest(int position, int image){
AccountViewModel account=data.get(position);
if(image==0)
return account.avaRequest;
return account.emojiHelper.getImageRequest(image-1);
}
}
private class SuggestionViewHolder extends BindableViewHolder<AccountViewModel> implements ImageLoaderViewHolder, UsableRecyclerView.Clickable{
private final TextView name, username, bio;
private final ImageView avatar;
private final ProgressBarButton actionButton;
private final ProgressBar actionProgress;
private final View actionWrap;
private Relationship relationship;
public SuggestionViewHolder(){
super(getActivity(), R.layout.item_user_row_m3, list);
name=findViewById(R.id.name);
username=findViewById(R.id.username);
bio=findViewById(R.id.bio);
avatar=findViewById(R.id.avatar);
actionButton=findViewById(R.id.action_btn);
actionProgress=findViewById(R.id.action_progress);
actionWrap=findViewById(R.id.action_btn_wrap);
avatar.setOutlineProvider(OutlineProviders.roundedRect(10));
avatar.setClipToOutline(true);
actionButton.setOnClickListener(UiUtils.rateLimitedClickListener(this::onActionButtonClick));
}
@Override
public void onBind(AccountViewModel item){
name.setText(item.parsedName);
username.setText(item.account.getDisplayUsername());
if(TextUtils.isEmpty(item.parsedBio)){
bio.setVisibility(View.GONE);
}else{
bio.setVisibility(View.VISIBLE);
bio.setText(item.parsedBio);
}
relationship=relationships.get(item.account.id);
if(relationship==null){
actionWrap.setVisibility(View.GONE);
}else{
actionWrap.setVisibility(View.VISIBLE);
UiUtils.setRelationshipToActionButtonM3(relationship, actionButton);
}
}
@Override
public void setImage(int index, Drawable image){
if(index==0){
avatar.setImageDrawable(image);
}else{
item.emojiHelper.setImageDrawable(index-1, image);
name.invalidate();
bio.invalidate();
}
if(image instanceof Animatable a && !a.isRunning())
a.start();
}
@Override
public void clearImage(int index){
setImage(index, null);
}
@Override
public void onClick(){
Bundle args=new Bundle();
args.putString("account", accountID);
args.putParcelable("profileAccount", Parcels.wrap(item.account));
Nav.go(getActivity(), ProfileFragment.class, args);
}
private void onActionButtonClick(View v){
itemView.setHasTransientState(true);
UiUtils.performAccountAction(getActivity(), item.account, accountID, relationship, actionButton, this::setActionProgressVisible, rel->{
itemView.setHasTransientState(false);
relationships.put(item.account.id, rel);
rebind();
});
}
private void setActionProgressVisible(boolean visible){
if(visible)
actionProgress.setIndeterminateTintList(actionButton.getTextColors());
actionButton.setTextVisible(!visible);
actionProgress.setVisibility(visible ? View.VISIBLE : View.GONE);
actionButton.setClickable(!visible);
}
@Override
protected void onConfigureViewHolder(AccountViewHolder holder){
super.onConfigureViewHolder(holder);
holder.setStyle(AccountViewHolder.AccessoryType.BUTTON, true);
}
}

View File

@ -1,5 +1,7 @@
package org.joinmastodon.android.model.viewmodel;
import android.text.SpannableStringBuilder;
import org.joinmastodon.android.GlobalUserPreferences;
import org.joinmastodon.android.api.session.AccountSessionManager;
import org.joinmastodon.android.model.Account;
@ -29,7 +31,9 @@ public class AccountViewModel{
else
parsedName=account.displayName;
parsedBio=HtmlParser.parse(account.note, account.emojis, Collections.emptyList(), Collections.emptyList(), accountID);
emojiHelper.setText(parsedName);
SpannableStringBuilder ssb=new SpannableStringBuilder(parsedName);
ssb.append(parsedBio);
emojiHelper.setText(ssb);
String verifiedLink=null;
for(AccountField fld:account.fields){
if(fld.verifiedAt!=null){

View File

@ -1,42 +1,21 @@
package org.joinmastodon.android.ui.displayitems;
import android.content.Context;
import android.graphics.drawable.Animatable;
import android.graphics.drawable.Drawable;
import android.text.TextUtils;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import org.joinmastodon.android.R;
import org.joinmastodon.android.api.session.AccountSessionManager;
import org.joinmastodon.android.fragments.BaseStatusListFragment;
import org.joinmastodon.android.model.Account;
import org.joinmastodon.android.ui.OutlineProviders;
import org.joinmastodon.android.ui.text.HtmlParser;
import org.joinmastodon.android.ui.utils.CustomEmojiHelper;
import org.joinmastodon.android.model.viewmodel.AccountViewModel;
import org.joinmastodon.android.ui.viewholders.AccountViewHolder;
import me.grishka.appkit.imageloader.ImageLoaderViewHolder;
import me.grishka.appkit.imageloader.requests.ImageLoaderRequest;
import me.grishka.appkit.imageloader.requests.UrlImageLoaderRequest;
import me.grishka.appkit.utils.V;
public class AccountStatusDisplayItem extends StatusDisplayItem{
public final Account account;
private CustomEmojiHelper emojiHelper=new CustomEmojiHelper();
private CharSequence parsedName;
public ImageLoaderRequest avaRequest;
public final AccountViewModel account;
public AccountStatusDisplayItem(String parentID, BaseStatusListFragment parentFragment, Account account){
super(parentID, parentFragment);
this.account=account;
if(AccountSessionManager.get(parentFragment.getAccountID()).getLocalPreferences().customEmojiInNames)
parsedName=HtmlParser.parseCustomEmoji(account.displayName, account.emojis);
else
parsedName=account.displayName;
emojiHelper.setText(parsedName);
if(!TextUtils.isEmpty(account.avatar))
avaRequest=new UrlImageLoaderRequest(account.avatar, V.dp(50), V.dp(50));
this.account=new AccountViewModel(account, parentFragment.getAccountID());
}
@Override
@ -46,51 +25,43 @@ public class AccountStatusDisplayItem extends StatusDisplayItem{
@Override
public int getImageCount(){
return 1+emojiHelper.getImageCount();
return 1+account.emojiHelper.getImageCount();
}
@Override
public ImageLoaderRequest getImageRequest(int index){
if(index==0)
return avaRequest;
return emojiHelper.getImageRequest(index-1);
return account.avaRequest;
return account.emojiHelper.getImageRequest(index-1);
}
public static class Holder extends StatusDisplayItem.Holder<AccountStatusDisplayItem> implements ImageLoaderViewHolder{
private final TextView name, username;
private final ImageView photo;
private final AccountViewHolder realHolder;
public Holder(Context context, ViewGroup parent){
super(context, R.layout.display_item_account, parent);
name=findViewById(R.id.name);
username=findViewById(R.id.username);
photo=findViewById(R.id.photo);
photo.setOutlineProvider(OutlineProviders.roundedRect(12));
photo.setClipToOutline(true);
public Holder(AccountViewHolder realHolder){
super(realHolder.itemView);
this.realHolder=realHolder;
realHolder.setStyle(AccountViewHolder.AccessoryType.NONE, false);
}
@Override
public void onBind(AccountStatusDisplayItem item){
name.setText(item.parsedName);
username.setText("@"+item.account.acct);
realHolder.bind(item.account);
}
@Override
public void setImage(int index, Drawable image){
if(image instanceof Animatable && !((Animatable) image).isRunning())
((Animatable) image).start();
if(index==0){
photo.setImageDrawable(image);
}else{
item.emojiHelper.setImageDrawable(index-1, image);
name.invalidate();
}
realHolder.setImage(index, image);
}
@Override
public void clearImage(int index){
setImage(index, null);
realHolder.clearImage(index);
}
@Override
public void onClick(){
realHolder.onClick();
}
}
}

View File

@ -241,6 +241,10 @@ public class HeaderStatusDisplayItem extends StatusDisplayItem{
@Override
public void clearImage(int index){
if(index==0){
avatar.setImageResource(R.drawable.image_placeholder);
return;
}
setImage(index, null);
}

View File

@ -1,6 +1,7 @@
package org.joinmastodon.android.ui.displayitems;
import android.app.Activity;
import android.app.Fragment;
import android.content.Context;
import android.text.SpannableStringBuilder;
import android.text.TextUtils;
@ -19,6 +20,7 @@ import org.joinmastodon.android.model.Poll;
import org.joinmastodon.android.model.Status;
import org.joinmastodon.android.ui.PhotoLayoutHelper;
import org.joinmastodon.android.ui.text.HtmlParser;
import org.joinmastodon.android.ui.viewholders.AccountViewHolder;
import java.util.ArrayList;
import java.util.List;
@ -57,7 +59,7 @@ public abstract class StatusDisplayItem{
return null;
}
public static BindableViewHolder<? extends StatusDisplayItem> createViewHolder(Type type, Activity activity, ViewGroup parent){
public static BindableViewHolder<? extends StatusDisplayItem> createViewHolder(Type type, Activity activity, ViewGroup parent, Fragment parentFragment){
return switch(type){
case HEADER -> new HeaderStatusDisplayItem.Holder(activity, parent);
case HEADER_CHECKABLE -> new CheckableHeaderStatusDisplayItem.Holder(activity, parent);
@ -68,7 +70,7 @@ public abstract class StatusDisplayItem{
case POLL_FOOTER -> new PollFooterStatusDisplayItem.Holder(activity, parent);
case CARD -> new LinkCardStatusDisplayItem.Holder(activity, parent);
case FOOTER -> new FooterStatusDisplayItem.Holder(activity, parent);
case ACCOUNT -> new AccountStatusDisplayItem.Holder(activity, parent);
case ACCOUNT -> new AccountStatusDisplayItem.Holder(new AccountViewHolder(parentFragment, parent, null));
case HASHTAG -> new HashtagStatusDisplayItem.Holder(activity, parent);
case GAP -> new GapStatusDisplayItem.Holder(activity, parent);
case EXTENDED_FOOTER -> new ExtendedFooterStatusDisplayItem.Holder(activity, parent);

View File

@ -127,11 +127,11 @@ public class UiUtils{
if(diff<1000L){
return context.getString(R.string.time_now);
}else if(diff<60_000L){
return context.getString(R.string.time_seconds, diff/1000L);
return context.getString(R.string.time_seconds_ago_short, diff/1000L);
}else if(diff<3600_000L){
return context.getString(R.string.time_minutes, diff/60_000L);
return context.getString(R.string.time_minutes_ago_short, diff/60_000L);
}else if(diff<3600_000L*24L){
return context.getString(R.string.time_hours, diff/3600_000L);
return context.getString(R.string.time_hours_ago_short, diff/3600_000L);
}else{
int days=(int)(diff/(3600_000L*24L));
if(days>30){
@ -142,7 +142,7 @@ public class UiUtils{
return DATE_FORMATTER_SHORT_WITH_YEAR.format(dt);
}
}
return context.getString(R.string.time_days, days);
return context.getString(R.string.time_days_ago_short, days);
}
}

View File

@ -1,12 +1,12 @@
package org.joinmastodon.android.ui.viewholders;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.Fragment;
import android.app.ProgressDialog;
import android.content.Intent;
import android.content.res.ColorStateList;
import android.graphics.drawable.Animatable;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.text.SpannableStringBuilder;
@ -16,8 +16,11 @@ import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.PopupMenu;
import android.widget.ProgressBar;
import android.widget.RadioButton;
import android.widget.TextView;
import org.joinmastodon.android.R;
@ -26,12 +29,12 @@ import org.joinmastodon.android.api.session.AccountSessionManager;
import org.joinmastodon.android.fragments.ProfileFragment;
import org.joinmastodon.android.fragments.report.ReportReasonChoiceFragment;
import org.joinmastodon.android.model.Account;
import org.joinmastodon.android.model.AccountField;
import org.joinmastodon.android.model.Relationship;
import org.joinmastodon.android.model.viewmodel.AccountViewModel;
import org.joinmastodon.android.ui.OutlineProviders;
import org.joinmastodon.android.ui.text.HtmlParser;
import org.joinmastodon.android.ui.utils.UiUtils;
import org.joinmastodon.android.ui.views.CheckableRelativeLayout;
import org.joinmastodon.android.ui.views.ProgressBarButton;
import org.parceler.Parcels;
import java.util.HashMap;
@ -46,18 +49,24 @@ import me.grishka.appkit.utils.BindableViewHolder;
import me.grishka.appkit.views.UsableRecyclerView;
public class AccountViewHolder extends BindableViewHolder<AccountViewModel> implements ImageLoaderViewHolder, UsableRecyclerView.Clickable, UsableRecyclerView.LongClickable{
private final TextView name, username, followers, verifiedLink;
private final TextView name, username, followers, verifiedLink, bio;
private final ImageView avatar;
private final Button button;
private final ProgressBarButton button;
private final PopupMenu contextMenu;
private final View menuAnchor;
private final TypefaceSpan mediumSpan=new TypefaceSpan("sans-serif-medium");
private final CheckableRelativeLayout view;
private final View checkbox;
private final ProgressBar actionProgress;
private final String accountID;
private final Fragment fragment;
private final HashMap<String, Relationship> relationships;
private Consumer<AccountViewHolder> onClick;
private AccessoryType accessoryType=AccessoryType.BUTTON;
private boolean showBio;
private boolean checked;
public AccountViewHolder(Fragment fragment, ViewGroup list, HashMap<String, Relationship> relationships){
super(fragment.getActivity(), R.layout.item_account_list, list);
@ -65,6 +74,7 @@ public class AccountViewHolder extends BindableViewHolder<AccountViewModel> impl
this.accountID=Objects.requireNonNull(fragment.getArguments().getString("account"));
this.relationships=relationships;
view=(CheckableRelativeLayout) itemView;
name=findViewById(R.id.name);
username=findViewById(R.id.username);
avatar=findViewById(R.id.avatar);
@ -72,8 +82,11 @@ public class AccountViewHolder extends BindableViewHolder<AccountViewModel> impl
menuAnchor=findViewById(R.id.menu_anchor);
followers=findViewById(R.id.followers_count);
verifiedLink=findViewById(R.id.verified_link);
bio=findViewById(R.id.bio);
checkbox=findViewById(R.id.checkbox);
actionProgress=findViewById(R.id.action_progress);
avatar.setOutlineProvider(OutlineProviders.roundedRect(16));
avatar.setOutlineProvider(OutlineProviders.roundedRect(10));
avatar.setClipToOutline(true);
button.setOnClickListener(this::onButtonClick);
@ -81,6 +94,8 @@ public class AccountViewHolder extends BindableViewHolder<AccountViewModel> impl
contextMenu=new PopupMenu(fragment.getActivity(), menuAnchor);
contextMenu.inflate(R.menu.profile);
contextMenu.setOnMenuItemClickListener(this::onContextMenuItemSelected);
setStyle(AccessoryType.BUTTON, false);
}
@SuppressLint("SetTextI18n")
@ -107,10 +122,13 @@ public class AccountViewHolder extends BindableViewHolder<AccountViewModel> impl
verifiedLink.setTextColor(tintColor);
verifiedLink.setCompoundDrawableTintList(ColorStateList.valueOf(tintColor));
bindRelationship();
if(showBio){
bio.setText(item.parsedBio);
}
}
public void bindRelationship(){
if(relationships==null)
if(relationships==null || accessoryType!=AccessoryType.BUTTON)
return;
Relationship rel=relationships.get(item.account.id);
if(rel==null || AccountSessionManager.getInstance().isSelf(accountID, item.account)){
@ -128,6 +146,7 @@ public class AccountViewHolder extends BindableViewHolder<AccountViewModel> impl
}else{
item.emojiHelper.setImageDrawable(index-1, image);
name.invalidate();
bio.invalidate();
}
if(image instanceof Animatable a && !a.isRunning())
@ -199,21 +218,22 @@ public class AccountViewHolder extends BindableViewHolder<AccountViewModel> impl
private void onButtonClick(View v){
if(relationships==null)
return;
ProgressDialog progress=new ProgressDialog(fragment.getActivity());
progress.setMessage(fragment.getString(R.string.loading));
progress.setCancelable(false);
UiUtils.performAccountAction(fragment.getActivity(), item.account, accountID, relationships.get(item.account.id), button, progressShown->{
itemView.setHasTransientState(progressShown);
if(progressShown)
progress.show();
else
progress.dismiss();
}, result->{
relationships.put(item.account.id, result);
itemView.setHasTransientState(true);
UiUtils.performAccountAction((Activity) v.getContext(), item.account, accountID, relationships.get(item.account.id), button, this::setActionProgressVisible, rel->{
itemView.setHasTransientState(false);
relationships.put(item.account.id, rel);
bindRelationship();
});
}
private void setActionProgressVisible(boolean visible){
if(visible)
actionProgress.setIndeterminateTintList(button.getTextColors());
button.setTextVisible(!visible);
actionProgress.setVisibility(visible ? View.VISIBLE : View.GONE);
button.setClickable(!visible);
}
private boolean onContextMenuItemSelected(MenuItem item){
Relationship relationship=relationships.get(this.item.account.id);
if(relationship==null)
@ -271,4 +291,45 @@ public class AccountViewHolder extends BindableViewHolder<AccountViewModel> impl
public void setOnClickListener(Consumer<AccountViewHolder> listener){
onClick=listener;
}
public void setStyle(AccessoryType accessoryType, boolean showBio){
if(accessoryType!=this.accessoryType){
this.accessoryType=accessoryType;
switch(accessoryType){
case NONE -> {
button.setVisibility(View.GONE);
checkbox.setVisibility(View.GONE);
}
case CHECKBOX -> {
button.setVisibility(View.GONE);
checkbox.setVisibility(View.VISIBLE);
checkbox.setBackground(new CheckBox(checkbox.getContext()).getButtonDrawable());
}
case RADIOBUTTON -> {
button.setVisibility(View.GONE);
checkbox.setVisibility(View.VISIBLE);
checkbox.setBackground(new RadioButton(checkbox.getContext()).getButtonDrawable());
}
case BUTTON -> {
button.setVisibility(View.VISIBLE);
checkbox.setVisibility(View.GONE);
}
}
view.setCheckable(accessoryType==AccessoryType.CHECKBOX || accessoryType==AccessoryType.RADIOBUTTON);
}
this.showBio=showBio;
bio.setVisibility(showBio ? View.VISIBLE : View.GONE);
}
public void setChecked(boolean checked){
this.checked=checked;
view.setChecked(checked);
}
public enum AccessoryType{
NONE,
BUTTON,
CHECKBOX,
RADIOBUTTON
}
}

View File

@ -7,7 +7,7 @@ import android.widget.Checkable;
import android.widget.RelativeLayout;
public class CheckableRelativeLayout extends RelativeLayout implements Checkable{
private boolean checked;
private boolean checked, checkable=true;
private static final int[] CHECKED_STATE_SET = {
android.R.attr.state_checked
};
@ -40,6 +40,10 @@ public class CheckableRelativeLayout extends RelativeLayout implements Checkable
setChecked(!checked);
}
public void setCheckable(boolean checkable){
this.checkable=checkable;
}
@Override
protected int[] onCreateDrawableState(int extraSpace) {
final int[] drawableState = super.onCreateDrawableState(extraSpace + 1);
@ -52,7 +56,7 @@ public class CheckableRelativeLayout extends RelativeLayout implements Checkable
@Override
public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info){
super.onInitializeAccessibilityNodeInfo(info);
info.setCheckable(true);
info.setCheckable(checkable);
info.setChecked(checked);
}
}

View File

@ -1,42 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
android:paddingTop="12dp"
android:paddingLeft="16dp"
android:paddingRight="16dp">
<ImageView
android:id="@+id/photo"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="12dp"
tools:src="#0f0"/>
<TextView
android:id="@+id/name"
android:layout_width="match_parent"
android:layout_height="24dp"
android:layout_toEndOf="@id/photo"
android:textAppearance="@style/m3_title_medium"
android:fontFamily="sans-serif"
android:singleLine="true"
android:ellipsize="end"
tools:text="User Name"/>
<TextView
android:id="@+id/username"
android:layout_width="match_parent"
android:layout_height="20dp"
android:layout_toEndOf="@id/photo"
android:layout_alignBottom="@id/photo"
android:layout_marginBottom="-4dp"
android:textAppearance="@style/m3_body_medium"
android:textColor="?android:textColorSecondary"
android:singleLine="true"
android:ellipsize="end"
tools:text="\@user@domain"/>
</RelativeLayout>

View File

@ -72,7 +72,7 @@
android:layout_toEndOf="@id/avatar"
android:singleLine="true"
android:ellipsize="end"
android:textAppearance="@style/m3_title_small"
android:textAppearance="@style/m3_body_medium"
android:gravity="center_vertical"
android:textColor="?colorM3OnSurfaceVariant"
tools:text="9h ago · \@Gargron@mastodon.social"/>

View File

@ -1,82 +1,139 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
<org.joinmastodon.android.ui.views.CheckableRelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="72dp"
android:layout_height="wrap_content"
android:paddingHorizontal="16dp"
android:paddingVertical="8dp"
android:clipToPadding="false">
<ImageView
android:id="@+id/avatar"
android:layout_width="56dp"
android:layout_height="56dp"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginEnd="8dp"
android:importantForAccessibility="no"
tools:src="#0f0"/>
<Button
android:id="@+id/button"
<LinearLayout
android:id="@+id/line1"
android:layout_width="match_parent"
android:layout_height="20dp"
android:orientation="horizontal"
android:layout_toStartOf="@id/accessory"
android:layout_toEndOf="@id/avatar">
<TextView
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="20dp"
android:singleLine="true"
android:ellipsize="end"
android:gravity="center_vertical"
android:textAppearance="@style/m3_title_small"
android:textColor="?colorM3OnSurface"
tools:text="User"/>
<TextView
android:id="@+id/username"
android:layout_width="match_parent"
android:layout_height="20dp"
android:layout_marginStart="4dp"
android:singleLine="true"
android:ellipsize="end"
android:gravity="center_vertical"
android:textAppearance="@style/m3_body_medium"
android:textColor="?colorM3Secondary"
tools:text="\@user@server"/>
</LinearLayout>
<LinearLayout
android:id="@+id/line2"
android:layout_width="match_parent"
android:layout_height="20dp"
android:orientation="horizontal"
android:layout_toEndOf="@id/avatar"
android:layout_toStartOf="@id/accessory"
android:layout_below="@id/line1">
<TextView
android:id="@+id/followers_count"
android:layout_width="wrap_content"
android:layout_height="20dp"
android:gravity="center_vertical"
android:textAppearance="@style/m3_body_medium"
android:textColor="?colorM3Secondary"
tools:text="123 followers"/>
<TextView
android:id="@+id/verified_link"
android:layout_width="wrap_content"
android:layout_height="20dp"
android:layout_marginStart="4dp"
android:singleLine="true"
android:ellipsize="end"
android:textAppearance="@style/m3_body_medium"
android:includeFontPadding="false"
android:gravity="center_vertical"
android:drawablePadding="2dp"
tools:text="example.com/example"/>
</LinearLayout>
<FrameLayout
android:id="@+id/accessory"
android:layout_width="wrap_content"
android:layout_height="36dp"
android:layout_height="40dp"
android:layout_alignParentEnd="true"
android:layout_alignParentTop="true"
android:layout_marginStart="8dp"
style="@style/Widget.Mastodon.M3.Button.Filled"
tools:text="Follow"/>
android:duplicateParentState="true">
<org.joinmastodon.android.ui.views.ProgressBarButton
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_gravity="center_vertical"
android:paddingHorizontal="10dp"
android:minWidth="96dp"
android:maxWidth="150dp"
style="@style/Widget.Mastodon.M3.Button.Filled"
tools:text="Follow back"/>
<ProgressBar
android:id="@+id/action_progress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:indeterminate="true"
style="?android:progressBarStyleSmall"
android:elevation="10dp"
android:outlineProvider="none"
android:indeterminateTint="?colorM3OnPrimary"
android:visibility="gone"/>
<View
android:id="@+id/checkbox"
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_marginHorizontal="4dp"
android:layout_marginTop="2dp"
android:duplicateParentState="true"
android:visibility="gone"/>
</FrameLayout>
<TextView
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="20dp"
android:id="@+id/bio"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toEndOf="@id/avatar"
android:singleLine="true"
android:ellipsize="end"
android:gravity="center_vertical"
android:textAppearance="@style/m3_title_small"
android:layout_below="@id/line2"
android:layout_toStartOf="@id/accessory"
android:textAppearance="@style/m3_body_medium"
android:textColor="?colorM3OnSurface"
tools:text="User"/>
<TextView
android:id="@+id/username"
android:layout_width="match_parent"
android:layout_height="20dp"
android:layout_marginStart="4dp"
android:layout_toEndOf="@id/name"
android:layout_toStartOf="@id/button"
android:singleLine="true"
android:ellipsize="end"
android:gravity="center_vertical"
android:textAppearance="@style/m3_body_medium"
android:textColor="?colorM3Secondary"
tools:text="\@user@server"/>
<TextView
android:id="@+id/followers_count"
android:layout_width="match_parent"
android:layout_height="20dp"
android:layout_toEndOf="@id/avatar"
android:layout_below="@id/name"
android:layout_toStartOf="@id/button"
android:gravity="center_vertical"
android:textAppearance="@style/m3_body_medium"
android:textColor="?colorM3Secondary"
tools:text="123 followers"/>
<TextView
android:id="@+id/verified_link"
android:layout_width="match_parent"
android:layout_height="16dp"
android:layout_toEndOf="@id/avatar"
android:layout_below="@id/followers_count"
android:layout_toStartOf="@id/button"
android:singleLine="true"
android:ellipsize="end"
android:textAppearance="@style/m3_body_medium"
android:includeFontPadding="false"
android:gravity="center_vertical"
android:drawablePadding="2dp"
tools:text="example.com/example"/>
android:maxLines="2"
android:paddingVertical="2dp"
tools:text="bla bla bla bla bla bla"/>
<View
android:id="@+id/menu_anchor"
@ -86,4 +143,4 @@
android:layout_alignParentLeft="true"
android:layout_marginLeft="-16dp"/>
</RelativeLayout>
</org.joinmastodon.android.ui.views.CheckableRelativeLayout>

View File

@ -1,187 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
android:background="?colorBackgroundLight"
android:elevation="2dp"
android:paddingBottom="16dp">
<ImageView
android:id="@+id/cover"
android:layout_width="match_parent"
android:layout_height="128dp"
android:layout_marginTop="4dp"
android:layout_marginLeft="4dp"
android:layout_marginRight="4dp"
android:scaleType="centerCrop"
tools:src="#0f0"/>
<View
android:id="@+id/avatar_border"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_below="@id/cover"
android:layout_alignParentStart="true"
android:layout_marginTop="-6dp"
android:layout_marginStart="14dp"
android:background="@drawable/discover_ava_bg"/>
<ImageView
android:id="@+id/avatar"
android:layout_width="56dp"
android:layout_height="56dp"
android:layout_below="@id/cover"
android:layout_alignParentStart="true"
android:layout_marginStart="16dp"
android:layout_marginTop="-4dp"
android:scaleType="centerCrop"
tools:src="#f00" />
<TextView
android:id="@+id/name"
android:layout_width="match_parent"
android:layout_height="24dp"
android:layout_toEndOf="@id/avatar"
android:layout_below="@id/cover"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="16dp"
android:singleLine="true"
android:ellipsize="end"
android:gravity="center_vertical"
android:textAppearance="@style/m3_title_medium"
tools:text="Eugen"/>
<TextView
android:id="@+id/username"
android:layout_width="match_parent"
android:layout_height="20dp"
android:layout_alignLeft="@id/name"
android:layout_alignRight="@id/name"
android:layout_below="@id/name"
android:singleLine="true"
android:ellipsize="end"
android:gravity="center_vertical"
android:textAppearance="@style/m3_title_small"
tools:text="\@Gargron@mastodon.social"/>
<TextView
android:id="@+id/bio"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/avatar"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginTop="8dp"
android:textAppearance="@style/m3_body_large"
tools:text="Founder, CEO and lead developer @Mastodon, Germany." />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/bio"
android:orientation="horizontal">
<LinearLayout
android:id="@+id/posts_btn"
android:layout_width="wrap_content"
android:layout_height="48dp"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:gravity="center_horizontal"
android:orientation="vertical">
<TextView
android:id="@+id/posts_count"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="@style/m3_title_large"
tools:text="123" />
<TextView
android:id="@+id/posts_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="@style/m3_title_small"
tools:text="following" />
</LinearLayout>
<LinearLayout
android:id="@+id/followers_btn"
android:layout_width="wrap_content"
android:layout_height="48dp"
android:layout_marginTop="16dp"
android:layout_marginStart="12dp"
android:orientation="vertical"
android:gravity="center_horizontal">
<TextView
android:id="@+id/followers_count"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="@style/m3_title_large"
tools:text="123"/>
<TextView
android:id="@+id/followers_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="@style/m3_title_small"
tools:text="following"/>
</LinearLayout>
<LinearLayout
android:id="@+id/following_btn"
android:layout_width="wrap_content"
android:layout_height="48dp"
android:layout_marginTop="16dp"
android:layout_marginStart="12dp"
android:orientation="vertical"
android:gravity="center_horizontal">
<TextView
android:id="@+id/following_count"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="@style/m3_title_large"
tools:text="123"/>
<TextView
android:id="@+id/following_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="@style/m3_title_small"
tools:text="following"/>
</LinearLayout>
<Space
android:layout_width="0px"
android:layout_height="1px"
android:layout_weight="1"/>
<FrameLayout
android:id="@+id/action_btn_wrap"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:padding="8dp"
android:layout_marginEnd="8dp"
android:clipToPadding="false">
<org.joinmastodon.android.ui.views.ProgressBarButton
android:id="@+id/action_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
tools:text="@string/follow_back"/>
<ProgressBar
android:id="@+id/action_progress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:indeterminate="true"
style="?android:progressBarStyleSmall"
android:elevation="10dp"
android:outlineProvider="none"
android:indeterminateTint="?colorButtonText"
android:visibility="gone"/>
</FrameLayout>
</LinearLayout>
</RelativeLayout>

View File

@ -34,17 +34,6 @@
style="@style/Widget.Mastodon.M3.Button.Filled"
tools:text="Follow"/>
<ProgressBar
android:id="@+id/action_progress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:indeterminate="true"
style="?android:progressBarStyleSmall"
android:elevation="10dp"
android:outlineProvider="none"
android:indeterminateTint="?colorM3OnPrimary"
android:visibility="gone"/>
</FrameLayout>

View File

@ -641,4 +641,10 @@
<string name="search_go_to_account">Go to %s</string>
<string name="posts_matching_string">Posts with “%s”</string>
<string name="accounts_matching_string">People with “%s”</string>
<!-- Shown in the post header. Please keep it short -->
<string name="time_seconds_ago_short">%ds ago</string>
<string name="time_minutes_ago_short">%dm ago</string>
<string name="time_hours_ago_short">%dh ago</string>
<string name="time_days_ago_short">%dd ago</string>
</resources>