Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/stefan-niedermann/nextcloud-deck.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorstefan-niedermann <info@niedermann.it>2019-10-19 22:35:07 +0300
committerstefan-niedermann <info@niedermann.it>2019-10-19 22:35:07 +0300
commit18103cb6e156c76c5e243deeafcab2db64a0b640 (patch)
tree9fb837a683c40ab10247e58a666b57e8506b2f43 /app
parentcc89e57d7860af61af33886f8c7005cec517a0fb (diff)
Catch OfflineException on version check when adding an account
Diffstat (limited to 'app')
-rw-r--r--app/src/main/java/it/niedermann/nextcloud/deck/ui/DrawerActivity.java64
-rw-r--r--app/src/main/res/values/strings.xml1
2 files changed, 38 insertions, 27 deletions
diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/ui/DrawerActivity.java b/app/src/main/java/it/niedermann/nextcloud/deck/ui/DrawerActivity.java
index 3322abb36..f3e3fb2d5 100644
--- a/app/src/main/java/it/niedermann/nextcloud/deck/ui/DrawerActivity.java
+++ b/app/src/main/java/it/niedermann/nextcloud/deck/ui/DrawerActivity.java
@@ -57,6 +57,7 @@ import it.niedermann.nextcloud.deck.Application;
import it.niedermann.nextcloud.deck.DeckLog;
import it.niedermann.nextcloud.deck.R;
import it.niedermann.nextcloud.deck.api.IResponseCallback;
+import it.niedermann.nextcloud.deck.exceptions.OfflineException;
import it.niedermann.nextcloud.deck.model.Account;
import it.niedermann.nextcloud.deck.model.ocs.Capabilities;
import it.niedermann.nextcloud.deck.model.ocs.Version;
@@ -144,34 +145,43 @@ public abstract class DrawerActivity extends AppCompatActivity implements Naviga
editor.putLong(sharedPreferenceLastAccount, createdAccount.getId());
editor.commit();
- syncManager.getServerVersion(new IResponseCallback<Capabilities>(createdAccount) {
- @Override
- public void onResponse(Capabilities response) {
- if (response.getDeckVersion().compareTo(new Version(minimumServerAppMajor, minimumServerAppMinor, minimumServerAppPatch)) < 0) {
- deckVersionTooLowSnackbar = Snackbar.make(coordinatorLayout, R.string.your_deck_version_is_too_old, Snackbar.LENGTH_INDEFINITE).setAction("Learn more", v -> {
- new AlertDialog.Builder(DrawerActivity.this, Application.getAppTheme(getApplicationContext()) ? R.style.DialogDarkTheme : R.style.ThemeOverlay_AppCompat_Dialog_Alert)
- .setTitle(R.string.update_deck)
- .setMessage(R.string.deck_outdated_please_update)
- .setPositiveButton(R.string.simple_update, (dialog, whichButton) -> {
- Intent openURL = new Intent(Intent.ACTION_VIEW);
- openURL.setData(Uri.parse(createdAccount.getUrl() + urlFragmentUpdateDeck));
- startActivity(openURL);
- })
- .setNegativeButton(R.string.simple_discard, null).show();
- });
- deckVersionTooLowSnackbar.show();
- syncManager.deleteAccount(createdAccount.getId());
-
- sharedPreferences.getLong(sharedPreferenceLastAccount, NO_ACCOUNTS);
- SharedPreferences.Editor editor = sharedPreferences.edit();
- DeckLog.log("--- Remove: shared_preference_last_account" + " | " + createdAccount.getId());
- editor.remove(sharedPreferenceLastAccount);
- editor.commit(); // Has to be done synchronously
- } else {
- accountIsGettingImportedSnackbar.show();
+ try {
+ syncManager.getServerVersion(new IResponseCallback<Capabilities>(createdAccount) {
+ @Override
+ public void onResponse(Capabilities response) {
+ if (response.getDeckVersion().compareTo(new Version(minimumServerAppMajor, minimumServerAppMinor, minimumServerAppPatch)) < 0) {
+ deckVersionTooLowSnackbar = Snackbar.make(coordinatorLayout, R.string.your_deck_version_is_too_old, Snackbar.LENGTH_INDEFINITE).setAction("Learn more", v -> {
+ new AlertDialog.Builder(DrawerActivity.this, Application.getAppTheme(getApplicationContext()) ? R.style.DialogDarkTheme : R.style.ThemeOverlay_AppCompat_Dialog_Alert)
+ .setTitle(R.string.update_deck)
+ .setMessage(R.string.deck_outdated_please_update)
+ .setPositiveButton(R.string.simple_update, (dialog, whichButton) -> {
+ Intent openURL = new Intent(Intent.ACTION_VIEW);
+ openURL.setData(Uri.parse(createdAccount.getUrl() + urlFragmentUpdateDeck));
+ startActivity(openURL);
+ })
+ .setNegativeButton(R.string.simple_discard, null).show();
+ });
+ deckVersionTooLowSnackbar.show();
+ syncManager.deleteAccount(createdAccount.getId());
+ SharedPreferences.Editor editor = sharedPreferences.edit();
+ DeckLog.log("--- Remove: shared_preference_last_account" + " | " + createdAccount.getId());
+ editor.remove(sharedPreferenceLastAccount);
+ editor.commit(); // Has to be done synchronously
+ } else {
+ accountIsGettingImportedSnackbar.show();
+ }
}
- }
- });
+ });
+ } catch (OfflineException e) {
+ new AlertDialog.Builder(DrawerActivity.this)
+ .setMessage(R.string.you_have_to_be_connected_to_the_internet_in_order_to_add_an_account)
+ .setPositiveButton(R.string.simple_close, null)
+ .show();
+ syncManager.deleteAccount(createdAccount.getId());
+ DeckLog.log("--- Remove: shared_preference_last_account" + " | " + createdAccount.getId());
+ editor.remove(sharedPreferenceLastAccount);
+ editor.commit(); // Has to be done synchronously
+ }
}
});
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 22f552746..6b019441a 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -141,4 +141,5 @@
<string name="you_are_currently_offline">You are currently offline</string>
<string name="simple_manage">manage</string>
<string name="simple_share">share</string>
+ <string name="you_have_to_be_connected_to_the_internet_in_order_to_add_an_account">You have to be connected to the internet in order to add an account.</string>
</resources>