improved message when no account selected

reduce some lengthy operation on main thread
This commit is contained in:
Mariotaku Lee 2015-04-24 16:26:39 +08:00
parent 17394ce47d
commit bb3ac5e287
22 changed files with 266 additions and 303 deletions

View File

@ -69,6 +69,7 @@ public class MessageEntriesAdapter extends Adapter<ViewHolder> implements Consta
private final boolean mDisplayProfileImage;
private boolean mLoadMoreSupported;
private boolean mLoadMoreIndicatorVisible;
private boolean mShowAccountsColor;
private Cursor mCursor;
private MessageEntriesAdapterListener mListener;
private StringLongPair[] mPositionPairs;
@ -275,6 +276,16 @@ public class MessageEntriesAdapter extends Adapter<ViewHolder> implements Consta
return true;
}
public void setShowAccountsColor(boolean showAccountsColor) {
if (mShowAccountsColor == showAccountsColor) return;
mShowAccountsColor = showAccountsColor;
notifyDataSetChanged();
}
public boolean shouldShowAccountsColor() {
return mShowAccountsColor;
}
public interface MessageEntriesAdapterListener {
void onEntryClick(int position, DirectMessageEntry entry);

View File

@ -24,7 +24,6 @@ import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
@ -164,7 +163,6 @@ public class SupportTabsAdapter extends SupportFixedFragmentStatePagerAdapter im
@Override
public void onPageSelected(final int position) {
Log.d(LOGTAG, "onPageSelected " + position);
if (mIndicator == null || position < 0 || position >= getCount()) return;
announceForAccessibilityCompat(mContext, (View) mIndicator, getPageTitle(position), getClass());
}

View File

@ -32,9 +32,12 @@ import android.support.v7.widget.FixedLinearLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewConfiguration;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import org.mariotaku.twidere.R;
import org.mariotaku.twidere.activity.iface.IControlBarActivity;
@ -54,19 +57,27 @@ import org.mariotaku.twidere.view.HeaderDrawerLayout.DrawerCallback;
/**
* Created by mariotaku on 15/4/16.
*/
public abstract class AbsContentListFragment<A extends IContentCardAdapter> extends BaseSupportFragment implements OnRefreshListener,
DrawerCallback, RefreshScrollTopInterface, ControlBarOffsetListener, ContentListSupport {
public abstract class AbsContentListFragment<A extends IContentCardAdapter> extends BaseSupportFragment
implements OnRefreshListener, DrawerCallback, RefreshScrollTopInterface, ControlBarOffsetListener,
ContentListSupport {
private Rect mSystemWindowsInsets = new Rect();
private LinearLayoutManager mLayoutManager;
private View mProgressContainer;
private SwipeRefreshLayout mSwipeRefreshLayout;
private RecyclerView mRecyclerView;
private SimpleDrawerCallback mDrawerCallback;
private View mErrorContainer;
private ImageView mErrorIconView;
private TextView mErrorTextView;
private LinearLayoutManager mLayoutManager;
private A mAdapter;
// Callbacks and listeners
private SimpleDrawerCallback mDrawerCallback;
private ContentListScrollListener mScrollListener;
// Data fields
private Rect mSystemWindowsInsets = new Rect();
@Override
public boolean canScroll(float dy) {
return mDrawerCallback.canScroll(dy);
@ -166,10 +177,6 @@ public abstract class AbsContentListFragment<A extends IContentCardAdapter> exte
return mRecyclerView;
}
public final ContentListScrollListener getScrollListener() {
return mScrollListener;
}
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
@ -203,6 +210,15 @@ public abstract class AbsContentListFragment<A extends IContentCardAdapter> exte
mLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
mRecyclerView.setLayoutManager(mLayoutManager);
mRecyclerView.setHasFixedSize(true);
mRecyclerView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getActionMasked() == MotionEvent.ACTION_DOWN) {
updateRefreshProgressOffset();
}
return false;
}
});
if (compact) {
mRecyclerView.addItemDecoration(new DividerItemDecoration(context, mLayoutManager.getOrientation()));
}
@ -210,7 +226,18 @@ public abstract class AbsContentListFragment<A extends IContentCardAdapter> exte
mScrollListener = new ContentListScrollListener(this);
mScrollListener.setTouchSlop(ViewConfiguration.get(context).getScaledTouchSlop());
mRecyclerView.setOnScrollListener(mScrollListener);
}
@Override
public void onStart() {
super.onStart();
mRecyclerView.addOnScrollListener(mScrollListener);
}
@Override
public void onStop() {
mRecyclerView.removeOnScrollListener(mScrollListener);
super.onStop();
}
@Override
@ -219,6 +246,9 @@ public abstract class AbsContentListFragment<A extends IContentCardAdapter> exte
mProgressContainer = view.findViewById(R.id.progress_container);
mSwipeRefreshLayout = (SwipeRefreshLayout) view.findViewById(R.id.swipe_layout);
mRecyclerView = (RecyclerView) view.findViewById(R.id.recycler_view);
mErrorContainer = view.findViewById(R.id.error_container);
mErrorIconView = (ImageView) view.findViewById(R.id.error_icon);
mErrorTextView = (TextView) view.findViewById(R.id.error_text);
}
@Override
@ -234,6 +264,7 @@ public abstract class AbsContentListFragment<A extends IContentCardAdapter> exte
protected void fitSystemWindows(Rect insets) {
super.fitSystemWindows(insets);
mRecyclerView.setPadding(insets.left, insets.top, insets.right, insets.bottom);
mErrorContainer.setPadding(insets.left, insets.top, insets.right, insets.bottom);
mProgressContainer.setPadding(insets.left, insets.top, insets.right, insets.bottom);
mSystemWindowsInsets.set(insets);
updateRefreshProgressOffset();
@ -255,9 +286,24 @@ public abstract class AbsContentListFragment<A extends IContentCardAdapter> exte
@NonNull
protected abstract A onCreateAdapter(Context context, boolean compact);
protected final void setListShown(boolean shown) {
mProgressContainer.setVisibility(shown ? View.GONE : View.VISIBLE);
mSwipeRefreshLayout.setVisibility(shown ? View.VISIBLE : View.GONE);
protected final void showContent() {
mErrorContainer.setVisibility(View.GONE);
mProgressContainer.setVisibility(View.GONE);
mSwipeRefreshLayout.setVisibility(View.VISIBLE);
}
protected final void showProgress() {
mErrorContainer.setVisibility(View.GONE);
mProgressContainer.setVisibility(View.VISIBLE);
mSwipeRefreshLayout.setVisibility(View.GONE);
}
protected final void showError(int icon, CharSequence text) {
mErrorContainer.setVisibility(View.VISIBLE);
mProgressContainer.setVisibility(View.GONE);
mSwipeRefreshLayout.setVisibility(View.GONE);
mErrorIconView.setImageResource(icon);
mErrorTextView.setText(text);
}
protected void updateRefreshProgressOffset() {

View File

@ -31,7 +31,6 @@ 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.ContentListScrollListener;
import org.mariotaku.twidere.util.KeyboardShortcutsHandler;
import org.mariotaku.twidere.util.KeyboardShortcutsHandler.KeyboardShortcutCallback;
import org.mariotaku.twidere.util.ReadStateManager;
@ -57,7 +56,7 @@ public abstract class AbsStatusesFragment<Data> extends AbsContentListFragment<A
private SharedPreferences mPreferences;
private PopupMenu mPopupMenu;
private ReadStateManager mReadStateManager;
private RecyclerViewNavigationHelper mRecyclerViewNavigationHelper;
private RecyclerViewNavigationHelper mNavigationHelper;
private ParcelableStatus mSelectedStatus;
@ -75,6 +74,14 @@ public abstract class AbsStatusesFragment<Data> extends AbsContentListFragment<A
getFragmentManager(), getTwitterWrapper(), status, item);
}
};
private OnScrollListener mOnScrollListener = new OnScrollListener() {
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
if (newState == RecyclerView.SCROLL_STATE_IDLE) {
saveReadPosition();
}
}
};
protected AbsStatusesFragment() {
mStatusesBusCallback = createMessageBusCallback();
@ -138,7 +145,7 @@ public abstract class AbsStatusesFragment<Data> extends AbsContentListFragment<A
@Override
public boolean handleKeyboardShortcutRepeat(@NonNull KeyboardShortcutsHandler handler, final int keyCode, final int repeatCount,
@NonNull final KeyEvent event) {
return mRecyclerViewNavigationHelper.handleKeyboardShortcutRepeat(handler, keyCode, repeatCount, event);
return mNavigationHelper.handleKeyboardShortcutRepeat(handler, keyCode, repeatCount, event);
}
@Override
@ -192,7 +199,6 @@ public abstract class AbsStatusesFragment<Data> extends AbsContentListFragment<A
if (loader instanceof IExtendedLoader) {
((IExtendedLoader) loader).setFromUser(false);
}
setListShown(true);
onLoadingFinished();
}
@ -312,6 +318,8 @@ public abstract class AbsStatusesFragment<Data> extends AbsContentListFragment<A
@Override
public void onStart() {
super.onStart();
final RecyclerView recyclerView = getRecyclerView();
recyclerView.addOnScrollListener(mOnScrollListener);
final Bus bus = TwidereApplication.getInstance(getActivity()).getMessageBus();
bus.register(mStatusesBusCallback);
}
@ -320,6 +328,8 @@ public abstract class AbsStatusesFragment<Data> extends AbsContentListFragment<A
public void onStop() {
final Bus bus = TwidereApplication.getInstance(getActivity()).getMessageBus();
bus.unregister(mStatusesBusCallback);
final RecyclerView recyclerView = getRecyclerView();
recyclerView.removeOnScrollListener(mOnScrollListener);
super.onStop();
}
@ -345,28 +355,17 @@ public abstract class AbsStatusesFragment<Data> extends AbsContentListFragment<A
super.onActivityCreated(savedInstanceState);
mReadStateManager = getReadStateManager();
final FragmentActivity activity = getActivity();
final TwidereApplication application = TwidereApplication.getInstance(activity);
final AbsStatusesAdapter<Data> adapter = getAdapter();
final RecyclerView recyclerView = getRecyclerView();
final LinearLayoutManager layoutManager = getLayoutManager();
final ContentListScrollListener scrollListener = getScrollListener();
mRecyclerViewNavigationHelper = new RecyclerViewNavigationHelper(recyclerView, layoutManager,
adapter);
mNavigationHelper = new RecyclerViewNavigationHelper(recyclerView, layoutManager, adapter);
adapter.setListener(this);
scrollListener.setOnScrollListener(new OnScrollListener() {
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
if (newState == RecyclerView.SCROLL_STATE_IDLE) {
saveReadPosition();
}
}
});
final Bundle loaderArgs = new Bundle(getArguments());
loaderArgs.putBoolean(EXTRA_FROM_USER, true);
getLoaderManager().initLoader(0, loaderArgs, this);
setListShown(false);
showProgress();
}
protected Object createMessageBusCallback() {

View File

@ -95,7 +95,7 @@ abstract class AbsUsersFragment<Data> extends AbsContentListFragment<AbsUsersAda
if (loader instanceof IExtendedLoader) {
((IExtendedLoader) loader).setFromUser(false);
}
setListShown(true);
showContent();
}
@Override

