1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-07-24 07:38:45 +02: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(); setBatteryLabels();
for (BatteryConfig batteryConfig : coordinator.getBatteryConfig(gbDevice)) { for (BatteryConfig batteryConfig : coordinator.getBatteryConfig(gbDevice)) {
if (batteryConfig.getBatteryIndex() == batteryIndex) { if (batteryConfig.getBatteryIndex() == batteryIndex) {
battery_status_extra_name.setText(batteryConfig.getBatteryLabel()); if (batteryConfig.getBatteryLabel() != GBDevice.BATTERY_LABEL_DEFAULT) {
battery_status_device_icon.setImageResource(batteryConfig.getBatteryIcon()); battery_status_extra_name.setText(batteryConfig.getBatteryLabel());
}
if (batteryConfig.getBatteryIcon() != GBDevice.BATTERY_ICON_DEFAULT) {
battery_status_device_icon.setImageResource(batteryConfig.getBatteryIcon());
}
if (gbDevice.isInitialized()) { if (gbDevice.isInitialized()) {
battery_status_device_icon.setColorFilter(this.getResources().getColor(R.color.accent)); 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()); final Preference prefHeader = new PreferenceCategory(requireContext());
prefHeader.setKey("pref_battery_header_" + batteryConfig.getBatteryIndex()); prefHeader.setKey("pref_battery_header_" + batteryConfig.getBatteryIndex());
prefHeader.setIconSpaceReserved(false); prefHeader.setIconSpaceReserved(false);
if (batteryConfig.getBatteryLabel() > 0) { if (batteryConfig.getBatteryLabel() != GBDevice.BATTERY_LABEL_DEFAULT) {
prefHeader.setTitle(batteryConfig.getBatteryLabel()); prefHeader.setTitle(batteryConfig.getBatteryLabel());
} else { } else {
prefHeader.setTitle(requireContext().getString(R.string.battery_i, batteryConfig.getBatteryIndex())); 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 (this == o) return true;
if (!(o instanceof BatteryConfig)) return false; if (!(o instanceof BatteryConfig)) return false;
BatteryConfig that = (BatteryConfig) o; 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 @Override
public int hashCode() { public int hashCode() {
return Objects.hash(getBatteryIndex(), getBatteryIcon(), getBatteryLabel()); return Objects.hash(
getBatteryIndex(),
getBatteryIcon(),
getBatteryLabel(),
getDefaultLowThreshold(),
getDefaultFullThreshold()
);
} }
} }