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.setViewVisibility(R.id.todaywidget_battery_icon, View.GONE);
if (deviceForWidget != null) {
String status = String.format("%1s", deviceForWidget.getStateString());
String status = String.format("%1s", deviceForWidget.getStateString(context));
if (deviceForWidget.isConnected()) {
if (deviceForWidget.getBatteryLevel() > 1) {
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);
connect();
} else {
setInfoText(getString(R.string.fwappinstaller_connection_state, device.getStateString()));
setInfoText(getString(R.string.fwappinstaller_connection_state, device.getStateString(context)));
}
} else {
validateInstallation();

View File

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

View File

@ -416,8 +416,8 @@ public class GBDevice implements Parcelable {
}
}
public String getStateString() {
return getStateString(true);
public String getStateString(final Context context) {
return getStateString(context, true);
}
/**
@ -425,16 +425,16 @@ public class GBDevice implements Parcelable {
* instead of connecting->connected->initializing->initialized
* Set simple to true to get this behavior.
*/
private String getStateString(boolean simple) {
private String getStateString(Context context, boolean simple) {
try{
// TODO: not sure if this is really neccessary...
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){}
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();
}
@NonNull
@Override
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"));
BtLEQueue queue = getQueue();
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 {
try {
TransactionBuilder builder = performInitialized("TX");
@ -270,7 +270,7 @@ public class BangleJSDeviceSupport extends AbstractBTLEDeviceSupport {
break;
}
case GBDevice.ACTION_DEVICE_CHANGED: {
String stateString = (gbDevice!=null ? gbDevice.getStateString():"");
String stateString = (gbDevice!=null ? gbDevice.getStateString(context):"");
if (!stateString.equals(lastStateString)) {
lastStateString = 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
context.getResources().updateConfiguration(config, context.getResources().getDisplayMetrics());
Locale.setDefault(language);
}
/**

View File

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