From 0acb265d579eb2a71e9abd7cddaec75541022f94 Mon Sep 17 00:00:00 2001 From: Gautier Nilhcem Date: Tue, 7 May 2013 13:59:25 +0200 Subject: [PATCH] Add error dialog when error happened while saving hosts (no root?) --- res/values/strings.xml | 5 ++++ .../hostseditor/list/ListHostsFragment.java | 24 +++++++++++++++++-- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/res/values/strings.xml b/res/values/strings.xml index ed8d22a..87e901b 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -33,6 +33,11 @@ Delete Toggle + + Error + Can\'t edit hosts, make sure your device is rooted.\nThe app should be allowed to request super user access. + OK + Delete diff --git a/src/com/nilhcem/hostseditor/list/ListHostsFragment.java b/src/com/nilhcem/hostseditor/list/ListHostsFragment.java index 7ac0617..83b928c 100644 --- a/src/com/nilhcem/hostseditor/list/ListHostsFragment.java +++ b/src/com/nilhcem/hostseditor/list/ListHostsFragment.java @@ -117,8 +117,7 @@ public void onTaskFinished(TaskCompletedEvent task) { if (task.isSuccessful()) { refreshHosts(false); } else { - // Display error message - // Force reload + displayErrorDialog(); } } @@ -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 clazz, Host[] hosts) { runGenericTask(clazz, hosts, hosts.length == 1); }