improved error info

This commit is contained in:
Mariotaku Lee 2016-02-06 20:50:06 +08:00
parent 8419e5db5e
commit e7cc857197
8 changed files with 40 additions and 12 deletions

View File

@ -51,6 +51,7 @@ import org.mariotaku.twidere.provider.TwidereDataStore.Accounts;
import org.mariotaku.twidere.provider.TwidereDataStore.Activities; import org.mariotaku.twidere.provider.TwidereDataStore.Activities;
import org.mariotaku.twidere.provider.TwidereDataStore.Filters; import org.mariotaku.twidere.provider.TwidereDataStore.Filters;
import org.mariotaku.twidere.util.DataStoreUtils; import org.mariotaku.twidere.util.DataStoreUtils;
import org.mariotaku.twidere.util.ErrorInfoStore;
import org.mariotaku.twidere.util.message.AccountChangedEvent; import org.mariotaku.twidere.util.message.AccountChangedEvent;
import org.mariotaku.twidere.util.message.FavoriteCreatedEvent; import org.mariotaku.twidere.util.message.FavoriteCreatedEvent;
import org.mariotaku.twidere.util.message.FavoriteDestroyedEvent; import org.mariotaku.twidere.util.message.FavoriteDestroyedEvent;
@ -75,8 +76,13 @@ public abstract class CursorActivitiesFragment extends AbsActivitiesFragment<Lis
if (adapter.getItemCount() > 0) { if (adapter.getItemCount() > 0) {
showContent(); showContent();
} else if (accountIds.length > 0) { } else if (accountIds.length > 0) {
final ErrorInfoStore.DisplayErrorInfo errorInfo = ErrorInfoStore.getErrorInfo(getContext(),
mErrorInfoStore.get(ErrorInfoStore.KEY_INTERACTIONS, accountIds[0]));
if (errorInfo != null) {
showError(errorInfo.getIcon(), errorInfo.getMessage());
} else {
showContent(); showContent();
showEmpty(R.drawable.ic_info_refresh, getString(R.string.swipe_down_to_refresh)); }
} else { } else {
showError(R.drawable.ic_info_accounts, getString(R.string.no_account_selected)); showError(R.drawable.ic_info_accounts, getString(R.string.no_account_selected));
} }

View File

@ -22,18 +22,16 @@ package org.mariotaku.twidere.loader.support;
import android.content.Context; import android.content.Context;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import org.mariotaku.twidere.api.twitter.model.CursorSupport;
import org.mariotaku.twidere.loader.support.iface.ICursorSupportLoader; import org.mariotaku.twidere.loader.support.iface.ICursorSupportLoader;
import org.mariotaku.twidere.model.ParcelableUser; import org.mariotaku.twidere.model.ParcelableUser;
import java.util.List; import java.util.List;
import org.mariotaku.twidere.api.twitter.model.CursorSupport;
public abstract class BaseCursorSupportUsersLoader extends TwitterAPIUsersLoader public abstract class BaseCursorSupportUsersLoader extends TwitterAPIUsersLoader
implements ICursorSupportLoader { implements ICursorSupportLoader {
private final long mCursor; private final long mCursor;
private final SharedPreferences mPreferences;
private final int mLoadItemLimit; private final int mLoadItemLimit;
private long mNextCursor, mPrevCursor; private long mNextCursor, mPrevCursor;
@ -42,8 +40,8 @@ public abstract class BaseCursorSupportUsersLoader extends TwitterAPIUsersLoader
final List<ParcelableUser> data, boolean fromUser) { final List<ParcelableUser> data, boolean fromUser) {
super(context, accountId, data, fromUser); super(context, accountId, data, fromUser);
mCursor = cursor; mCursor = cursor;
mPreferences = context.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE); final SharedPreferences preferences = context.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE);
final int loadItemLimit = mPreferences.getInt(KEY_LOAD_ITEM_LIMIT, DEFAULT_LOAD_ITEM_LIMIT); final int loadItemLimit = preferences.getInt(KEY_LOAD_ITEM_LIMIT, DEFAULT_LOAD_ITEM_LIMIT);
mLoadItemLimit = Math.min(100, loadItemLimit); mLoadItemLimit = Math.min(100, loadItemLimit);
} }

