Use brandingUtil for MaterialAlertDialogs

Signed-off-by: alperozturk <alper_ozturk@proton.me>
This commit is contained in:
alperozturk 2024-07-22 15:47:08 +02:00 committed by Tobias Kaminsky
parent 4738872f77
commit 94f1617031
7 changed files with 67 additions and 44 deletions

View file

@ -27,6 +27,7 @@ import java.util.List;
import java.util.Objects; import java.util.Objects;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import it.niedermann.owncloud.notes.NotesApplication;
import it.niedermann.owncloud.notes.R; import it.niedermann.owncloud.notes.R;
import it.niedermann.owncloud.notes.branding.BrandedDialogFragment; import it.niedermann.owncloud.notes.branding.BrandedDialogFragment;
import it.niedermann.owncloud.notes.databinding.DialogChooseAccountBinding; import it.niedermann.owncloud.notes.databinding.DialogChooseAccountBinding;
@ -80,11 +81,11 @@ public class AccountPickerDialogFragment extends BrandedDialogFragment {
@NonNull @NonNull
@Override @Override
public Dialog onCreateDialog(Bundle savedInstanceState) { public Dialog onCreateDialog(Bundle savedInstanceState) {
final var dialogBuilder = new MaterialAlertDialogBuilder(requireActivity()) final MaterialAlertDialogBuilder dialogBuilder = new MaterialAlertDialogBuilder(requireActivity())
.setTitle(R.string.simple_move) .setTitle(R.string.simple_move)
.setNegativeButton(android.R.string.cancel, null); .setNegativeButton(android.R.string.cancel, null);
if (targetAccounts.size() > 0) { if (!targetAccounts.isEmpty()) {
final var binding = DialogChooseAccountBinding.inflate(LayoutInflater.from(requireContext())); final var binding = DialogChooseAccountBinding.inflate(LayoutInflater.from(requireContext()));
final var adapter = new AccountChooserAdapter(targetAccounts, (account -> { final var adapter = new AccountChooserAdapter(targetAccounts, (account -> {
accountPickerListener.onAccountPicked(account); accountPickerListener.onAccountPicked(account);
@ -96,6 +97,8 @@ public class AccountPickerDialogFragment extends BrandedDialogFragment {
dialogBuilder.setMessage(getString(R.string.no_other_accounts)); dialogBuilder.setMessage(getString(R.string.no_other_accounts));
} }
NotesApplication.brandingUtil().dialog.colorMaterialAlertDialogBackground(requireContext(), dialogBuilder);
return dialogBuilder.create(); return dialogBuilder.create();
} }

View file

@ -109,7 +109,7 @@ public class AccountSwitcherDialog extends BrandedDialogFragment {
dismiss(); dismiss();
}); });
MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(requireContext()) final MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(requireContext())
.setView(binding.getRoot()); .setView(binding.getRoot());
NotesApplication.brandingUtil().dialog.colorMaterialAlertDialogBackground(requireContext(), builder); NotesApplication.brandingUtil().dialog.colorMaterialAlertDialogBackground(requireContext(), builder);

View file

@ -24,6 +24,7 @@ import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import java.util.List; import java.util.List;
import it.niedermann.owncloud.notes.NotesApplication;
import it.niedermann.owncloud.notes.R; import it.niedermann.owncloud.notes.R;
import it.niedermann.owncloud.notes.branding.BrandedDialogFragment; import it.niedermann.owncloud.notes.branding.BrandedDialogFragment;
import it.niedermann.owncloud.notes.branding.BrandingUtil; 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) .setTitle(R.string.change_category_title)
.setView(dialogView) .setView(dialogView)
.setCancelable(true) .setCancelable(true)
.setPositiveButton(R.string.action_edit_save, (dialog, which) -> listener.onCategoryChosen(editCategory.getText().toString())) .setPositiveButton(R.string.action_edit_save, (dialog, which) -> listener.onCategoryChosen(editCategory.getText().toString()))
.setNegativeButton(R.string.simple_cancel, null) .setNegativeButton(R.string.simple_cancel, null);
.create();
NotesApplication.brandingUtil().dialog.colorMaterialAlertDialogBackground(requireContext(), alertDialogBuilder);
return alertDialogBuilder.create();
} }
@Override @Override

View file

@ -17,6 +17,7 @@ import androidx.fragment.app.DialogFragment;
import com.google.android.material.dialog.MaterialAlertDialogBuilder; import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import it.niedermann.owncloud.notes.NotesApplication;
import it.niedermann.owncloud.notes.R; import it.niedermann.owncloud.notes.R;
import it.niedermann.owncloud.notes.branding.BrandedDialogFragment; import it.niedermann.owncloud.notes.branding.BrandedDialogFragment;
import it.niedermann.owncloud.notes.branding.BrandingUtil; import it.niedermann.owncloud.notes.branding.BrandingUtil;
@ -59,13 +60,16 @@ public class EditTitleDialogFragment extends BrandedDialogFragment {
binding.title.setText(oldTitle); binding.title.setText(oldTitle);
} }
return new MaterialAlertDialogBuilder(requireContext()) final MaterialAlertDialogBuilder alertDialogBuilder = new MaterialAlertDialogBuilder(requireContext())
.setTitle(R.string.change_note_title) .setTitle(R.string.change_note_title)
.setView(dialogView) .setView(dialogView)
.setCancelable(true) .setCancelable(true)
.setPositiveButton(R.string.action_edit_save, (dialog, which) -> listener.onTitleEdited(binding.title.getText().toString())) .setPositiveButton(R.string.action_edit_save, (dialog, which) -> listener.onTitleEdited(binding.title.getText().toString()))
.setNegativeButton(R.string.simple_cancel, null) .setNegativeButton(R.string.simple_cancel, null);
.create();
NotesApplication.brandingUtil().dialog.colorMaterialAlertDialogBackground(requireContext(), alertDialogBuilder);
return alertDialogBuilder.create();
} }
@Override @Override

