|
71 | 71 |
|
72 | 72 | import it.niedermann.android.util.ColorUtil; |
73 | 73 | import it.niedermann.owncloud.notes.LockedActivity; |
| 74 | +import it.niedermann.owncloud.notes.NotesApplication; |
74 | 75 | import it.niedermann.owncloud.notes.R; |
75 | 76 | import it.niedermann.owncloud.notes.accountpicker.AccountPickerListener; |
76 | 77 | import it.niedermann.owncloud.notes.accountswitcher.AccountSwitcherDialog; |
@@ -179,37 +180,7 @@ protected void onCreate(Bundle savedInstanceState) { |
179 | 180 | runOnUiThread(() -> mainViewModel.postCurrentAccount(account)); |
180 | 181 | } catch (NextcloudFilesAppAccountNotFoundException e) { |
181 | 182 | // Verbose log output for https://github.com/nextcloud/notes-android/issues/1256 |
182 | | - runOnUiThread(() -> new MaterialAlertDialogBuilder(this) |
183 | | - .setTitle(NextcloudFilesAppAccountNotFoundException.class.getSimpleName()) |
184 | | - .setMessage(R.string.backup) |
185 | | - .setPositiveButton(R.string.simple_backup, (a, b) -> executor.submit(() -> { |
186 | | - final var modifiedNotes = new LinkedList<Note>(); |
187 | | - for (final var account : mainViewModel.getAccounts()) { |
188 | | - modifiedNotes.addAll(mainViewModel.getLocalModifiedNotes(account.getId())); |
189 | | - } |
190 | | - if (modifiedNotes.size() == 1) { |
191 | | - final var note = modifiedNotes.get(0); |
192 | | - ShareUtil.openShareDialog(this, note.getTitle(), note.getContent()); |
193 | | - } else { |
194 | | - ShareUtil.openShareDialog(this, |
195 | | - getResources().getQuantityString(R.plurals.share_multiple, modifiedNotes.size(), modifiedNotes.size()), |
196 | | - mainViewModel.collectNoteContents(modifiedNotes.stream().map(Note::getId).collect(Collectors.toList()))); |
197 | | - } |
198 | | - })) |
199 | | - .setNegativeButton(R.string.simple_error, (a, b) -> { |
200 | | - final var ssoPreferences = AccountImporter.getSharedPreferences(getApplicationContext()); |
201 | | - final var ssoPreferencesString = new StringBuilder() |
202 | | - .append("Current SSO account: ").append(ssoPreferences.getString("PREF_CURRENT_ACCOUNT_STRING", null)).append("\n") |
203 | | - .append("\n") |
204 | | - .append("SSO SharedPreferences: ").append("\n"); |
205 | | - for (final var entry : ssoPreferences.getAll().entrySet()) { |
206 | | - ssoPreferencesString.append(entry.getKey()).append(": ").append(entry.getValue()).append("\n"); |
207 | | - } |
208 | | - ssoPreferencesString.append("\n") |
209 | | - .append("Available accounts in DB: ").append(TextUtils.join(", ", mainViewModel.getAccounts().stream().map(Account::getAccountName).collect(Collectors.toList()))); |
210 | | - runOnUiThread(() -> ExceptionDialogFragment.newInstance(new RuntimeException(e.getMessage(), new RuntimeException(ssoPreferencesString.toString(), e))).show(getSupportFragmentManager(), ExceptionDialogFragment.class.getSimpleName())); |
211 | | - }) |
212 | | - .show()); |
| 183 | + runOnUiThread(() -> showExceptionAlertDialog(e)); |
213 | 184 | } catch (NoCurrentAccountSelectedException e) { |
214 | 185 | runOnUiThread(() -> ExceptionDialogFragment.newInstance(e).show(getSupportFragmentManager(), ExceptionDialogFragment.class.getSimpleName())); |
215 | 186 | } |
@@ -354,6 +325,43 @@ public void onError(@NonNull Throwable t) { |
354 | 325 | }); |
355 | 326 | } |
356 | 327 |
|
| 328 | + private void showExceptionAlertDialog(NextcloudFilesAppAccountNotFoundException e) { |
| 329 | + final MaterialAlertDialogBuilder alertDialogBuilder = new MaterialAlertDialogBuilder(this) |
| 330 | + .setTitle(NextcloudFilesAppAccountNotFoundException.class.getSimpleName()) |
| 331 | + .setMessage(R.string.backup) |
| 332 | + .setPositiveButton(R.string.simple_backup, (a, b) -> executor.submit(() -> { |
| 333 | + final var modifiedNotes = new LinkedList<Note>(); |
| 334 | + for (final var account : mainViewModel.getAccounts()) { |
| 335 | + modifiedNotes.addAll(mainViewModel.getLocalModifiedNotes(account.getId())); |
| 336 | + } |
| 337 | + if (modifiedNotes.size() == 1) { |
| 338 | + final var note = modifiedNotes.get(0); |
| 339 | + ShareUtil.openShareDialog(this, note.getTitle(), note.getContent()); |
| 340 | + } else { |
| 341 | + ShareUtil.openShareDialog(this, |
| 342 | + getResources().getQuantityString(R.plurals.share_multiple, modifiedNotes.size(), modifiedNotes.size()), |
| 343 | + mainViewModel.collectNoteContents(modifiedNotes.stream().map(Note::getId).collect(Collectors.toList()))); |
| 344 | + } |
| 345 | + })) |
| 346 | + .setNegativeButton(R.string.simple_error, (a, b) -> { |
| 347 | + final var ssoPreferences = AccountImporter.getSharedPreferences(getApplicationContext()); |
| 348 | + final var ssoPreferencesString = new StringBuilder() |
| 349 | + .append("Current SSO account: ").append(ssoPreferences.getString("PREF_CURRENT_ACCOUNT_STRING", null)).append("\n") |
| 350 | + .append("\n") |
| 351 | + .append("SSO SharedPreferences: ").append("\n"); |
| 352 | + for (final var entry : ssoPreferences.getAll().entrySet()) { |
| 353 | + ssoPreferencesString.append(entry.getKey()).append(": ").append(entry.getValue()).append("\n"); |
| 354 | + } |
| 355 | + ssoPreferencesString.append("\n") |
| 356 | + .append("Available accounts in DB: ").append(TextUtils.join(", ", mainViewModel.getAccounts().stream().map(Account::getAccountName).collect(Collectors.toList()))); |
| 357 | + runOnUiThread(() -> ExceptionDialogFragment.newInstance(new RuntimeException(e.getMessage(), new RuntimeException(ssoPreferencesString.toString(), e))).show(getSupportFragmentManager(), ExceptionDialogFragment.class.getSimpleName())); |
| 358 | + }); |
| 359 | + |
| 360 | + NotesApplication.brandingUtil().dialog.colorMaterialAlertDialogBackground(this, alertDialogBuilder); |
| 361 | + |
| 362 | + alertDialogBuilder.show(); |
| 363 | + } |
| 364 | + |
357 | 365 | @Override |
358 | 366 | protected void onResume() { |
359 | 367 | final var accountLiveData = mainViewModel.getCurrentAccount(); |
|
0 commit comments