diff --git a/twidere.component.common/src/main/java/org/mariotaku/twidere/util/TwitterContentUtils.java b/twidere.component.common/src/main/java/org/mariotaku/twidere/util/TwitterContentUtils.java index 3af5cc9ba..830906524 100644 --- a/twidere.component.common/src/main/java/org/mariotaku/twidere/util/TwitterContentUtils.java +++ b/twidere.component.common/src/main/java/org/mariotaku/twidere/util/TwitterContentUtils.java @@ -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; } } diff --git a/twidere/src/main/java/org/mariotaku/twidere/activity/support/SignInActivity.java b/twidere/src/main/java/org/mariotaku/twidere/activity/support/SignInActivity.java index b44698820..891d52881 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/activity/support/SignInActivity.java +++ b/twidere/src/main/java/org/mariotaku/twidere/activity/support/SignInActivity.java @@ -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)); } diff --git a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/AbsStatusesFragment.java b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/AbsStatusesFragment.java index d6ab663df..ce6d4b3bc 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/AbsStatusesFragment.java +++ b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/AbsStatusesFragment.java @@ -154,12 +154,13 @@ public abstract class AbsStatusesFragment 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; } diff --git a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/AccountsDashboardFragment.java b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/AccountsDashboardFragment.java index 66feb0c92..0e4a0dfb7 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/AccountsDashboardFragment.java +++ b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/AccountsDashboardFragment.java @@ -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(); diff --git a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/MessagesConversationFragment.java b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/MessagesConversationFragment.java index d0729c415..1aee42a0e 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/MessagesConversationFragment.java +++ b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/MessagesConversationFragment.java @@ -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)); diff --git a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/SearchFragment.java b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/SearchFragment.java index 4068ee074..bd00d513c 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/SearchFragment.java +++ b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/SearchFragment.java @@ -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())); } diff --git a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/StatusFragment.java b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/StatusFragment.java index 57be2c448..767ccf354 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/StatusFragment.java +++ b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/StatusFragment.java @@ -516,9 +516,7 @@ public class StatusFragment extends BaseSupportFragment implements LoaderCallbac public void onLoadFinished(final Loader> loader, final SingleResponse 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); } diff --git a/twidere/src/main/java/org/mariotaku/twidere/util/ReadStateManager.java b/twidere/src/main/java/org/mariotaku/twidere/util/ReadStateManager.java index 4abc3ad0e..7f272c989 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/util/ReadStateManager.java +++ b/twidere/src/main/java/org/mariotaku/twidere/util/ReadStateManager.java @@ -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) {