Use requireActivity/Context in SettingsActivity

This commit is contained in:
xynngh 2020-10-02 15:56:47 +04:00
parent b921c58abf
commit 32ec2abf63
2 changed files with 12 additions and 13 deletions

View File

@ -11,7 +11,6 @@ import android.text.TextUtils;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
@ -52,7 +51,7 @@ public class PermissionHelper {
CONTACTS_PERMISSIONS.add(Manifest.permission.READ_CONTACTS);
}
public static void checkPermissions(AppCompatActivity activity, boolean info,
public static void checkPermissions(Activity activity, boolean info,
boolean block, boolean contacts) {
Set<String> requiredPermissions = new HashSet<>();

View File

@ -147,14 +147,14 @@ public class SettingsActivity extends AppCompatActivity
requireNonNull(findPreference(Settings.PREF_INCOMING_CALL_NOTIFICATIONS));
incomingCallNotificationPref.setOnPreferenceChangeListener((preference, newValue) -> {
if (Boolean.TRUE.equals(newValue)) {
PermissionHelper.checkPermissions((AppCompatActivity) getActivity(), true, false, false);
PermissionHelper.checkPermissions(requireActivity(), true, false, false);
}
return true;
});
Preference.OnPreferenceChangeListener callBlockingListener = (preference, newValue) -> {
if (Boolean.TRUE.equals(newValue)) {
PermissionHelper.checkPermissions((AppCompatActivity) getActivity(), false, true, false);
PermissionHelper.checkPermissions(requireActivity(), false, true, false);
}
return true;
};
@ -167,12 +167,12 @@ public class SettingsActivity extends AppCompatActivity
SwitchPreferenceCompat callScreeningPref =
requireNonNull(findPreference(PREF_USE_CALL_SCREENING_SERVICE));
callScreeningPref.setChecked(PermissionHelper.isCallScreeningHeld(getActivity()));
callScreeningPref.setChecked(PermissionHelper.isCallScreeningHeld(requireContext()));
callScreeningPref.setOnPreferenceChangeListener((preference, newValue) -> {
if (Boolean.TRUE.equals(newValue)) {
PermissionHelper.requestCallScreening(getActivity());
PermissionHelper.requestCallScreening(requireActivity());
} else {
Toast.makeText(getActivity(),
Toast.makeText(requireActivity(),
R.string.use_call_screening_service_disable_message,
Toast.LENGTH_LONG).show();
return false;
@ -216,7 +216,7 @@ public class SettingsActivity extends AppCompatActivity
requireNonNull(findPreference(Settings.PREF_USE_CONTACTS));
useContactsPref.setOnPreferenceChangeListener((preference, newValue) -> {
if (Boolean.TRUE.equals(newValue)) {
PermissionHelper.checkPermissions((AppCompatActivity) getActivity(), false, false, true);
PermissionHelper.checkPermissions(requireActivity(), false, false, true);
}
return true;
});
@ -251,7 +251,7 @@ public class SettingsActivity extends AppCompatActivity
requireNonNull((Preference) findPreference(PREF_DB_MANAGEMENT))
.setOnPreferenceClickListener(preference -> {
startActivity(new Intent(getActivity(), DbManagementActivity.class));
startActivity(new Intent(requireContext(), DbManagementActivity.class));
return true;
});
@ -263,7 +263,7 @@ public class SettingsActivity extends AppCompatActivity
= requireNonNull(findPreference(PREF_COUNTRY_CODES_INFO));
countryCodesInfoPreference.setSummary(countryCodesExplanationSummary);
countryCodesInfoPreference.setOnPreferenceClickListener(preference -> {
new AlertDialog.Builder(getActivity())
new AlertDialog.Builder(requireActivity())
.setTitle(R.string.settings_category_country_codes)
.setMessage(countryCodesExplanationSummary)
.setNegativeButton(R.string.back, null)
@ -278,7 +278,7 @@ public class SettingsActivity extends AppCompatActivity
return true;
}
Toast.makeText(getActivity(), R.string.country_code_incorrect_format,
Toast.makeText(requireActivity(), R.string.country_code_incorrect_format,
Toast.LENGTH_SHORT).show();
return false;
};
@ -301,11 +301,11 @@ public class SettingsActivity extends AppCompatActivity
public void updateCallScreeningPreference() {
SwitchPreferenceCompat callScreeningPref =
requireNonNull(findPreference(PREF_USE_CALL_SCREENING_SERVICE));
callScreeningPref.setChecked(PermissionHelper.isCallScreeningHeld(getActivity()));
callScreeningPref.setChecked(PermissionHelper.isCallScreeningHeld(requireContext()));
}
private void exportLogcat() {
Activity activity = getActivity();
Activity activity = requireActivity();
String path = null;
try {