mirror of
https://github.com/nextcloud/notes-android.git
synced 2024-12-18 16:42:17 +03:00
Use brandingUtil for MaterialAlertDialogs
Signed-off-by: alperozturk <alper_ozturk@proton.me>
This commit is contained in:
parent
4738872f77
commit
94f1617031
7 changed files with 67 additions and 44 deletions
|
@ -27,6 +27,7 @@ import java.util.List;
|
|||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import it.niedermann.owncloud.notes.NotesApplication;
|
||||
import it.niedermann.owncloud.notes.R;
|
||||
import it.niedermann.owncloud.notes.branding.BrandedDialogFragment;
|
||||
import it.niedermann.owncloud.notes.databinding.DialogChooseAccountBinding;
|
||||
|
@ -80,11 +81,11 @@ public class AccountPickerDialogFragment extends BrandedDialogFragment {
|
|||
@NonNull
|
||||
@Override
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
final var dialogBuilder = new MaterialAlertDialogBuilder(requireActivity())
|
||||
final MaterialAlertDialogBuilder dialogBuilder = new MaterialAlertDialogBuilder(requireActivity())
|
||||
.setTitle(R.string.simple_move)
|
||||
.setNegativeButton(android.R.string.cancel, null);
|
||||
|
||||
if (targetAccounts.size() > 0) {
|
||||
if (!targetAccounts.isEmpty()) {
|
||||
final var binding = DialogChooseAccountBinding.inflate(LayoutInflater.from(requireContext()));
|
||||
final var adapter = new AccountChooserAdapter(targetAccounts, (account -> {
|
||||
accountPickerListener.onAccountPicked(account);
|
||||
|
@ -96,6 +97,8 @@ public class AccountPickerDialogFragment extends BrandedDialogFragment {
|
|||
dialogBuilder.setMessage(getString(R.string.no_other_accounts));
|
||||
}
|
||||
|
||||
NotesApplication.brandingUtil().dialog.colorMaterialAlertDialogBackground(requireContext(), dialogBuilder);
|
||||
|
||||
return dialogBuilder.create();
|
||||
}
|
||||
|
||||
|
|
|
@ -109,7 +109,7 @@ public class AccountSwitcherDialog extends BrandedDialogFragment {
|
|||
dismiss();
|
||||
});
|
||||
|
||||
MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(requireContext())
|
||||
final MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(requireContext())
|
||||
.setView(binding.getRoot());
|
||||
|
||||
NotesApplication.brandingUtil().dialog.colorMaterialAlertDialogBackground(requireContext(), builder);
|
||||
|
|
|
@ -24,6 +24,7 @@ import com.google.android.material.dialog.MaterialAlertDialogBuilder;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
import it.niedermann.owncloud.notes.NotesApplication;
|
||||
import it.niedermann.owncloud.notes.R;
|
||||
import it.niedermann.owncloud.notes.branding.BrandedDialogFragment;
|
||||
import it.niedermann.owncloud.notes.branding.BrandingUtil;
|
||||
|
@ -155,13 +156,16 @@ public class CategoryDialogFragment extends BrandedDialogFragment {
|
|||
}
|
||||
});
|
||||
|
||||
return new MaterialAlertDialogBuilder(requireContext())
|
||||
final MaterialAlertDialogBuilder alertDialogBuilder = new MaterialAlertDialogBuilder(requireContext())
|
||||
.setTitle(R.string.change_category_title)
|
||||
.setView(dialogView)
|
||||
.setCancelable(true)
|
||||
.setPositiveButton(R.string.action_edit_save, (dialog, which) -> listener.onCategoryChosen(editCategory.getText().toString()))
|
||||
.setNegativeButton(R.string.simple_cancel, null)
|
||||
.create();
|
||||
.setNegativeButton(R.string.simple_cancel, null);
|
||||
|
||||
NotesApplication.brandingUtil().dialog.colorMaterialAlertDialogBackground(requireContext(), alertDialogBuilder);
|
||||
|
||||
return alertDialogBuilder.create();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -17,6 +17,7 @@ import androidx.fragment.app.DialogFragment;
|
|||
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
|
||||
|
||||
import it.niedermann.owncloud.notes.NotesApplication;
|
||||
import it.niedermann.owncloud.notes.R;
|
||||
import it.niedermann.owncloud.notes.branding.BrandedDialogFragment;
|
||||
import it.niedermann.owncloud.notes.branding.BrandingUtil;
|
||||
|
@ -59,13 +60,16 @@ public class EditTitleDialogFragment extends BrandedDialogFragment {
|
|||
binding.title.setText(oldTitle);
|
||||
}
|
||||
|
||||
return new MaterialAlertDialogBuilder(requireContext())
|
||||
final MaterialAlertDialogBuilder alertDialogBuilder = new MaterialAlertDialogBuilder(requireContext())
|
||||
.setTitle(R.string.change_note_title)
|
||||
.setView(dialogView)
|
||||
.setCancelable(true)
|
||||
.setPositiveButton(R.string.action_edit_save, (dialog, which) -> listener.onTitleEdited(binding.title.getText().toString()))
|
||||
.setNegativeButton(R.string.simple_cancel, null)
|
||||
.create();
|
||||
.setNegativeButton(R.string.simple_cancel, null);
|
||||
|
||||
NotesApplication.brandingUtil().dialog.colorMaterialAlertDialogBackground(requireContext(), alertDialogBuilder);
|
||||
|
||||
return alertDialogBuilder.create();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -22,6 +22,7 @@ import java.util.ArrayList;
|
|||
import it.niedermann.android.util.ClipboardUtil;
|
||||
import it.niedermann.nextcloud.exception.ExceptionUtil;
|
||||
import it.niedermann.owncloud.notes.BuildConfig;
|
||||
import it.niedermann.owncloud.notes.NotesApplication;
|
||||
import it.niedermann.owncloud.notes.R;
|
||||
import it.niedermann.owncloud.notes.databinding.DialogExceptionBinding;
|
||||
import it.niedermann.owncloud.notes.exception.tips.TipsAdapter;
|
||||
|
@ -69,12 +70,15 @@ public class ExceptionDialogFragment extends AppCompatDialogFragment {
|
|||
|
||||
adapter.setThrowables(throwables);
|
||||
|
||||
return new MaterialAlertDialogBuilder(requireActivity())
|
||||
final MaterialAlertDialogBuilder alertDialogBuilder = new MaterialAlertDialogBuilder(requireActivity())
|
||||
.setView(binding.getRoot())
|
||||
.setTitle(R.string.error_dialog_title)
|
||||
.setPositiveButton(android.R.string.copy, (a, b) -> ClipboardUtil.copyToClipboard(requireContext(), getString(R.string.simple_exception), "```\n" + debugInfos + "\n```"))
|
||||
.setNegativeButton(R.string.simple_close, null)
|
||||
.create();
|
||||
.setNegativeButton(R.string.simple_close, null);
|
||||
|
||||
NotesApplication.brandingUtil().dialog.colorMaterialAlertDialogBackground(requireContext(), alertDialogBuilder);
|
||||
|
||||
return alertDialogBuilder.create();
|
||||
}
|
||||
|
||||
public static DialogFragment newInstance(ArrayList<Throwable> exceptions) {
|
||||
|
|
|
@ -71,6 +71,7 @@ import java.util.stream.Collectors;
|
|||
|
||||
import it.niedermann.android.util.ColorUtil;
|
||||
import it.niedermann.owncloud.notes.LockedActivity;
|
||||
import it.niedermann.owncloud.notes.NotesApplication;
|
||||
import it.niedermann.owncloud.notes.R;
|
||||
import it.niedermann.owncloud.notes.accountpicker.AccountPickerListener;
|
||||
import it.niedermann.owncloud.notes.accountswitcher.AccountSwitcherDialog;
|
||||
|
@ -179,37 +180,7 @@ public class MainActivity extends LockedActivity implements NoteClickListener, A
|
|||
runOnUiThread(() -> mainViewModel.postCurrentAccount(account));
|
||||
} catch (NextcloudFilesAppAccountNotFoundException e) {
|
||||
// Verbose log output for https://github.com/nextcloud/notes-android/issues/1256
|
||||
runOnUiThread(() -> new MaterialAlertDialogBuilder(this)
|
||||
.setTitle(NextcloudFilesAppAccountNotFoundException.class.getSimpleName())
|
||||
.setMessage(R.string.backup)
|
||||
.setPositiveButton(R.string.simple_backup, (a, b) -> executor.submit(() -> {
|
||||
final var modifiedNotes = new LinkedList<Note>();
|
||||
for (final var account : mainViewModel.getAccounts()) {
|
||||
modifiedNotes.addAll(mainViewModel.getLocalModifiedNotes(account.getId()));
|
||||
}
|
||||
if (modifiedNotes.size() == 1) {
|
||||
final var note = modifiedNotes.get(0);
|
||||
ShareUtil.openShareDialog(this, note.getTitle(), note.getContent());
|
||||
} else {
|
||||
ShareUtil.openShareDialog(this,
|
||||
getResources().getQuantityString(R.plurals.share_multiple, modifiedNotes.size(), modifiedNotes.size()),
|
||||
mainViewModel.collectNoteContents(modifiedNotes.stream().map(Note::getId).collect(Collectors.toList())));
|
||||
}
|
||||
}))
|
||||
.setNegativeButton(R.string.simple_error, (a, b) -> {
|
||||
final var ssoPreferences = AccountImporter.getSharedPreferences(getApplicationContext());
|
||||
final var ssoPreferencesString = new StringBuilder()
|
||||
.append("Current SSO account: ").append(ssoPreferences.getString("PREF_CURRENT_ACCOUNT_STRING", null)).append("\n")
|
||||
.append("\n")
|
||||
.append("SSO SharedPreferences: ").append("\n");
|
||||
for (final var entry : ssoPreferences.getAll().entrySet()) {
|
||||
ssoPreferencesString.append(entry.getKey()).append(": ").append(entry.getValue()).append("\n");
|
||||
}
|
||||
ssoPreferencesString.append("\n")
|
||||
.append("Available accounts in DB: ").append(TextUtils.join(", ", mainViewModel.getAccounts().stream().map(Account::getAccountName).collect(Collectors.toList())));
|
||||
runOnUiThread(() -> ExceptionDialogFragment.newInstance(new RuntimeException(e.getMessage(), new RuntimeException(ssoPreferencesString.toString(), e))).show(getSupportFragmentManager(), ExceptionDialogFragment.class.getSimpleName()));
|
||||
})
|
||||
.show());
|
||||
runOnUiThread(() -> showExceptionAlertDialog(e));
|
||||
} catch (NoCurrentAccountSelectedException e) {
|
||||
runOnUiThread(() -> ExceptionDialogFragment.newInstance(e).show(getSupportFragmentManager(), ExceptionDialogFragment.class.getSimpleName()));
|
||||
}
|
||||
|
@ -354,6 +325,43 @@ public class MainActivity extends LockedActivity implements NoteClickListener, A
|
|||
});
|
||||
}
|
||||
|
||||
private void showExceptionAlertDialog(NextcloudFilesAppAccountNotFoundException e) {
|
||||
final MaterialAlertDialogBuilder alertDialogBuilder = new MaterialAlertDialogBuilder(this)
|
||||
.setTitle(NextcloudFilesAppAccountNotFoundException.class.getSimpleName())
|
||||
.setMessage(R.string.backup)
|
||||
.setPositiveButton(R.string.simple_backup, (a, b) -> executor.submit(() -> {
|
||||
final var modifiedNotes = new LinkedList<Note>();
|
||||
for (final var account : mainViewModel.getAccounts()) {
|
||||
modifiedNotes.addAll(mainViewModel.getLocalModifiedNotes(account.getId()));
|
||||
}
|
||||
if (modifiedNotes.size() == 1) {
|
||||
final var note = modifiedNotes.get(0);
|
||||
ShareUtil.openShareDialog(this, note.getTitle(), note.getContent());
|
||||
} else {
|
||||
ShareUtil.openShareDialog(this,
|
||||
getResources().getQuantityString(R.plurals.share_multiple, modifiedNotes.size(), modifiedNotes.size()),
|
||||
mainViewModel.collectNoteContents(modifiedNotes.stream().map(Note::getId).collect(Collectors.toList())));
|
||||
}
|
||||
}))
|
||||
.setNegativeButton(R.string.simple_error, (a, b) -> {
|
||||
final var ssoPreferences = AccountImporter.getSharedPreferences(getApplicationContext());
|
||||
final var ssoPreferencesString = new StringBuilder()
|
||||
.append("Current SSO account: ").append(ssoPreferences.getString("PREF_CURRENT_ACCOUNT_STRING", null)).append("\n")
|
||||
.append("\n")
|
||||
.append("SSO SharedPreferences: ").append("\n");
|
||||
for (final var entry : ssoPreferences.getAll().entrySet()) {
|
||||
ssoPreferencesString.append(entry.getKey()).append(": ").append(entry.getValue()).append("\n");
|
||||
}
|
||||
ssoPreferencesString.append("\n")
|
||||
.append("Available accounts in DB: ").append(TextUtils.join(", ", mainViewModel.getAccounts().stream().map(Account::getAccountName).collect(Collectors.toList())));
|
||||
runOnUiThread(() -> ExceptionDialogFragment.newInstance(new RuntimeException(e.getMessage(), new RuntimeException(ssoPreferencesString.toString(), e))).show(getSupportFragmentManager(), ExceptionDialogFragment.class.getSimpleName()));
|
||||
});
|
||||
|
||||
NotesApplication.brandingUtil().dialog.colorMaterialAlertDialogBackground(this, alertDialogBuilder);
|
||||
|
||||
alertDialogBuilder.show();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
final var accountLiveData = mainViewModel.getCurrentAccount();
|
||||
|
|
|
@ -147,7 +147,7 @@ public class ManageAccountsActivity extends LockedActivity implements IManageAcc
|
|||
|
||||
binding.inputWrapper.setHint(title);
|
||||
|
||||
MaterialAlertDialogBuilder alertDialogBuilder = new MaterialAlertDialogBuilder(this)
|
||||
final MaterialAlertDialogBuilder alertDialogBuilder = new MaterialAlertDialogBuilder(this)
|
||||
.setTitle(title)
|
||||
.setMessage(message)
|
||||
.setView(binding.getRoot())
|
||||
|
|
Loading…
Reference in a new issue