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
diff options
context:
space:
mode:
authorstefan-niedermann <info@niedermann.it>2020-02-01 20:29:51 +0300
committerstefan-niedermann <info@niedermann.it>2020-02-01 20:29:51 +0300
commit9e497befcef99493c36e6d9b6db35734a3d252e3 (patch)
tree0cb657ea9cba956f2b1a282b7c1eeca0cdc30c6a
parent16182e52f9ad7b4d24186d8dc3359ce04e0da54b (diff)
#253 NPE on drag after dark-mode toggle
-rw-r--r--app/src/main/java/it/niedermann/nextcloud/deck/ui/DrawerActivity.java127
1 files changed, 67 insertions, 60 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 0126e251e..5727e52d0 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
@@ -75,6 +75,7 @@ public abstract class DrawerActivity extends AppCompatActivity implements Naviga
protected static final int MENU_ID_SETTINGS = -3;
protected static final int MENU_ID_ADD_ACCOUNT = -2;
protected static final int ACTIVITY_ABOUT = 1;
+ protected static final int ACTIVITY_SETTINGS = 2;
protected static final long NO_ACCOUNTS = -1;
protected static final long NO_BOARDS = -1;
protected static final long NO_STACKS = -1;
@@ -131,68 +132,74 @@ public abstract class DrawerActivity extends AppCompatActivity implements Naviga
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
- try {
- AccountImporter.onActivityResult(requestCode, resultCode, data, this, (SingleSignOnAccount account) -> {
- final WrappedLiveData<Account> accountLiveData = this.syncManager.createAccount(new Account(account.name, account.userId, account.url));
- accountLiveData.observe(this, (Account createdAccount) -> {
- if (accountLiveData.hasError()) {
- try {
- accountLiveData.throwError();
- } catch (SQLiteConstraintException ex) {
- Snackbar.make(coordinatorLayout, accountAlreadyAdded, Snackbar.LENGTH_LONG).show();
- }
- } else {
- // Remember last account - THIS HAS TO BE DONE SYNCHRONOUSLY
- SharedPreferences.Editor editor = sharedPreferences.edit();
- DeckLog.log("--- Write: shared_preference_last_account" + " | " + createdAccount.getId());
- editor.putLong(sharedPreferenceLastAccount, createdAccount.getId());
- editor.commit();
-
- 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 {
- SyncWorker.update(getApplicationContext());
- accountIsGettingImportedSnackbar.show();
+ if (requestCode == ACTIVITY_SETTINGS) {
+ if (resultCode == RESULT_OK) {
+ recreate();
+ }
+ } else {
+ try {
+ AccountImporter.onActivityResult(requestCode, resultCode, data, this, (SingleSignOnAccount account) -> {
+ final WrappedLiveData<Account> accountLiveData = this.syncManager.createAccount(new Account(account.name, account.userId, account.url));
+ accountLiveData.observe(this, (Account createdAccount) -> {
+ if (accountLiveData.hasError()) {
+ try {
+ accountLiveData.throwError();
+ } catch (SQLiteConstraintException ex) {
+ Snackbar.make(coordinatorLayout, accountAlreadyAdded, Snackbar.LENGTH_LONG).show();
+ }
+ } else {
+ // Remember last account - THIS HAS TO BE DONE SYNCHRONOUSLY
+ SharedPreferences.Editor editor = sharedPreferences.edit();
+ DeckLog.log("--- Write: shared_preference_last_account" + " | " + createdAccount.getId());
+ editor.putLong(sharedPreferenceLastAccount, createdAccount.getId());
+ editor.commit();
+
+ 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 {
+ SyncWorker.update(getApplicationContext());
+ 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
+ });
+ } 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
+ }
}
- }
- });
+ });
- SingleAccountHelper.setCurrentAccount(getApplicationContext(), account.name);
- });
- } catch (AccountImportCancelledException e) {
- // TODO: do nothing?
+ SingleAccountHelper.setCurrentAccount(getApplicationContext(), account.name);
+ });
+ } catch (AccountImportCancelledException e) {
+ // TODO: do nothing?
+ }
}
}
@@ -331,7 +338,7 @@ public abstract class DrawerActivity extends AppCompatActivity implements Naviga
break;
case MENU_ID_SETTINGS:
Intent settingsIntent = new Intent(getApplicationContext(), SettingsActivity.class);
- startActivityForResult(settingsIntent, ACTIVITY_ABOUT);
+ startActivityForResult(settingsIntent, ACTIVITY_SETTINGS);
break;
case MENU_ID_ADD_BOARD:
EditBoardDialogFragment.newInstance().show(getSupportFragmentManager(), addBoard);