fixed status action item click

This commit is contained in:
Mariotaku Lee 2016-03-30 15:07:22 +08:00
parent b1d15ff14f
commit 1a2a7cad0d
4 changed files with 129 additions and 68 deletions

View File

@ -26,7 +26,7 @@ import android.graphics.Rect;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.LoaderManager.LoaderCallbacks;
import android.support.v4.content.Loader;
import android.support.v7.widget.LinearLayoutManager;
@ -47,6 +47,7 @@ import org.mariotaku.twidere.R;
import org.mariotaku.twidere.adapter.ParcelableStatusesAdapter;
import org.mariotaku.twidere.adapter.iface.ILoadMoreSupportAdapter.IndicatorPosition;
import org.mariotaku.twidere.annotation.ReadPositionTag;
import org.mariotaku.twidere.constant.IntentConstants;
import org.mariotaku.twidere.graphic.like.LikeAnimationDrawable;
import org.mariotaku.twidere.loader.iface.IExtendedLoader;
import org.mariotaku.twidere.model.BaseRefreshTaskParam;
@ -349,6 +350,47 @@ public abstract class AbsStatusesFragment extends AbsContentListRecyclerViewFrag
// END HotMobi
}
@Override
public void onItemActionClick(RecyclerView.ViewHolder holder, int id, int position) {
final Context context = getContext();
if (context == null) return;
final ParcelableStatusesAdapter adapter = getAdapter();
final ParcelableStatus status = adapter.getStatus(position);
if (status == null) return;
handleStatusActionClick(context, getFragmentManager(), mTwitterWrapper,
(StatusViewHolder) holder, status, id);
}
public static void handleStatusActionClick(Context context, FragmentManager fm,
AsyncTwitterWrapper twitter, StatusViewHolder holder,
ParcelableStatus status, int id) {
if (status == null) return;
switch (id) {
case R.id.reply: {
final Intent intent = new Intent(IntentConstants.INTENT_ACTION_REPLY);
intent.setPackage(context.getPackageName());
intent.putExtra(IntentConstants.EXTRA_STATUS, status);
context.startActivity(intent);
break;
}
case R.id.retweet: {
RetweetQuoteDialogFragment.show(fm, status);
break;
}
case R.id.favorite: {
if (twitter == null) return;
if (status.is_favorite) {
twitter.destroyFavoriteAsync(status.account_key, status.id);
} else {
holder.playLikeAnimation(new DefaultOnLikedListener(twitter,
status));
}
break;
}
}
}
protected void saveReadPosition() {
final LinearLayoutManager layoutManager = getLayoutManager();
if (layoutManager != null) {
@ -363,38 +405,6 @@ public abstract class AbsStatusesFragment extends AbsContentListRecyclerViewFrag
@TimelineType
protected abstract String getTimelineType();
@Override
public void onItemActionClick(RecyclerView.ViewHolder holder, int id, int position) {
final ParcelableStatusesAdapter adapter = getAdapter();
final ParcelableStatus status = adapter.getStatus(position);
if (status == null) return;
final FragmentActivity activity = getActivity();
switch (id) {
case R.id.reply: {
final Intent intent = new Intent(INTENT_ACTION_REPLY);
intent.setPackage(activity.getPackageName());
intent.putExtra(EXTRA_STATUS, status);
activity.startActivity(intent);
break;
}
case R.id.retweet: {
RetweetQuoteDialogFragment.show(getFragmentManager(), status);
break;
}
case R.id.favorite: {
final AsyncTwitterWrapper twitter = mTwitterWrapper;
if (twitter == null) return;
if (status.is_favorite) {
twitter.destroyFavoriteAsync(status.account_key, status.id);
} else {
((StatusViewHolder) holder).playLikeAnimation(new DefaultOnLikedListener(twitter,
status));
}
break;
}
}
}
@Override
public void onStatusClick(IStatusViewHolder holder, int position) {
final ParcelableStatusesAdapter adapter = getAdapter();

View File

@ -1,6 +1,7 @@
package org.mariotaku.twidere.fragment;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Parcelable;
import android.support.annotation.NonNull;
@ -9,7 +10,12 @@ import android.support.v4.app.LoaderManager.LoaderCallbacks;
import android.support.v4.content.AsyncTaskLoader;
import android.support.v4.content.Loader;
import android.support.v7.widget.RecyclerView;
import android.view.ContextMenu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import org.mariotaku.twidere.R;
import org.mariotaku.twidere.adapter.DummyItemAdapter;
import org.mariotaku.twidere.adapter.VariousItemsAdapter;
import org.mariotaku.twidere.adapter.decorator.DividerItemDecoration;
@ -17,6 +23,11 @@ import org.mariotaku.twidere.adapter.iface.IUsersAdapter;
import org.mariotaku.twidere.model.ParcelableStatus;
import org.mariotaku.twidere.model.ParcelableUser;
import org.mariotaku.twidere.util.IntentUtils;
import org.mariotaku.twidere.util.LinkCreator;
import org.mariotaku.twidere.util.MenuUtils;
import org.mariotaku.twidere.util.Utils;
import org.mariotaku.twidere.view.ExtendedRecyclerView;
import org.mariotaku.twidere.view.holder.StatusViewHolder;
import org.mariotaku.twidere.view.holder.UserViewHolder;
import org.mariotaku.twidere.view.holder.iface.IStatusViewHolder;
@ -30,6 +41,7 @@ public class ItemsListFragment extends AbsContentListRecyclerViewFragment<Variou
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
registerForContextMenu(getRecyclerView());
getLoaderManager().initLoader(0, null, this);
setRefreshEnabled(false);
showContent();
@ -47,6 +59,24 @@ public class ItemsListFragment extends AbsContentListRecyclerViewFragment<Variou
if (status == null) return;
IntentUtils.openStatus(getContext(), status, null);
}
@Override
public void onItemActionClick(RecyclerView.ViewHolder holder, int id, int position) {
final Context context = getContext();
if (context == null) return;
final ParcelableStatus status = dummyItemAdapter.getStatus(position);
if (status == null) return;
AbsStatusesFragment.handleStatusActionClick(context, getFragmentManager(),
mTwitterWrapper, (StatusViewHolder) holder, status, id);
}
@Override
public void onItemMenuClick(RecyclerView.ViewHolder holder, View menuView, int position) {
if (getActivity() == null) return;
final View view = getLayoutManager().findViewByPosition(position);
if (view == null) return;
getRecyclerView().showContextMenuForChild(view);
}
});
dummyItemAdapter.setUserClickListener(new IUsersAdapter.SimpleUserClickListener() {
@Override
@ -120,6 +150,53 @@ public class ItemsListFragment extends AbsContentListRecyclerViewFragment<Variou
return false;
}
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
if (!getUserVisibleHint() || menuInfo == null) return;
final MenuInflater inflater = new MenuInflater(getContext());
final ExtendedRecyclerView.ContextMenuInfo contextMenuInfo =
(ExtendedRecyclerView.ContextMenuInfo) menuInfo;
final int position = contextMenuInfo.getPosition();
final VariousItemsAdapter adapter = getAdapter();
switch (adapter.getItemViewType(position)) {
case VariousItemsAdapter.VIEW_TYPE_STATUS: {
final DummyItemAdapter dummyAdapter = getAdapter().getDummyAdapter();
final ParcelableStatus status = dummyAdapter.getStatus(contextMenuInfo.getPosition());
if (status == null) break;
inflater.inflate(R.menu.action_status, menu);
MenuUtils.setupForStatus(getContext(), mPreferences, menu, status,
mTwitterWrapper);
break;
}
}
}
@Override
public boolean onContextItemSelected(MenuItem item) {
if (!getUserVisibleHint()) return false;
final ExtendedRecyclerView.ContextMenuInfo contextMenuInfo =
(ExtendedRecyclerView.ContextMenuInfo) item.getMenuInfo();
final int position = contextMenuInfo.getPosition();
final VariousItemsAdapter adapter = getAdapter();
switch (adapter.getItemViewType(position)) {
case VariousItemsAdapter.VIEW_TYPE_STATUS: {
final DummyItemAdapter dummyAdapter = adapter.getDummyAdapter();
final ParcelableStatus status = dummyAdapter.getStatus(position);
if (status == null) return false;
if (item.getItemId() == R.id.share) {
final Intent shareIntent = Utils.createStatusShareIntent(getActivity(), status);
final Intent chooser = Intent.createChooser(shareIntent, getString(R.string.share_status));
Utils.addCopyLinkIntent(getContext(), chooser, LinkCreator.getStatusWebLink(status));
startActivity(chooser);
return true;
}
return MenuUtils.handleStatusClick(getActivity(), this, getFragmentManager(),
mUserColorNameManager, mTwitterWrapper, status, item);
}
}
return false;
}
public static class ItemsLoader extends AsyncTaskLoader<List<?>> {
private final Bundle mArguments;

View File

@ -98,8 +98,6 @@ import org.mariotaku.twidere.api.twitter.TwitterException;
import org.mariotaku.twidere.api.twitter.model.Paging;
import org.mariotaku.twidere.api.twitter.model.Status;
import org.mariotaku.twidere.api.twitter.model.TranslationResult;
import org.mariotaku.twidere.constant.IntentConstants;
import org.mariotaku.twidere.fragment.AbsStatusesFragment.DefaultOnLikedListener;
import org.mariotaku.twidere.loader.ConversationLoader;
import org.mariotaku.twidere.loader.ParcelableStatusLoader;
import org.mariotaku.twidere.menu.support.FavoriteItemProvider;
@ -429,32 +427,8 @@ public class StatusFragment extends BaseSupportFragment implements LoaderCallbac
@Override
public void onItemActionClick(ViewHolder holder, int id, int position) {
final ParcelableStatus status = mStatusAdapter.getStatus(position);
if (status == null) return;
switch (id) {
case R.id.reply: {
final Context context = getActivity();
final Intent intent = new Intent(IntentConstants.INTENT_ACTION_REPLY);
intent.setPackage(context.getPackageName());
intent.putExtra(IntentConstants.EXTRA_STATUS, status);
context.startActivity(intent);
break;
}
case R.id.retweet: {
RetweetQuoteDialogFragment.show(getFragmentManager(), status);
break;
}
case R.id.favorite: {
final AsyncTwitterWrapper twitter = mTwitterWrapper;
if (twitter == null) return;
if (status.is_favorite) {
twitter.destroyFavoriteAsync(status.account_key, status.id);
} else {
((StatusViewHolder) holder).playLikeAnimation(new DefaultOnLikedListener(twitter,
status));
}
break;
}
}
AbsStatusesFragment.handleStatusActionClick(getContext(), getFragmentManager(), mTwitterWrapper,
(StatusViewHolder) holder, status, id);
}
@Override

View File

@ -167,11 +167,6 @@ public class UserMediaTimelineFragment extends AbsContentRecyclerViewFragment<St
}
@Override
public void onItemActionClick(RecyclerView.ViewHolder holder, int id, int position) {
}
@Override
public void onStatusClick(IStatusViewHolder holder, int position) {
IntentUtils.openStatus(getContext(), getAdapter().getStatus(position), null);
@ -183,12 +178,17 @@ public class UserMediaTimelineFragment extends AbsContentRecyclerViewFragment<St
}
@Override
public void onItemMenuClick(RecyclerView.ViewHolder holder, View menuView, int position) {
public void onUserProfileClick(IStatusViewHolder holder, int position) {
}
@Override
public void onUserProfileClick(IStatusViewHolder holder, int position) {
public void onItemActionClick(RecyclerView.ViewHolder holder, int id, int position) {
}
@Override
public void onItemMenuClick(RecyclerView.ViewHolder holder, View menuView, int position) {
}
}