From 2780811a79055a3a2e2e7f9893e7653ca43fc212 Mon Sep 17 00:00:00 2001 From: alperozturk Date: Mon, 22 Jul 2024 14:47:02 +0200 Subject: [PATCH 01/13] Add static BrandingUtil instance Signed-off-by: alperozturk --- .../it/niedermann/owncloud/notes/NotesApplication.java | 7 +++++++ .../niedermann/owncloud/notes/branding/BrandingUtil.java | 8 ++++++++ 2 files changed, 15 insertions(+) diff --git a/app/src/main/java/it/niedermann/owncloud/notes/NotesApplication.java b/app/src/main/java/it/niedermann/owncloud/notes/NotesApplication.java index e93e587cc..d6a6b095a 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/NotesApplication.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/NotesApplication.java @@ -20,6 +20,7 @@ import androidx.appcompat.app.AppCompatDelegate; +import it.niedermann.owncloud.notes.branding.BrandingUtil; import it.niedermann.owncloud.notes.preferences.DarkModeSetting; public class NotesApplication extends Application { @@ -31,6 +32,7 @@ public class NotesApplication extends Application { private static long lastInteraction = 0; private static String PREF_KEY_THEME; private static boolean isGridViewEnabled = false; + private static BrandingUtil brandingUtil; @Override public void onCreate() { @@ -40,11 +42,16 @@ public void onCreate() { lockedPreference = prefs.getBoolean(getString(R.string.pref_key_lock), false); isGridViewEnabled = getDefaultSharedPreferences(this).getBoolean(getString(R.string.pref_key_gridview), false); super.onCreate(); + brandingUtil = BrandingUtil.getInstance(this); if (BuildConfig.DEBUG) { WebView.setWebContentsDebuggingEnabled(true); } } + public static BrandingUtil brandingUtil() { + return brandingUtil; + } + public static void setAppTheme(DarkModeSetting setting) { AppCompatDelegate.setDefaultNightMode(setting.getModeId()); } diff --git a/app/src/main/java/it/niedermann/owncloud/notes/branding/BrandingUtil.java b/app/src/main/java/it/niedermann/owncloud/notes/branding/BrandingUtil.java index d42ce8e01..71b0311be 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/branding/BrandingUtil.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/branding/BrandingUtil.java @@ -54,6 +54,14 @@ private BrandingUtil( this.notes = new NotesViewThemeUtils(schemes); } + public static BrandingUtil getInstance(@NonNull Context context) { + int color = BrandingUtil.readBrandMainColor(context); + return new BrandingUtil( + MaterialSchemes.Companion.fromColor(color), + new com.nextcloud.android.common.ui.color.ColorUtil(context) + ); + } + public static BrandingUtil of(@ColorInt int color, @NonNull Context context) { return CACHE.computeIfAbsent(color, c -> new BrandingUtil( MaterialSchemes.Companion.fromColor(c), From e7eda9bbbeeb1fcfb5737aab34b1acbdd3bfb1c3 Mon Sep 17 00:00:00 2001 From: alperozturk Date: Mon, 22 Jul 2024 15:09:34 +0200 Subject: [PATCH 02/13] Add colors Signed-off-by: alperozturk --- app/src/main/res/values/colors.xml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index ce764c365..3f2301a3a 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -41,4 +41,6 @@ #ddffffff #222222 + #000000 + #ffffff From 43c0e3dbc35cec18d1f7f496b82fa9f7d5b2fd44 Mon Sep 17 00:00:00 2001 From: alperozturk Date: Mon, 22 Jul 2024 15:10:06 +0200 Subject: [PATCH 03/13] Use branding color for account switcher dialog Signed-off-by: alperozturk --- .../notes/accountswitcher/AccountSwitcherDialog.java | 11 ++++++++--- app/src/main/res/layout/dialog_account_switcher.xml | 2 ++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/it/niedermann/owncloud/notes/accountswitcher/AccountSwitcherDialog.java b/app/src/main/java/it/niedermann/owncloud/notes/accountswitcher/AccountSwitcherDialog.java index 31876116f..323b18ee2 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/accountswitcher/AccountSwitcherDialog.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/accountswitcher/AccountSwitcherDialog.java @@ -7,6 +7,7 @@ */ package it.niedermann.owncloud.notes.accountswitcher; + import android.app.Dialog; import android.content.Context; import android.content.Intent; @@ -21,6 +22,7 @@ import com.bumptech.glide.request.RequestOptions; 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; @@ -107,9 +109,12 @@ public Dialog onCreateDialog(Bundle savedInstanceState) { dismiss(); }); - return new MaterialAlertDialogBuilder(requireContext()) - .setView(binding.getRoot()) - .create(); + MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(requireContext()) + .setView(binding.getRoot()); + + NotesApplication.brandingUtil().dialog.colorMaterialAlertDialogBackground(requireContext(), builder); + + return builder.create(); } public static DialogFragment newInstance(long currentAccountId) { diff --git a/app/src/main/res/layout/dialog_account_switcher.xml b/app/src/main/res/layout/dialog_account_switcher.xml index 97c923145..f033c98f4 100644 --- a/app/src/main/res/layout/dialog_account_switcher.xml +++ b/app/src/main/res/layout/dialog_account_switcher.xml @@ -101,6 +101,7 @@ android:contentDescription="@null" android:focusable="false" android:scaleType="center" + app:tint="@color/black" app:srcCompat="@drawable/ic_person_add_grey600_24dp" /> Date: Mon, 22 Jul 2024 15:14:57 +0200 Subject: [PATCH 04/13] Use correct fg colors Signed-off-by: alperozturk --- app/src/main/res/layout/dialog_account_switcher.xml | 4 ++-- app/src/main/res/values/colors.xml | 2 -- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/app/src/main/res/layout/dialog_account_switcher.xml b/app/src/main/res/layout/dialog_account_switcher.xml index f033c98f4..76b3a9a6d 100644 --- a/app/src/main/res/layout/dialog_account_switcher.xml +++ b/app/src/main/res/layout/dialog_account_switcher.xml @@ -101,7 +101,7 @@ android:contentDescription="@null" android:focusable="false" android:scaleType="center" - app:tint="@color/black" + app:tint="@color/fg_default" app:srcCompat="@drawable/ic_person_add_grey600_24dp" /> #ddffffff #222222 - #000000 - #ffffff From 4738872f773657df7041d52a9c2b7c4a4f156e25 Mon Sep 17 00:00:00 2001 From: alperozturk Date: Mon, 22 Jul 2024 15:37:42 +0200 Subject: [PATCH 05/13] Use brandingUtil Signed-off-by: alperozturk --- .../notes/manageaccounts/ManageAccountsActivity.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/it/niedermann/owncloud/notes/manageaccounts/ManageAccountsActivity.java b/app/src/main/java/it/niedermann/owncloud/notes/manageaccounts/ManageAccountsActivity.java index 12dda8d76..1dd1905ab 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/manageaccounts/ManageAccountsActivity.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/manageaccounts/ManageAccountsActivity.java @@ -28,6 +28,7 @@ import java.util.function.Function; import it.niedermann.owncloud.notes.LockedActivity; +import it.niedermann.owncloud.notes.NotesApplication; import it.niedermann.owncloud.notes.R; import it.niedermann.owncloud.notes.branding.BrandingUtil; import it.niedermann.owncloud.notes.branding.DeleteAlertDialogBuilder; @@ -146,7 +147,7 @@ private void changeAccountSetting(@NonNull Account localAccount, @StringRes int binding.inputWrapper.setHint(title); - final var dialog = new MaterialAlertDialogBuilder(this) + MaterialAlertDialogBuilder alertDialogBuilder = new MaterialAlertDialogBuilder(this) .setTitle(title) .setMessage(message) .setView(binding.getRoot()) @@ -176,8 +177,13 @@ public void onFailure(@NonNull Call call, @NonNull Throwable t) { ExceptionDialogFragment.newInstance(e).show(getSupportFragmentManager(), ExceptionDialogFragment.class.getSimpleName()); } }); - }) - .show(); + }); + + NotesApplication.brandingUtil().dialog.colorMaterialAlertDialogBackground(this, alertDialogBuilder); + + var dialog = alertDialogBuilder.create(); + alertDialogBuilder.show(); + try { repository.getServerSettings(AccountImporter.getSingleSignOnAccount(this, localAccount.getAccountName()), getPreferredApiVersion(localAccount.getApiVersion())) .enqueue(new Callback<>() { From 94f1617031318be7f0e140a52a9a55eca1682c5b Mon Sep 17 00:00:00 2001 From: alperozturk Date: Mon, 22 Jul 2024 15:47:08 +0200 Subject: [PATCH 06/13] Use brandingUtil for MaterialAlertDialogs Signed-off-by: alperozturk --- .../AccountPickerDialogFragment.java | 7 +- .../AccountSwitcherDialog.java | 2 +- .../edit/category/CategoryDialogFragment.java | 10 ++- .../edit/title/EditTitleDialogFragment.java | 10 ++- .../exception/ExceptionDialogFragment.java | 10 ++- .../owncloud/notes/main/MainActivity.java | 70 +++++++++++-------- .../ManageAccountsActivity.java | 2 +- 7 files changed, 67 insertions(+), 44 deletions(-) diff --git a/app/src/main/java/it/niedermann/owncloud/notes/accountpicker/AccountPickerDialogFragment.java b/app/src/main/java/it/niedermann/owncloud/notes/accountpicker/AccountPickerDialogFragment.java index 75fb39e54..9f9a11ee7 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/accountpicker/AccountPickerDialogFragment.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/accountpicker/AccountPickerDialogFragment.java @@ -27,6 +27,7 @@ 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 void onAttach(@NonNull Context context) { @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 Dialog onCreateDialog(Bundle savedInstanceState) { dialogBuilder.setMessage(getString(R.string.no_other_accounts)); } + NotesApplication.brandingUtil().dialog.colorMaterialAlertDialogBackground(requireContext(), dialogBuilder); + return dialogBuilder.create(); } diff --git a/app/src/main/java/it/niedermann/owncloud/notes/accountswitcher/AccountSwitcherDialog.java b/app/src/main/java/it/niedermann/owncloud/notes/accountswitcher/AccountSwitcherDialog.java index 323b18ee2..3c9e4e20f 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/accountswitcher/AccountSwitcherDialog.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/accountswitcher/AccountSwitcherDialog.java @@ -109,7 +109,7 @@ public Dialog onCreateDialog(Bundle savedInstanceState) { dismiss(); }); - MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(requireContext()) + final MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(requireContext()) .setView(binding.getRoot()); NotesApplication.brandingUtil().dialog.colorMaterialAlertDialogBackground(requireContext(), builder); diff --git a/app/src/main/java/it/niedermann/owncloud/notes/edit/category/CategoryDialogFragment.java b/app/src/main/java/it/niedermann/owncloud/notes/edit/category/CategoryDialogFragment.java index 500a5bcfb..ebc0c73bd 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/edit/category/CategoryDialogFragment.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/edit/category/CategoryDialogFragment.java @@ -24,6 +24,7 @@ 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 void afterTextChanged(Editable s) { } }); - 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 diff --git a/app/src/main/java/it/niedermann/owncloud/notes/edit/title/EditTitleDialogFragment.java b/app/src/main/java/it/niedermann/owncloud/notes/edit/title/EditTitleDialogFragment.java index 55b3bddb3..c657912c7 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/edit/title/EditTitleDialogFragment.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/edit/title/EditTitleDialogFragment.java @@ -17,6 +17,7 @@ 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 Dialog onCreateDialog(@Nullable Bundle savedInstanceState) { 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 diff --git a/app/src/main/java/it/niedermann/owncloud/notes/exception/ExceptionDialogFragment.java b/app/src/main/java/it/niedermann/owncloud/notes/exception/ExceptionDialogFragment.java index 4a6d1e876..4f5e15aa3 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/exception/ExceptionDialogFragment.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/exception/ExceptionDialogFragment.java @@ -22,6 +22,7 @@ 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 Dialog onCreateDialog(Bundle savedInstanceState) { 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 exceptions) { diff --git a/app/src/main/java/it/niedermann/owncloud/notes/main/MainActivity.java b/app/src/main/java/it/niedermann/owncloud/notes/main/MainActivity.java index f06641543..5e2e60c0a 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/main/MainActivity.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/main/MainActivity.java @@ -71,6 +71,7 @@ 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 @@ protected void onCreate(Bundle savedInstanceState) { 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(); - 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 void onError(@NonNull Throwable t) { }); } + 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(); + 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(); diff --git a/app/src/main/java/it/niedermann/owncloud/notes/manageaccounts/ManageAccountsActivity.java b/app/src/main/java/it/niedermann/owncloud/notes/manageaccounts/ManageAccountsActivity.java index 1dd1905ab..30e8199f9 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/manageaccounts/ManageAccountsActivity.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/manageaccounts/ManageAccountsActivity.java @@ -147,7 +147,7 @@ private void changeAccountSetting(@NonNull Account localAccount, @StringRes int binding.inputWrapper.setHint(title); - MaterialAlertDialogBuilder alertDialogBuilder = new MaterialAlertDialogBuilder(this) + final MaterialAlertDialogBuilder alertDialogBuilder = new MaterialAlertDialogBuilder(this) .setTitle(title) .setMessage(message) .setView(binding.getRoot()) From dbfaffa445c70c58ec0173f81e0b6a2548c0d000 Mon Sep 17 00:00:00 2001 From: alperozturk Date: Mon, 22 Jul 2024 16:25:55 +0200 Subject: [PATCH 07/13] Apply correct theme Signed-off-by: alperozturk --- .../owncloud/notes/preferences/PreferencesActivity.java | 3 +-- app/src/main/res/values/styles.xml | 3 ++- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/it/niedermann/owncloud/notes/preferences/PreferencesActivity.java b/app/src/main/java/it/niedermann/owncloud/notes/preferences/PreferencesActivity.java index 723b895a4..6c7d3c90a 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/preferences/PreferencesActivity.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/preferences/PreferencesActivity.java @@ -18,14 +18,13 @@ public class PreferencesActivity extends LockedActivity { - private PreferencesViewModel viewModel; private ActivityPreferencesBinding binding; @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); - viewModel = new ViewModelProvider(this).get(PreferencesViewModel.class); + PreferencesViewModel viewModel = new ViewModelProvider(this).get(PreferencesViewModel.class); viewModel.resultCode$.observe(this, this::setResult); binding = ActivityPreferencesBinding.inflate(getLayoutInflater()); diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index c0ddd1714..8cde0df4e 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -86,7 +86,8 @@ + + \ No newline at end of file From 03156e89f849ad5dda94489502724f7ff009e752 Mon Sep 17 00:00:00 2001 From: alperozturk Date: Tue, 23 Jul 2024 10:19:31 +0200 Subject: [PATCH 09/13] Use M3 and background color for DeleteAlertDialogBuilder Signed-off-by: alperozturk --- .../branding/DeleteAlertDialogBuilder.java | 14 ++++++++------ .../ManageAccountsActivity.java | 19 +++++++++++++------ 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/it/niedermann/owncloud/notes/branding/DeleteAlertDialogBuilder.java b/app/src/main/java/it/niedermann/owncloud/notes/branding/DeleteAlertDialogBuilder.java index 8d9cdb155..1c8166b1a 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/branding/DeleteAlertDialogBuilder.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/branding/DeleteAlertDialogBuilder.java @@ -7,15 +7,14 @@ package it.niedermann.owncloud.notes.branding; import android.content.Context; -import android.content.DialogInterface; import androidx.annotation.NonNull; import androidx.appcompat.app.AlertDialog; -import androidx.core.content.ContextCompat; +import com.google.android.material.button.MaterialButton; import com.google.android.material.dialog.MaterialAlertDialogBuilder; -import it.niedermann.owncloud.notes.R; +import it.niedermann.owncloud.notes.NotesApplication; public class DeleteAlertDialogBuilder extends MaterialAlertDialogBuilder { @@ -35,9 +34,12 @@ public AlertDialog create() { } public void applyBrand() { - final var positiveButton = dialog.getButton(DialogInterface.BUTTON_POSITIVE); - if (positiveButton != null) { - positiveButton.setTextColor(ContextCompat.getColor(getContext(), R.color.danger)); + if (dialog.getButton(AlertDialog.BUTTON_POSITIVE) instanceof MaterialButton positiveButton) { + NotesApplication.brandingUtil().material.colorMaterialButtonPrimaryTonal(positiveButton); + } + + if (dialog.getButton(AlertDialog.BUTTON_NEGATIVE) instanceof MaterialButton negativeButton) { + NotesApplication.brandingUtil().material.colorMaterialButtonPrimaryBorderless(negativeButton); } } } diff --git a/app/src/main/java/it/niedermann/owncloud/notes/manageaccounts/ManageAccountsActivity.java b/app/src/main/java/it/niedermann/owncloud/notes/manageaccounts/ManageAccountsActivity.java index 30e8199f9..d6c904c5d 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/manageaccounts/ManageAccountsActivity.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/manageaccounts/ManageAccountsActivity.java @@ -95,12 +95,7 @@ public void onDelete(@NonNull Account accountToDelete) { public void onSuccess(Long unsynchronizedChangesCount) { runOnUiThread(() -> { if (unsynchronizedChangesCount > 0) { - new DeleteAlertDialogBuilder(ManageAccountsActivity.this) - .setTitle(getString(R.string.remove_account, accountToDelete.getUserName())) - .setMessage(getResources().getQuantityString(R.plurals.remove_account_message, (int) unsynchronizedChangesCount.longValue(), accountToDelete.getAccountName(), unsynchronizedChangesCount)) - .setNeutralButton(android.R.string.cancel, null) - .setPositiveButton(R.string.simple_remove, (d, l) -> viewModel.deleteAccount(accountToDelete, ManageAccountsActivity.this)) - .show(); + showDeleteAlertDialog(accountToDelete, unsynchronizedChangesCount); } else { viewModel.deleteAccount(accountToDelete, ManageAccountsActivity.this); } @@ -114,6 +109,18 @@ public void onError(@NonNull Throwable t) { }); } + private void showDeleteAlertDialog(@NonNull Account accountToDelete, Long unsynchronizedChangesCount) { + final MaterialAlertDialogBuilder alertDialogBuilder = new DeleteAlertDialogBuilder(ManageAccountsActivity.this) + .setTitle(getString(R.string.remove_account, accountToDelete.getUserName())) + .setMessage(getResources().getQuantityString(R.plurals.remove_account_message, (int) unsynchronizedChangesCount.longValue(), accountToDelete.getAccountName(), unsynchronizedChangesCount)) + .setNegativeButton(android.R.string.cancel, null) + .setPositiveButton(R.string.simple_remove, (d, l) -> viewModel.deleteAccount(accountToDelete, ManageAccountsActivity.this)); + + NotesApplication.brandingUtil().dialog.colorMaterialAlertDialogBackground(this, alertDialogBuilder); + + alertDialogBuilder.show(); + } + public void onChangeNotesPath(@NonNull Account localAccount) { changeAccountSetting(localAccount, R.string.settings_notes_path, From 4d7472f19038ab635a6b4897d980d4b1a4db9862 Mon Sep 17 00:00:00 2001 From: alperozturk Date: Tue, 23 Jul 2024 10:38:53 +0200 Subject: [PATCH 10/13] Use M3 and branding util for ExceptionActivity Signed-off-by: alperozturk --- .../owncloud/notes/exception/ExceptionActivity.java | 6 ++++++ app/src/main/res/layout/activity_exception.xml | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/it/niedermann/owncloud/notes/exception/ExceptionActivity.java b/app/src/main/java/it/niedermann/owncloud/notes/exception/ExceptionActivity.java index 0d9f4d268..4401d0b3a 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/exception/ExceptionActivity.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/exception/ExceptionActivity.java @@ -19,6 +19,7 @@ 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.ActivityExceptionBinding; import it.niedermann.owncloud.notes.exception.tips.TipsAdapter; @@ -53,6 +54,11 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { binding.copy.setOnClickListener((v) -> ClipboardUtil.copyToClipboard(this, getString(R.string.simple_exception), "```\n" + debugInfos + "\n```")); binding.close.setOnClickListener((v) -> finish()); + NotesApplication.brandingUtil().platform.themeStatusBar(this); + NotesApplication.brandingUtil().material.themeToolbar(binding.toolbar); + NotesApplication.brandingUtil().material.colorMaterialButtonPrimaryBorderless(binding.close); + NotesApplication.brandingUtil().material.colorMaterialButtonPrimaryFilled(binding.copy); + adapter.setThrowables(Collections.singletonList(throwable)); } diff --git a/app/src/main/res/layout/activity_exception.xml b/app/src/main/res/layout/activity_exception.xml index f7e26d963..dcac31e2c 100644 --- a/app/src/main/res/layout/activity_exception.xml +++ b/app/src/main/res/layout/activity_exception.xml @@ -81,7 +81,7 @@ android:orientation="horizontal" android:weightSum="1.0"> -