mirror of
https://github.com/ArcaneChat/android.git
synced 2026-07-03 14:05:24 +02:00
avoid deprecated AdvancedPreferenceFragment.onActivityResult()
This commit is contained in:
+13
-9
@@ -18,6 +18,8 @@ import android.view.View;
|
||||
import android.widget.EditText;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.activity.result.ActivityResultLauncher;
|
||||
import androidx.activity.result.contract.ActivityResultContracts;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
@@ -55,11 +57,21 @@ public class AdvancedPreferenceFragment extends ListSummaryPreferenceFragment
|
||||
CheckBoxPreference multiDeviceCheckbox;
|
||||
CheckBoxPreference mvboxMoveCheckbox;
|
||||
CheckBoxPreference onlyFetchMvboxCheckbox;
|
||||
private ActivityResultLauncher<Intent> screenLockLauncher;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle paramBundle) {
|
||||
super.onCreate(paramBundle);
|
||||
|
||||
screenLockLauncher = registerForActivityResult(
|
||||
new ActivityResultContracts.StartActivityForResult(),
|
||||
result -> {
|
||||
if (result.getResultCode() == RESULT_OK) {
|
||||
openRelayListActivity();
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
showEmails = (ListPreference) this.findPreference("pref_show_emails");
|
||||
if (showEmails != null) {
|
||||
showEmails.setOnPreferenceChangeListener((preference, newValue) -> {
|
||||
@@ -211,7 +223,7 @@ public class AdvancedPreferenceFragment extends ListSummaryPreferenceFragment
|
||||
Preference relayListBtn = this.findPreference("pref_relay_list_button");
|
||||
if (relayListBtn != null) {
|
||||
relayListBtn.setOnPreferenceClickListener(((preference) -> {
|
||||
boolean result = ScreenLockUtil.applyScreenLock(requireActivity(), getString(R.string.transports), getString(R.string.enter_system_secret_to_continue), REQUEST_CODE_CONFIRM_CREDENTIALS_ACCOUNT);
|
||||
boolean result = ScreenLockUtil.applyScreenLock(requireActivity(), getString(R.string.transports), getString(R.string.enter_system_secret_to_continue), screenLockLauncher);
|
||||
if (!result) {
|
||||
openRelayListActivity();
|
||||
}
|
||||
@@ -244,14 +256,6 @@ public class AdvancedPreferenceFragment extends ListSummaryPreferenceFragment
|
||||
onlyFetchMvboxCheckbox.setChecked(0!=dcContext.getConfigInt(CONFIG_ONLY_FETCH_MVBOX));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
if (resultCode == RESULT_OK && requestCode == REQUEST_CODE_CONFIRM_CREDENTIALS_ACCOUNT) {
|
||||
openRelayListActivity();
|
||||
}
|
||||
}
|
||||
|
||||
protected File copyToCacheDir(Uri uri) throws IOException {
|
||||
try (InputStream inputStream = requireActivity().getContentResolver().openInputStream(uri)) {
|
||||
File file = File.createTempFile("tmp-keys-file", ".tmp", requireActivity().getCacheDir());
|
||||
|
||||
@@ -5,6 +5,8 @@ import android.app.KeyguardManager;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
||||
import androidx.activity.result.ActivityResultLauncher;
|
||||
|
||||
public class ScreenLockUtil {
|
||||
|
||||
public static final int REQUEST_CODE_CONFIRM_CREDENTIALS = 1001;
|
||||
@@ -22,4 +24,17 @@ public class ScreenLockUtil {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean applyScreenLock(Activity activity, String title, String descr, ActivityResultLauncher<Intent> launcher) {
|
||||
KeyguardManager keyguardManager = (KeyguardManager) activity.getSystemService(Context.KEYGUARD_SERVICE);
|
||||
Intent intent;
|
||||
if (keyguardManager != null) {
|
||||
intent = keyguardManager.createConfirmDeviceCredentialIntent(title, descr);
|
||||
if (intent != null) {
|
||||
launcher.launch(intent);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user