Extract alert dialog creation to a function

This commit is contained in:
Suchit Kar 2018-02-28 01:57:53 +05:30
parent de9bb89ff2
commit 67d1df27fb

View file

@ -233,26 +233,14 @@ public class SingleUploadFragment extends CommonsDaggerSupportFragment {
if (ViewCompat.getLayoutDirection(getView()) == ViewCompat.LAYOUT_DIRECTION_LTR) { if (ViewCompat.getLayoutDirection(getView()) == ViewCompat.LAYOUT_DIRECTION_LTR) {
value = titleEdit.getRight() - titleEdit.getCompoundDrawables()[2].getBounds().width(); value = titleEdit.getRight() - titleEdit.getCompoundDrawables()[2].getBounds().width();
if (motionEvent.getAction() == ACTION_UP && motionEvent.getRawX() >= value) { if (motionEvent.getAction() == ACTION_UP && motionEvent.getRawX() >= value) {
new AlertDialog.Builder(getContext()) showInfoAlert(R.string.media_detail_title, R.string.title_info);
.setTitle(R.string.media_detail_title)
.setMessage(R.string.title_info)
.setCancelable(true)
.setNeutralButton(android.R.string.ok, (dialog, id) -> dialog.cancel())
.create()
.show();
return true; return true;
} }
} }
else { else {
value = titleEdit.getLeft() + titleEdit.getCompoundDrawables()[0].getBounds().width(); value = titleEdit.getLeft() + titleEdit.getCompoundDrawables()[0].getBounds().width();
if (motionEvent.getAction() == ACTION_UP && motionEvent.getRawX() <= value) { if (motionEvent.getAction() == ACTION_UP && motionEvent.getRawX() <= value) {
new AlertDialog.Builder(getContext()) showInfoAlert(R.string.media_detail_title, R.string.title_info);
.setTitle(R.string.media_detail_title)
.setMessage(R.string.title_info)
.setCancelable(true)
.setNeutralButton(android.R.string.ok, (dialog, id) -> dialog.cancel())
.create()
.show();
return true; return true;
} }
} }
@ -265,26 +253,14 @@ public class SingleUploadFragment extends CommonsDaggerSupportFragment {
if (ViewCompat.getLayoutDirection(getView()) == ViewCompat.LAYOUT_DIRECTION_LTR) { if (ViewCompat.getLayoutDirection(getView()) == ViewCompat.LAYOUT_DIRECTION_LTR) {
value = descEdit.getRight() - descEdit.getCompoundDrawables()[2].getBounds().width(); value = descEdit.getRight() - descEdit.getCompoundDrawables()[2].getBounds().width();
if (motionEvent.getAction() == ACTION_UP && motionEvent.getRawX() >= value) { if (motionEvent.getAction() == ACTION_UP && motionEvent.getRawX() >= value) {
new AlertDialog.Builder(getContext()) showInfoAlert(R.string.media_detail_description,R.string.description_info);
.setTitle(R.string.media_detail_description)
.setMessage(R.string.description_info)
.setCancelable(true)
.setNeutralButton(android.R.string.ok, (dialog, id) -> dialog.cancel())
.create()
.show();
return true; return true;
} }
} }
else{ else{
value = descEdit.getLeft() + descEdit.getCompoundDrawables()[0].getBounds().width(); value = descEdit.getLeft() + descEdit.getCompoundDrawables()[0].getBounds().width();
if (motionEvent.getAction() == ACTION_UP && motionEvent.getRawX() <= value) { if (motionEvent.getAction() == ACTION_UP && motionEvent.getRawX() <= value) {
new AlertDialog.Builder(getContext()) showInfoAlert(R.string.media_detail_description,R.string.description_info);
.setTitle(R.string.media_detail_description)
.setMessage(R.string.description_info)
.setCancelable(true)
.setNeutralButton(android.R.string.ok, (dialog, id) -> dialog.cancel())
.create()
.show();
return true; return true;
} }
} }
@ -351,4 +327,14 @@ public class SingleUploadFragment extends CommonsDaggerSupportFragment {
} }
} }
} }
private void showInfoAlert (int titleStringID, int messageStringID){
new AlertDialog.Builder(getContext())
.setTitle(titleStringID)
.setMessage(messageStringID)
.setCancelable(true)
.setNeutralButton(android.R.string.ok, (dialog, id) -> dialog.cancel())
.create()
.show();
}
} }