Skip to content

Commit 39a8d17

Browse files
committed
Move cannot open document dialog to reusable function.
1 parent 124c70c commit 39a8d17

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

lib/src/main/java/com/artifex/mupdf/viewer/DocumentActivity.java

+14-11
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,19 @@ private MuPDFCore openCore(Uri uri, long size, String mimetype) throws IOExcepti
178178
}
179179
}
180180

181+
private void showCannotOpenDialog(String reason) {
182+
Resources res = getResources();
183+
AlertDialog alert = mAlertBuilder.create();
184+
setTitle(String.format(Locale.ROOT, res.getString(R.string.cannot_open_document_Reason), reason));
185+
alert.setButton(AlertDialog.BUTTON_POSITIVE, getString(R.string.dismiss),
186+
new DialogInterface.OnClickListener() {
187+
public void onClick(DialogInterface dialog, int which) {
188+
finish();
189+
}
190+
});
191+
alert.show();
192+
}
193+
181194
/** Called when the activity is first created. */
182195
@Override
183196
public void onCreate(final Bundle savedInstanceState)
@@ -257,17 +270,7 @@ public void onCreate(final Bundle savedInstanceState)
257270
core = openCore(uri, size, mimetype);
258271
SearchTaskResult.set(null);
259272
} catch (Exception x) {
260-
String reason = x.toString();
261-
Resources res = getResources();
262-
AlertDialog alert = mAlertBuilder.create();
263-
setTitle(String.format(Locale.ROOT, res.getString(R.string.cannot_open_document_Reason), reason));
264-
alert.setButton(AlertDialog.BUTTON_POSITIVE, getString(R.string.dismiss),
265-
new DialogInterface.OnClickListener() {
266-
public void onClick(DialogInterface dialog, int which) {
267-
finish();
268-
}
269-
});
270-
alert.show();
273+
showCannotOpenDialog(x.toString());
271274
return;
272275
}
273276
}

0 commit comments

Comments
 (0)