View file

@ -22,6 +22,7 @@ import java.util.ArrayList;
import it.niedermann.android.util.ClipboardUtil; import it.niedermann.android.util.ClipboardUtil;
import it.niedermann.nextcloud.exception.ExceptionUtil; import it.niedermann.nextcloud.exception.ExceptionUtil;
import it.niedermann.owncloud.notes.BuildConfig; import it.niedermann.owncloud.notes.BuildConfig;
import it.niedermann.owncloud.notes.NotesApplication;
import it.niedermann.owncloud.notes.R; import it.niedermann.owncloud.notes.R;
import it.niedermann.owncloud.notes.databinding.DialogExceptionBinding; import it.niedermann.owncloud.notes.databinding.DialogExceptionBinding;
import it.niedermann.owncloud.notes.exception.tips.TipsAdapter; import it.niedermann.owncloud.notes.exception.tips.TipsAdapter;
@ -69,12 +70,15 @@ public class ExceptionDialogFragment extends AppCompatDialogFragment {
adapter.setThrowables(throwables); adapter.setThrowables(throwables);
return new MaterialAlertDialogBuilder(requireActivity()) final MaterialAlertDialogBuilder alertDialogBuilder = new MaterialAlertDialogBuilder(requireActivity())
.setView(binding.getRoot()) .setView(binding.getRoot())
.setTitle(R.string.error_dialog_title) .setTitle(R.string.error_dialog_title)
.setPositiveButton(android.R.string.copy, (a, b) -> ClipboardUtil.copyToClipboard(requireContext(), getString(R.string.simple_exception), "```\n" + debugInfos + "\n```")) .setPositiveButton(android.R.string.copy, (a, b) -> ClipboardUtil.copyToClipboard(requireContext(), getString(R.string.simple_exception), "```\n" + debugInfos + "\n```"))
.setNegativeButton(R.string.simple_close, null) .setNegativeButton(R.string.simple_close, null);
.create();
NotesApplication.brandingUtil().dialog.colorMaterialAlertDialogBackground(requireContext(), alertDialogBuilder);
return alertDialogBuilder.create();
} }
public static DialogFragment newInstance(ArrayList<Throwable> exceptions) { public static DialogFragment newInstance(ArrayList<Throwable> exceptions) {

View file

@ -71,6 +71,7 @@ import java.util.stream.Collectors;
import it.niedermann.android.util.ColorUtil; import it.niedermann.android.util.ColorUtil;
import it.niedermann.owncloud.notes.LockedActivity; import it.niedermann.owncloud.notes.LockedActivity;
import it.niedermann.owncloud.notes.NotesApplication;
import it.niedermann.owncloud.notes.R; import it.niedermann.owncloud.notes.R;
import it.niedermann.owncloud.notes.accountpicker.AccountPickerListener; import it.niedermann.owncloud.notes.accountpicker.AccountPickerListener;
import it.niedermann.owncloud.notes.accountswitcher.AccountSwitcherDialog; import it.niedermann.owncloud.notes.accountswitcher.AccountSwitcherDialog;
@ -179,37 +180,7 @@ public class MainActivity extends LockedActivity implements NoteClickListener, A
runOnUiThread(() -> mainViewModel.postCurrentAccount(account)); runOnUiThread(() -> mainViewModel.postCurrentAccount(account));
} catch (NextcloudFilesAppAccountNotFoundException e) { } catch (NextcloudFilesAppAccountNotFoundException e) {
// Verbose log output for https://github.com/nextcloud/notes-android/issues/1256 // Verbose log output for https://github.com/nextcloud/notes-android/issues/1256
runOnUiThread(() -> new MaterialAlertDialogBuilder(this) runOnUiThread(() -> showExceptionAlertDialog(e));
.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());
} catch (NoCurrentAccountSelectedException e) { } catch (NoCurrentAccountSelectedException e) {
runOnUiThread(() -> ExceptionDialogFragment.newInstance(e).show(getSupportFragmentManager(), ExceptionDialogFragment.class.getSimpleName())); 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 @Override
protected void onResume() { protected void onResume() {
final var accountLiveData = mainViewModel.getCurrentAccount(); final var accountLiveData = mainViewModel.getCurrentAccount();

View file

@ -147,7 +147,7 @@ public class ManageAccountsActivity extends LockedActivity implements IManageAcc
binding.inputWrapper.setHint(title); binding.inputWrapper.setHint(title);
MaterialAlertDialogBuilder alertDialogBuilder = new MaterialAlertDialogBuilder(this) final MaterialAlertDialogBuilder alertDialogBuilder = new MaterialAlertDialogBuilder(this)
.setTitle(title) .setTitle(title)
.setMessage(message) .setMessage(message)
.setView(binding.getRoot()) .setView(binding.getRoot())