From 344136e7bd79730ac57594c5ec928ee44fc5deb2 Mon Sep 17 00:00:00 2001 From: Mariotaku Lee Date: Sun, 29 Mar 2015 15:17:42 +0800 Subject: [PATCH] click media preview to open media now works --- .../twidere/adapter/AbsActivitiesAdapter.java | 8 ++++++++ .../twidere/adapter/AbsStatusesAdapter.java | 11 +++++++++++ .../twidere/adapter/CursorStatusesAdapter.java | 1 + .../adapter/MessageConversationAdapter.java | 4 ++-- .../adapter/ParcelableActivitiesAdapter.java | 2 ++ .../fragment/support/AbsStatusesFragment.java | 8 ++++++++ .../fragment/support/StatusFragment.java | 17 ++++++++++++++--- .../twidere/util/StatusLinkClickHandler.java | 2 +- .../java/org/mariotaku/twidere/util/Utils.java | 12 ++++-------- .../twidere/view/CardMediaContainer.java | 3 ++- .../holder/MessageConversationViewHolder.java | 10 ++++++++-- .../twidere/view/holder/StatusViewHolder.java | 18 ++++++++++++++---- 12 files changed, 75 insertions(+), 21 deletions(-) diff --git a/twidere/src/main/java/org/mariotaku/twidere/adapter/AbsActivitiesAdapter.java b/twidere/src/main/java/org/mariotaku/twidere/adapter/AbsActivitiesAdapter.java index 0247b3941..eb08fc793 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/adapter/AbsActivitiesAdapter.java +++ b/twidere/src/main/java/org/mariotaku/twidere/adapter/AbsActivitiesAdapter.java @@ -37,6 +37,7 @@ import org.mariotaku.twidere.adapter.iface.IActivitiesAdapter; import org.mariotaku.twidere.app.TwidereApplication; import org.mariotaku.twidere.fragment.support.UserFragment; import org.mariotaku.twidere.model.ParcelableActivity; +import org.mariotaku.twidere.model.ParcelableMedia; import org.mariotaku.twidere.model.ParcelableStatus; import org.mariotaku.twidere.util.AsyncTwitterWrapper; import org.mariotaku.twidere.util.ImageLoadingHandler; @@ -255,6 +256,13 @@ public abstract class AbsActivitiesAdapter extends Adapter imp } } + + @Override + public void onMediaClick(StatusViewHolder holder, ParcelableMedia media, int position) { + + } + + @Override public void onItemActionClick(ViewHolder holder, int id, int position) { diff --git a/twidere/src/main/java/org/mariotaku/twidere/adapter/AbsStatusesAdapter.java b/twidere/src/main/java/org/mariotaku/twidere/adapter/AbsStatusesAdapter.java index 6722a0dcc..b6c86b5f1 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/adapter/AbsStatusesAdapter.java +++ b/twidere/src/main/java/org/mariotaku/twidere/adapter/AbsStatusesAdapter.java @@ -16,6 +16,7 @@ import org.mariotaku.twidere.R; import org.mariotaku.twidere.adapter.iface.IStatusesAdapter; import org.mariotaku.twidere.app.TwidereApplication; import org.mariotaku.twidere.fragment.support.UserFragment; +import org.mariotaku.twidere.model.ParcelableMedia; import org.mariotaku.twidere.model.ParcelableStatus; import org.mariotaku.twidere.util.AsyncTwitterWrapper; import org.mariotaku.twidere.util.ImageLoadingHandler; @@ -245,6 +246,14 @@ public abstract class AbsStatusesAdapter extends Adapter implemen } } + + @Override + public void onMediaClick(StatusViewHolder holder, ParcelableMedia media, int position) { + if (mStatusAdapterListener != null) { + mStatusAdapterListener.onMediaClick(holder, media, position); + } + } + public void setListener(StatusAdapterListener listener) { mStatusAdapterListener = listener; } @@ -267,6 +276,8 @@ public abstract class AbsStatusesAdapter extends Adapter implemen public static interface StatusAdapterListener { void onGapClick(GapViewHolder holder, int position); + void onMediaClick(StatusViewHolder holder, ParcelableMedia media, int position); + void onStatusActionClick(StatusViewHolder holder, int id, int position); void onStatusClick(StatusViewHolder holder, int position); diff --git a/twidere/src/main/java/org/mariotaku/twidere/adapter/CursorStatusesAdapter.java b/twidere/src/main/java/org/mariotaku/twidere/adapter/CursorStatusesAdapter.java index eb30fad4e..61ef9b5ca 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/adapter/CursorStatusesAdapter.java +++ b/twidere/src/main/java/org/mariotaku/twidere/adapter/CursorStatusesAdapter.java @@ -23,6 +23,7 @@ import android.content.Context; import android.database.Cursor; import android.support.v7.widget.RecyclerView; +import org.mariotaku.twidere.model.ParcelableMedia; import org.mariotaku.twidere.model.ParcelableStatus; import org.mariotaku.twidere.model.ParcelableStatus.CursorIndices; import org.mariotaku.twidere.view.holder.StatusViewHolder; diff --git a/twidere/src/main/java/org/mariotaku/twidere/adapter/MessageConversationAdapter.java b/twidere/src/main/java/org/mariotaku/twidere/adapter/MessageConversationAdapter.java index f4fbfe99c..5c447a439 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/adapter/MessageConversationAdapter.java +++ b/twidere/src/main/java/org/mariotaku/twidere/adapter/MessageConversationAdapter.java @@ -36,8 +36,8 @@ import org.mariotaku.twidere.app.TwidereApplication; import org.mariotaku.twidere.model.ParcelableDirectMessage; import org.mariotaku.twidere.model.ParcelableDirectMessage.CursorIndices; import org.mariotaku.twidere.util.DirectMessageOnLinkClickHandler; -import org.mariotaku.twidere.util.MediaLoaderWrapper; import org.mariotaku.twidere.util.ImageLoadingHandler; +import org.mariotaku.twidere.util.MediaLoaderWrapper; import org.mariotaku.twidere.util.MultiSelectManager; import org.mariotaku.twidere.util.ThemeUtils; import org.mariotaku.twidere.util.TwidereLinkify; @@ -172,7 +172,7 @@ public class MessageConversationAdapter extends Adapter case R.id.media_preview: { final ParcelableDirectMessage message = getDirectMessage(position); if (message == null || message.media == null) return; - openMedia(mContext, message.account_id, false, message, null, message.media); + openMedia(mContext, message, null); } } } diff --git a/twidere/src/main/java/org/mariotaku/twidere/adapter/ParcelableActivitiesAdapter.java b/twidere/src/main/java/org/mariotaku/twidere/adapter/ParcelableActivitiesAdapter.java index 98722f17d..87d8b4a37 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/adapter/ParcelableActivitiesAdapter.java +++ b/twidere/src/main/java/org/mariotaku/twidere/adapter/ParcelableActivitiesAdapter.java @@ -24,7 +24,9 @@ import android.support.v7.widget.RecyclerView.ViewHolder; import android.view.View; import org.mariotaku.twidere.model.ParcelableActivity; +import org.mariotaku.twidere.model.ParcelableMedia; import org.mariotaku.twidere.view.holder.ActivityTitleSummaryViewHolder; +import org.mariotaku.twidere.view.holder.StatusViewHolder; import java.util.List; diff --git a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/AbsStatusesFragment.java b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/AbsStatusesFragment.java index 6dc7a8423..affbd69fb 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/AbsStatusesFragment.java +++ b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/AbsStatusesFragment.java @@ -38,6 +38,7 @@ import org.mariotaku.twidere.adapter.decorator.DividerItemDecoration; import org.mariotaku.twidere.app.TwidereApplication; import org.mariotaku.twidere.fragment.iface.RefreshScrollTopInterface; import org.mariotaku.twidere.loader.iface.IExtendedLoader; +import org.mariotaku.twidere.model.ParcelableMedia; import org.mariotaku.twidere.model.ParcelableStatus; import org.mariotaku.twidere.util.AsyncTwitterWrapper; import org.mariotaku.twidere.util.ColorUtils; @@ -446,6 +447,13 @@ public abstract class AbsStatusesFragment extends BaseSupportFragment impl mSwipeRefreshLayout.setVisibility(shown ? View.VISIBLE : View.GONE); } + @Override + public void onMediaClick(StatusViewHolder holder, ParcelableMedia media, int position) { + final ParcelableStatus status = mAdapter.getStatus(position); + if (status == null) return; + Utils.openMedia(getActivity(), status, media); + } + private void updateRefreshProgressOffset() { if (mSystemWindowsInsets.top == 0 || mSwipeRefreshLayout == null || isRefreshing()) return; final float density = getResources().getDisplayMetrics().density; diff --git a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/StatusFragment.java b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/StatusFragment.java index c869b3182..aa43c2a00 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/StatusFragment.java +++ b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/StatusFragment.java @@ -108,18 +108,15 @@ import twitter4j.TwitterException; import static android.text.TextUtils.isEmpty; import static org.mariotaku.twidere.util.UserColorNameUtils.clearUserColor; -import static org.mariotaku.twidere.util.UserColorNameUtils.getUserColor; import static org.mariotaku.twidere.util.UserColorNameUtils.getUserNickname; import static org.mariotaku.twidere.util.UserColorNameUtils.setUserColor; import static org.mariotaku.twidere.util.Utils.findStatus; import static org.mariotaku.twidere.util.Utils.formatToLongTimeString; import static org.mariotaku.twidere.util.Utils.getLocalizedNumber; import static org.mariotaku.twidere.util.Utils.getUserTypeIconRes; -import static org.mariotaku.twidere.util.Utils.isMyRetweet; import static org.mariotaku.twidere.util.Utils.openStatus; import static org.mariotaku.twidere.util.Utils.openUserProfile; import static org.mariotaku.twidere.util.Utils.showErrorMessage; -import static org.mariotaku.twidere.util.Utils.showOkMessage; /** * Created by mariotaku on 14/12/5. @@ -248,6 +245,13 @@ public class StatusFragment extends BaseSupportFragment } + @Override + public void onMediaClick(StatusViewHolder holder, ParcelableMedia media, int position) { + final ParcelableStatus status = mStatusAdapter.getStatus(position); + if (status == null) return; + Utils.openMedia(getActivity(), status, media); + } + @Override public void onStatusActionClick(StatusViewHolder holder, int id, int position) { final ParcelableStatus status = mStatusAdapter.getStatus(position); @@ -579,6 +583,13 @@ public class StatusFragment extends BaseSupportFragment } } + @Override + public void onMediaClick(StatusViewHolder holder, ParcelableMedia media, int position) { + if (mStatusAdapterListener != null) { + mStatusAdapterListener.onMediaClick(holder, media, position); + } + } + @Override public void onUserProfileClick(StatusViewHolder holder, int position) { final Context context = getContext(); diff --git a/twidere/src/main/java/org/mariotaku/twidere/util/StatusLinkClickHandler.java b/twidere/src/main/java/org/mariotaku/twidere/util/StatusLinkClickHandler.java index 6a2ecf8cd..da8e924aa 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/util/StatusLinkClickHandler.java +++ b/twidere/src/main/java/org/mariotaku/twidere/util/StatusLinkClickHandler.java @@ -35,7 +35,7 @@ public class StatusLinkClickHandler extends OnLinkClickHandler { protected void openMedia(long account_id, boolean sensitive, String link, int start, int end) { final ParcelableStatus status = mStatus; final ParcelableMedia current = findByLink(status.media, link); - Utils.openMedia(context, account_id, sensitive, status, current, status.media); + Utils.openMedia(context, status, current); } private ParcelableMedia findByLink(ParcelableMedia[] media, String link) { diff --git a/twidere/src/main/java/org/mariotaku/twidere/util/Utils.java b/twidere/src/main/java/org/mariotaku/twidere/util/Utils.java index 989cf8f4a..58e850edb 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/util/Utils.java +++ b/twidere/src/main/java/org/mariotaku/twidere/util/Utils.java @@ -2885,16 +2885,12 @@ public final class Utils implements Constants, TwitterConstants { activity.startActivity(intent); } - public static void openMedia(final Context context, final long accountId, final boolean isPossiblySensitive, - final ParcelableDirectMessage message, final ParcelableMedia current, - final ParcelableMedia[] media) { - openMedia(context, accountId, isPossiblySensitive, null, message, current, media); + public static void openMedia(final Context context, final ParcelableDirectMessage message, final ParcelableMedia current) { + openMedia(context, message.account_id, false, null, message, current, message.media); } - public static void openMedia(final Context context, final long accountId, final boolean isPossiblySensitive, - final ParcelableStatus status, final ParcelableMedia current, - final ParcelableMedia[] media) { - openMedia(context, accountId, isPossiblySensitive, status, null, current, media); + public static void openMedia(final Context context, final ParcelableStatus status, final ParcelableMedia current) { + openMedia(context, status.account_id, status.is_possibly_sensitive, status, null, current, status.media); } public static void openMedia(final Context context, final long accountId, final boolean isPossiblySensitive, diff --git a/twidere/src/main/java/org/mariotaku/twidere/view/CardMediaContainer.java b/twidere/src/main/java/org/mariotaku/twidere/view/CardMediaContainer.java index 61845ed9c..0bcc60025 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/view/CardMediaContainer.java +++ b/twidere/src/main/java/org/mariotaku/twidere/view/CardMediaContainer.java @@ -33,8 +33,8 @@ import android.widget.TextView; import org.mariotaku.twidere.Constants; import org.mariotaku.twidere.R; import org.mariotaku.twidere.model.ParcelableMedia; -import org.mariotaku.twidere.util.MediaLoaderWrapper; import org.mariotaku.twidere.util.ImageLoadingHandler; +import org.mariotaku.twidere.util.MediaLoaderWrapper; import org.mariotaku.twidere.util.Utils.OnMediaClickListener; /** @@ -113,6 +113,7 @@ public class CardMediaContainer extends ViewGroup implements Constants { if (i < k) { final ParcelableMedia media = mediaArray[i]; loader.displayPreviewImage(imageView, media.page_url, loadingHandler); + child.setTag(media); child.setVisibility(VISIBLE); if (i == j - 1) { final TextView moreIndicator = (TextView) child.findViewById(R.id.more_media); diff --git a/twidere/src/main/java/org/mariotaku/twidere/view/holder/MessageConversationViewHolder.java b/twidere/src/main/java/org/mariotaku/twidere/view/holder/MessageConversationViewHolder.java index 4971a0d14..edb5bb117 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/view/holder/MessageConversationViewHolder.java +++ b/twidere/src/main/java/org/mariotaku/twidere/view/holder/MessageConversationViewHolder.java @@ -38,9 +38,10 @@ import org.mariotaku.twidere.util.MediaLoaderWrapper; import org.mariotaku.twidere.util.SimpleValueSerializer; import org.mariotaku.twidere.util.TwidereLinkify; import org.mariotaku.twidere.util.Utils; +import org.mariotaku.twidere.util.Utils.OnMediaClickListener; import org.mariotaku.twidere.view.CardMediaContainer; -public class MessageConversationViewHolder extends ViewHolder { +public class MessageConversationViewHolder extends ViewHolder implements OnMediaClickListener { public final CardMediaContainer mediaContainer; public final TextView text, time; @@ -83,7 +84,12 @@ public class MessageConversationViewHolder extends ViewHolder { text.setMovementMethod(null); time.setText(Utils.formatToLongTimeString(context, timestamp)); mediaContainer.setVisibility(media != null && media.length > 0 ? View.VISIBLE : View.GONE); - mediaContainer.displayMedia(media, loader, accountId, null, null); + mediaContainer.displayMedia(media, loader, accountId, this, null); + } + + @Override + public void onMediaClick(View view, ParcelableMedia media, long accountId) { + Utils.openMedia(adapter.getContext(), adapter.getDirectMessage(getAdapterPosition()), media); } public void setMessageColor(int color) { diff --git a/twidere/src/main/java/org/mariotaku/twidere/view/holder/StatusViewHolder.java b/twidere/src/main/java/org/mariotaku/twidere/view/holder/StatusViewHolder.java index 4ba80b09d..ba19023bb 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/view/holder/StatusViewHolder.java +++ b/twidere/src/main/java/org/mariotaku/twidere/view/holder/StatusViewHolder.java @@ -27,6 +27,7 @@ import org.mariotaku.twidere.util.SimpleValueSerializer; import org.mariotaku.twidere.util.TwitterCardUtils; import org.mariotaku.twidere.util.UserColorNameUtils; import org.mariotaku.twidere.util.Utils; +import org.mariotaku.twidere.util.Utils.OnMediaClickListener; import org.mariotaku.twidere.view.CardMediaContainer; import org.mariotaku.twidere.view.ShapedImageView; import org.mariotaku.twidere.view.ShortTimeView; @@ -44,7 +45,8 @@ import static org.mariotaku.twidere.util.Utils.getUserTypeIconRes; *

* Created by mariotaku on 14/11/19. */ -public class StatusViewHolder extends RecyclerView.ViewHolder implements Constants, OnClickListener { +public class StatusViewHolder extends RecyclerView.ViewHolder implements Constants, OnClickListener, + OnMediaClickListener { private final IStatusesAdapter adapter; @@ -172,7 +174,7 @@ public class StatusViewHolder extends RecyclerView.ViewHolder implements Constan } else { mediaPreviewContainer.setVisibility(View.GONE); } - mediaPreviewContainer.displayMedia(media, loader, status.account_id, null, handler); + mediaPreviewContainer.displayMedia(media, loader, status.account_id, this, handler); } else { mediaPreviewContainer.setVisibility(View.GONE); } @@ -312,7 +314,7 @@ public class StatusViewHolder extends RecyclerView.ViewHolder implements Constan if (adapter.isMediaPreviewEnabled()) { mediaPreviewContainer.setStyle(adapter.getMediaPreviewStyle()); mediaPreviewContainer.setVisibility(media != null && media.length > 0 ? View.VISIBLE : View.GONE); - mediaPreviewContainer.displayMedia(media, loader, account_id, null, + mediaPreviewContainer.displayMedia(media, loader, account_id, this, adapter.getImageLoadingHandler()); } else { mediaPreviewContainer.setVisibility(View.GONE); @@ -396,6 +398,13 @@ public class StatusViewHolder extends RecyclerView.ViewHolder implements Constan } } + @Override + public void onMediaClick(View view, ParcelableMedia media, long accountId) { + if (statusClickListener == null) return; + final int position = getAdapterPosition(); + statusClickListener.onMediaClick(this, media, position); + } + public void setOnClickListeners() { setStatusClickListener(adapter); } @@ -407,7 +416,6 @@ public class StatusViewHolder extends RecyclerView.ViewHolder implements Constan itemView.setOnClickListener(this); profileImageView.setOnClickListener(this); - mediaPreviewContainer.setOnClickListener(this); replyCountView.setOnClickListener(this); retweetCountView.setOnClickListener(this); favoriteCountView.setOnClickListener(this); @@ -465,6 +473,8 @@ public class StatusViewHolder extends RecyclerView.ViewHolder implements Constan void onStatusClick(StatusViewHolder holder, int position); + void onMediaClick(StatusViewHolder holder, ParcelableMedia media, int position); + void onUserProfileClick(StatusViewHolder holder, int position); } }