From e7cc857197240c3461c97a7d5d198ac7f29154b5 Mon Sep 17 00:00:00 2001 From: Mariotaku Lee Date: Sat, 6 Feb 2016 20:50:06 +0800 Subject: [PATCH] improved error info --- .../fragment/support/CursorActivitiesFragment.java | 10 ++++++++-- .../support/BaseCursorSupportUsersLoader.java | 8 +++----- .../twidere/loader/support/UserSearchLoader.java | 3 --- .../twidere/task/twitter/GetActivitiesTask.java | 13 ++++++++++++- .../mariotaku/twidere/util/AsyncTwitterWrapper.java | 6 +++++- .../org/mariotaku/twidere/util/ErrorInfoStore.java | 6 ++++++ .../main/java/org/mariotaku/twidere/util/Utils.java | 5 +++++ twidere/src/main/res/values/strings.xml | 1 + 8 files changed, 40 insertions(+), 12 deletions(-) diff --git a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/CursorActivitiesFragment.java b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/CursorActivitiesFragment.java index c2be3981d..ff9740e85 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/CursorActivitiesFragment.java +++ b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/CursorActivitiesFragment.java @@ -51,6 +51,7 @@ import org.mariotaku.twidere.provider.TwidereDataStore.Accounts; import org.mariotaku.twidere.provider.TwidereDataStore.Activities; import org.mariotaku.twidere.provider.TwidereDataStore.Filters; 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.FavoriteCreatedEvent; import org.mariotaku.twidere.util.message.FavoriteDestroyedEvent; @@ -75,8 +76,13 @@ public abstract class CursorActivitiesFragment extends AbsActivitiesFragment 0) { showContent(); } else if (accountIds.length > 0) { - showContent(); - showEmpty(R.drawable.ic_info_refresh, getString(R.string.swipe_down_to_refresh)); + final ErrorInfoStore.DisplayErrorInfo errorInfo = ErrorInfoStore.getErrorInfo(getContext(), + mErrorInfoStore.get(ErrorInfoStore.KEY_INTERACTIONS, accountIds[0])); + if (errorInfo != null) { + showError(errorInfo.getIcon(), errorInfo.getMessage()); + } else { + showContent(); + } } else { showError(R.drawable.ic_info_accounts, getString(R.string.no_account_selected)); } diff --git a/twidere/src/main/java/org/mariotaku/twidere/loader/support/BaseCursorSupportUsersLoader.java b/twidere/src/main/java/org/mariotaku/twidere/loader/support/BaseCursorSupportUsersLoader.java index 44c1ad2b1..4ed2cc57f 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/loader/support/BaseCursorSupportUsersLoader.java +++ b/twidere/src/main/java/org/mariotaku/twidere/loader/support/BaseCursorSupportUsersLoader.java @@ -22,18 +22,16 @@ package org.mariotaku.twidere.loader.support; import android.content.Context; 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.ParcelableUser; import java.util.List; -import org.mariotaku.twidere.api.twitter.model.CursorSupport; - public abstract class BaseCursorSupportUsersLoader extends TwitterAPIUsersLoader implements ICursorSupportLoader { private final long mCursor; - private final SharedPreferences mPreferences; private final int mLoadItemLimit; private long mNextCursor, mPrevCursor; @@ -42,8 +40,8 @@ public abstract class BaseCursorSupportUsersLoader extends TwitterAPIUsersLoader final List 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); + final SharedPreferences preferences = context.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE); + final int loadItemLimit = preferences.getInt(KEY_LOAD_ITEM_LIMIT, DEFAULT_LOAD_ITEM_LIMIT); mLoadItemLimit = Math.min(100, loadItemLimit); } diff --git a/twidere/src/main/java/org/mariotaku/twidere/loader/support/UserSearchLoader.java b/twidere/src/main/java/org/mariotaku/twidere/loader/support/UserSearchLoader.java index aaede560f..3161ecf59 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/loader/support/UserSearchLoader.java +++ b/twidere/src/main/java/org/mariotaku/twidere/loader/support/UserSearchLoader.java @@ -58,7 +58,4 @@ public class UserSearchLoader extends TwitterAPIUsersLoader { return twitter.searchUsers(mQuery, paging); } - protected long getUserPosition(final User user, final int index) { - return (mPage + 1) * 20 + index; - } } diff --git a/twidere/src/main/java/org/mariotaku/twidere/task/twitter/GetActivitiesTask.java b/twidere/src/main/java/org/mariotaku/twidere/task/twitter/GetActivitiesTask.java index 98ebe6e23..3ec1e0f07 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/task/twitter/GetActivitiesTask.java +++ b/twidere/src/main/java/org/mariotaku/twidere/task/twitter/GetActivitiesTask.java @@ -4,8 +4,10 @@ import android.content.ContentResolver; import android.content.ContentValues; import android.content.Context; import android.net.Uri; +import android.util.Log; import org.mariotaku.sqliteqb.library.Expression; +import org.mariotaku.twidere.BuildConfig; import org.mariotaku.twidere.api.twitter.Twitter; import org.mariotaku.twidere.api.twitter.TwitterException; 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.ContentValuesCreator; import org.mariotaku.twidere.util.DataStoreUtils; +import org.mariotaku.twidere.util.ErrorInfoStore; import org.mariotaku.twidere.util.TwitterAPIFactory; import org.mariotaku.twidere.util.content.ContentResolverUtils; import org.mariotaku.twidere.util.message.GetActivitiesTaskEvent; @@ -68,6 +71,7 @@ public abstract class GetActivitiesTask extends ManagedAsyncTask activities = getActivities(accountId, twitter, paging); @@ -76,8 +80,15 @@ public abstract class GetActivitiesTask extends ManagedAsyncTask getActivities(long accountId, Twitter twitter, Paging paging) throws TwitterException { - if (TwitterAPIFactory.isOfficialKeyAccount(getContext(), accountId)) { + if (Utils.shouldUsePrivateAPIs(getContext(), accountId)) { return twitter.getActivitiesAboutMe(paging); } final ResponseList activities = new ResponseList<>(); @@ -600,6 +600,10 @@ public class AsyncTwitterWrapper extends TwitterWrapper { AsyncManager.runBackgroundTask(task); } + public ErrorInfoStore getErrorInfoStore() { + return mErrorInfoStore; + } + static class GetSavedSearchesTask extends ManagedAsyncTask> { private final Context mContext; diff --git a/twidere/src/main/java/org/mariotaku/twidere/util/ErrorInfoStore.java b/twidere/src/main/java/org/mariotaku/twidere/util/ErrorInfoStore.java index 707e3bb02..83d9b435a 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/util/ErrorInfoStore.java +++ b/twidere/src/main/java/org/mariotaku/twidere/util/ErrorInfoStore.java @@ -15,8 +15,10 @@ import org.mariotaku.twidere.R; public class ErrorInfoStore { 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_ACCESS_FOR_CREDENTIALS = 2; private final SharedPreferences mPreferences; @@ -47,6 +49,10 @@ public class ErrorInfoStore { return new DisplayErrorInfo(code, R.drawable.ic_info_error_generic, 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; } diff --git a/twidere/src/main/java/org/mariotaku/twidere/util/Utils.java b/twidere/src/main/java/org/mariotaku/twidere/util/Utils.java index 095bdbf42..4823134d3 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/util/Utils.java +++ b/twidere/src/main/java/org/mariotaku/twidere/util/Utils.java @@ -3074,6 +3074,11 @@ public final class Utils implements Constants { || 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 { @TargetApi(Build.VERSION_CODES.LOLLIPOP) diff --git a/twidere/src/main/res/values/strings.xml b/twidere/src/main/res/values/strings.xml index 952365827..6021b7a53 100644 --- a/twidere/src/main/res/values/strings.xml +++ b/twidere/src/main/res/values/strings.xml @@ -841,6 +841,7 @@ %1$s: %2$s Mentions only No direct message permission, check your Twitter application permission setting. + Your application can\'t access this resource, have you enabled \'Force using private APIs\'? Select accounts for compose Interactions \ No newline at end of file