1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-27 12:26:48 +01:00

Fix language not being respected in some situations

This commit is contained in:
José Rebelo 2024-10-06 22:22:48 +01:00
parent 9191500fd9
commit 32e955abe2
7 changed files with 17 additions and 14 deletions

View File

@ -142,7 +142,7 @@ public class Widget extends AppWidgetProvider {
views.setProgressBar(R.id.todaywidget_distance_progress, distanceGoal, steps * stepLength, false); views.setProgressBar(R.id.todaywidget_distance_progress, distanceGoal, steps * stepLength, false);
views.setViewVisibility(R.id.todaywidget_battery_icon, View.GONE); views.setViewVisibility(R.id.todaywidget_battery_icon, View.GONE);
if (deviceForWidget != null) { if (deviceForWidget != null) {
String status = String.format("%1s", deviceForWidget.getStateString()); String status = String.format("%1s", deviceForWidget.getStateString(context));
if (deviceForWidget.isConnected()) { if (deviceForWidget.isConnected()) {
if (deviceForWidget.getBatteryLevel() > 1) { if (deviceForWidget.getBatteryLevel() > 1) {
views.setViewVisibility(R.id.todaywidget_battery_icon, View.VISIBLE); views.setViewVisibility(R.id.todaywidget_battery_icon, View.VISIBLE);

View File

@ -94,7 +94,7 @@ public class FwAppInstallerActivity extends AbstractGBActivity implements Instal
GB.toast(FwAppInstallerActivity.this, getString(R.string.connecting), Toast.LENGTH_SHORT, GB.INFO); GB.toast(FwAppInstallerActivity.this, getString(R.string.connecting), Toast.LENGTH_SHORT, GB.INFO);
connect(); connect();
} else { } else {
setInfoText(getString(R.string.fwappinstaller_connection_state, device.getStateString())); setInfoText(getString(R.string.fwappinstaller_connection_state, device.getStateString(context)));
} }
} else { } else {
validateInstallation(); validateInstallation();

View File

@ -344,7 +344,7 @@ public class GBDeviceAdapterv2 extends ListAdapter<GBDevice, GBDeviceAdapterv2.V
holder.deviceStatusLabel.setText(device.getBusyTask()); holder.deviceStatusLabel.setText(device.getBusyTask());
holder.busyIndicator.setVisibility(View.VISIBLE); holder.busyIndicator.setVisibility(View.VISIBLE);
} else { } else {
holder.deviceStatusLabel.setText(device.getStateString()); holder.deviceStatusLabel.setText(device.getStateString(context));
holder.busyIndicator.setVisibility(View.INVISIBLE); holder.busyIndicator.setVisibility(View.INVISIBLE);
} }

View File

@ -416,8 +416,8 @@ public class GBDevice implements Parcelable {
} }
} }
public String getStateString() { public String getStateString(final Context context) {
return getStateString(true); return getStateString(context, true);
} }
/** /**
@ -425,16 +425,16 @@ public class GBDevice implements Parcelable {
* instead of connecting->connected->initializing->initialized * instead of connecting->connected->initializing->initialized
* Set simple to true to get this behavior. * Set simple to true to get this behavior.
*/ */
private String getStateString(boolean simple) { private String getStateString(Context context, boolean simple) {
try{ try{
// TODO: not sure if this is really neccessary... // TODO: not sure if this is really neccessary...
if(simple){ if(simple){
return GBApplication.getContext().getString(mState.getSimpleStringId()); return context.getString(mState.getSimpleStringId());
} }
return GBApplication.getContext().getString(mState.getStringId()); return context.getString(mState.getStringId());
}catch (Exception e){} }catch (Exception e){}
return GBApplication.getContext().getString(R.string.unknown_state); return context.getString(R.string.unknown_state);
} }
/** /**
@ -629,9 +629,10 @@ public class GBDevice implements Parcelable {
getDeviceCoordinator().getDisabledIconResource(); getDeviceCoordinator().getDisabledIconResource();
} }
@NonNull
@Override @Override
public String toString() { public String toString() {
return "Device " + getName() + ", " + getAddress() + ", " + getStateString(false); return "Device " + getName() + ", " + getAddress() + ", " + mState;
} }
/** /**

View File

@ -257,7 +257,7 @@ public class BangleJSDeviceSupport extends AbstractBTLEDeviceSupport {
String data = String.valueOf(intent.getExtras().get("DATA")); String data = String.valueOf(intent.getExtras().get("DATA"));
BtLEQueue queue = getQueue(); BtLEQueue queue = getQueue();
if (queue==null) { if (queue==null) {
LOG.warn("BANGLEJS_COMMAND_TX received, but getQueue()==null (state=" + gbDevice.getStateString() + ")"); LOG.warn("BANGLEJS_COMMAND_TX received, but getQueue()==null (state=" + gbDevice.getStateString(context) + ")");
} else { } else {
try { try {
TransactionBuilder builder = performInitialized("TX"); TransactionBuilder builder = performInitialized("TX");
@ -270,7 +270,7 @@ public class BangleJSDeviceSupport extends AbstractBTLEDeviceSupport {
break; break;
} }
case GBDevice.ACTION_DEVICE_CHANGED: { case GBDevice.ACTION_DEVICE_CHANGED: {
String stateString = (gbDevice!=null ? gbDevice.getStateString():""); String stateString = (gbDevice!=null ? gbDevice.getStateString(context):"");
if (!stateString.equals(lastStateString)) { if (!stateString.equals(lastStateString)) {
lastStateString = stateString; lastStateString = stateString;
LOG.info("ACTION_DEVICE_CHANGED " + stateString); LOG.info("ACTION_DEVICE_CHANGED " + stateString);

View File

@ -111,6 +111,8 @@ public class AndroidUtils {
// FIXME: I have no idea what I am doing // FIXME: I have no idea what I am doing
context.getResources().updateConfiguration(config, context.getResources().getDisplayMetrics()); context.getResources().updateConfiguration(config, context.getResources().getDisplayMetrics());
Locale.setDefault(language);
} }
/** /**

View File

@ -195,7 +195,7 @@ public class GB {
}else if(devices.size() == 1) { }else if(devices.size() == 1) {
GBDevice device = devices.get(0); GBDevice device = devices.get(0);
String deviceName = device.getAliasOrName(); String deviceName = device.getAliasOrName();
String text = device.getStateString(); String text = device.getStateString(context);
text += buildDeviceBatteryString(context, device); text += buildDeviceBatteryString(context, device);
@ -242,7 +242,7 @@ public class GB {
anyDeviceSupportesActivityDataFetching |= device.getDeviceCoordinator().supportsActivityDataFetching(); anyDeviceSupportesActivityDataFetching |= device.getDeviceCoordinator().supportsActivityDataFetching();
String deviceName = device.getAliasOrName(); String deviceName = device.getAliasOrName();
String text = device.getStateString(); String text = device.getStateString(context);
text += buildDeviceBatteryString(context, device); text += buildDeviceBatteryString(context, device);
contentText.append(deviceName).append(" (").append(text).append(")<br>"); contentText.append(deviceName).append(" (").append(text).append(")<br>");
} }