mirror of
https://gitlab.com/xynngh/YetAnotherCallBlocker.git
synced 2025-02-13 18:20:45 +01:00
Use requireActivity/Context in SettingsActivity
This commit is contained in:
parent
b921c58abf
commit
32ec2abf63
@ -11,7 +11,6 @@ import android.text.TextUtils;
|
|||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
|
||||||
import androidx.core.app.ActivityCompat;
|
import androidx.core.app.ActivityCompat;
|
||||||
import androidx.core.content.ContextCompat;
|
import androidx.core.content.ContextCompat;
|
||||||
|
|
||||||
@ -52,7 +51,7 @@ public class PermissionHelper {
|
|||||||
CONTACTS_PERMISSIONS.add(Manifest.permission.READ_CONTACTS);
|
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) {
|
boolean block, boolean contacts) {
|
||||||
Set<String> requiredPermissions = new HashSet<>();
|
Set<String> requiredPermissions = new HashSet<>();
|
||||||
|
|
||||||
|
@ -147,14 +147,14 @@ public class SettingsActivity extends AppCompatActivity
|
|||||||
requireNonNull(findPreference(Settings.PREF_INCOMING_CALL_NOTIFICATIONS));
|
requireNonNull(findPreference(Settings.PREF_INCOMING_CALL_NOTIFICATIONS));
|
||||||
incomingCallNotificationPref.setOnPreferenceChangeListener((preference, newValue) -> {
|
incomingCallNotificationPref.setOnPreferenceChangeListener((preference, newValue) -> {
|
||||||
if (Boolean.TRUE.equals(newValue)) {
|
if (Boolean.TRUE.equals(newValue)) {
|
||||||
PermissionHelper.checkPermissions((AppCompatActivity) getActivity(), true, false, false);
|
PermissionHelper.checkPermissions(requireActivity(), true, false, false);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
|
||||||
Preference.OnPreferenceChangeListener callBlockingListener = (preference, newValue) -> {
|
Preference.OnPreferenceChangeListener callBlockingListener = (preference, newValue) -> {
|
||||||
if (Boolean.TRUE.equals(newValue)) {
|
if (Boolean.TRUE.equals(newValue)) {
|
||||||
PermissionHelper.checkPermissions((AppCompatActivity) getActivity(), false, true, false);
|
PermissionHelper.checkPermissions(requireActivity(), false, true, false);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
@ -167,12 +167,12 @@ public class SettingsActivity extends AppCompatActivity
|
|||||||
|
|
||||||
SwitchPreferenceCompat callScreeningPref =
|
SwitchPreferenceCompat callScreeningPref =
|
||||||
requireNonNull(findPreference(PREF_USE_CALL_SCREENING_SERVICE));
|
requireNonNull(findPreference(PREF_USE_CALL_SCREENING_SERVICE));
|
||||||
callScreeningPref.setChecked(PermissionHelper.isCallScreeningHeld(getActivity()));
|
callScreeningPref.setChecked(PermissionHelper.isCallScreeningHeld(requireContext()));
|
||||||
callScreeningPref.setOnPreferenceChangeListener((preference, newValue) -> {
|
callScreeningPref.setOnPreferenceChangeListener((preference, newValue) -> {
|
||||||
if (Boolean.TRUE.equals(newValue)) {
|
if (Boolean.TRUE.equals(newValue)) {
|
||||||
PermissionHelper.requestCallScreening(getActivity());
|
PermissionHelper.requestCallScreening(requireActivity());
|
||||||
} else {
|
} else {
|
||||||
Toast.makeText(getActivity(),
|
Toast.makeText(requireActivity(),
|
||||||
R.string.use_call_screening_service_disable_message,
|
R.string.use_call_screening_service_disable_message,
|
||||||
Toast.LENGTH_LONG).show();
|
Toast.LENGTH_LONG).show();
|
||||||
return false;
|
return false;
|
||||||
@ -216,7 +216,7 @@ public class SettingsActivity extends AppCompatActivity
|
|||||||
requireNonNull(findPreference(Settings.PREF_USE_CONTACTS));
|
requireNonNull(findPreference(Settings.PREF_USE_CONTACTS));
|
||||||
useContactsPref.setOnPreferenceChangeListener((preference, newValue) -> {
|
useContactsPref.setOnPreferenceChangeListener((preference, newValue) -> {
|
||||||
if (Boolean.TRUE.equals(newValue)) {
|
if (Boolean.TRUE.equals(newValue)) {
|
||||||
PermissionHelper.checkPermissions((AppCompatActivity) getActivity(), false, false, true);
|
PermissionHelper.checkPermissions(requireActivity(), false, false, true);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
@ -251,7 +251,7 @@ public class SettingsActivity extends AppCompatActivity
|
|||||||
|
|
||||||
requireNonNull((Preference) findPreference(PREF_DB_MANAGEMENT))
|
requireNonNull((Preference) findPreference(PREF_DB_MANAGEMENT))
|
||||||
.setOnPreferenceClickListener(preference -> {
|
.setOnPreferenceClickListener(preference -> {
|
||||||
startActivity(new Intent(getActivity(), DbManagementActivity.class));
|
startActivity(new Intent(requireContext(), DbManagementActivity.class));
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -263,7 +263,7 @@ public class SettingsActivity extends AppCompatActivity
|
|||||||
= requireNonNull(findPreference(PREF_COUNTRY_CODES_INFO));
|
= requireNonNull(findPreference(PREF_COUNTRY_CODES_INFO));
|
||||||
countryCodesInfoPreference.setSummary(countryCodesExplanationSummary);
|
countryCodesInfoPreference.setSummary(countryCodesExplanationSummary);
|
||||||
countryCodesInfoPreference.setOnPreferenceClickListener(preference -> {
|
countryCodesInfoPreference.setOnPreferenceClickListener(preference -> {
|
||||||
new AlertDialog.Builder(getActivity())
|
new AlertDialog.Builder(requireActivity())
|
||||||
.setTitle(R.string.settings_category_country_codes)
|
.setTitle(R.string.settings_category_country_codes)
|
||||||
.setMessage(countryCodesExplanationSummary)
|
.setMessage(countryCodesExplanationSummary)
|
||||||
.setNegativeButton(R.string.back, null)
|
.setNegativeButton(R.string.back, null)
|
||||||
@ -278,7 +278,7 @@ public class SettingsActivity extends AppCompatActivity
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Toast.makeText(getActivity(), R.string.country_code_incorrect_format,
|
Toast.makeText(requireActivity(), R.string.country_code_incorrect_format,
|
||||||
Toast.LENGTH_SHORT).show();
|
Toast.LENGTH_SHORT).show();
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
@ -301,11 +301,11 @@ public class SettingsActivity extends AppCompatActivity
|
|||||||
public void updateCallScreeningPreference() {
|
public void updateCallScreeningPreference() {
|
||||||
SwitchPreferenceCompat callScreeningPref =
|
SwitchPreferenceCompat callScreeningPref =
|
||||||
requireNonNull(findPreference(PREF_USE_CALL_SCREENING_SERVICE));
|
requireNonNull(findPreference(PREF_USE_CALL_SCREENING_SERVICE));
|
||||||
callScreeningPref.setChecked(PermissionHelper.isCallScreeningHeld(getActivity()));
|
callScreeningPref.setChecked(PermissionHelper.isCallScreeningHeld(requireContext()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void exportLogcat() {
|
private void exportLogcat() {
|
||||||
Activity activity = getActivity();
|
Activity activity = requireActivity();
|
||||||
|
|
||||||
String path = null;
|
String path = null;
|
||||||
try {
|
try {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user