From 0f1550934548de3ca977211f62fddb41e0698087 Mon Sep 17 00:00:00 2001 From: Ivan Kupalov Date: Wed, 28 Jun 2017 11:10:56 +0300 Subject: [PATCH] Add boost click handling --- .../tusky/adapter/AccountViewHolder.java | 8 ++++---- .../tusky/adapter/StatusViewHolder.java | 14 ++++++++++++-- .../tusky/fragment/NotificationsFragment.java | 6 ++++++ .../keylesspalace/tusky/fragment/SFragment.java | 5 +++++ .../tusky/fragment/TimelineFragment.java | 5 +++++ .../tusky/fragment/ViewThreadFragment.java | 6 ++++++ .../tusky/interfaces/StatusActionListener.java | 1 + 7 files changed, 39 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/com/keylesspalace/tusky/adapter/AccountViewHolder.java b/app/src/main/java/com/keylesspalace/tusky/adapter/AccountViewHolder.java index 6c197e27a..f6a5b2282 100644 --- a/app/src/main/java/com/keylesspalace/tusky/adapter/AccountViewHolder.java +++ b/app/src/main/java/com/keylesspalace/tusky/adapter/AccountViewHolder.java @@ -17,7 +17,7 @@ class AccountViewHolder extends RecyclerView.ViewHolder { private TextView username; private TextView displayName; private CircularImageView avatar; - private String id; + private String accountId; AccountViewHolder(View itemView) { super(itemView); @@ -28,7 +28,7 @@ class AccountViewHolder extends RecyclerView.ViewHolder { } void setupWithAccount(Account account) { - id = account.id; + accountId = account.id; String format = username.getContext().getString(R.string.status_username_format); String formattedUsername = String.format(format, account.username); username.setText(formattedUsername); @@ -45,7 +45,7 @@ class AccountViewHolder extends RecyclerView.ViewHolder { container.setOnClickListener(new View.OnClickListener() { @Override 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() { @Override public void onClick(View v) { - listener.onViewAccount(id); + listener.onViewAccount(accountId); } }); } diff --git a/app/src/main/java/com/keylesspalace/tusky/adapter/StatusViewHolder.java b/app/src/main/java/com/keylesspalace/tusky/adapter/StatusViewHolder.java index ec16f333f..9646e4f25 100644 --- a/app/src/main/java/com/keylesspalace/tusky/adapter/StatusViewHolder.java +++ b/app/src/main/java/com/keylesspalace/tusky/adapter/StatusViewHolder.java @@ -425,8 +425,8 @@ class StatusViewHolder extends RecyclerView.ViewHolder { container.setOnClickListener(viewThreadListener); } - void setupWithStatus(Status status, StatusActionListener listener, - boolean mediaPreviewEnabled) { + void setupWithStatus(Status status, final StatusActionListener listener, + boolean mediaPreviewEnabled) { Status realStatus = status.getActionableStatus(); setDisplayName(realStatus.account.getDisplayName()); @@ -474,5 +474,15 @@ class StatusViewHolder extends RecyclerView.ViewHolder { } else { 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()); + } + }); } } \ No newline at end of file diff --git a/app/src/main/java/com/keylesspalace/tusky/fragment/NotificationsFragment.java b/app/src/main/java/com/keylesspalace/tusky/fragment/NotificationsFragment.java index 4f128b18c..cf5204edb 100644 --- a/app/src/main/java/com/keylesspalace/tusky/fragment/NotificationsFragment.java +++ b/app/src/main/java/com/keylesspalace/tusky/fragment/NotificationsFragment.java @@ -225,6 +225,12 @@ public class NotificationsFragment extends SFragment implements super.viewThread(notification.status); } + @Override + public void onOpenReblog(int position) { + Notification notification = adapter.getItem(position); + if (notification != null) onViewAccount(notification.account.id); + } + @Override public void onViewTag(String tag) { super.viewTag(tag); diff --git a/app/src/main/java/com/keylesspalace/tusky/fragment/SFragment.java b/app/src/main/java/com/keylesspalace/tusky/fragment/SFragment.java index f131ee185..4d7113dfa 100644 --- a/app/src/main/java/com/keylesspalace/tusky/fragment/SFragment.java +++ b/app/src/main/java/com/keylesspalace/tusky/fragment/SFragment.java @@ -169,6 +169,11 @@ public abstract class SFragment extends BaseFragment { callList.add(call); } + protected void openReblog(@Nullable final Status status) { + if (status == null) return; + viewAccount(status.account.id); + } + private void mute(String id) { Call call = mastodonApi.muteAccount(id); call.enqueue(new Callback() { diff --git a/app/src/main/java/com/keylesspalace/tusky/fragment/TimelineFragment.java b/app/src/main/java/com/keylesspalace/tusky/fragment/TimelineFragment.java index 013461393..b9e7487c8 100644 --- a/app/src/main/java/com/keylesspalace/tusky/fragment/TimelineFragment.java +++ b/app/src/main/java/com/keylesspalace/tusky/fragment/TimelineFragment.java @@ -246,6 +246,11 @@ public class TimelineFragment extends SFragment implements super.more(adapter.getItem(position), view, adapter, position); } + @Override + public void onOpenReblog(int position) { + super.openReblog(adapter.getItem(position)); + } + @Override public void onViewMedia(String[] urls, int urlIndex, Status.MediaAttachment.Type type) { super.viewMedia(urls, urlIndex, type); diff --git a/app/src/main/java/com/keylesspalace/tusky/fragment/ViewThreadFragment.java b/app/src/main/java/com/keylesspalace/tusky/fragment/ViewThreadFragment.java index 078d67879..3529533ea 100644 --- a/app/src/main/java/com/keylesspalace/tusky/fragment/ViewThreadFragment.java +++ b/app/src/main/java/com/keylesspalace/tusky/fragment/ViewThreadFragment.java @@ -158,6 +158,12 @@ public class ViewThreadFragment extends SFragment implements 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 public void onViewTag(String tag) { super.viewTag(tag); diff --git a/app/src/main/java/com/keylesspalace/tusky/interfaces/StatusActionListener.java b/app/src/main/java/com/keylesspalace/tusky/interfaces/StatusActionListener.java index fa220385c..9c00fc42c 100644 --- a/app/src/main/java/com/keylesspalace/tusky/interfaces/StatusActionListener.java +++ b/app/src/main/java/com/keylesspalace/tusky/interfaces/StatusActionListener.java @@ -26,4 +26,5 @@ public interface StatusActionListener extends LinkListener { void onMore(View view, final int position); void onViewMedia(String[] urls, int index, Status.MediaAttachment.Type type); void onViewThread(int position); + void onOpenReblog(int position); }