trying to improve performance

This commit is contained in:
Mariotaku Lee 2015-04-24 01:36:36 +08:00
parent b564feddfb
commit 865f42d171
10 changed files with 96 additions and 61 deletions

View File

@ -601,32 +601,7 @@ public class ComposeActivity extends ThemedFragmentActivity implements LocationL
return;
}
mMenuBar.setOnMenuItemClickListener(this);
final boolean sendByEnter = mPreferences.getBoolean(KEY_QUICK_SEND);
EditTextEnterHandler.attach(mEditText, new EnterListener() {
@Override
public void onHitEnter() {
updateStatus();
}
}, sendByEnter);
mEditText.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(final CharSequence s, final int start, final int count, final int after) {
}
@Override
public void onTextChanged(final CharSequence s, final int start, final int before, final int count) {
mTextChanged = true;
setMenu();
updateTextCount();
}
@Override
public void afterTextChanged(final Editable s) {
}
});
mEditText.setCustomSelectionActionModeCallback(this);
setupEditText();
mAccountSelectorContainer.setOnClickListener(this);
mAccountSelectorButton.setOnClickListener(this);
mLocationContainer.setOnClickListener(this);
@ -700,6 +675,37 @@ public class ComposeActivity extends ThemedFragmentActivity implements LocationL
updateLocationState();
updateMediaPreview();
notifyAccountSelectionChanged();
mTextChanged = false;
}
private void setupEditText() {
final boolean sendByEnter = mPreferences.getBoolean(KEY_QUICK_SEND);
EditTextEnterHandler.attach(mEditText, new EnterListener() {
@Override
public void onHitEnter() {
updateStatus();
}
}, sendByEnter);
mEditText.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(final CharSequence s, final int start, final int count, final int after) {
}
@Override
public void onTextChanged(final CharSequence s, final int start, final int before, final int count) {
setMenu();
updateTextCount();
}
@Override
public void afterTextChanged(final Editable s) {
mTextChanged = s.length() == 0;
}
});
mEditText.setCustomSelectionActionModeCallback(this);
}
@Override
@ -721,10 +727,10 @@ public class ComposeActivity extends ThemedFragmentActivity implements LocationL
}
});
toast.show();
mNavigateBackPressed = true;
} else {
onBackPressed();
}
mNavigateBackPressed = true;
} else {
mTextChanged = false;
}

View File

