From c34ab39eab257df0c78c6c9e8a40ef7cf07c6d1c Mon Sep 17 00:00:00 2001 From: Moez Bhatti Date: Mon, 22 Aug 2016 14:06:17 -0400 Subject: [PATCH] Fixed crashlytics #975 --- .../java/com/moez/QKSMS/QKSMSAppBase.java | 3 ++ .../ConversationListFragment.java | 44 ++++++++++++------- .../ui/messagelist/MessageListFragment.java | 21 ++++++--- 3 files changed, 45 insertions(+), 23 deletions(-) diff --git a/QKSMS/src/main/java/com/moez/QKSMS/QKSMSAppBase.java b/QKSMS/src/main/java/com/moez/QKSMS/QKSMSAppBase.java index 19a1a49b..06a0efb6 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/QKSMSAppBase.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/QKSMSAppBase.java @@ -53,6 +53,9 @@ import java.util.Locale; public class QKSMSAppBase extends MultiDexApplication { public static final String LOG_TAG = "Mms"; + public static final int LOADER_CONVERSATIONS = 0; + public static final int LOADER_MESSAGES = 1; + private SearchRecentSuggestions mRecentSuggestions; private TelephonyManager mTelephonyManager; private String mCountryIso; diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/conversationlist/ConversationListFragment.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/conversationlist/ConversationListFragment.java index 1731123e..99ebd8ee 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/conversationlist/ConversationListFragment.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/conversationlist/ConversationListFragment.java @@ -21,6 +21,7 @@ import android.widget.ImageView; import butterknife.Bind; import butterknife.ButterKnife; import com.melnykov.fab.FloatingActionButton; +import com.moez.QKSMS.QKSMSApp; import com.moez.QKSMS.R; import com.moez.QKSMS.common.BlockedConversationHelper; import com.moez.QKSMS.common.DialogHelper; @@ -265,7 +266,7 @@ public class ConversationListFragment extends QKFragment implements LoaderManage } private void initLoaderManager() { - getLoaderManager().restartLoader(0, null, this); + getLoaderManager().restartLoader(QKSMSApp.LOADER_CONVERSATIONS, null, this); } @Override @@ -289,27 +290,36 @@ public class ConversationListFragment extends QKFragment implements LoaderManage } } + @Override public Loader onCreateLoader(int id, Bundle args) { - return new CursorLoader(mContext, SmsHelper.CONVERSATIONS_CONTENT_PROVIDER, Conversation.ALL_THREADS_PROJECTION, - BlockedConversationHelper.getCursorSelection(mPrefs, mShowBlocked), - BlockedConversationHelper.getBlockedConversationArray(mPrefs), "date DESC"); - } - - public void onLoadFinished(Loader loader, Cursor data) { - if (mAdapter != null) { - // Swap the new cursor in. (The framework will take care of closing the, old cursor once we return.) - mAdapter.changeCursor(data); - if (mPosition != 0) { - mRecyclerView.scrollToPosition(Math.min(mPosition, data.getCount() - 1)); - mPosition = 0; - } + if (id == QKSMSApp.LOADER_CONVERSATIONS) { + return new CursorLoader(mContext, SmsHelper.CONVERSATIONS_CONTENT_PROVIDER, Conversation.ALL_THREADS_PROJECTION, + BlockedConversationHelper.getCursorSelection(mPrefs, mShowBlocked), + BlockedConversationHelper.getBlockedConversationArray(mPrefs), "date DESC"); + } else { + return null; } - - mEmptyState.setVisibility(data != null && data.getCount() > 0 ? View.GONE : View.VISIBLE); } + @Override + public void onLoadFinished(Loader loader, Cursor data) { + if (loader.getId() == QKSMSApp.LOADER_CONVERSATIONS) { + if (mAdapter != null) { + // Swap the new cursor in. (The framework will take care of closing the, old cursor once we return.) + mAdapter.changeCursor(data); + if (mPosition != 0) { + mRecyclerView.scrollToPosition(Math.min(mPosition, data.getCount() - 1)); + mPosition = 0; + } + } + + mEmptyState.setVisibility(data != null && data.getCount() > 0 ? View.GONE : View.VISIBLE); + } + } + + @Override public void onLoaderReset(Loader loader) { - if (mAdapter != null) { + if (mAdapter != null && loader.getId() == QKSMSApp.LOADER_CONVERSATIONS) { mAdapter.changeCursor(null); } } diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/messagelist/MessageListFragment.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/messagelist/MessageListFragment.java index 8f106cc9..9f19186b 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/messagelist/MessageListFragment.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/messagelist/MessageListFragment.java @@ -82,6 +82,8 @@ import java.util.ArrayList; import java.util.HashSet; import java.util.List; +import static android.R.attr.data; + public class MessageListFragment extends QKFragment implements ActivityLauncher, SensorEventListener, LoaderManager.LoaderCallbacks, RecyclerCursorAdapter.MultiSelectListener, SwipeBackLayout.ScrollChangedListener, RecyclerCursorAdapter.ItemClickListener { @@ -572,7 +574,7 @@ public class MessageListFragment extends QKFragment implements ActivityLauncher, } private void initLoaderManager() { - getLoaderManager().initLoader(0, null, this); + getLoaderManager().initLoader(QKSMSApp.LOADER_MESSAGES, null, this); } @Override @@ -619,21 +621,28 @@ public class MessageListFragment extends QKFragment implements ActivityLauncher, // Ignored } + @Override public Loader onCreateLoader(int id, Bundle args) { - return new CursorLoader(mContext, - Uri.withAppendedPath(Message.MMS_SMS_CONTENT_PROVIDER, String.valueOf(mThreadId)), - MessageColumns.PROJECTION, null, null, "normalized_date ASC"); + if (id == QKSMSApp.LOADER_MESSAGES) { + return new CursorLoader(mContext, + Uri.withAppendedPath(Message.MMS_SMS_CONTENT_PROVIDER, String.valueOf(mThreadId)), + MessageColumns.PROJECTION, null, null, "normalized_date ASC"); + } else { + return null; + } } + @Override public void onLoadFinished(Loader loader, Cursor data) { - if (mAdapter != null) { + if (mAdapter != null && loader.getId() == QKSMSApp.LOADER_MESSAGES) { // Swap the new cursor in. (The framework will take care of closing the, old cursor once we return.) mAdapter.changeCursor(data); } } + @Override public void onLoaderReset(Loader loader) { - if (mAdapter != null) { + if (mAdapter != null && loader.getId() == QKSMSApp.LOADER_MESSAGES) { mAdapter.changeCursor(null); } }