1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-25 19:36:50 +01:00

Fix crash if Catima is not installed

This commit is contained in:
José Rebelo 2023-07-04 09:43:35 +01:00
parent fea3bf50a4
commit 3516099dc9

View File

@ -131,9 +131,12 @@ public class LoyaltyCardsSettingsFragment extends PreferenceFragmentCompat {
return true; return true;
}); });
if (catimaInstalled) {
// Ensure the currently selected value is actually an installed Catima package
if (StringUtils.isNullOrEmpty(catimaPackage.getValue()) || !installedCatimaPackages.contains(catimaPackage.getValue())) { if (StringUtils.isNullOrEmpty(catimaPackage.getValue()) || !installedCatimaPackages.contains(catimaPackage.getValue())) {
catimaPackage.setValue(installedCatimaPackages.get(0).toString()); catimaPackage.setValue(installedCatimaPackages.get(0).toString());
} }
}
if (installedCatimaPackages.size() <= 1) { if (installedCatimaPackages.size() <= 1) {
catimaPackage.setVisible(false); catimaPackage.setVisible(false);
@ -172,10 +175,9 @@ public class LoyaltyCardsSettingsFragment extends PreferenceFragmentCompat {
} }
final boolean permissionGranted = ContextCompat.checkSelfPermission(requireContext(), CatimaContentProvider.PERMISSION_READ_CARDS) == PackageManager.PERMISSION_GRANTED; final boolean permissionGranted = ContextCompat.checkSelfPermission(requireContext(), CatimaContentProvider.PERMISSION_READ_CARDS) == PackageManager.PERMISSION_GRANTED;
if (catimaInstalled) {
final Preference catimaPermissions = findPreference(LOYALTY_CARDS_CATIMA_PERMISSIONS); final Preference catimaPermissions = findPreference(LOYALTY_CARDS_CATIMA_PERMISSIONS);
if (catimaPermissions != null) { if (catimaPermissions != null) {
catimaPermissions.setVisible(!permissionGranted); catimaPermissions.setVisible(catimaInstalled && !permissionGranted);
catimaPermissions.setOnPreferenceClickListener(preference -> { catimaPermissions.setOnPreferenceClickListener(preference -> {
ActivityCompat.requestPermissions( ActivityCompat.requestPermissions(
requireActivity(), requireActivity(),
@ -185,7 +187,6 @@ public class LoyaltyCardsSettingsFragment extends PreferenceFragmentCompat {
return true; return true;
}); });
} }
}
final boolean catimaCompatible = catima != null && catima.isCatimaCompatible(); final boolean catimaCompatible = catima != null && catima.isCatimaCompatible();
final Preference catimaNotCompatible = findPreference(LOYALTY_CARDS_CATIMA_NOT_COMPATIBLE); final Preference catimaNotCompatible = findPreference(LOYALTY_CARDS_CATIMA_NOT_COMPATIBLE);