fixed #421
fixed #420
This commit is contained in:
Mariotaku Lee 2016-03-01 22:36:49 +08:00
parent 7b0f59d9a0
commit ee3bc778d7
14 changed files with 75 additions and 66 deletions

View File

@ -50,8 +50,8 @@ public interface TwidereConstants extends SharedPreferenceConstants, IntentConst
String TWITTER_CONSUMER_KEY_LEGACY = "uAFVpMhBntJutfVj6abfA";
String TWITTER_CONSUMER_SECRET_LEGACY = "JARXkJTfxo0F8MyctYy9bUmrLISjo8vXAHsZHYuk2E";
String TWITTER_CONSUMER_KEY = "YVROlQkXFvkPfH3jcFaR4A";
String TWITTER_CONSUMER_SECRET = "0UnEHDq5IzVK9nstiz2nWOtG5rOMM5JkUpATfM78Do";
String TWITTER_CONSUMER_KEY = "i5XtSVfoWjLjKlnrvhiLPMZC0";
String TWITTER_CONSUMER_SECRET = "sQncmZ2atQR6tKbqnnAtqjrECqN8k6FD4p4OoNS0XTDkUz3HGH";
String DEFAULT_TWITTER_API_URL_FORMAT = "https://[DOMAIN.]twitter.com/";
String DEFAULT_TWITTER_OAUTH_BASE_URL = "https://api.twitter.com/oauth/";

View File

