mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-12-01 14:32:54 +01:00
Upgrade charts preferences to androidx
This commit is contained in:
parent
116703adff
commit
cac41ea945
@ -1,5 +1,5 @@
|
|||||||
/* Copyright (C) 2015-2020 Andreas Shimokawa, Carsten Pfeiffer, Lem Dulfo,
|
/* Copyright (C) 2015-2023 Andreas Shimokawa, Carsten Pfeiffer, Lem Dulfo,
|
||||||
vanous
|
vanous, José Rebelo
|
||||||
|
|
||||||
This file is part of Gadgetbridge.
|
This file is part of Gadgetbridge.
|
||||||
|
|
||||||
@ -19,49 +19,57 @@ package nodomain.freeyourgadget.gadgetbridge.activities.charts;
|
|||||||
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.preference.Preference;
|
import android.text.InputType;
|
||||||
|
|
||||||
|
import androidx.fragment.app.Fragment;
|
||||||
|
import androidx.preference.Preference;
|
||||||
|
|
||||||
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
|
||||||
import nodomain.freeyourgadget.gadgetbridge.R;
|
import nodomain.freeyourgadget.gadgetbridge.R;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.activities.AboutUserPreferencesActivity;
|
import nodomain.freeyourgadget.gadgetbridge.activities.AboutUserPreferencesActivity;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.activities.AbstractSettingsActivity;
|
import nodomain.freeyourgadget.gadgetbridge.activities.AbstractGBActivity;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.activities.SettingsActivity;
|
|
||||||
import nodomain.freeyourgadget.gadgetbridge.util.GBPrefs;
|
import nodomain.freeyourgadget.gadgetbridge.util.GBPrefs;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
|
|
||||||
|
|
||||||
public class ChartsPreferencesActivity extends AbstractSettingsActivity {
|
public class ChartsPreferencesActivity extends AbstractGBActivity {
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(final Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
addPreferencesFromResource(R.xml.charts_preferences);
|
setContentView(R.layout.activity_device_settings);
|
||||||
}
|
|
||||||
@Override
|
|
||||||
protected void onPostCreate(Bundle savedInstanceState) {
|
|
||||||
super.onPostCreate(savedInstanceState);
|
|
||||||
|
|
||||||
Preference pref = findPreference("pref_category_activity_personal");
|
if (savedInstanceState == null) {
|
||||||
pref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
|
Fragment fragment = getSupportFragmentManager().findFragmentByTag(ChartsPreferencesFragment.FRAGMENT_TAG);
|
||||||
public boolean onPreferenceClick(Preference preference) {
|
if (fragment == null) {
|
||||||
Intent enableIntent = new Intent(ChartsPreferencesActivity.this, AboutUserPreferencesActivity.class);
|
fragment = new ChartsPreferencesFragment();
|
||||||
startActivity(enableIntent);
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
});
|
getSupportFragmentManager()
|
||||||
|
.beginTransaction()
|
||||||
|
.replace(R.id.settings_container, fragment, ChartsPreferencesFragment.FRAGMENT_TAG)
|
||||||
|
.commit();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class ChartsPreferencesFragment extends AbstractPreferenceFragment {
|
||||||
|
static final String FRAGMENT_TAG = "CHARTS_PREFERENCES_FRAGMENT";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String[] getPreferenceKeysWithSummary() {
|
public void onCreatePreferences(final Bundle savedInstanceState, final String rootKey) {
|
||||||
return new String[]{
|
addPreferencesFromResource(R.xml.charts_preferences);
|
||||||
"chart_list_min_session_length",
|
|
||||||
"chart_list_max_idle_phase_length",
|
setInputTypeFor(GBPrefs.CHART_MAX_HEART_RATE, InputType.TYPE_CLASS_NUMBER);
|
||||||
"chart_list_min_steps_per_minute",
|
setInputTypeFor(GBPrefs.CHART_MIN_HEART_RATE, InputType.TYPE_CLASS_NUMBER);
|
||||||
"chart_list_min_steps_per_minute_for_run",
|
setInputTypeFor("chart_sleep_lines_limit", InputType.TYPE_CLASS_NUMBER);
|
||||||
GBPrefs.CHART_MAX_HEART_RATE,
|
setInputTypeFor("chart_list_min_session_length", InputType.TYPE_CLASS_NUMBER);
|
||||||
GBPrefs.CHART_MIN_HEART_RATE,
|
setInputTypeFor("chart_list_max_idle_phase_length", InputType.TYPE_CLASS_NUMBER);
|
||||||
"chart_sleep_lines_limit",
|
setInputTypeFor("chart_list_min_steps_per_minute", InputType.TYPE_CLASS_NUMBER);
|
||||||
};
|
setInputTypeFor("chart_list_min_steps_per_minute_for_run", InputType.TYPE_CLASS_NUMBER);
|
||||||
|
|
||||||
|
final Preference aboutUserPref = findPreference("pref_category_activity_personal");
|
||||||
|
if (aboutUserPref != null) {
|
||||||
|
aboutUserPref.setOnPreferenceClickListener(preference -> {
|
||||||
|
final Intent enableIntent = new Intent(getActivity(), AboutUserPreferencesActivity.class);
|
||||||
|
startActivity(enableIntent);
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?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">
|
||||||
<PreferenceCategory
|
<PreferenceCategory
|
||||||
android:key="pref_charts"
|
android:key="pref_charts"
|
||||||
android:title="@string/activity_prefs_charts">
|
android:title="@string/activity_prefs_charts">
|
||||||
@ -9,47 +10,49 @@
|
|||||||
android:inputType="number"
|
android:inputType="number"
|
||||||
android:key="chart_max_heart_rate"
|
android:key="chart_max_heart_rate"
|
||||||
android:maxLength="3"
|
android:maxLength="3"
|
||||||
android:title="@string/activity_prefs_chart_max_heart_rate" />
|
android:title="@string/activity_prefs_chart_max_heart_rate"
|
||||||
|
app:useSimpleSummaryProvider="true" />
|
||||||
|
|
||||||
<EditTextPreference
|
<EditTextPreference
|
||||||
android:defaultValue="10"
|
android:defaultValue="10"
|
||||||
android:inputType="number"
|
android:inputType="number"
|
||||||
android:key="chart_min_heart_rate"
|
android:key="chart_min_heart_rate"
|
||||||
android:maxLength="3"
|
android:maxLength="3"
|
||||||
android:title="@string/activity_prefs_chart_min_heart_rate" />
|
android:title="@string/activity_prefs_chart_min_heart_rate"
|
||||||
|
app:useSimpleSummaryProvider="true" />
|
||||||
|
|
||||||
<CheckBoxPreference
|
<SwitchPreference
|
||||||
android:defaultValue="false"
|
android:defaultValue="false"
|
||||||
android:key="chart_heartrate_color"
|
android:key="chart_heartrate_color"
|
||||||
android:summaryOff="@string/pref_chart_heartrate_color_orange"
|
android:summaryOff="@string/pref_chart_heartrate_color_orange"
|
||||||
android:summaryOn="@string/pref_chart_heartrate_color_red"
|
android:summaryOn="@string/pref_chart_heartrate_color_red"
|
||||||
android:title="@string/pref_title_chart_heartrate_color" />
|
android:title="@string/pref_title_chart_heartrate_color" />
|
||||||
|
|
||||||
<CheckBoxPreference
|
<SwitchPreference
|
||||||
android:defaultValue="true"
|
android:defaultValue="true"
|
||||||
android:key="charts_allow_swipe"
|
android:key="charts_allow_swipe"
|
||||||
android:title="@string/pref_title_charts_swipe" />
|
android:title="@string/pref_title_charts_swipe" />
|
||||||
|
|
||||||
<CheckBoxPreference
|
<SwitchPreference
|
||||||
android:defaultValue="false"
|
android:defaultValue="false"
|
||||||
android:key="chart_sleep_range_24h"
|
android:key="chart_sleep_range_24h"
|
||||||
android:summaryOff="@string/pref_chart_sleep_rolling_24_off"
|
android:summaryOff="@string/pref_chart_sleep_rolling_24_off"
|
||||||
android:summaryOn="@string/pref_chart_sleep_rolling_24_on"
|
android:summaryOn="@string/pref_chart_sleep_rolling_24_on"
|
||||||
android:title="@string/pref_title_chart_sleep_rolling_24_hour" />
|
android:title="@string/pref_title_chart_sleep_rolling_24_hour" />
|
||||||
|
|
||||||
<CheckBoxPreference
|
<SwitchPreference
|
||||||
android:defaultValue="true"
|
android:defaultValue="true"
|
||||||
android:key="charts_show_average"
|
android:key="charts_show_average"
|
||||||
android:title="@string/pref_title_charts_average" />
|
android:title="@string/pref_title_charts_average" />
|
||||||
|
|
||||||
<CheckBoxPreference
|
<SwitchPreference
|
||||||
android:defaultValue="false"
|
android:defaultValue="false"
|
||||||
android:key="charts_range"
|
android:key="charts_range"
|
||||||
android:summaryOff="@string/pref_charts_range_off"
|
android:summaryOff="@string/pref_charts_range_off"
|
||||||
android:summaryOn="@string/pref_charts_range_on"
|
android:summaryOn="@string/pref_charts_range_on"
|
||||||
android:title="@string/pref_title_charts_range" />
|
android:title="@string/pref_title_charts_range" />
|
||||||
|
|
||||||
<CheckBoxPreference
|
<SwitchPreference
|
||||||
android:defaultValue="true"
|
android:defaultValue="true"
|
||||||
android:key="charts_show_ongoing_activity"
|
android:key="charts_show_ongoing_activity"
|
||||||
android:title="@string/show_ongoing_activity" />
|
android:title="@string/show_ongoing_activity" />
|
||||||
@ -59,7 +62,8 @@
|
|||||||
android:inputType="number"
|
android:inputType="number"
|
||||||
android:key="chart_sleep_lines_limit"
|
android:key="chart_sleep_lines_limit"
|
||||||
android:maxLength="2"
|
android:maxLength="2"
|
||||||
android:title="@string/pref_chart_sleep_lines_limit" />
|
android:title="@string/pref_chart_sleep_lines_limit"
|
||||||
|
app:useSimpleSummaryProvider="true" />
|
||||||
|
|
||||||
</PreferenceCategory>
|
</PreferenceCategory>
|
||||||
|
|
||||||
@ -72,28 +76,32 @@
|
|||||||
android:inputType="number"
|
android:inputType="number"
|
||||||
android:key="chart_list_min_session_length"
|
android:key="chart_list_min_session_length"
|
||||||
android:maxLength="2"
|
android:maxLength="2"
|
||||||
android:title="@string/activity_prefs_chart_min_session_length" />
|
android:title="@string/activity_prefs_chart_min_session_length"
|
||||||
|
app:useSimpleSummaryProvider="true" />
|
||||||
|
|
||||||
<EditTextPreference
|
<EditTextPreference
|
||||||
android:defaultValue="5"
|
android:defaultValue="5"
|
||||||
android:inputType="number"
|
android:inputType="number"
|
||||||
android:key="chart_list_max_idle_phase_length"
|
android:key="chart_list_max_idle_phase_length"
|
||||||
android:maxLength="2"
|
android:maxLength="2"
|
||||||
android:title="@string/activity_prefs_chart_max_idle_phase_length" />
|
android:title="@string/activity_prefs_chart_max_idle_phase_length"
|
||||||
|
app:useSimpleSummaryProvider="true" />
|
||||||
|
|
||||||
<EditTextPreference
|
<EditTextPreference
|
||||||
android:defaultValue="20"
|
android:defaultValue="20"
|
||||||
android:inputType="number"
|
android:inputType="number"
|
||||||
android:key="chart_list_min_steps_per_minute"
|
android:key="chart_list_min_steps_per_minute"
|
||||||
android:maxLength="3"
|
android:maxLength="3"
|
||||||
android:title="@string/activity_prefs_chart_min_steps_per_minute" />
|
android:title="@string/activity_prefs_chart_min_steps_per_minute"
|
||||||
|
app:useSimpleSummaryProvider="true" />
|
||||||
|
|
||||||
<EditTextPreference
|
<EditTextPreference
|
||||||
android:defaultValue="120"
|
android:defaultValue="120"
|
||||||
android:inputType="number"
|
android:inputType="number"
|
||||||
android:key="chart_list_min_steps_per_minute_for_run"
|
android:key="chart_list_min_steps_per_minute_for_run"
|
||||||
android:maxLength="3"
|
android:maxLength="3"
|
||||||
android:title="@string/activity_prefs_chart_min_steps_per_minute_for_run" />
|
android:title="@string/activity_prefs_chart_min_steps_per_minute_for_run"
|
||||||
|
app:useSimpleSummaryProvider="true" />
|
||||||
</PreferenceCategory>
|
</PreferenceCategory>
|
||||||
|
|
||||||
<PreferenceCategory
|
<PreferenceCategory
|
||||||
|
Loading…
Reference in New Issue
Block a user