diff options
author | Stefan Niedermann <info@niedermann.it> | 2020-04-17 18:13:06 +0300 |
---|---|---|
committer | Stefan Niedermann <info@niedermann.it> | 2020-04-17 18:13:06 +0300 |
commit | b71ea521c703dd11c6e1e0f8d056a811b7115735 (patch) | |
tree | 5bc6f674fc3c338930e4caf7dfa3134597b8e4d2 /app | |
parent | b19c751d70b65a3564e686de4366745091a7822c (diff) |
#317 Adjust theme for each account
Rewrite branding strategy
Signed-off-by: Stefan Niedermann <info@niedermann.it>
Diffstat (limited to 'app')
25 files changed, 228 insertions, 337 deletions
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 1afa1dbe1..432c2da98 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -19,7 +19,7 @@ android:requestLegacyExternalStorage="true" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" - android:theme="@style/LightThemeDarkBrand" + android:theme="@style/AppTheme" tools:ignore="GoogleAppIndexingWarning" tools:targetApi="q"> @@ -60,7 +60,7 @@ android:name=".ui.card.EditActivity" android:label="@string/edit" android:parentActivityName="it.niedermann.nextcloud.deck.ui.MainActivity" - android:theme="@style/LightThemeDarkBrand" /> + android:theme="@style/AppTheme" /> <activity android:name=".ui.attachments.AttachmentsActivity" @@ -71,28 +71,28 @@ android:name=".ui.settings.SettingsActivity" android:label="@string/simple_settings" android:parentActivityName="it.niedermann.nextcloud.deck.ui.MainActivity" - android:theme="@style/LightThemeDarkBrand" /> + android:theme="@style/AppTheme" /> <activity android:name=".ui.ImportAccountActivity" android:label="@string/app_name" - android:theme="@style/LightThemeDarkBrand" /> + android:theme="@style/AppTheme" /> <activity android:name=".ui.preparecreate.PrepareCreateActivity" android:label="@string/simple_select" - android:theme="@style/LightThemeDarkBrand" /> + android:theme="@style/AppTheme" /> <activity android:name=".ui.about.AboutActivity" android:label="@string/about" android:parentActivityName="it.niedermann.nextcloud.deck.ui.MainActivity" - android:theme="@style/LightThemeDarkBrand" /> + android:theme="@style/AppTheme" /> <activity android:name=".ui.PushNotificationActivity" android:label="@string/app_name" - android:theme="@style/LightThemeDarkBrand"> + android:theme="@style/AppTheme"> <intent-filter> <action android:name="android.intent.action.MAIN"/> </intent-filter> diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/Application.java b/app/src/main/java/it/niedermann/nextcloud/deck/Application.java index f05fdef5f..7155fe6ef 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/Application.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/Application.java @@ -2,15 +2,13 @@ package it.niedermann.nextcloud.deck; import android.content.Context; import android.content.SharedPreferences; +import android.graphics.Color; import androidx.annotation.ColorInt; import androidx.annotation.NonNull; import androidx.preference.PreferenceManager; -import java.util.ArrayList; -import java.util.List; - -import it.niedermann.nextcloud.deck.ui.branding.Branded; +import it.niedermann.nextcloud.deck.ui.branding.BrandedActivity; import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_NO; import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_YES; @@ -23,21 +21,12 @@ public class Application extends android.app.Application { public static final long NO_BOARD_ID = -1L; public static final long NO_STACK_ID = -1L; - private static boolean brandingEnabled; - - @NonNull - private static List<Branded> brandedComponents = new ArrayList<>(); + private static boolean brandingEnabled = false; @Override public void onCreate() { setAppTheme(getAppTheme(getApplicationContext())); - brandingEnabled = getApplicationContext().getResources().getBoolean(R.bool.enable_brand); - if (brandingEnabled) { - @ColorInt final int mainColor = readBrandMainColor(getApplicationContext()); - @ColorInt final int textColor = readBrandTextColor(getApplicationContext()); - applyBrand(mainColor, textColor); - } super.onCreate(); } @@ -68,57 +57,42 @@ public class Application extends android.app.Application { // Branding // -------- - public static void registerBrandedComponent(@NonNull Context context, @NonNull Branded brandedComponent) { - if (brandingEnabled && !brandedComponents.contains(brandedComponent)) { - brandedComponents.add(brandedComponent); - - @ColorInt final int mainColor = readBrandMainColor(context); - @ColorInt final int textColor = readBrandTextColor(context); - brandedComponent.applyBrand(mainColor, textColor); - } - } - - public static void deregisterBrandedComponent(@NonNull Branded brandedComponent) { - brandedComponents.remove(brandedComponent); - } - - public static void setBrand(@NonNull Context context, @ColorInt int mainColor, @ColorInt int textColor) { - @ColorInt final int currentMainColor = readBrandMainColor(context); - @ColorInt final int currentTextColor = readBrandTextColor(context); - if (mainColor != currentMainColor || textColor != currentTextColor) { - if (brandingEnabled) { - applyBrand(mainColor, textColor); - } - saveBrandColors(context, mainColor, textColor); - } - } - - public static void applyBrand(@ColorInt int mainColor, @ColorInt int textColor) { - for (Branded themableComponent : brandedComponents) { - themableComponent.applyBrand(mainColor, textColor); - } + public static boolean isBrandingEnabled(@NonNull Context context) { + return context.getApplicationContext().getResources().getBoolean(R.bool.enable_brand); } @ColorInt public static int readBrandMainColor(@NonNull Context context) { - SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context.getApplicationContext()); - DeckLog.log("--- Read: shared_preference_theme_main"); - return sharedPreferences.getInt(context.getString(R.string.shared_preference_theme_main), context.getApplicationContext().getResources().getColor(R.color.primary)); + if (Application.isBrandingEnabled(context)) { + SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context.getApplicationContext()); + DeckLog.log("--- Read: shared_preference_theme_main"); + return sharedPreferences.getInt(context.getString(R.string.shared_preference_theme_main), context.getApplicationContext().getResources().getColor(R.color.primary)); + } else { + return context.getResources().getColor(R.color.primary); + } } @ColorInt public static int readBrandTextColor(@NonNull Context context) { - SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context.getApplicationContext()); - DeckLog.log("--- Read: shared_preference_theme_text"); - return sharedPreferences.getInt(context.getString(R.string.shared_preference_theme_text), context.getApplicationContext().getResources().getColor(android.R.color.white)); + if (isBrandingEnabled(context)) { + SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context.getApplicationContext()); + DeckLog.log("--- Read: shared_preference_theme_text"); + return sharedPreferences.getInt(context.getString(R.string.shared_preference_theme_text), context.getApplicationContext().getResources().getColor(android.R.color.white)); + } else { + return Color.WHITE; + } } - public static void saveBrandColors(@NonNull Context context, @ColorInt int mainColor, @ColorInt int textColor) { - SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(context).edit(); + public static void saveBrandColors(@NonNull BrandedActivity activity, @ColorInt int mainColor, @ColorInt int textColor) { + if (isBrandingEnabled(activity)) { + activity.applyBrand(mainColor, textColor); + BrandedActivity.applyBrandToStatusbar(activity.getWindow(), mainColor, textColor); + } + SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(activity).edit(); DeckLog.log("--- Write: shared_preference_theme_main" + " | " + mainColor); DeckLog.log("--- Write: shared_preference_theme_text" + " | " + textColor); - editor.putInt(context.getString(R.string.shared_preference_theme_main), mainColor); - editor.putInt(context.getString(R.string.shared_preference_theme_text), textColor); + editor.putInt(activity.getString(R.string.shared_preference_theme_main), mainColor); + editor.putInt(activity.getString(R.string.shared_preference_theme_text), textColor); editor.apply(); } diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/ui/MainActivity.java b/app/src/main/java/it/niedermann/nextcloud/deck/ui/MainActivity.java index bede5efdd..8dba6e7f3 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/ui/MainActivity.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/ui/MainActivity.java @@ -90,6 +90,7 @@ import it.niedermann.nextcloud.deck.util.DrawerMenuUtil.DrawerAccountListener; import it.niedermann.nextcloud.deck.util.ExceptionUtil; import it.niedermann.nextcloud.deck.util.ViewUtil; +import static android.graphics.Color.parseColor; import static androidx.lifecycle.Transformations.switchMap; import static it.niedermann.nextcloud.deck.Application.NO_ACCOUNT_ID; import static it.niedermann.nextcloud.deck.Application.NO_BOARD_ID; @@ -151,12 +152,12 @@ public class MainActivity extends BrandedActivity implements DeleteStackListener super.onCreate(savedInstanceState); Thread.setDefaultUncaughtExceptionHandler(new ExceptionHandler(this)); - setTheme(Application.getAppTheme(this) ? R.style.DarkThemeDarkBrand : R.style.LightThemeDarkBrand); binding = ActivityMainBinding.inflate(getLayoutInflater()); headerBinding = NavHeaderMainBinding.bind(binding.navigationView.getHeaderView(0)); setContentView(binding.getRoot()); + addList = getString(R.string.add_list); addBoard = getString(R.string.add_board); accountAlreadyAdded = getString(R.string.account_already_added); @@ -309,14 +310,20 @@ public class MainActivity extends BrandedActivity implements DeleteStackListener DeckLog.info("Do not clear Glide caches, because the user currently does not have a working internet connection"); } } else DeckLog.warn("ConnectivityManager is null"); - new Thread(() -> { - syncManager.refreshCapabilities(new IResponseCallback<Capabilities>(currentAccount) { - @Override - public void onResponse(Capabilities response) { - runOnUiThread(() -> Application.setBrand(MainActivity.this, Color.parseColor(response.getColor()), Color.parseColor(response.getTextColor()))); - } - }); - }).start(); + new Thread(() -> syncManager.refreshCapabilities(new IResponseCallback<Capabilities>(currentAccount) { + @Override + public void onResponse(Capabilities response) { + runOnUiThread(() -> { + @ColorInt final int mainColor = parseColor(response.getColor()); + @ColorInt final int textColor = parseColor(response.getTextColor()); + if (currentAccount != null) { + currentAccount.setColor(response.getColor()); + currentAccount.setTextColor(response.getTextColor()); + } + Application.saveBrandColors(MainActivity.this, mainColor, textColor); + }); + } + })).start(); syncManager.synchronize(new IResponseCallback<Boolean>(currentAccount) { @Override public void onResponse(Boolean response) { @@ -340,8 +347,6 @@ public class MainActivity extends BrandedActivity implements DeleteStackListener @Override public void applyBrand(@ColorInt int mainColor, @ColorInt int textColor) { - super.applyBrand(mainColor, textColor); - applyBrandToPrimaryToolbar(mainColor, textColor, binding.toolbar); applyBrandToPrimaryTabLayout(mainColor, textColor, binding.stackTitles); applyBrandToFAB(mainColor, textColor, binding.fab); @@ -426,7 +431,7 @@ public class MainActivity extends BrandedActivity implements DeleteStackListener protected void setCurrentAccount(@NonNull Account account) { this.currentAccount = account; SingleAccountHelper.setCurrentAccount(getApplicationContext(), this.currentAccount.getName()); - Application.setBrand(MainActivity.this, Color.parseColor(currentAccount.getColor()), Color.parseColor(currentAccount.getTextColor())); + Application.saveBrandColors(this, Color.parseColor(currentAccount.getColor()), Color.parseColor(currentAccount.getTextColor())); syncManager = new SyncManager(this); Application.saveCurrentAccountId(this, this.currentAccount.getId()); diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/ui/about/AboutActivity.java b/app/src/main/java/it/niedermann/nextcloud/deck/ui/about/AboutActivity.java index 781826660..55eda4eb9 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/ui/about/AboutActivity.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/ui/about/AboutActivity.java @@ -11,7 +11,6 @@ import androidx.viewpager2.adapter.FragmentStateAdapter; import com.google.android.material.tabs.TabLayoutMediator; -import it.niedermann.nextcloud.deck.Application; import it.niedermann.nextcloud.deck.R; import it.niedermann.nextcloud.deck.databinding.ActivityAboutBinding; import it.niedermann.nextcloud.deck.model.Account; @@ -31,7 +30,6 @@ public class AboutActivity extends BrandedActivity { @Override protected void onCreate(Bundle savedInstanceState) { - setTheme(Application.getAppTheme(this) ? R.style.DarkThemeDarkBrand : R.style.LightThemeDarkBrand); super.onCreate(savedInstanceState); Thread.currentThread().setUncaughtExceptionHandler(new ExceptionHandler(this)); @@ -84,7 +82,6 @@ public class AboutActivity extends BrandedActivity { @Override public void applyBrand(int mainColor, int textColor) { - super.applyBrand(mainColor, textColor); applyBrandToPrimaryToolbar(mainColor, textColor, binding.toolbar); applyBrandToPrimaryTabLayout(mainColor, textColor, binding.tabLayout); } diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/ui/about/AboutFragmentLicenseTab.java b/app/src/main/java/it/niedermann/nextcloud/deck/ui/about/AboutFragmentLicenseTab.java index 7a8a8f868..f33b30ea3 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/ui/about/AboutFragmentLicenseTab.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/ui/about/AboutFragmentLicenseTab.java @@ -8,23 +8,20 @@ import android.view.View; import android.view.ViewGroup; import androidx.annotation.NonNull; -import androidx.fragment.app.Fragment; -import it.niedermann.nextcloud.deck.Application; import it.niedermann.nextcloud.deck.R; import it.niedermann.nextcloud.deck.databinding.FragmentAboutLicenseTabBinding; -import it.niedermann.nextcloud.deck.ui.branding.Branded; +import it.niedermann.nextcloud.deck.ui.branding.BrandedFragment; import static it.niedermann.nextcloud.deck.util.SpannableUtil.setTextWithURL; -public class AboutFragmentLicenseTab extends Fragment implements Branded { +public class AboutFragmentLicenseTab extends BrandedFragment { private FragmentAboutLicenseTabBinding binding; @Override public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { binding = FragmentAboutLicenseTabBinding.inflate(inflater, container, false); - Application.registerBrandedComponent(requireContext(), this); setTextWithURL(binding.aboutIconsDisclaimerAppIcon, getResources(), R.string.about_icons_disclaimer_app_icon, R.string.about_app_icon_author_link_label, R.string.url_about_icon_author); setTextWithURL(binding.aboutIconsDisclaimerMdiIcons, getResources(), R.string.about_icons_disclaimer_mdi_icons, R.string.about_icons_disclaimer_mdi, R.string.url_about_icons_disclaimer_mdi); binding.aboutAppLicenseButton.setOnClickListener((v) -> startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(getString(R.string.url_license))))); @@ -32,18 +29,6 @@ public class AboutFragmentLicenseTab extends Fragment implements Branded { } @Override - public void onResume() { - Application.registerBrandedComponent(requireContext(), this); - super.onResume(); - } - - @Override - public void onPause() { - Application.deregisterBrandedComponent(this); - super.onPause(); - } - - @Override public void applyBrand(int mainColor, int textColor) { binding.aboutAppLicenseButton.setBackgroundColor(mainColor); binding.aboutAppLicenseButton.setTextColor(textColor); diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/ui/branding/Branded.java b/app/src/main/java/it/niedermann/nextcloud/deck/ui/branding/Branded.java index 9d9d2d3db..466512017 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/ui/branding/Branded.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/ui/branding/Branded.java @@ -3,5 +3,5 @@ package it.niedermann.nextcloud.deck.ui.branding; import androidx.annotation.ColorInt; public interface Branded { - void applyBrand(@ColorInt int mainColor, @ColorInt int textColor); - }
\ No newline at end of file + void applyBrand(@ColorInt int mainColor, @ColorInt int textColor); +}
\ No newline at end of file diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/ui/branding/BrandedActivity.java b/app/src/main/java/it/niedermann/nextcloud/deck/ui/branding/BrandedActivity.java index 062825047..fcda2ca68 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/ui/branding/BrandedActivity.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/ui/branding/BrandedActivity.java @@ -5,12 +5,12 @@ import android.content.res.ColorStateList; import android.graphics.Color; import android.graphics.PorterDuff; import android.graphics.drawable.Drawable; +import android.os.Bundle; import android.view.Menu; import android.view.View; import android.view.Window; import android.widget.EditText; -import androidx.annotation.CallSuper; import androidx.annotation.ColorInt; import androidx.annotation.NonNull; import androidx.annotation.Nullable; @@ -24,6 +24,7 @@ import com.google.android.material.tabs.TabLayout; import it.niedermann.nextcloud.deck.Application; import it.niedermann.nextcloud.deck.DeckLog; import it.niedermann.nextcloud.deck.R; +import it.niedermann.nextcloud.deck.util.ColorUtil; import static android.os.Build.VERSION.SDK_INT; import static android.os.Build.VERSION_CODES.LOLLIPOP; @@ -33,47 +34,41 @@ import static it.niedermann.nextcloud.deck.util.ColorUtil.isColorDark; public abstract class BrandedActivity extends AppCompatActivity implements Branded { - /** - * Member variable needed for onCreateOptionsMenu()-callback - */ - @Nullable - @ColorInt - private Integer textColor = null; - - @Override - protected void onResume() { - super.onResume(); - Application.registerBrandedComponent(this, this); - } - @Override - protected void onPause() { - super.onPause(); - Application.deregisterBrandedComponent(this); + protected void onCreate(@Nullable Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + if (Application.isBrandingEnabled(this)) { + @ColorInt final int mainColor = Application.readBrandMainColor(this); + @ColorInt final int textColor = Application.readBrandTextColor(this); + setTheme(ColorUtil.isColorDark(textColor) ? R.style.AppThemeLightBrand : R.style.AppTheme); + applyBrandToStatusbar(getWindow(), mainColor, textColor); + } else { + setTheme(R.style.AppTheme); + } } @Override - protected void onDestroy() { - super.onDestroy(); - Application.deregisterBrandedComponent(this); - } + protected void onStart() { + super.onStart(); - @CallSuper - @Override - public void applyBrand(@ColorInt int mainColor, @ColorInt int textColor) { - this.textColor = textColor; - applyBrandToStatusbar(getWindow(), mainColor, textColor); - setTheme(isColorDark(mainColor) ? R.style.LightThemeDarkBrand : R.style.LightThemeLightBrand); + if (Application.isBrandingEnabled(this)) { + @ColorInt final int mainColor = Application.readBrandMainColor(this); + @ColorInt final int textColor = Application.readBrandTextColor(this); + applyBrand(mainColor, textColor); + } } + // TODO maybe this can be handled in R.style.AppThemLightBrand @Override public boolean onCreateOptionsMenu(Menu menu) { - if (this.textColor != null) { + if (Application.isBrandingEnabled(this)) { + @ColorInt final int textColor = Application.readBrandTextColor(this); for (int i = 0; i < menu.size(); i++) { Drawable drawable = menu.getItem(i).getIcon(); if (drawable != null) { drawable = DrawableCompat.wrap(drawable); - DrawableCompat.setTint(drawable, this.textColor); + DrawableCompat.setTint(drawable, textColor); menu.getItem(i).setIcon(drawable); } } @@ -113,7 +108,7 @@ public abstract class BrandedActivity extends AppCompatActivity implements Brand } } - protected static void applyBrandToPrimaryTabLayout(@ColorInt int mainColor, @ColorInt int textColor, @NonNull TabLayout tabLayout) { + protected void applyBrandToPrimaryTabLayout(@ColorInt int mainColor, @ColorInt int textColor, @NonNull TabLayout tabLayout) { tabLayout.setBackgroundColor(mainColor); tabLayout.setTabTextColors(textColor, textColor); tabLayout.setTabIconTint(ColorStateList.valueOf(textColor)); @@ -126,7 +121,7 @@ public abstract class BrandedActivity extends AppCompatActivity implements Brand } public static void applyBrandToEditText(@ColorInt int mainColor, @ColorInt int textColor, @NonNull EditText editText) { - @ColorInt final int finalMainColor = getColorDependingOnTheme(editText.getContext(), mainColor); + @ColorInt final int finalMainColor = getSecondaryForegroundColorDependingOnTheme(editText.getContext(), mainColor); DrawableCompat.setTintList(editText.getBackground(), new ColorStateList( new int[][]{ new int[]{android.R.attr.state_active}, @@ -150,7 +145,7 @@ public abstract class BrandedActivity extends AppCompatActivity implements Brand */ @ColorInt public static int - getColorDependingOnTheme(@NonNull Context context, @ColorInt int mainColor) { + getSecondaryForegroundColorDependingOnTheme(@NonNull Context context, @ColorInt int mainColor) { final boolean isDarkTheme = Application.getAppTheme(context); if (isDarkTheme && !contrastRatioIsSufficient(mainColor, Color.BLACK)) { DeckLog.verbose("Contrast ratio between brand color " + String.format("#%06X", (0xFFFFFF & mainColor)) + " and dark theme is too low. Falling back to WHITE as brand color."); diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/ui/branding/BrandedAlertDialogBuilder.java b/app/src/main/java/it/niedermann/nextcloud/deck/ui/branding/BrandedAlertDialogBuilder.java index e77050486..d502772b3 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/ui/branding/BrandedAlertDialogBuilder.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/ui/branding/BrandedAlertDialogBuilder.java @@ -5,6 +5,8 @@ import android.content.DialogInterface; import android.widget.Button; import androidx.annotation.CallSuper; +import androidx.annotation.ColorInt; +import androidx.annotation.NonNull; import androidx.appcompat.app.AlertDialog; import org.jetbrains.annotations.NotNull; @@ -23,7 +25,12 @@ public class BrandedAlertDialogBuilder extends AlertDialog.Builder implements Br @Override public AlertDialog create() { this.dialog = super.create(); - dialog.setOnShowListener(dialog -> Application.registerBrandedComponent(getContext(), this)); + + @NonNull Context context = getContext(); + @ColorInt final int mainColor = Application.readBrandMainColor(context); + @ColorInt final int textColor = Application.readBrandTextColor(context); + applyBrand(mainColor, textColor); + dialog.setOnShowListener(dialog -> applyBrand(mainColor, textColor)); return dialog; } @@ -36,9 +43,8 @@ public class BrandedAlertDialogBuilder extends AlertDialog.Builder implements Br buttons[2] = dialog.getButton(DialogInterface.BUTTON_NEUTRAL); for (Button button : buttons) { if (button != null) { - button.setTextColor(BrandedActivity.getColorDependingOnTheme(button.getContext(), mainColor)); + button.setTextColor(BrandedActivity.getSecondaryForegroundColorDependingOnTheme(button.getContext(), mainColor)); } } - Application.deregisterBrandedComponent(this); } } diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/ui/branding/BrandedDatePickerDialog.java b/app/src/main/java/it/niedermann/nextcloud/deck/ui/branding/BrandedDatePickerDialog.java index e515bf892..b56ad3669 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/ui/branding/BrandedDatePickerDialog.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/ui/branding/BrandedDatePickerDialog.java @@ -1,5 +1,7 @@ package it.niedermann.nextcloud.deck.ui.branding; +import android.content.Context; +import android.graphics.Color; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; @@ -7,36 +9,38 @@ import android.view.ViewGroup; import androidx.annotation.ColorInt; import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import com.wdullaer.materialdatetimepicker.date.DatePickerDialog; import java.util.Calendar; import it.niedermann.nextcloud.deck.Application; +import it.niedermann.nextcloud.deck.util.ColorUtil; public class BrandedDatePickerDialog extends DatePickerDialog implements Branded { @Override - public void applyBrand(int mainColor, int textColor) { - @ColorInt int buttonTextColor = BrandedActivity.getColorDependingOnTheme(requireContext(), mainColor); - if (buttonTextColor != mainColor) { - setOkColor(buttonTextColor); - setCancelColor(buttonTextColor); - } - setAccentColor(mainColor); - } - - @Override public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - setThemeDark(Application.getAppTheme(getContext())); - Application.registerBrandedComponent(requireContext(), this); + @Nullable Context context = getContext(); + if (context != null) { + setThemeDark(Application.getAppTheme(context)); + if (Application.isBrandingEnabled(context)) { + @ColorInt final int mainColor = Application.readBrandMainColor(context); + @ColorInt final int textColor = Application.readBrandTextColor(context); + applyBrand(mainColor, textColor); + } + } return super.onCreateView(inflater, container, savedInstanceState); } @Override - public void onDestroy() { - Application.deregisterBrandedComponent(this); - super.onDestroy(); + public void applyBrand(int mainColor, int textColor) { + @ColorInt final int buttonTextColor = BrandedActivity.getSecondaryForegroundColorDependingOnTheme(requireContext(), mainColor); + setOkColor(buttonTextColor); + setCancelColor(buttonTextColor); + // Text in picker title is always white + setAccentColor(ColorUtil.contrastRatioIsSufficient(Color.WHITE, mainColor) ? mainColor : textColor); } /** diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/ui/branding/BrandedDialogFragment.java b/app/src/main/java/it/niedermann/nextcloud/deck/ui/branding/BrandedDialogFragment.java index 8c7804def..75eb90b12 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/ui/branding/BrandedDialogFragment.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/ui/branding/BrandedDialogFragment.java @@ -1,5 +1,9 @@ package it.niedermann.nextcloud.deck.ui.branding; +import android.content.Context; + +import androidx.annotation.ColorInt; +import androidx.annotation.Nullable; import androidx.fragment.app.DialogFragment; import it.niedermann.nextcloud.deck.Application; @@ -7,14 +11,16 @@ import it.niedermann.nextcloud.deck.Application; public abstract class BrandedDialogFragment extends DialogFragment implements Branded { @Override - public void onResume() { - super.onResume(); - Application.registerBrandedComponent(requireContext(), this); - } + public void onStart() { + super.onStart(); - @Override - public void onPause() { - Application.deregisterBrandedComponent(this); - super.onPause(); + @Nullable Context context = getContext(); + if (context != null) { + if (Application.isBrandingEnabled(context)) { + @ColorInt final int mainColor = Application.readBrandMainColor(context); + @ColorInt final int textColor = Application.readBrandTextColor(context); + applyBrand(mainColor, textColor); + } + } } } diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/ui/branding/BrandedFragment.java b/app/src/main/java/it/niedermann/nextcloud/deck/ui/branding/BrandedFragment.java new file mode 100644 index 000000000..57a0c52d8 --- /dev/null +++ b/app/src/main/java/it/niedermann/nextcloud/deck/ui/branding/BrandedFragment.java @@ -0,0 +1,26 @@ +package it.niedermann.nextcloud.deck.ui.branding; + +import android.content.Context; + +import androidx.annotation.ColorInt; +import androidx.annotation.Nullable; +import androidx.fragment.app.Fragment; + +import it.niedermann.nextcloud.deck.Application; + +public abstract class BrandedFragment extends Fragment implements Branded { + + @Override + public void onStart() { + super.onStart(); + + @Nullable Context context = getContext(); + if (context != null) { + if (Application.isBrandingEnabled(context)) { + @ColorInt final int mainColor = Application.readBrandMainColor(context); + @ColorInt final int textColor = Application.readBrandTextColor(context); + applyBrand(mainColor, textColor); + } + } + } +} diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/ui/branding/BrandedSwitchPreference.java b/app/src/main/java/it/niedermann/nextcloud/deck/ui/branding/BrandedSwitchPreference.java index a2ca9e38a..f8c9b87f3 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/ui/branding/BrandedSwitchPreference.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/ui/branding/BrandedSwitchPreference.java @@ -13,11 +13,12 @@ import androidx.core.graphics.drawable.DrawableCompat; import androidx.preference.PreferenceViewHolder; import androidx.preference.SwitchPreference; +import it.niedermann.nextcloud.deck.Application; import it.niedermann.nextcloud.deck.R; import static android.os.Build.VERSION.SDK_INT; import static android.os.Build.VERSION_CODES.JELLY_BEAN; -import static it.niedermann.nextcloud.deck.ui.branding.BrandedActivity.getColorDependingOnTheme; +import static it.niedermann.nextcloud.deck.ui.branding.BrandedActivity.getSecondaryForegroundColorDependingOnTheme; public class BrandedSwitchPreference extends SwitchPreference implements Branded { @@ -50,10 +51,12 @@ public class BrandedSwitchPreference extends SwitchPreference implements Branded public void onBindViewHolder(PreferenceViewHolder holder) { super.onBindViewHolder(holder); - if (holder.itemView instanceof ViewGroup) { - switchView = findSwitchWidget(holder.itemView); - if (mainColor != null && textColor != null) { - applyBrand(); + if (Application.isBrandingEnabled(getContext())) { + if (holder.itemView instanceof ViewGroup) { + switchView = findSwitchWidget(holder.itemView); + if (mainColor != null && textColor != null) { + applyBrand(); + } } } } @@ -63,12 +66,14 @@ public class BrandedSwitchPreference extends SwitchPreference implements Branded this.mainColor = mainColor; this.textColor = textColor; // onBindViewHolder is called after applyBrand, therefore we have to store the given values and apply them later. - applyBrand(); + if (Application.isBrandingEnabled(getContext())) { + applyBrand(); + } } private void applyBrand() { if (switchView != null && SDK_INT >= JELLY_BEAN) { - final int finalMainColor = getColorDependingOnTheme(getContext(), mainColor); + final int finalMainColor = getSecondaryForegroundColorDependingOnTheme(getContext(), mainColor); // int trackColor = Color.argb(77, Color.red(finalMainColor), Color.green(finalMainColor), Color.blue(finalMainColor)); DrawableCompat.setTintList(switchView.getThumbDrawable(), new ColorStateList( new int[][]{new int[]{android.R.attr.state_checked}, new int[]{}}, diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/ui/branding/BrandedTimePickerDialog.java b/app/src/main/java/it/niedermann/nextcloud/deck/ui/branding/BrandedTimePickerDialog.java index 58d6825ec..cd67d7820 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/ui/branding/BrandedTimePickerDialog.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/ui/branding/BrandedTimePickerDialog.java @@ -1,5 +1,7 @@ package it.niedermann.nextcloud.deck.ui.branding; +import android.content.Context; +import android.graphics.Color; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; @@ -7,36 +9,38 @@ import android.view.ViewGroup; import androidx.annotation.ColorInt; import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import com.wdullaer.materialdatetimepicker.time.TimePickerDialog; import java.util.Calendar; import it.niedermann.nextcloud.deck.Application; +import it.niedermann.nextcloud.deck.util.ColorUtil; public class BrandedTimePickerDialog extends TimePickerDialog implements Branded { @Override - public void applyBrand(int mainColor, int textColor) { - @ColorInt int buttonTextColor = BrandedActivity.getColorDependingOnTheme(requireContext(), mainColor); - if (buttonTextColor != mainColor) { - setOkColor(buttonTextColor); - setCancelColor(buttonTextColor); - } - setAccentColor(mainColor); - } - - @Override public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - setThemeDark(Application.getAppTheme(getContext())); - Application.registerBrandedComponent(requireContext(), this); + @Nullable Context context = getContext(); + if (context != null) { + setThemeDark(Application.getAppTheme(context)); + if (Application.isBrandingEnabled(context)) { + @ColorInt final int mainColor = Application.readBrandMainColor(context); + @ColorInt final int textColor = Application.readBrandTextColor(context); + applyBrand(mainColor, textColor); + } + } return super.onCreateView(inflater, container, savedInstanceState); } @Override - public void onDestroy() { - Application.deregisterBrandedComponent(this); - super.onDestroy(); + public void applyBrand(int mainColor, int textColor) { + @ColorInt final int buttonTextColor = BrandedActivity.getSecondaryForegroundColorDependingOnTheme(requireContext(), mainColor); + setOkColor(buttonTextColor); + setCancelColor(buttonTextColor); + // Text in picker title is always white + setAccentColor(ColorUtil.contrastRatioIsSufficient(Color.WHITE, mainColor) ? mainColor : textColor); } /** @@ -59,6 +63,7 @@ public class BrandedTimePickerDialog extends TimePickerDialog implements Branded /** * Create a new TimePickerDialog instance with a given initial selection + * * @param callback How the parent is notified that the time is set. * @param hourOfDay The initial hour of the dialog. * @param minute The initial minute of the dialog. @@ -72,6 +77,7 @@ public class BrandedTimePickerDialog extends TimePickerDialog implements Branded /** * Create a new TimePickerDialog instance initialized to the current system time + * * @param callback How the parent is notified that the time is set. * @param is24HourMode True to render 24 hour mode, false to render AM / PM selectors. * @return a new TimePickerDialog instance. diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/ui/card/CardAdapter.java b/app/src/main/java/it/niedermann/nextcloud/deck/ui/card/CardAdapter.java index 5b603c312..5a884c5a9 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/ui/card/CardAdapter.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/ui/card/CardAdapter.java @@ -357,7 +357,7 @@ public class CardAdapter extends RecyclerView.Adapter<ItemCardViewHolder> implem @Override public void applyBrand(int mainColor, int textColor) { - this.mainColor = BrandedActivity.getColorDependingOnTheme(context, mainColor); + this.mainColor = BrandedActivity.getSecondaryForegroundColorDependingOnTheme(context, mainColor); notifyDataSetChanged(); } } diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/ui/card/EditActivity.java b/app/src/main/java/it/niedermann/nextcloud/deck/ui/card/EditActivity.java index c72c9feda..1b4348c35 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/ui/card/EditActivity.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/ui/card/EditActivity.java @@ -1,23 +1,13 @@ package it.niedermann.nextcloud.deck.ui.card; -import android.content.res.ColorStateList; import android.graphics.Color; -import android.graphics.ColorFilter; -import android.graphics.PorterDuff; -import android.graphics.drawable.Drawable; import android.os.Bundle; import android.text.Editable; import android.text.TextWatcher; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; -import android.view.View; import android.view.WindowManager; -import android.widget.EditText; - -import androidx.annotation.ColorInt; -import androidx.annotation.NonNull; -import androidx.core.graphics.drawable.DrawableCompat; import com.google.android.material.tabs.TabLayout; import com.google.android.material.tabs.TabLayoutMediator; @@ -25,7 +15,6 @@ import com.google.android.material.tabs.TabLayoutMediator; import java.util.ArrayList; import java.util.Date; -import it.niedermann.nextcloud.deck.Application; import it.niedermann.nextcloud.deck.R; import it.niedermann.nextcloud.deck.databinding.ActivityEditBinding; import it.niedermann.nextcloud.deck.model.Attachment; @@ -101,7 +90,6 @@ public class EditActivity extends BrandedActivity implements CardDetailsListener super.onCreate(savedInstanceState); Thread.currentThread().setUncaughtExceptionHandler(new ExceptionHandler(this)); - setTheme(Application.getAppTheme(this) ? R.style.DarkThemeDarkBrand : R.style.LightThemeDarkBrand); binding = ActivityEditBinding.inflate(getLayoutInflater()); setContentView(binding.getRoot()); @@ -348,40 +336,11 @@ public class EditActivity extends BrandedActivity implements CardDetailsListener @Override public void applyBrand(int mainColor, int textColor) { - super.applyBrand(mainColor, textColor); applyBrandToPrimaryToolbar(mainColor, textColor, binding.toolbar); applyBrandToPrimaryTabLayout(mainColor, textColor, binding.tabLayout); - applyBrandToTitle(textColor, binding.title); - } - - private static void applyBrandToTitle(@ColorInt int textColor, @NonNull EditText editText) { final int highlightColor = Color.argb(77, Color.red(textColor), Color.green(textColor), Color.blue(textColor)); - editText.setHighlightColor(highlightColor); - editText.setTextColor(textColor); - DrawableCompat.setTintList(editText.getBackground(), ColorStateList.valueOf(textColor)); - - final Drawable background = editText.getBackground(); - final ColorFilter oldColorFilter = DrawableCompat.getColorFilter(background); - final View.OnFocusChangeListener oldOnFocusChangeListener = editText.getOnFocusChangeListener(); - - final boolean isFocused = editText.isFocused(); - if (isFocused) { - editText.clearFocus(); - } - editText.setOnFocusChangeListener((v, hasFocus) -> { - if (hasFocus) { - editText.setHintTextColor(textColor); - editText.setTextColor(textColor); - background.setColorFilter(textColor, PorterDuff.Mode.SRC_ATOP); - } else { - background.setColorFilter(oldColorFilter); - } - if (oldOnFocusChangeListener != null) { - oldOnFocusChangeListener.onFocusChange(v, hasFocus); - } - }); - if (isFocused) { - editText.requestFocus(); - } + binding.title.setHighlightColor(highlightColor); + binding.title.setTextColor(textColor); +// DrawableCompat.setTintList(binding.title.getBackground(), ColorStateList.valueOf(textColor)); } } diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/ui/card/attachments/CardAttachmentAdapter.java b/app/src/main/java/it/niedermann/nextcloud/deck/ui/card/attachments/CardAttachmentAdapter.java index 7728eb5ca..02cfe4625 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/ui/card/attachments/CardAttachmentAdapter.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/ui/card/attachments/CardAttachmentAdapter.java @@ -30,28 +30,27 @@ import it.niedermann.nextcloud.deck.model.Account; import it.niedermann.nextcloud.deck.model.Attachment; import it.niedermann.nextcloud.deck.model.enums.DBStatus; import it.niedermann.nextcloud.deck.ui.attachments.AttachmentsActivity; -import it.niedermann.nextcloud.deck.ui.branding.Branded; -import it.niedermann.nextcloud.deck.ui.branding.BrandedActivity; import it.niedermann.nextcloud.deck.util.AttachmentUtil; import it.niedermann.nextcloud.deck.util.DateUtil; +import static it.niedermann.nextcloud.deck.Application.readBrandMainColor; import static it.niedermann.nextcloud.deck.ui.attachments.AttachmentsActivity.BUNDLE_KEY_CURRENT_ATTACHMENT_LOCAL_ID; +import static it.niedermann.nextcloud.deck.ui.branding.BrandedActivity.getSecondaryForegroundColorDependingOnTheme; import static it.niedermann.nextcloud.deck.ui.card.CardAdapter.BUNDLE_KEY_ACCOUNT_ID; import static it.niedermann.nextcloud.deck.ui.card.CardAdapter.BUNDLE_KEY_LOCAL_ID; import static it.niedermann.nextcloud.deck.ui.card.CardAdapter.NO_LOCAL_ID; import static it.niedermann.nextcloud.deck.util.ClipboardUtil.copyToClipboard; @SuppressWarnings("WeakerAccess") -public class CardAttachmentAdapter extends RecyclerView.Adapter<AttachmentViewHolder> implements Branded { +public class CardAttachmentAdapter extends RecyclerView.Adapter<AttachmentViewHolder> { public static final int VIEW_TYPE_DEFAULT = 2; public static final int VIEW_TYPE_IMAGE = 1; private final MenuInflater menuInflater; - @ColorInt private int mainColor; + @ColorInt + private int mainColor; private final Account account; - @NonNull - private final Context context; @Nullable private Long cardRemoteId = null; private final long cardLocalId; @@ -71,13 +70,12 @@ public class CardAttachmentAdapter extends RecyclerView.Adapter<AttachmentViewHo long cardLocalId ) { super(); - this.context = context; this.fragmentManager = fragmentManager; this.menuInflater = menuInflater; this.attachmentClickedListener = attachmentClickedListener; this.account = account; this.cardLocalId = cardLocalId; - this.mainColor = context.getResources().getColor(R.color.primary); + this.mainColor = getSecondaryForegroundColorDependingOnTheme(context, readBrandMainColor(context)); setHasStableIds(true); } @@ -215,10 +213,4 @@ public class CardAttachmentAdapter extends RecyclerView.Adapter<AttachmentViewHo } } } - - @Override - public void applyBrand(int mainColor, int textColor) { - this.mainColor = BrandedActivity.getColorDependingOnTheme(context, mainColor); - notifyDataSetChanged(); - } } diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/ui/card/attachments/CardAttachmentsFragment.java b/app/src/main/java/it/niedermann/nextcloud/deck/ui/card/attachments/CardAttachmentsFragment.java index 6c6c21d85..fd8e6c10e 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/ui/card/attachments/CardAttachmentsFragment.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/ui/card/attachments/CardAttachmentsFragment.java @@ -15,7 +15,6 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.annotation.RequiresApi; import androidx.core.app.SharedElementCallback; -import androidx.fragment.app.Fragment; import androidx.recyclerview.widget.GridLayoutManager; import androidx.recyclerview.widget.RecyclerView; @@ -24,14 +23,13 @@ import java.util.Date; import java.util.List; import java.util.Map; -import it.niedermann.nextcloud.deck.Application; import it.niedermann.nextcloud.deck.DeckLog; import it.niedermann.nextcloud.deck.R; import it.niedermann.nextcloud.deck.databinding.FragmentCardEditTabAttachmentsBinding; import it.niedermann.nextcloud.deck.model.Account; import it.niedermann.nextcloud.deck.model.Attachment; import it.niedermann.nextcloud.deck.persistence.sync.SyncManager; -import it.niedermann.nextcloud.deck.ui.branding.Branded; +import it.niedermann.nextcloud.deck.ui.branding.BrandedFragment; import it.niedermann.nextcloud.deck.util.FileUtils; import static it.niedermann.nextcloud.deck.ui.branding.BrandedActivity.applyBrandToFAB; @@ -43,7 +41,7 @@ import static it.niedermann.nextcloud.deck.ui.card.CardAdapter.NO_LOCAL_ID; import static it.niedermann.nextcloud.deck.ui.card.attachments.CardAttachmentAdapter.VIEW_TYPE_DEFAULT; import static it.niedermann.nextcloud.deck.ui.card.attachments.CardAttachmentAdapter.VIEW_TYPE_IMAGE; -public class CardAttachmentsFragment extends Fragment implements AttachmentDeletedListener, AttachmentClickedListener, Branded { +public class CardAttachmentsFragment extends BrandedFragment implements AttachmentDeletedListener, AttachmentClickedListener { private FragmentCardEditTabAttachmentsBinding binding; private static final int REQUEST_CODE_ADD_ATTACHMENT = 1; @@ -154,18 +152,6 @@ public class CardAttachmentsFragment extends Fragment implements AttachmentDelet } @Override - public void onResume() { - super.onResume(); - Application.registerBrandedComponent(requireContext(), this); - } - - @Override - public void onPause() { - Application.deregisterBrandedComponent(this); - super.onPause(); - } - - @Override public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == REQUEST_CODE_ADD_ATTACHMENT && resultCode == Activity.RESULT_OK) { @@ -267,8 +253,5 @@ public class CardAttachmentsFragment extends Fragment implements AttachmentDelet @Override public void applyBrand(int mainColor, int textColor) { applyBrandToFAB(mainColor, textColor, binding.fab); - if(adapter != null) { - adapter.applyBrand(mainColor, textColor); - } } } diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/ui/card/comments/CardCommentsAdapter.java b/app/src/main/java/it/niedermann/nextcloud/deck/ui/card/comments/CardCommentsAdapter.java index 9a7025848..34fdc3712 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/ui/card/comments/CardCommentsAdapter.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/ui/card/comments/CardCommentsAdapter.java @@ -34,20 +34,18 @@ import it.niedermann.nextcloud.deck.model.Account; import it.niedermann.nextcloud.deck.model.enums.DBStatus; import it.niedermann.nextcloud.deck.model.ocs.comment.DeckComment; import it.niedermann.nextcloud.deck.model.ocs.comment.Mention; -import it.niedermann.nextcloud.deck.ui.branding.Branded; -import it.niedermann.nextcloud.deck.ui.branding.BrandedActivity; import it.niedermann.nextcloud.deck.util.DateUtil; import it.niedermann.nextcloud.deck.util.ViewUtil; +import static it.niedermann.nextcloud.deck.Application.readBrandMainColor; +import static it.niedermann.nextcloud.deck.ui.branding.BrandedActivity.getSecondaryForegroundColorDependingOnTheme; import static it.niedermann.nextcloud.deck.util.ClipboardUtil.copyToClipboard; import static it.niedermann.nextcloud.deck.util.DimensionUtil.getAvatarDimension; -public class CardCommentsAdapter extends RecyclerView.Adapter<ItemCommentViewHolder> implements Branded { +public class CardCommentsAdapter extends RecyclerView.Adapter<ItemCommentViewHolder> { private int mainColor; @NonNull - private final Context context; - @NonNull private final List<DeckComment> comments = new ArrayList<>(); @NonNull private final Account account; @@ -59,12 +57,11 @@ public class CardCommentsAdapter extends RecyclerView.Adapter<ItemCommentViewHol private final FragmentManager fragmentManager; CardCommentsAdapter(@NonNull Context context, @NonNull Account account, @NonNull MenuInflater menuInflater, @NonNull CommentDeletedListener commentDeletedListener, @NonNull FragmentManager fragmentManager) { - this.context = context; this.account = account; this.menuInflater = menuInflater; this.commentDeletedListener = commentDeletedListener; this.fragmentManager = fragmentManager; - this.mainColor = context.getResources().getColor(R.color.primary); + this.mainColor = getSecondaryForegroundColorDependingOnTheme(context, readBrandMainColor(context)); setHasStableIds(true); } @@ -170,10 +167,4 @@ public class CardCommentsAdapter extends RecyclerView.Adapter<ItemCommentViewHol public int getItemCount() { return comments.size(); } - - @Override - public void applyBrand(int mainColor, int textColor) { - this.mainColor = BrandedActivity.getColorDependingOnTheme(context, mainColor); - notifyDataSetChanged(); - } } diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/ui/card/comments/CardCommentsFragment.java b/app/src/main/java/it/niedermann/nextcloud/deck/ui/card/comments/CardCommentsFragment.java index 695922f53..3a8541543 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/ui/card/comments/CardCommentsFragment.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/ui/card/comments/CardCommentsFragment.java @@ -9,15 +9,13 @@ import android.view.WindowManager; import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import androidx.fragment.app.Fragment; import java.util.Date; -import it.niedermann.nextcloud.deck.Application; import it.niedermann.nextcloud.deck.databinding.FragmentCardEditTabCommentsBinding; import it.niedermann.nextcloud.deck.model.ocs.comment.DeckComment; import it.niedermann.nextcloud.deck.persistence.sync.SyncManager; -import it.niedermann.nextcloud.deck.ui.branding.Branded; +import it.niedermann.nextcloud.deck.ui.branding.BrandedFragment; import static android.view.View.GONE; import static android.view.View.VISIBLE; @@ -27,7 +25,7 @@ import static it.niedermann.nextcloud.deck.ui.card.CardAdapter.BUNDLE_KEY_ACCOUN import static it.niedermann.nextcloud.deck.ui.card.CardAdapter.BUNDLE_KEY_CAN_EDIT; import static it.niedermann.nextcloud.deck.ui.card.CardAdapter.BUNDLE_KEY_LOCAL_ID; -public class CardCommentsFragment extends Fragment implements Branded, CommentEditedListener { +public class CardCommentsFragment extends BrandedFragment implements CommentEditedListener { private FragmentCardEditTabCommentsBinding binding; private SyncManager syncManager; @@ -119,23 +117,8 @@ public class CardCommentsFragment extends Fragment implements Branded, CommentEd } @Override - public void onResume() { - super.onResume(); - Application.registerBrandedComponent(requireContext(), this); - } - - @Override - public void onPause() { - Application.deregisterBrandedComponent(this); - super.onPause(); - } - - @Override public void applyBrand(int mainColor, int textColor) { applyBrandToEditText(mainColor, textColor, binding.message); applyBrandToFAB(mainColor, textColor, binding.fab); - if (adapter != null) { - adapter.applyBrand(mainColor, textColor); - } } } diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/ui/card/details/CardDetailsFragment.java b/app/src/main/java/it/niedermann/nextcloud/deck/ui/card/details/CardDetailsFragment.java index 6b5489e8f..dbbf98ad6 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/ui/card/details/CardDetailsFragment.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/ui/card/details/CardDetailsFragment.java @@ -18,7 +18,6 @@ import androidx.annotation.Nullable; import androidx.appcompat.app.AppCompatActivity; import androidx.core.graphics.ColorUtils; import androidx.core.graphics.drawable.DrawableCompat; -import androidx.fragment.app.Fragment; import com.google.android.material.chip.Chip; import com.google.android.material.snackbar.Snackbar; @@ -37,7 +36,6 @@ import java.util.Calendar; import java.util.Date; import java.util.Locale; -import it.niedermann.nextcloud.deck.Application; import it.niedermann.nextcloud.deck.DeckLog; import it.niedermann.nextcloud.deck.R; import it.niedermann.nextcloud.deck.databinding.FragmentCardEditTabDetailsBinding; @@ -46,8 +44,8 @@ import it.niedermann.nextcloud.deck.model.Label; import it.niedermann.nextcloud.deck.model.User; import it.niedermann.nextcloud.deck.model.full.FullCard; import it.niedermann.nextcloud.deck.persistence.sync.SyncManager; -import it.niedermann.nextcloud.deck.ui.branding.Branded; import it.niedermann.nextcloud.deck.ui.branding.BrandedDatePickerDialog; +import it.niedermann.nextcloud.deck.ui.branding.BrandedFragment; import it.niedermann.nextcloud.deck.ui.branding.BrandedTimePickerDialog; import it.niedermann.nextcloud.deck.ui.card.LabelAutoCompleteAdapter; import it.niedermann.nextcloud.deck.ui.card.UserAutoCompleteAdapter; @@ -64,7 +62,7 @@ import static it.niedermann.nextcloud.deck.ui.card.CardAdapter.BUNDLE_KEY_CAN_ED import static it.niedermann.nextcloud.deck.ui.card.CardAdapter.BUNDLE_KEY_LOCAL_ID; import static it.niedermann.nextcloud.deck.ui.card.CardAdapter.NO_LOCAL_ID; -public class CardDetailsFragment extends Fragment implements Branded, OnDateSetListener, OnTimeSetListener { +public class CardDetailsFragment extends BrandedFragment implements OnDateSetListener, OnTimeSetListener { private FragmentCardEditTabDetailsBinding binding; @@ -393,7 +391,6 @@ public class CardDetailsFragment extends Fragment implements Branded, OnDateSetL @Override public void onResume() { super.onResume(); - Application.registerBrandedComponent(requireContext(), this); // https://github.com/wdullaer/MaterialDateTimePicker#why-are-my-callbacks-lost-when-the-device-changes-orientation final DatePickerDialog dpd = (DatePickerDialog) getChildFragmentManager().findFragmentByTag(BrandedDatePickerDialog.class.getCanonicalName()); @@ -404,7 +401,6 @@ public class CardDetailsFragment extends Fragment implements Branded, OnDateSetL @Override public void onPause() { - Application.deregisterBrandedComponent(this); super.onPause(); } diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/ui/preparecreate/PrepareCreateActivity.java b/app/src/main/java/it/niedermann/nextcloud/deck/ui/preparecreate/PrepareCreateActivity.java index 7ececd17f..7be8504ac 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/ui/preparecreate/PrepareCreateActivity.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/ui/preparecreate/PrepareCreateActivity.java @@ -99,7 +99,6 @@ public class PrepareCreateActivity extends BrandedActivity { super.onCreate(savedInstanceState); Thread.setDefaultUncaughtExceptionHandler(new ExceptionHandler(this)); - setTheme(Application.getAppTheme(this) ? R.style.DarkThemeDarkBrand : R.style.LightThemeDarkBrand); brandingEnabled = getResources().getBoolean(R.bool.enable_brand); @@ -194,7 +193,7 @@ public class PrepareCreateActivity extends BrandedActivity { Account selectedAccount = accountAdapter.getItem(binding.accountSelect.getSelectedItemPosition()); if (selectedAccount != null) { - Application.setBrand(this, parseColor(selectedAccount.getColor()), parseColor(selectedAccount.getTextColor())); + applyBrand(parseColor(selectedAccount.getColor()), parseColor(selectedAccount.getTextColor())); } finish(); @@ -212,7 +211,6 @@ public class PrepareCreateActivity extends BrandedActivity { @Override public void applyBrand(int mainColor, int textColor) { - super.applyBrand(mainColor, textColor); applyBrandToPrimaryToolbar(mainColor, textColor, binding.toolbar); binding.submit.setBackgroundColor(mainColor); binding.submit.setTextColor(textColor); diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/ui/settings/SettingsActivity.java b/app/src/main/java/it/niedermann/nextcloud/deck/ui/settings/SettingsActivity.java index 9ad8ac845..363e5b46e 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/ui/settings/SettingsActivity.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/ui/settings/SettingsActivity.java @@ -4,7 +4,6 @@ import android.os.Bundle; import androidx.annotation.Nullable; -import it.niedermann.nextcloud.deck.Application; import it.niedermann.nextcloud.deck.R; import it.niedermann.nextcloud.deck.databinding.ActivitySettingsBinding; import it.niedermann.nextcloud.deck.ui.branding.BrandedActivity; @@ -16,7 +15,6 @@ public class SettingsActivity extends BrandedActivity { @Override protected void onCreate(@Nullable Bundle savedInstanceState) { - setTheme(Application.getAppTheme(this) ? R.style.DarkThemeDarkBrand : R.style.LightThemeDarkBrand); super.onCreate(savedInstanceState); Thread.currentThread().setUncaughtExceptionHandler(new ExceptionHandler(this)); @@ -40,7 +38,6 @@ public class SettingsActivity extends BrandedActivity { @Override public void applyBrand(int mainColor, int textColor) { - super.applyBrand(mainColor, textColor); applyBrandToPrimaryToolbar(mainColor, textColor, binding.toolbar); } } diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/ui/settings/SettingsFragment.java b/app/src/main/java/it/niedermann/nextcloud/deck/ui/settings/SettingsFragment.java index 5ca6aab99..a7602fcc9 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/ui/settings/SettingsFragment.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/ui/settings/SettingsFragment.java @@ -1,10 +1,10 @@ package it.niedermann.nextcloud.deck.ui.settings; import android.app.Activity; +import android.content.Context; import android.os.Bundle; -import android.view.View; -import androidx.annotation.NonNull; +import androidx.annotation.ColorInt; import androidx.annotation.Nullable; import androidx.preference.ListPreference; import androidx.preference.Preference; @@ -63,15 +63,25 @@ public class SettingsFragment extends PreferenceFragmentCompat implements Brande } @Override - public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { - super.onViewCreated(view, savedInstanceState); - Application.registerBrandedComponent(requireContext(), this); + public void onStart() { + super.onStart(); + @Nullable Context context = getContext(); + if (context != null) { + @ColorInt final int mainColor = Application.readBrandMainColor(context); + @ColorInt final int textColor = Application.readBrandTextColor(context); + applyBrand(mainColor, textColor); + } } @Override - public void onDestroy() { - Application.deregisterBrandedComponent(this); - super.onDestroy(); + public void onStop() { + @Nullable Context context = getContext(); + if (context != null) { + @ColorInt final int mainColor = Application.readBrandMainColor(context); + @ColorInt final int textColor = Application.readBrandTextColor(context); + applyBrand(mainColor, textColor); + } + super.onStop(); } @Override diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/ui/stack/StackFragment.java b/app/src/main/java/it/niedermann/nextcloud/deck/ui/stack/StackFragment.java index 690e8368a..d07629de3 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/ui/stack/StackFragment.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/ui/stack/StackFragment.java @@ -8,22 +8,20 @@ import android.view.View; import android.view.ViewGroup; import androidx.annotation.NonNull; -import androidx.fragment.app.Fragment; import androidx.recyclerview.widget.RecyclerView; import java.util.List; import it.niedermann.android.crosstabdnd.DragAndDropTab; -import it.niedermann.nextcloud.deck.Application; import it.niedermann.nextcloud.deck.databinding.FragmentStackBinding; import it.niedermann.nextcloud.deck.model.Account; import it.niedermann.nextcloud.deck.model.full.FullCard; import it.niedermann.nextcloud.deck.persistence.sync.SyncManager; -import it.niedermann.nextcloud.deck.ui.branding.Branded; +import it.niedermann.nextcloud.deck.ui.branding.BrandedFragment; import it.niedermann.nextcloud.deck.ui.card.CardAdapter; import it.niedermann.nextcloud.deck.ui.card.SelectCardListener; -public class StackFragment extends Fragment implements DragAndDropTab<CardAdapter>, Branded { +public class StackFragment extends BrandedFragment implements DragAndDropTab<CardAdapter> { private static final String KEY_BOARD_ID = "boardId"; private static final String KEY_STACK_ID = "stackId"; @@ -119,18 +117,6 @@ public class StackFragment extends Fragment implements DragAndDropTab<CardAdapte } @Override - public void onResume() { - Application.registerBrandedComponent(requireContext(), this); - super.onResume(); - } - - @Override - public void onPause() { - Application.deregisterBrandedComponent(this); - super.onPause(); - } - - @Override public CardAdapter getAdapter() { return adapter; } diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index ec16220f6..e19a6b8b0 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -1,7 +1,7 @@ <resources xmlns:tools="http://schemas.android.com/tools"> <!-- Default is a light theme with the dark blue brand --> - <style name="LightThemeDarkBrand" parent="Theme.MaterialComponents.Light.NoActionBar.Bridge"> + <style name="AppTheme" parent="Theme.MaterialComponents.DayNight.NoActionBar.Bridge"> <item name="colorPrimary">@color/primary</item> <item name="colorPrimaryDark">@color/primary</item> <item name="colorAccent">@color/primary</item> @@ -11,27 +11,14 @@ </style> <!-- This is a light theme with a bright brand color like yellow --> - <style name="LightThemeLightBrand" parent="LightThemeDarkBrand"> - <item name="editTextForegroundOnPrimaryBackground">@android:color/black</item> - </style> - - <!-- Enabled dark mode with a dark brand like the default Nextcloud blue --> - <style name="DarkThemeDarkBrand" parent="Theme.MaterialComponents.NoActionBar.Bridge"> - <item name="colorPrimary">@color/primary</item> - <item name="colorPrimaryDark">@color/primary</item> - <item name="colorAccent">@color/primary</item> - <item name="editTextForegroundOnPrimaryBackground">@android:color/white</item> - <item name="android:textColor">@color/fg_secondary</item> - <item name="android:textViewStyle">@style/DarkTextView</item> - </style> - - <!-- Enabled dark mode with a bright brand color like yellow --> - <style name="DarkThemeLightBrand" parent="DarkThemeDarkBrand"> + <style name="AppThemeLightBrand" parent="AppTheme"> <item name="editTextForegroundOnPrimaryBackground">@android:color/black</item> </style> <!-- This styles an EditText which is on a primary background like in the toolbar --> <style name="EditTextOnPrimaryBackground" parent="ThemeOverlay.MaterialComponents.Dark"> + <item name="android:textColor">?editTextForegroundOnPrimaryBackground</item> + <item name="android:textColorHighlight">?editTextForegroundOnPrimaryBackground</item> <item name="colorControlNormal">?editTextForegroundOnPrimaryBackground</item> <item name="colorControlActivated">?editTextForegroundOnPrimaryBackground</item> <item name="colorControlHighlight">?editTextForegroundOnPrimaryBackground</item> |