@ -147,13 +147,16 @@ public class CustomTabEditorActivity extends BaseSupportDialogActivity implement
case R.id.save: {
if (!isEditMode()) {
if (conf == null) return;
final boolean account_id_required = conf.getAccountRequirement() == CustomTabConfiguration.ACCOUNT_REQUIRED;
final boolean accountIdRequired = conf.getAccountRequirement() == CustomTabConfiguration.ACCOUNT_REQUIRED;
final boolean no_account_id = conf.getAccountRequirement() == CustomTabConfiguration.ACCOUNT_NONE;
final boolean secondaryFieldRequired = conf.getSecondaryFieldType() != CustomTabConfiguration.FIELD_TYPE_NONE;
final boolean account_id_invalid = getAccountId() <= 0;
final boolean secondary_field_invalid = mSecondaryFieldValue == null;
if (account_id_required && account_id_invalid || secondaryFieldRequired && secondary_field_invalid) {
Toast.makeText(this, R.string.invalid_settings, Toast.LENGTH_SHORT).show();
final boolean accountIdInvalid = getAccountId() <= 0;
final boolean secondaryFieldInvalid = mSecondaryFieldValue == null;
if (accountIdRequired && accountIdInvalid) {
Toast.makeText(this, R.string.no_account_selected, Toast.LENGTH_SHORT).show();
return;
} else if (secondaryFieldRequired && secondaryFieldInvalid) {
Toast.makeText(this, getString(R.string.name_not_set, mSecondaryFieldLabel.getText()), Toast.LENGTH_SHORT).show();
return;
}
final Intent data = new Intent();

View File

@ -121,7 +121,6 @@ import edu.ucdavis.earlybird.ProfilingUtil;
import static org.mariotaku.twidere.util.CompareUtils.classEquals;
import static org.mariotaku.twidere.util.Utils.cleanDatabasesByItemLimit;
import static org.mariotaku.twidere.util.Utils.getAccountIds;
import static org.mariotaku.twidere.util.Utils.getDefaultAccountId;
import static org.mariotaku.twidere.util.Utils.getTabDisplayOptionInt;
import static org.mariotaku.twidere.util.Utils.isDatabaseReady;
@ -353,8 +352,7 @@ public class HomeActivity extends BaseAppCompatActivity implements OnClickListen
mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
mMultiSelectHandler = new MultiSelectEventHandler(this);
mMultiSelectHandler.dispatchOnCreate();
final long[] accountIds = getAccountIds(this);
if (accountIds.length == 0) {
if (!Utils.hasAccount(this)) {
final Intent signInIntent = new Intent(INTENT_ACTION_TWITTER_LOGIN);
signInIntent.setClass(this, SignInActivity.class);
startActivity(signInIntent);
@ -481,13 +479,13 @@ public class HomeActivity extends BaseAppCompatActivity implements OnClickListen
public void notifyAccountsChanged() {
if (mPreferences == null) return;
final long[] account_ids = getAccountIds(this);
final long default_id = mPreferences.getLong(KEY_DEFAULT_ACCOUNT_ID, -1);
if (account_ids == null || account_ids.length == 0) {
finish();
} else if (account_ids.length > 0 && !ArrayUtils.contains(account_ids, default_id)) {
mPreferences.edit().putLong(KEY_DEFAULT_ACCOUNT_ID, account_ids[0]).apply();
}
// final long[] accountIds = getAccountIds(this);
// final long default_id = mPreferences.getLong(KEY_DEFAULT_ACCOUNT_ID, -1);
// if (accountIds == null || accountIds.length == 0) {
// finish();
// } else if (accountIds.length > 0 && !ArrayUtils.contains(accountIds, default_id)) {
// mPreferences.edit().putLong(KEY_DEFAULT_ACCOUNT_ID, accountIds[0]).apply();
// }
}
@Subscribe

View File

@ -43,11 +43,11 @@ import org.mariotaku.twidere.activity.support.BaseAppCompatActivity;
import org.mariotaku.twidere.adapter.decorator.DividerItemDecoration;
import org.mariotaku.twidere.adapter.iface.IContentCardAdapter;
import org.mariotaku.twidere.fragment.iface.RefreshScrollTopInterface;
import org.mariotaku.twidere.util.TwidereColorUtils;
import org.mariotaku.twidere.util.ContentListScrollListener;
import org.mariotaku.twidere.util.ContentListScrollListener.ContentListSupport;
import org.mariotaku.twidere.util.SimpleDrawerCallback;
import org.mariotaku.twidere.util.ThemeUtils;
import org.mariotaku.twidere.util.TwidereColorUtils;
import org.mariotaku.twidere.util.Utils;
import org.mariotaku.twidere.view.HeaderDrawerLayout.DrawerCallback;
@ -58,7 +58,6 @@ public abstract class AbsContentListFragment<A extends IContentCardAdapter> exte
DrawerCallback, RefreshScrollTopInterface, ControlBarOffsetListener, ContentListSupport {
private Rect mSystemWindowsInsets = new Rect();
private int mControlBarOffsetPixels;
private LinearLayoutManager mLayoutManager;
private View mProgressContainer;
private SwipeRefreshLayout mSwipeRefreshLayout;
@ -90,7 +89,6 @@ public abstract class AbsContentListFragment<A extends IContentCardAdapter> exte
@Override
public void onControlBarOffsetChanged(IControlBarActivity activity, float offset) {
mControlBarOffsetPixels = Math.round(activity.getControlBarHeight() * (1 - offset));
updateRefreshProgressOffset();
}
@ -99,6 +97,12 @@ public abstract class AbsContentListFragment<A extends IContentCardAdapter> exte
triggerRefresh();
}
@Override
public void setUserVisibleHint(boolean isVisibleToUser) {
super.setUserVisibleHint(isVisibleToUser);
updateRefreshProgressOffset();
}
@Override
public void scrollBy(float dy) {
mDrawerCallback.scrollBy(dy);
@ -142,10 +146,14 @@ public abstract class AbsContentListFragment<A extends IContentCardAdapter> exte
return mLayoutManager;
}
public void setRefreshing(boolean refreshing) {
if (refreshing == mSwipeRefreshLayout.isRefreshing()) return;
// if (!refreshing) updateRefreshProgressOffset();
mSwipeRefreshLayout.setRefreshing(refreshing && !mAdapter.isLoadMoreIndicatorVisible());
public void setRefreshing(final boolean refreshing) {
final boolean currentRefreshing = mSwipeRefreshLayout.isRefreshing();
if (!currentRefreshing) {
updateRefreshProgressOffset();
}
if (refreshing == currentRefreshing) return;
final boolean layoutRefreshing = refreshing && !mAdapter.isLoadMoreIndicatorVisible();
mSwipeRefreshLayout.setRefreshing(layoutRefreshing);
}
@Override
@ -239,6 +247,11 @@ public abstract class AbsContentListFragment<A extends IContentCardAdapter> exte
mSwipeRefreshLayout.setEnabled(enabled);
}
@Override
public boolean triggerRefresh() {
return false;
}
@NonNull
protected abstract A onCreateAdapter(Context context, boolean compact);
@ -248,10 +261,16 @@ public abstract class AbsContentListFragment<A extends IContentCardAdapter> exte
}
protected void updateRefreshProgressOffset() {
if (mSystemWindowsInsets.top == 0 || mSwipeRefreshLayout == null || isRefreshing()) return;
final FragmentActivity activity = getActivity();
if (!(activity instanceof IControlBarActivity) || mSystemWindowsInsets.top == 0 || mSwipeRefreshLayout == null
|| isRefreshing()) {
return;
}
final float density = getResources().getDisplayMetrics().density;
final int progressCircleDiameter = mSwipeRefreshLayout.getProgressCircleDiameter();
final int swipeStart = (mSystemWindowsInsets.top - mControlBarOffsetPixels) - progressCircleDiameter;
final IControlBarActivity control = (IControlBarActivity) activity;
final int controlBarOffsetPixels = Math.round(control.getControlBarHeight() * (1 - control.getControlBarOffset()));
final int swipeStart = (mSystemWindowsInsets.top - controlBarOffsetPixels) - progressCircleDiameter;
// 64: SwipeRefreshLayout.DEFAULT_CIRCLE_TARGET
final int swipeDistance = Math.round(64 * density);
mSwipeRefreshLayout.setProgressViewOffset(false, swipeStart, swipeStart + swipeDistance);

View File

@ -216,6 +216,7 @@ public abstract class CursorStatusesFragment extends AbsStatusesFragment<Cursor>
@Override
public boolean triggerRefresh() {
super.triggerRefresh();
AsyncTaskUtils.executeTask(new AsyncTask<Object, Object, long[][]>() {
@Override

View File

@ -318,6 +318,8 @@ public class MessagesConversationFragment extends BaseSupportFragment implements
mUsersSearchList.setVisibility(View.GONE);
mUsersSearchProgress.setVisibility(View.GONE);
mQueryTextChanged = false;
mTextChanged = false;
}
@Override
@ -646,7 +648,6 @@ public class MessagesConversationFragment extends BaseSupportFragment implements
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
mQueryTextChanged = true;
}
@Override
@ -671,6 +672,7 @@ public class MessagesConversationFragment extends BaseSupportFragment implements
@Override
public void afterTextChanged(Editable s) {
Utils.removeLineBreaks(s);
mQueryTextChanged = s.length() == 0;
}
});
}
@ -687,6 +689,7 @@ public class MessagesConversationFragment extends BaseSupportFragment implements
@Override
public void afterTextChanged(final Editable s) {
Utils.removeLineBreaks(s);
mTextChanged = s.length() == 0;
}
@Override
@ -696,7 +699,6 @@ public class MessagesConversationFragment extends BaseSupportFragment implements
@Override
public void onTextChanged(final CharSequence s, final int start, final int before, final int count) {
mTextChanged = true;
updateTextCount();
if (mSendButton == null || s == null) return;
mSendButton.setEnabled(mValidator.isValidTweet(s.toString()));

View File

@ -143,6 +143,7 @@ public abstract class ParcelableStatusesFragment extends AbsStatusesFragment<Lis
@Override
public boolean triggerRefresh() {
super.triggerRefresh();
final IStatusesAdapter<List<ParcelableStatus>> adapter = getAdapter();
final long[] accountIds = getAccountIds();
if (adapter.getStatusesCount() > 0) {

View File

@ -44,12 +44,6 @@ public abstract class ParcelableUsersFragment extends AbsUsersFragment<List<Parc
return new ParcelableUsersAdapter(context, compact);
}
@Override
public boolean triggerRefresh() {
return false;
}
protected long getAccountId() {
final Bundle args = getArguments();
return args != null ? args.getLong(EXTRA_ACCOUNT_ID, -1) : -1;

View File

@ -1302,6 +1302,18 @@ public final class Utils implements Constants, TwitterConstants {
}
}
public static boolean hasAccount(final Context context) {
if (context == null) return false;
final Cursor cur = ContentResolverUtils.query(context.getContentResolver(), Accounts.CONTENT_URI,
new String[]{SQLFunctions.COUNT()}, null, null, null);
try {
cur.moveToFirst();
return cur.getInt(0) > 0;
} finally {
cur.close();
}
}
public static String getAccountName(final Context context, final long accountId) {
if (context == null) return null;
final String cached = sAccountNames.get(accountId);

View File

@ -34,7 +34,6 @@
<string name="error_occurred">An error occurred, please try again.</string>
<string name="error_already_logged_in">You have already logged in.</string>
<string name="no_account_selected">No account selected.</string>
<string name="empty_account_selection_disallowed">Please select at least one account.</string>
<string name="error_unknown_error">Error: Unknown error, this is probably a bug.</string>
<string name="error_message">Error: <xliff:g id="message">%s</xliff:g></string>
<string name="error_message_with_action">Error while <xliff:g id="action">%1$s</xliff:g>: <xliff:g id="message">%2$s</xliff:g></string>
@ -223,7 +222,6 @@
<string name="tabs">Tabs</string>
<string name="add_tab">Add tab</string>
<string name="edit_tab">Edit tab</string>
<string name="invalid_settings">Found invalid settings.</string>
<string name="icon">Icon</string>
<string name="pick_file">Pick file</string>
<string name="user_timeline">User timeline</string>
@ -738,4 +736,5 @@
<string name="next_tab">Next tab</string>
<string name="keyboard_shortcut_back">Back</string>
<string name="press_again_to_close">Press again to close</string>
<string name="name_not_set"><xliff:g id="name">%s</xliff:g> not set</string>
</resources>