diff options
author | Stefan Niedermann <info@niedermann.it> | 2020-04-17 21:29:00 +0300 |
---|---|---|
committer | Stefan Niedermann <info@niedermann.it> | 2020-04-17 21:29:00 +0300 |
commit | 9ce1517b6f5a031ff93137f12fee18515c126eab (patch) | |
tree | 05e748a9df66d53361a14776c3c3de0ec1040d21 | |
parent | bfb2e2f60d7362c7e7e4cedb0889292aa48331a4 (diff) |
#317 Adjust theme for each account
11 files changed, 116 insertions, 50 deletions
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 7155fe6ef..9bd544da9 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/Application.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/Application.java @@ -21,12 +21,9 @@ 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 = false; - @Override public void onCreate() { setAppTheme(getAppTheme(getApplicationContext())); - brandingEnabled = getApplicationContext().getResources().getBoolean(R.bool.enable_brand); super.onCreate(); } @@ -58,7 +55,8 @@ public class Application extends android.app.Application { // -------- public static boolean isBrandingEnabled(@NonNull Context context) { - return context.getApplicationContext().getResources().getBoolean(R.bool.enable_brand); + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); + return prefs.getBoolean(context.getString(R.string.pref_key_branding), false); } @ColorInt diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/ui/PushNotificationActivity.java b/app/src/main/java/it/niedermann/nextcloud/deck/ui/PushNotificationActivity.java index 34d9ddd67..11d00008f 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/ui/PushNotificationActivity.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/ui/PushNotificationActivity.java @@ -9,6 +9,7 @@ import androidx.annotation.ColorInt; import androidx.annotation.NonNull; import androidx.appcompat.app.AppCompatActivity; +import it.niedermann.nextcloud.deck.Application; import it.niedermann.nextcloud.deck.DeckLog; import it.niedermann.nextcloud.deck.R; import it.niedermann.nextcloud.deck.databinding.ActivityPushNotificationBinding; @@ -54,7 +55,7 @@ public class PushNotificationActivity extends AppCompatActivity implements Brand setContentView(binding.getRoot()); setSupportActionBar(binding.toolbar); - brandingEnabled = getResources().getBoolean(R.bool.enable_brand); + brandingEnabled = Application.isBrandingEnabled(this); binding.subject.setText(getIntent().getStringExtra(KEY_SUBJECT)); 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 fcda2ca68..6278ac1f5 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 @@ -62,15 +62,13 @@ public abstract class BrandedActivity extends AppCompatActivity implements Brand // TODO maybe this can be handled in R.style.AppThemLightBrand @Override public boolean onCreateOptionsMenu(Menu menu) { - 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, textColor); - menu.getItem(i).setIcon(drawable); - } + @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, textColor); + menu.getItem(i).setIcon(drawable); } } return super.onCreateOptionsMenu(menu); diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/ui/branding/BrandedPreferenceCategory.java b/app/src/main/java/it/niedermann/nextcloud/deck/ui/branding/BrandedPreferenceCategory.java new file mode 100644 index 000000000..dd7f0a037 --- /dev/null +++ b/app/src/main/java/it/niedermann/nextcloud/deck/ui/branding/BrandedPreferenceCategory.java @@ -0,0 +1,49 @@ +package it.niedermann.nextcloud.deck.ui.branding; + +import android.content.Context; +import android.util.AttributeSet; +import android.view.View; +import android.widget.TextView; + +import androidx.annotation.ColorInt; +import androidx.annotation.Nullable; +import androidx.preference.PreferenceCategory; +import androidx.preference.PreferenceViewHolder; + +import it.niedermann.nextcloud.deck.Application; + +import static it.niedermann.nextcloud.deck.Application.readBrandMainColor; +import static it.niedermann.nextcloud.deck.ui.branding.BrandedActivity.getSecondaryForegroundColorDependingOnTheme; + +public class BrandedPreferenceCategory extends PreferenceCategory { + + @Override + public void onBindViewHolder(PreferenceViewHolder holder) { + super.onBindViewHolder(holder); + + if (Application.isBrandingEnabled(getContext())) { + final View v = holder.itemView.findViewById(android.R.id.title); + @Nullable final Context context = getContext(); + if (context != null && v instanceof TextView) { + @ColorInt final int mainColor = getSecondaryForegroundColorDependingOnTheme(context, readBrandMainColor(context)); + ((TextView) v).setTextColor(mainColor); + } + } + } + + public BrandedPreferenceCategory(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { + super(context, attrs, defStyleAttr, defStyleRes); + } + + public BrandedPreferenceCategory(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + } + + public BrandedPreferenceCategory(Context context, AttributeSet attrs) { + super(context, attrs); + } + + public BrandedPreferenceCategory(Context context) { + super(context); + } +} 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 7be8504ac..1e00352de 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 @@ -13,7 +13,6 @@ import java.util.List; import it.niedermann.nextcloud.deck.Application; import it.niedermann.nextcloud.deck.DeckLog; -import it.niedermann.nextcloud.deck.R; import it.niedermann.nextcloud.deck.databinding.ActivityPrepareCreateBinding; import it.niedermann.nextcloud.deck.model.Account; import it.niedermann.nextcloud.deck.model.Board; @@ -100,7 +99,7 @@ public class PrepareCreateActivity extends BrandedActivity { Thread.setDefaultUncaughtExceptionHandler(new ExceptionHandler(this)); - brandingEnabled = getResources().getBoolean(R.bool.enable_brand); + brandingEnabled = Application.isBrandingEnabled(this); binding = ActivityPrepareCreateBinding.inflate(getLayoutInflater()); setContentView(binding.getRoot()); 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 a7602fcc9..f531abbe1 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 @@ -21,15 +21,17 @@ public class SettingsFragment extends PreferenceFragmentCompat implements Brande private BrandedSwitchPreference wifiOnlyPref; private BrandedSwitchPreference themePref; + private BrandedSwitchPreference brandingPref; @Override public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { setPreferencesFromResource(R.xml.settings, rootKey); wifiOnlyPref = findPreference(getString(R.string.pref_key_wifi_only)); + if (wifiOnlyPref != null) { wifiOnlyPref.setOnPreferenceChangeListener((Preference preference, Object newValue) -> { - Boolean syncOnWifiOnly = (Boolean) newValue; + final Boolean syncOnWifiOnly = (Boolean) newValue; DeckLog.log("syncOnWifiOnly: " + syncOnWifiOnly); return true; }); @@ -40,7 +42,7 @@ public class SettingsFragment extends PreferenceFragmentCompat implements Brande themePref = findPreference(getString(R.string.pref_key_dark_theme)); if (themePref != null) { themePref.setOnPreferenceChangeListener((Preference preference, Object newValue) -> { - Boolean darkTheme = (Boolean) newValue; + final Boolean darkTheme = (Boolean) newValue; DeckLog.log("darkTheme: " + darkTheme); Application.setAppTheme(darkTheme); requireActivity().setResult(Activity.RESULT_OK); @@ -51,6 +53,19 @@ public class SettingsFragment extends PreferenceFragmentCompat implements Brande DeckLog.error("Could not find preference with key: \"" + getString(R.string.pref_key_dark_theme) + "\""); } + brandingPref = findPreference(getString(R.string.pref_key_branding)); + if (brandingPref != null) { + brandingPref.setOnPreferenceChangeListener((Preference preference, Object newValue) -> { + final Boolean branding = (Boolean) newValue; + DeckLog.log("branding: " + branding); + requireActivity().setResult(Activity.RESULT_OK); + requireActivity().recreate(); + return true; + }); + } else { + DeckLog.error("Could not find preference with key: \"" + getString(R.string.pref_key_dark_theme) + "\""); + } + final ListPreference backgroundSyncPref = findPreference(getString(R.string.pref_key_background_sync)); if (backgroundSyncPref != null) { backgroundSyncPref.setOnPreferenceChangeListener((Preference preference, Object newValue) -> { @@ -74,19 +89,9 @@ public class SettingsFragment extends PreferenceFragmentCompat implements Brande } @Override - 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 public void applyBrand(int mainColor, int textColor) { wifiOnlyPref.applyBrand(mainColor, textColor); themePref.applyBrand(mainColor, textColor); + brandingPref.applyBrand(mainColor, textColor); } } diff --git a/app/src/main/res/drawable/ic_format_paint_grey600_24dp.xml b/app/src/main/res/drawable/ic_format_paint_grey600_24dp.xml new file mode 100644 index 000000000..a2308a55f --- /dev/null +++ b/app/src/main/res/drawable/ic_format_paint_grey600_24dp.xml @@ -0,0 +1,5 @@ +<vector android:autoMirrored="true" android:height="24dp" + android:tint="#757575" android:viewportHeight="24.0" + android:viewportWidth="24.0" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android"> + <path android:fillColor="#FF000000" android:pathData="M18,4V3c0,-0.55 -0.45,-1 -1,-1H5c-0.55,0 -1,0.45 -1,1v4c0,0.55 0.45,1 1,1h12c0.55,0 1,-0.45 1,-1V6h1v4H9v11c0,0.55 0.45,1 1,1h2c0.55,0 1,-0.45 1,-1v-9h8V4h-3z"/> +</vector> diff --git a/app/src/main/res/values/customization.xml b/app/src/main/res/values/customization.xml index 6e7e42a47..cb39e381a 100644 --- a/app/src/main/res/values/customization.xml +++ b/app/src/main/res/values/customization.xml @@ -1,7 +1,5 @@ <?xml version="1.0" encoding="utf-8"?> <resources> - <!-- Apply the brand of the instance for each account to UI elements --> - <bool name="enable_brand">false</bool> <!-- How many avatars should be displayed in the card list view --> <integer name="max_avatar_count">3</integer> <!-- How many users should be suggested when clicking on the assigned users input field --> diff --git a/app/src/main/res/values/setup.xml b/app/src/main/res/values/setup.xml index a51735dc5..fb917ffb7 100644 --- a/app/src/main/res/values/setup.xml +++ b/app/src/main/res/values/setup.xml @@ -8,6 +8,7 @@ <string name="pref_key_wifi_only" translatable="false">wifiOnly</string> <string name="pref_key_dark_theme" translatable="false">darkTheme</string> + <string name="pref_key_branding" translatable="false">branding</string> <string name="pref_key_background_sync" translatable="false">backgroundSync</string> <string name="pref_value_background_sync_off">off</string> diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 8349d91f7..7f8bbaf99 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -88,6 +88,8 @@ <string name="error">An error appeared</string> <string name="operation_not_yet_supported">Not yet supported</string> <string name="simple_copy">copy</string> + <string name="simple_synchronization">Synchronization</string> + <string name="simple_appearance">Appearance</string> <string name="simple_error">Error</string> <string name="simple_exception">Exception</string> <string name="copied_to_clipboard">Copied to clipboard</string> @@ -129,6 +131,7 @@ <string name="simple_rename">Rename</string> <string name="simple_settings">Settings</string> <string name="settings_theme_title">Dark theme</string> + <string name="settings_branding_title">Branding</string> <string name="settings_background_sync">Background synchronization</string> <string name="pref_value_wifi_and_mobile">Sync on Wi-Fi and mobile data</string> <string name="pref_value_wifi_only">Sync only on Wi-Fi</string> diff --git a/app/src/main/res/xml/settings.xml b/app/src/main/res/xml/settings.xml index 69249ec38..0fe560a34 100644 --- a/app/src/main/res/xml/settings.xml +++ b/app/src/main/res/xml/settings.xml @@ -1,24 +1,33 @@ <?xml version="1.0" encoding="utf-8"?> -<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"> +<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:app="http://schemas.android.com/apk/res-auto"> + <it.niedermann.nextcloud.deck.ui.branding.BrandedPreferenceCategory app:title="@string/simple_synchronization"> + <it.niedermann.nextcloud.deck.ui.branding.BrandedSwitchPreference + android:defaultValue="@string/pref_value_wifi_and_mobile" + android:icon="@drawable/ic_network_wifi_grey600_24dp" + android:key="@string/pref_key_wifi_only" + android:title="@string/pref_value_wifi_only" /> - <it.niedermann.nextcloud.deck.ui.branding.BrandedSwitchPreference - android:defaultValue="@string/pref_value_wifi_and_mobile" - android:icon="@drawable/ic_network_wifi_grey600_24dp" - android:key="@string/pref_key_wifi_only" - android:title="@string/pref_value_wifi_only" /> + <ListPreference + android:defaultValue="@string/minutes_15" + android:entries="@array/background_sync_entries" + android:entryValues="@array/background_sync_values" + android:icon="@drawable/ic_sync_grey600_24dp" + android:key="@string/pref_key_background_sync" + android:summary="%s" + android:title="@string/settings_background_sync" /> + </it.niedermann.nextcloud.deck.ui.branding.BrandedPreferenceCategory> - <ListPreference - android:defaultValue="@string/minutes_15" - android:entries="@array/background_sync_entries" - android:entryValues="@array/background_sync_values" - android:icon="@drawable/ic_sync_grey600_24dp" - android:key="@string/pref_key_background_sync" - android:summary="%s" - android:title="@string/settings_background_sync" /> + <it.niedermann.nextcloud.deck.ui.branding.BrandedPreferenceCategory android:title="@string/simple_appearance"> + <it.niedermann.nextcloud.deck.ui.branding.BrandedSwitchPreference + android:defaultValue="@string/pref_value_theme_light" + android:icon="@drawable/ic_brightness_2_grey600_24dp" + android:key="@string/pref_key_dark_theme" + android:title="@string/settings_theme_title" /> - <it.niedermann.nextcloud.deck.ui.branding.BrandedSwitchPreference - android:defaultValue="@string/pref_value_theme_light" - android:icon="@drawable/ic_brightness_2_grey600_24dp" - android:key="@string/pref_key_dark_theme" - android:title="@string/settings_theme_title" /> + <it.niedermann.nextcloud.deck.ui.branding.BrandedSwitchPreference + android:icon="@drawable/ic_format_paint_grey600_24dp" + android:key="@string/pref_key_branding" + android:title="@string/settings_branding_title" /> + </it.niedermann.nextcloud.deck.ui.branding.BrandedPreferenceCategory> </PreferenceScreen> |