migrating users list to RecyclerView

This commit is contained in:
Mariotaku Lee 2015-04-16 22:14:40 +08:00
parent eb82d1eee7
commit 0e452a4f59
49 changed files with 620 additions and 503 deletions

View File

@ -21,6 +21,7 @@ package org.mariotaku.twidere.adapter;
import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.CardView;
import android.support.v7.widget.RecyclerView.ViewHolder;
import android.view.LayoutInflater;
import android.view.View;
@ -97,6 +98,10 @@ public abstract class AbsUsersAdapter<D> extends LoadMoreSupportAdapter<ViewHold
public abstract D getData();
public boolean isUser(int position) {
return position < getUsersCount();
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
switch (viewType) {
@ -104,16 +109,16 @@ public abstract class AbsUsersAdapter<D> extends LoadMoreSupportAdapter<ViewHold
final View view;
if (mCompactCards) {
view = mInflater.inflate(R.layout.card_item_user_compact, parent, false);
// final View itemContent = view.findViewById(R.id.item_content);
// itemContent.setBackgroundColor(mCardBackgroundColor);
final View itemContent = view.findViewById(R.id.item_content);
itemContent.setBackgroundColor(mCardBackgroundColor);
} else {
view = mInflater.inflate(R.layout.card_item_user, parent, false);
// final CardView cardView = (CardView) view.findViewById(R.id.card);
// cardView.setCardBackgroundColor(mCardBackgroundColor);
final CardView cardView = (CardView) view.findViewById(R.id.card);
cardView.setCardBackgroundColor(mCardBackgroundColor);
}
final UserViewHolder holder = new UserViewHolder(this, view);
// holder.setOnClickListeners();
// holder.setupViewOptions();
holder.setOnClickListeners();
holder.setupViewOptions();
return holder;
}
case ITEM_VIEW_TYPE_LOAD_INDICATOR: {
@ -134,10 +139,6 @@ public abstract class AbsUsersAdapter<D> extends LoadMoreSupportAdapter<ViewHold
}
}
public boolean isUser(int position) {
return position < getUsersCount();
}
@Override
public int getItemViewType(int position) {
if (position == getUsersCount()) {
@ -146,6 +147,26 @@ public abstract class AbsUsersAdapter<D> extends LoadMoreSupportAdapter<ViewHold
return ITEM_VIEW_TYPE_USER;
}
@Override
public void onItemActionClick(ViewHolder holder, int id, int position) {
}
@Override
public void onItemMenuClick(ViewHolder holder, View menuView, int position) {
}
@Override
public void onUserClick(UserViewHolder holder, int position) {
}
@Override
public boolean onUserLongClick(UserViewHolder holder, int position) {
return false;
}
@Override
public boolean shouldShowAccountsColor() {
return false;

View File

@ -20,6 +20,8 @@
package org.mariotaku.twidere.adapter;
import android.content.Context;
import android.support.v7.widget.RecyclerView.ViewHolder;
import android.view.View;
import org.mariotaku.twidere.model.ParcelableUser;
import org.mariotaku.twidere.view.holder.UserViewHolder;
@ -40,6 +42,7 @@ public class ParcelableUsersAdapter extends AbsUsersAdapter<List<ParcelableUser>
return mData;
}
@Override
public void setData(List<ParcelableUser> data) {
mData = data;

View File

@ -21,12 +21,12 @@ package org.mariotaku.twidere.adapter.iface;
import org.mariotaku.twidere.model.ParcelableUser;
import org.mariotaku.twidere.util.MediaLoaderWrapper;
import org.mariotaku.twidere.util.MediaLoadingHandler;
import org.mariotaku.twidere.view.holder.UserViewHolder.UserClickListener;
/**
* Created by mariotaku on 15/4/16.
*/
public interface IUsersAdapter<Data> extends IContentCardAdapter {
public interface IUsersAdapter<Data> extends IContentCardAdapter, UserClickListener {
ParcelableUser getUser(int position);

View File

@ -258,7 +258,7 @@ public abstract class AbsStatusesFragment<Data> extends AbsContentListFragment<A
}
}
public abstract Loader<Data> onCreateStatusesLoader(final Context context, final Bundle args,
protected abstract Loader<Data> onCreateStatusesLoader(final Context context, final Bundle args,
final boolean fromUser);
@Override

View File

@ -38,22 +38,23 @@ abstract class AbsUsersFragment<Data> extends AbsContentListFragment<AbsUsersAda
return getAdapter().getData();
}
@Override
public Loader<Data> onCreateLoader(int id, Bundle args) {
return newLoaderInstance(getActivity(), args);
}
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
final Bundle loaderArgs = new Bundle(getArguments());
loaderArgs.putBoolean(EXTRA_FROM_USER, true);
getLoaderManager().initLoader(0, loaderArgs, this);
}
@Override
public final void onLoadFinished(Loader<Data> loader, Data data) {
public final Loader<Data> onCreateLoader(int id, Bundle args) {
final boolean fromUser = args.getBoolean(EXTRA_FROM_USER);
args.remove(EXTRA_FROM_USER);
return onCreateUsersLoader(getActivity(), args, fromUser);
}
@Override
public void onLoadFinished(Loader<Data> loader, Data data) {
final AbsUsersAdapter<Data> adapter = getAdapter();
final long lastReadId;
final int lastVisiblePos, lastVisibleTop;
@ -86,11 +87,8 @@ abstract class AbsUsersFragment<Data> extends AbsContentListFragment<AbsUsersAda
((IExtendedLoader) loader).setFromUser(false);
}
setListShown(true);
onLoadingFinished(data);
}
protected abstract boolean hasMoreData(Data data);
@Override
public void onLoaderReset(Loader<Data> loader) {
if (loader instanceof IExtendedLoader) {
@ -103,8 +101,8 @@ abstract class AbsUsersFragment<Data> extends AbsContentListFragment<AbsUsersAda
return null;
}
protected abstract Loader<Data> newLoaderInstance(Context context, Bundle args);
protected abstract boolean hasMoreData(Data data);
protected abstract void onLoadingFinished(Data data);
protected abstract Loader<Data> onCreateUsersLoader(Context context, Bundle args, boolean fromUser);
}

View File

@ -69,7 +69,7 @@ public abstract class CursorStatusesFragment extends AbsStatusesFragment<Cursor>
public abstract Uri getContentUri();
@Override
public Loader<Cursor> onCreateStatusesLoader(final Context context,
protected Loader<Cursor> onCreateStatusesLoader(final Context context,
final Bundle args,
final boolean fromUser) {
final Uri uri = getContentUri();

View File

@ -30,57 +30,66 @@ import java.util.List;
public abstract class CursorSupportUsersListFragment extends ParcelableUsersFragment {
private long mNextCursor, mPrevCursor;
private long mNextCursor, mPrevCursor;
@Override
public void onActivityCreated(final Bundle savedInstanceState) {
if (savedInstanceState != null) {
mNextCursor = savedInstanceState.getLong(EXTRA_NEXT_CURSOR, -1);
mPrevCursor = savedInstanceState.getLong(EXTRA_PREV_CURSOR, -1);
} else {
mNextCursor = -1;
mPrevCursor = -1;
}
super.onActivityCreated(savedInstanceState);
}
@Override
public void onActivityCreated(final Bundle savedInstanceState) {
if (savedInstanceState != null) {
mNextCursor = savedInstanceState.getLong(EXTRA_NEXT_CURSOR, -1);
mPrevCursor = savedInstanceState.getLong(EXTRA_PREV_CURSOR, -1);
} else {
mNextCursor = -1;
mPrevCursor = -1;
}
super.onActivityCreated(savedInstanceState);
}
@Override
public void onDestroyView() {
super.onDestroyView();
mNextCursor = -1;
mPrevCursor = -1;
}
@Override
public void onDestroyView() {
super.onDestroyView();
mNextCursor = -1;
mPrevCursor = -1;
}
@Override
public void onLoaderReset(final Loader<List<ParcelableUser>> loader) {
super.onLoaderReset(loader);
mNextCursor = -1;
mPrevCursor = -1;
}
@Override
public void onLoaderReset(final Loader<List<ParcelableUser>> loader) {
super.onLoaderReset(loader);
mNextCursor = -1;
mPrevCursor = -1;
}
// @Override
// public void onLoadFinished(final Loader<List<ParcelableUser>> loader, final List<ParcelableUser> data) {
// super.onLoadFinished(loader, data);
// final BaseCursorSupportUsersLoader cursorLoader = (BaseCursorSupportUsersLoader) loader;
// mNextCursor = cursorLoader.getNextCursor();
// mPrevCursor = cursorLoader.getPrevCursor();
// }
@Override
public void onLoadFinished(final Loader<List<ParcelableUser>> loader, final List<ParcelableUser> data) {
super.onLoadFinished(loader, data);
final BaseCursorSupportUsersLoader cursorLoader = (BaseCursorSupportUsersLoader) loader;
mNextCursor = cursorLoader.getNextCursor();
mPrevCursor = cursorLoader.getPrevCursor();
}
@Override
public void onSaveInstanceState(final Bundle outState) {
super.onSaveInstanceState(outState);
outState.putLong(EXTRA_NEXT_CURSOR, mNextCursor);
outState.putLong(EXTRA_PREV_CURSOR, mPrevCursor);
}
@Override
public void onLoadMoreContents() {
super.onLoadMoreContents();
final Bundle loaderArgs = new Bundle(getArguments());
loaderArgs.putBoolean(EXTRA_FROM_USER, true);
loaderArgs.putLong(EXTRA_NEXT_CURSOR, mNextCursor);
getLoaderManager().restartLoader(0, loaderArgs, this);
}
protected final long getNextCursor() {
return mNextCursor;
}
@Override
public void onSaveInstanceState(final Bundle outState) {
super.onSaveInstanceState(outState);
outState.putLong(EXTRA_NEXT_CURSOR, mNextCursor);
outState.putLong(EXTRA_PREV_CURSOR, mPrevCursor);
}
protected final long getPrevCursor() {
return mPrevCursor;
}
protected final long getNextCursor() {
return mNextCursor;
}
@Override
protected abstract BaseCursorSupportUsersLoader newLoaderInstance(final Context context, final Bundle args);
protected final long getPrevCursor() {
return mPrevCursor;
}
@Override
protected abstract BaseCursorSupportUsersLoader onCreateUsersLoader(final Context context, final Bundle args, boolean fromUser);
}

View File

@ -28,10 +28,10 @@ import org.mariotaku.twidere.loader.support.IncomingFriendshipsLoader;
public class IncomingFriendshipsFragment extends CursorSupportUsersListFragment {
@Override
public IDsUsersLoader newLoaderInstance(final Context context, final Bundle args) {
public IDsUsersLoader onCreateUsersLoader(final Context context, final Bundle args, boolean fromUser) {
if (args == null) return null;
final long accountId = args.getLong(EXTRA_ACCOUNT_ID, -1);
return new IncomingFriendshipsLoader(context, accountId, getNextCursor(), getData());
return new IncomingFriendshipsLoader(context, accountId, getNextCursor(), getData(), fromUser);
}
}

View File

@ -164,7 +164,8 @@ public class MessagesConversationFragment extends BaseSupportFragment implements
final long accountId = args.getLong(EXTRA_ACCOUNT_ID);
final String query = args.getString(EXTRA_QUERY);
final boolean fromCache = args.getBoolean(EXTRA_FROM_CACHE);
return new CacheUserSearchLoader(getActivity(), accountId, query, fromCache);
final boolean fromUser = args.getBoolean(EXTRA_FROM_USER, false);
return new CacheUserSearchLoader(getActivity(), accountId, query, fromCache, fromUser);
}
@Override
@ -739,8 +740,8 @@ public class MessagesConversationFragment extends BaseSupportFragment implements
public static class CacheUserSearchLoader extends UserSearchLoader {
private final boolean mFromCache;
public CacheUserSearchLoader(Context context, long accountId, String query, boolean fromCache) {
super(context, accountId, query, 0, null);
public CacheUserSearchLoader(Context context, long accountId, String query, boolean fromCache, boolean fromUser) {
super(context, accountId, query, 0, null, fromUser);
mFromCache = fromCache;
}

View File

@ -28,10 +28,10 @@ import org.mariotaku.twidere.loader.support.MutesUsersLoader;
public class MutesUsersListFragment extends CursorSupportUsersListFragment {
@Override
public CursorSupportUsersLoader newLoaderInstance(final Context context, final Bundle args) {
public CursorSupportUsersLoader onCreateUsersLoader(final Context context, final Bundle args, boolean fromUser) {
if (args == null) return null;
final long account_id = args.getLong(EXTRA_ACCOUNT_ID, -1);
return new MutesUsersLoader(context, account_id, getNextCursor(), getData());
return new MutesUsersLoader(context, account_id, getNextCursor(), getData(), fromUser);
}
}

View File

@ -126,7 +126,7 @@ public abstract class ParcelableStatusesFragment extends AbsStatusesFragment<Lis
public void onLoadMoreContents() {
super.onLoadMoreContents();
final IStatusesAdapter<List<ParcelableStatus>> adapter = getAdapter();
final long[] maxIds = new long[]{adapter.getStatus(adapter.getStatusesCount() - 1).id};
final long[] maxIds = new long[]{adapter.getStatusId(adapter.getStatusesCount() - 1)};
getStatuses(null, maxIds, null);
}

View File

@ -23,6 +23,7 @@ import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.LoaderManager;
import android.support.v4.content.Loader;
import org.mariotaku.twidere.adapter.ParcelableUsersAdapter;
import org.mariotaku.twidere.model.ParcelableUser;
@ -43,6 +44,7 @@ public abstract class ParcelableUsersFragment extends AbsUsersFragment<List<Parc
return new ParcelableUsersAdapter(context, compact);
}
@Override
public boolean triggerRefresh() {
return false;
@ -55,11 +57,12 @@ public abstract class ParcelableUsersFragment extends AbsUsersFragment<List<Parc
@Override
protected boolean hasMoreData(List<ParcelableUser> data) {
return data == null || data.isEmpty();
return data == null || !data.isEmpty();
}
@Override
protected void onLoadingFinished(List<ParcelableUser> data) {
public void onLoadFinished(Loader<List<ParcelableUser>> loader, List<ParcelableUser> data) {
super.onLoadFinished(loader, data);
setRefreshEnabled(true);
setRefreshing(false);
setLoadMoreIndicatorVisible(false);

View File

@ -31,7 +31,7 @@ import java.util.List;
public class RetweetsOfMeFragment extends ParcelableStatusesFragment {
@Override
public Loader<List<ParcelableStatus>> onCreateStatusesLoader(final Context context,
protected Loader<List<ParcelableStatus>> onCreateStatusesLoader(final Context context,
final Bundle args,
final boolean fromUser) {
final long accountId = args.getLong(EXTRA_ACCOUNT_ID, -1);

View File

@ -23,6 +23,7 @@ import android.content.Context;
import android.os.Bundle;
import android.support.v4.content.Loader;
import org.mariotaku.twidere.loader.iface.IExtendedLoader;
import org.mariotaku.twidere.loader.support.UserSearchLoader;
import org.mariotaku.twidere.model.ParcelableUser;
@ -32,14 +33,6 @@ public class SearchUsersFragment extends ParcelableUsersFragment {
private int mPage = 1;
@Override
public Loader<List<ParcelableUser>> newLoaderInstance(final Context context, final Bundle args) {
if (args == null) return null;
final long account_id = args.getLong(EXTRA_ACCOUNT_ID);
final String query = args.getString(EXTRA_QUERY);
return new UserSearchLoader(context, account_id, query, mPage, getData());
}
@Override
public void onActivityCreated(final Bundle savedInstanceState) {
if (savedInstanceState != null) {
@ -49,22 +42,40 @@ public class SearchUsersFragment extends ParcelableUsersFragment {
}
@Override
public void onDestroyView() {
mPage = 1;
super.onDestroyView();
public Loader<List<ParcelableUser>> onCreateUsersLoader(final Context context, final Bundle args, boolean fromUser) {
if (args == null) return null;
final long account_id = args.getLong(EXTRA_ACCOUNT_ID);
final String query = args.getString(EXTRA_QUERY);
return new UserSearchLoader(context, account_id, query, mPage, getData(), fromUser);
}
@Override
public void onLoadingFinished(final List<ParcelableUser> data) {
if (data != null) {
public void onLoadFinished(final Loader<List<ParcelableUser>> loader, final List<ParcelableUser> data) {
super.onLoadFinished(loader, data);
if (loader instanceof IExtendedLoader && ((IExtendedLoader) loader).isFromUser() && data != null) {
mPage++;
}
}
@Override
public void onLoadMoreContents() {
super.onLoadMoreContents();
final Bundle loaderArgs = new Bundle(getArguments());
loaderArgs.putBoolean(EXTRA_FROM_USER, true);
loaderArgs.putLong(EXTRA_PAGE, mPage);
getLoaderManager().restartLoader(0, loaderArgs, this);
}
@Override
public void onSaveInstanceState(final Bundle outState) {
outState.putInt(EXTRA_PAGE, mPage);
super.onSaveInstanceState(outState);
}
@Override
public void onDestroyView() {
mPage = 1;
super.onDestroyView();
}
}

View File

@ -28,11 +28,11 @@ import org.mariotaku.twidere.loader.support.StatusFavoritersLoader;
public class StatusFavoritersListFragment extends CursorSupportUsersListFragment {
@Override
public IDsUsersLoader newLoaderInstance(final Context context, final Bundle args) {
public IDsUsersLoader onCreateUsersLoader(final Context context, final Bundle args, boolean fromUser) {
if (args == null) return null;
final long account_id = args.getLong(EXTRA_ACCOUNT_ID, -1);
final long status_id = args.getLong(EXTRA_STATUS_ID, -1);
return new StatusFavoritersLoader(context, account_id, status_id, getNextCursor(), getData());
return new StatusFavoritersLoader(context, account_id, status_id, getNextCursor(), getData(), false);
}
}

View File

@ -31,7 +31,7 @@ import java.util.List;
public class StatusRepliesListFragment extends StatusesSearchFragment {
@Override
public Loader<List<ParcelableStatus>> onCreateStatusesLoader(final Context context,
protected Loader<List<ParcelableStatus>> onCreateStatusesLoader(final Context context,
final Bundle args,
final boolean fromUser) {
final long accountId = args.getLong(EXTRA_ACCOUNT_ID, -1);

View File

@ -28,11 +28,11 @@ import org.mariotaku.twidere.loader.support.StatusRetweetersLoader;
public class StatusRetweetersListFragment extends CursorSupportUsersListFragment {
@Override
public IDsUsersLoader newLoaderInstance(final Context context, final Bundle args) {
public IDsUsersLoader onCreateUsersLoader(final Context context, final Bundle args, boolean fromUser) {
if (args == null) return null;
final long account_id = args.getLong(EXTRA_ACCOUNT_ID, -1);
final long status_id = args.getLong(EXTRA_STATUS_ID, -1);
return new StatusRetweetersLoader(context, account_id, status_id, getNextCursor(), getData());
return new StatusRetweetersLoader(context, account_id, status_id, getNextCursor(), getData(), fromUser);
}
}

View File

@ -31,7 +31,7 @@ import java.util.List;
public class StatusesListFragment extends ParcelableStatusesFragment {
@Override
public Loader<List<ParcelableStatus>> onCreateStatusesLoader(final Context context,
protected Loader<List<ParcelableStatus>> onCreateStatusesLoader(final Context context,
final Bundle args,
final boolean fromUser) {
return new IntentExtrasStatusesLoader(context, getArguments(), getAdapterData(), fromUser);

View File

@ -35,7 +35,7 @@ import java.util.List;
public class StatusesSearchFragment extends ParcelableStatusesFragment {
@Override
public Loader<List<ParcelableStatus>> onCreateStatusesLoader(final Context context,
protected Loader<List<ParcelableStatus>> onCreateStatusesLoader(final Context context,
final Bundle args,
final boolean fromUser) {
setRefreshing(true);

View File

@ -28,10 +28,10 @@ import org.mariotaku.twidere.loader.support.UserBlocksLoader;
public class UserBlocksListFragment extends CursorSupportUsersListFragment {
@Override
public CursorSupportUsersLoader newLoaderInstance(final Context context, final Bundle args) {
public CursorSupportUsersLoader onCreateUsersLoader(final Context context, final Bundle args, boolean fromUser) {
if (args == null) return null;
final long account_id = args.getLong(EXTRA_ACCOUNT_ID, -1);
return new UserBlocksLoader(context, account_id, getNextCursor(), getData());
return new UserBlocksLoader(context, account_id, getNextCursor(), getData(), fromUser);
}
}

View File

@ -34,7 +34,7 @@ import java.util.List;
public class UserFavoritesFragment extends ParcelableStatusesFragment {
@Override
public Loader<List<ParcelableStatus>> onCreateStatusesLoader(final Context context,
protected Loader<List<ParcelableStatus>> onCreateStatusesLoader(final Context context,
final Bundle args,
final boolean fromUser) {
setRefreshing(true);

View File

@ -53,12 +53,12 @@ public class UserFollowersFragment extends CursorSupportUsersListFragment {
};
@Override
public CursorSupportUsersLoader newLoaderInstance(final Context context, final Bundle args) {
public CursorSupportUsersLoader onCreateUsersLoader(final Context context, final Bundle args, boolean fromUser) {
if (args == null) return null;
final long account_id = args.getLong(EXTRA_ACCOUNT_ID, -1);
final long user_id = args.getLong(EXTRA_USER_ID, -1);
final String screen_name = args.getString(EXTRA_SCREEN_NAME);
return new UserFollowersLoader(context, account_id, user_id, screen_name, getNextCursor(), getData());
return new UserFollowersLoader(context, account_id, user_id, screen_name, getNextCursor(), getData(), fromUser);
}
@Override

View File

@ -28,12 +28,12 @@ import org.mariotaku.twidere.loader.support.UserFriendsLoader;
public class UserFriendsFragment extends CursorSupportUsersListFragment {
@Override
public CursorSupportUsersLoader newLoaderInstance(final Context context, final Bundle args) {
public CursorSupportUsersLoader onCreateUsersLoader(final Context context, final Bundle args, boolean fromUser) {
if (args == null) return null;
final long account_id = args.getLong(EXTRA_ACCOUNT_ID, -1);
final long user_id = args.getLong(EXTRA_USER_ID, -1);
final String screen_name = args.getString(EXTRA_SCREEN_NAME);
return new UserFriendsLoader(context, account_id, user_id, screen_name, getNextCursor(), getData());
return new UserFriendsLoader(context, account_id, user_id, screen_name, getNextCursor(), getData(), fromUser);
}
}

View File

@ -57,7 +57,7 @@ public class UserListMembersFragment extends CursorSupportUsersListFragment {
};
@Override
public CursorSupportUsersLoader newLoaderInstance(final Context context, final Bundle args) {
public CursorSupportUsersLoader onCreateUsersLoader(final Context context, final Bundle args, boolean fromUser) {
if (args == null) return null;
final long listId = args.getLong(EXTRA_LIST_ID, -1);
final long accountId = args.getLong(EXTRA_ACCOUNT_ID, -1);
@ -65,7 +65,7 @@ public class UserListMembersFragment extends CursorSupportUsersListFragment {
final String screenName = args.getString(EXTRA_SCREEN_NAME);
final String listName = args.getString(EXTRA_LIST_NAME);
return new UserListMembersLoader(context, accountId, listId, userId, screenName, listName,
getNextCursor(), getData());
getNextCursor(), getData(), fromUser);
}
@Override

View File

@ -28,7 +28,7 @@ import org.mariotaku.twidere.loader.support.UserListSubscribersLoader;
public class UserListSubscribersFragment extends CursorSupportUsersListFragment {
@Override
public CursorSupportUsersLoader newLoaderInstance(final Context context, final Bundle args) {
public CursorSupportUsersLoader onCreateUsersLoader(final Context context, final Bundle args, boolean fromUser) {
if (args == null) return null;
final long listId = args.getLong(EXTRA_LIST_ID, -1);
final long accountId = args.getLong(EXTRA_ACCOUNT_ID, -1);
@ -36,7 +36,7 @@ public class UserListSubscribersFragment extends CursorSupportUsersListFragment
final String screenName = args.getString(EXTRA_SCREEN_NAME);
final String listName = args.getString(EXTRA_LIST_NAME);
return new UserListSubscribersLoader(context, accountId, listId, userId, screenName, listName,
getNextCursor(), getData());
getNextCursor(), getData(), fromUser);
}
}

View File

@ -34,7 +34,7 @@ import java.util.List;
public class UserListTimelineFragment extends ParcelableStatusesFragment {
@Override
public Loader<List<ParcelableStatus>> onCreateStatusesLoader(final Context context,
protected Loader<List<ParcelableStatus>> onCreateStatusesLoader(final Context context,
final Bundle args,
final boolean fromUser) {
setRefreshing(true);

View File

@ -31,7 +31,7 @@ import java.util.List;
public class UserMentionsFragment extends StatusesSearchFragment {
@Override
public Loader<List<ParcelableStatus>> onCreateStatusesLoader(final Context context,
protected Loader<List<ParcelableStatus>> onCreateStatusesLoader(final Context context,
final Bundle args,
final boolean fromUser) {
if (args == null) return null;

View File

@ -34,7 +34,7 @@ import java.util.List;
public class UserTimelineFragment extends ParcelableStatusesFragment {
@Override
public Loader<List<ParcelableStatus>> onCreateStatusesLoader(final Context context,
protected Loader<List<ParcelableStatus>> onCreateStatusesLoader(final Context context,
final Bundle args,
final boolean fromUser) {
setRefreshing(true);

View File

@ -31,9 +31,9 @@ import java.util.List;
public class UsersListFragment extends ParcelableUsersFragment {
@Override
public Loader<List<ParcelableUser>> newLoaderInstance(final Context context, final Bundle args) {
public Loader<List<ParcelableUser>> onCreateUsersLoader(final Context context, final Bundle args, boolean fromUser) {
if (args == null) return null;
if (args.containsKey(EXTRA_USERS)) return new IntentExtrasUsersLoader(context, args, getData());
if (args.containsKey(EXTRA_USERS)) return new IntentExtrasUsersLoader(context, args, getData(), fromUser);
return null;
}

View File

@ -30,41 +30,41 @@ import twitter4j.CursorSupport;
public abstract class BaseCursorSupportUsersLoader extends Twitter4JUsersLoader {
private final long mCursor;
private final SharedPreferences mPreferences;
private final int mLoadItemLimit;
private final long mCursor;
private final SharedPreferences mPreferences;
private final int mLoadItemLimit;
private long mNextCursor, mPrevCursor;
private long mNextCursor, mPrevCursor;
public BaseCursorSupportUsersLoader(final Context context, final long account_id, final long cursor,
final List<ParcelableUser> data) {
super(context, account_id, data);
mCursor = cursor;
mPreferences = getContext().getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE);
final int prefs_load_item_limit = mPreferences.getInt(KEY_LOAD_ITEM_LIMIT, DEFAULT_LOAD_ITEM_LIMIT);
mLoadItemLimit = Math.min(100, prefs_load_item_limit);
}
public BaseCursorSupportUsersLoader(final Context context, final long accountId, final long cursor,
final List<ParcelableUser> data, boolean fromUser) {
super(context, accountId, data, fromUser);
mCursor = cursor;
mPreferences = context.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE);
final int loadItemLimit = mPreferences.getInt(KEY_LOAD_ITEM_LIMIT, DEFAULT_LOAD_ITEM_LIMIT);
mLoadItemLimit = Math.min(100, loadItemLimit);
}
public final int getCount() {
return mLoadItemLimit;
}
public final int getCount() {
return mLoadItemLimit;
}
public final long getCursor() {
return mCursor;
}
public final long getCursor() {
return mCursor;
}
public final long getNextCursor() {
return mNextCursor;
}
public final long getNextCursor() {
return mNextCursor;
}
public final long getPrevCursor() {
return mPrevCursor;
}
public final long getPrevCursor() {
return mPrevCursor;
}
protected final void setCursorIds(final CursorSupport cursor) {
if (cursor == null) return;
mNextCursor = cursor.getNextCursor();
mPrevCursor = cursor.getPreviousCursor();
}
protected final void setCursorIds(final CursorSupport cursor) {
if (cursor == null) return;
mNextCursor = cursor.getNextCursor();
mPrevCursor = cursor.getPreviousCursor();
}
}

View File

@ -33,25 +33,25 @@ import twitter4j.User;
public abstract class CursorSupportUsersLoader extends BaseCursorSupportUsersLoader {
public CursorSupportUsersLoader(final Context context, final long account_id, final long cursor,
final List<ParcelableUser> data) {
super(context, account_id, cursor, data);
}
public CursorSupportUsersLoader(final Context context, final long accountId, final long cursor,
final List<ParcelableUser> data, boolean fromUser) {
super(context, accountId, cursor, data, fromUser);
}
protected abstract PageableResponseList<User> getCursoredUsers(Twitter twitter, CursorPaging paging)
throws TwitterException;
protected abstract PageableResponseList<User> getCursoredUsers(Twitter twitter, CursorPaging paging)
throws TwitterException;
@Override
protected final List<User> getUsers(final Twitter twitter) throws TwitterException {
if (twitter == null) return null;
final CursorPaging paging = new CursorPaging(getCount());
if (getCursor() > 0) {
paging.setCursor(getCursor());
}
final PageableResponseList<User> users = getCursoredUsers(twitter, paging);
if (users == null) return null;
setCursorIds(users);
return users;
}
@Override
protected final List<User> getUsers(final Twitter twitter) throws TwitterException {
if (twitter == null) return null;
final CursorPaging paging = new CursorPaging(getCount());
if (getCursor() > 0) {
paging.setCursor(getCursor());
}
final PageableResponseList<User> users = getCursoredUsers(twitter, paging);
if (users == null) return null;
setCursorIds(users);
return users;
}
}

View File

@ -28,8 +28,8 @@ import java.util.List;
public final class DummyParcelableUsersLoader extends ParcelableUsersLoader {
public DummyParcelableUsersLoader(final Context context) {
super(context, null);
public DummyParcelableUsersLoader(final Context context, boolean fromUser) {
super(context, null, fromUser);
}
@Override

View File

@ -33,24 +33,24 @@ import twitter4j.User;
public abstract class IDsUsersLoader extends BaseCursorSupportUsersLoader {
public IDsUsersLoader(final Context context, final long account_id, final long cursor,
final List<ParcelableUser> data) {
super(context, account_id, cursor, data);
}
public IDsUsersLoader(final Context context, final long accountId, final long cursor,
final List<ParcelableUser> data, boolean fromUser) {
super(context, accountId, cursor, data, fromUser);
}
@Override
public List<User> getUsers(final Twitter twitter) throws TwitterException {
if (twitter == null) return null;
final CursorPaging paging = new CursorPaging(getCount());
if (getCursor() > 0) {
paging.setCursor(getCursor());
}
final IDs ids = getIDs(twitter, paging);
if (ids == null) return null;
setCursorIds(ids);
return twitter.lookupUsers(ids.getIDs());
}
@Override
public List<User> getUsers(final Twitter twitter) throws TwitterException {
if (twitter == null) return null;
final CursorPaging paging = new CursorPaging(getCount());
if (getCursor() > 0) {
paging.setCursor(getCursor());
}
final IDs ids = getIDs(twitter, paging);
if (ids == null) return null;
setCursorIds(ids);
return twitter.lookupUsers(ids.getIDs());
}
protected abstract IDs getIDs(Twitter twitter, CursorPaging paging) throws TwitterException;
protected abstract IDs getIDs(Twitter twitter, CursorPaging paging) throws TwitterException;
}

View File

@ -32,9 +32,9 @@ import twitter4j.TwitterException;
public class IncomingFriendshipsLoader extends IDsUsersLoader {
public IncomingFriendshipsLoader(final Context context, final long account_id, final long max_id,
final List<ParcelableUser> users_list) {
super(context, account_id, max_id, users_list);
public IncomingFriendshipsLoader(final Context context, final long accountId, final long maxId,
final List<ParcelableUser> data, boolean fromUser) {
super(context, accountId, maxId, data, fromUser);
}
@Override

View File

@ -31,8 +31,8 @@ public class IntentExtrasUsersLoader extends ParcelableUsersLoader {
private final Bundle mExtras;
public IntentExtrasUsersLoader(final Context context, final Bundle extras, final List<ParcelableUser> data) {
super(context, data);
public IntentExtrasUsersLoader(final Context context, final Bundle extras, final List<ParcelableUser> data, boolean fromUser) {
super(context, data, fromUser);
mExtras = extras;
}

View File

@ -33,16 +33,16 @@ import twitter4j.User;
public class MutesUsersLoader extends CursorSupportUsersLoader {
public MutesUsersLoader(final Context context, final long account_id, final long cursor,
final List<ParcelableUser> data) {
super(context, account_id, cursor, data);
}
public MutesUsersLoader(final Context context, final long accountId, final long cursor,
final List<ParcelableUser> data, boolean fromUser) {
super(context, accountId, cursor, data, fromUser);
}
@Override
protected final PageableResponseList<User> getCursoredUsers(final Twitter twitter, final CursorPaging paging)
throws TwitterException {
if (twitter == null) return null;
return twitter.getMutesUsersList(paging);
}
@Override
protected final PageableResponseList<User> getCursoredUsers(final Twitter twitter, final CursorPaging paging)
throws TwitterException {
if (twitter == null) return null;
return twitter.getMutesUsersList(paging);
}
}

View File

@ -23,38 +23,51 @@ import android.content.Context;
import android.support.v4.content.AsyncTaskLoader;
import org.mariotaku.twidere.Constants;
import org.mariotaku.twidere.loader.iface.IExtendedLoader;
import org.mariotaku.twidere.model.ParcelableUser;
import org.mariotaku.twidere.util.collection.NoDuplicatesArrayList;
import java.util.Collections;
import java.util.List;
public abstract class ParcelableUsersLoader extends AsyncTaskLoader<List<ParcelableUser>> implements Constants {
public abstract class ParcelableUsersLoader extends AsyncTaskLoader<List<ParcelableUser>> implements IExtendedLoader, Constants {
private final List<ParcelableUser> mData = Collections
.synchronizedList(new NoDuplicatesArrayList<ParcelableUser>());
private final List<ParcelableUser> mData = Collections
.synchronizedList(new NoDuplicatesArrayList<ParcelableUser>());
private boolean mFromUser;
public ParcelableUsersLoader(final Context context, final List<ParcelableUser> data) {
super(context);
if (data != null) {
mData.addAll(data);
}
}
public ParcelableUsersLoader(final Context context, final List<ParcelableUser> data, boolean fromUser) {
super(context);
setFromUser(fromUser);
if (data != null) {
mData.addAll(data);
}
}
@Override
public void onStartLoading() {
forceLoad();
}
@Override
public void setFromUser(boolean fromUser) {
mFromUser = fromUser;
}
protected List<ParcelableUser> getData() {
return mData;
}
@Override
public boolean isFromUser() {
return mFromUser;
}
protected boolean hasId(final long id) {
for (final ParcelableUser user : mData) {
if (user.id == id) return true;
}
return false;
}
@Override
public void onStartLoading() {
forceLoad();
}
protected List<ParcelableUser> getData() {
return mData;
}
protected boolean hasId(final long id) {
for (final ParcelableUser user : mData) {
if (user.id == id) return true;
}
return false;
}
}

View File

@ -34,10 +34,10 @@ public class StatusFavoritersLoader extends IDsUsersLoader {
private final long mStatusId;
public StatusFavoritersLoader(final Context context, final long account_id, final long status_id,
final long cursor, final List<ParcelableUser> data) {
super(context, account_id, cursor, data);
mStatusId = status_id;
public StatusFavoritersLoader(final Context context, final long accountId, final long statusId,
final long cursor, final List<ParcelableUser> data, boolean fromUser) {
super(context, accountId, cursor, data, fromUser);
mStatusId = statusId;
}
@Override

View File

@ -32,19 +32,19 @@ import twitter4j.TwitterException;
public class StatusRetweetersLoader extends IDsUsersLoader {
private final long mStatusId;
private final long mStatusId;
public StatusRetweetersLoader(final Context context, final long account_id, final long status_id,
final long cursor, final List<ParcelableUser> data) {
super(context, account_id, cursor, data);
mStatusId = status_id;
}
public StatusRetweetersLoader(final Context context, final long accountId, final long statusId,
final long cursor, final List<ParcelableUser> data, boolean fromUser) {
super(context, accountId, cursor, data, fromUser);
mStatusId = statusId;
}
@Override
protected IDs getIDs(final Twitter twitter, final CursorPaging paging) throws TwitterException {
if (twitter == null) return null;
if (mStatusId > 0) return twitter.getRetweetersIDs(mStatusId, paging);
return null;
}
@Override
protected IDs getIDs(final Twitter twitter, final CursorPaging paging) throws TwitterException {
if (twitter == null) return null;
if (mStatusId > 0) return twitter.getRetweetersIDs(mStatusId, paging);
return null;
}
}

View File

@ -34,38 +34,38 @@ import static org.mariotaku.twidere.util.Utils.getTwitterInstance;
public abstract class Twitter4JUsersLoader extends ParcelableUsersLoader {
private final long mAccountId;
private final long mAccountId;
private final Context mContext;
private final Context mContext;
public Twitter4JUsersLoader(final Context context, final long account_id, final List<ParcelableUser> data) {
super(context, data);
mContext = context;
mAccountId = account_id;
}
public Twitter4JUsersLoader(final Context context, final long accountId, final List<ParcelableUser> data, boolean fromUser) {
super(context, data, fromUser);
mContext = context;
mAccountId = accountId;
}
@Override
public List<ParcelableUser> loadInBackground() {
final List<ParcelableUser> data = getData();
final List<User> users;
try {
users = getUsers(getTwitterInstance(mContext, mAccountId, true));
if (users == null) return data;
} catch (final TwitterException e) {
e.printStackTrace();
return data;
}
int pos = data.size();
for (final User user : users) {
if (hasId(user.getId())) {
continue;
}
data.add(new ParcelableUser(user, mAccountId, pos));
pos++;
}
Collections.sort(data);
return data;
}
@Override
public List<ParcelableUser> loadInBackground() {
final List<ParcelableUser> data = getData();
final List<User> users;
try {
users = getUsers(getTwitterInstance(mContext, mAccountId, true));
if (users == null) return data;
} catch (final TwitterException e) {
e.printStackTrace();
return data;
}
int pos = data.size();
for (final User user : users) {
if (hasId(user.getId())) {
continue;
}
data.add(new ParcelableUser(user, mAccountId, pos));
pos++;
}
Collections.sort(data);
return data;
}
protected abstract List<User> getUsers(Twitter twitter) throws TwitterException;
protected abstract List<User> getUsers(Twitter twitter) throws TwitterException;
}

View File

@ -33,16 +33,16 @@ import twitter4j.User;
public class UserBlocksLoader extends CursorSupportUsersLoader {
public UserBlocksLoader(final Context context, final long account_id, final long cursor,
final List<ParcelableUser> data) {
super(context, account_id, cursor, data);
}
public UserBlocksLoader(final Context context, final long accountId, final long cursor,
final List<ParcelableUser> data, boolean fromUser) {
super(context, accountId, cursor, data, fromUser);
}
@Override
protected final PageableResponseList<User> getCursoredUsers(final Twitter twitter, final CursorPaging paging)
throws TwitterException {
if (twitter == null) return null;
return twitter.getBlocksList(paging);
}
@Override
protected final PageableResponseList<User> getCursoredUsers(final Twitter twitter, final CursorPaging paging)
throws TwitterException {
if (twitter == null) return null;
return twitter.getBlocksList(paging);
}
}

View File

@ -33,24 +33,25 @@ import twitter4j.User;
public class UserFollowersLoader extends CursorSupportUsersLoader {
private final long mUserId;
private final String mScreenName;
private final long mUserId;
private final String mScreenName;
public UserFollowersLoader(final Context context, final long account_id, final long user_id,
final String screen_name, final long cursor, final List<ParcelableUser> data) {
super(context, account_id, cursor, data);
mUserId = user_id;
mScreenName = screen_name;
}
public UserFollowersLoader(final Context context, final long accountId, final long userId,
final String screenName, final long cursor, final List<ParcelableUser> data,
boolean fromUser) {
super(context, accountId, cursor, data, fromUser);
mUserId = userId;
mScreenName = screenName;
}
@Override
protected PageableResponseList<User> getCursoredUsers(final Twitter twitter, final CursorPaging paging)
throws TwitterException {
if (twitter == null) return null;
if (mUserId > 0)
return twitter.getFollowersList(mUserId, paging);
else if (mScreenName != null) return twitter.getFollowersList(mScreenName, paging);
return null;
}
@Override
protected PageableResponseList<User> getCursoredUsers(final Twitter twitter, final CursorPaging paging)
throws TwitterException {
if (twitter == null) return null;
if (mUserId > 0)
return twitter.getFollowersList(mUserId, paging);
else if (mScreenName != null) return twitter.getFollowersList(mScreenName, paging);
return null;
}
}

View File

@ -33,24 +33,25 @@ import twitter4j.User;
public class UserFriendsLoader extends CursorSupportUsersLoader {
private final long mUserId;
private final String mScreenName;
private final long mUserId;
private final String mScreenName;
public UserFriendsLoader(final Context context, final long account_id, final long user_id,
final String screen_name, final long max_id, final List<ParcelableUser> users_list) {
super(context, account_id, max_id, users_list);
mUserId = user_id;
mScreenName = screen_name;
}
public UserFriendsLoader(final Context context, final long accountId, final long userId,
final String screenName, final long maxId, final List<ParcelableUser> userList,
boolean fromUser) {
super(context, accountId, maxId, userList, fromUser);
mUserId = userId;
mScreenName = screenName;
}
@Override
protected PageableResponseList<User> getCursoredUsers(final Twitter twitter, final CursorPaging paging)
throws TwitterException {
if (twitter == null) return null;
if (mUserId > 0)
return twitter.getFriendsList(mUserId, paging);
else if (mScreenName != null) return twitter.getFriendsList(mScreenName, paging);
return null;
}
@Override
protected PageableResponseList<User> getCursoredUsers(final Twitter twitter, final CursorPaging paging)
throws TwitterException {
if (twitter == null) return null;
if (mUserId > 0)
return twitter.getFriendsList(mUserId, paging);
else if (mScreenName != null) return twitter.getFriendsList(mScreenName, paging);
return null;
}
}

View File

@ -37,13 +37,14 @@ public class UserListMembersLoader extends CursorSupportUsersLoader {
private final long mUserId;
private final String mScreenName, mListName;
public UserListMembersLoader(final Context context, final long account_id, final long listId, final long user_id,
final String screen_name, final String list_name, final long cursor, final List<ParcelableUser> data) {
super(context, account_id, cursor, data);
public UserListMembersLoader(final Context context, final long accountId, final long listId,
final long userId, final String screenName, final String listName,
final long cursor, final List<ParcelableUser> data, boolean fromUser) {
super(context, accountId, cursor, data, fromUser);
mListId = listId;
mUserId = user_id;
mScreenName = screen_name;
mListName = list_name;
mUserId = userId;
mScreenName = screenName;
mListName = listName;
}
@Override

View File

@ -37,10 +37,10 @@ public class UserListSubscribersLoader extends CursorSupportUsersLoader {
private final long mUserId;
private final String mScreenName, mListName;
public UserListSubscribersLoader(final Context context, final long account_id, final long listId,
public UserListSubscribersLoader(final Context context, final long accountId, final long listId,
final long userId, final String screenName, final String listName, final long cursor,
final List<ParcelableUser> data) {
super(context, account_id, cursor, data);
final List<ParcelableUser> data, boolean fromUser) {
super(context, accountId, cursor, data, fromUser);
mListId = listId;
mUserId = userId;
mScreenName = screenName;

View File

@ -34,9 +34,9 @@ public class UserSearchLoader extends Twitter4JUsersLoader {
private final String mQuery;
private final int mPage;
public UserSearchLoader(final Context context, final long account_id, final String query, final int page,
final List<ParcelableUser> data) {
super(context, account_id, data);
public UserSearchLoader(final Context context, final long accountId, final String query, final int page,
final List<ParcelableUser> data, boolean fromUser) {
super(context, accountId, data, fromUser);
mQuery = query;
mPage = page;
}

View File

@ -20,17 +20,20 @@
package org.mariotaku.twidere.view.holder;
import android.content.Context;
import android.graphics.Color;
import android.support.v7.widget.RecyclerView.ViewHolder;
import android.text.TextUtils;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnLongClickListener;
import android.widget.ImageView;
import android.widget.TextView;
import org.mariotaku.twidere.R;
import org.mariotaku.twidere.adapter.iface.IContentCardAdapter;
import org.mariotaku.twidere.adapter.iface.ContentCardClickListener;
import org.mariotaku.twidere.adapter.iface.IUsersAdapter;
import org.mariotaku.twidere.model.ParcelableUser;
import org.mariotaku.twidere.util.MediaLoaderWrapper;
import org.mariotaku.twidere.view.ShapedImageView;
import org.mariotaku.twidere.view.iface.IColorLabelView;
import java.util.Locale;
@ -40,56 +43,32 @@ import static org.mariotaku.twidere.util.UserColorNameUtils.getUserNickname;
import static org.mariotaku.twidere.util.Utils.getLocalizedNumber;
import static org.mariotaku.twidere.util.Utils.getUserTypeIconRes;
public class UserViewHolder extends ViewHolder {
public class UserViewHolder extends ViewHolder implements OnClickListener, OnLongClickListener {
private final IContentCardAdapter adapter;
private final IUsersAdapter<?> adapter;
public final IColorLabelView content;
private final ImageView profileImageView, profileTypeView;
private final TextView name, screenName, description, location, url, statusesCount, followersCount,
friendsCount;
private boolean account_color_enabled;
private final IColorLabelView itemContent;
private final ShapedImageView profileImageView;
private final ImageView profileTypeView;
private final TextView nameView, screenNameView, descriptionView, locationView, urlView,
statusesCountView, followersCountView, friendsCountView;
public UserViewHolder(final IContentCardAdapter adapter, final View itemView) {
private UserClickListener userClickListener;
public UserViewHolder(final IUsersAdapter<?> adapter, final View itemView) {
super(itemView);
this.adapter = adapter;
content = (IColorLabelView) itemView.findViewById(R.id.content);
profileImageView = (ImageView) itemView.findViewById(R.id.profile_image);
itemContent = (IColorLabelView) itemView.findViewById(R.id.item_content);
profileImageView = (ShapedImageView) itemView.findViewById(R.id.profile_image);
profileTypeView = (ImageView) itemView.findViewById(R.id.profile_type);
name = (TextView) itemView.findViewById(R.id.name);
screenName = (TextView) itemView.findViewById(R.id.screen_name);
description = (TextView) itemView.findViewById(R.id.description);
location = (TextView) itemView.findViewById(R.id.location);
url = (TextView) itemView.findViewById(R.id.url);
statusesCount = (TextView) itemView.findViewById(R.id.statuses_count);
followersCount = (TextView) itemView.findViewById(R.id.followers_count);
friendsCount = (TextView) itemView.findViewById(R.id.friends_count);
}
public void setAccountColor(final int color) {
content.drawEnd(account_color_enabled ? color : Color.TRANSPARENT);
}
public void setAccountColorEnabled(final boolean enabled) {
account_color_enabled = enabled;
if (!account_color_enabled) {
content.drawEnd(Color.TRANSPARENT);
}
}
public void setHighlightColor(final int color) {
content.drawBackground(color);
}
public void setTextSize(final float textSize) {
description.setTextSize(textSize);
name.setTextSize(textSize);
screenName.setTextSize(textSize * 0.75f);
location.setTextSize(textSize);
url.setTextSize(textSize);
statusesCount.setTextSize(textSize);
followersCount.setTextSize(textSize);
friendsCount.setTextSize(textSize);
nameView = (TextView) itemView.findViewById(R.id.name);
screenNameView = (TextView) itemView.findViewById(R.id.screen_name);
descriptionView = (TextView) itemView.findViewById(R.id.description);
locationView = (TextView) itemView.findViewById(R.id.location);
urlView = (TextView) itemView.findViewById(R.id.url);
statusesCountView = (TextView) itemView.findViewById(R.id.statuses_count);
followersCountView = (TextView) itemView.findViewById(R.id.followers_count);
friendsCountView = (TextView) itemView.findViewById(R.id.friends_count);
}
public void displayUser(ParcelableUser user) {
@ -106,18 +85,18 @@ public class UserViewHolder extends ViewHolder {
} else {
profileTypeView.setImageDrawable(null);
}
name.setText(getUserNickname(context, user.id, user.name));
screenName.setText("@" + user.screen_name);
description.setVisibility(TextUtils.isEmpty(user.description_unescaped) ? View.GONE : View.VISIBLE);
description.setText(user.description_unescaped);
location.setVisibility(TextUtils.isEmpty(user.location) ? View.GONE : View.VISIBLE);
location.setText(user.location);
url.setVisibility(TextUtils.isEmpty(user.url_expanded) ? View.GONE : View.VISIBLE);
url.setText(user.url_expanded);
nameView.setText(getUserNickname(context, user.id, user.name));
screenNameView.setText("@" + user.screen_name);
descriptionView.setVisibility(TextUtils.isEmpty(user.description_unescaped) ? View.GONE : View.VISIBLE);
descriptionView.setText(user.description_unescaped);
locationView.setVisibility(TextUtils.isEmpty(user.location) ? View.GONE : View.VISIBLE);
locationView.setText(user.location);
urlView.setVisibility(TextUtils.isEmpty(user.url_expanded) ? View.GONE : View.VISIBLE);
urlView.setText(user.url_expanded);
final Locale locale = Locale.getDefault();
statusesCount.setText(getLocalizedNumber(locale, user.statuses_count));
followersCount.setText(getLocalizedNumber(locale, user.followers_count));
friendsCount.setText(getLocalizedNumber(locale, user.friends_count));
statusesCountView.setText(getLocalizedNumber(locale, user.statuses_count));
followersCountView.setText(getLocalizedNumber(locale, user.followers_count));
friendsCountView.setText(getLocalizedNumber(locale, user.friends_count));
if (adapter.isProfileImageEnabled()) {
profileImageView.setVisibility(View.VISIBLE);
loader.displayProfileImage(profileImageView, user.profile_image_url);
@ -127,8 +106,63 @@ public class UserViewHolder extends ViewHolder {
}
}
public void setUserColor(final int color) {
content.drawStart(color);
@Override
public void onClick(View v) {
if (userClickListener == null) return;
switch (v.getId()) {
case R.id.item_content: {
userClickListener.onUserClick(this, getLayoutPosition());
break;
}
}
}
@Override
public boolean onLongClick(View v) {
if (userClickListener == null) return false;
switch (v.getId()) {
case R.id.item_content: {
return userClickListener.onUserLongClick(this, getLayoutPosition());
}
}
return false;
}
public void setOnClickListeners() {
setUserClickListener(adapter);
}
public void setTextSize(final float textSize) {
descriptionView.setTextSize(textSize);
nameView.setTextSize(textSize);
screenNameView.setTextSize(textSize * 0.75f);
locationView.setTextSize(textSize);
urlView.setTextSize(textSize);
statusesCountView.setTextSize(textSize);
followersCountView.setTextSize(textSize);
friendsCountView.setTextSize(textSize);
}
public void setUserClickListener(UserClickListener listener) {
userClickListener = listener;
((View) itemContent).setOnClickListener(this);
((View) itemContent).setOnLongClickListener(this);
}
public void setUserColor(final int color) {
itemContent.drawStart(color);
}
public void setupViewOptions() {
setTextSize(adapter.getTextSize());
profileImageView.setStyle(adapter.getProfileImageStyle());
}
public static interface UserClickListener extends ContentCardClickListener {
void onUserClick(UserViewHolder holder, int position);
boolean onUserLongClick(UserViewHolder holder, int position);
}
}

View File

@ -18,144 +18,164 @@
~ along with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<org.mariotaku.twidere.view.ColorLabelLinearLayout
android:id="@+id/content"
<android.support.v7.widget.CardView
android:id="@+id/card"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingBottom="@dimen/element_spacing_small"
android:paddingLeft="@dimen/element_spacing_normal"
android:paddingRight="@dimen/element_spacing_normal"
android:paddingTop="@dimen/element_spacing_small"
tools:context=".adapter.ParcelableUsersAdapter">
android:layout_marginBottom="@dimen/element_spacing_small"
android:layout_marginLeft="@dimen/element_spacing_normal"
android:layout_marginRight="@dimen/element_spacing_normal"
android:layout_marginTop="@dimen/element_spacing_small"
app:cardBackgroundColor="?cardItemBackgroundColor"
app:cardCornerRadius="2dp"
app:cardElevation="2dp">
<RelativeLayout
android:id="@+id/profile_container"
<org.mariotaku.twidere.view.ColorLabelLinearLayout
android:id="@+id/item_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="@dimen/element_spacing_normal"
android:background="?android:selectableItemBackground"
android:focusable="true"
android:focusableInTouchMode="false"
android:orientation="vertical"
android:paddingBottom="@dimen/element_spacing_small"
android:paddingLeft="@dimen/element_spacing_normal"
android:paddingRight="@dimen/element_spacing_xlarge"
android:paddingTop="@dimen/element_spacing_normal">
android:paddingRight="@dimen/element_spacing_normal"
android:paddingTop="@dimen/element_spacing_small"
tools:context=".adapter.ParcelableUsersAdapter">
<org.mariotaku.twidere.view.ShapedImageView
android:id="@+id/profile_image"
android:layout_width="@dimen/icon_size_card_list_item"
android:layout_height="@dimen/icon_size_card_list_item"
android:layout_centerVertical="true"
android:contentDescription="@string/profile_image"
android:scaleType="fitCenter"/>
<RelativeLayout
android:id="@+id/profile_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="@dimen/element_spacing_normal"
android:paddingLeft="@dimen/element_spacing_normal"
android:paddingRight="@dimen/element_spacing_xlarge"
android:paddingTop="@dimen/element_spacing_normal">
<ImageView
android:id="@+id/profile_type"
android:layout_width="@dimen/icon_size_profile_type"
android:layout_height="@dimen/icon_size_profile_type"
android:layout_alignBottom="@id/profile_image"
android:layout_alignRight="@id/profile_image"
android:layout_marginBottom="@dimen/element_spacing_minus_small"
android:layout_marginRight="@dimen/element_spacing_minus_normal"
android:scaleType="centerInside"
tools:ignore="ContentDescription"/>
<org.mariotaku.twidere.view.ShapedImageView
android:id="@+id/profile_image"
style="?profileImageStyle"
android:layout_width="@dimen/icon_size_card_list_item"
android:layout_height="@dimen/icon_size_card_list_item"
android:layout_centerVertical="true"
android:contentDescription="@string/profile_image"
android:scaleType="fitCenter"/>
<ImageView
android:id="@+id/profile_type"
android:layout_width="@dimen/icon_size_profile_type"
android:layout_height="@dimen/icon_size_profile_type"
android:layout_alignBottom="@id/profile_image"
android:layout_alignRight="@id/profile_image"
android:layout_marginBottom="@dimen/element_spacing_minus_small"
android:layout_marginRight="@dimen/element_spacing_minus_normal"
android:scaleType="centerInside"
tools:ignore="ContentDescription"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="@+id/profile_image"
android:gravity="center_vertical"
android:orientation="vertical"
android:paddingLeft="8dp">
<org.mariotaku.twidere.view.themed.ThemedTextView
android:id="@+id/name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="?android:attr/textColorPrimary"
android:textStyle="bold"
tools:text="Name"/>
<org.mariotaku.twidere.view.themed.ThemedTextView
android:id="@+id/screen_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="?android:attr/textColorSecondary"
tools:text="\@username"/>
</LinearLayout>
</RelativeLayout>
<View
android:id="@+id/divider"
android:layout_width="match_parent"
android:layout_height="0.2dp"
android:background="#40808080"/>
<org.mariotaku.twidere.view.themed.ThemedTextView
android:id="@+id/description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="8dp"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="?android:attr/textColorSecondary"/>
<org.mariotaku.twidere.view.themed.ThemedTextView
android:id="@+id/location"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableLeft="@drawable/ic_indicator_location"
android:drawablePadding="4dp"
android:padding="8dp"
android:singleLine="true"
android:textAppearance="?android:attr/textAppearanceSmall"/>
<org.mariotaku.twidere.view.themed.ThemedTextView
android:id="@+id/url"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableLeft="@drawable/ic_indicator_web"
android:drawablePadding="4dp"
android:padding="8dp"
android:singleLine="true"
android:textAppearance="?android:attr/textAppearanceSmall"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="@+id/profile_image"
android:gravity="center_vertical"
android:orientation="vertical"
android:paddingLeft="8dp">
android:orientation="horizontal"
android:padding="8dp">
<org.mariotaku.twidere.view.themed.ThemedTextView
android:id="@+id/name"
android:layout_width="match_parent"
android:id="@+id/statuses_count"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:drawableLeft="@drawable/ic_indicator_twitter"
android:drawablePadding="4dp"
android:singleLine="true"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="?android:attr/textColorPrimary"
android:textStyle="bold"/>
android:textAppearance="?android:attr/textAppearanceSmall"/>
<org.mariotaku.twidere.view.themed.ThemedTextView
android:id="@+id/screen_name"
android:layout_width="match_parent"
android:id="@+id/followers_count"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:drawableLeft="@drawable/ic_indicator_followers"
android:drawablePadding="4dp"
android:singleLine="true"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="?android:attr/textColorSecondary"/>
android:textAppearance="?android:attr/textAppearanceSmall"/>
<org.mariotaku.twidere.view.themed.ThemedTextView
android:id="@+id/friends_count"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:drawableLeft="@drawable/ic_indicator_following"
android:drawablePadding="4dp"
android:singleLine="true"
android:textAppearance="?android:attr/textAppearanceSmall"/>
</LinearLayout>
</RelativeLayout>
<View
android:id="@+id/divider"
android:layout_width="match_parent"
android:layout_height="0.2dp"
android:background="#40808080"/>
<org.mariotaku.twidere.view.themed.ThemedTextView
android:id="@+id/description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="8dp"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="?android:attr/textColorSecondary"/>
<org.mariotaku.twidere.view.themed.ThemedTextView
android:id="@+id/location"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableLeft="@drawable/ic_indicator_location"
android:drawablePadding="4dp"
android:padding="8dp"
android:singleLine="true"
android:textAppearance="?android:attr/textAppearanceSmall"/>
<org.mariotaku.twidere.view.themed.ThemedTextView
android:id="@+id/url"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableLeft="@drawable/ic_indicator_web"
android:drawablePadding="4dp"
android:padding="8dp"
android:singleLine="true"
android:textAppearance="?android:attr/textAppearanceSmall"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="8dp">
<org.mariotaku.twidere.view.themed.ThemedTextView
android:id="@+id/statuses_count"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:drawableLeft="@drawable/ic_indicator_twitter"
android:drawablePadding="4dp"
android:singleLine="true"
android:textAppearance="?android:attr/textAppearanceSmall"/>
<org.mariotaku.twidere.view.themed.ThemedTextView
android:id="@+id/followers_count"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:drawableLeft="@drawable/ic_indicator_followers"
android:drawablePadding="4dp"
android:singleLine="true"
android:textAppearance="?android:attr/textAppearanceSmall"/>
<org.mariotaku.twidere.view.themed.ThemedTextView
android:id="@+id/friends_count"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:drawableLeft="@drawable/ic_indicator_following"
android:drawablePadding="4dp"
android:singleLine="true"
android:textAppearance="?android:attr/textAppearanceSmall"/>
</LinearLayout>
</org.mariotaku.twidere.view.ColorLabelLinearLayout>
</org.mariotaku.twidere.view.ColorLabelLinearLayout>
</android.support.v7.widget.CardView>

View File

@ -19,12 +19,13 @@
-->
<org.mariotaku.twidere.view.ColorLabelFrameLayout
android:id="@+id/content"
android:id="@+id/item_content"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="@dimen/element_spacing_small"
android:background="?android:selectableItemBackground"
android:paddingLeft="@dimen/element_spacing_normal"
android:paddingRight="@dimen/element_spacing_normal"
android:paddingTop="@dimen/element_spacing_small"
@ -40,13 +41,13 @@
<org.mariotaku.twidere.view.ShapedImageView
android:id="@+id/profile_image"
style="?profileImageStyle"
android:layout_width="@dimen/icon_size_card_list_item"
android:layout_height="@dimen/icon_size_card_list_item"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginRight="@dimen/element_spacing_normal"
android:contentDescription="@string/profile_image"
android:scaleType="fitCenter"/>
android:contentDescription="@string/profile_image"/>
<ImageView
android:id="@+id/profile_type"