show dynamic colors setting only if available
This commit is contained in:
parent
7d42da8c34
commit
1f22c5f534
|
@ -1,10 +1,9 @@
|
|||
package im.conversations.android.ui.fragment.settings;
|
||||
|
||||
import android.os.Bundle;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceFragmentCompat;
|
||||
import com.google.android.material.color.DynamicColors;
|
||||
import im.conversations.android.Conversations;
|
||||
import im.conversations.android.R;
|
||||
import im.conversations.android.ui.activity.SettingsActivity;
|
||||
|
@ -16,7 +15,10 @@ public class InterfaceSettingsFragment extends PreferenceFragmentCompat {
|
|||
setPreferencesFromResource(R.xml.preferences_interface, rootKey);
|
||||
final var themePreference = findPreference("theme");
|
||||
final var dynamicColors = findPreference("dynamic_colors");
|
||||
if (themePreference != null) {
|
||||
if (themePreference == null || dynamicColors == null) {
|
||||
throw new IllegalStateException(
|
||||
"The preference resource file did not contain theme or color preferences");
|
||||
}
|
||||
themePreference.setOnPreferenceChangeListener(
|
||||
(preference, newValue) -> {
|
||||
if (newValue instanceof String) {
|
||||
|
@ -26,20 +28,13 @@ public class InterfaceSettingsFragment extends PreferenceFragmentCompat {
|
|||
}
|
||||
return true;
|
||||
});
|
||||
}
|
||||
if (dynamicColors != null) {
|
||||
dynamicColors.setVisible(DynamicColors.isDynamicColorAvailable());
|
||||
dynamicColors.setOnPreferenceChangeListener(
|
||||
new Preference.OnPreferenceChangeListener() {
|
||||
@Override
|
||||
public boolean onPreferenceChange(
|
||||
@NonNull Preference preference, Object newValue) {
|
||||
requireSettingsActivity()
|
||||
.setDynamicColors(Boolean.TRUE.equals(newValue));
|
||||
(preference, newValue) -> {
|
||||
requireSettingsActivity().setDynamicColors(Boolean.TRUE.equals(newValue));
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public SettingsActivity requireSettingsActivity() {
|
||||
final var activity = requireActivity();
|
||||
|
|
Loading…
Reference in a new issue