1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-07-21 22:31:16 +02:00

Extract Pebble and HPlus settings to standalone activities

This commit is contained in:
José Rebelo 2023-07-27 22:42:00 +01:00 committed by José Rebelo
parent e068bfdb75
commit f9ef3f47ab
7 changed files with 333 additions and 200 deletions

View File

@ -132,6 +132,14 @@
android:name=".activities.loyaltycards.LoyaltyCardsSettingsActivity"
android:label="@string/loyalty_cards"
android:parentActivityName=".activities.devicesettings.DeviceSettingsActivity" />
<activity
android:name=".devices.pebble.PebbleSettingsActivity"
android:label="@string/pref_title_pebble_settings"
android:parentActivityName=".activities.SettingsActivity" />
<activity
android:name=".devices.hplus.HPlusSettingsActivity"
android:label="@string/preferences_hplus_settings"
android:parentActivityName=".activities.SettingsActivity" />
<activity
android:name=".devices.zetime.ZeTimePreferenceActivity"
android:label="@string/zetime_title_settings"

View File

@ -43,11 +43,9 @@ import android.widget.LinearLayout;
import android.widget.Spinner;
import android.widget.Toast;
import androidx.preference.EditTextPreference;
import androidx.core.app.ActivityCompat;
import androidx.preference.ListPreference;
import androidx.preference.Preference;
import androidx.core.app.ActivityCompat;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import androidx.preference.PreferenceFragmentCompat;
import org.slf4j.Logger;
@ -64,8 +62,9 @@ import nodomain.freeyourgadget.gadgetbridge.GBApplication;
import nodomain.freeyourgadget.gadgetbridge.R;
import nodomain.freeyourgadget.gadgetbridge.activities.charts.ChartsPreferencesActivity;
import nodomain.freeyourgadget.gadgetbridge.database.PeriodicExporter;
import nodomain.freeyourgadget.gadgetbridge.devices.DeviceManager;
import nodomain.freeyourgadget.gadgetbridge.devices.hplus.HPlusSettingsActivity;
import nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandPreferencesActivity;
import nodomain.freeyourgadget.gadgetbridge.devices.pebble.PebbleSettingsActivity;
import nodomain.freeyourgadget.gadgetbridge.devices.qhybrid.ConfigActivity;
import nodomain.freeyourgadget.gadgetbridge.devices.zetime.ZeTimePreferenceActivity;
import nodomain.freeyourgadget.gadgetbridge.model.Weather;
@ -143,31 +142,29 @@ public class SettingsActivity extends AbstractSettingsActivityV2 {
});
}
pref = findPreference("pref_key_zetime");
pref = findPreference("pref_key_pebble");
if (pref != null) {
pref.setOnPreferenceClickListener(preference -> {
Intent enableIntent = new Intent(requireContext(), ZeTimePreferenceActivity.class);
Intent enableIntent = new Intent(requireContext(), PebbleSettingsActivity.class);
startActivity(enableIntent);
return true;
});
}
pref = findPreference("pebble_emu_addr");
pref = findPreference("pref_key_hplus");
if (pref != null) {
pref.setOnPreferenceChangeListener((preference, newVal) -> {
Intent refreshIntent = new Intent(DeviceManager.ACTION_REFRESH_DEVICELIST);
LocalBroadcastManager.getInstance(requireContext().getApplicationContext()).sendBroadcast(refreshIntent);
preference.setSummary(newVal.toString());
pref.setOnPreferenceClickListener(preference -> {
Intent enableIntent = new Intent(requireContext(), HPlusSettingsActivity.class);
startActivity(enableIntent);
return true;
});
}
pref = findPreference("pebble_emu_port");
pref = findPreference("pref_key_zetime");
if (pref != null) {
pref.setOnPreferenceChangeListener((preference, newVal) -> {
Intent refreshIntent = new Intent(DeviceManager.ACTION_REFRESH_DEVICELIST);
LocalBroadcastManager.getInstance(requireContext().getApplicationContext()).sendBroadcast(refreshIntent);
preference.setSummary(newVal.toString());
pref.setOnPreferenceClickListener(preference -> {
Intent enableIntent = new Intent(requireContext(), ZeTimePreferenceActivity.class);
startActivity(enableIntent);
return true;
});
}

View File

@ -0,0 +1,49 @@
/* Copyright (C) 2023 José Rebelo,
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.devices.hplus;
import android.os.Bundle;
import android.text.InputType;
import androidx.preference.PreferenceFragmentCompat;
import nodomain.freeyourgadget.gadgetbridge.R;
import nodomain.freeyourgadget.gadgetbridge.activities.AbstractPreferenceFragment;
import nodomain.freeyourgadget.gadgetbridge.activities.AbstractSettingsActivityV2;
public class HPlusSettingsActivity extends AbstractSettingsActivityV2 {
@Override
protected String fragmentTag() {
return HPlusSettingsFragment.FRAGMENT_TAG;
}
@Override
protected PreferenceFragmentCompat newFragment() {
return new HPlusSettingsFragment();
}
public static class HPlusSettingsFragment extends AbstractPreferenceFragment {
static final String FRAGMENT_TAG = "HPLUS_SETTINGS_FRAGMENT";
@Override
public void onCreatePreferences(final Bundle savedInstanceState, final String rootKey) {
setPreferencesFromResource(R.xml.hplus_preferences, rootKey);
setInputTypeFor("hplus_screentime", InputType.TYPE_CLASS_NUMBER);
}
}
}

View File

@ -0,0 +1,73 @@
/* Copyright (C) 2023 José Rebelo,
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.devices.pebble;
import android.content.Intent;
import android.os.Bundle;
import android.text.InputType;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import androidx.preference.Preference;
import androidx.preference.PreferenceFragmentCompat;
import nodomain.freeyourgadget.gadgetbridge.R;
import nodomain.freeyourgadget.gadgetbridge.activities.AbstractPreferenceFragment;
import nodomain.freeyourgadget.gadgetbridge.activities.AbstractSettingsActivityV2;
import nodomain.freeyourgadget.gadgetbridge.devices.DeviceManager;
public class PebbleSettingsActivity extends AbstractSettingsActivityV2 {
@Override
protected String fragmentTag() {
return PebbleSettingsFragment.FRAGMENT_TAG;
}
@Override
protected PreferenceFragmentCompat newFragment() {
return new PebbleSettingsFragment();
}
public static class PebbleSettingsFragment extends AbstractPreferenceFragment {
static final String FRAGMENT_TAG = "PEBBLE_SETTINGS_FRAGMENT";
@Override
public void onCreatePreferences(final Bundle savedInstanceState, final String rootKey) {
setPreferencesFromResource(R.xml.pebble_preferences, rootKey);
setInputTypeFor("pebble_reconnect_attempts", InputType.TYPE_CLASS_NUMBER);
setInputTypeFor("pebble_mtu_limit", InputType.TYPE_CLASS_NUMBER);
setInputTypeFor("pebble_emu_port", InputType.TYPE_CLASS_NUMBER);
final Preference pebbleEmuAddrPref = findPreference("pebble_emu_addr");
if (pebbleEmuAddrPref != null) {
pebbleEmuAddrPref.setOnPreferenceChangeListener((preference, newVal) -> {
Intent refreshIntent = new Intent(DeviceManager.ACTION_REFRESH_DEVICELIST);
LocalBroadcastManager.getInstance(requireContext().getApplicationContext()).sendBroadcast(refreshIntent);
return true;
});
}
final Preference pebbleEmuPort = findPreference("pebble_emu_port");
if (pebbleEmuPort != null) {
pebbleEmuPort.setOnPreferenceChangeListener((preference, newVal) -> {
Intent refreshIntent = new Intent(DeviceManager.ACTION_REFRESH_DEVICELIST);
LocalBroadcastManager.getInstance(requireContext().getApplicationContext()).sendBroadcast(refreshIntent);
return true;
});
}
}
}
}

View File

@ -0,0 +1,23 @@
<?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_category_hplus_general"
android:title="@string/pref_header_general"
app:iconSpaceReserved="false">
<EditTextPreference
android:defaultValue="5"
android:key="hplus_screentime"
android:title="@string/pref_title_screentime"
app:iconSpaceReserved="false"
app:useSimpleSummaryProvider="true"/>
<SwitchPreference
android:defaultValue="true"
android:key="hplus_alldayhr"
android:layout="@layout/preference_checkbox"
android:title="@string/prefs_title_all_day_heart_rate"
app:iconSpaceReserved="false" />
</PreferenceCategory>
</PreferenceScreen>

View File

@ -0,0 +1,162 @@
<?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:title="@string/pref_header_general"
app:iconSpaceReserved="false">
<SwitchPreference
android:defaultValue="true"
android:key="pebble_enable_outgoing_call"
android:layout="@layout/preference_checkbox"
android:summary="@string/pref_summary_enable_outgoing_call"
android:title="@string/pref_title_enable_outgoing_call"
app:iconSpaceReserved="false" />
<SwitchPreference
android:defaultValue="false"
android:key="pebble_enable_pebblekit"
android:layout="@layout/preference_checkbox"
android:summary="@string/pref_summary_enable_pebblekit"
android:title="@string/pref_title_enable_pebblekit"
app:iconSpaceReserved="false" />
<EditTextPreference
android:defaultValue="12"
android:inputType="number"
android:key="pebble_reconnect_attempts"
android:maxLength="4"
android:title="@string/pref_title_pebble_reconnect_attempts"
app:iconSpaceReserved="false"
app:useSimpleSummaryProvider="true" />
<ListPreference
android:defaultValue="@string/p_pebble_privacy_mode_off"
android:entries="@array/pebble_privacymode"
android:entryValues="@array/pebble_privacymode_values"
android:key="pebble_pref_privacy_mode"
android:summary="%s"
android:title="@string/pref_title_pebble_privacy_mode"
app:iconSpaceReserved="false" />
</PreferenceCategory>
<PreferenceCategory
android:title="@string/pref_header_pebble_timeline"
app:iconSpaceReserved="false">
<SwitchPreference
android:key="send_sunrise_sunset"
android:layout="@layout/preference_checkbox"
android:summary="@string/pref_summary_sunrise_sunset"
android:title="@string/pref_title_sunrise_sunset"
app:iconSpaceReserved="false" />
</PreferenceCategory>
<PreferenceCategory
android:title="@string/pref_header_activitytrackers"
app:iconSpaceReserved="false">
<ListPreference
android:defaultValue="4"
android:entries="@array/pebble_activitytracker"
android:entryValues="@array/pebble_activitytracker_values"
android:key="pebble_activitytracker"
android:summary="%s"
android:title="@string/pref_title_pebble_activitytracker"
app:iconSpaceReserved="false" />
<SwitchPreference
android:defaultValue="true"
android:key="pebble_sync_health"
android:layout="@layout/preference_checkbox"
android:title="@string/pref_title_pebble_sync_health"
app:iconSpaceReserved="false" />
<SwitchPreference
android:defaultValue="true"
android:dependency="pebble_sync_health"
android:key="pebble_health_store_raw"
android:layout="@layout/preference_checkbox"
android:summary="@string/pref_summary_pebble_health_store_raw"
android:title="@string/pref_title_pebble_health_store_raw"
app:iconSpaceReserved="false" />
<SwitchPreference
android:defaultValue="true"
android:key="pebble_sync_misfit"
android:layout="@layout/preference_checkbox"
android:title="@string/pref_title_pebble_sync_misfit"
app:iconSpaceReserved="false" />>
<SwitchPreference
android:defaultValue="true"
android:key="pebble_sync_morpheuz"
android:layout="@layout/preference_checkbox"
android:title="@string/pref_title_pebble_sync_morpheuz"
app:iconSpaceReserved="false" />
</PreferenceCategory>
<PreferenceCategory
android:title="@string/pref_header_development"
app:iconSpaceReserved="false">
<SwitchPreference
android:defaultValue="false"
android:key="pebble_force_protocol"
android:layout="@layout/preference_checkbox"
android:summary="@string/pref_summary_pebble_forceprotocol"
android:title="@string/pref_title_pebble_forceprotocol"
app:iconSpaceReserved="false" />
<SwitchPreference
android:defaultValue="false"
android:key="pebble_force_untested"
android:layout="@layout/preference_checkbox"
android:summary="@string/pref_summary_pebble_forceuntested"
android:title="@string/pref_title_pebble_forceuntested"
app:iconSpaceReserved="false" />
<SwitchPreference
android:defaultValue="false"
android:key="pebble_force_le"
android:layout="@layout/preference_checkbox"
android:summary="@string/pref_summary_pebble_forcele"
android:title="@string/pref_title_pebble_forcele"
app:iconSpaceReserved="false" />
<EditTextPreference
android:defaultValue="512"
android:inputType="number"
android:key="pebble_mtu_limit"
android:maxLength="3"
android:summary="@string/pref_summary_pebble_mtu_limit"
android:title="@string/pref_title_pebble_mtu_limit"
app:iconSpaceReserved="false" />
<SwitchPreference
android:defaultValue="false"
android:key="pebble_gatt_clientonly"
android:layout="@layout/preference_checkbox"
android:summary="@string/pref_summary_pebble_gatt_clientonly"
android:title="@string/pref_title_pebble_gatt_clientonly"
app:iconSpaceReserved="false" />
<SwitchPreference
android:defaultValue="false"
android:key="pebble_enable_applogs"
android:layout="@layout/preference_checkbox"
android:summary="@string/pref_summary_pebble_enable_applogs"
android:title="@string/pref_title_pebble_enable_applogs"
app:iconSpaceReserved="false" />
<SwitchPreference
android:defaultValue="false"
android:key="pebble_always_ack_pebblekit"
android:layout="@layout/preference_checkbox"
android:summary="@string/pref_summary_pebble_always_ack_pebblekit"
android:title="@string/pref_title_pebble_always_ack_pebblekit"
app:iconSpaceReserved="false" />
<SwitchPreference
android:defaultValue="false"
android:dependency="pebble_force_untested"
android:key="pebble_enable_background_javascript"
android:layout="@layout/preference_checkbox"
android:summary="@string/pref_summary_pebble_enable_bgjs"
android:title="@string/pref_title_pebble_enable_bgjs"
app:iconSpaceReserved="false" />
<EditTextPreference
android:digits="0123456789."
android:key="pebble_emu_addr"
android:maxLength="15"
android:title="Emulator IP"
app:iconSpaceReserved="false"
app:useSimpleSummaryProvider="true" />
<EditTextPreference
android:inputType="number"
android:key="pebble_emu_port"
android:maxLength="5"
android:title="Emulator Port"
app:iconSpaceReserved="false"
app:useSimpleSummaryProvider="true" />
</PreferenceCategory>
</PreferenceScreen>

View File

@ -227,195 +227,16 @@
android:key="pref_key_miband"
android:title="@string/preferences_miband_settings" />
<PreferenceScreen
<Preference
android:icon="@drawable/ic_device_pebble"
android:key="pref_key_pebble"
android:title="@string/pref_title_pebble_settings">
<PreferenceCategory
android:title="@string/pref_header_general"
app:iconSpaceReserved="false">
<SwitchPreference
android:defaultValue="true"
android:key="pebble_enable_outgoing_call"
android:layout="@layout/preference_checkbox"
android:summary="@string/pref_summary_enable_outgoing_call"
android:title="@string/pref_title_enable_outgoing_call"
app:iconSpaceReserved="false" />
<SwitchPreference
android:defaultValue="false"
android:key="pebble_enable_pebblekit"
android:layout="@layout/preference_checkbox"
android:summary="@string/pref_summary_enable_pebblekit"
android:title="@string/pref_title_enable_pebblekit"
app:iconSpaceReserved="false" />
<EditTextPreference
android:defaultValue="12"
android:inputType="number"
android:key="pebble_reconnect_attempts"
android:maxLength="4"
android:title="@string/pref_title_pebble_reconnect_attempts"
app:iconSpaceReserved="false"
app:useSimpleSummaryProvider="true" />
<ListPreference
android:defaultValue="@string/p_pebble_privacy_mode_off"
android:entries="@array/pebble_privacymode"
android:entryValues="@array/pebble_privacymode_values"
android:key="pebble_pref_privacy_mode"
android:summary="%s"
android:title="@string/pref_title_pebble_privacy_mode"
app:iconSpaceReserved="false" />
</PreferenceCategory>
<PreferenceCategory
android:title="@string/pref_header_pebble_timeline"
app:iconSpaceReserved="false">
<SwitchPreference
android:key="send_sunrise_sunset"
android:layout="@layout/preference_checkbox"
android:summary="@string/pref_summary_sunrise_sunset"
android:title="@string/pref_title_sunrise_sunset"
app:iconSpaceReserved="false" />
</PreferenceCategory>
<PreferenceCategory
android:title="@string/pref_header_activitytrackers"
app:iconSpaceReserved="false">
<ListPreference
android:defaultValue="4"
android:entries="@array/pebble_activitytracker"
android:entryValues="@array/pebble_activitytracker_values"
android:key="pebble_activitytracker"
android:summary="%s"
android:title="@string/pref_title_pebble_activitytracker"
app:iconSpaceReserved="false" />
<SwitchPreference
android:defaultValue="true"
android:key="pebble_sync_health"
android:layout="@layout/preference_checkbox"
android:title="@string/pref_title_pebble_sync_health"
app:iconSpaceReserved="false" />
<SwitchPreference
android:defaultValue="true"
android:dependency="pebble_sync_health"
android:key="pebble_health_store_raw"
android:layout="@layout/preference_checkbox"
android:summary="@string/pref_summary_pebble_health_store_raw"
android:title="@string/pref_title_pebble_health_store_raw"
app:iconSpaceReserved="false" />
<SwitchPreference
android:defaultValue="true"
android:key="pebble_sync_misfit"
android:layout="@layout/preference_checkbox"
android:title="@string/pref_title_pebble_sync_misfit"
app:iconSpaceReserved="false" />>
<SwitchPreference
android:defaultValue="true"
android:key="pebble_sync_morpheuz"
android:layout="@layout/preference_checkbox"
android:title="@string/pref_title_pebble_sync_morpheuz"
app:iconSpaceReserved="false" />
</PreferenceCategory>
<PreferenceCategory
android:title="@string/pref_header_development"
app:iconSpaceReserved="false">
<SwitchPreference
android:defaultValue="false"
android:key="pebble_force_protocol"
android:layout="@layout/preference_checkbox"
android:summary="@string/pref_summary_pebble_forceprotocol"
android:title="@string/pref_title_pebble_forceprotocol"
app:iconSpaceReserved="false" />
<SwitchPreference
android:defaultValue="false"
android:key="pebble_force_untested"
android:layout="@layout/preference_checkbox"
android:summary="@string/pref_summary_pebble_forceuntested"
android:title="@string/pref_title_pebble_forceuntested"
app:iconSpaceReserved="false" />
<SwitchPreference
android:defaultValue="false"
android:key="pebble_force_le"
android:layout="@layout/preference_checkbox"
android:summary="@string/pref_summary_pebble_forcele"
android:title="@string/pref_title_pebble_forcele"
app:iconSpaceReserved="false" />
<EditTextPreference
android:defaultValue="512"
android:inputType="number"
android:key="pebble_mtu_limit"
android:maxLength="3"
android:summary="@string/pref_summary_pebble_mtu_limit"
android:title="@string/pref_title_pebble_mtu_limit"
app:iconSpaceReserved="false" />
<SwitchPreference
android:defaultValue="false"
android:key="pebble_gatt_clientonly"
android:layout="@layout/preference_checkbox"
android:summary="@string/pref_summary_pebble_gatt_clientonly"
android:title="@string/pref_title_pebble_gatt_clientonly"
app:iconSpaceReserved="false" />
<SwitchPreference
android:defaultValue="false"
android:key="pebble_enable_applogs"
android:layout="@layout/preference_checkbox"
android:summary="@string/pref_summary_pebble_enable_applogs"
android:title="@string/pref_title_pebble_enable_applogs"
app:iconSpaceReserved="false" />
<SwitchPreference
android:defaultValue="false"
android:key="pebble_always_ack_pebblekit"
android:layout="@layout/preference_checkbox"
android:summary="@string/pref_summary_pebble_always_ack_pebblekit"
android:title="@string/pref_title_pebble_always_ack_pebblekit"
app:iconSpaceReserved="false" />
<SwitchPreference
android:defaultValue="false"
android:dependency="pebble_force_untested"
android:key="pebble_enable_background_javascript"
android:layout="@layout/preference_checkbox"
android:summary="@string/pref_summary_pebble_enable_bgjs"
android:title="@string/pref_title_pebble_enable_bgjs"
app:iconSpaceReserved="false" />
<EditTextPreference
android:digits="0123456789."
android:key="pebble_emu_addr"
android:maxLength="15"
android:title="Emulator IP"
app:iconSpaceReserved="false"
app:useSimpleSummaryProvider="true" />
<EditTextPreference
android:inputType="number"
android:key="pebble_emu_port"
android:maxLength="5"
android:title="Emulator Port"
app:iconSpaceReserved="false"
app:useSimpleSummaryProvider="true" />
</PreferenceCategory>
</PreferenceScreen>
<PreferenceScreen
</Preference>
<Preference
android:icon="@drawable/ic_device_hplus"
android:key="pref_key_hplus"
android:title="@string/preferences_hplus_settings"
app:iconSpaceReserved="false">
<PreferenceCategory
android:key="pref_category_hplus_general"
android:title="@string/pref_header_general"
app:iconSpaceReserved="false">
<EditTextPreference
android:defaultValue="5"
android:key="hplus_screentime"
android:title="@string/pref_title_screentime"
app:iconSpaceReserved="false" />
<SwitchPreference
android:defaultValue="true"
android:key="hplus_alldayhr"
android:layout="@layout/preference_checkbox"
android:title="@string/prefs_title_all_day_heart_rate"
app:iconSpaceReserved="false" />
</PreferenceCategory>
</PreferenceScreen>
android:title="@string/preferences_hplus_settings">
</Preference>
<Preference
android:icon="@drawable/ic_device_zetime"
android:key="pref_key_zetime"