BatteryTip: Hide Learn more button if URL is empty

When help_url_battery_defender is empty, tapping on Learn more button
causes a NPE.

Issue: calyxos#2809
Change-Id: Ib1c52dcff430cae7c4bc0793120ace837f5bf4c7
This commit is contained in:
Michael Bestas 2024-11-08 12:02:56 +02:00 committed by Michael Bestas
parent 91d0faa4aa
commit 3df966cc65
No known key found for this signature in database

View file

@ -87,26 +87,28 @@ public class BatteryDefenderTip extends BatteryTip {
cardPreference.setSelectable(false);
cardPreference.setIconResId(getIconId());
cardPreference.setPrimaryButtonText(context.getString(R.string.learn_more));
cardPreference.setPrimaryButtonAction(
() -> {
var helpIntent =
HelpUtils.getHelpIntent(
context,
context.getString(R.string.help_url_battery_defender),
/* backupContext= */ "");
ActivityCompat.startActivityForResult(
(Activity) preference.getContext(),
helpIntent,
/* requestCode= */ 0,
/* options= */ null);
return Unit.INSTANCE;
});
cardPreference.setPrimaryButtonVisibility(true);
cardPreference.setPrimaryButtonContentDescription(
context.getString(
R.string.battery_tip_limited_temporarily_sec_button_content_description));
if (getHelpResource() != 0) {
cardPreference.setPrimaryButtonText(context.getString(R.string.learn_more));
cardPreference.setPrimaryButtonAction(
() -> {
var helpIntent =
HelpUtils.getHelpIntent(
context,
context.getString(getHelpResource()),
/* backupContext= */ "");
ActivityCompat.startActivityForResult(
(Activity) preference.getContext(),
helpIntent,
/* requestCode= */ 0,
/* options= */ null);
return Unit.INSTANCE;
});
cardPreference.setPrimaryButtonVisibility(true);
cardPreference.setPrimaryButtonContentDescription(context.getString(
R.string.battery_tip_limited_temporarily_sec_button_content_description));
}
cardPreference.setSecondaryButtonText(
context.getString(R.string.battery_tip_charge_to_full_button));
@ -121,6 +123,10 @@ public class BatteryDefenderTip extends BatteryTip {
cardPreference.buildContent();
}
private int getHelpResource() {
return R.string.help_url_battery_defender;
}
private void resumeCharging(Context context) {
final Intent intent =
FeatureFactory.getFeatureFactory()