From ebc5762200eb13ad16bd1dcc7714af14b4c4270a Mon Sep 17 00:00:00 2001 From: Moez Bhatti Date: Thu, 24 Dec 2015 23:22:54 -0500 Subject: [PATCH] Better constructor for MessageListFragment --- .../java/com/moez/QKSMS/ui/MainActivity.java | 12 ++---------- .../ui/messagelist/MessageListFragment.java | 19 ++++++++++++++----- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/MainActivity.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/MainActivity.java index 1359c4e1..2612051a 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/MainActivity.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/MainActivity.java @@ -158,7 +158,7 @@ public class MainActivity extends QKActivity implements LiveView, SlidingMenu.Sl case TYPE_CONVERSATION: Bundle args = new Bundle(); args.putLong(MessageListFragment.ARG_THREAD_ID, mThreadId); - mContent = MessageListFragment.getInstance(args); + mContent = MessageListFragment.getInstance(mThreadId, 0, null, false); break; case TYPE_SETTINGS: mContent = SettingsFragment.newInstance(R.xml.settings_simple); @@ -535,15 +535,7 @@ public class MainActivity extends QKActivity implements LiveView, SlidingMenu.Sl } public void setConversation(long threadId, long rowId, String pattern, boolean animate) { - - // Build the arguments for this conversation - Bundle args = new Bundle(); - args.putLong(MessageListFragment.ARG_THREAD_ID, threadId); - args.putLong(MessageListFragment.ARG_ROW_ID, rowId); - args.putString(MessageListFragment.ARG_HIGHLIGHT, pattern); - args.putBoolean(MessageListFragment.ARG_SHOW_IMMEDIATE, !animate); - - MessageListFragment fragment = MessageListFragment.getInstance(args); + MessageListFragment fragment = MessageListFragment.getInstance(threadId, rowId, pattern, !animate); // Save the thread ID here and switch the content mThreadId = threadId; 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 8fdc2a10..4e48bf0f 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 @@ -190,15 +190,24 @@ public class MessageListFragment extends QKContentFragment implements ActivityLa private String mHighlight; private boolean mShowImmediate; - public static MessageListFragment getInstance(Bundle args) { - MessageListFragment fragment = new MessageListFragment(); + public static MessageListFragment getInstance(long threadId, long rowId, String highlight, boolean showImmediate) { - // Update the fragment with the new arguments. + Bundle args = new Bundle(); + args.putLong(ARG_THREAD_ID, threadId); + args.putLong(ARG_ROW_ID, rowId); + args.putString(ARG_HIGHLIGHT, highlight); + args.putBoolean(ARG_SHOW_IMMEDIATE, showImmediate); + + MessageListFragment fragment = new MessageListFragment(); fragment.updateArguments(args); return fragment; } + public MessageListFragment() { + + } + @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -323,7 +332,7 @@ public class MessageListFragment extends QKContentFragment implements ActivityLa /** * To be called when the user opens a conversation. Initializes the Conversation objects, sets * up the draft, and marks the conversation as read. - *

+ *

* Note: This will have no effect if the context has not been initialized yet. */ private void onOpenConversation() { @@ -672,7 +681,7 @@ public class MessageListFragment extends QKContentFragment implements ActivityLa /** * Should only be called for failed messages. Deletes the message, placing the text from the * message back in the edit box to be updated and then sent. - *

+ *

* Assumes that cursor points to the correct MessageItem. * * @param msgItem