That fuck shit the fascists are using
1package org.tm.archive.preferences;
2
3import android.content.Intent;
4import android.os.Bundle;
5
6import androidx.annotation.Nullable;
7import androidx.preference.Preference;
8
9import com.google.android.material.dialog.MaterialAlertDialogBuilder;
10import com.google.android.material.snackbar.Snackbar;
11
12import org.tm.archive.R;
13import org.tm.archive.keyvalue.SignalStore;
14import org.tm.archive.lock.v2.CreateSvrPinActivity;
15import org.tm.archive.payments.backup.PaymentsRecoveryStartFragmentArgs;
16import org.tm.archive.payments.preferences.PaymentsActivity;
17import org.tm.archive.pin.PinOptOutDialog;
18
19public class AdvancedPinPreferenceFragment extends ListSummaryPreferenceFragment {
20
21 private static final String PREF_ENABLE = "pref_pin_enable";
22 private static final String PREF_DISABLE = "pref_pin_disable";
23
24 @Override
25 public void onCreate(Bundle paramBundle) {
26 super.onCreate(paramBundle);
27 }
28
29 @Override
30 public void onCreatePreferences(@Nullable Bundle savedInstanceState, String rootKey) {
31 addPreferencesFromResource(R.xml.preferences_advanced_pin);
32 }
33
34 @Override
35 public void onResume() {
36 super.onResume();
37 updatePreferenceState();
38 }
39
40 @Override
41 public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
42 if (requestCode == CreateSvrPinActivity.REQUEST_NEW_PIN && resultCode == CreateSvrPinActivity.RESULT_OK) {
43 Snackbar.make(requireView(), R.string.ApplicationPreferencesActivity_pin_created, Snackbar.LENGTH_LONG).show();
44 }
45 }
46
47 private void updatePreferenceState() {
48 Preference enable = this.findPreference(PREF_ENABLE);
49 Preference disable = this.findPreference(PREF_DISABLE);
50
51 if (SignalStore.svr().hasOptedOut()) {
52 enable.setVisible(true);
53 disable.setVisible(false);
54
55 enable.setOnPreferenceClickListener(preference -> {
56 onPreferenceChanged(true);
57 return true;
58 });
59 } else {
60 enable.setVisible(false);
61 disable.setVisible(true);
62
63 disable.setOnPreferenceClickListener(preference -> {
64 onPreferenceChanged(false);
65 return true;
66 });
67 }
68 }
69
70 private void onPreferenceChanged(boolean enabled) {
71 boolean hasRegistrationLock = SignalStore.svr().isRegistrationLockEnabled();
72
73 if (!enabled && hasRegistrationLock) {
74 new MaterialAlertDialogBuilder(requireContext())
75 .setMessage(R.string.ApplicationPreferencesActivity_pins_are_required_for_registration_lock)
76 .setCancelable(true)
77 .setPositiveButton(android.R.string.ok, (d, which) -> d.dismiss())
78 .show();
79 } else if (!enabled && SignalStore.paymentsValues().mobileCoinPaymentsEnabled() && !SignalStore.paymentsValues().getUserConfirmedMnemonic()) {
80 new MaterialAlertDialogBuilder(requireContext())
81 .setTitle(R.string.ApplicationPreferencesActivity_record_payments_recovery_phrase)
82 .setMessage(R.string.ApplicationPreferencesActivity_before_you_can_disable_your_pin)
83 .setPositiveButton(R.string.ApplicationPreferencesActivity_record_phrase, (dialog, which) -> {
84 Intent intent = new Intent(requireContext(), PaymentsActivity.class);
85 intent.putExtra(PaymentsActivity.EXTRA_PAYMENTS_STARTING_ACTION, R.id.action_directly_to_paymentsBackup);
86 intent.putExtra(PaymentsActivity.EXTRA_STARTING_ARGUMENTS, new PaymentsRecoveryStartFragmentArgs.Builder().setFinishOnConfirm(true).build().toBundle());
87
88 startActivity(intent);
89
90 dialog.dismiss();
91 })
92 .setNegativeButton(android.R.string.cancel, (dialog, which) -> dialog.dismiss())
93 .setCancelable(true)
94 .show();
95 } else if (!enabled) {
96 PinOptOutDialog.show(requireContext(),
97 () -> {
98 updatePreferenceState();
99 Snackbar.make(requireView(), R.string.ApplicationPreferencesActivity_pin_disabled, Snackbar.LENGTH_SHORT).show();
100 });
101 } else {
102 startActivityForResult(CreateSvrPinActivity.getIntentForPinCreate(requireContext()), CreateSvrPinActivity.REQUEST_NEW_PIN);
103 }
104 }
105}