fixed crashes

This commit is contained in:
Mariotaku Lee 2015-09-07 10:07:03 +08:00
parent 74346a0deb
commit d311951fb8
8 changed files with 22 additions and 11 deletions

View File

@ -183,7 +183,10 @@ public class TwitterContentUtils {
for (int i = entities.length - 1; i >= 0; i--) {
final Matcher m = PATTERN_TWITTER_STATUS_LINK.matcher(entities[i].getExpandedUrl());
if (!m.matches()) continue;
quotes.put(Long.parseLong(m.group(3)), status);
final long quoteId = ParseUtils.parseLong(m.group(3), -1);
if (quoteId > 0) {
quotes.put(quoteId, status);
}
break;
}
}

View File

@ -38,6 +38,7 @@ import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.view.ViewCompat;
@ -838,11 +839,13 @@ public class SignInActivity extends BaseAppCompatActivity implements OnClickList
dialog.setOnShowListener(new DialogInterface.OnShowListener() {
@Override
public void onShow(DialogInterface dialog) {
final FragmentActivity activity = getActivity();
if (activity == null) return;
final MaterialEditText editConsumerKey = (MaterialEditText) ((Dialog) dialog).findViewById(R.id.consumer_key);
final MaterialEditText editConsumerSecret = (MaterialEditText) ((Dialog) dialog).findViewById(R.id.consumer_secret);
editConsumerKey.addValidator(new ConsumerKeySecretValidator(getString(R.string.invalid_consumer_key)));
editConsumerSecret.addValidator(new ConsumerKeySecretValidator(getString(R.string.invalid_consumer_secret)));
final SharedPreferences prefs = SharedPreferencesWrapper.getInstance(getActivity(), SHARED_PREFERENCES_NAME, MODE_PRIVATE);
final SharedPreferences prefs = SharedPreferencesWrapper.getInstance(activity, SHARED_PREFERENCES_NAME, MODE_PRIVATE);
editConsumerKey.setText(prefs.getString(KEY_CONSUMER_KEY, null));
editConsumerSecret.setText(prefs.getString(KEY_CONSUMER_SECRET, null));
}

View File

@ -154,12 +154,13 @@ public abstract class AbsStatusesFragment<Data> extends AbsContentRecyclerViewFr
triggerRefresh();
return true;
}
final RecyclerView mRecyclerView = getRecyclerView();
final RecyclerView recyclerView = getRecyclerView();
final LinearLayoutManager layoutManager = getLayoutManager();
final View focusedChild = RecyclerViewUtils.findRecyclerViewChild(mRecyclerView, layoutManager.getFocusedChild());
if (recyclerView == null || layoutManager == null) return false;
final View focusedChild = RecyclerViewUtils.findRecyclerViewChild(recyclerView, layoutManager.getFocusedChild());
final int position;
if (focusedChild != null && focusedChild.getParent() == mRecyclerView) {
position = mRecyclerView.getChildLayoutPosition(focusedChild);
if (focusedChild != null && focusedChild.getParent() == recyclerView) {
position = recyclerView.getChildLayoutPosition(focusedChild);
} else {
return false;
}

View File

@ -139,6 +139,7 @@ public class AccountsDashboardFragment extends BaseSupportFragment implements Lo
@Override
public void onChange(boolean selfChange, @Nullable Uri uri) {
final ContentResolver cr = getContentResolver();
if (cr == null) return;
final Cursor c = cr.query(Accounts.CONTENT_URI, Accounts.COLUMNS, null, null, Accounts.SORT_POSITION);
updateAccountProviderData(c);
c.close();

View File

@ -784,6 +784,7 @@ public class MessagesConversationFragment extends BaseSupportFragment implements
private void updateRecipientInfo() {
final FragmentActivity activity = getActivity();
if (activity == null) return;
if (mRecipient != null) {
activity.setTitle(mUserColorNameManager.getDisplayName(mRecipient,
mPreferences.getBoolean(KEY_NAME_FIRST), true));

View File

@ -218,6 +218,7 @@ public class SearchFragment extends BaseSupportFragment implements RefreshScroll
@Override
public void onPrepareOptionsMenu(Menu menu) {
if (isDetached() || getActivity() == null) return;
final MenuItem item = menu.findItem(R.id.compose);
item.setTitle(getString(R.string.tweet_hashtag, getQuery()));
}

View File

@ -516,9 +516,7 @@ public class StatusFragment extends BaseSupportFragment implements LoaderCallbac
public void onLoadFinished(final Loader<SingleResponse<ParcelableStatus>> loader,
final SingleResponse<ParcelableStatus> data) {
if (data.hasData()) {
final long itemId = mStatusAdapter.getItemId(mLayoutManager.findFirstVisibleItemPosition());
final View firstChild = mLayoutManager.getChildAt(0);
final int top = firstChild != null ? firstChild.getTop() : 0;
final int firstVisibleItemPosition = mLayoutManager.findFirstVisibleItemPosition();
final ParcelableStatus status = data.getData();
final Bundle dataExtra = data.getExtras();
final ParcelableCredentials credentials = dataExtra.getParcelable(EXTRA_ACCOUNT);
@ -531,7 +529,10 @@ public class StatusFragment extends BaseSupportFragment implements LoaderCallbac
final TweetEvent event = TweetEvent.create(getActivity(), status, TimelineType.OTHER);
event.setAction(TweetEvent.Action.OPEN);
mStatusEvent = event;
} else {
} else if (firstVisibleItemPosition >= 0) {
final long itemId = mStatusAdapter.getItemId(firstVisibleItemPosition);
final View firstChild = mLayoutManager.getChildAt(0);
final int top = firstChild != null ? firstChild.getTop() : 0;
final int position = mStatusAdapter.findPositionById(itemId);
mLayoutManager.scrollToPositionWithOffset(position, top);
}

View File

@ -53,7 +53,7 @@ public class ReadStateManager implements Constants {
if (set == null) return new StringLongPair[0];
final StringLongPair[] pairs = new StringLongPair[set.size()];
int count = 0;
for (String entry : set) {
for (String entry : set.toArray(new String[set.size()])) {
try {
pairs[count++] = StringLongPair.valueOf(entry);
} catch (NumberFormatException e) {