1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-29 13:26: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,8 +131,11 @@ public class LoyaltyCardsSettingsFragment extends PreferenceFragmentCompat {
return true; return true;
}); });
if (StringUtils.isNullOrEmpty(catimaPackage.getValue()) || !installedCatimaPackages.contains(catimaPackage.getValue())) { if (catimaInstalled) {
catimaPackage.setValue(installedCatimaPackages.get(0).toString()); // Ensure the currently selected value is actually an installed Catima package
if (StringUtils.isNullOrEmpty(catimaPackage.getValue()) || !installedCatimaPackages.contains(catimaPackage.getValue())) {
catimaPackage.setValue(installedCatimaPackages.get(0).toString());
}
} }
if (installedCatimaPackages.size() <= 1) { if (installedCatimaPackages.size() <= 1) {
@ -172,19 +175,17 @@ 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(catimaInstalled && !permissionGranted);
catimaPermissions.setVisible(!permissionGranted); catimaPermissions.setOnPreferenceClickListener(preference -> {
catimaPermissions.setOnPreferenceClickListener(preference -> { ActivityCompat.requestPermissions(
ActivityCompat.requestPermissions( requireActivity(),
requireActivity(), new String[]{CatimaContentProvider.PERMISSION_READ_CARDS},
new String[]{CatimaContentProvider.PERMISSION_READ_CARDS}, LoyaltyCardsSettingsActivity.PERMISSION_REQUEST_CODE
LoyaltyCardsSettingsActivity.PERMISSION_REQUEST_CODE );
); return true;
return true; });
});
}
} }
final boolean catimaCompatible = catima != null && catima.isCatimaCompatible(); final boolean catimaCompatible = catima != null && catima.isCatimaCompatible();