mirror of
https://github.com/TwidereProject/Twidere-Android
synced 2025-01-27 07:05:01 +01:00
improved user paging for statusnet
This commit is contained in:
parent
9e6c97759c
commit
1a3b2e33db
@ -169,6 +169,7 @@ public interface IntentConstants {
|
||||
String EXTRA_PERMISSIONS = "permissions";
|
||||
String EXTRA_LOCATION = "location";
|
||||
String EXTRA_URL = "url";
|
||||
String EXTRA_NEXT_PAGE = "next_page";
|
||||
String EXTRA_NEXT_CURSOR = "next_cursor";
|
||||
String EXTRA_PREV_CURSOR = "prev_cursor";
|
||||
String EXTRA_EXTRA_INTENT = "extra_intent";
|
||||
|
@ -20,6 +20,8 @@
|
||||
package org.mariotaku.twidere.fragment.support;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
@ -35,9 +37,11 @@ import org.mariotaku.twidere.adapter.iface.ILoadMoreSupportAdapter.IndicatorPosi
|
||||
import org.mariotaku.twidere.adapter.iface.IUsersAdapter.UserAdapterListener;
|
||||
import org.mariotaku.twidere.loader.iface.IExtendedLoader;
|
||||
import org.mariotaku.twidere.model.ParcelableUser;
|
||||
import org.mariotaku.twidere.model.util.UserKeyUtils;
|
||||
import org.mariotaku.twidere.util.IntentUtils;
|
||||
import org.mariotaku.twidere.util.KeyboardShortcutsHandler;
|
||||
import org.mariotaku.twidere.util.KeyboardShortcutsHandler.KeyboardShortcutCallback;
|
||||
import org.mariotaku.twidere.util.LinkCreator;
|
||||
import org.mariotaku.twidere.util.RecyclerViewNavigationHelper;
|
||||
import org.mariotaku.twidere.view.holder.UserViewHolder;
|
||||
|
||||
@ -112,8 +116,18 @@ abstract class AbsUsersFragment<Data> extends AbsContentListRecyclerViewFragment
|
||||
public void onUserClick(UserViewHolder holder, int position) {
|
||||
final ParcelableUser user = getAdapter().getUser(position);
|
||||
final FragmentActivity activity = getActivity();
|
||||
IntentUtils.openUserProfile(activity, user.account_key, user.key.getId(),
|
||||
user.screen_name, null, true, getUserReferral());
|
||||
if (UserKeyUtils.isSameHost(user.account_key, user.key)) {
|
||||
IntentUtils.openUserProfile(activity, user.account_key, user.key.getId(),
|
||||
user.screen_name, null, true, getUserReferral());
|
||||
} else if (user.extras != null && user.extras.statusnet_profile_url != null) {
|
||||
final Uri uri = Uri.parse(user.extras.statusnet_profile_url);
|
||||
final Intent intent = new Intent(Intent.ACTION_VIEW, uri);
|
||||
startActivity(intent);
|
||||
} else {
|
||||
final Uri uri = LinkCreator.getTwitterUserLink(user.screen_name);
|
||||
final Intent intent = new Intent(Intent.ACTION_VIEW, uri);
|
||||
startActivity(intent);
|
||||
}
|
||||
}
|
||||
|
||||
@UserFragment.Referral
|
||||
|
@ -103,6 +103,7 @@ import org.mariotaku.twidere.util.MediaLoaderWrapper;
|
||||
import org.mariotaku.twidere.util.SharedPreferencesWrapper;
|
||||
import org.mariotaku.twidere.util.ThemeUtils;
|
||||
import org.mariotaku.twidere.util.TransitionUtils;
|
||||
import org.mariotaku.twidere.util.TwitterAPIFactory;
|
||||
import org.mariotaku.twidere.util.UserColorNameManager;
|
||||
import org.mariotaku.twidere.util.Utils;
|
||||
import org.mariotaku.twidere.util.content.SupportFragmentReloadCursorObserver;
|
||||
@ -577,7 +578,10 @@ public class AccountsDashboardFragment extends BaseSupportFragment implements Lo
|
||||
mAccountOptionsAdapter.add(new OptionItem(R.string.likes, R.drawable.ic_action_heart,
|
||||
R.id.favorites));
|
||||
}
|
||||
mAccountOptionsAdapter.add(new OptionItem(R.string.lists, R.drawable.ic_action_list, R.id.lists));
|
||||
if (TwitterAPIFactory.isTwitterCredentials(account)) {
|
||||
mAccountOptionsAdapter.add(new OptionItem(R.string.lists, R.drawable.ic_action_list,
|
||||
R.id.lists));
|
||||
}
|
||||
}
|
||||
|
||||
private boolean hasAccountInTab(SupportTabSpec tab, UserKey accountId, boolean isActivated) {
|
||||
|
@ -32,16 +32,15 @@ import java.util.List;
|
||||
|
||||
public abstract class CursorSupportUsersListFragment extends ParcelableUsersFragment {
|
||||
|
||||
private long mNextCursor, mPrevCursor;
|
||||
private long mNextCursor = -1, mPrevCursor = -1;
|
||||
private int mNextPage = 1;
|
||||
|
||||
@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;
|
||||
mNextPage = savedInstanceState.getInt(EXTRA_NEXT_PAGE, -1);
|
||||
}
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
}
|
||||
@ -49,15 +48,11 @@ public abstract class CursorSupportUsersListFragment extends ParcelableUsersFrag
|
||||
@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
|
||||
@ -66,6 +61,7 @@ public abstract class CursorSupportUsersListFragment extends ParcelableUsersFrag
|
||||
final BaseCursorSupportUsersLoader cursorLoader = (BaseCursorSupportUsersLoader) loader;
|
||||
mNextCursor = cursorLoader.getNextCursor();
|
||||
mPrevCursor = cursorLoader.getPrevCursor();
|
||||
mNextPage = cursorLoader.getNextPage();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -77,6 +73,7 @@ public abstract class CursorSupportUsersListFragment extends ParcelableUsersFrag
|
||||
final Bundle loaderArgs = new Bundle(getArguments());
|
||||
loaderArgs.putBoolean(EXTRA_FROM_USER, true);
|
||||
loaderArgs.putLong(EXTRA_NEXT_CURSOR, mNextCursor);
|
||||
loaderArgs.putLong(EXTRA_PAGE, mNextPage);
|
||||
getLoaderManager().restartLoader(0, loaderArgs, this);
|
||||
}
|
||||
|
||||
@ -85,12 +82,17 @@ public abstract class CursorSupportUsersListFragment extends ParcelableUsersFrag
|
||||
super.onSaveInstanceState(outState);
|
||||
outState.putLong(EXTRA_NEXT_CURSOR, mNextCursor);
|
||||
outState.putLong(EXTRA_PREV_CURSOR, mPrevCursor);
|
||||
outState.putLong(EXTRA_NEXT_PAGE, mNextPage);
|
||||
}
|
||||
|
||||
protected final long getNextCursor() {
|
||||
return mNextCursor;
|
||||
}
|
||||
|
||||
protected final int getNextPage() {
|
||||
return mNextPage;
|
||||
}
|
||||
|
||||
protected final long getPrevCursor() {
|
||||
return mPrevCursor;
|
||||
}
|
||||
|
@ -43,6 +43,7 @@ public class UserFollowersFragment extends CursorSupportUsersListFragment {
|
||||
final UserFollowersLoader loader = new UserFollowersLoader(context, accountKey, userId,
|
||||
screenName, getData(), fromUser);
|
||||
loader.setCursor(getNextCursor());
|
||||
loader.setPage(getNextPage());
|
||||
return loader;
|
||||
}
|
||||
|
||||
|
@ -24,8 +24,8 @@ import android.content.SharedPreferences;
|
||||
|
||||
import org.mariotaku.twidere.api.twitter.model.CursorSupport;
|
||||
import org.mariotaku.twidere.loader.support.iface.ICursorSupportLoader;
|
||||
import org.mariotaku.twidere.model.UserKey;
|
||||
import org.mariotaku.twidere.model.ParcelableUser;
|
||||
import org.mariotaku.twidere.model.UserKey;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -37,6 +37,7 @@ public abstract class BaseCursorSupportUsersLoader extends TwitterAPIUsersLoader
|
||||
private final int mLoadItemLimit;
|
||||
|
||||
private long mNextCursor, mPrevCursor;
|
||||
private int mNextPage;
|
||||
|
||||
public BaseCursorSupportUsersLoader(final Context context, final UserKey accountKey,
|
||||
final List<ParcelableUser> data, boolean fromUser) {
|
||||
@ -81,6 +82,10 @@ public abstract class BaseCursorSupportUsersLoader extends TwitterAPIUsersLoader
|
||||
if (cursor == null) return;
|
||||
mNextCursor = cursor.getNextCursor();
|
||||
mPrevCursor = cursor.getPreviousCursor();
|
||||
mNextPage = mPage + 1;
|
||||
}
|
||||
|
||||
public int getNextPage() {
|
||||
return mNextPage;
|
||||
}
|
||||
}
|
||||
|
@ -28,8 +28,8 @@ import org.mariotaku.twidere.api.twitter.model.CursorSupport;
|
||||
import org.mariotaku.twidere.api.twitter.model.Paging;
|
||||
import org.mariotaku.twidere.api.twitter.model.ResponseList;
|
||||
import org.mariotaku.twidere.api.twitter.model.User;
|
||||
import org.mariotaku.twidere.model.UserKey;
|
||||
import org.mariotaku.twidere.model.ParcelableUser;
|
||||
import org.mariotaku.twidere.model.UserKey;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -51,7 +51,7 @@ public abstract class CursorSupportUsersLoader extends BaseCursorSupportUsersLoa
|
||||
paging.count(getCount());
|
||||
if (getCursor() > 0) {
|
||||
paging.setCursor(getCursor());
|
||||
} else if (getPage() >= -1) {
|
||||
} else if (getPage() > 0) {
|
||||
paging.setPage(getPage());
|
||||
}
|
||||
final ResponseList<User> users = getCursoredUsers(twitter, paging);
|
||||
|
@ -4,6 +4,7 @@ import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import org.mariotaku.twidere.TwidereConstants;
|
||||
import org.mariotaku.twidere.api.twitter.model.User;
|
||||
@ -65,4 +66,10 @@ public class UserKeyUtils {
|
||||
if (authority == null) return TwidereConstants.USER_TYPE_TWITTER_COM;
|
||||
return authority.replaceAll("[^\\w\\d\\.]", "-");
|
||||
}
|
||||
|
||||
public static boolean isSameHost(UserKey accountKey, UserKey userKey) {
|
||||
final String a = accountKey.getHost(), b = userKey.getHost();
|
||||
if (TextUtils.isEmpty(a) || TextUtils.isEmpty(b)) return true;
|
||||
return a.equals(b);
|
||||
}
|
||||
}
|
||||
|
@ -39,9 +39,11 @@ import org.mariotaku.twidere.api.twitter.auth.OAuthAuthorization;
|
||||
import org.mariotaku.twidere.api.twitter.auth.OAuthEndpoint;
|
||||
import org.mariotaku.twidere.api.twitter.auth.OAuthToken;
|
||||
import org.mariotaku.twidere.api.twitter.util.TwitterConverterFactory;
|
||||
import org.mariotaku.twidere.model.UserKey;
|
||||
import org.mariotaku.twidere.model.ConsumerKeyType;
|
||||
import org.mariotaku.twidere.model.ParcelableAccount;
|
||||
import org.mariotaku.twidere.model.ParcelableCredentials;
|
||||
import org.mariotaku.twidere.model.UserKey;
|
||||
import org.mariotaku.twidere.model.util.ParcelableAccountUtils;
|
||||
import org.mariotaku.twidere.model.util.ParcelableCredentialsUtils;
|
||||
import org.mariotaku.twidere.provider.TwidereDataStore.Accounts;
|
||||
import org.mariotaku.twidere.util.dagger.DependencyHolder;
|
||||
@ -197,15 +199,15 @@ public class TwitterAPIFactory implements TwidereConstants {
|
||||
}
|
||||
|
||||
public static boolean isTwitterCredentials(Context context, UserKey accountId) {
|
||||
return isTwitterCredentials(ParcelableCredentialsUtils.getCredentials(context, accountId));
|
||||
return isTwitterCredentials(ParcelableAccountUtils.getAccount(context, accountId));
|
||||
}
|
||||
|
||||
public static boolean isTwitterCredentials(ParcelableCredentials credentials) {
|
||||
public static boolean isTwitterCredentials(ParcelableAccount credentials) {
|
||||
return credentials.account_type == null ||
|
||||
ParcelableCredentials.ACCOUNT_TYPE_TWITTER.equals(credentials.account_type);
|
||||
}
|
||||
|
||||
public static boolean isStatusNetCredentials(ParcelableCredentials credentials) {
|
||||
public static boolean isStatusNetCredentials(ParcelableAccount credentials) {
|
||||
return ParcelableCredentials.ACCOUNT_TYPE_STATUSNET.equals(credentials.account_type);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user