View File

@ -58,7 +58,4 @@ public class UserSearchLoader extends TwitterAPIUsersLoader {
return twitter.searchUsers(mQuery, paging); return twitter.searchUsers(mQuery, paging);
} }
protected long getUserPosition(final User user, final int index) {
return (mPage + 1) * 20 + index;
}
} }

View File

@ -4,8 +4,10 @@ import android.content.ContentResolver;
import android.content.ContentValues; import android.content.ContentValues;
import android.content.Context; import android.content.Context;
import android.net.Uri; import android.net.Uri;
import android.util.Log;
import org.mariotaku.sqliteqb.library.Expression; import org.mariotaku.sqliteqb.library.Expression;
import org.mariotaku.twidere.BuildConfig;
import org.mariotaku.twidere.api.twitter.Twitter; import org.mariotaku.twidere.api.twitter.Twitter;
import org.mariotaku.twidere.api.twitter.TwitterException; import org.mariotaku.twidere.api.twitter.TwitterException;
import org.mariotaku.twidere.api.twitter.model.Activity; import org.mariotaku.twidere.api.twitter.model.Activity;
@ -18,6 +20,7 @@ import org.mariotaku.twidere.task.ManagedAsyncTask;
import org.mariotaku.twidere.util.AsyncTwitterWrapper; import org.mariotaku.twidere.util.AsyncTwitterWrapper;
import org.mariotaku.twidere.util.ContentValuesCreator; import org.mariotaku.twidere.util.ContentValuesCreator;
import org.mariotaku.twidere.util.DataStoreUtils; import org.mariotaku.twidere.util.DataStoreUtils;
import org.mariotaku.twidere.util.ErrorInfoStore;
import org.mariotaku.twidere.util.TwitterAPIFactory; import org.mariotaku.twidere.util.TwitterAPIFactory;
import org.mariotaku.twidere.util.content.ContentResolverUtils; import org.mariotaku.twidere.util.content.ContentResolverUtils;
import org.mariotaku.twidere.util.message.GetActivitiesTaskEvent; import org.mariotaku.twidere.util.message.GetActivitiesTaskEvent;
@ -68,6 +71,7 @@ public abstract class GetActivitiesTask extends ManagedAsyncTask<Object, Object,
saveReadPosition = true; saveReadPosition = true;
} }
} }
final ErrorInfoStore errorInfoStore = twitterWrapper.getErrorInfoStore();
// We should delete old activities has intersection with new items // We should delete old activities has intersection with new items
try { try {
final ResponseList<Activity> activities = getActivities(accountId, twitter, paging); final ResponseList<Activity> activities = getActivities(accountId, twitter, paging);
@ -76,8 +80,15 @@ public abstract class GetActivitiesTask extends ManagedAsyncTask<Object, Object,
if (saveReadPosition) { if (saveReadPosition) {
saveReadPosition(accountId, twitter); saveReadPosition(accountId, twitter);
} }
errorInfoStore.remove(ErrorInfoStore.KEY_INTERACTIONS, accountId);
} catch (TwitterException e) { } catch (TwitterException e) {
if (BuildConfig.DEBUG) {
Log.w(LOGTAG, e);
}
if (e.getErrorCode() == 220) {
errorInfoStore.put(ErrorInfoStore.KEY_INTERACTIONS, accountId,
ErrorInfoStore.CODE_NO_ACCESS_FOR_CREDENTIALS);
}
} }
} }
return null; return null;

View File

