1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-28 12:56:49 +01:00

Fix crash when opening battery status activity

This commit is contained in:
José Rebelo 2024-06-14 20:38:07 +01:00
parent 527773d3d8
commit d4dc686148
3 changed files with 19 additions and 5 deletions

View File

@ -195,8 +195,12 @@ public class BatteryInfoActivity extends AbstractGBActivity {
setBatteryLabels();
for (BatteryConfig batteryConfig : coordinator.getBatteryConfig(gbDevice)) {
if (batteryConfig.getBatteryIndex() == batteryIndex) {
if (batteryConfig.getBatteryLabel() != GBDevice.BATTERY_LABEL_DEFAULT) {
battery_status_extra_name.setText(batteryConfig.getBatteryLabel());
}
if (batteryConfig.getBatteryIcon() != GBDevice.BATTERY_ICON_DEFAULT) {
battery_status_device_icon.setImageResource(batteryConfig.getBatteryIcon());
}
if (gbDevice.isInitialized()) {
battery_status_device_icon.setColorFilter(this.getResources().getColor(R.color.accent));
}

View File

@ -212,7 +212,7 @@ public class DeviceSpecificSettingsFragment extends AbstractPreferenceFragment i
final Preference prefHeader = new PreferenceCategory(requireContext());
prefHeader.setKey("pref_battery_header_" + batteryConfig.getBatteryIndex());
prefHeader.setIconSpaceReserved(false);
if (batteryConfig.getBatteryLabel() > 0) {
if (batteryConfig.getBatteryLabel() != GBDevice.BATTERY_LABEL_DEFAULT) {
prefHeader.setTitle(batteryConfig.getBatteryLabel());
} else {
prefHeader.setTitle(requireContext().getString(R.string.battery_i, batteryConfig.getBatteryIndex()));

View File

@ -69,11 +69,21 @@ public class BatteryConfig {
if (this == o) return true;
if (!(o instanceof BatteryConfig)) return false;
BatteryConfig that = (BatteryConfig) o;
return getBatteryIndex() == that.getBatteryIndex() && getBatteryIcon() == that.getBatteryIcon() && getBatteryLabel() == that.getBatteryLabel();
return getBatteryIndex() == that.getBatteryIndex() &&
getBatteryIcon() == that.getBatteryIcon() &&
getBatteryLabel() == that.getBatteryLabel() &&
getDefaultLowThreshold() == that.getDefaultLowThreshold() &&
getDefaultFullThreshold() == that.getDefaultFullThreshold();
}
@Override
public int hashCode() {
return Objects.hash(getBatteryIndex(), getBatteryIcon(), getBatteryLabel());
return Objects.hash(
getBatteryIndex(),
getBatteryIcon(),
getBatteryLabel(),
getDefaultLowThreshold(),
getDefaultFullThreshold()
);
}
}