diff options
author | Stefan Niedermann <info@niedermann.it> | 2020-05-04 11:34:26 +0300 |
---|---|---|
committer | Stefan Niedermann <info@niedermann.it> | 2020-05-04 11:34:26 +0300 |
commit | bac4d824d781eac5d9a85465b3ce0c37fc2f88b2 (patch) | |
tree | c6f4d93d549986e126cd2195a1ef527eb2a3dca4 /app/src/main/java/it/niedermann/nextcloud/deck/ui/ImportAccountActivity.java | |
parent | f30dde0702dff5163582e8df4f1ae4cbab28e534 (diff) |
Use new ExceptionDialogFragment with tips
Diffstat (limited to 'app/src/main/java/it/niedermann/nextcloud/deck/ui/ImportAccountActivity.java')
-rw-r--r-- | app/src/main/java/it/niedermann/nextcloud/deck/ui/ImportAccountActivity.java | 102 |
1 files changed, 48 insertions, 54 deletions
diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/ui/ImportAccountActivity.java b/app/src/main/java/it/niedermann/nextcloud/deck/ui/ImportAccountActivity.java index a3f3beeed..81bed1ec2 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/ui/ImportAccountActivity.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/ui/ImportAccountActivity.java @@ -17,7 +17,6 @@ import com.nextcloud.android.sso.AccountImporter; import com.nextcloud.android.sso.exceptions.AccountImportCancelledException; import com.nextcloud.android.sso.exceptions.AndroidGetAccountsPermissionNotGranted; import com.nextcloud.android.sso.exceptions.NextcloudFilesAppNotInstalledException; -import com.nextcloud.android.sso.exceptions.NextcloudHttpRequestFailedException; import com.nextcloud.android.sso.helper.SingleAccountHelper; import com.nextcloud.android.sso.model.SingleSignOnAccount; @@ -31,11 +30,11 @@ import it.niedermann.nextcloud.deck.model.ocs.Capabilities; import it.niedermann.nextcloud.deck.persistence.sync.SyncManager; import it.niedermann.nextcloud.deck.persistence.sync.SyncWorker; import it.niedermann.nextcloud.deck.persistence.sync.adapters.db.util.WrappedLiveData; +import it.niedermann.nextcloud.deck.ui.exception.ExceptionDialogFragment; import it.niedermann.nextcloud.deck.ui.exception.ExceptionHandler; import it.niedermann.nextcloud.deck.util.ExceptionUtil; import static com.nextcloud.android.sso.AccountImporter.REQUEST_AUTH_TOKEN_SSO; -import static it.niedermann.nextcloud.deck.util.ExceptionUtil.handleHttpRequestFailedException; public class ImportAccountActivity extends AppCompatActivity { @@ -119,7 +118,7 @@ public class ImportAccountActivity extends AppCompatActivity { } assert error != null; setStatusText(error.getMessage()); - DeckLog.logError(error); + runOnUiThread(() -> ExceptionDialogFragment.newInstance(error).show(getSupportFragmentManager(), ExceptionDialogFragment.class.getSimpleName())); restoreWifiPref(); } else { // Remember last account - THIS HAS TO BE DONE SYNCHRONOUSLY @@ -128,63 +127,58 @@ public class ImportAccountActivity extends AppCompatActivity { editor.putLong(sharedPreferenceLastAccount, createdAccount.getId()); editor.commit(); - try { - syncManager.refreshCapabilities(new IResponseCallback<Capabilities>(createdAccount) { - @Override - public void onResponse(Capabilities response) { - if (!response.isMaintenanceEnabled()) { - if (response.getDeckVersion().isSupported(getApplicationContext())) { - syncManager.synchronize(new IResponseCallback<Boolean>(account) { - @Override - public void onResponse(Boolean response) { - restoreWifiPref(); - SyncWorker.update(getApplicationContext()); - setResult(RESULT_OK); - finish(); - } - - @Override - public void onError(Throwable throwable) { - super.onError(throwable); - setStatusText(throwable.getMessage()); - if (throwable instanceof NextcloudHttpRequestFailedException) { - runOnUiThread(() -> handleHttpRequestFailedException((NextcloudHttpRequestFailedException) throwable, binding.scrollView, ImportAccountActivity.this)); - } - rollbackAccountCreation(syncManager, createdAccount.getId()); - } - }); - } else { - setStatusText(R.string.deck_outdated_please_update); - runOnUiThread(() -> { - binding.updateDeckButton.setOnClickListener((v) -> { - Intent openURL = new Intent(Intent.ACTION_VIEW); - openURL.setData(Uri.parse(createdAccount.getUrl() + urlFragmentUpdateDeck)); - startActivity(openURL); - }); - binding.updateDeckButton.setVisibility(View.VISIBLE); - }); - rollbackAccountCreation(syncManager, createdAccount.getId()); - } + syncManager.refreshCapabilities(new IResponseCallback<Capabilities>(createdAccount) { + @Override + public void onResponse(Capabilities response) { + if (!response.isMaintenanceEnabled()) { + if (response.getDeckVersion().isSupported(getApplicationContext())) { + syncManager.synchronize(new IResponseCallback<Boolean>(account) { + @Override + public void onResponse(Boolean response) { + restoreWifiPref(); + SyncWorker.update(getApplicationContext()); + setResult(RESULT_OK); + finish(); + } + + @Override + public void onError(Throwable throwable) { + super.onError(throwable); + setStatusText(throwable.getMessage()); + runOnUiThread(() -> ExceptionDialogFragment.newInstance(throwable).show(getSupportFragmentManager(), ExceptionDialogFragment.class.getSimpleName())); + rollbackAccountCreation(syncManager, createdAccount.getId()); + } + }); } else { - setStatusText(R.string.maintenance_mode); + setStatusText(R.string.deck_outdated_please_update); + runOnUiThread(() -> { + binding.updateDeckButton.setOnClickListener((v) -> { + Intent openURL = new Intent(Intent.ACTION_VIEW); + openURL.setData(Uri.parse(createdAccount.getUrl() + urlFragmentUpdateDeck)); + startActivity(openURL); + }); + binding.updateDeckButton.setVisibility(View.VISIBLE); + }); rollbackAccountCreation(syncManager, createdAccount.getId()); } + } else { + setStatusText(R.string.maintenance_mode); + rollbackAccountCreation(syncManager, createdAccount.getId()); } - - @Override - public void onError(Throwable throwable) { - super.onError(throwable); + } + + @Override + public void onError(Throwable throwable) { + super.onError(throwable); + if (throwable instanceof OfflineException) { + setStatusText(R.string.you_have_to_be_connected_to_the_internet_in_order_to_add_an_account); + } else { setStatusText(throwable.getMessage()); - if (throwable instanceof NextcloudHttpRequestFailedException) { - runOnUiThread(() -> handleHttpRequestFailedException((NextcloudHttpRequestFailedException) throwable, binding.scrollView, ImportAccountActivity.this)); - } - rollbackAccountCreation(syncManager, createdAccount.getId()); + runOnUiThread(() -> ExceptionDialogFragment.newInstance(throwable).show(getSupportFragmentManager(), ExceptionDialogFragment.class.getSimpleName())); } - }); - } catch (OfflineException e) { - setStatusText(R.string.you_have_to_be_connected_to_the_internet_in_order_to_add_an_account); - rollbackAccountCreation(syncManager, createdAccount.getId()); - } + rollbackAccountCreation(syncManager, createdAccount.getId()); + } + }); } }); } |