This commit is contained in:
Mariotaku Lee 2016-02-28 13:49:27 +08:00
parent 8a55903ca6
commit 2026846829
7 changed files with 91 additions and 90 deletions

View File

@ -61,16 +61,13 @@ import android.widget.FrameLayout.LayoutParams;
import com.squareup.otto.Subscribe;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.math.NumberUtils;
import org.mariotaku.sqliteqb.library.Expression;
import org.mariotaku.twidere.R;
import org.mariotaku.twidere.activity.SettingsActivity;
import org.mariotaku.twidere.activity.SettingsWizardActivity;
import org.mariotaku.twidere.activity.UsageStatisticsActivity;
import org.mariotaku.twidere.adapter.support.SupportTabsAdapter;
import org.mariotaku.twidere.annotation.CustomTabType;
import org.mariotaku.twidere.api.twitter.model.Activity;
import org.mariotaku.twidere.fragment.CustomTabsFragment;
import org.mariotaku.twidere.fragment.iface.RefreshScrollTopInterface;
import org.mariotaku.twidere.fragment.iface.SupportFragmentCallback;
@ -83,7 +80,6 @@ import org.mariotaku.twidere.model.SupportTabSpec;
import org.mariotaku.twidere.model.message.TaskStateChangedEvent;
import org.mariotaku.twidere.model.message.UnreadCountUpdatedEvent;
import org.mariotaku.twidere.provider.TwidereDataStore.Accounts;
import org.mariotaku.twidere.provider.TwidereDataStore.Activities;
import org.mariotaku.twidere.provider.TwidereDataStore.Statuses;
import org.mariotaku.twidere.service.StreamingService;
import org.mariotaku.twidere.task.AbstractTask;
@ -308,7 +304,7 @@ public class HomeActivity extends BaseAppCompatActivity implements OnClickListen
if (isDrawerOpen()) {
drawer.closeDrawers();
} else {
drawer.openDrawer(Gravity.LEFT);
drawer.openDrawer(GravityCompat.START);
}
return true;
}
@ -392,8 +388,8 @@ public class HomeActivity extends BaseAppCompatActivity implements OnClickListen
setupBars();
showDataProfilingRequest();
initUnreadCount();
setupHomeTabs();
updateActionsButton();
updateSlidingMenuTouchMode();
if (savedInstanceState == null) {
if (refreshOnStart) {
@ -403,9 +399,9 @@ public class HomeActivity extends BaseAppCompatActivity implements OnClickListen
openAccountsDrawer();
}
}
setupHomeTabs();
final int initialTabPosition = handleIntent(intent, savedInstanceState == null);
final int initialTabPosition = handleIntent(intent, savedInstanceState == null,
savedInstanceState != null);
setTabPosition(initialTabPosition);
if (Utils.isStreamingEnabled()) {
@ -437,7 +433,6 @@ public class HomeActivity extends BaseAppCompatActivity implements OnClickListen
invalidateOptionsMenu();
updateActionsButtonStyle();
updateActionsButton();
updateSlidingMenuTouchMode();
}
@Override
@ -458,10 +453,6 @@ public class HomeActivity extends BaseAppCompatActivity implements OnClickListen
super.onStop();
}
public ViewPager getViewPager() {
return mViewPager;
}
public void notifyAccountsChanged() {
}
@ -518,7 +509,6 @@ public class HomeActivity extends BaseAppCompatActivity implements OnClickListen
if (mDrawerLayout.isDrawerOpen(GravityCompat.START)) {
mDrawerLayout.closeDrawers();
}
updateSlidingMenuTouchMode();
updateActionsButton();
}
@ -563,7 +553,7 @@ public class HomeActivity extends BaseAppCompatActivity implements OnClickListen
@Override
protected void onNewIntent(final Intent intent) {
final int tabPosition = handleIntent(intent, false);
final int tabPosition = handleIntent(intent, false, false);
if (tabPosition >= 0) {
mViewPager.setCurrentItem(TwidereMathUtils.clamp(tabPosition, mPagerAdapter.getCount(), 0));
}
@ -678,7 +668,8 @@ public class HomeActivity extends BaseAppCompatActivity implements OnClickListen
return false;
}
private int handleIntent(final Intent intent, final boolean firstCreate) {
private int handleIntent(final Intent intent, final boolean handleExtraIntent,
final boolean restoreInstanceState) {
// use packge's class loader to prevent BadParcelException
intent.setExtrasClassLoader(getClassLoader());
// reset intent
@ -700,43 +691,47 @@ public class HomeActivity extends BaseAppCompatActivity implements OnClickListen
final long[] refreshedIds = intent.getLongArrayExtra(EXTRA_REFRESH_IDS);
if (refreshedIds != null) {
mTwitterWrapper.refreshAll(refreshedIds);
} else if (firstCreate && refreshOnStart) {
} else if (handleExtraIntent && refreshOnStart) {
mTwitterWrapper.refreshAll();
}
final Uri uri = intent.getData();
@CustomTabType
final String tabType = uri != null ? Utils.matchTabType(uri) : null;
int initialTab = -1;
if (tabType != null) {
final long accountId = NumberUtils.toLong(uri.getQueryParameter(QUERY_PARAM_ACCOUNT_ID), -1);
for (int i = mPagerAdapter.getCount() - 1; i > -1; i--) {
for (int i = 0, j = mPagerAdapter.getCount(); i < j; i++) {
final SupportTabSpec tab = mPagerAdapter.getTab(i);
if (tabType.equals(CustomTabUtils.getTabTypeAlias(tab.type))) {
initialTab = i;
if (hasAccountId(tab.args, accountId)) {
if (tab.args != null && CustomTabUtils.hasAccountId(tab.args,
getActivatedAccountIds(), accountId)) {
initialTab = i;
break;
}
}
}
if (initialTab == -1 && !restoreInstanceState) {
switch (tabType) {
case CustomTabType.NOTIFICATIONS_TIMELINE: {
Utils.openInteractions(this, NumberUtils.toLong(uri.getQueryParameter(EXTRA_ACCOUNT_ID), -1));
break;
}
case CustomTabType.DIRECT_MESSAGES: {
Utils.openDirectMessages(this, NumberUtils.toLong(uri.getQueryParameter(EXTRA_ACCOUNT_ID), -1));
break;
}
}
}
}
final Intent extraIntent = intent.getParcelableExtra(EXTRA_EXTRA_INTENT);
if (extraIntent != null && firstCreate) {
if (extraIntent != null && handleExtraIntent) {
extraIntent.setExtrasClassLoader(getClassLoader());
startActivity(extraIntent);
}
return initialTab;
}
private boolean hasAccountId(Bundle args, long accountId) {
if (args == null) return false;
if (args.containsKey(EXTRA_ACCOUNT_ID)) {
return args.getLong(EXTRA_ACCOUNT_ID) == accountId;
} else if (args.containsKey(EXTRA_ACCOUNT_IDS)) {
return ArrayUtils.contains(args.getLongArray(EXTRA_ACCOUNT_IDS), accountId);
}
return false;
}
private void initUnreadCount() {
for (int i = 0, j = mTabIndicator.getCount(); i < j; i++) {
mTabIndicator.setBadge(i, 0);
@ -839,17 +834,14 @@ public class HomeActivity extends BaseAppCompatActivity implements OnClickListen
private void triggerActionsClick() {
if (mViewPager == null || mPagerAdapter == null) return;
final int position = mViewPager.getCurrentItem();
if (mPagerAdapter.getCount() == 0) return;
final SupportTabSpec tab = mPagerAdapter.getTab(position);
if (tab == null) {
startActivity(new Intent(INTENT_ACTION_COMPOSE));
if (classEquals(DirectMessagesFragment.class, tab.cls)) {
openMessageConversation(this, -1, -1);
} else if (classEquals(TrendsSuggestionsFragment.class, tab.cls)) {
openSearchView(null);
} else {
if (classEquals(DirectMessagesFragment.class, tab.cls)) {
openMessageConversation(this, -1, -1);
} else if (classEquals(TrendsSuggestionsFragment.class, tab.cls)) {
openSearchView(null);
} else {
startActivity(new Intent(INTENT_ACTION_COMPOSE));
}
startActivity(new Intent(INTENT_ACTION_COMPOSE));
}
}
@ -857,21 +849,17 @@ public class HomeActivity extends BaseAppCompatActivity implements OnClickListen
if (mViewPager == null || mPagerAdapter == null) return;
final int icon, title;
final int position = mViewPager.getCurrentItem();
if (mPagerAdapter.getCount() == 0) return;
final SupportTabSpec tab = mPagerAdapter.getTab(position);
if (tab == null) {
title = R.string.compose;
icon = R.drawable.ic_action_status_compose;
if (classEquals(DirectMessagesFragment.class, tab.cls)) {
icon = R.drawable.ic_action_add;
title = R.string.new_direct_message;
} else if (classEquals(TrendsSuggestionsFragment.class, tab.cls)) {
icon = R.drawable.ic_action_search;
title = android.R.string.search_go;
} else {
if (classEquals(DirectMessagesFragment.class, tab.cls)) {
icon = R.drawable.ic_action_add;
title = R.string.new_direct_message;
} else if (classEquals(TrendsSuggestionsFragment.class, tab.cls)) {
icon = R.drawable.ic_action_search;
title = android.R.string.search_go;
} else {
icon = R.drawable.ic_action_status_compose;
title = R.string.compose;
}
icon = R.drawable.ic_action_status_compose;
title = R.string.compose;
}
if (mActionsButton instanceof IHomeActionButton) {
final IHomeActionButton hab = (IHomeActionButton) mActionsButton;
@ -887,16 +875,6 @@ public class HomeActivity extends BaseAppCompatActivity implements OnClickListen
mActionsButton.setLayoutParams(lp);
}
private void updateSlidingMenuTouchMode() {
// if (mViewPager == null || mSlidingMenu == null) return;
// final int position = mViewPager.getCurrentItem();
// final boolean pagingEnabled = mViewPager.isEnabled();
// final boolean atFirstOrLast = position == 0 || position == mPagerAdapter.getCount() - 1;
// final int mode = !pagingEnabled || atFirstOrLast ? SlidingMenu.TOUCHMODE_FULLSCREEN
// : SlidingMenu.TOUCHMODE_MARGIN;
// mSlidingMenu.setTouchModeAbove(mode);
}
private static final class AccountChangeObserver extends ContentObserver {
private final HomeActivity mActivity;
@ -955,29 +933,8 @@ public class HomeActivity extends BaseAppCompatActivity implements OnClickListen
}
case CustomTabType.NOTIFICATIONS_TIMELINE: {
final long[] accountIds = Utils.getAccountIds(spec.args);
final String tagWithAccounts = Utils.getReadPositionTagWithAccounts(mContext,
true, spec.tag, accountIds);
final long position = mReadStateManager.getPosition(tagWithAccounts);
Expression extraWhere = null;
String[] extraWhereArgs = null;
boolean followingOnly = false;
if (spec.args != null) {
Bundle extras = spec.args.getBundle(EXTRA_EXTRAS);
if (extras != null) {
if (extras.getBoolean(EXTRA_MENTIONS_ONLY)) {
extraWhere = Expression.inArgs(Activities.ACTION, 3);
extraWhereArgs = new String[]{Activity.Action.MENTION,
Activity.Action.REPLY, Activity.Action.QUOTE};
}
if (extras.getBoolean(EXTRA_MY_FOLLOWING_ONLY)) {
followingOnly = true;
}
}
}
final int count = DataStoreUtils.getActivitiesCount(mContext,
Activities.AboutMe.CONTENT_URI, extraWhere, extraWhereArgs,
position, followingOnly, accountIds);
final int count = DataStoreUtils.getInteractionsCount(mContext, mReadStateManager,
spec.tag, spec.args, accountIds);
publishProgress(new TabBadge(i, count));
result.put(i, count);
break;

View File

@ -22,6 +22,7 @@ package org.mariotaku.twidere.adapter.support;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.view.View;
@ -144,8 +145,9 @@ public class SupportTabsAdapter extends SupportFixedFragmentStatePagerAdapter im
return getTabIconDrawable(mContext, mTabs.get(position).icon);
}
@NonNull
public SupportTabSpec getTab(final int position) {
return position >= 0 && position < mTabs.size() ? mTabs.get(position) : null;
return mTabs.get(position);
}
public List<SupportTabSpec> getTabs() {

View File

@ -568,7 +568,7 @@ public class AccountsDashboardFragment extends BaseSupportFragment implements Lo
// Single account tab, return true if is current account
if (tabAccountId == accountId) return true;
// Check activated account if empty
return isActivated;
return tabAccountId <= 0 && isActivated;
} else if (ArrayUtils.contains(accountIds, accountId)) {
return true;
}

View File

@ -1426,8 +1426,9 @@ public final class TwidereDataProvider extends ContentProvider implements Consta
homeLinkBuilder.appendQueryParameter(QUERY_PARAM_ACCOUNT_ID, String.valueOf(accountId));
homeLinkBuilder.appendQueryParameter(QUERY_PARAM_FROM_NOTIFICATION, String.valueOf(true));
homeLinkBuilder.appendQueryParameter(QUERY_PARAM_TIMESTAMP, String.valueOf(System.currentTimeMillis()));
homeLinkBuilder.appendQueryParameter(QUERY_PARAM_NOTIFICATION_TYPE, type);
homeLinkBuilder.appendQueryParameter(QUERY_PARAM_NOTIFICATION_TYPE, notificationType);
homeIntent.setData(homeLinkBuilder.build());
homeIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
return PendingIntent.getActivity(context, 0, homeIntent, 0);
}
@ -1448,7 +1449,7 @@ public final class TwidereDataProvider extends ContentProvider implements Consta
UriExtraUtils.addExtra(homeLinkBuilder, "item_user_following", userFollowing);
homeLinkBuilder.appendQueryParameter(QUERY_PARAM_FROM_NOTIFICATION, String.valueOf(true));
homeLinkBuilder.appendQueryParameter(QUERY_PARAM_TIMESTAMP, String.valueOf(System.currentTimeMillis()));
homeLinkBuilder.appendQueryParameter(QUERY_PARAM_NOTIFICATION_TYPE, type);
homeLinkBuilder.appendQueryParameter(QUERY_PARAM_NOTIFICATION_TYPE, notificationType);
homeIntent.setData(homeLinkBuilder.build());
return PendingIntent.getActivity(context, 0, homeIntent, 0);
}

View File

@ -34,6 +34,7 @@ import android.support.v4.app.Fragment;
import android.support.v4.content.res.ResourcesCompat;
import android.text.TextUtils;
import org.apache.commons.lang3.ArrayUtils;
import org.mariotaku.twidere.Constants;
import org.mariotaku.twidere.R;
import org.mariotaku.twidere.annotation.CustomTabType;
@ -289,4 +290,13 @@ public class CustomTabUtils implements Constants {
public static boolean isTabTypeValid(final String tabType) {
return tabType != null && CUSTOM_TABS_CONFIGURATION_MAP.containsKey(getTabTypeAlias(tabType));
}
public static boolean hasAccountId(@NonNull Bundle args, long[] activatedAccountIds, long accountId) {
if (args.containsKey(EXTRA_ACCOUNT_ID)) {
return args.getLong(EXTRA_ACCOUNT_ID) == accountId;
} else if (args.containsKey(EXTRA_ACCOUNT_IDS)) {
return ArrayUtils.contains(args.getLongArray(EXTRA_ACCOUNT_IDS), accountId);
}
return ArrayUtils.contains(activatedAccountIds, accountId);
}
}

View File

@ -25,6 +25,7 @@ import android.content.UriMatcher;
import android.database.Cursor;
import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;
import android.provider.BaseColumns;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
@ -47,6 +48,8 @@ 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;
import org.mariotaku.twidere.model.ParcelableCredentials;
@ -953,4 +956,30 @@ 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);
Expression extraWhere = null;
String[] extraWhereArgs = null;
boolean followingOnly = false;
if (extraArgs != null) {
Bundle extras = extraArgs.getBundle(EXTRA_EXTRAS);
if (extras != null) {
if (extras.getBoolean(EXTRA_MENTIONS_ONLY)) {
extraWhere = Expression.inArgs(Activities.ACTION, 3);
extraWhereArgs = new String[]{Activity.Action.MENTION,
Activity.Action.REPLY, Activity.Action.QUOTE};
}
if (extras.getBoolean(EXTRA_MY_FOLLOWING_ONLY)) {
followingOnly = true;
}
}
}
return getActivitiesCount(context, Activities.AboutMe.CONTENT_URI, extraWhere, extraWhereArgs,
position, followingOnly, accountIds);
}
}

View File

@ -1657,10 +1657,12 @@ public final class Utils implements Constants {
}
@CustomTabType
public static String matchTabType(@Nullable final Uri uri) {
return getTabType(matchTabCode(uri));
}
@CustomTabType
public static String getTabType(final int code) {
switch (code) {
case TAB_CODE_HOME_TIMELINE: {