mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-28 12:56:49 +01:00
Refactor language and Mi Band 6 preferences code
This commit is contained in:
parent
99dc218cd1
commit
fe2a760891
@ -96,11 +96,10 @@ public class DeviceSpecificSettingsFragment extends AbstractPreferenceFragment i
|
||||
|
||||
private GBDevice device;
|
||||
|
||||
private void setSettingsFileSuffix(String settingsFileSuffix, @NonNull int[] supportedSettings, String[] supportedLanguages) {
|
||||
private void setSettingsFileSuffix(String settingsFileSuffix, @NonNull int[] supportedSettings) {
|
||||
Bundle args = new Bundle();
|
||||
args.putString("settingsFileSuffix", settingsFileSuffix);
|
||||
args.putIntArray("supportedSettings", supportedSettings);
|
||||
args.putStringArray("supportedLanguages", supportedLanguages);
|
||||
setArguments(args);
|
||||
}
|
||||
|
||||
@ -144,19 +143,6 @@ public class DeviceSpecificSettingsFragment extends AbstractPreferenceFragment i
|
||||
} else {
|
||||
addPreferencesFromResource(setting);
|
||||
}
|
||||
if (setting == R.xml.devicesettings_language_generic) {
|
||||
ListPreference languageListPreference = findPreference("language");
|
||||
CharSequence[] entries = languageListPreference.getEntries();
|
||||
CharSequence[] values = languageListPreference.getEntryValues();
|
||||
for (int i = entries.length - 1; i >= 0; i--) {
|
||||
if (!ArrayUtils.contains(supportedLanguages, values[i])) {
|
||||
entries = ArrayUtils.remove(entries, i);
|
||||
values = ArrayUtils.remove(values, i);
|
||||
}
|
||||
}
|
||||
languageListPreference.setEntries(entries);
|
||||
languageListPreference.setEntryValues(values);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Now, this is ugly: search all the xml files for the rootKey
|
||||
@ -196,6 +182,22 @@ public class DeviceSpecificSettingsFragment extends AbstractPreferenceFragment i
|
||||
final DeviceCoordinator coordinator = device.getDeviceCoordinator();
|
||||
|
||||
final Prefs prefs = new Prefs(getPreferenceManager().getSharedPreferences());
|
||||
|
||||
final ListPreference languageListPreference = findPreference("language");
|
||||
if (languageListPreference != null) {
|
||||
final String[] supportedLanguages = coordinator.getSupportedLanguageSettings(device);
|
||||
CharSequence[] entries = languageListPreference.getEntries();
|
||||
CharSequence[] values = languageListPreference.getEntryValues();
|
||||
for (int i = entries.length - 1; i >= 0; i--) {
|
||||
if (!ArrayUtils.contains(supportedLanguages, values[i])) {
|
||||
entries = ArrayUtils.remove(entries, i);
|
||||
values = ArrayUtils.remove(values, i);
|
||||
}
|
||||
}
|
||||
languageListPreference.setEntries(entries);
|
||||
languageListPreference.setEntryValues(values);
|
||||
}
|
||||
|
||||
String disconnectNotificationState = prefs.getString(PREF_DISCONNECT_NOTIFICATION, PREF_DO_NOT_DISTURB_OFF);
|
||||
boolean disconnectNotificationScheduled = disconnectNotificationState.equals(PREF_DO_NOT_DISTURB_SCHEDULED);
|
||||
|
||||
@ -1033,15 +1035,10 @@ public class DeviceSpecificSettingsFragment extends AbstractPreferenceFragment i
|
||||
String[] supportedLanguages = null;
|
||||
|
||||
if (applicationSpecificSettings.equals(DeviceSettingsActivity.MENU_ENTRY_POINTS.AUTH_SETTINGS)) { //auth settings screen
|
||||
addElementsToList(supportedSettings, coordinator.getSupportedDeviceSpecificAuthenticationSettings());
|
||||
supportedSettings.add(R.xml.devicesettings_pairingkey_explanation);
|
||||
if (device.getType() == DeviceType.MIBAND6) { // miband6 might require new protocol and people do not know what to do, hint them:
|
||||
supportedSettings.add(R.xml.devicesettings_miband6_new_protocol);
|
||||
supportedSettings.add(R.xml.devicesettings_miband6_new_auth_protocol_explanation);
|
||||
}
|
||||
addElementsToList(supportedSettings, coordinator.getSupportedDeviceSpecificAuthenticationSettings());
|
||||
} else { //device/application settings
|
||||
supportedLanguages = coordinator.getSupportedLanguageSettings(device);
|
||||
if (supportedLanguages != null) {
|
||||
if (coordinator.getSupportedLanguageSettings(device) != null) {
|
||||
supportedSettings.add(R.xml.devicesettings_language_generic);
|
||||
}
|
||||
addElementsToList(supportedSettings, coordinator.getSupportedDeviceSpecificSettings(device));
|
||||
@ -1070,7 +1067,7 @@ public class DeviceSpecificSettingsFragment extends AbstractPreferenceFragment i
|
||||
final DeviceSpecificSettingsCustomizer deviceSpecificSettingsCustomizer = coordinator.getDeviceSpecificSettingsCustomizer(device);
|
||||
final String settingsFileSuffix = device.getAddress();
|
||||
final DeviceSpecificSettingsFragment fragment = new DeviceSpecificSettingsFragment();
|
||||
fragment.setSettingsFileSuffix(settingsFileSuffix, supportedSettingsInts, supportedLanguages);
|
||||
fragment.setSettingsFileSuffix(settingsFileSuffix, supportedSettingsInts);
|
||||
fragment.setDeviceSpecificSettingsCustomizer(deviceSpecificSettingsCustomizer);
|
||||
fragment.setDevice(device);
|
||||
|
||||
|
@ -36,8 +36,6 @@ import nodomain.freeyourgadget.gadgetbridge.devices.InstallHandler;
|
||||
import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst;
|
||||
import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiCoordinator;
|
||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceCandidate;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.DeviceType;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.DeviceSupport;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.miband6.MiBand6Support;
|
||||
|
||||
@ -132,6 +130,15 @@ public class MiBand6Coordinator extends HuamiCoordinator {
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] getSupportedDeviceSpecificAuthenticationSettings() {
|
||||
return new int[]{
|
||||
R.xml.devicesettings_pairingkey,
|
||||
R.xml.devicesettings_miband6_new_protocol,
|
||||
R.xml.devicesettings_miband6_new_auth_protocol_explanation,
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getSupportedLanguageSettings(GBDevice device) {
|
||||
return new String[]{
|
||||
|
@ -8,7 +8,7 @@
|
||||
android:summary="@string/pref_explanation_authkey_new_protocol" >
|
||||
<intent
|
||||
android:action="android.intent.action.VIEW"
|
||||
android:data="https://codeberg.org/Freeyourgadget/Gadgetbridge/wiki/Mi-Band-6#new-auth-protocol"
|
||||
android:data="https://gadgetbridge.org/gadgets/wearables/xiaomi/#device__xiaomi_mi_band_6"
|
||||
/>
|
||||
</Preference>
|
||||
|
||||
|
@ -2,6 +2,7 @@
|
||||
<androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<SwitchPreferenceCompat
|
||||
android:defaultValue="false"
|
||||
android:icon="@drawable/ic_mtu"
|
||||
android:key="force_new_protocol"
|
||||
android:summary="@string/pref_summary_huami_force_new_protocol"
|
||||
android:title="@string/pref_title_huami_force_new_protocol" />
|
||||
|
@ -8,7 +8,7 @@
|
||||
android:summary="@string/pref_explanation_authkey" >
|
||||
<intent
|
||||
android:action="android.intent.action.VIEW"
|
||||
android:data="https://codeberg.org/Freeyourgadget/Gadgetbridge/wiki/Pairing"
|
||||
android:data="https://gadgetbridge.org/basics/pairing/"
|
||||
/>
|
||||
</Preference>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user