@ -541,7 +541,7 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
@Override @Override
protected ResponseList<Activity> getActivities(long accountId, Twitter twitter, Paging paging) throws TwitterException { protected ResponseList<Activity> getActivities(long accountId, Twitter twitter, Paging paging) throws TwitterException {
if (TwitterAPIFactory.isOfficialKeyAccount(getContext(), accountId)) { if (Utils.shouldUsePrivateAPIs(getContext(), accountId)) {
return twitter.getActivitiesAboutMe(paging); return twitter.getActivitiesAboutMe(paging);
} }
final ResponseList<Activity> activities = new ResponseList<>(); final ResponseList<Activity> activities = new ResponseList<>();
@ -600,6 +600,10 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
AsyncManager.runBackgroundTask(task); AsyncManager.runBackgroundTask(task);
} }
public ErrorInfoStore getErrorInfoStore() {
return mErrorInfoStore;
}
static class GetSavedSearchesTask extends ManagedAsyncTask<Long, Object, SingleResponse<Object>> { static class GetSavedSearchesTask extends ManagedAsyncTask<Long, Object, SingleResponse<Object>> {
private final Context mContext; private final Context mContext;

View File

@ -15,8 +15,10 @@ import org.mariotaku.twidere.R;
public class ErrorInfoStore { public class ErrorInfoStore {
public static final String KEY_DIRECT_MESSAGES = "direct_messages"; public static final String KEY_DIRECT_MESSAGES = "direct_messages";
public static final String KEY_INTERACTIONS = "interactions";
public static final int CODE_NO_DM_PERMISSION = 1; public static final int CODE_NO_DM_PERMISSION = 1;
public static final int CODE_NO_ACCESS_FOR_CREDENTIALS = 2;
private final SharedPreferences mPreferences; private final SharedPreferences mPreferences;
@ -47,6 +49,10 @@ public class ErrorInfoStore {
return new DisplayErrorInfo(code, R.drawable.ic_info_error_generic, return new DisplayErrorInfo(code, R.drawable.ic_info_error_generic,
context.getString(R.string.error_no_dm_permission)); context.getString(R.string.error_no_dm_permission));
} }
case CODE_NO_ACCESS_FOR_CREDENTIALS: {
return new DisplayErrorInfo(code, R.drawable.ic_info_error_generic,
context.getString(R.string.error_no_access_for_credentials));
}
} }
return null; return null;
} }

View File

@ -3074,6 +3074,11 @@ public final class Utils implements Constants {
|| plugged == BatteryManager.BATTERY_PLUGGED_WIRELESS; || plugged == BatteryManager.BATTERY_PLUGGED_WIRELESS;
} }
public static boolean shouldUsePrivateAPIs(Context context, long accountId) {
if (shouldForceUsingPrivateAPIs(context)) return true;
return TwitterAPIFactory.isOfficialKeyAccount(context, accountId);
}
static class UtilsL { static class UtilsL {
@TargetApi(Build.VERSION_CODES.LOLLIPOP) @TargetApi(Build.VERSION_CODES.LOLLIPOP)

View File

@ -841,6 +841,7 @@
<string name="title_summary_line_format"><xliff:g id="title">%1$s</xliff:g>: <xliff:g id="summary">%2$s</xliff:g></string> <string name="title_summary_line_format"><xliff:g id="title">%1$s</xliff:g>: <xliff:g id="summary">%2$s</xliff:g></string>
<string name="mentions_only">Mentions only</string> <string name="mentions_only">Mentions only</string>
<string name="error_no_dm_permission">No direct message permission, check your Twitter application permission setting.</string> <string name="error_no_dm_permission">No direct message permission, check your Twitter application permission setting.</string>
<string name="error_no_access_for_credentials">Your application can\'t access this resource, have you enabled \'Force using private APIs\'?</string>
<string name="select_accounts_for_compose">Select accounts for compose</string> <string name="select_accounts_for_compose">Select accounts for compose</string>
<string name="interactions">Interactions</string> <string name="interactions">Interactions</string>
</resources> </resources>