@ -165,19 +165,12 @@ public class ParcelableMedia implements Parcelable {
@Retention(RetentionPolicy.SOURCE)
public @interface Type {
@Type
int UNKNOWN = 0;
@Type
int IMAGE = 1;
@Type
int VIDEO = 2;
@Type
int ANIMATED_GIF = 3;
@Type
int CARD_ANIMATED_GIF = 4;
@Type
int EXTERNAL_PLAYER = 5;
@Type
int VARIABLE_TYPE = 6;
}

View File

@ -81,8 +81,6 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import static org.mariotaku.twidere.util.CompareUtils.classEquals;
public class SettingsWizardActivity extends BaseThemedActivity implements Constants {
public static final String WIZARD_PREFERENCE_KEY_NEXT_PAGE = "next_page";
@ -667,9 +665,9 @@ public class SettingsWizardActivity extends BaseThemedActivity implements Consta
private boolean wasConfigured(final List<SupportTabSpec> tabs) {
for (final SupportTabSpec spec : tabs) {
if (classEquals(spec.cls, HomeTimelineFragment.class)
|| classEquals(spec.cls, InteractionsTimelineFragment.class)
|| classEquals(spec.cls, DirectMessagesFragment.class)) return true;
if (spec.cls == HomeTimelineFragment.class
|| spec.cls == InteractionsTimelineFragment.class
|| spec.cls == DirectMessagesFragment.class) return true;
}
return false;
}

View File

@ -107,13 +107,6 @@ import org.mariotaku.twidere.view.iface.IHomeActionButton;
import java.util.Collections;
import java.util.List;
import static org.mariotaku.twidere.util.CompareUtils.classEquals;
import static org.mariotaku.twidere.util.DataStoreUtils.cleanDatabasesByItemLimit;
import static org.mariotaku.twidere.util.Utils.getDefaultAccountId;
import static org.mariotaku.twidere.util.Utils.getTabDisplayOptionInt;
import static org.mariotaku.twidere.util.Utils.openMessageConversation;
import static org.mariotaku.twidere.util.Utils.openSearch;
public class HomeActivity extends BaseAppCompatActivity implements OnClickListener, OnPageChangeListener,
SupportFragmentCallback, OnLongClickListener, DrawerLayout.DrawerListener {
private final Handler mHandler = new Handler();
@ -355,7 +348,7 @@ public class HomeActivity extends BaseAppCompatActivity implements OnClickListen
setSupportActionBar(mActionBar);
sendBroadcast(new Intent(BROADCAST_HOME_ACTIVITY_ONCREATE));
final boolean refreshOnStart = mPreferences.getBoolean(KEY_REFRESH_ON_START, false);
int tabDisplayOptionInt = getTabDisplayOptionInt(this);
int tabDisplayOptionInt = Utils.getTabDisplayOptionInt(this);
mTabColumns = getResources().getInteger(R.integer.default_tab_columns);
@ -570,7 +563,7 @@ public class HomeActivity extends BaseAppCompatActivity implements OnClickListen
TaskStarter.execute(new AbstractTask() {
@Override
public Object doLongOperation(Object o) {
cleanDatabasesByItemLimit(context);
DataStoreUtils.cleanDatabasesByItemLimit(context);
return null;
}
});
@ -682,9 +675,9 @@ public class HomeActivity extends BaseAppCompatActivity implements OnClickListen
if (appSearchData != null && appSearchData.containsKey(EXTRA_ACCOUNT_ID)) {
accountId = appSearchData.getLong(EXTRA_ACCOUNT_ID, -1);
} else {
accountId = getDefaultAccountId(this);
accountId = Utils.getDefaultAccountId(this);
}
openSearch(this, accountId, query);
Utils.openSearch(this, accountId, query);
return -1;
}
final boolean refreshOnStart = mPreferences.getBoolean(KEY_REFRESH_ON_START, false);
@ -715,7 +708,8 @@ public class HomeActivity extends BaseAppCompatActivity implements OnClickListen
final long readPosition = NumberUtils.toLong(uri.getQueryParameter(QUERY_PARAM_READ_POSITION), -1);
switch (tabType) {
case CustomTabType.HOME_TIMELINE: {
final String tag = Utils.getReadPositionTagWithAccounts(ReadPositionTag.HOME_TIMELINE, accountId);
final String tag = Utils.getReadPositionTagWithAccounts(ReadPositionTag.HOME_TIMELINE,
accountId);
mReadStateManager.setPosition(tag, readPosition, false);
break;
}
@ -723,8 +717,9 @@ public class HomeActivity extends BaseAppCompatActivity implements OnClickListen
if (initialTab == -1 && !restoreInstanceState) {
Utils.openInteractions(this, accountId);
}
final String tag = Utils.getReadPositionTagWithAccounts(ReadPositionTag.ACTIVITIES_ABOUT_ME, accountId);
mReadStateManager.setPosition(tag, accountId, readPosition, false);
final String tag = Utils.getReadPositionTagWithAccounts(ReadPositionTag.ACTIVITIES_ABOUT_ME,
accountId);
mReadStateManager.setPosition(tag, readPosition, false);
break;
}
case CustomTabType.DIRECT_MESSAGES: {
@ -847,9 +842,9 @@ public class HomeActivity extends BaseAppCompatActivity implements OnClickListen
final int position = mViewPager.getCurrentItem();
if (mPagerAdapter.getCount() == 0) return;
final SupportTabSpec tab = mPagerAdapter.getTab(position);
if (classEquals(DirectMessagesFragment.class, tab.cls)) {
openMessageConversation(this, -1, -1);
} else if (classEquals(TrendsSuggestionsFragment.class, tab.cls)) {
if (DirectMessagesFragment.class == tab.cls) {
Utils.openMessageConversation(this, -1, -1);
} else if (TrendsSuggestionsFragment.class == tab.cls) {
openSearchView(null);
} else {
startActivity(new Intent(INTENT_ACTION_COMPOSE));
@ -862,10 +857,10 @@ public class HomeActivity extends BaseAppCompatActivity implements OnClickListen
final int position = mViewPager.getCurrentItem();
if (mPagerAdapter.getCount() == 0) return;
final SupportTabSpec tab = mPagerAdapter.getTab(position);
if (classEquals(DirectMessagesFragment.class, tab.cls)) {
if (DirectMessagesFragment.class == tab.cls) {
icon = R.drawable.ic_action_add;
title = R.string.new_direct_message;
} else if (classEquals(TrendsSuggestionsFragment.class, tab.cls)) {
} else if (TrendsSuggestionsFragment.class == tab.cls) {
icon = R.drawable.ic_action_search;
title = android.R.string.search_go;
} else {
@ -957,7 +952,7 @@ public class HomeActivity extends BaseAppCompatActivity implements OnClickListen
case CustomTabType.HOME_TIMELINE: {
final long[] accountIds = Utils.getAccountIds(spec.args);
final String tagWithAccounts = Utils.getReadPositionTagWithAccounts(mContext,
true, spec.tag, accountIds);
true, ReadPositionTag.HOME_TIMELINE, accountIds);
final long position = mReadStateManager.getPosition(tagWithAccounts);
final int count = DataStoreUtils.getStatusesCount(mContext, Statuses.CONTENT_URI,
position, accountIds);
@ -967,8 +962,11 @@ public class HomeActivity extends BaseAppCompatActivity implements OnClickListen
}
case CustomTabType.NOTIFICATIONS_TIMELINE: {
final long[] accountIds = Utils.getAccountIds(spec.args);
final int count = DataStoreUtils.getInteractionsCount(mContext, mReadStateManager,
spec.tag, spec.args, accountIds);
final String tagWithAccounts = Utils.getReadPositionTagWithAccounts(mContext,
true, ReadPositionTag.ACTIVITIES_ABOUT_ME, accountIds);
final long position = mReadStateManager.getPosition(tagWithAccounts);
final int count = DataStoreUtils.getInteractionsCount(mContext, spec.args,
accountIds, position);
publishProgress(new TabBadge(i, count));
result.put(i, count);
break;

View File

@ -112,13 +112,17 @@ import org.mariotaku.twidere.model.ParcelableCredentials;
import org.mariotaku.twidere.model.ParcelableLocation;
import org.mariotaku.twidere.model.ParcelableMedia;
import org.mariotaku.twidere.model.ParcelableStatus;
import org.mariotaku.twidere.model.ParcelableStatusValuesCreator;
import org.mariotaku.twidere.model.ParcelableUser;
import org.mariotaku.twidere.model.SingleResponse;
import org.mariotaku.twidere.model.message.FavoriteTaskEvent;
import org.mariotaku.twidere.model.message.StatusListChangedEvent;
import org.mariotaku.twidere.model.util.ParcelableMediaUtils;
import org.mariotaku.twidere.model.util.ParcelableStatusUtils;
import org.mariotaku.twidere.model.util.ParcelableUserUtils;
import org.mariotaku.twidere.provider.TwidereDataStore;
import org.mariotaku.twidere.provider.TwidereDataStore.Activities;
import org.mariotaku.twidere.provider.TwidereDataStore.CachedStatuses;
import org.mariotaku.twidere.provider.TwidereDataStore.Statuses;
import org.mariotaku.twidere.util.AsyncTaskUtils;
import org.mariotaku.twidere.util.AsyncTwitterWrapper;
@ -1584,11 +1588,13 @@ public class StatusFragment extends BaseSupportFragment implements LoaderCallbac
public void onLinkClick(String link, String orig, long accountId, long extraId, int type, boolean sensitive, int start, int end) {
final ParcelableStatus status = adapter.getStatus();
ParcelableMedia current;
if ((current = ParcelableMediaUtils.findByUrl(status.media, link)) != null) {
if ((current = ParcelableMediaUtils.findByUrl(status.media, link)) != null &&
!current.open_browser) {
expandOrOpenMedia(current);
return;
}
if ((current = ParcelableMediaUtils.findByUrl(status.quoted_media, link)) != null) {
if ((current = ParcelableMediaUtils.findByUrl(status.quoted_media, link)) != null &&
!current.open_browser) {
expandOrOpenMedia(current);
return;
}
@ -2432,27 +2438,30 @@ public class StatusFragment extends BaseSupportFragment implements LoaderCallbac
}
}
activitySummary.setRetweeters(retweeters);
final ContentValues statusValues = new ContentValues();
final ContentValues countValues = new ContentValues();
final Status status = twitter.showStatus(mStatusId);
activitySummary.setFavoriteCount(status.getFavoriteCount());
activitySummary.setRetweetCount(status.getRetweetCount());
activitySummary.setReplyCount(status.getReplyCount());
statusValues.put(Statuses.REPLY_COUNT, activitySummary.replyCount);
statusValues.put(Statuses.FAVORITE_COUNT, activitySummary.favoriteCount);
statusValues.put(Statuses.RETWEET_COUNT, activitySummary.retweetCount);
countValues.put(Statuses.REPLY_COUNT, activitySummary.replyCount);
countValues.put(Statuses.FAVORITE_COUNT, activitySummary.favoriteCount);
countValues.put(Statuses.RETWEET_COUNT, activitySummary.retweetCount);
final ContentResolver cr = context.getContentResolver();
final Expression statusWhere = Expression.or(
Expression.equals(Statuses.STATUS_ID, mStatusId),
Expression.equals(Statuses.RETWEET_ID, mStatusId)
);
cr.update(Statuses.CONTENT_URI, statusValues, statusWhere.getSQL(), null);
cr.update(Statuses.CONTENT_URI, countValues, statusWhere.getSQL(), null);
final Expression activityWhere = Expression.or(
Expression.equals(Activities.STATUS_ID, mStatusId),
Expression.equals(Activities.STATUS_RETWEET_ID, mStatusId)
);
final ParcelableStatus pStatus = ParcelableStatusUtils.fromStatus(status, mAccountId, false);
cr.insert(CachedStatuses.CONTENT_URI, ParcelableStatusValuesCreator.create(pStatus));
final Cursor activityCursor = cr.query(Activities.AboutMe.CONTENT_URI,
Activities.COLUMNS, activityWhere.getSQL(), null, null);
assert activityCursor != null;

View File

@ -29,7 +29,6 @@ import org.mariotaku.twidere.TwidereConstants;
import org.mariotaku.twidere.annotation.CustomTabType;
import static org.mariotaku.twidere.util.CompareUtils.bundleEquals;
import static org.mariotaku.twidere.util.CompareUtils.classEquals;
import static org.mariotaku.twidere.util.CompareUtils.objectEquals;
public class SupportTabSpec implements Comparable<SupportTabSpec>, TwidereConstants {
@ -74,7 +73,7 @@ public class SupportTabSpec implements Comparable<SupportTabSpec>, TwidereConsta
public boolean equals(final Object o) {
if (!(o instanceof SupportTabSpec)) return false;
final SupportTabSpec spec = (SupportTabSpec) o;
return objectEquals(name, spec.name) && objectEquals(icon, spec.icon) && classEquals(cls, spec.cls)
return objectEquals(name, spec.name) && objectEquals(icon, spec.icon) && cls == spec.cls
&& bundleEquals(args, spec.args) && position == spec.position;
}

View File

@ -23,7 +23,6 @@ import android.app.Fragment;
import android.os.Bundle;
import static org.mariotaku.twidere.util.CompareUtils.bundleEquals;
import static org.mariotaku.twidere.util.CompareUtils.classEquals;
import static org.mariotaku.twidere.util.CompareUtils.objectEquals;
public class TabSpec {
@ -51,7 +50,7 @@ public class TabSpec {
public boolean equals(final Object o) {
if (!(o instanceof TabSpec)) return false;
final TabSpec spec = (TabSpec) o;
return objectEquals(name, spec.name) && objectEquals(icon, spec.icon) && classEquals(cls, spec.cls)
return objectEquals(name, spec.name) && objectEquals(icon, spec.icon) && cls == spec.cls
&& bundleEquals(args, spec.args) && position == spec.position;
}

View File

@ -184,6 +184,7 @@ public class ParcelableMediaUtils {
media.media_url = ((CardEntity.ImageValue) photoImageFullSize).getUrl();
media.width = ((CardEntity.ImageValue) photoImageFullSize).getWidth();
media.height = ((CardEntity.ImageValue) photoImageFullSize).getHeight();
media.open_browser = true;
final CardEntity.BindingValue summaryPhotoImage = card.getBindingValue("summary_photo_image");
if (summaryPhotoImage instanceof CardEntity.ImageValue) {
media.preview_url = ((CardEntity.ImageValue) summaryPhotoImage).getUrl();

View File

@ -34,17 +34,12 @@ public class CompareUtils {
return true;
}
public static boolean classEquals(final Class<?> cls1, final Class<?> cls2) {
if (cls1 == null || cls2 == null) return cls1 == cls2;
return cls1.getName().equals(cls2.getName());
}
public static boolean objectEquals(final Object object1, final Object object2) {
if (object1 == null || object2 == null) return object1 == object2;
if (object1 instanceof Bundle && object2 instanceof Bundle)
return bundleEquals((Bundle) object1, (Bundle) object2);
else if (object1 instanceof Class && object2 instanceof Class)
return classEquals((Class<?>) object1, (Class<?>) object2);
return object1 == object2;
return object1.equals(object2);
}

View File

@ -61,8 +61,6 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map.Entry;
import static org.mariotaku.twidere.util.CompareUtils.classEquals;
public class CustomTabUtils implements Constants {
private static final HashMap<String, CustomTabConfiguration> CUSTOM_TABS_CONFIGURATION_MAP = new HashMap<>();
private static final HashMap<String, Integer> CUSTOM_TABS_ICON_NAME_MAP = new HashMap<>();
@ -132,7 +130,7 @@ public class CustomTabUtils implements Constants {
public static String findTabType(final Class<? extends Fragment> cls) {
for (final Entry<String, CustomTabConfiguration> entry : getConfigurationMap().entrySet()) {
if (classEquals(cls, entry.getValue().getFragmentClass())) return entry.getKey();
if (cls == entry.getValue().getFragmentClass()) return entry.getKey();
}
return null;
}

View File

@ -122,7 +122,7 @@ public class DataImportExportUtils implements Constants {
final HashMap<String, Preference> supportedPrefsMap = new HashMap<>();
for (final Field field : fields) {
final Preference annotation = field.getAnnotation(Preference.class);
if (Modifier.isStatic(field.getModifiers()) && CompareUtils.classEquals(field.getType(), String.class)
if (Modifier.isStatic(field.getModifiers()) && field.getType() == String.class
&& annotation != null && annotation.exportable() && annotation.type() != PreferenceType.INVALID) {
try {
supportedPrefsMap.put((String) field.get(null), annotation);

View File

@ -48,7 +48,6 @@ import org.mariotaku.sqliteqb.library.Tables;
import org.mariotaku.sqliteqb.library.query.SQLSelectQuery;
import org.mariotaku.twidere.Constants;
import org.mariotaku.twidere.TwidereConstants;
import org.mariotaku.twidere.annotation.CustomTabType;
import org.mariotaku.twidere.api.twitter.model.Activity;
import org.mariotaku.twidere.model.ParcelableAccount;
import org.mariotaku.twidere.model.ParcelableAccountCursorIndices;
@ -960,13 +959,8 @@ public class DataStoreUtils implements Constants {
return accounts;
}
public static int getInteractionsCount(final Context context, final ReadStateManager readStateManager,
@CustomTabType final String tag, @Nullable final Bundle extraArgs,
final long[] accountIds) {
final String tagWithAccounts = Utils.getReadPositionTagWithAccounts(context,
true, tag, accountIds);
final long position = readStateManager.getPosition(tagWithAccounts);
public static int getInteractionsCount(final Context context, @Nullable final Bundle extraArgs,
final long[] accountIds, final long position) {
Expression extraWhere = null;
String[] extraWhereArgs = null;
boolean followingOnly = false;

View File

@ -27,6 +27,7 @@ import android.support.annotation.Nullable;
import android.text.TextUtils;
import org.mariotaku.twidere.Constants;
import org.mariotaku.twidere.annotation.CustomTabType;
import org.mariotaku.twidere.annotation.NotificationType;
import org.mariotaku.twidere.annotation.ReadPositionTag;
import org.mariotaku.twidere.model.StringLongPair;
@ -167,6 +168,12 @@ public class ReadStateManager implements Constants {
public static String getReadPositionTagForNotificationType(@NotificationType String notificationType) {
if (notificationType == null) return null;
switch (notificationType) {
case NotificationType.HOME_TIMELINE: {
return ReadPositionTag.HOME_TIMELINE;
}
case NotificationType.DIRECT_MESSAGES: {
return ReadPositionTag.DIRECT_MESSAGES;
}
case NotificationType.INTERACTIONS: {
return ReadPositionTag.ACTIVITIES_ABOUT_ME;
}
@ -174,4 +181,22 @@ public class ReadStateManager implements Constants {
return null;
}
@Nullable
@ReadPositionTag
public static String getReadPositionTagForTabType(@CustomTabType String tabType) {
if (tabType == null) return null;
switch (tabType) {
case CustomTabType.HOME_TIMELINE: {
return ReadPositionTag.HOME_TIMELINE;
}
case CustomTabType.NOTIFICATIONS_TIMELINE: {
return ReadPositionTag.ACTIVITIES_ABOUT_ME;
}
case CustomTabType.DIRECT_MESSAGES: {
return ReadPositionTag.DIRECT_MESSAGES;
}
}
return null;
}
}

View File

@ -813,7 +813,7 @@ public final class Utils implements Constants {
@Nullable
public static String getReadPositionTagWithAccounts(Context context, boolean activatedIfMissing,
@Nullable String tag,
@Nullable @ReadPositionTag String tag,
long... accountIds) {
if (tag == null) return null;
if (accountIds == null || accountIds.length == 0 || (accountIds.length == 1 && accountIds[0] < 0)) {