From 167e143f952a2633cef88ae721f8fffdef352b9c Mon Sep 17 00:00:00 2001 From: Mariotaku Lee Date: Mon, 26 Oct 2015 17:00:20 +0800 Subject: [PATCH] media tweets is clickable --- ...taggeredGridParcelableStatusesAdapter.java | 32 ++++++++++--- .../support/UserMediaTimelineFragment.java | 48 +++++++++++++++++-- .../view/holder/iface/IStatusViewHolder.java | 4 -- .../res/layout/adapter_item_media_status.xml | 1 + 4 files changed, 71 insertions(+), 14 deletions(-) diff --git a/twidere/src/main/java/org/mariotaku/twidere/adapter/StaggeredGridParcelableStatusesAdapter.java b/twidere/src/main/java/org/mariotaku/twidere/adapter/StaggeredGridParcelableStatusesAdapter.java index 95a379dc8..f14518dab 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/adapter/StaggeredGridParcelableStatusesAdapter.java +++ b/twidere/src/main/java/org/mariotaku/twidere/adapter/StaggeredGridParcelableStatusesAdapter.java @@ -57,10 +57,14 @@ public class StaggeredGridParcelableStatusesAdapter extends AbsParcelableStatuse @Override protected IStatusViewHolder onCreateStatusViewHolder(ViewGroup parent, boolean compact) { final View view = getInflater().inflate(R.layout.adapter_item_media_status, parent, false); - return new MediaTimelineViewHolder(this, view); + final MediaStatusViewHolder holder = new MediaStatusViewHolder(this, view); + holder.setOnClickListeners(); + holder.setupViewOptions(); + return holder; } - public static class MediaTimelineViewHolder extends RecyclerView.ViewHolder implements IStatusViewHolder { + public static class MediaStatusViewHolder extends RecyclerView.ViewHolder + implements IStatusViewHolder, View.OnClickListener, View.OnLongClickListener { private final SimpleAspectRatioSource aspectRatioSource = new SimpleAspectRatioSource(); private final AspectLockedFrameLayout mediaImageContainer; @@ -68,8 +72,9 @@ public class StaggeredGridParcelableStatusesAdapter extends AbsParcelableStatuse private final ImageView mediaProfileImageView; private final TextView mediaTextView; private final IStatusesAdapter adapter; + private StatusClickListener listener; - public MediaTimelineViewHolder(IStatusesAdapter adapter, View itemView) { + public MediaStatusViewHolder(IStatusesAdapter adapter, View itemView) { super(itemView); this.adapter = adapter; mediaImageContainer = (AspectLockedFrameLayout) itemView.findViewById(R.id.media_image_container); @@ -117,22 +122,27 @@ public class StaggeredGridParcelableStatusesAdapter extends AbsParcelableStatuse @Override public void onClick(View v) { - + if (listener == null) return; + switch (v.getId()) { + case R.id.item_content: { + listener.onStatusClick(this, getLayoutPosition()); + break; + } + } } - @Override public boolean onLongClick(View v) { return false; } @Override public void onMediaClick(View view, ParcelableMedia media, long accountId) { - } @Override public void setStatusClickListener(StatusClickListener listener) { - + this.listener = listener; + itemView.findViewById(R.id.item_content).setOnClickListener(this); } @Override @@ -140,6 +150,14 @@ public class StaggeredGridParcelableStatusesAdapter extends AbsParcelableStatuse } + public void setOnClickListeners() { + setStatusClickListener(adapter); + } + + public void setupViewOptions() { + setTextSize(adapter.getTextSize()); + } + private static class SimpleAspectRatioSource implements AspectLockedFrameLayout.AspectRatioSource { private int width, height; diff --git a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/UserMediaTimelineFragment.java b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/UserMediaTimelineFragment.java index ffb8c671a..e79829298 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/UserMediaTimelineFragment.java +++ b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/UserMediaTimelineFragment.java @@ -12,12 +12,17 @@ import android.view.View; import android.view.ViewGroup; import org.mariotaku.twidere.R; +import org.mariotaku.twidere.adapter.AbsStatusesAdapter; import org.mariotaku.twidere.adapter.StaggeredGridParcelableStatusesAdapter; import org.mariotaku.twidere.adapter.iface.IStatusesAdapter; import org.mariotaku.twidere.loader.iface.IExtendedLoader; import org.mariotaku.twidere.loader.support.MediaTimelineLoader; +import org.mariotaku.twidere.model.ParcelableMedia; import org.mariotaku.twidere.model.ParcelableStatus; +import org.mariotaku.twidere.util.Utils; import org.mariotaku.twidere.view.HeaderDrawerLayout.DrawerCallback; +import org.mariotaku.twidere.view.holder.GapViewHolder; +import org.mariotaku.twidere.view.holder.iface.IStatusViewHolder; import java.util.List; @@ -25,7 +30,7 @@ import java.util.List; * Created by mariotaku on 14/11/5. */ public class UserMediaTimelineFragment extends AbsContentRecyclerViewFragment - implements LoaderCallbacks>, DrawerCallback { + implements LoaderCallbacks>, DrawerCallback, AbsStatusesAdapter.StatusAdapterListener { @Override @@ -36,14 +41,16 @@ public class UserMediaTimelineFragment extends AbsContentRecyclerViewFragment loader = getLoaderManager().getLoader(0); + return loader != null && loader.isStarted(); } @Override public void onActivityCreated(@Nullable Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); + final AbsStatusesAdapter> adapter = getAdapter(); + adapter.setListener(this); final Bundle loaderArgs = new Bundle(getArguments()); loaderArgs.putBoolean(EXTRA_FROM_USER, true); getLoaderManager().initLoader(0, loaderArgs, this); @@ -145,4 +152,39 @@ public class UserMediaTimelineFragment extends AbsContentRecyclerViewFragment