From f9ef3f47abdf4fb56a112859154d8520bc7bcc0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Rebelo?= Date: Thu, 27 Jul 2023 22:42:00 +0100 Subject: [PATCH] Extract Pebble and HPlus settings to standalone activities --- app/src/main/AndroidManifest.xml | 8 + .../activities/SettingsActivity.java | 29 ++- .../devices/hplus/HPlusSettingsActivity.java | 49 +++++ .../pebble/PebbleSettingsActivity.java | 73 +++++++ app/src/main/res/xml/hplus_preferences.xml | 23 +++ app/src/main/res/xml/pebble_preferences.xml | 162 +++++++++++++++ app/src/main/res/xml/preferences.xml | 189 +----------------- 7 files changed, 333 insertions(+), 200 deletions(-) create mode 100644 app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/hplus/HPlusSettingsActivity.java create mode 100644 app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/pebble/PebbleSettingsActivity.java create mode 100644 app/src/main/res/xml/hplus_preferences.xml create mode 100644 app/src/main/res/xml/pebble_preferences.xml diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 919a0f358..106c5867b 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -132,6 +132,14 @@ android:name=".activities.loyaltycards.LoyaltyCardsSettingsActivity" android:label="@string/loyalty_cards" android:parentActivityName=".activities.devicesettings.DeviceSettingsActivity" /> + + { - 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; }); } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/hplus/HPlusSettingsActivity.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/hplus/HPlusSettingsActivity.java new file mode 100644 index 000000000..85507ef43 --- /dev/null +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/hplus/HPlusSettingsActivity.java @@ -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 . */ +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); + } + } +} diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/pebble/PebbleSettingsActivity.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/pebble/PebbleSettingsActivity.java new file mode 100644 index 000000000..f07f0b827 --- /dev/null +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/pebble/PebbleSettingsActivity.java @@ -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 . */ +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; + }); + } + } + } +} diff --git a/app/src/main/res/xml/hplus_preferences.xml b/app/src/main/res/xml/hplus_preferences.xml new file mode 100644 index 000000000..d2b409556 --- /dev/null +++ b/app/src/main/res/xml/hplus_preferences.xml @@ -0,0 +1,23 @@ + + + + + + + + + diff --git a/app/src/main/res/xml/pebble_preferences.xml b/app/src/main/res/xml/pebble_preferences.xml new file mode 100644 index 000000000..a4eb6ce5c --- /dev/null +++ b/app/src/main/res/xml/pebble_preferences.xml @@ -0,0 +1,162 @@ + + + + + + + + + + + + + + + + > + + + + + + + + + + + + + + + diff --git a/app/src/main/res/xml/preferences.xml b/app/src/main/res/xml/preferences.xml index d81bf5256..3398e3dc4 100644 --- a/app/src/main/res/xml/preferences.xml +++ b/app/src/main/res/xml/preferences.xml @@ -227,195 +227,16 @@ android:key="pref_key_miband" android:title="@string/preferences_miband_settings" /> - - - - - - - - - - - - - - - > - - - - - - - - - - - - - - - - + - - - - - - - - - + android:title="@string/preferences_hplus_settings"> +