mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2025-01-14 11:47:32 +01:00
Add new getSupportedLanguageSettings() to coordinator to get rid of all those arrays
There is one big generic one now, unssupported languages will be removed at runtime. Tested with Amazfit Bip U.
This commit is contained in:
parent
2219eb489e
commit
bef015b0c2
@ -50,13 +50,20 @@ public class DeviceSettingsActivity extends AbstractGBActivity implements
|
|||||||
if (fragment == null) {
|
if (fragment == null) {
|
||||||
DeviceCoordinator coordinator = DeviceHelper.getInstance().getCoordinator(device);
|
DeviceCoordinator coordinator = DeviceHelper.getInstance().getCoordinator(device);
|
||||||
int[] supportedSettings = coordinator.getSupportedDeviceSpecificSettings(device);
|
int[] supportedSettings = coordinator.getSupportedDeviceSpecificSettings(device);
|
||||||
|
String[] supportedLanguages = coordinator.getSupportedLanguageSettings(device);
|
||||||
|
|
||||||
|
if (supportedLanguages != null) {
|
||||||
|
supportedSettings = ArrayUtils.insert(0, supportedSettings, R.xml.devicesettings_language_generic);
|
||||||
|
}
|
||||||
if (coordinator.supportsActivityTracking()) {
|
if (coordinator.supportsActivityTracking()) {
|
||||||
supportedSettings = ArrayUtils.addAll(supportedSettings, R.xml.devicesettings_chartstabs);
|
supportedSettings = ArrayUtils.addAll(supportedSettings, R.xml.devicesettings_chartstabs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FIXME: this does not belong here
|
||||||
if (!ArrayUtils.contains(supportedSettings, R.xml.devicesettings_transliteration)) {
|
if (!ArrayUtils.contains(supportedSettings, R.xml.devicesettings_transliteration)) {
|
||||||
supportedSettings = ArrayUtils.addAll(supportedSettings, R.xml.devicesettings_transliteration);
|
supportedSettings = ArrayUtils.addAll(supportedSettings, R.xml.devicesettings_transliteration);
|
||||||
}
|
}
|
||||||
fragment = DeviceSpecificSettingsFragment.newInstance(device.getAddress(), supportedSettings);
|
fragment = DeviceSpecificSettingsFragment.newInstance(device.getAddress(), supportedSettings, supportedLanguages);
|
||||||
}
|
}
|
||||||
getSupportFragmentManager()
|
getSupportFragmentManager()
|
||||||
.beginTransaction()
|
.beginTransaction()
|
||||||
@ -70,11 +77,17 @@ public class DeviceSettingsActivity extends AbstractGBActivity implements
|
|||||||
public boolean onPreferenceStartScreen(PreferenceFragmentCompat caller, PreferenceScreen preferenceScreen) {
|
public boolean onPreferenceStartScreen(PreferenceFragmentCompat caller, PreferenceScreen preferenceScreen) {
|
||||||
DeviceCoordinator coordinator = DeviceHelper.getInstance().getCoordinator(device);
|
DeviceCoordinator coordinator = DeviceHelper.getInstance().getCoordinator(device);
|
||||||
int[] supportedSettings = coordinator.getSupportedDeviceSpecificSettings(device);
|
int[] supportedSettings = coordinator.getSupportedDeviceSpecificSettings(device);
|
||||||
|
String[] supportedLanguages = coordinator.getSupportedLanguageSettings(device);
|
||||||
|
|
||||||
|
if (supportedLanguages != null) {
|
||||||
|
supportedSettings = ArrayUtils.insert(0, supportedSettings, R.xml.devicesettings_language_generic);
|
||||||
|
}
|
||||||
|
|
||||||
if (coordinator.supportsActivityTracking()) {
|
if (coordinator.supportsActivityTracking()) {
|
||||||
supportedSettings = ArrayUtils.addAll(supportedSettings, R.xml.devicesettings_chartstabs);
|
supportedSettings = ArrayUtils.addAll(supportedSettings, R.xml.devicesettings_chartstabs);
|
||||||
}
|
}
|
||||||
|
|
||||||
PreferenceFragmentCompat fragment = DeviceSpecificSettingsFragment.newInstance(device.getAddress(), supportedSettings);
|
PreferenceFragmentCompat fragment = DeviceSpecificSettingsFragment.newInstance(device.getAddress(), supportedSettings, supportedLanguages);
|
||||||
Bundle args = fragment.getArguments();
|
Bundle args = fragment.getArguments();
|
||||||
args.putString(PreferenceFragmentCompat.ARG_PREFERENCE_ROOT, preferenceScreen.getKey());
|
args.putString(PreferenceFragmentCompat.ARG_PREFERENCE_ROOT, preferenceScreen.getKey());
|
||||||
fragment.setArguments(args);
|
fragment.setArguments(args);
|
||||||
|
@ -23,12 +23,14 @@ import android.widget.EditText;
|
|||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.fragment.app.DialogFragment;
|
import androidx.fragment.app.DialogFragment;
|
||||||
import androidx.preference.EditTextPreference;
|
import androidx.preference.EditTextPreference;
|
||||||
|
import androidx.preference.ListPreference;
|
||||||
import androidx.preference.Preference;
|
import androidx.preference.Preference;
|
||||||
import androidx.preference.PreferenceFragmentCompat;
|
import androidx.preference.PreferenceFragmentCompat;
|
||||||
|
|
||||||
import com.mobeta.android.dslv.DragSortListPreference;
|
import com.mobeta.android.dslv.DragSortListPreference;
|
||||||
import com.mobeta.android.dslv.DragSortListPreferenceFragment;
|
import com.mobeta.android.dslv.DragSortListPreferenceFragment;
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.ArrayUtils;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
@ -36,6 +38,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.R;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst;
|
import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.devices.makibeshr3.MakibesHR3Constants;
|
import nodomain.freeyourgadget.gadgetbridge.devices.makibeshr3.MakibesHR3Constants;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst;
|
import nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst;
|
||||||
@ -145,10 +148,11 @@ public class DeviceSpecificSettingsFragment extends PreferenceFragmentCompat {
|
|||||||
|
|
||||||
static final String FRAGMENT_TAG = "DEVICE_SPECIFIC_SETTINGS_FRAGMENT";
|
static final String FRAGMENT_TAG = "DEVICE_SPECIFIC_SETTINGS_FRAGMENT";
|
||||||
|
|
||||||
private void setSettingsFileSuffix(String settingsFileSuffix, @NonNull int[] supportedSettings) {
|
private void setSettingsFileSuffix(String settingsFileSuffix, @NonNull int[] supportedSettings, String[] supportedLanguages) {
|
||||||
Bundle args = new Bundle();
|
Bundle args = new Bundle();
|
||||||
args.putString("settingsFileSuffix", settingsFileSuffix);
|
args.putString("settingsFileSuffix", settingsFileSuffix);
|
||||||
args.putIntArray("supportedSettings", supportedSettings);
|
args.putIntArray("supportedSettings", supportedSettings);
|
||||||
|
args.putStringArray("supportedLanguages", supportedLanguages);
|
||||||
setArguments(args);
|
setArguments(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -161,6 +165,8 @@ public class DeviceSpecificSettingsFragment extends PreferenceFragmentCompat {
|
|||||||
}
|
}
|
||||||
String settingsFileSuffix = arguments.getString("settingsFileSuffix", null);
|
String settingsFileSuffix = arguments.getString("settingsFileSuffix", null);
|
||||||
int[] supportedSettings = arguments.getIntArray("supportedSettings");
|
int[] supportedSettings = arguments.getIntArray("supportedSettings");
|
||||||
|
String[] supportedLanguages = arguments.getStringArray("supportedLanguages");
|
||||||
|
|
||||||
if (settingsFileSuffix == null || supportedSettings == null) {
|
if (settingsFileSuffix == null || supportedSettings == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -177,6 +183,19 @@ public class DeviceSpecificSettingsFragment extends PreferenceFragmentCompat {
|
|||||||
} else {
|
} else {
|
||||||
addPreferencesFromResource(setting);
|
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 {
|
} else {
|
||||||
// Now, this is ugly: search all the xml files for the rootKey
|
// Now, this is ugly: search all the xml files for the rootKey
|
||||||
@ -678,9 +697,9 @@ public class DeviceSpecificSettingsFragment extends PreferenceFragmentCompat {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static DeviceSpecificSettingsFragment newInstance(String settingsFileSuffix, @NonNull int[] supportedSettings) {
|
static DeviceSpecificSettingsFragment newInstance(String settingsFileSuffix, @NonNull int[] supportedSettings, String[] supportedLanguages) {
|
||||||
DeviceSpecificSettingsFragment fragment = new DeviceSpecificSettingsFragment();
|
DeviceSpecificSettingsFragment fragment = new DeviceSpecificSettingsFragment();
|
||||||
fragment.setSettingsFileSuffix(settingsFileSuffix, supportedSettings);
|
fragment.setSettingsFileSuffix(settingsFileSuffix, supportedSettings, supportedLanguages);
|
||||||
|
|
||||||
return fragment;
|
return fragment;
|
||||||
}
|
}
|
||||||
|
@ -236,6 +236,11 @@ public abstract class AbstractDeviceCoordinator implements DeviceCoordinator {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String[] getSupportedLanguageSettings(GBDevice device) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public Class<? extends Activity> getCalibrationActivity() {
|
public Class<? extends Activity> getCalibrationActivity() {
|
||||||
|
@ -342,4 +342,10 @@ public interface DeviceCoordinator {
|
|||||||
* Indicates which device specific settings the device supports (not per device type or family, but unique per device).
|
* Indicates which device specific settings the device supports (not per device type or family, but unique per device).
|
||||||
*/
|
*/
|
||||||
int[] getSupportedDeviceSpecificSettings(GBDevice device);
|
int[] getSupportedDeviceSpecificSettings(GBDevice device);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates which device specific language the device supports
|
||||||
|
*/
|
||||||
|
String[] getSupportedLanguageSettings(GBDevice device);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -105,6 +105,33 @@ public class AmazfitBipUCoordinator extends HuamiCoordinator {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String[] getSupportedLanguageSettings(GBDevice device) {
|
||||||
|
return new String[]{
|
||||||
|
"auto",
|
||||||
|
"zh_CH",
|
||||||
|
"zh_TW",
|
||||||
|
"cs_CZ",
|
||||||
|
"de_DE",
|
||||||
|
"el_GR",
|
||||||
|
"en_US",
|
||||||
|
"es_ES",
|
||||||
|
"fr_FR",
|
||||||
|
"id_ID",
|
||||||
|
"it_IT",
|
||||||
|
"ja_JP",
|
||||||
|
"ko_KO",
|
||||||
|
"nl_NL",
|
||||||
|
"pl_PL",
|
||||||
|
"pt_BR",
|
||||||
|
"ru_RU",
|
||||||
|
"th_TH",
|
||||||
|
"uk_UA",
|
||||||
|
"vi_VN",
|
||||||
|
"tr_TR",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getBondingStyle() {
|
public int getBondingStyle() {
|
||||||
return BONDING_STYLE_REQUIRE_KEY;
|
return BONDING_STYLE_REQUIRE_KEY;
|
||||||
|
@ -34,11 +34,18 @@ public class HuamiLanguageType {
|
|||||||
put("de_DE", 0x07);
|
put("de_DE", 0x07);
|
||||||
put("de_AT", 0x07);
|
put("de_AT", 0x07);
|
||||||
put("de_CH", 0x07);
|
put("de_CH", 0x07);
|
||||||
|
put("id_ID", 0x08);
|
||||||
put("pl_PL", 0x09);
|
put("pl_PL", 0x09);
|
||||||
put("it_IT", 0x0a);
|
put("it_IT", 0x0a);
|
||||||
|
put("ja_JP", 0x0b);
|
||||||
|
put("th_TH", 0x0c);
|
||||||
|
put("vi_VN", 0x0e);
|
||||||
put("pt_PT", 0x0f);
|
put("pt_PT", 0x0f);
|
||||||
|
put("nl_NL", 0x10);
|
||||||
put("tr_TR", 0x11);
|
put("tr_TR", 0x11);
|
||||||
|
put("uk_UA", 0x12);
|
||||||
put("pt_BR", 0x14);
|
put("pt_BR", 0x14);
|
||||||
put("cs_CZ", 0x16);
|
put("cs_CZ", 0x16);
|
||||||
|
put("el_GR", 0x17);
|
||||||
}};
|
}};
|
||||||
}
|
}
|
||||||
|
@ -1268,6 +1268,54 @@
|
|||||||
<item>@string/p_call_privacy_mode_complete</item>
|
<item>@string/p_call_privacy_mode_complete</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
|
|
||||||
|
<string-array name="pref_language_all">
|
||||||
|
<item name="auto">@string/automatic</item>
|
||||||
|
<item name="zh_CN">@string/simplified_chinese</item>
|
||||||
|
<item name="zh_TW">@string/traditional_chinese</item>
|
||||||
|
<item name="en_US">@string/english</item>
|
||||||
|
<item name="es_ES">@string/spanish</item>
|
||||||
|
<item name="de_DE">@string/german</item>
|
||||||
|
<item name="it_IT">@string/italian</item>
|
||||||
|
<item name="fr_FR">@string/french</item>
|
||||||
|
<item name="pt_BR">@string/portuguese</item>
|
||||||
|
<item name="nl_NL">@string/dutch</item>
|
||||||
|
<item name="pl_PL">@string/polish</item>
|
||||||
|
<item name="tr_TR">@string/turkish</item>
|
||||||
|
<item name="el_GR">@string/greek</item>
|
||||||
|
<item name="ru_RU">@string/russian</item>
|
||||||
|
<item name="uk_UA">@string/ukrainian</item>
|
||||||
|
<item name="ar_SA">@string/arabic</item>
|
||||||
|
<item name="id_ID">@string/indonesian</item>
|
||||||
|
<item name="th_TH">@string/thai</item>
|
||||||
|
<item name="vi_VN">@string/vietnamese</item>
|
||||||
|
<item name="ja_JP">@string/japanese</item>
|
||||||
|
<item name="ko_KO">@string/korean</item>
|
||||||
|
</string-array>
|
||||||
|
|
||||||
|
<string-array name="pref_language_all_values">
|
||||||
|
<item>auto</item>
|
||||||
|
<item>zh_CN</item>
|
||||||
|
<item>zh_TW</item>
|
||||||
|
<item>en_US</item>
|
||||||
|
<item>es_ES</item>
|
||||||
|
<item>de_DE</item>
|
||||||
|
<item>it_IT</item>
|
||||||
|
<item>fr_FR</item>
|
||||||
|
<item>pt_BR</item>
|
||||||
|
<item>nl_NL</item>
|
||||||
|
<item>pl_PL</item>
|
||||||
|
<item>tr_TR</item>
|
||||||
|
<item>el_GR</item>
|
||||||
|
<item>ru_RU</item>
|
||||||
|
<item>uk_UA</item>
|
||||||
|
<item>ar_SA</item>
|
||||||
|
<item>id_ID</item>
|
||||||
|
<item>th_TH</item>
|
||||||
|
<item>vi_VN</item>
|
||||||
|
<item>ja_JP</item>
|
||||||
|
<item>ko_KO</item>
|
||||||
|
</string-array>
|
||||||
|
|
||||||
<string-array name="pref_amazfitbip_language">
|
<string-array name="pref_amazfitbip_language">
|
||||||
<item name="auto">@string/automatic</item>
|
<item name="auto">@string/automatic</item>
|
||||||
<item name="zh_CN">@string/simplified_chinese</item>
|
<item name="zh_CN">@string/simplified_chinese</item>
|
||||||
|
@ -10,12 +10,4 @@
|
|||||||
android:persistent="true"
|
android:persistent="true"
|
||||||
android:summary="@string/mi2_prefs_display_items_summary"
|
android:summary="@string/mi2_prefs_display_items_summary"
|
||||||
android:title="@string/mi2_prefs_display_items" />
|
android:title="@string/mi2_prefs_display_items" />
|
||||||
<ListPreference
|
|
||||||
android:icon="@drawable/ic_language"
|
|
||||||
android:defaultValue="auto"
|
|
||||||
android:entries="@array/pref_amazfitbip_language"
|
|
||||||
android:entryValues="@array/pref_amazfitbip_language_values"
|
|
||||||
android:key="language"
|
|
||||||
android:summary="%s"
|
|
||||||
android:title="@string/pref_title_language" />
|
|
||||||
</androidx.preference.PreferenceScreen>
|
</androidx.preference.PreferenceScreen>
|
||||||
|
11
app/src/main/res/xml/devicesettings_language_generic.xml
Normal file
11
app/src/main/res/xml/devicesettings_language_generic.xml
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<ListPreference
|
||||||
|
android:icon="@drawable/ic_language"
|
||||||
|
android:defaultValue="auto"
|
||||||
|
android:entries="@array/pref_language_all"
|
||||||
|
android:entryValues="@array/pref_language_all_values"
|
||||||
|
android:key="language"
|
||||||
|
android:summary="%s"
|
||||||
|
android:title="@string/pref_title_language" />
|
||||||
|
</androidx.preference.PreferenceScreen>
|
Loading…
x
Reference in New Issue
Block a user