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