1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-12-26 10:35:50 +01:00

Show warning when choosing dynamic theme but dynamic colors are not supported by Android

This commit is contained in:
Arjan Schrijver 2023-08-12 10:51:56 +02:00
parent b8c3622449
commit c9bbc05674
2 changed files with 25 additions and 8 deletions

View File

@ -47,6 +47,7 @@ import androidx.preference.ListPreference;
import androidx.preference.Preference;
import androidx.preference.PreferenceFragmentCompat;
import com.google.android.material.color.DynamicColors;
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import org.slf4j.Logger;
@ -394,10 +395,7 @@ public class SettingsActivity extends AbstractSettingsActivityV2 {
amoled_black.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newVal) {
// Signal activities that the theme has changed
Intent intent = new Intent();
intent.setAction(GBApplication.ACTION_THEME_CHANGE);
LocalBroadcastManager.getInstance(requireContext()).sendBroadcast(intent);
sendThemeChangeIntent();
return true;
}
});
@ -414,10 +412,19 @@ public class SettingsActivity extends AbstractSettingsActivityV2 {
else
amoled_black.setEnabled(true);
}
// Signal activities that the theme has changed
Intent intent = new Intent();
intent.setAction(GBApplication.ACTION_THEME_CHANGE);
LocalBroadcastManager.getInstance(requireContext()).sendBroadcast(intent);
// Warn user if dynamic colors are not available
if (val.equals(requireContext().getString(R.string.pref_theme_value_dynamic)) && !DynamicColors.isDynamicColorAvailable()) {
new MaterialAlertDialogBuilder(requireContext())
.setTitle(R.string.warning)
.setMessage(R.string.pref_theme_dynamic_colors_not_available_warning)
.setIcon(R.drawable.ic_warning)
.setPositiveButton(R.string.ok, (dialog, whichButton) -> {
sendThemeChangeIntent();
})
.show();
} else {
sendThemeChangeIntent();
}
return true;
}
});
@ -562,5 +569,14 @@ public class SettingsActivity extends AbstractSettingsActivityV2 {
.putString("location_longitude", longitude)
.apply();
}
/**
* Signal running activities that the theme has changed
*/
private void sendThemeChangeIntent() {
Intent intent = new Intent();
intent.setAction(GBApplication.ACTION_THEME_CHANGE);
LocalBroadcastManager.getInstance(requireContext()).sendBroadcast(intent);
}
}
}

View File

@ -2227,4 +2227,5 @@
<string name="pref_activity_full_sync_trigger_summary">Trigger a full sync of all activity data</string>
<string name="pref_activity_full_sync_trigger_title">Full sync</string>
<string name="pref_activity_full_sync_trigger_warning">This will trigger a full sync of all activity data from the device. It may take a few minutes to complete.</string>
<string name="pref_theme_dynamic_colors_not_available_warning">Dynamic colors are not available on your device, only Android 12+ supports this functionality. Gadgetbridge will use the default Material 3 colors.</string>
</resources>