improved activities refresh
This commit is contained in:
parent
24a476aba4
commit
f080f840f7
|
@ -50,7 +50,6 @@ public abstract class ThemedAppCompatActivity extends AppCompatActivity implemen
|
|||
|
||||
private ThemedAppCompatDelegateFactory.ThemedAppCompatDelegate mDelegate;
|
||||
private Toolbar mToolbar;
|
||||
private int mCurrentThemeResource;
|
||||
|
||||
@Override
|
||||
public String getCurrentThemeFontFamily() {
|
||||
|
@ -104,9 +103,6 @@ public abstract class ThemedAppCompatActivity extends AppCompatActivity implemen
|
|||
StrictModeUtils.detectAllVmPolicy();
|
||||
StrictModeUtils.detectAllThreadPolicy();
|
||||
}
|
||||
if (mCurrentThemeResource != 0) {
|
||||
getTheme().applyStyle(mCurrentThemeResource, true);
|
||||
}
|
||||
super.onCreate(savedInstanceState);
|
||||
ThemeUtils.applyToolbarItemColor(this, getActionBarToolbar(), getCurrentThemeColor());
|
||||
}
|
||||
|
@ -129,7 +125,6 @@ public abstract class ThemedAppCompatActivity extends AppCompatActivity implemen
|
|||
@Override
|
||||
public void setTheme(int resId) {
|
||||
super.setTheme(resId);
|
||||
mCurrentThemeResource = resId;
|
||||
if (shouldApplyWindowBackground()) {
|
||||
ThemeUtils.applyWindowBackground(this, getWindow(), mCurrentThemeBackgroundOption,
|
||||
mCurrentThemeBackgroundAlpha);
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
package org.mariotaku.twidere.model.util;
|
||||
|
||||
import org.mariotaku.twidere.model.ParcelableCredentials;
|
||||
|
||||
/**
|
||||
* Created by mariotaku on 16/3/4.
|
||||
*/
|
||||
public class ParcelableCredentialsUtils {
|
||||
public static boolean isOAuth(int authType) {
|
||||
switch (authType) {
|
||||
case ParcelableCredentials.AUTH_TYPE_OAUTH:
|
||||
case ParcelableCredentials.AUTH_TYPE_XAUTH: {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -45,7 +45,7 @@ public class GetActivitiesAboutMeTask extends GetActivitiesTask {
|
|||
|
||||
@Override
|
||||
protected ResponseList<Activity> getActivities(@NonNull final Twitter twitter, final long accountId, final Paging paging) throws TwitterException {
|
||||
if (Utils.shouldUsePrivateAPIs(context, accountId)) {
|
||||
if (Utils.isOfficialCredentials(context, accountId)) {
|
||||
return twitter.getActivitiesAboutMe(paging);
|
||||
}
|
||||
final ResponseList<Activity> activities = new ResponseList<>();
|
||||
|
|
|
@ -87,7 +87,7 @@ public abstract class GetActivitiesTask extends AbstractTask<RefreshTaskParam, O
|
|||
// We should delete old activities has intersection with new items
|
||||
try {
|
||||
final ResponseList<Activity> activities = getActivities(twitter, accountId, paging);
|
||||
storeActivities(cr, loadItemLimit, accountId, noItemsBefore, activities);
|
||||
storeActivities(cr, accountId, noItemsBefore, activities);
|
||||
// if (saveReadPosition && TwitterAPIFactory.isOfficialTwitterInstance(context, twitter)) {
|
||||
if (saveReadPosition) {
|
||||
saveReadPosition(accountId, twitter);
|
||||
|
@ -112,8 +112,8 @@ public abstract class GetActivitiesTask extends AbstractTask<RefreshTaskParam, O
|
|||
@NonNull
|
||||
protected abstract String getErrorInfoKey();
|
||||
|
||||
private void storeActivities(ContentResolver cr, int loadItemLimit, long accountId,
|
||||
boolean noItemsBefore, ResponseList<Activity> activities) {
|
||||
private void storeActivities(ContentResolver cr, long accountId, boolean noItemsBefore,
|
||||
ResponseList<Activity> activities) {
|
||||
long[] deleteBound = new long[2];
|
||||
Arrays.fill(deleteBound, -1);
|
||||
List<ContentValues> valuesList = new ArrayList<>();
|
||||
|
@ -140,8 +140,7 @@ public abstract class GetActivitiesTask extends AbstractTask<RefreshTaskParam, O
|
|||
Expression.lesserEquals(Activities.MAX_POSITION, deleteBound[1])
|
||||
);
|
||||
int rowsDeleted = cr.delete(getContentUri(), where.getSQL(), null);
|
||||
boolean insertGap = valuesList.size() >= loadItemLimit && !noItemsBefore
|
||||
&& rowsDeleted <= 0;
|
||||
boolean insertGap = !noItemsBefore && rowsDeleted <= 0;
|
||||
if (insertGap && !valuesList.isEmpty()) {
|
||||
valuesList.get(valuesList.size() - 1).put(Activities.IS_GAP, true);
|
||||
}
|
||||
|
|
|
@ -982,7 +982,6 @@ public class ThemeUtils implements Constants {
|
|||
break;
|
||||
}
|
||||
}
|
||||
delegate.applyDayNight();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -15,7 +15,6 @@ import com.fasterxml.jackson.core.JsonParseException;
|
|||
|
||||
import org.mariotaku.restfu.ExceptionFactory;
|
||||
import org.mariotaku.restfu.RestAPIFactory;
|
||||
import org.mariotaku.restfu.RestClient;
|
||||
import org.mariotaku.restfu.RestConverter;
|
||||
import org.mariotaku.restfu.RestFuUtils;
|
||||
import org.mariotaku.restfu.RestRequest;
|
||||
|
@ -38,12 +37,12 @@ import org.mariotaku.twidere.api.twitter.auth.BasicAuthorization;
|
|||
import org.mariotaku.twidere.api.twitter.auth.EmptyAuthorization;
|
||||
import org.mariotaku.twidere.api.twitter.auth.OAuthAuthorization;
|
||||
import org.mariotaku.twidere.api.twitter.auth.OAuthEndpoint;
|
||||
import org.mariotaku.twidere.api.twitter.auth.OAuthSupport;
|
||||
import org.mariotaku.twidere.api.twitter.auth.OAuthToken;
|
||||
import org.mariotaku.twidere.api.twitter.util.TwitterConverterFactory;
|
||||
import org.mariotaku.twidere.model.ConsumerKeyType;
|
||||
import org.mariotaku.twidere.model.ParcelableCredentials;
|
||||
import org.mariotaku.twidere.provider.TwidereDataStore;
|
||||
import org.mariotaku.twidere.model.util.ParcelableCredentialsUtils;
|
||||
import org.mariotaku.twidere.provider.TwidereDataStore.Accounts;
|
||||
import org.mariotaku.twidere.util.dagger.DependencyHolder;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -381,21 +380,18 @@ public class TwitterAPIFactory implements TwidereConstants {
|
|||
return ('A' <= codePoint && codePoint <= 'Z') || ('a' <= codePoint && codePoint <= 'z') || '0' <= codePoint && codePoint <= '9';
|
||||
}
|
||||
|
||||
public static boolean isOfficialKeyAccount(final Context context, final long accountId) {
|
||||
return getOfficialKeyType(context, accountId) != ConsumerKeyType.UNKNOWN;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public static ConsumerKeyType getOfficialKeyType(final Context context, final long accountId) {
|
||||
if (context == null) return ConsumerKeyType.UNKNOWN;
|
||||
final String[] projection = {TwidereDataStore.Accounts.CONSUMER_KEY, TwidereDataStore.Accounts.CONSUMER_SECRET};
|
||||
final String selection = Expression.equals(TwidereDataStore.Accounts.ACCOUNT_ID, accountId).getSQL();
|
||||
final Cursor c = context.getContentResolver().query(TwidereDataStore.Accounts.CONTENT_URI, projection, selection, null, null);
|
||||
final String[] projection = {Accounts.CONSUMER_KEY, Accounts.CONSUMER_SECRET, Accounts.AUTH_TYPE};
|
||||
final String selection = Expression.equals(Accounts.ACCOUNT_ID, accountId).getSQL();
|
||||
final Cursor c = context.getContentResolver().query(Accounts.CONTENT_URI, projection, selection, null, null);
|
||||
if (c == null) return ConsumerKeyType.UNKNOWN;
|
||||
//noinspection TryFinallyCanBeTryWithResources
|
||||
try {
|
||||
if (c.moveToPosition(0))
|
||||
if (c.moveToPosition(0) && ParcelableCredentialsUtils.isOAuth(c.getInt(2))) {
|
||||
return TwitterContentUtils.getOfficialKeyType(context, c.getString(0), c.getString(1));
|
||||
}
|
||||
} finally {
|
||||
c.close();
|
||||
}
|
||||
|
|
|
@ -176,6 +176,7 @@ import org.mariotaku.twidere.model.ParcelableUserList;
|
|||
import org.mariotaku.twidere.model.ParcelableUserMention;
|
||||
import org.mariotaku.twidere.model.PebbleMessage;
|
||||
import org.mariotaku.twidere.model.TwitterAccountExtra;
|
||||
import org.mariotaku.twidere.model.util.ParcelableCredentialsUtils;
|
||||
import org.mariotaku.twidere.model.util.ParcelableStatusUtils;
|
||||
import org.mariotaku.twidere.model.util.ParcelableUserUtils;
|
||||
import org.mariotaku.twidere.provider.TwidereDataStore;
|
||||
|
@ -969,9 +970,10 @@ public final class Utils implements Constants {
|
|||
return hasNavBar(context);
|
||||
}
|
||||
|
||||
public static boolean isOfficialCredentials(@NonNull final Context context,
|
||||
@NonNull final long accountId) {
|
||||
return isOfficialCredentials(context, DataStoreUtils.getCredentials(context, accountId));
|
||||
public static boolean isOfficialCredentials(@NonNull final Context context, final long accountId) {
|
||||
final ParcelableCredentials credentials = DataStoreUtils.getCredentials(context, accountId);
|
||||
if (credentials == null) return false;
|
||||
return isOfficialCredentials(context, credentials);
|
||||
}
|
||||
|
||||
public static boolean isOfficialCredentials(@NonNull final Context context,
|
||||
|
@ -983,8 +985,7 @@ public final class Utils implements Constants {
|
|||
return extra.isOfficialCredentials();
|
||||
}
|
||||
}
|
||||
final boolean isOAuth = account.auth_type == ParcelableCredentials.AUTH_TYPE_OAUTH
|
||||
|| account.auth_type == ParcelableCredentials.AUTH_TYPE_XAUTH;
|
||||
final boolean isOAuth = ParcelableCredentialsUtils.isOAuth(account.auth_type);
|
||||
final String consumerKey = account.consumer_key, consumerSecret = account.consumer_secret;
|
||||
return isOAuth && TwitterContentUtils.isOfficialKey(context, consumerKey, consumerSecret);
|
||||
}
|
||||
|
@ -2667,10 +2668,6 @@ public final class Utils implements Constants {
|
|||
|| plugged == BatteryManager.BATTERY_PLUGGED_WIRELESS;
|
||||
}
|
||||
|
||||
public static boolean shouldUsePrivateAPIs(Context context, long accountId) {
|
||||
return TwitterAPIFactory.isOfficialKeyAccount(context, accountId);
|
||||
}
|
||||
|
||||
public static boolean isMediaPreviewEnabled(Context context, SharedPreferencesWrapper preferences) {
|
||||
if (!preferences.getBoolean(KEY_MEDIA_PREVIEW)) return false;
|
||||
final ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
|
|
Loading…
Reference in New Issue