Cherish: Enable lockscreen weather options properly

Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
Signed-off-by: Hưng Phan <phandinhhungvp2001@gmail.com>
This commit is contained in:
Pranav Vashi
2023-04-26 23:57:16 +05:30
committed by Hưng Phan
parent 05c66c10b7
commit db0e4181c3

View File

@@ -74,6 +74,7 @@ public class LockScreenSettings extends SettingsPreferenceFragment implements
private ListPreference mLockClockStyles; private ListPreference mLockClockStyles;
private OmniJawsClient mWeatherClient;
private Preference mWeather; private Preference mWeather;
private PreferenceCategory mUdfpsCategory; private PreferenceCategory mUdfpsCategory;
private Context mContext; private Context mContext;
@@ -132,17 +133,8 @@ public class LockScreenSettings extends SettingsPreferenceFragment implements
} }
mWeather = (Preference) findPreference(KEY_WEATHER); mWeather = (Preference) findPreference(KEY_WEATHER);
OmniJawsClient weatherClient = new OmniJawsClient(getContext()); mWeatherClient = new OmniJawsClient(getContext());
boolean weatherEnabled = weatherClient.isOmniJawsEnabled(); updateWeatherSettings();
if (!weatherEnabled) {
mWeather.setEnabled(false);
mWeather.setSummary(R.string.lockscreen_weather_enabled_info);
}
}
@Override
public void onResume() {
super.onResume();
} }
public boolean onPreferenceChange(Preference preference, Object newValue) { public boolean onPreferenceChange(Preference preference, Object newValue) {
@@ -165,15 +157,25 @@ public class LockScreenSettings extends SettingsPreferenceFragment implements
Settings.System.putInt(getActivity().getContentResolver(), Settings.System.putInt(getActivity().getContentResolver(),
Settings.System.FP_ERROR_VIBRATE, value ? 1 : 0); Settings.System.FP_ERROR_VIBRATE, value ? 1 : 0);
return true; return true;
} else if (preference == mWeather) {
boolean value = (Boolean) newValue;
Settings.System.putInt(getActivity().getContentResolver(),
Settings.System.LOCKSCREEN_WEATHER_ENABLED, value ? 0 : 0);
return true;
} }
return false; return false;
} }
private void updateWeatherSettings() {
if (mWeatherClient == null || mWeather == null) return;
boolean weatherEnabled = mWeatherClient.isOmniJawsEnabled();
mWeather.setEnabled(weatherEnabled);
mWeather.setSummary(weatherEnabled ? R.string.lockscreen_weather_summary :
R.string.lockscreen_weather_enabled_info);
}
@Override
public void onResume() {
super.onResume();
updateWeatherSettings();
}
@Override @Override
public int getMetricsCategory() { public int getMetricsCategory() {
return MetricsProto.MetricsEvent.CHERISH_SETTINGS; return MetricsProto.MetricsEvent.CHERISH_SETTINGS;