fixed fanfou fav load more

This commit is contained in:
Mariotaku Lee 2016-06-20 14:33:22 +08:00
parent e7edf60a96
commit c5e0f90111
19 changed files with 116 additions and 53 deletions

View File

@ -7,10 +7,10 @@ android:
- tools
# The BuildTools version used by your project
- build-tools-23.0.3
- build-tools-24.0.0
# The SDK version used to compile your project
- android-23
- android-24
# Additional components
- extra-google-google_play_services

View File

@ -36,8 +36,8 @@ subprojects {
if (project.hasProperty('android')) {
android {
compileSdkVersion 23
buildToolsVersion '23.0.3'
compileSdkVersion 24
buildToolsVersion '24.0.0'
lintOptions {
abortOnError false

View File

@ -19,17 +19,16 @@
package org.mariotaku.microblog.library.twitter.api;
import org.mariotaku.microblog.library.twitter.template.StatusAnnotationTemplate;
import org.mariotaku.restfu.annotation.method.GET;
import org.mariotaku.restfu.annotation.method.POST;
import org.mariotaku.restfu.annotation.param.KeyValue;
import org.mariotaku.restfu.annotation.param.Param;
import org.mariotaku.restfu.annotation.param.Queries;
import org.mariotaku.restfu.annotation.param.Query;
import org.mariotaku.microblog.library.MicroBlogException;
import org.mariotaku.microblog.library.twitter.model.Paging;
import org.mariotaku.microblog.library.twitter.model.ResponseList;
import org.mariotaku.microblog.library.twitter.model.Status;
import org.mariotaku.microblog.library.twitter.template.StatusAnnotationTemplate;
import org.mariotaku.restfu.annotation.method.GET;
import org.mariotaku.restfu.annotation.method.POST;
import org.mariotaku.restfu.annotation.param.Param;
import org.mariotaku.restfu.annotation.param.Queries;
import org.mariotaku.restfu.annotation.param.Query;
@SuppressWarnings("RedundantThrows")
@Queries(template = StatusAnnotationTemplate.class)
@ -45,8 +44,8 @@ public interface FavoritesResources {
ResponseList<Status> getFavorites() throws MicroBlogException;
@GET("/favorites/list.json")
ResponseList<Status> getFavorites(@Query("user_id") String userId, @Query({"since_id", "max_id", "count"}) Paging paging) throws MicroBlogException;
ResponseList<Status> getFavorites(@Query("user_id") String userId, @Query Paging paging) throws MicroBlogException;
@GET("/favorites/list.json")
ResponseList<Status> getFavoritesByScreenName(@Query("screen_name") String screenName, @Query({"since_id", "max_id", "count"}) Paging paging) throws MicroBlogException;
ResponseList<Status> getFavoritesByScreenName(@Query("screen_name") String screenName, @Query Paging paging) throws MicroBlogException;
}

View File

@ -27,7 +27,7 @@ android {
defaultConfig {
applicationId "org.mariotaku.twidere"
minSdkVersion 14
targetSdkVersion 23
targetSdkVersion 24
versionCode 196
versionName "3.1.7"
multiDexEnabled true

View File

@ -72,6 +72,7 @@
android:hardwareAccelerated="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:resizeableActivity="true"
android:supportsRtl="true"
android:theme="@style/Theme.Twidere.NoActionBar"
tools:ignore="UnusedAttribute">

View File

@ -320,7 +320,7 @@ public abstract class AbsStatusesFragment extends AbsContentListRecyclerViewFrag
if (loader instanceof IExtendedLoader) {
((IExtendedLoader) loader).setFromUser(false);
}
onLoadingFinished();
onStatusesLoaded(loader, data);
}
@Override
@ -574,7 +574,7 @@ public abstract class AbsStatusesFragment extends AbsContentListRecyclerViewFrag
protected abstract Loader<List<ParcelableStatus>> onCreateStatusesLoader(final Context context, final Bundle args,
final boolean fromUser);
protected abstract void onLoadingFinished();
protected abstract void onStatusesLoaded(Loader<List<ParcelableStatus>> loader, List<ParcelableStatus> data);
protected final void saveReadPosition(int position) {
final String readPositionTag = getReadPositionTagWithAccounts();

View File

@ -70,22 +70,8 @@ import static org.mariotaku.twidere.util.DataStoreUtils.getTableNameByUri;
public abstract class CursorStatusesFragment extends AbsStatusesFragment {
@Override
protected void onLoadingFinished() {
final UserKey[] accountKeys = getAccountKeys();
final ParcelableStatusesAdapter adapter = getAdapter();
if (adapter.getItemCount() > 0) {
showContent();
} else if (accountKeys.length > 0) {
final ErrorInfoStore.DisplayErrorInfo errorInfo = ErrorInfoStore.getErrorInfo(getContext(),
mErrorInfoStore.get(getErrorInfoKey(), accountKeys[0]));
if (errorInfo != null) {
showEmpty(errorInfo.getIcon(), errorInfo.getMessage());
} else {
showEmpty(R.drawable.ic_info_refresh, getString(R.string.swipe_down_to_refresh));
}
} else {
showError(R.drawable.ic_info_accounts, getString(R.string.no_account_selected));
}
protected void onStatusesLoaded(Loader<List<ParcelableStatus>> loader, List<ParcelableStatus> data) {
showContentOrError();
}
private ContentObserver mContentObserver;
@ -126,6 +112,24 @@ public abstract class CursorStatusesFragment extends AbsStatusesFragment {
return new CursorStatusesBusCallback();
}
private void showContentOrError() {
final UserKey[] accountKeys = getAccountKeys();
final ParcelableStatusesAdapter adapter = getAdapter();
if (adapter.getItemCount() > 0) {
showContent();
} else if (accountKeys.length > 0) {
final ErrorInfoStore.DisplayErrorInfo errorInfo = ErrorInfoStore.getErrorInfo(getContext(),
mErrorInfoStore.get(getErrorInfoKey(), accountKeys[0]));
if (errorInfo != null) {
showEmpty(errorInfo.getIcon(), errorInfo.getMessage());
} else {
showEmpty(R.drawable.ic_info_refresh, getString(R.string.swipe_down_to_refresh));
}
} else {
showError(R.drawable.ic_info_accounts, getString(R.string.no_account_selected));
}
}
protected class CursorStatusesBusCallback {
@ -136,7 +140,7 @@ public abstract class CursorStatusesFragment extends AbsStatusesFragment {
if (!event.running) {
setLoadMoreIndicatorPosition(IndicatorPosition.NONE);
setRefreshEnabled(true);
onLoadingFinished();
showContentOrError();
}
}

View File

@ -24,15 +24,19 @@ import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.LoaderManager;
import android.support.v4.content.Loader;
import android.support.v7.widget.LinearLayoutManager;
import android.text.TextUtils;
import com.squareup.otto.Subscribe;
import org.mariotaku.microblog.library.MicroBlogException;
import org.mariotaku.twidere.R;
import org.mariotaku.twidere.adapter.ListParcelableStatusesAdapter;
import org.mariotaku.twidere.adapter.ParcelableStatusesAdapter;
import org.mariotaku.twidere.adapter.iface.ILoadMoreSupportAdapter.IndicatorPosition;
import org.mariotaku.twidere.adapter.iface.IStatusesAdapter;
import org.mariotaku.twidere.loader.MicroBlogAPIStatusesLoader;
import org.mariotaku.twidere.model.BaseRefreshTaskParam;
import org.mariotaku.twidere.model.ParcelableStatus;
import org.mariotaku.twidere.model.RefreshTaskParam;
@ -139,11 +143,23 @@ public abstract class ParcelableStatusesFragment extends AbsStatusesFragment {
}
@Override
protected void onLoadingFinished() {
showContent();
protected void onStatusesLoaded(Loader<List<ParcelableStatus>> loader, List<ParcelableStatus> data) {
setRefreshEnabled(true);
setRefreshing(false);
setLoadMoreIndicatorPosition(IndicatorPosition.NONE);
final ParcelableStatusesAdapter adapter = getAdapter();
if (adapter.getItemCount() > 0) {
showContent();
} else if (loader instanceof MicroBlogAPIStatusesLoader) {
MicroBlogException e = ((MicroBlogAPIStatusesLoader) loader).getException();
if (e != null) {
showError(R.drawable.ic_info_error_generic, Utils.getErrorMessage(getContext(), e));
} else {
showEmpty(R.drawable.ic_info_refresh, getString(R.string.swipe_down_to_refresh));
}
} else {
showEmpty(R.drawable.ic_info_refresh, getString(R.string.swipe_down_to_refresh));
}
}

View File

@ -47,12 +47,14 @@ public class UserFavoritesFragment extends ParcelableStatusesFragment {
final UserKey accountKey = Utils.getAccountKey(context, args);
final String maxId = args.getString(EXTRA_MAX_ID);
final String sinceId = args.getString(EXTRA_SINCE_ID);
final int page = args.getInt(EXTRA_PAGE, -1);
final UserKey userKey = args.getParcelable(EXTRA_USER_KEY);
final String screenName = args.getString(EXTRA_SCREEN_NAME);
final int tabPosition = args.getInt(EXTRA_TAB_POSITION, -1);
final boolean loadingMore = args.getBoolean(EXTRA_LOADING_MORE, false);
return new UserFavoritesLoader(context, accountKey, userKey, screenName, sinceId, maxId,
getAdapterData(), getSavedStatusesFileArgs(), tabPosition, fromUser, loadingMore);
page,getAdapterData(), getSavedStatusesFileArgs(), tabPosition, fromUser,
loadingMore);
}
@Override

View File

@ -56,7 +56,7 @@ public class ConversationLoader extends MicroBlogAPIStatusesLoader {
final long sinceSortId, final long maxSortId,
final List<ParcelableStatus> data, final boolean fromUser,
final boolean loadingMore) {
super(context, status.account_key, sinceId, maxId, data, null, -1, fromUser, loadingMore);
super(context, status.account_key, sinceId, maxId, -1, data, null, -1, fromUser, loadingMore);
mStatus = Nullables.assertNonNull(ParcelUtils.clone(status));
mSinceSortId = sinceSortId;
mMaxSortId = maxSortId;

View File

@ -45,7 +45,7 @@ public class GroupTimelineLoader extends MicroBlogAPIStatusesLoader {
final String groupName, final String sinceId, final String maxId,
final List<ParcelableStatus> data, final String[] savedStatusesArgs,
final int tabPosition, boolean fromUser, boolean loadingMore) {
super(context, accountKey, sinceId, maxId, data, savedStatusesArgs, tabPosition, fromUser, loadingMore);
super(context, accountKey, sinceId, maxId, -1, data, savedStatusesArgs, tabPosition, fromUser, loadingMore);
mGroupId = groupId;
mGroupName = groupName;
}

View File

@ -61,7 +61,7 @@ public class MediaTimelineLoader extends MicroBlogAPIStatusesLoader {
@Nullable final String screenName, final String sinceId, final String maxId,
final List<ParcelableStatus> data, final String[] savedStatusesArgs,
final int tabPosition, final boolean fromUser, boolean loadingMore) {
super(context, accountKey, sinceId, maxId, data, savedStatusesArgs, tabPosition, fromUser,
super(context, accountKey, sinceId, maxId, -1, data, savedStatusesArgs, tabPosition, fromUser,
loadingMore);
mUserKey = userKey;
mUserScreenName = screenName;

View File

@ -62,6 +62,7 @@ import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.atomic.AtomicReference;
import javax.inject.Inject;
@ -70,11 +71,13 @@ public abstract class MicroBlogAPIStatusesLoader extends ParcelableStatusesLoade
@Nullable
private final UserKey mAccountKey;
private final String mMaxId, mSinceId;
private final int mPage;
@Nullable
private final Object[] mSavedStatusesFileArgs;
private final boolean mLoadingMore;
// Statuses sorted descending by default
private Comparator<ParcelableStatus> mComparator = ParcelableStatus.REVERSE_COMPARATOR;
private AtomicReference<MicroBlogException> mException = new AtomicReference<>();
@Inject
protected DiskCache mFileCache;
@ -86,7 +89,7 @@ public abstract class MicroBlogAPIStatusesLoader extends ParcelableStatusesLoade
public MicroBlogAPIStatusesLoader(@NonNull final Context context,
@Nullable final UserKey accountKey,
final String sinceId, final String maxId,
@Nullable final List<ParcelableStatus> data,
int page, @Nullable final List<ParcelableStatus> data,
@Nullable final String[] savedStatusesArgs,
final int tabPosition, final boolean fromUser, boolean loadingMore) {
super(context, data, tabPosition, fromUser);
@ -94,6 +97,7 @@ public abstract class MicroBlogAPIStatusesLoader extends ParcelableStatusesLoade
mAccountKey = accountKey;
mMaxId = maxId;
mSinceId = sinceId;
mPage = page;
mSavedStatusesFileArgs = savedStatusesArgs;
mLoadingMore = loadingMore;
}
@ -142,6 +146,7 @@ public abstract class MicroBlogAPIStatusesLoader extends ParcelableStatusesLoade
statuses = getStatuses(twitter, credentials, paging);
} catch (final MicroBlogException e) {
// mHandler.post(new ShowErrorRunnable(e));
mException.set(e);
if (BuildConfig.DEBUG) {
Log.w(LOGTAG, e);
}
@ -209,6 +214,10 @@ public abstract class MicroBlogAPIStatusesLoader extends ParcelableStatusesLoade
return mMaxId;
}
public int getPage() {
return mPage;
}
@Nullable
public UserKey getAccountKey() {
return mAccountKey;
@ -222,9 +231,18 @@ public abstract class MicroBlogAPIStatusesLoader extends ParcelableStatusesLoade
@WorkerThread
protected abstract boolean shouldFilterStatus(final SQLiteDatabase database, final ParcelableStatus status);
@Nullable
public MicroBlogException getException() {
return mException.get();
}
@Override
protected void onStartLoading() {
mException.set(null);
super.onStartLoading();
}
protected void processPaging(@NonNull ParcelableCredentials credentials, int loadItemLimit, @NonNull final Paging paging) {
paging.setCount(loadItemLimit);
if (mMaxId != null) {
paging.setMaxId(mMaxId);

View File

@ -42,7 +42,7 @@ public class PublicTimelineLoader extends MicroBlogAPIStatusesLoader {
final String sinceId, final String maxId,
final List<ParcelableStatus> data, final String[] savedStatusesArgs,
final int tabPosition, boolean fromUser, boolean loadingMore) {
super(context, accountId, sinceId, maxId, data, savedStatusesArgs, tabPosition, fromUser, loadingMore);
super(context, accountId, sinceId, maxId, -1, data, savedStatusesArgs, tabPosition, fromUser, loadingMore);
}
@NonNull

View File

@ -43,7 +43,7 @@ public class RetweetsOfMeLoader extends MicroBlogAPIStatusesLoader {
final String sinceId, final String maxId,
final List<ParcelableStatus> data, final String[] savedStatusesArgs,
final int tabPosition, boolean fromUser, boolean loadingMore) {
super(context, accountKey, sinceId, maxId, data, savedStatusesArgs, tabPosition, fromUser,
super(context, accountKey, sinceId, maxId, -1, data, savedStatusesArgs, tabPosition, fromUser,
loadingMore);
}

View File

@ -44,7 +44,6 @@ public class TweetSearchLoader extends MicroBlogAPIStatusesLoader {
@Nullable
private final String mQuery;
private final int mPage;
private final boolean mGapEnabled;
public TweetSearchLoader(final Context context, final UserKey accountKey, @Nullable final String query,
@ -52,8 +51,8 @@ public class TweetSearchLoader extends MicroBlogAPIStatusesLoader {
final List<ParcelableStatus> data, final String[] savedStatusesArgs,
final int tabPosition, final boolean fromUser, final boolean makeGap,
boolean loadingMore) {
super(context, accountKey, sinceId, maxId, data, savedStatusesArgs, tabPosition, fromUser, loadingMore);
mPage = page;
super(context, accountKey, sinceId, maxId, page, data, savedStatusesArgs, tabPosition,
fromUser, loadingMore);
mQuery = query;
mGapEnabled = makeGap;
}
@ -99,8 +98,9 @@ public class TweetSearchLoader extends MicroBlogAPIStatusesLoader {
protected void processPaging(@NonNull ParcelableCredentials credentials, int loadItemLimit, @NonNull Paging paging) {
if (MicroBlogAPIFactory.isStatusNetCredentials(credentials)) {
paging.setRpp(loadItemLimit);
if (mPage > 0) {
paging.setPage(mPage);
final int page = getPage();
if (page > 0) {
paging.setPage(page);
}
} else {
super.processPaging(credentials, loadItemLimit, paging);

View File

@ -29,9 +29,12 @@ import org.mariotaku.microblog.library.MicroBlogException;
import org.mariotaku.microblog.library.twitter.model.Paging;
import org.mariotaku.microblog.library.twitter.model.ResponseList;
import org.mariotaku.microblog.library.twitter.model.Status;
import org.mariotaku.twidere.model.ParcelableAccount;
import org.mariotaku.twidere.model.ParcelableCredentials;
import org.mariotaku.twidere.model.ParcelableStatus;
import org.mariotaku.twidere.model.UserKey;
import org.mariotaku.twidere.model.util.ParcelableAccountUtils;
import org.mariotaku.twidere.util.InternalTwitterContentUtils;
import java.util.List;
@ -42,9 +45,10 @@ public class UserFavoritesLoader extends MicroBlogAPIStatusesLoader {
public UserFavoritesLoader(final Context context, final UserKey accountKey, final UserKey userKey,
final String screenName, final String sinceId, final String maxId,
final int page,
final List<ParcelableStatus> data, final String[] savedStatusesArgs,
final int tabPosition, boolean fromUser, boolean loadingMore) {
super(context, accountKey, sinceId, maxId, data, savedStatusesArgs, tabPosition, fromUser,
super(context, accountKey, sinceId, maxId, page, data, savedStatusesArgs, tabPosition, fromUser,
loadingMore);
mUserKey = userKey;
mUserScreenName = screenName;
@ -64,6 +68,25 @@ public class UserFavoritesLoader extends MicroBlogAPIStatusesLoader {
@WorkerThread
@Override
protected boolean shouldFilterStatus(final SQLiteDatabase database, final ParcelableStatus status) {
return false;
return InternalTwitterContentUtils.isFiltered(database, status, false);
}
@Override
protected void processPaging(@NonNull ParcelableCredentials credentials, int loadItemLimit, @NonNull Paging paging) {
switch (ParcelableAccountUtils.getAccountType(credentials)) {
case ParcelableAccount.Type.FANFOU: {
paging.setCount(loadItemLimit);
final int page = getPage();
if (page > 0) {
paging.setPage(page);
}
break;
}
default: {
super.processPaging(credentials, loadItemLimit, paging);
break;
}
}
}
}

View File

@ -46,7 +46,7 @@ public class UserListTimelineLoader extends MicroBlogAPIStatusesLoader {
final UserKey userKey, final String screenName, final String listName,
final String sinceId, final String maxId, final List<ParcelableStatus> data,
final String[] savedStatusesArgs, final int tabPosition, boolean fromUser, boolean loadingMore) {
super(context, accountKey, sinceId, maxId, data, savedStatusesArgs, tabPosition, fromUser, loadingMore);
super(context, accountKey, sinceId, maxId, -1, data, savedStatusesArgs, tabPosition, fromUser, loadingMore);
mListId = listId;
mUserKey = userKey;
mScreenName = screenName;

View File

@ -50,7 +50,7 @@ public class UserTimelineLoader extends MicroBlogAPIStatusesLoader {
final String sinceId, final String maxId,
final List<ParcelableStatus> data, final String[] savedStatusesArgs,
final int tabPosition, boolean fromUser, boolean loadingMore) {
super(context, accountId, sinceId, maxId, data, savedStatusesArgs, tabPosition, fromUser, loadingMore);
super(context, accountId, sinceId, maxId, -1, data, savedStatusesArgs, tabPosition, fromUser, loadingMore);
mUserId = userId;
mUserScreenName = screenName;
}