View File

@ -67,8 +67,6 @@ import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.animation.DecelerateInterpolator;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.ImageView;
import android.widget.ListAdapter;
import android.widget.ListView;
@ -78,7 +76,7 @@ import com.commonsware.cwac.merge.MergeAdapter;
import com.nostra13.universalimageloader.core.assist.FailReason;
import com.nostra13.universalimageloader.core.listener.ImageLoadingListener;
import org.apache.commons.lang3.ArrayUtils;
import org.mariotaku.querybuilder.Expression;
import org.mariotaku.twidere.R;
import org.mariotaku.twidere.activity.FiltersActivity;
import org.mariotaku.twidere.activity.SettingsActivity;
@ -92,7 +90,7 @@ import org.mariotaku.twidere.activity.support.UserProfileEditorActivity;
import org.mariotaku.twidere.adapter.ArrayAdapter;
import org.mariotaku.twidere.app.TwidereApplication;
import org.mariotaku.twidere.constant.SharedPreferenceConstants;
import org.mariotaku.twidere.menu.SupportAccountActionProvider;
import org.mariotaku.twidere.menu.support.AccountToggleProvider;
import org.mariotaku.twidere.model.ParcelableAccount;
import org.mariotaku.twidere.provider.TwidereDataStore.Accounts;
import org.mariotaku.twidere.util.CompareUtils;
@ -110,17 +108,14 @@ import org.mariotaku.twidere.view.ShapedImageView;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import static org.mariotaku.twidere.util.Utils.openUserFavorites;
import static org.mariotaku.twidere.util.Utils.openUserLists;
import static org.mariotaku.twidere.util.Utils.openUserProfile;
public class AccountsDashboardFragment extends BaseSupportListFragment implements LoaderCallbacks<Cursor>,
OnSharedPreferenceChangeListener, OnCheckedChangeListener, ImageLoadingListener, OnClickListener,
KeyboardShortcutCallback {
OnSharedPreferenceChangeListener, ImageLoadingListener, OnClickListener, KeyboardShortcutCallback {
private final SupportFragmentReloadCursorObserver mReloadContentObserver = new SupportFragmentReloadCursorObserver(
this, 0, this);
@ -145,15 +140,15 @@ public class AccountsDashboardFragment extends BaseSupportListFragment implement
private Context mThemedContext;
private MediaLoaderWrapper mImageLoader;
private SupportAccountActionProvider mAccountActionProvider;
private AccountToggleProvider mAccountActionProvider;
private boolean mSwitchAccountAnimationPlaying;
public long[] getActivatedAccountIds() {
if (mAccountActionProvider == null) {
return Utils.getActivatedAccountIds(getActivity());
if (mAccountActionProvider != null) {
return mAccountActionProvider.getActivatedAccountIds();
}
return mAccountActionProvider.getActivatedAccountIds();
return Utils.getActivatedAccountIds(getActivity());
}
@Override
@ -226,16 +221,6 @@ public class AccountsDashboardFragment extends BaseSupportListFragment implement
updateDefaultAccountState();
}
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
final ParcelableAccount account = mAccountsAdapter.getSelectedAccount();
if (account == null) return;
final ContentValues values = new ContentValues();
values.put(Accounts.IS_ACTIVATED, isChecked);
final String where = Accounts.ACCOUNT_ID + " = " + account.account_id;
mResolver.update(Accounts.CONTENT_URI, values, where, null);
}
@Override
public void onClick(View v) {
switch (v.getId()) {
@ -260,24 +245,20 @@ public class AccountsDashboardFragment extends BaseSupportListFragment implement
@Override
public void onLoadFinished(final Loader<Cursor> loader, final Cursor data) {
final Menu menu = mAccountsToggleMenu.getMenu();
mAccountActionProvider = (SupportAccountActionProvider) MenuItemCompat.getActionProvider(menu.findItem(MENU_SELECT_ACCOUNT));
mAccountActionProvider = (AccountToggleProvider) MenuItemCompat.getActionProvider(menu.findItem(MENU_SELECT_ACCOUNT));
mAccountActionProvider.setExclusive(false);
final ParcelableAccount[] accounts = ParcelableAccount.getAccounts(data);
final Set<Long> activatedIds = new HashSet<>();
long defaultId = -1;
for (ParcelableAccount account : accounts) {
if (account.is_activated) {
if (defaultId < 0) {
defaultId = account.account_id;
}
activatedIds.add(account.account_id);
defaultId = account.account_id;
break;
}
}
mAccountsAdapter.setAccounts(accounts);
mAccountsAdapter.setSelectedAccountId(mPreferences.getLong(KEY_DEFAULT_ACCOUNT_ID, defaultId));
mAccountOptionsAdapter.setSelectedAccount(mAccountsAdapter.getSelectedAccount());
mAccountActionProvider.setAccounts(accounts);
mAccountActionProvider.setSelectedAccountIds(ArrayUtils.toPrimitive(activatedIds.toArray(new Long[activatedIds.size()])));
initAccountActionsAdapter(accounts);
updateAccountOptionsSeparatorLabel(null);
@ -435,12 +416,14 @@ public class AccountsDashboardFragment extends BaseSupportListFragment implement
mAccountsToggleMenu.setOnMenuItemClickListener(new OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
if (item.getGroupId() != SupportAccountActionProvider.MENU_GROUP) return false;
if (item.getGroupId() != AccountToggleProvider.MENU_GROUP) return false;
final ParcelableAccount[] accounts = mAccountActionProvider.getAccounts();
final ParcelableAccount account = accounts[item.getOrder()];
final ContentValues values = new ContentValues();
values.put(Accounts.IS_ACTIVATED, !account.is_activated);
final String where = Accounts.ACCOUNT_ID + " = " + account.account_id;
final boolean newActivated = !account.is_activated;
mAccountActionProvider.setAccountActivated(account.account_id, newActivated);
values.put(Accounts.IS_ACTIVATED, newActivated);
final String where = Expression.equals(Accounts.ACCOUNT_ID, account.account_id).getSQL();
mResolver.update(Accounts.CONTENT_URI, values, where, null);
return true;
}

View File

@ -37,6 +37,7 @@ import com.squareup.otto.Subscribe;
import org.mariotaku.querybuilder.Columns.Column;
import org.mariotaku.querybuilder.Expression;
import org.mariotaku.querybuilder.RawItemArray;
import org.mariotaku.twidere.R;
import org.mariotaku.twidere.activity.support.HomeActivity;
import org.mariotaku.twidere.adapter.AbsStatusesAdapter;
import org.mariotaku.twidere.adapter.CursorStatusesAdapter;
@ -45,6 +46,7 @@ import org.mariotaku.twidere.provider.TwidereDataStore.Accounts;
import org.mariotaku.twidere.provider.TwidereDataStore.Statuses;
import org.mariotaku.twidere.util.AsyncTaskUtils;
import org.mariotaku.twidere.util.Utils;
import org.mariotaku.twidere.util.message.AccountChangedEvent;
import org.mariotaku.twidere.util.message.FavoriteCreatedEvent;
import org.mariotaku.twidere.util.message.FavoriteDestroyedEvent;
import org.mariotaku.twidere.util.message.GetStatusesTaskEvent;
@ -64,7 +66,12 @@ public abstract class CursorStatusesFragment extends AbsStatusesFragment<Cursor>
@Override
protected void onLoadingFinished() {
final long[] accountIds = getAccountIds();
if (accountIds.length > 0) {
showContent();
} else {
showError(R.drawable.ic_info_account, getString(R.string.no_account_selected));
}
}
private ContentObserver mContentObserver;
@ -132,6 +139,11 @@ public abstract class CursorStatusesFragment extends AbsStatusesFragment<Cursor>
public void notifyStatusRetweeted(StatusRetweetedEvent event) {
}
@Subscribe
public void notifyAccountChanged(AccountChangedEvent event) {
}
}
@Override

View File

@ -19,34 +19,24 @@
package org.mariotaku.twidere.fragment.support;
import android.app.Activity;
import android.content.ContentResolver;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.Resources;
import android.database.Cursor;
import android.graphics.Rect;
import android.net.Uri;
import android.os.AsyncTask;
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.LoaderManager.LoaderCallbacks;
import android.support.v4.content.CursorLoader;
import android.support.v4.content.Loader;
import android.support.v4.util.LongSparseArray;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v4.widget.SwipeRefreshLayout.OnRefreshListener;
import android.support.v7.widget.FixedLinearLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewConfiguration;
import android.view.ViewGroup;
import com.squareup.otto.Bus;
import com.squareup.otto.Subscribe;
@ -55,8 +45,6 @@ import org.mariotaku.querybuilder.Columns.Column;
import org.mariotaku.querybuilder.Expression;
import org.mariotaku.querybuilder.RawItemArray;
import org.mariotaku.twidere.R;
import org.mariotaku.twidere.activity.iface.IControlBarActivity;
import org.mariotaku.twidere.activity.iface.IControlBarActivity.ControlBarOffsetListener;
import org.mariotaku.twidere.activity.support.BaseAppCompatActivity;
import org.mariotaku.twidere.activity.support.HomeActivity;
import org.mariotaku.twidere.adapter.MessageEntriesAdapter;
@ -64,20 +52,16 @@ import org.mariotaku.twidere.adapter.MessageEntriesAdapter.DirectMessageEntry;
import org.mariotaku.twidere.adapter.MessageEntriesAdapter.MessageEntriesAdapterListener;
import org.mariotaku.twidere.adapter.decorator.DividerItemDecoration;
import org.mariotaku.twidere.app.TwidereApplication;
import org.mariotaku.twidere.fragment.iface.RefreshScrollTopInterface;
import org.mariotaku.twidere.provider.TwidereDataStore.Accounts;
import org.mariotaku.twidere.provider.TwidereDataStore.DirectMessages;
import org.mariotaku.twidere.provider.TwidereDataStore.DirectMessages.Inbox;
import org.mariotaku.twidere.provider.TwidereDataStore.Statuses;
import org.mariotaku.twidere.util.AsyncTaskUtils;
import org.mariotaku.twidere.util.AsyncTwitterWrapper;
import org.mariotaku.twidere.util.ContentListScrollListener;
import org.mariotaku.twidere.util.ContentListScrollListener.ContentListSupport;
import org.mariotaku.twidere.util.KeyboardShortcutsHandler;
import org.mariotaku.twidere.util.KeyboardShortcutsHandler.KeyboardShortcutCallback;
import org.mariotaku.twidere.util.MultiSelectManager;
import org.mariotaku.twidere.util.RecyclerViewNavigationHelper;
import org.mariotaku.twidere.util.ThemeUtils;
import org.mariotaku.twidere.util.Utils;
import org.mariotaku.twidere.util.content.SupportFragmentReloadCursorObserver;
import org.mariotaku.twidere.util.message.GetMessagesTaskEvent;
@ -88,9 +72,8 @@ import java.util.Set;
import static org.mariotaku.twidere.util.Utils.openMessageConversation;
public class DirectMessagesFragment extends BaseSupportFragment implements LoaderCallbacks<Cursor>,
RefreshScrollTopInterface, OnRefreshListener, MessageEntriesAdapterListener,
ControlBarOffsetListener, ContentListSupport, KeyboardShortcutCallback {
public class DirectMessagesFragment extends AbsContentListFragment<MessageEntriesAdapter>
implements LoaderCallbacks<Cursor>, MessageEntriesAdapterListener, KeyboardShortcutCallback {
// Listeners
private final SupportFragmentReloadCursorObserver mReloadContentObserver = new SupportFragmentReloadCursorObserver(
@ -98,38 +81,18 @@ public class DirectMessagesFragment extends BaseSupportFragment implements Loade
// Utility classes
private MultiSelectManager mMultiSelectManager;
private SharedPreferences mPreferences;
private RemoveUnreadCountsTask mRemoveUnreadCountsTask;
private LinearLayoutManager mLayoutManager;
private RecyclerViewNavigationHelper mRecyclerViewNavigationHelper;
// Views
private RecyclerView mRecyclerView;
private MessageEntriesAdapter mAdapter;
private SwipeRefreshLayout mSwipeRefreshLayout;
private View mProgressContainer;
// Data fields
private final LongSparseArray<Set<Long>> mUnreadCountsToRemove = new LongSparseArray<>();
private final Set<Integer> mReadPositions = Collections.synchronizedSet(new HashSet<Integer>());
private Rect mSystemWindowsInsets = new Rect();
private int mControlBarOffsetPixels;
private int mFirstVisibleItem;
@NonNull
@Override
public MessageEntriesAdapter getAdapter() {
return mAdapter;
}
@Override
public boolean isRefreshing() {
if (mSwipeRefreshLayout == null || mAdapter == null) return false;
return mSwipeRefreshLayout.isRefreshing() || mAdapter.isLoadMoreIndicatorVisible();
}
public void setRefreshing(boolean refreshing) {
if (mAdapter == null || refreshing == mSwipeRefreshLayout.isRefreshing()) return;
mSwipeRefreshLayout.setRefreshing(refreshing && !mAdapter.isLoadMoreIndicatorVisible());
protected MessageEntriesAdapter onCreateAdapter(Context context, boolean compact) {
return new MessageEntriesAdapter(context);
}
@Override
@ -145,6 +108,12 @@ public class DirectMessagesFragment extends BaseSupportFragment implements Loade
}
}
@Override
public boolean isRefreshing() {
final AsyncTwitterWrapper twitter = getTwitterWrapper();
return twitter != null && (twitter.isReceivedDirectMessagesRefreshing() || twitter.isSentDirectMessagesRefreshing());
}
public final LongSparseArray<Set<Long>> getUnreadCountsToRemove() {
return mUnreadCountsToRemove;
}
@ -162,37 +131,11 @@ public class DirectMessagesFragment extends BaseSupportFragment implements Loade
return false;
}
@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
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 Loader<Cursor> onCreateLoader(final int id, final Bundle args) {
final Uri uri = DirectMessages.ConversationEntries.CONTENT_URI;
final long[] accountIds = getAccountIds();
final boolean no_account_selected = accountIds.length == 0;
// setEmptyText(no_account_selected ? getString(R.string.no_account_selected) : null);
// if (!no_account_selected) {
// getListView().setEmptyView(null);
// }
final Expression account_where = Expression.in(new Column(Statuses.ACCOUNT_ID), new RawItemArray(accountIds));
return new CursorLoader(getActivity(), uri, null, account_where.getSQL(), null, null);
}
@ -201,17 +144,29 @@ public class DirectMessagesFragment extends BaseSupportFragment implements Loade
public void onLoadFinished(final Loader<Cursor> loader, final Cursor cursor) {
if (getActivity() == null) return;
mFirstVisibleItem = -1;
mAdapter.setCursor(cursor);
mAdapter.setLoadMoreIndicatorVisible(false);
mAdapter.setLoadMoreSupported(cursor != null && cursor.getCount() > 0);
mSwipeRefreshLayout.setEnabled(true);
// mAdapter.setShowAccountColor(getActivatedAccountIds(getActivity()).length > 1);
setListShown(true);
final MessageEntriesAdapter adapter = getAdapter();
adapter.setCursor(cursor);
adapter.setLoadMoreIndicatorVisible(false);
adapter.setLoadMoreSupported(cursor != null && cursor.getCount() > 0);
adapter.setLoadMoreSupported(hasMoreData(cursor));
final long[] accountIds = getAccountIds();
adapter.setShowAccountsColor(accountIds.length > 1);
setRefreshEnabled(true);
if (accountIds.length > 0) {
showContent();
} else {
showError(R.drawable.ic_info_account, getString(R.string.no_account_selected));
}
}
protected boolean hasMoreData(final Cursor cursor) {
return cursor != null && cursor.getCount() != 0;
}
@Override
public void onLoaderReset(final Loader<Cursor> loader) {
mAdapter.setCursor(null);
final MessageEntriesAdapter adapter = getAdapter();
adapter.setCursor(null);
}
@Override
@ -228,8 +183,8 @@ public class DirectMessagesFragment extends BaseSupportFragment implements Loade
public void onGetMessagesTaskChanged(GetMessagesTaskEvent event) {
if (event.uri.equals(Inbox.CONTENT_URI) && !event.running) {
setRefreshing(false);
mAdapter.setLoadMoreIndicatorVisible(false);
mSwipeRefreshLayout.setEnabled(true);
setLoadMoreIndicatorVisible(false);
setRefreshEnabled(true);
}
}
@ -240,13 +195,15 @@ public class DirectMessagesFragment extends BaseSupportFragment implements Loade
@Override
public boolean scrollToStart() {
final AsyncTwitterWrapper twitter = getTwitterWrapper();
final int tabPosition = getTabPosition();
if (twitter != null && tabPosition >= 0) {
twitter.clearUnreadCountAsync(tabPosition);
final boolean result = super.scrollToStart();
if (result) {
final AsyncTwitterWrapper twitter = getTwitterWrapper();
final int tabPosition = getTabPosition();
if (twitter != null && tabPosition >= 0) {
twitter.clearUnreadCountAsync(tabPosition);
}
}
mRecyclerView.smoothScrollToPosition(0);
return true;
return result;
}
@Override
@ -273,57 +230,30 @@ public class DirectMessagesFragment extends BaseSupportFragment implements Loade
return true;
}
@Override
public void setUserVisibleHint(final boolean isVisibleToUser) {
super.setUserVisibleHint(isVisibleToUser);
}
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
if (activity instanceof IControlBarActivity) {
((IControlBarActivity) activity).registerControlBarOffsetListener(this);
}
}
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_recycler_view, container, false);
}
@Override
public void onActivityCreated(final Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
final View view = getView();
if (view == null) throw new AssertionError();
final TwidereApplication application = TwidereApplication.getInstance(getActivity());
mPreferences = getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE);
final Context viewContext = view.getContext();
mMultiSelectManager = getMultiSelectManager();
mAdapter = new MessageEntriesAdapter(viewContext);
mAdapter.setListener(this);
mLayoutManager = new FixedLinearLayoutManager(viewContext);
mLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
mSwipeRefreshLayout.setOnRefreshListener(this);
mSwipeRefreshLayout.setColorSchemeColors(ThemeUtils.getUserAccentColor(viewContext));
mRecyclerView.setLayoutManager(mLayoutManager);
mRecyclerView.setAdapter(mAdapter);
mRecyclerViewNavigationHelper = new RecyclerViewNavigationHelper(mRecyclerView, mLayoutManager, mAdapter);
final MessageEntriesAdapter adapter = getAdapter();
final RecyclerView recyclerView = getRecyclerView();
final LinearLayoutManager layoutManager = getLayoutManager();
mRecyclerViewNavigationHelper = new RecyclerViewNavigationHelper(recyclerView, layoutManager, adapter);
final ContentListScrollListener scrollListener = new ContentListScrollListener(this);
scrollListener.setTouchSlop(ViewConfiguration.get(viewContext).getScaledTouchSlop());
// TODO remove scroll listener
mRecyclerView.addOnScrollListener(scrollListener);
adapter.setListener(this);
final DividerItemDecoration itemDecoration = new DividerItemDecoration(viewContext, mLayoutManager.getOrientation());
final DividerItemDecoration itemDecoration = new DividerItemDecoration(viewContext, layoutManager.getOrientation());
final Resources res = viewContext.getResources();
final int decorPaddingLeft = res.getDimensionPixelSize(R.dimen.element_spacing_normal) * 3
+ res.getDimensionPixelSize(R.dimen.icon_size_status_profile_image);
itemDecoration.setPadding(decorPaddingLeft, 0, 0, 0);
itemDecoration.setDecorationEndOffset(1);
mRecyclerView.addItemDecoration(itemDecoration);
recyclerView.addItemDecoration(itemDecoration);
getLoaderManager().initLoader(0, null, this);
setListShown(false);
showProgress();
}
@Override
@ -333,7 +263,8 @@ public class DirectMessagesFragment extends BaseSupportFragment implements Loade
resolver.registerContentObserver(Accounts.CONTENT_URI, true, mReloadContentObserver);
final Bus bus = TwidereApplication.getInstance(getActivity()).getMessageBus();
bus.register(this);
mAdapter.updateReadState();
final MessageEntriesAdapter adapter = getAdapter();
adapter.updateReadState();
updateRefreshState();
}
@ -346,14 +277,6 @@ public class DirectMessagesFragment extends BaseSupportFragment implements Loade
super.onStop();
}
@Override
public void onDetach() {
final FragmentActivity activity = getActivity();
if (activity instanceof IControlBarActivity) {
((IControlBarActivity) activity).unregisterControlBarOffsetListener(this);
}
super.onDetach();
}
@Override
public boolean onOptionsItemSelected(final MenuItem item) {
@ -408,8 +331,8 @@ public class DirectMessagesFragment extends BaseSupportFragment implements Loade
private void loadMoreMessages() {
if (isRefreshing()) return;
mAdapter.setLoadMoreIndicatorVisible(true);
mSwipeRefreshLayout.setEnabled(false);
setLoadMoreIndicatorVisible(true);
setRefreshEnabled(false);
AsyncTaskUtils.executeTask(new AsyncTask<Object, Object, long[][]>() {
@Override
@ -439,21 +362,6 @@ public class DirectMessagesFragment extends BaseSupportFragment implements Loade
AsyncTaskUtils.executeTask(mRemoveUnreadCountsTask);
}
private void setListShown(boolean shown) {
mProgressContainer.setVisibility(shown ? View.GONE : View.VISIBLE);
mSwipeRefreshLayout.setVisibility(shown ? View.VISIBLE : View.GONE);
}
private void updateRefreshProgressOffset() {
if (mSystemWindowsInsets.top == 0 || mSwipeRefreshLayout == null || isRefreshing()) return;
final float density = getResources().getDisplayMetrics().density;
final int progressCircleDiameter = mSwipeRefreshLayout.getProgressCircleDiameter();
final int swipeStart = (mSystemWindowsInsets.top - mControlBarOffsetPixels) - progressCircleDiameter;
// 64: SwipeRefreshLayout.DEFAULT_CIRCLE_TARGET
final int swipeDistance = Math.round(64 * density);
mSwipeRefreshLayout.setProgressViewOffset(true, swipeStart, swipeStart + swipeDistance);
}
static class RemoveUnreadCountsTask extends AsyncTask<Object, Object, Object> {
private final Set<Integer> read_positions;
private final MessageEntriesAdapter adapter;

View File

@ -116,6 +116,7 @@ public abstract class ParcelableStatusesFragment extends AbsStatusesFragment<Lis
@Override
protected void onLoadingFinished() {
showContent();
setRefreshEnabled(true);
setRefreshing(false);
setLoadMoreIndicatorVisible(false);

View File

@ -292,7 +292,7 @@ public class StatusFragment extends BaseSupportFragment implements LoaderCallbac
mStatusContent = view.findViewById(R.id.status_content);
mRecyclerView = (RecyclerView) view.findViewById(R.id.recycler_view);
mProgressContainer = view.findViewById(R.id.progress_container);
mErrorContainer = view.findViewById(R.id.error_retry_container);
mErrorContainer = view.findViewById(R.id.error_container);
}
@Override

View File

@ -177,12 +177,12 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener
private ImageView mProfileTypeView;
private ProfileBannerImageView mProfileBannerView;
private TextView mNameView, mScreenNameView, mDescriptionView, mLocationView, mURLView, mCreatedAtView,
mListedCount, mFollowersCount, mFriendsCount, mErrorMessageView;
mListedCount, mFollowersCount, mFriendsCount, mHeaderErrorTextView;
private View mDescriptionContainer, mLocationContainer, mURLContainer, mListedContainer, mFollowersContainer,
mFriendsContainer;
private Button mRetryButton;
private ImageView mHeaderErrorIcon;
private ColorLabelRelativeLayout mProfileNameContainer;
private View mProgressContainer, mErrorRetryContainer;
private View mProgressContainer, mHeaderErrorContainer;
private View mCardContent;
private View mProfileBannerSpace;
private TintedStatusFrameLayout mTintedStatusContent;
@ -322,10 +322,10 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener
final String screenName = args.getString(EXTRA_SCREEN_NAME);
if (mUser == null && (!omitIntentExtra || !args.containsKey(EXTRA_USER))) {
mCardContent.setVisibility(View.GONE);
mErrorRetryContainer.setVisibility(View.GONE);
mHeaderErrorContainer.setVisibility(View.GONE);
mProgressContainer.setVisibility(View.VISIBLE);
mErrorMessageView.setText(null);
mErrorMessageView.setVisibility(View.GONE);
mHeaderErrorTextView.setText(null);
mHeaderErrorTextView.setVisibility(View.GONE);
setListShown(false);
}
setProgressBarIndeterminateVisibility(true);
@ -346,7 +346,7 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener
if (data.hasData()) {
final ParcelableUser user = data.getData();
mCardContent.setVisibility(View.VISIBLE);
mErrorRetryContainer.setVisibility(View.GONE);
mHeaderErrorContainer.setVisibility(View.GONE);
mProgressContainer.setVisibility(View.GONE);
setListShown(true);
displayUser(user);
@ -360,17 +360,17 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener
}
} else if (mUser != null && mUser.is_cache) {
mCardContent.setVisibility(View.VISIBLE);
mErrorRetryContainer.setVisibility(View.GONE);
mHeaderErrorContainer.setVisibility(View.GONE);
mProgressContainer.setVisibility(View.GONE);
setListShown(true);
displayUser(mUser);
} else {
if (data.hasException()) {
mErrorMessageView.setText(Utils.getErrorMessage(getActivity(), data.getException()));
mErrorMessageView.setVisibility(View.VISIBLE);
mHeaderErrorTextView.setText(Utils.getErrorMessage(getActivity(), data.getException()));
mHeaderErrorTextView.setVisibility(View.VISIBLE);
}
mCardContent.setVisibility(View.GONE);
mErrorRetryContainer.setVisibility(View.VISIBLE);
mHeaderErrorContainer.setVisibility(View.VISIBLE);
mProgressContainer.setVisibility(View.GONE);
}
setProgressBarIndeterminateVisibility(false);
@ -496,7 +496,7 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener
lm.destroyLoader(LOADER_ID_FRIENDSHIP);
final boolean userIsMe = user.account_id == user.id;
mCardContent.setVisibility(View.VISIBLE);
mErrorRetryContainer.setVisibility(View.GONE);
mHeaderErrorContainer.setVisibility(View.GONE);
mProgressContainer.setVisibility(View.GONE);
mUser = user;
final int userColor = manager.getUserColor(user.id, true);
@ -592,7 +592,7 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener
}
if (accountId == -1 || userId == -1 && screenName == null) {
mCardContent.setVisibility(View.GONE);
mErrorRetryContainer.setVisibility(View.GONE);
mHeaderErrorContainer.setVisibility(View.GONE);
}
}
@ -766,7 +766,7 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener
mListedContainer.setOnClickListener(this);
mFollowersContainer.setOnClickListener(this);
mFriendsContainer.setOnClickListener(this);
mRetryButton.setOnClickListener(this);
mHeaderErrorIcon.setOnClickListener(this);
mProfileBannerView.setOnSizeChangedListener(this);
mProfileBannerSpace.setOnTouchListener(this);
@ -1040,10 +1040,10 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener
final View headerView = mHeaderDrawerLayout.getHeader();
final View contentView = mHeaderDrawerLayout.getContent();
mCardContent = headerView.findViewById(R.id.card_content);
mErrorRetryContainer = headerView.findViewById(R.id.error_retry_container);
mHeaderErrorContainer = headerView.findViewById(R.id.error_container);
mHeaderErrorTextView = (TextView) headerView.findViewById(R.id.error_text);
mHeaderErrorIcon = (ImageView) headerView.findViewById(R.id.error_icon);
mProgressContainer = headerView.findViewById(R.id.progress_container);
mRetryButton = (Button) headerView.findViewById(R.id.retry);
mErrorMessageView = (TextView) headerView.findViewById(R.id.error_message);
mProfileBannerView = (ProfileBannerImageView) view.findViewById(R.id.profile_banner);
mProfileBannerContainer = view.findViewById(R.id.profile_banner_container);
mNameView = (TextView) headerView.findViewById(R.id.name);
@ -1151,7 +1151,7 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener
final ParcelableUser user = getUser();
if (activity == null || user == null) return;
switch (view.getId()) {
case R.id.retry: {
case R.id.error_container: {
getUserInfo(true);
break;
}

View File

@ -106,10 +106,10 @@ public class UserListFragment extends BaseSupportFragment implements OnClickList
private AsyncTwitterWrapper mTwitterWrapper;
private ImageView mProfileImageView;
private TextView mListNameView, mCreatedByView, mDescriptionView, mErrorMessageView;
private View mErrorRetryContainer, mProgressContainer;
private TextView mListNameView, mCreatedByView, mDescriptionView, mErrorTextView;
private View mErrorContainer, mProgressContainer;
private ColorLabelLinearLayout mUserListDetails;
private Button mRetryButton;
private Button mErrorIconView;
private HeaderDrawerLayout mHeaderDrawerLayout;
private ViewPager mViewPager;
private TabPagerIndicator mPagerIndicator;
@ -197,7 +197,7 @@ public class UserListFragment extends BaseSupportFragment implements OnClickList
public void displayUserList(final ParcelableUserList userList) {
if (userList == null || getActivity() == null) return;
getLoaderManager().destroyLoader(0);
mErrorRetryContainer.setVisibility(View.GONE);
mErrorContainer.setVisibility(View.GONE);
mProgressContainer.setVisibility(View.GONE);
mUserList = userList;
mUserListDetails.drawEnd(getAccountColor(getActivity(), userList.account_id));
@ -326,7 +326,7 @@ public class UserListFragment extends BaseSupportFragment implements OnClickList
mProfileImageView.setOnClickListener(this);
mUserListDetails.setOnClickListener(this);
mRetryButton.setOnClickListener(this);
mErrorIconView.setOnClickListener(this);
getUserListInfo(false);
setupUserPages();
@ -461,7 +461,7 @@ public class UserListFragment extends BaseSupportFragment implements OnClickList
@Override
public void onClick(final View view) {
switch (view.getId()) {
case R.id.retry: {
case R.id.error_container: {
getUserListInfo(true);
break;
}
@ -477,9 +477,9 @@ public class UserListFragment extends BaseSupportFragment implements OnClickList
@Override
public Loader<SingleResponse<ParcelableUserList>> onCreateLoader(final int id, final Bundle args) {
mErrorMessageView.setText(null);
mErrorMessageView.setVisibility(View.GONE);
mErrorRetryContainer.setVisibility(View.GONE);
mErrorTextView.setText(null);
mErrorTextView.setVisibility(View.GONE);
mErrorContainer.setVisibility(View.GONE);
mHeaderDrawerLayout.setVisibility(View.GONE);
mProgressContainer.setVisibility(View.VISIBLE);
setProgressBarIndeterminateVisibility(true);
@ -502,15 +502,15 @@ public class UserListFragment extends BaseSupportFragment implements OnClickList
final ParcelableUserList list = data.getData();
displayUserList(list);
mHeaderDrawerLayout.setVisibility(View.VISIBLE);
mErrorRetryContainer.setVisibility(View.GONE);
mErrorContainer.setVisibility(View.GONE);
mProgressContainer.setVisibility(View.GONE);
} else {
if (data.hasException()) {
mErrorMessageView.setText(data.getException().getMessage());
mErrorMessageView.setVisibility(View.VISIBLE);
mErrorTextView.setText(data.getException().getMessage());
mErrorTextView.setVisibility(View.VISIBLE);
}
mHeaderDrawerLayout.setVisibility(View.GONE);
mErrorRetryContainer.setVisibility(View.VISIBLE);
mErrorContainer.setVisibility(View.VISIBLE);
mProgressContainer.setVisibility(View.GONE);
}
setProgressBarIndeterminateVisibility(false);
@ -525,7 +525,7 @@ public class UserListFragment extends BaseSupportFragment implements OnClickList
public void onBaseViewCreated(final View view, final Bundle savedInstanceState) {
super.onBaseViewCreated(view, savedInstanceState);
mHeaderDrawerLayout = (HeaderDrawerLayout) view.findViewById(R.id.details_container);
mErrorRetryContainer = view.findViewById(R.id.error_retry_container);
mErrorContainer = view.findViewById(R.id.error_container);
mProgressContainer = view.findViewById(R.id.progress_container);
final View headerView = mHeaderDrawerLayout.getHeader();
@ -536,8 +536,8 @@ public class UserListFragment extends BaseSupportFragment implements OnClickList
mCreatedByView = (TextView) headerView.findViewById(R.id.created_by);
mDescriptionView = (TextView) headerView.findViewById(R.id.description);
mProfileImageView = (ImageView) headerView.findViewById(R.id.profile_image);
mRetryButton = (Button) mErrorRetryContainer.findViewById(R.id.retry);
mErrorMessageView = (TextView) mErrorRetryContainer.findViewById(R.id.error_message);
mErrorIconView = (Button) mErrorContainer.findViewById(R.id.error_icon);
mErrorTextView = (TextView) mErrorContainer.findViewById(R.id.error_text);
mViewPager = (ViewPager) contentView.findViewById(R.id.view_pager);
mPagerIndicator = (TabPagerIndicator) contentView.findViewById(R.id.view_pager_tabs);
}
@ -545,7 +545,7 @@ public class UserListFragment extends BaseSupportFragment implements OnClickList
@Override
protected void fitSystemWindows(Rect insets) {
super.fitSystemWindows(insets);
final View progress = mProgressContainer, error = mErrorRetryContainer;
final View progress = mProgressContainer, error = mErrorContainer;
final HeaderDrawerLayout content = mHeaderDrawerLayout;
if (progress == null || error == null || content == null) {
return;

View File

@ -17,36 +17,30 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.mariotaku.twidere.menu;
package org.mariotaku.twidere.menu.support;
import android.content.Context;
import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.v4.view.ActionProvider;
import android.view.Menu;
import android.view.MenuItem;
import android.view.SubMenu;
import android.view.View;
import org.apache.commons.lang3.ArrayUtils;
import org.mariotaku.twidere.TwidereConstants;
import org.mariotaku.twidere.model.ParcelableAccount;
public class SupportAccountActionProvider extends ActionProvider implements TwidereConstants {
public class AccountToggleProvider extends ActionProvider implements TwidereConstants {
public static final int MENU_GROUP = 201;
private ParcelableAccount[] mAccounts;
private long[] mAccountIds;
private boolean mExclusive;
public SupportAccountActionProvider(final Context context, final ParcelableAccount[] accounts) {
public AccountToggleProvider(final Context context) {
super(context);
setAccounts(accounts);
}
public SupportAccountActionProvider(final Context context) {
this(context, ParcelableAccount.getAccounts(context, false, false));
}
public ParcelableAccount[] getAccounts() {
@ -57,6 +51,7 @@ public class SupportAccountActionProvider extends ActionProvider implements Twid
mAccounts = accounts;
}
@NonNull
public long[] getActivatedAccountIds() {
if (mAccounts == null) return new long[0];
long[] temp = new long[mAccounts.length];
@ -106,17 +101,20 @@ public class SupportAccountActionProvider extends ActionProvider implements Twid
item.setIntent(intent);
}
subMenu.setGroupCheckable(MENU_GROUP, true, mExclusive);
if (mAccountIds == null) return;
for (int i = 0, j = subMenu.size(); i < j; i++) {
final MenuItem item = subMenu.getItem(i);
if (ArrayUtils.contains(mAccountIds, mAccounts[i].account_id)) {
if (mAccounts[i].is_activated) {
item.setChecked(true);
}
}
}
public void setSelectedAccountIds(final long... accountIds) {
mAccountIds = accountIds;
public void setAccountActivated(long accountId, boolean isChecked) {
if (mAccounts == null) return;
for (final ParcelableAccount account : mAccounts) {
if (account.account_id == accountId) {
account.is_activated = isChecked;
}
}
}
}

View File

@ -36,7 +36,6 @@ public class ContentListScrollListener extends OnScrollListener {
private int mTouchSlop;
private ContentListSupport mContentListSupport;
private OnScrollListener mOnScrollListener;
public ContentListScrollListener(@NonNull ContentListSupport contentListSupport) {
mContentListSupport = contentListSupport;
@ -44,9 +43,6 @@ public class ContentListScrollListener extends OnScrollListener {
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
if (mOnScrollListener != null) {
mOnScrollListener.onScrollStateChanged(recyclerView, newState);
}
if (mScrollState != RecyclerView.SCROLL_STATE_IDLE) {
notifyScrollStateChanged(recyclerView);
}
@ -55,9 +51,6 @@ public class ContentListScrollListener extends OnScrollListener {
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
if (mOnScrollListener != null) {
mOnScrollListener.onScrolled(recyclerView, dx, dy);
}
//Reset mScrollSum when scrolling in reverse direction
if (dy * mScrollSum < 0) {
mScrollSum = 0;
@ -72,10 +65,6 @@ public class ContentListScrollListener extends OnScrollListener {
}
}
public void setOnScrollListener(OnScrollListener listener) {
mOnScrollListener = listener;
}
public void setTouchSlop(int touchSlop) {
mTouchSlop = touchSlop;
}

View File

@ -0,0 +1,32 @@
/*
* Twidere - Twitter client for Android
*
* Copyright (C) 2012-2015 Mariotaku Lee <mariotaku.lee@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.mariotaku.twidere.util.message;
/**
* Created by mariotaku on 15/4/24.
*/
public class AccountChangedEvent {
public final long[] account_ids, activated_ids;
public AccountChangedEvent(long[] account_ids, long[] activated_ids) {
this.account_ids = account_ids;
this.activated_ids = activated_ids;
}
}

View File

@ -21,7 +21,6 @@ package org.mariotaku.twidere.view.holder;
import android.content.Context;
import android.database.Cursor;
import android.graphics.Color;
import android.graphics.Typeface;
import android.support.v7.widget.RecyclerView.ViewHolder;
import android.view.View;
@ -47,7 +46,6 @@ public class MessageEntryViewHolder extends ViewHolder implements OnClickListene
public final ShortTimeView timeView;
private final MessageEntriesAdapter adapter;
private final IColorLabelView content;
private boolean account_color_enabled;
public MessageEntryViewHolder(final MessageEntriesAdapter adapter, final View itemView) {
super(itemView);
@ -89,8 +87,10 @@ public class MessageEntryViewHolder extends ViewHolder implements OnClickListene
nameView.setTypeface(null, isUnread && !isOutgoing ? Typeface.BOLD : Typeface.NORMAL);
screenNameView.setTypeface(null, isUnread && !isOutgoing ? Typeface.BOLD : Typeface.NORMAL);
textView.setTypeface(null, isUnread && !isOutgoing ? Typeface.BOLD : Typeface.NORMAL);
if (account_color_enabled) {
if (adapter.shouldShowAccountsColor()) {
content.drawEnd(Utils.getAccountColor(context, accountId));
} else {
content.drawEnd();
}
content.drawStart(manager.getUserColor(conversationId, false));
@ -114,14 +114,6 @@ public class MessageEntryViewHolder extends ViewHolder implements OnClickListene
}
}
public void setAccountColorEnabled(final boolean enabled) {
if (account_color_enabled == enabled) return;
account_color_enabled = enabled;
if (!account_color_enabled) {
content.drawEnd(Color.TRANSPARENT);
}
}
public void setTextSize(final float textSize) {
nameView.setTextSize(textSize * 1.1f);
screenNameView.setTextSize(textSize);
@ -129,7 +121,4 @@ public class MessageEntryViewHolder extends ViewHolder implements OnClickListene
timeView.setTextSize(textSize * 0.85f);
}
public void setUserColor(final int color) {
// content.drawStart(color);
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 596 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 637 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

@ -36,7 +36,7 @@
</FrameLayout>
<LinearLayout
android:id="@+id/error_retry_container"
android:id="@+id/error_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
@ -44,22 +44,20 @@
android:padding="@dimen/element_spacing_large"
android:visibility="gone">
<TextView
android:id="@+id/error_message"
<org.mariotaku.twidere.view.ActionIconView
android:id="@+id/error_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:visibility="gone"/>
android:color="?android:textColorSecondary"
android:src="@drawable/ic_info_error_generic"/>
<Button
android:id="@+id/retry"
<TextView
android:id="@+id/error_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minHeight="48dp"
android:minWidth="84dp"
android:text="@string/retry"
android:textAppearance="?android:attr/textAppearanceSmall"/>
android:layout_gravity="center"
android:layout_marginTop="@dimen/element_spacing_normal"
android:textAppearance="?android:textAppearanceMedium"/>
</LinearLayout>
</merge>

View File

@ -1,5 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
<?xml version="1.0" encoding="utf-8"?><!--
~ Twidere - Twitter client for Android
~
~ Copyright (C) 2012-2015 Mariotaku Lee <mariotaku.lee@gmail.com>
@ -19,14 +18,14 @@
-->
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@id/select_account"
android:icon="@drawable/ic_action_more_vertical"
android:title="@string/select_account"
app:actionProviderClass="org.mariotaku.twidere.menu.SupportAccountActionProvider"
app:showAsAction="always"/>
app:actionProviderClass="org.mariotaku.twidere.menu.support.AccountToggleProvider"
app:showAsAction="always" />
</menu>