Refactor MMS Dialog fragment

This commit is contained in:
Moez Bhatti
2015-12-06 03:28:11 -05:00
parent b844b5aa4a
commit 20520ca8f6
2 changed files with 36 additions and 36 deletions
@@ -36,7 +36,7 @@ import com.moez.QKSMS.ui.view.QKTextView;
* DialogFragmentListener. Then, the "onDialogFragmentResult" methods will get called much like * DialogFragmentListener. Then, the "onDialogFragmentResult" methods will get called much like
* "onActivityResult". * "onActivityResult".
*/ */
public class QKDialogFragment extends DialogFragment { public class MMSDialogFragment extends DialogFragment {
private final String TAG = "QKDialogFragment"; private final String TAG = "QKDialogFragment";
private Context mContext; private Context mContext;
@@ -104,7 +104,7 @@ public class QKDialogFragment extends DialogFragment {
* DialogFragmentListener. * DialogFragmentListener.
*/ */
public <T extends Fragment & DialogFragmentListener> public <T extends Fragment & DialogFragmentListener>
QKDialogFragment setListener(T l) { MMSDialogFragment setListener(T l) {
mListener = l; mListener = l;
setTargetFragment(l, 0); setTargetFragment(l, 0);
return this; return this;
@@ -253,54 +253,54 @@ public class QKDialogFragment extends DialogFragment {
onResult(DISMISS_RESULT); onResult(DISMISS_RESULT);
} }
public QKDialogFragment setContext(Context context) { public MMSDialogFragment setContext(Context context) {
mContext = context; mContext = context;
mResources = context.getResources(); mResources = context.getResources();
return this; return this;
} }
public QKDialogFragment setTitle(int resource) { public MMSDialogFragment setTitle(int resource) {
return setTitle(mResources.getString(resource)); return setTitle(mResources.getString(resource));
} }
public QKDialogFragment setTitle(String title) { public MMSDialogFragment setTitle(String title) {
mTitleEnabled = true; mTitleEnabled = true;
mTitleText = title; mTitleText = title;
return this; return this;
} }
public QKDialogFragment setMessage(int resource) { public MMSDialogFragment setMessage(int resource) {
return setMessage(mResources.getString(resource)); return setMessage(mResources.getString(resource));
} }
public QKDialogFragment setMessage(String message) { public MMSDialogFragment setMessage(String message) {
mMessageEnabled = true; mMessageEnabled = true;
mMessageText = message; mMessageText = message;
return this; return this;
} }
public QKDialogFragment setCancelOnTouchOutside(boolean cancelable) { public MMSDialogFragment setCancelOnTouchOutside(boolean cancelable) {
setCancelable(cancelable); setCancelable(cancelable);
return this; return this;
} }
// TODO fix stack from bottom issue // TODO fix stack from bottom issue
public QKDialogFragment setButtonBarOrientation(int orientation) { public MMSDialogFragment setButtonBarOrientation(int orientation) {
mButtonBarOrientation = orientation; mButtonBarOrientation = orientation;
return this; return this;
} }
public QKDialogFragment setCustomView(View view) { public MMSDialogFragment setCustomView(View view) {
mCustomViewEnabled = true; mCustomViewEnabled = true;
mCustomView = view; mCustomView = view;
return this; return this;
} }
public QKDialogFragment setItems(int resource, final int resultCode) { public MMSDialogFragment setItems(int resource, final int resultCode) {
return setItems(mResources.getStringArray(resource)); return setItems(mResources.getStringArray(resource));
} }
public QKDialogFragment setItems(String[] items) { public MMSDialogFragment setItems(String[] items) {
ArrayAdapter adapter = new ArrayAdapter<>(mContext, R.layout.list_item_simple, items); ArrayAdapter adapter = new ArrayAdapter<>(mContext, R.layout.list_item_simple, items);
ListView listView = new ListView(mContext); ListView listView = new ListView(mContext);
listView.setAdapter(adapter); listView.setAdapter(adapter);
@@ -316,13 +316,13 @@ public class QKDialogFragment extends DialogFragment {
return setCustomView(listView); return setCustomView(listView);
} }
public QKDialogFragment setDoubleLineItems(int titles, int bodies) { public MMSDialogFragment setDoubleLineItems(int titles, int bodies) {
return setDoubleLineItems( return setDoubleLineItems(
mResources.getStringArray(titles), mResources.getStringArray(bodies) mResources.getStringArray(titles), mResources.getStringArray(bodies)
); );
} }
public QKDialogFragment setDoubleLineItems(String[] titles, String[] bodies) { public MMSDialogFragment setDoubleLineItems(String[] titles, String[] bodies) {
int size = Math.min(titles.length, bodies.length); int size = Math.min(titles.length, bodies.length);
DoubleLineListItem[] doubleLineListItems = new DoubleLineListItem[size]; DoubleLineListItem[] doubleLineListItems = new DoubleLineListItem[size];
@@ -347,15 +347,15 @@ public class QKDialogFragment extends DialogFragment {
return setCustomView(listView); return setCustomView(listView);
} }
public QKDialogFragment setTripleLineItems(int titles, int subtitles, int bodies) { public MMSDialogFragment setTripleLineItems(int titles, int subtitles, int bodies) {
return setTripleLineItems( return setTripleLineItems(
mResources.getStringArray(titles), mResources.getStringArray(subtitles), mResources.getStringArray(titles), mResources.getStringArray(subtitles),
mResources.getStringArray(bodies) mResources.getStringArray(bodies)
); );
} }
public QKDialogFragment setTripleLineItems(String[] titles, String[] subtitles, public MMSDialogFragment setTripleLineItems(String[] titles, String[] subtitles,
String[] bodies) { String[] bodies) {
int size = Math.min(titles.length, Math.min(subtitles.length, bodies.length)); int size = Math.min(titles.length, Math.min(subtitles.length, bodies.length));
TripleLineListItem[] tripleLineListItems = new TripleLineListItem[size]; TripleLineListItem[] tripleLineListItems = new TripleLineListItem[size];
@@ -381,31 +381,31 @@ public class QKDialogFragment extends DialogFragment {
return setCustomView(listView); return setCustomView(listView);
} }
public QKDialogFragment setPositiveButton(int resource) { public MMSDialogFragment setPositiveButton(int resource) {
return setPositiveButton(mResources.getString(resource)); return setPositiveButton(mResources.getString(resource));
} }
public QKDialogFragment setPositiveButton(String text) { public MMSDialogFragment setPositiveButton(String text) {
mPositiveButtonEnabled = true; mPositiveButtonEnabled = true;
mPositiveButtonText = text; mPositiveButtonText = text;
return this; return this;
} }
public QKDialogFragment setNeutralButton(int resource) { public MMSDialogFragment setNeutralButton(int resource) {
return setNeutralButton(mResources.getString(resource)); return setNeutralButton(mResources.getString(resource));
} }
public QKDialogFragment setNeutralButton(String text) { public MMSDialogFragment setNeutralButton(String text) {
mNeutralButtonEnabled = true; mNeutralButtonEnabled = true;
mNeutralButtonText = text; mNeutralButtonText = text;
return this; return this;
} }
public QKDialogFragment setNegativeButton(int resource) { public MMSDialogFragment setNegativeButton(int resource) {
return setNegativeButton(mResources.getString(resource)); return setNegativeButton(mResources.getString(resource));
} }
public QKDialogFragment setNegativeButton(String text) { public MMSDialogFragment setNegativeButton(String text) {
mNegativeButtonEnabled = true; mNegativeButtonEnabled = true;
mNegativeButtonText = text; mNegativeButtonText = text;
return this; return this;
@@ -18,12 +18,12 @@ import com.moez.QKSMS.ui.base.QKFragment;
import java.util.List; import java.util.List;
import static com.moez.QKSMS.ui.dialog.mms.QKDialogFragment.DISMISS_RESULT; import static com.moez.QKSMS.ui.dialog.mms.MMSDialogFragment.DISMISS_RESULT;
import static com.moez.QKSMS.ui.dialog.mms.QKDialogFragment.DialogFragmentListener; import static com.moez.QKSMS.ui.dialog.mms.MMSDialogFragment.DialogFragmentListener;
import static com.moez.QKSMS.ui.dialog.mms.QKDialogFragment.LIST_ITEM_CLICK_RESULT; import static com.moez.QKSMS.ui.dialog.mms.MMSDialogFragment.LIST_ITEM_CLICK_RESULT;
import static com.moez.QKSMS.ui.dialog.mms.QKDialogFragment.NEGATIVE_BUTTON_RESULT; import static com.moez.QKSMS.ui.dialog.mms.MMSDialogFragment.NEGATIVE_BUTTON_RESULT;
import static com.moez.QKSMS.ui.dialog.mms.QKDialogFragment.NEUTRAL_BUTTON_RESULT; import static com.moez.QKSMS.ui.dialog.mms.MMSDialogFragment.NEUTRAL_BUTTON_RESULT;
import static com.moez.QKSMS.ui.dialog.mms.QKDialogFragment.POSITIVE_BUTTON_RESULT; import static com.moez.QKSMS.ui.dialog.mms.MMSDialogFragment.POSITIVE_BUTTON_RESULT;
/** /**
* @author Shane Creighton-Young * @author Shane Creighton-Young
@@ -270,7 +270,7 @@ public class MMSSetupFragment extends QKFragment implements DialogFragmentListen
mDialogTag = dialogTag; mDialogTag = dialogTag;
if (SET_UP_MMS.equals(dialogTag)) { if (SET_UP_MMS.equals(dialogTag)) {
QKDialogFragment f = new QKDialogFragment() MMSDialogFragment f = new MMSDialogFragment()
.setContext(mContext) .setContext(mContext)
.setTitle(R.string.set_up_mms_title) .setTitle(R.string.set_up_mms_title)
.setMessage(R.string.set_up_mms_description) .setMessage(R.string.set_up_mms_description)
@@ -288,7 +288,7 @@ public class MMSSetupFragment extends QKFragment implements DialogFragmentListen
f.show(getFragmentManager(), SET_UP_MMS); f.show(getFragmentManager(), SET_UP_MMS);
} else if (NO_CONFIGURATIONS_FOUND.equals(dialogTag)) { } else if (NO_CONFIGURATIONS_FOUND.equals(dialogTag)) {
new QKDialogFragment() new MMSDialogFragment()
.setContext(mContext) .setContext(mContext)
.setTitle(R.string.mms_setup_no_configurations_found_title) .setTitle(R.string.mms_setup_no_configurations_found_title)
.setMessage(R.string.mms_setup_no_configurations_found_body) .setMessage(R.string.mms_setup_no_configurations_found_body)
@@ -302,7 +302,7 @@ public class MMSSetupFragment extends QKFragment implements DialogFragmentListen
String message = getString(R.string.mms_setup_one_configuration_found_body, String message = getString(R.string.mms_setup_one_configuration_found_body,
carrier); carrier);
new QKDialogFragment() new MMSDialogFragment()
.setContext(mContext) .setContext(mContext)
.setTitle(R.string.mms_setup_one_configuration_found_title) .setTitle(R.string.mms_setup_one_configuration_found_title)
.setMessage(message) .setMessage(message)
@@ -317,7 +317,7 @@ public class MMSSetupFragment extends QKFragment implements DialogFragmentListen
items[i] = mAPNs.get(i).name; items[i] = mAPNs.get(i).name;
} }
new QKDialogFragment() new MMSDialogFragment()
.setContext(mContext) .setContext(mContext)
.setTitle(R.string.mms_setup_multiple_configurations_found_title) .setTitle(R.string.mms_setup_multiple_configurations_found_title)
.setMessage(R.string.mms_setup_multiple_configurations_found_body) .setMessage(R.string.mms_setup_multiple_configurations_found_body)
@@ -327,7 +327,7 @@ public class MMSSetupFragment extends QKFragment implements DialogFragmentListen
.show(getFragmentManager(), MULTIPLE_CONFIGURATIONS_FOUND); .show(getFragmentManager(), MULTIPLE_CONFIGURATIONS_FOUND);
} else if (SETTING_UP_MMS_LATER.equals(dialogTag)) { } else if (SETTING_UP_MMS_LATER.equals(dialogTag)) {
new QKDialogFragment() new MMSDialogFragment()
.setContext(mContext) .setContext(mContext)
.setTitle(R.string.mms_setup_setting_up_later_title) .setTitle(R.string.mms_setup_setting_up_later_title)
.setMessage(R.string.mms_setup_setting_up_later_body) .setMessage(R.string.mms_setup_setting_up_later_body)
@@ -336,7 +336,7 @@ public class MMSSetupFragment extends QKFragment implements DialogFragmentListen
.show(getFragmentManager(), SETTING_UP_MMS_LATER); .show(getFragmentManager(), SETTING_UP_MMS_LATER);
} else if (NEXT_STEPS.equals(dialogTag)) { } else if (NEXT_STEPS.equals(dialogTag)) {
new QKDialogFragment() new MMSDialogFragment()
.setContext(mContext) .setContext(mContext)
.setTitle(R.string.mms_setup_next_steps_title) .setTitle(R.string.mms_setup_next_steps_title)
.setMessage(R.string.mms_setup_next_steps_body) .setMessage(R.string.mms_setup_next_steps_body)
@@ -345,7 +345,7 @@ public class MMSSetupFragment extends QKFragment implements DialogFragmentListen
.show(getFragmentManager(), NEXT_STEPS); .show(getFragmentManager(), NEXT_STEPS);
} else if (SUCCESS.equals(dialogTag)) { } else if (SUCCESS.equals(dialogTag)) {
new QKDialogFragment() new MMSDialogFragment()
.setContext(mContext) .setContext(mContext)
.setTitle(R.string.mms_setup_success_title) .setTitle(R.string.mms_setup_success_title)
.setMessage(R.string.mms_setup_success_body) .setMessage(R.string.mms_setup_success_body)