2014-12-03 11:27:11 +01:00
|
|
|
package org.mariotaku.twidere.fragment.support;
|
|
|
|
|
2015-03-12 10:43:28 +01:00
|
|
|
import android.app.Activity;
|
2014-12-03 11:27:11 +01:00
|
|
|
import android.content.Context;
|
2014-12-04 15:31:29 +01:00
|
|
|
import android.content.Intent;
|
2014-12-03 11:27:11 +01:00
|
|
|
import android.content.SharedPreferences;
|
|
|
|
import android.graphics.Rect;
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.support.annotation.Nullable;
|
2015-03-08 11:35:05 +01:00
|
|
|
import android.support.v4.app.FragmentActivity;
|
2014-12-03 11:27:11 +01:00
|
|
|
import android.support.v4.app.LoaderManager.LoaderCallbacks;
|
|
|
|
import android.support.v4.content.Loader;
|
|
|
|
import android.support.v4.widget.SwipeRefreshLayout;
|
|
|
|
import android.support.v4.widget.SwipeRefreshLayout.OnRefreshListener;
|
2015-03-24 16:40:47 +01:00
|
|
|
import android.support.v7.widget.FixedLinearLayoutManager;
|
2014-12-03 11:27:11 +01:00
|
|
|
import android.support.v7.widget.LinearLayoutManager;
|
2015-01-17 19:58:29 +01:00
|
|
|
import android.support.v7.widget.PopupMenu;
|
2014-12-03 11:27:11 +01:00
|
|
|
import android.support.v7.widget.RecyclerView;
|
2015-03-24 16:40:47 +01:00
|
|
|
import android.support.v7.widget.RecyclerView.OnScrollListener;
|
2015-01-17 19:58:29 +01:00
|
|
|
import android.view.Gravity;
|
2014-12-03 11:27:11 +01:00
|
|
|
import android.view.LayoutInflater;
|
|
|
|
import android.view.View;
|
2015-03-08 16:44:47 +01:00
|
|
|
import android.view.ViewConfiguration;
|
2014-12-03 11:27:11 +01:00
|
|
|
import android.view.ViewGroup;
|
|
|
|
|
2014-12-10 15:41:55 +01:00
|
|
|
import com.squareup.otto.Bus;
|
2014-12-12 14:53:18 +01:00
|
|
|
import com.squareup.otto.Subscribe;
|
2014-12-10 15:41:55 +01:00
|
|
|
|
2014-12-03 11:27:11 +01:00
|
|
|
import org.mariotaku.twidere.R;
|
2015-03-12 10:43:28 +01:00
|
|
|
import org.mariotaku.twidere.activity.iface.IControlBarActivity;
|
|
|
|
import org.mariotaku.twidere.activity.iface.IControlBarActivity.ControlBarOffsetListener;
|
2015-03-12 21:32:54 +01:00
|
|
|
import org.mariotaku.twidere.activity.support.BaseActionBarActivity;
|
2014-12-03 11:27:11 +01:00
|
|
|
import org.mariotaku.twidere.adapter.AbsStatusesAdapter;
|
2014-12-08 16:16:33 +01:00
|
|
|
import org.mariotaku.twidere.adapter.AbsStatusesAdapter.StatusAdapterListener;
|
2014-12-03 11:27:11 +01:00
|
|
|
import org.mariotaku.twidere.adapter.decorator.DividerItemDecoration;
|
2014-12-10 15:41:55 +01:00
|
|
|
import org.mariotaku.twidere.app.TwidereApplication;
|
2014-12-04 15:31:29 +01:00
|
|
|
import org.mariotaku.twidere.fragment.iface.RefreshScrollTopInterface;
|
2015-01-10 16:17:02 +01:00
|
|
|
import org.mariotaku.twidere.loader.iface.IExtendedLoader;
|
2014-12-04 15:31:29 +01:00
|
|
|
import org.mariotaku.twidere.model.ParcelableStatus;
|
|
|
|
import org.mariotaku.twidere.util.AsyncTwitterWrapper;
|
2015-03-08 16:44:47 +01:00
|
|
|
import org.mariotaku.twidere.util.ColorUtils;
|
2015-03-15 15:40:45 +01:00
|
|
|
import org.mariotaku.twidere.util.ContentListScrollListener;
|
2015-03-24 16:40:47 +01:00
|
|
|
import org.mariotaku.twidere.util.ContentListScrollListener.ContentListSupport;
|
|
|
|
import org.mariotaku.twidere.util.PositionManager;
|
2014-12-03 11:27:11 +01:00
|
|
|
import org.mariotaku.twidere.util.SimpleDrawerCallback;
|
|
|
|
import org.mariotaku.twidere.util.ThemeUtils;
|
|
|
|
import org.mariotaku.twidere.util.Utils;
|
2014-12-12 14:53:18 +01:00
|
|
|
import org.mariotaku.twidere.util.message.StatusListChangedEvent;
|
2014-12-03 11:27:11 +01:00
|
|
|
import org.mariotaku.twidere.view.HeaderDrawerLayout.DrawerCallback;
|
2014-12-04 15:31:29 +01:00
|
|
|
import org.mariotaku.twidere.view.holder.GapViewHolder;
|
|
|
|
import org.mariotaku.twidere.view.holder.StatusViewHolder;
|
2014-12-03 11:27:11 +01:00
|
|
|
|
2015-03-04 09:02:32 +01:00
|
|
|
import edu.tsinghua.spice.Utilies.SpiceProfilingUtil;
|
|
|
|
|
2015-01-14 09:47:51 +01:00
|
|
|
import static org.mariotaku.twidere.util.Utils.setMenuForStatus;
|
|
|
|
|
2014-12-03 11:27:11 +01:00
|
|
|
/**
|
|
|
|
* Created by mariotaku on 14/11/5.
|
|
|
|
*/
|
2014-12-04 15:31:29 +01:00
|
|
|
public abstract class AbsStatusesFragment<Data> extends BaseSupportFragment implements LoaderCallbacks<Data>,
|
2015-03-12 10:43:28 +01:00
|
|
|
OnRefreshListener, DrawerCallback, RefreshScrollTopInterface, StatusAdapterListener,
|
2015-03-24 16:40:47 +01:00
|
|
|
ControlBarOffsetListener, ContentListSupport {
|
2014-12-12 14:53:18 +01:00
|
|
|
|
2015-01-14 09:47:51 +01:00
|
|
|
private final Object mStatusesBusCallback;
|
2015-01-10 16:17:02 +01:00
|
|
|
private AbsStatusesAdapter<Data> mAdapter;
|
|
|
|
private LinearLayoutManager mLayoutManager;
|
2014-12-03 11:27:11 +01:00
|
|
|
private SharedPreferences mPreferences;
|
2014-12-04 15:31:29 +01:00
|
|
|
private View mProgressContainer;
|
|
|
|
private SwipeRefreshLayout mSwipeRefreshLayout;
|
|
|
|
private RecyclerView mRecyclerView;
|
|
|
|
private SimpleDrawerCallback mDrawerCallback;
|
2015-03-12 10:43:28 +01:00
|
|
|
private Rect mSystemWindowsInsets = new Rect();
|
|
|
|
private int mControlBarOffsetPixels;
|
2015-01-14 09:47:51 +01:00
|
|
|
private PopupMenu mPopupMenu;
|
2015-03-24 16:40:47 +01:00
|
|
|
private PositionManager mPositionManager;
|
2014-12-03 11:27:11 +01:00
|
|
|
|
2015-01-10 16:17:02 +01:00
|
|
|
protected AbsStatusesFragment() {
|
|
|
|
mStatusesBusCallback = createMessageBusCallback();
|
|
|
|
}
|
|
|
|
|
2014-12-03 11:27:11 +01:00
|
|
|
@Override
|
2014-12-04 15:31:29 +01:00
|
|
|
public boolean canScroll(float dy) {
|
|
|
|
return mDrawerCallback.canScroll(dy);
|
2014-12-03 11:27:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-12-04 15:31:29 +01:00
|
|
|
public void cancelTouch() {
|
|
|
|
mDrawerCallback.cancelTouch();
|
2014-12-03 11:27:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-12-04 15:31:29 +01:00
|
|
|
public void fling(float velocity) {
|
|
|
|
mDrawerCallback.fling(velocity);
|
2014-12-03 11:27:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isScrollContent(float x, float y) {
|
|
|
|
return mDrawerCallback.isScrollContent(x, y);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-12-04 15:31:29 +01:00
|
|
|
public void scrollBy(float dy) {
|
|
|
|
mDrawerCallback.scrollBy(dy);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean shouldLayoutHeaderBottom() {
|
|
|
|
return mDrawerCallback.shouldLayoutHeaderBottom();
|
2014-12-03 11:27:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void topChanged(int offset) {
|
|
|
|
mDrawerCallback.topChanged(offset);
|
|
|
|
}
|
|
|
|
|
2014-12-04 15:31:29 +01:00
|
|
|
public SharedPreferences getSharedPreferences() {
|
|
|
|
if (mPreferences != null) return mPreferences;
|
|
|
|
return mPreferences = getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE);
|
|
|
|
}
|
2014-12-03 11:27:11 +01:00
|
|
|
|
2014-12-04 15:31:29 +01:00
|
|
|
public abstract int getStatuses(long[] accountIds, long[] maxIds, long[] sinceIds);
|
2014-12-03 11:27:11 +01:00
|
|
|
|
2014-12-04 15:31:29 +01:00
|
|
|
public boolean isRefreshing() {
|
|
|
|
return mSwipeRefreshLayout.isRefreshing();
|
|
|
|
}
|
2014-12-03 11:27:11 +01:00
|
|
|
|
2015-03-24 16:40:47 +01:00
|
|
|
public AbsStatusesAdapter<Data> getAdapter() {
|
|
|
|
return mAdapter;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setControlVisible(boolean visible) {
|
|
|
|
final FragmentActivity activity = getActivity();
|
|
|
|
if (activity instanceof BaseActionBarActivity) {
|
|
|
|
((BaseActionBarActivity) activity).setControlBarVisibleAnimate(visible);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-04 15:31:29 +01:00
|
|
|
public void setRefreshing(boolean refreshing) {
|
2015-03-11 15:15:32 +01:00
|
|
|
if (refreshing == mSwipeRefreshLayout.isRefreshing()) return;
|
2015-03-24 16:40:47 +01:00
|
|
|
if (!refreshing) updateRefreshProgressOffset();
|
2014-12-04 15:31:29 +01:00
|
|
|
mSwipeRefreshLayout.setRefreshing(refreshing);
|
|
|
|
}
|
|
|
|
|
2015-01-10 16:17:02 +01:00
|
|
|
@Override
|
2015-03-12 10:43:28 +01:00
|
|
|
public void onAttach(Activity activity) {
|
|
|
|
super.onAttach(activity);
|
|
|
|
if (activity instanceof IControlBarActivity) {
|
|
|
|
((IControlBarActivity) activity).registerControlBarOffsetListener(this);
|
2015-01-17 21:19:11 +01:00
|
|
|
}
|
2015-01-10 16:17:02 +01:00
|
|
|
}
|
|
|
|
|
2014-12-04 15:31:29 +01:00
|
|
|
@Override
|
|
|
|
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
|
|
|
return inflater.inflate(R.layout.fragment_recycler_view, container, false);
|
|
|
|
}
|
2014-12-03 11:27:11 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
|
|
|
|
super.onActivityCreated(savedInstanceState);
|
2015-03-24 16:40:47 +01:00
|
|
|
mPositionManager = new PositionManager(getActivity());
|
2014-12-03 11:27:11 +01:00
|
|
|
final View view = getView();
|
|
|
|
if (view == null) throw new AssertionError();
|
|
|
|
final Context context = view.getContext();
|
|
|
|
final boolean compact = Utils.isCompactCards(context);
|
|
|
|
mDrawerCallback = new SimpleDrawerCallback(mRecyclerView);
|
|
|
|
mSwipeRefreshLayout.setOnRefreshListener(this);
|
|
|
|
mSwipeRefreshLayout.setColorSchemeColors(ThemeUtils.getUserAccentColor(context));
|
2015-03-08 16:44:47 +01:00
|
|
|
final int backgroundColor = ThemeUtils.getThemeBackgroundColor(context);
|
|
|
|
final int colorRes = ColorUtils.getContrastYIQ(backgroundColor,
|
|
|
|
R.color.bg_refresh_progress_color_light, R.color.bg_refresh_progress_color_dark);
|
2015-03-18 08:34:23 +01:00
|
|
|
mSwipeRefreshLayout.setProgressBackgroundColorSchemeResource(colorRes);
|
2014-12-03 11:27:11 +01:00
|
|
|
mAdapter = onCreateAdapter(context, compact);
|
2015-03-24 16:40:47 +01:00
|
|
|
mLayoutManager = new FixedLinearLayoutManager(context);
|
2015-01-10 16:17:02 +01:00
|
|
|
mLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
|
|
|
|
mRecyclerView.setLayoutManager(mLayoutManager);
|
2015-03-24 16:40:47 +01:00
|
|
|
mRecyclerView.setHasFixedSize(true);
|
2014-12-03 11:27:11 +01:00
|
|
|
if (compact) {
|
2015-01-10 16:17:02 +01:00
|
|
|
mRecyclerView.addItemDecoration(new DividerItemDecoration(context, mLayoutManager.getOrientation()));
|
2014-12-03 11:27:11 +01:00
|
|
|
}
|
|
|
|
mRecyclerView.setAdapter(mAdapter);
|
2015-03-15 15:40:45 +01:00
|
|
|
|
|
|
|
final ContentListScrollListener scrollListener = new ContentListScrollListener(this);
|
|
|
|
scrollListener.setTouchSlop(ViewConfiguration.get(context).getScaledTouchSlop());
|
2015-03-24 16:40:47 +01:00
|
|
|
scrollListener.setOnScrollListener(new OnScrollListener() {
|
|
|
|
@Override
|
|
|
|
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
|
|
|
|
if (newState == RecyclerView.SCROLL_STATE_IDLE) {
|
|
|
|
saveReadPosition();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2015-03-15 15:40:45 +01:00
|
|
|
mRecyclerView.setOnScrollListener(scrollListener);
|
2015-01-15 06:43:12 +01:00
|
|
|
mAdapter.setListener(this);
|
2015-01-17 19:58:29 +01:00
|
|
|
final Bundle loaderArgs = new Bundle(getArguments());
|
|
|
|
loaderArgs.putBoolean(EXTRA_FROM_USER, true);
|
|
|
|
getLoaderManager().initLoader(0, loaderArgs, this);
|
2014-12-03 11:27:11 +01:00
|
|
|
setListShown(false);
|
|
|
|
}
|
|
|
|
|
2014-12-04 15:31:29 +01:00
|
|
|
@Override
|
|
|
|
public void onStart() {
|
|
|
|
super.onStart();
|
2014-12-10 15:41:55 +01:00
|
|
|
final Bus bus = TwidereApplication.getInstance(getActivity()).getMessageBus();
|
2014-12-12 14:53:18 +01:00
|
|
|
bus.register(mStatusesBusCallback);
|
2014-12-04 15:31:29 +01:00
|
|
|
}
|
2014-12-03 11:27:11 +01:00
|
|
|
|
2014-12-04 15:31:29 +01:00
|
|
|
@Override
|
|
|
|
public void onStop() {
|
2014-12-10 15:41:55 +01:00
|
|
|
final Bus bus = TwidereApplication.getInstance(getActivity()).getMessageBus();
|
2014-12-12 14:53:18 +01:00
|
|
|
bus.unregister(mStatusesBusCallback);
|
2014-12-04 15:31:29 +01:00
|
|
|
super.onStop();
|
2014-12-03 11:27:11 +01:00
|
|
|
}
|
|
|
|
|
2015-01-14 09:47:51 +01:00
|
|
|
@Override
|
|
|
|
public void onDestroyView() {
|
|
|
|
if (mPopupMenu != null) {
|
|
|
|
mPopupMenu.dismiss();
|
|
|
|
}
|
|
|
|
super.onDestroyView();
|
|
|
|
}
|
|
|
|
|
2015-03-12 10:43:28 +01:00
|
|
|
@Override
|
|
|
|
public void onBaseViewCreated(View view, @Nullable Bundle savedInstanceState) {
|
|
|
|
super.onBaseViewCreated(view, savedInstanceState);
|
|
|
|
mProgressContainer = view.findViewById(R.id.progress_container);
|
|
|
|
mSwipeRefreshLayout = (SwipeRefreshLayout) view.findViewById(R.id.swipe_layout);
|
|
|
|
mRecyclerView = (RecyclerView) view.findViewById(R.id.recycler_view);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onDetach() {
|
|
|
|
final FragmentActivity activity = getActivity();
|
|
|
|
if (activity instanceof IControlBarActivity) {
|
|
|
|
((IControlBarActivity) activity).unregisterControlBarOffsetListener(this);
|
|
|
|
}
|
|
|
|
super.onDetach();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void fitSystemWindows(Rect insets) {
|
|
|
|
super.fitSystemWindows(insets);
|
|
|
|
mRecyclerView.setPadding(insets.left, insets.top, insets.right, insets.bottom);
|
|
|
|
mSystemWindowsInsets.set(insets);
|
|
|
|
updateRefreshProgressOffset();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onControlBarOffsetChanged(IControlBarActivity activity, float offset) {
|
|
|
|
mControlBarOffsetPixels = Math.round(activity.getControlBarHeight() * (1 - offset));
|
|
|
|
updateRefreshProgressOffset();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public final Loader<Data> onCreateLoader(int id, Bundle args) {
|
|
|
|
final boolean fromUser = args.getBoolean(EXTRA_FROM_USER);
|
|
|
|
args.remove(EXTRA_FROM_USER);
|
|
|
|
return onCreateStatusesLoader(getActivity(), args, fromUser);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public final void onLoadFinished(Loader<Data> loader, Data data) {
|
|
|
|
setRefreshing(false);
|
|
|
|
final SharedPreferences preferences = getSharedPreferences();
|
|
|
|
final boolean readFromBottom = preferences.getBoolean(KEY_READ_FROM_BOTTOM, false);
|
|
|
|
final long lastReadId;
|
|
|
|
final int lastVisiblePos, lastVisibleTop;
|
|
|
|
if (readFromBottom) {
|
|
|
|
lastVisiblePos = mLayoutManager.findLastVisibleItemPosition();
|
|
|
|
} else {
|
|
|
|
lastVisiblePos = mLayoutManager.findFirstVisibleItemPosition();
|
|
|
|
}
|
|
|
|
if (lastVisiblePos != -1) {
|
|
|
|
lastReadId = mAdapter.getItemId(lastVisiblePos);
|
|
|
|
if (readFromBottom) {
|
|
|
|
lastVisibleTop = mLayoutManager.getChildAt(mLayoutManager.getChildCount() - 1).getTop();
|
|
|
|
} else {
|
|
|
|
lastVisibleTop = mLayoutManager.getChildAt(0).getTop();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
lastReadId = -1;
|
|
|
|
lastVisibleTop = 0;
|
|
|
|
}
|
|
|
|
mAdapter.setData(data);
|
2015-03-12 17:14:53 +01:00
|
|
|
if (!(loader instanceof IExtendedLoader) || ((IExtendedLoader) loader).isFromUser()) {
|
2015-03-12 10:43:28 +01:00
|
|
|
mAdapter.setLoadMoreIndicatorEnabled(hasMoreData(data));
|
|
|
|
int pos = -1;
|
|
|
|
for (int i = 0; i < mAdapter.getItemCount(); i++) {
|
|
|
|
if (lastReadId == mAdapter.getItemId(i)) {
|
|
|
|
pos = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (pos != -1 && mAdapter.isStatus(pos) && (readFromBottom || lastVisiblePos != 0)) {
|
|
|
|
mLayoutManager.scrollToPositionWithOffset(pos, lastVisibleTop - mLayoutManager.getPaddingTop());
|
|
|
|
}
|
|
|
|
}
|
2015-03-12 17:14:53 +01:00
|
|
|
if (loader instanceof IExtendedLoader) {
|
|
|
|
((IExtendedLoader) loader).setFromUser(false);
|
2015-03-12 10:43:28 +01:00
|
|
|
}
|
|
|
|
setListShown(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onLoaderReset(Loader<Data> loader) {
|
2015-03-12 17:14:53 +01:00
|
|
|
if (loader instanceof IExtendedLoader) {
|
|
|
|
((IExtendedLoader) loader).setFromUser(false);
|
|
|
|
}
|
2015-03-12 10:43:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public abstract Loader<Data> onCreateStatusesLoader(final Context context, final Bundle args,
|
|
|
|
final boolean fromUser);
|
|
|
|
|
2014-12-04 15:31:29 +01:00
|
|
|
@Override
|
2015-01-10 16:17:02 +01:00
|
|
|
public void onGapClick(GapViewHolder holder, int position) {
|
|
|
|
final ParcelableStatus status = mAdapter.getStatus(position);
|
2015-03-15 15:40:45 +01:00
|
|
|
final long sinceId = position + 1 < mAdapter.getStatusesCount() ? mAdapter.getStatus(position + 1).id : -1;
|
2015-01-10 16:17:02 +01:00
|
|
|
final long[] accountIds = {status.account_id};
|
|
|
|
final long[] maxIds = {status.id};
|
|
|
|
final long[] sinceIds = {sinceId};
|
|
|
|
getStatuses(accountIds, maxIds, sinceIds);
|
2014-12-04 15:31:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onStatusActionClick(StatusViewHolder holder, int id, int position) {
|
2014-12-10 13:15:09 +01:00
|
|
|
final ParcelableStatus status = mAdapter.getStatus(position);
|
|
|
|
if (status == null) return;
|
2015-03-18 08:34:23 +01:00
|
|
|
final FragmentActivity activity = getActivity();
|
2014-12-04 15:31:29 +01:00
|
|
|
switch (id) {
|
|
|
|
case R.id.reply_count: {
|
2015-01-01 11:38:34 +01:00
|
|
|
final Intent intent = new Intent(INTENT_ACTION_REPLY);
|
2015-03-18 08:34:23 +01:00
|
|
|
intent.setPackage(activity.getPackageName());
|
2015-01-01 11:38:34 +01:00
|
|
|
intent.putExtra(EXTRA_STATUS, status);
|
2015-03-18 08:34:23 +01:00
|
|
|
activity.startActivity(intent);
|
2014-12-04 15:31:29 +01:00
|
|
|
break;
|
|
|
|
}
|
2014-12-10 13:15:09 +01:00
|
|
|
case R.id.retweet_count: {
|
|
|
|
RetweetQuoteDialogFragment.show(getFragmentManager(), status);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case R.id.favorite_count: {
|
|
|
|
final AsyncTwitterWrapper twitter = getTwitterWrapper();
|
|
|
|
if (twitter == null) return;
|
|
|
|
if (status.is_favorite) {
|
|
|
|
twitter.destroyFavoriteAsync(status.account_id, status.id);
|
2015-03-04 09:02:32 +01:00
|
|
|
//spice
|
2015-03-18 08:34:23 +01:00
|
|
|
SpiceProfilingUtil.profile(activity, status.account_id, status.id + ",Unfavor,"
|
|
|
|
+ status.account_id + "," + status.user_id + "," + status.timestamp);
|
|
|
|
SpiceProfilingUtil.log(activity, status.id + ",Unfavor," + status.account_id
|
|
|
|
+ "," + status.user_id + "," + status.timestamp);
|
2015-03-04 09:02:32 +01:00
|
|
|
//end
|
2014-12-10 13:15:09 +01:00
|
|
|
} else {
|
|
|
|
twitter.createFavoriteAsync(status.account_id, status.id);
|
2015-03-04 09:02:32 +01:00
|
|
|
//spice
|
2015-03-18 08:34:23 +01:00
|
|
|
SpiceProfilingUtil.profile(activity, status.account_id, status.id + ",Favor,"
|
|
|
|
+ status.account_id + "," + status.user_id + "," + status.timestamp);
|
|
|
|
SpiceProfilingUtil.log(activity, status.id + ",Favor," + status.account_id
|
|
|
|
+ "," + status.user_id + "," + status.timestamp);
|
2015-03-04 09:02:32 +01:00
|
|
|
//end
|
2014-12-10 13:15:09 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2014-12-04 15:31:29 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onStatusClick(StatusViewHolder holder, int position) {
|
2014-12-08 16:16:33 +01:00
|
|
|
Utils.openStatus(getActivity(), mAdapter.getStatus(position), null);
|
2014-12-04 15:31:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-01-14 09:47:51 +01:00
|
|
|
public void onStatusMenuClick(StatusViewHolder holder, View menuView, int position) {
|
|
|
|
if (mPopupMenu != null) {
|
|
|
|
mPopupMenu.dismiss();
|
|
|
|
}
|
2015-01-17 19:58:29 +01:00
|
|
|
final PopupMenu popupMenu = new PopupMenu(mAdapter.getContext(), menuView,
|
|
|
|
Gravity.NO_GRAVITY, R.attr.actionOverflowMenuStyle, 0);
|
2015-01-14 09:47:51 +01:00
|
|
|
popupMenu.inflate(R.menu.action_status);
|
|
|
|
setMenuForStatus(mAdapter.getContext(), popupMenu.getMenu(), mAdapter.getStatus(position));
|
|
|
|
popupMenu.show();
|
|
|
|
mPopupMenu = popupMenu;
|
2014-12-04 15:31:29 +01:00
|
|
|
}
|
2014-12-03 11:27:11 +01:00
|
|
|
|
2015-01-10 16:17:02 +01:00
|
|
|
@Override
|
|
|
|
public void onRefresh() {
|
|
|
|
triggerRefresh();
|
|
|
|
}
|
|
|
|
|
2014-12-03 11:27:11 +01:00
|
|
|
@Override
|
2014-12-04 15:31:29 +01:00
|
|
|
public boolean scrollToStart() {
|
|
|
|
final AsyncTwitterWrapper twitter = getTwitterWrapper();
|
|
|
|
final int tabPosition = getTabPosition();
|
|
|
|
if (twitter != null && tabPosition != -1) {
|
|
|
|
twitter.clearUnreadCountAsync(tabPosition);
|
|
|
|
}
|
2015-01-04 16:12:10 +01:00
|
|
|
mRecyclerView.smoothScrollToPosition(0);
|
2015-03-12 10:43:28 +01:00
|
|
|
// mRecyclerView.scrollToPosition(0);
|
2014-12-04 15:31:29 +01:00
|
|
|
return true;
|
2014-12-03 11:27:11 +01:00
|
|
|
}
|
|
|
|
|
2015-01-10 16:17:02 +01:00
|
|
|
protected Object createMessageBusCallback() {
|
|
|
|
return new StatusesBusCallback();
|
|
|
|
}
|
|
|
|
|
2014-12-04 15:31:29 +01:00
|
|
|
protected abstract long[] getAccountIds();
|
|
|
|
|
2014-12-03 11:27:11 +01:00
|
|
|
protected Data getAdapterData() {
|
|
|
|
return mAdapter.getData();
|
|
|
|
}
|
|
|
|
|
2014-12-04 15:31:29 +01:00
|
|
|
protected void setAdapterData(Data data) {
|
2014-12-03 11:27:11 +01:00
|
|
|
mAdapter.setData(data);
|
|
|
|
}
|
|
|
|
|
2015-03-24 16:40:47 +01:00
|
|
|
protected String getReadPositionTag() {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2015-01-10 16:17:02 +01:00
|
|
|
protected abstract boolean hasMoreData(Data data);
|
2014-12-10 15:41:55 +01:00
|
|
|
|
2014-12-04 15:31:29 +01:00
|
|
|
protected abstract AbsStatusesAdapter<Data> onCreateAdapter(Context context, boolean compact);
|
2014-12-03 11:27:11 +01:00
|
|
|
|
2015-03-24 16:40:47 +01:00
|
|
|
protected void saveReadPosition() {
|
|
|
|
final String readPositionTag = getReadPositionTag();
|
|
|
|
if (readPositionTag == null) return;
|
|
|
|
final int position = mLayoutManager.findFirstVisibleItemPosition();
|
|
|
|
if (position == RecyclerView.NO_POSITION) return;
|
|
|
|
final ParcelableStatus status = mAdapter.getStatus(position);
|
|
|
|
if (status == null) return;
|
|
|
|
mPositionManager.setPosition(readPositionTag, status.id);
|
2015-03-12 10:43:28 +01:00
|
|
|
}
|
|
|
|
|
2014-12-04 15:31:29 +01:00
|
|
|
private void setListShown(boolean shown) {
|
|
|
|
mProgressContainer.setVisibility(shown ? View.GONE : View.VISIBLE);
|
|
|
|
mSwipeRefreshLayout.setVisibility(shown ? View.VISIBLE : View.GONE);
|
|
|
|
}
|
2014-12-12 14:53:18 +01:00
|
|
|
|
2015-03-12 10:43:28 +01:00
|
|
|
private void updateRefreshProgressOffset() {
|
|
|
|
if (mSystemWindowsInsets.top == 0 || mSwipeRefreshLayout == null || isRefreshing()) return;
|
|
|
|
final float density = getResources().getDisplayMetrics().density;
|
2015-03-19 09:34:30 +01:00
|
|
|
final int progressCircleDiameter = mSwipeRefreshLayout.getProgressCircleDiameter();
|
|
|
|
final int swipeStart = (mSystemWindowsInsets.top - mControlBarOffsetPixels) - progressCircleDiameter;
|
2015-03-12 10:43:28 +01:00
|
|
|
// 64: SwipeRefreshLayout.DEFAULT_CIRCLE_TARGET
|
|
|
|
final int swipeDistance = Math.round(64 * density);
|
|
|
|
mSwipeRefreshLayout.setProgressViewOffset(true, swipeStart, swipeStart + swipeDistance);
|
|
|
|
}
|
2014-12-12 14:53:18 +01:00
|
|
|
|
|
|
|
protected final class StatusesBusCallback {
|
|
|
|
|
|
|
|
protected StatusesBusCallback() {
|
|
|
|
}
|
|
|
|
|
|
|
|
@Subscribe
|
|
|
|
public void notifyStatusListChanged(StatusListChangedEvent event) {
|
|
|
|
mAdapter.notifyDataSetChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2014-12-03 11:27:11 +01:00
|
|
|
}
|