diff --git a/twidere/src/main/java/org/mariotaku/twidere/adapter/MessageEntriesAdapter.java b/twidere/src/main/java/org/mariotaku/twidere/adapter/MessageEntriesAdapter.java index 673b34d1f..9a2553858 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/adapter/MessageEntriesAdapter.java +++ b/twidere/src/main/java/org/mariotaku/twidere/adapter/MessageEntriesAdapter.java @@ -69,6 +69,7 @@ public class MessageEntriesAdapter extends Adapter 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 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); diff --git a/twidere/src/main/java/org/mariotaku/twidere/adapter/support/SupportTabsAdapter.java b/twidere/src/main/java/org/mariotaku/twidere/adapter/support/SupportTabsAdapter.java index 9b4c1489e..c58df8e5a 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/adapter/support/SupportTabsAdapter.java +++ b/twidere/src/main/java/org/mariotaku/twidere/adapter/support/SupportTabsAdapter.java @@ -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()); } diff --git a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/AbsContentListFragment.java b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/AbsContentListFragment.java index 2a3934ad3..b75e45c1a 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/AbsContentListFragment.java +++ b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/AbsContentListFragment.java @@ -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 extends BaseSupportFragment implements OnRefreshListener, - DrawerCallback, RefreshScrollTopInterface, ControlBarOffsetListener, ContentListSupport { +public abstract class AbsContentListFragment 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 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 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 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 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 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 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() { diff --git a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/AbsStatusesFragment.java b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/AbsStatusesFragment.java index 216559669..b75c03c4b 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/AbsStatusesFragment.java +++ b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/AbsStatusesFragment.java @@ -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 extends AbsContentListFragment extends AbsContentListFragment extends AbsContentListFragment extends AbsContentListFragment extends AbsContentListFragment extends AbsContentListFragment extends AbsContentListFragment 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() { diff --git a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/AbsUsersFragment.java b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/AbsUsersFragment.java index 6e43ea14c..f1f1403fe 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/AbsUsersFragment.java +++ b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/AbsUsersFragment.java @@ -95,7 +95,7 @@ abstract class AbsUsersFragment extends AbsContentListFragment, - 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 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 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; } diff --git a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/CursorStatusesFragment.java b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/CursorStatusesFragment.java index b45a3a42d..74c3761d3 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/CursorStatusesFragment.java +++ b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/CursorStatusesFragment.java @@ -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 @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 public void notifyStatusRetweeted(StatusRetweetedEvent event) { } + @Subscribe + public void notifyAccountChanged(AccountChangedEvent event) { + + } + } @Override diff --git a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/DirectMessagesFragment.java b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/DirectMessagesFragment.java index 250e91a91..8496cc3c1 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/DirectMessagesFragment.java +++ b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/DirectMessagesFragment.java @@ -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, - RefreshScrollTopInterface, OnRefreshListener, MessageEntriesAdapterListener, - ControlBarOffsetListener, ContentListSupport, KeyboardShortcutCallback { +public class DirectMessagesFragment extends AbsContentListFragment + implements LoaderCallbacks, 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> mUnreadCountsToRemove = new LongSparseArray<>(); private final Set mReadPositions = Collections.synchronizedSet(new HashSet()); - 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> 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 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 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 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() { @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 { private final Set read_positions; private final MessageEntriesAdapter adapter; diff --git a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/ParcelableStatusesFragment.java b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/ParcelableStatusesFragment.java index 0f10f6a6c..f7e247b08 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/ParcelableStatusesFragment.java +++ b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/ParcelableStatusesFragment.java @@ -116,6 +116,7 @@ public abstract class ParcelableStatusesFragment extends AbsStatusesFragment> 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; diff --git a/twidere/src/main/java/org/mariotaku/twidere/menu/SupportAccountActionProvider.java b/twidere/src/main/java/org/mariotaku/twidere/menu/support/AccountToggleProvider.java similarity index 81% rename from twidere/src/main/java/org/mariotaku/twidere/menu/SupportAccountActionProvider.java rename to twidere/src/main/java/org/mariotaku/twidere/menu/support/AccountToggleProvider.java index c23021d3b..dff03d20a 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/menu/SupportAccountActionProvider.java +++ b/twidere/src/main/java/org/mariotaku/twidere/menu/support/AccountToggleProvider.java @@ -17,36 +17,30 @@ * along with this program. If not, see . */ -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; + } + } } - } diff --git a/twidere/src/main/java/org/mariotaku/twidere/util/ContentListScrollListener.java b/twidere/src/main/java/org/mariotaku/twidere/util/ContentListScrollListener.java index c56cc1907..cbc5abafd 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/util/ContentListScrollListener.java +++ b/twidere/src/main/java/org/mariotaku/twidere/util/ContentListScrollListener.java @@ -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; } diff --git a/twidere/src/main/java/org/mariotaku/twidere/util/message/AccountChangedEvent.java b/twidere/src/main/java/org/mariotaku/twidere/util/message/AccountChangedEvent.java new file mode 100644 index 000000000..d4205f816 --- /dev/null +++ b/twidere/src/main/java/org/mariotaku/twidere/util/message/AccountChangedEvent.java @@ -0,0 +1,32 @@ +/* + * Twidere - Twitter client for Android + * + * Copyright (C) 2012-2015 Mariotaku Lee + * + * 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 . + */ + +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; + } +} diff --git a/twidere/src/main/java/org/mariotaku/twidere/view/holder/MessageEntryViewHolder.java b/twidere/src/main/java/org/mariotaku/twidere/view/holder/MessageEntryViewHolder.java index 3f8de9926..3dca8a5c7 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/view/holder/MessageEntryViewHolder.java +++ b/twidere/src/main/java/org/mariotaku/twidere/view/holder/MessageEntryViewHolder.java @@ -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); - } } diff --git a/twidere/src/main/res/drawable-hdpi/ic_info_account.png b/twidere/src/main/res/drawable-hdpi/ic_info_account.png new file mode 100755 index 000000000..f34280f86 Binary files /dev/null and b/twidere/src/main/res/drawable-hdpi/ic_info_account.png differ diff --git a/twidere/src/main/res/drawable-mdpi/ic_info_account.png b/twidere/src/main/res/drawable-mdpi/ic_info_account.png new file mode 100755 index 000000000..95bddb531 Binary files /dev/null and b/twidere/src/main/res/drawable-mdpi/ic_info_account.png differ diff --git a/twidere/src/main/res/drawable-xhdpi/ic_info_account.png b/twidere/src/main/res/drawable-xhdpi/ic_info_account.png new file mode 100755 index 000000000..c60a23669 Binary files /dev/null and b/twidere/src/main/res/drawable-xhdpi/ic_info_account.png differ diff --git a/twidere/src/main/res/drawable-xxhdpi/ic_info_account.png b/twidere/src/main/res/drawable-xxhdpi/ic_info_account.png new file mode 100755 index 000000000..e5038dd83 Binary files /dev/null and b/twidere/src/main/res/drawable-xxhdpi/ic_info_account.png differ diff --git a/twidere/src/main/res/layout/layout_content_fragment_common.xml b/twidere/src/main/res/layout/layout_content_fragment_common.xml index 662d4b554..c7b67d9c1 100644 --- a/twidere/src/main/res/layout/layout_content_fragment_common.xml +++ b/twidere/src/main/res/layout/layout_content_fragment_common.xml @@ -36,7 +36,7 @@ - + android:color="?android:textColorSecondary" + android:src="@drawable/ic_info_error_generic"/> -