mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-06-01 19:06:06 +02:00
Split out dashboard preferences from SettingsActivity
This commit is contained in:
parent
2535f554b0
commit
9cd858b39c
|
@ -128,6 +128,10 @@
|
|||
android:name=".activities.SettingsActivity"
|
||||
android:label="@string/title_activity_settings"
|
||||
android:parentActivityName=".activities.ControlCenterv2" />
|
||||
<activity
|
||||
android:name=".activities.DashboardPreferencesActivity"
|
||||
android:label="@string/dashboard_settings"
|
||||
android:parentActivityName=".activities.SettingsActivity" />
|
||||
<activity
|
||||
android:name=".activities.AboutUserPreferencesActivity"
|
||||
android:label="@string/activity_prefs_about_you"
|
||||
|
|
|
@ -0,0 +1,101 @@
|
|||
/* Copyright (C) 2024 Arjan Schrijver
|
||||
|
||||
This file is part of Gadgetbridge.
|
||||
|
||||
Gadgetbridge is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published
|
||||
by the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Gadgetbridge is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
package nodomain.freeyourgadget.gadgetbridge.activities;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.text.InputType;
|
||||
|
||||
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
|
||||
import androidx.preference.MultiSelectListPreference;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceFragmentCompat;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
||||
import nodomain.freeyourgadget.gadgetbridge.R;
|
||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
||||
|
||||
public class DashboardPreferencesActivity extends AbstractSettingsActivityV2 {
|
||||
@Override
|
||||
protected String fragmentTag() {
|
||||
return DashboardPreferencesFragment.FRAGMENT_TAG;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected PreferenceFragmentCompat newFragment() {
|
||||
return new DashboardPreferencesFragment();
|
||||
}
|
||||
|
||||
public static class DashboardPreferencesFragment extends AbstractPreferenceFragment {
|
||||
static final String FRAGMENT_TAG = "DASHBOARD_PREFERENCES_FRAGMENT";
|
||||
|
||||
@Override
|
||||
public void onCreatePreferences(final Bundle savedInstanceState, final String rootKey) {
|
||||
setPreferencesFromResource(R.xml.dashboard_preferences, rootKey);
|
||||
|
||||
setInputTypeFor("dashboard_widget_today_hr_interval", InputType.TYPE_CLASS_NUMBER);
|
||||
|
||||
final MultiSelectListPreference dashboardDevices = findPreference("dashboard_devices_multiselect");
|
||||
if (dashboardDevices != null) {
|
||||
List<GBDevice> devices = GBApplication.app().getDeviceManager().getDevices();
|
||||
List<String> deviceMACs = new ArrayList<>();
|
||||
List<String> deviceNames = new ArrayList<>();
|
||||
for (GBDevice dev : devices) {
|
||||
deviceMACs.add(dev.getAddress());
|
||||
deviceNames.add(dev.getAliasOrName());
|
||||
}
|
||||
dashboardDevices.setEntryValues(deviceMACs.toArray(new String[0]));
|
||||
dashboardDevices.setEntries(deviceNames.toArray(new String[0]));
|
||||
}
|
||||
List<String> dashboardPrefs = Arrays.asList(
|
||||
"dashboard_cards_enabled",
|
||||
"pref_dashboard_widgets_order",
|
||||
"dashboard_widget_today_24h",
|
||||
"dashboard_widget_today_2columns",
|
||||
"dashboard_widget_today_legend",
|
||||
"dashboard_widget_today_hr_interval",
|
||||
"dashboard_widget_goals_2columns",
|
||||
"dashboard_widget_goals_legend",
|
||||
"dashboard_devices_all",
|
||||
"dashboard_devices_multiselect"
|
||||
);
|
||||
Preference pref;
|
||||
for (String dashboardPref : dashboardPrefs) {
|
||||
pref = findPreference(dashboardPref);
|
||||
if (pref != null) {
|
||||
pref.setOnPreferenceChangeListener((preference, autoExportEnabled) -> {
|
||||
sendDashboardConfigChangedIntent();
|
||||
return true;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Signal dashboard that its config has changed
|
||||
*/
|
||||
private void sendDashboardConfigChangedIntent() {
|
||||
Intent intent = new Intent();
|
||||
intent.setAction(DashboardFragment.ACTION_CONFIG_CHANGE);
|
||||
LocalBroadcastManager.getInstance(requireContext()).sendBroadcast(intent);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -109,7 +109,6 @@ public class SettingsActivity extends AbstractSettingsActivityV2 {
|
|||
public void onCreatePreferences(final Bundle savedInstanceState, final String rootKey) {
|
||||
setPreferencesFromResource(R.xml.preferences, rootKey);
|
||||
|
||||
setInputTypeFor("dashboard_widget_today_hr_interval", InputType.TYPE_CLASS_NUMBER);
|
||||
setInputTypeFor("rtl_max_line_length", InputType.TYPE_CLASS_NUMBER);
|
||||
setInputTypeFor("location_latitude", InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_SIGNED);
|
||||
setInputTypeFor("location_longitude", InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_SIGNED);
|
||||
|
@ -402,38 +401,13 @@ public class SettingsActivity extends AbstractSettingsActivityV2 {
|
|||
audioPlayer.setDefaultValue(newValues[0]);
|
||||
}
|
||||
|
||||
final MultiSelectListPreference dashboardDevices = findPreference("dashboard_devices_multiselect");
|
||||
if (dashboardDevices != null) {
|
||||
List<GBDevice> devices = GBApplication.app().getDeviceManager().getDevices();
|
||||
List<String> deviceMACs = new ArrayList<>();
|
||||
List<String> deviceNames = new ArrayList<>();
|
||||
for (GBDevice dev : devices) {
|
||||
deviceMACs.add(dev.getAddress());
|
||||
deviceNames.add(dev.getAliasOrName());
|
||||
}
|
||||
dashboardDevices.setEntryValues(deviceMACs.toArray(new String[0]));
|
||||
dashboardDevices.setEntries(deviceNames.toArray(new String[0]));
|
||||
}
|
||||
List<String> dashboardPrefs = Arrays.asList(
|
||||
"dashboard_cards_enabled",
|
||||
"pref_dashboard_widgets_order",
|
||||
"dashboard_widget_today_24h",
|
||||
"dashboard_widget_today_2columns",
|
||||
"dashboard_widget_today_legend",
|
||||
"dashboard_widget_today_hr_interval",
|
||||
"dashboard_widget_goals_2columns",
|
||||
"dashboard_widget_goals_legend",
|
||||
"dashboard_devices_all",
|
||||
"dashboard_devices_multiselect"
|
||||
);
|
||||
for (String dashboardPref : dashboardPrefs) {
|
||||
pref = findPreference(dashboardPref);
|
||||
if (pref != null) {
|
||||
pref.setOnPreferenceChangeListener((preference, autoExportEnabled) -> {
|
||||
sendDashboardConfigChangedIntent();
|
||||
return true;
|
||||
});
|
||||
}
|
||||
pref = findPreference("pref_category_dashboard");
|
||||
if (pref != null) {
|
||||
pref.setOnPreferenceClickListener(preference -> {
|
||||
Intent enableIntent = new Intent(requireContext(), DashboardPreferencesActivity.class);
|
||||
startActivity(enableIntent);
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
final Preference theme = findPreference("pref_key_theme");
|
||||
|
@ -630,14 +604,5 @@ public class SettingsActivity extends AbstractSettingsActivityV2 {
|
|||
intent.setAction(GBApplication.ACTION_THEME_CHANGE);
|
||||
LocalBroadcastManager.getInstance(requireContext()).sendBroadcast(intent);
|
||||
}
|
||||
|
||||
/**
|
||||
* Signal dashboard that its config has changed
|
||||
*/
|
||||
private void sendDashboardConfigChangedIntent() {
|
||||
Intent intent = new Intent();
|
||||
intent.setAction(DashboardFragment.ACTION_CONFIG_CHANGE);
|
||||
LocalBroadcastManager.getInstance(requireContext()).sendBroadcast(intent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
115
app/src/main/res/xml/dashboard_preferences.xml
Normal file
115
app/src/main/res/xml/dashboard_preferences.xml
Normal file
|
@ -0,0 +1,115 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
<PreferenceCategory
|
||||
android:key="pref_key_dashboard_general"
|
||||
android:title="@string/pref_header_general"
|
||||
app:iconSpaceReserved="false">
|
||||
<SwitchPreferenceCompat
|
||||
android:defaultValue="true"
|
||||
android:key="dashboard_as_default_view"
|
||||
android:layout="@layout/preference_checkbox"
|
||||
android:title="@string/pref_dashboard_first_title"
|
||||
android:summary="@string/pref_dashboard_first_summary"
|
||||
app:iconSpaceReserved="false" />
|
||||
<SwitchPreferenceCompat
|
||||
android:defaultValue="true"
|
||||
android:key="dashboard_cards_enabled"
|
||||
android:layout="@layout/preference_checkbox"
|
||||
android:title="@string/pref_dashboard_cards_title"
|
||||
android:summary="@string/pref_dashboard_cards_summary"
|
||||
app:iconSpaceReserved="false" />
|
||||
<com.mobeta.android.dslv.DragSortListPreference
|
||||
android:defaultValue="@array/pref_dashboard_widgets_order_values"
|
||||
android:dialogTitle="@string/menuitem_widgets"
|
||||
android:entries="@array/pref_dashboard_widgets_order"
|
||||
android:entryValues="@array/pref_dashboard_widgets_order_values"
|
||||
android:key="pref_dashboard_widgets_order"
|
||||
android:persistent="true"
|
||||
android:summary="@string/pref_dashboard_widgets_order_summary"
|
||||
android:title="@string/menuitem_widgets"
|
||||
app:iconSpaceReserved="false" />
|
||||
</PreferenceCategory>
|
||||
|
||||
<PreferenceCategory
|
||||
android:key="pref_key_dashboard_widgets"
|
||||
android:title="@string/pref_dashboard_widget_settings"
|
||||
app:iconSpaceReserved="false">
|
||||
<PreferenceScreen
|
||||
android:key="pref_key_dashboard_today"
|
||||
android:title="@string/pref_dashboard_widget_today_title"
|
||||
app:iconSpaceReserved="false">
|
||||
<SwitchPreferenceCompat
|
||||
android:defaultValue="false"
|
||||
android:key="dashboard_widget_today_24h"
|
||||
android:layout="@layout/preference_checkbox"
|
||||
android:title="@string/pref_dashboard_widget_today_24h_title"
|
||||
android:summary="@string/pref_dashboard_widget_today_24h_summary"
|
||||
app:iconSpaceReserved="false" />
|
||||
<SwitchPreferenceCompat
|
||||
android:defaultValue="true"
|
||||
android:key="dashboard_widget_today_2columns"
|
||||
android:layout="@layout/preference_checkbox"
|
||||
android:title="@string/pref_dashboard_widget_double_size_title"
|
||||
android:summary="@string/pref_dashboard_widget_double_size_summary"
|
||||
app:iconSpaceReserved="false" />
|
||||
<SwitchPreferenceCompat
|
||||
android:defaultValue="true"
|
||||
android:key="dashboard_widget_today_legend"
|
||||
android:layout="@layout/preference_checkbox"
|
||||
android:title="@string/pref_dashboard_widget_show_legend_title"
|
||||
android:summary="@string/pref_dashboard_widget_show_legend_summary"
|
||||
app:iconSpaceReserved="false" />
|
||||
<EditTextPreference
|
||||
android:defaultValue="1"
|
||||
android:inputType="number"
|
||||
android:key="dashboard_widget_today_hr_interval"
|
||||
android:maxLength="4"
|
||||
android:summary="@string/pref_dashboard_widget_today_hr_interval_summary"
|
||||
android:title="@string/pref_dashboard_widget_today_hr_interval_title"
|
||||
app:iconSpaceReserved="false" />
|
||||
</PreferenceScreen>
|
||||
<PreferenceScreen
|
||||
android:key="pref_key_dashboard_goals"
|
||||
android:title="@string/pref_dashboard_widget_goals_chart_title"
|
||||
app:iconSpaceReserved="false">
|
||||
<SwitchPreferenceCompat
|
||||
android:defaultValue="true"
|
||||
android:key="dashboard_widget_goals_2columns"
|
||||
android:layout="@layout/preference_checkbox"
|
||||
android:title="@string/pref_dashboard_widget_double_size_title"
|
||||
android:summary="@string/pref_dashboard_widget_double_size_summary"
|
||||
app:iconSpaceReserved="false" />
|
||||
<SwitchPreferenceCompat
|
||||
android:defaultValue="true"
|
||||
android:key="dashboard_widget_goals_legend"
|
||||
android:layout="@layout/preference_checkbox"
|
||||
android:title="@string/pref_dashboard_widget_show_legend_title"
|
||||
android:summary="@string/pref_dashboard_widget_show_legend_summary"
|
||||
app:iconSpaceReserved="false" />
|
||||
</PreferenceScreen>
|
||||
</PreferenceCategory>
|
||||
|
||||
<PreferenceCategory
|
||||
android:key="pref_key_dashboard_devices"
|
||||
android:title="@string/pref_dashboard_devices_to_include"
|
||||
app:iconSpaceReserved="false">
|
||||
<SwitchPreferenceCompat
|
||||
android:defaultValue="true"
|
||||
android:key="dashboard_devices_all"
|
||||
android:layout="@layout/preference_checkbox"
|
||||
android:title="@string/pref_dashboard_all_devices_title"
|
||||
android:summary="@string/pref_dashboard_all_devices_summary"
|
||||
android:disableDependentsState="true"
|
||||
app:iconSpaceReserved="false" />
|
||||
<MultiSelectListPreference
|
||||
android:dependency="dashboard_devices_all"
|
||||
android:dialogTitle="@string/pref_dashboard_select_devices_title"
|
||||
android:entries="@array/empty_array"
|
||||
android:entryValues="@array/empty_array"
|
||||
android:key="dashboard_devices_multiselect"
|
||||
android:title="@string/pref_dashboard_select_devices_title"
|
||||
android:summary="@string/pref_dashboard_select_devices_summary"
|
||||
app:iconSpaceReserved="false" />
|
||||
</PreferenceCategory>
|
||||
</PreferenceScreen>
|
|
@ -58,123 +58,10 @@
|
|||
android:title="@string/pref_title_audio_player"
|
||||
app:iconSpaceReserved="false" />
|
||||
|
||||
<PreferenceScreen
|
||||
<Preference
|
||||
android:key="pref_category_dashboard"
|
||||
android:title="@string/bottom_nav_dashboard"
|
||||
app:iconSpaceReserved="false">
|
||||
|
||||
<PreferenceCategory
|
||||
android:key="pref_key_dashboard_general"
|
||||
android:title="@string/pref_header_general"
|
||||
app:iconSpaceReserved="false">
|
||||
<SwitchPreferenceCompat
|
||||
android:defaultValue="true"
|
||||
android:key="dashboard_as_default_view"
|
||||
android:layout="@layout/preference_checkbox"
|
||||
android:title="@string/pref_dashboard_first_title"
|
||||
android:summary="@string/pref_dashboard_first_summary"
|
||||
app:iconSpaceReserved="false" />
|
||||
<SwitchPreferenceCompat
|
||||
android:defaultValue="true"
|
||||
android:key="dashboard_cards_enabled"
|
||||
android:layout="@layout/preference_checkbox"
|
||||
android:title="@string/pref_dashboard_cards_title"
|
||||
android:summary="@string/pref_dashboard_cards_summary"
|
||||
app:iconSpaceReserved="false" />
|
||||
<com.mobeta.android.dslv.DragSortListPreference
|
||||
android:defaultValue="@array/pref_dashboard_widgets_order_values"
|
||||
android:dialogTitle="@string/menuitem_widgets"
|
||||
android:entries="@array/pref_dashboard_widgets_order"
|
||||
android:entryValues="@array/pref_dashboard_widgets_order_values"
|
||||
android:key="pref_dashboard_widgets_order"
|
||||
android:persistent="true"
|
||||
android:summary="@string/pref_dashboard_widgets_order_summary"
|
||||
android:title="@string/menuitem_widgets"
|
||||
app:iconSpaceReserved="false" />
|
||||
</PreferenceCategory>
|
||||
|
||||
<PreferenceCategory
|
||||
android:key="pref_key_dashboard_widgets"
|
||||
android:title="@string/pref_dashboard_widget_settings"
|
||||
app:iconSpaceReserved="false">
|
||||
<PreferenceScreen
|
||||
android:key="pref_key_dashboard_today"
|
||||
android:title="@string/pref_dashboard_widget_today_title"
|
||||
app:iconSpaceReserved="false">
|
||||
<SwitchPreferenceCompat
|
||||
android:defaultValue="false"
|
||||
android:key="dashboard_widget_today_24h"
|
||||
android:layout="@layout/preference_checkbox"
|
||||
android:title="@string/pref_dashboard_widget_today_24h_title"
|
||||
android:summary="@string/pref_dashboard_widget_today_24h_summary"
|
||||
app:iconSpaceReserved="false" />
|
||||
<SwitchPreferenceCompat
|
||||
android:defaultValue="true"
|
||||
android:key="dashboard_widget_today_2columns"
|
||||
android:layout="@layout/preference_checkbox"
|
||||
android:title="@string/pref_dashboard_widget_double_size_title"
|
||||
android:summary="@string/pref_dashboard_widget_double_size_summary"
|
||||
app:iconSpaceReserved="false" />
|
||||
<SwitchPreferenceCompat
|
||||
android:defaultValue="true"
|
||||
android:key="dashboard_widget_today_legend"
|
||||
android:layout="@layout/preference_checkbox"
|
||||
android:title="@string/pref_dashboard_widget_show_legend_title"
|
||||
android:summary="@string/pref_dashboard_widget_show_legend_summary"
|
||||
app:iconSpaceReserved="false" />
|
||||
<EditTextPreference
|
||||
android:defaultValue="1"
|
||||
android:inputType="number"
|
||||
android:key="dashboard_widget_today_hr_interval"
|
||||
android:maxLength="4"
|
||||
android:summary="@string/pref_dashboard_widget_today_hr_interval_summary"
|
||||
android:title="@string/pref_dashboard_widget_today_hr_interval_title"
|
||||
app:iconSpaceReserved="false" />
|
||||
</PreferenceScreen>
|
||||
<PreferenceScreen
|
||||
android:key="pref_key_dashboard_goals"
|
||||
android:title="@string/pref_dashboard_widget_goals_chart_title"
|
||||
app:iconSpaceReserved="false">
|
||||
<SwitchPreferenceCompat
|
||||
android:defaultValue="true"
|
||||
android:key="dashboard_widget_goals_2columns"
|
||||
android:layout="@layout/preference_checkbox"
|
||||
android:title="@string/pref_dashboard_widget_double_size_title"
|
||||
android:summary="@string/pref_dashboard_widget_double_size_summary"
|
||||
app:iconSpaceReserved="false" />
|
||||
<SwitchPreferenceCompat
|
||||
android:defaultValue="true"
|
||||
android:key="dashboard_widget_goals_legend"
|
||||
android:layout="@layout/preference_checkbox"
|
||||
android:title="@string/pref_dashboard_widget_show_legend_title"
|
||||
android:summary="@string/pref_dashboard_widget_show_legend_summary"
|
||||
app:iconSpaceReserved="false" />
|
||||
</PreferenceScreen>
|
||||
</PreferenceCategory>
|
||||
|
||||
<PreferenceCategory
|
||||
android:key="pref_key_dashboard_devices"
|
||||
android:title="@string/pref_dashboard_devices_to_include"
|
||||
app:iconSpaceReserved="false">
|
||||
<SwitchPreferenceCompat
|
||||
android:defaultValue="true"
|
||||
android:key="dashboard_devices_all"
|
||||
android:layout="@layout/preference_checkbox"
|
||||
android:title="@string/pref_dashboard_all_devices_title"
|
||||
android:summary="@string/pref_dashboard_all_devices_summary"
|
||||
android:disableDependentsState="true"
|
||||
app:iconSpaceReserved="false" />
|
||||
<MultiSelectListPreference
|
||||
android:dependency="dashboard_devices_all"
|
||||
android:dialogTitle="@string/pref_dashboard_select_devices_title"
|
||||
android:entries="@array/empty_array"
|
||||
android:entryValues="@array/empty_array"
|
||||
android:key="dashboard_devices_multiselect"
|
||||
android:title="@string/pref_dashboard_select_devices_title"
|
||||
android:summary="@string/pref_dashboard_select_devices_summary"
|
||||
app:iconSpaceReserved="false" />
|
||||
</PreferenceCategory>
|
||||
</PreferenceScreen>
|
||||
app:iconSpaceReserved="false" />
|
||||
|
||||
<PreferenceScreen
|
||||
android:key="pref_screen_theme"
|
||||
|
|
Loading…
Reference in New Issue
Block a user