Merge branch 'charlag-boost-actions'

This commit is contained in:
Vavassor 2017-07-04 17:44:29 -04:00
commit b07151b707
7 changed files with 39 additions and 6 deletions

View file

@ -17,7 +17,7 @@ class AccountViewHolder extends RecyclerView.ViewHolder {
private TextView username; private TextView username;
private TextView displayName; private TextView displayName;
private CircularImageView avatar; private CircularImageView avatar;
private String id; private String accountId;
AccountViewHolder(View itemView) { AccountViewHolder(View itemView) {
super(itemView); super(itemView);
@ -28,7 +28,7 @@ class AccountViewHolder extends RecyclerView.ViewHolder {
} }
void setupWithAccount(Account account) { void setupWithAccount(Account account) {
id = account.id; accountId = account.id;
String format = username.getContext().getString(R.string.status_username_format); String format = username.getContext().getString(R.string.status_username_format);
String formattedUsername = String.format(format, account.username); String formattedUsername = String.format(format, account.username);
username.setText(formattedUsername); username.setText(formattedUsername);
@ -45,7 +45,7 @@ class AccountViewHolder extends RecyclerView.ViewHolder {
container.setOnClickListener(new View.OnClickListener() { container.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
listener.onViewAccount(id); listener.onViewAccount(accountId);
} }
}); });
} }
@ -54,7 +54,7 @@ class AccountViewHolder extends RecyclerView.ViewHolder {
container.setOnClickListener(new View.OnClickListener() { container.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
listener.onViewAccount(id); listener.onViewAccount(accountId);
} }
}); });
} }

View file

@ -425,7 +425,7 @@ class StatusViewHolder extends RecyclerView.ViewHolder {
container.setOnClickListener(viewThreadListener); container.setOnClickListener(viewThreadListener);
} }
void setupWithStatus(Status status, StatusActionListener listener, void setupWithStatus(Status status, final StatusActionListener listener,
boolean mediaPreviewEnabled) { boolean mediaPreviewEnabled) {
Status realStatus = status.getActionableStatus(); Status realStatus = status.getActionableStatus();
@ -474,5 +474,15 @@ class StatusViewHolder extends RecyclerView.ViewHolder {
} else { } else {
setSpoilerText(realStatus.spoilerText); setSpoilerText(realStatus.spoilerText);
} }
// I think it's not efficient to create new object every time we bind a holder.
// More efficient approach would be creating View.OnClickListener during holder creation
// and storing StatusActionListener in a variable after binding.
rebloggedBar.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
listener.onOpenReblog(getAdapterPosition());
}
});
} }
} }

View file

@ -225,6 +225,12 @@ public class NotificationsFragment extends SFragment implements
super.viewThread(notification.status); super.viewThread(notification.status);
} }
@Override
public void onOpenReblog(int position) {
Notification notification = adapter.getItem(position);
if (notification != null) onViewAccount(notification.account.id);
}
@Override @Override
public void onViewTag(String tag) { public void onViewTag(String tag) {
super.viewTag(tag); super.viewTag(tag);

View file

@ -169,6 +169,11 @@ public abstract class SFragment extends BaseFragment {
callList.add(call); callList.add(call);
} }
protected void openReblog(@Nullable final Status status) {
if (status == null) return;
viewAccount(status.account.id);
}
private void mute(String id) { private void mute(String id) {
Call<Relationship> call = mastodonApi.muteAccount(id); Call<Relationship> call = mastodonApi.muteAccount(id);
call.enqueue(new Callback<Relationship>() { call.enqueue(new Callback<Relationship>() {

View file

@ -246,6 +246,11 @@ public class TimelineFragment extends SFragment implements
super.more(adapter.getItem(position), view, adapter, position); super.more(adapter.getItem(position), view, adapter, position);
} }
@Override
public void onOpenReblog(int position) {
super.openReblog(adapter.getItem(position));
}
@Override @Override
public void onViewMedia(String[] urls, int urlIndex, Status.MediaAttachment.Type type) { public void onViewMedia(String[] urls, int urlIndex, Status.MediaAttachment.Type type) {
super.viewMedia(urls, urlIndex, type); super.viewMedia(urls, urlIndex, type);

View file

@ -158,6 +158,12 @@ public class ViewThreadFragment extends SFragment implements
super.viewThread(status); super.viewThread(status);
} }
@Override
public void onOpenReblog(int position) {
// there should be no reblogs in the thread but let's implement it to be sure
super.openReblog(adapter.getItem(position));
}
@Override @Override
public void onViewTag(String tag) { public void onViewTag(String tag) {
super.viewTag(tag); super.viewTag(tag);

View file

@ -26,4 +26,5 @@ public interface StatusActionListener extends LinkListener {
void onMore(View view, final int position); void onMore(View view, final int position);
void onViewMedia(String[] urls, int index, Status.MediaAttachment.Type type); void onViewMedia(String[] urls, int index, Status.MediaAttachment.Type type);
void onViewThread(int position); void onViewThread(int position);
void onOpenReblog(int position);
} }