Skip to content

Commit

Permalink
Add error dialog when error happened while saving hosts (no root?)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nilhcem committed May 7, 2013
1 parent 3055cc3 commit 0acb265
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
5 changes: 5 additions & 0 deletions res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@
<string name="list_menu_delete">Delete</string>
<string name="list_menu_toggle">Toggle</string>

<!-- List hosts error dialog -->
<string name="list_error_title">Error</string>
<string name="list_error_content">Can\'t edit hosts, make sure your device is rooted.\nThe app should be allowed to request super user access.</string>
<string name="list_error_ok">OK</string>

<!-- Delete confirmation dialog -->
<string name="delete_dialog_title">Delete</string>
<plurals name="delete_dialog_content">
Expand Down
24 changes: 22 additions & 2 deletions src/com/nilhcem/hostseditor/list/ListHostsFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,7 @@ public void onTaskFinished(TaskCompletedEvent task) {
if (task.isSuccessful()) {
refreshHosts(false);
} else {
// Display error message
// Force reload
displayErrorDialog();
}
}

Expand Down Expand Up @@ -247,6 +246,27 @@ public void onClick(DialogInterface dialog, int which) {
mDisplayedDialog.show();
}

private void displayErrorDialog() {
mBus.post(new LoadingEvent(false));
mDisplayedDialog = new AlertDialog.Builder(mActivity)
.setTitle(R.string.list_error_title)
.setMessage(R.string.list_error_content)
.setNeutralButton(R.string.list_error_ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
refreshHosts(true);
}
})
.setOnCancelListener(new DialogInterface.OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
refreshHosts(true);
}
})
.create();
mDisplayedDialog.show();
}

private void runGenericTask(Class<? extends GenericTaskAsync> clazz, Host[] hosts) {
runGenericTask(clazz, hosts, hosts.length == 1);
}
Expand Down

0 comments on commit 0acb265

Please sign in to comment.