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:
parent
6c6a2b1f38
commit
fa7e6f0919
1 changed files with 25 additions and 19 deletions
|
|
@ -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()
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue