Payments.

Co-authored-by: Alan Evans <alan@signal.org>
Co-authored-by: Alex Hart <alex@signal.org>
Co-authored-by: Cody Henthorne <cody@signal.org>
This commit is contained in:
Android Team
2021-04-06 13:03:33 -03:00
committed by Alan Evans
parent c42023855b
commit fddba2906a
311 changed files with 18956 additions and 235 deletions

View File

@@ -14,6 +14,8 @@ import org.thoughtcrime.securesms.ApplicationPreferencesActivity;
import org.thoughtcrime.securesms.R;
import org.thoughtcrime.securesms.keyvalue.SignalStore;
import org.thoughtcrime.securesms.lock.v2.CreateKbsPinActivity;
import org.thoughtcrime.securesms.payments.backup.PaymentsRecoveryStartFragmentArgs;
import org.thoughtcrime.securesms.payments.preferences.PaymentsActivity;
import org.thoughtcrime.securesms.pin.PinOptOutDialog;
import org.thoughtcrime.securesms.util.TextSecurePreferences;
@@ -80,6 +82,22 @@ public class AdvancedPinPreferenceFragment extends ListSummaryPreferenceFragment
.setCancelable(true)
.setPositiveButton(android.R.string.ok, (d, which) -> d.dismiss())
.show();
} else if (!enabled && SignalStore.paymentsValues().mobileCoinPaymentsEnabled() && !SignalStore.paymentsValues().userConfirmedMnemonic()) {
new AlertDialog.Builder(requireContext())
.setTitle(R.string.ApplicationPreferencesActivity_record_payments_recovery_phrase)
.setMessage(R.string.ApplicationPreferencesActivity_before_you_can_disable_your_pin)
.setPositiveButton(R.string.ApplicationPreferencesActivity_record_phrase, (dialog, which) -> {
Intent intent = new Intent(requireContext(), PaymentsActivity.class);
intent.putExtra(PaymentsActivity.EXTRA_PAYMENTS_STARTING_ACTION, R.id.action_directly_to_paymentsBackup);
intent.putExtra(PaymentsActivity.EXTRA_STARTING_ARGUMENTS, new PaymentsRecoveryStartFragmentArgs.Builder().setFinishOnConfirm(true).build().toBundle());
startActivity(intent);
dialog.dismiss();
})
.setNegativeButton(android.R.string.cancel, (dialog, which) -> dialog.dismiss())
.setCancelable(true)
.show();
} else if (!enabled) {
PinOptOutDialog.show(requireContext(),
() -> {

View File

@@ -32,14 +32,18 @@ import org.thoughtcrime.securesms.delete.DeleteAccountFragment;
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies;
import org.thoughtcrime.securesms.keyvalue.SignalStore;
import org.thoughtcrime.securesms.logsubmit.SubmitDebugLogActivity;
import org.thoughtcrime.securesms.payments.preferences.PaymentsActivity;
import org.thoughtcrime.securesms.payments.preferences.transfer.PaymentsTransferFragmentArgs;
import org.thoughtcrime.securesms.phonenumbers.PhoneNumberFormatter;
import org.thoughtcrime.securesms.registration.RegistrationNavigationActivity;
import org.thoughtcrime.securesms.util.DynamicTheme;
import org.thoughtcrime.securesms.util.FeatureFlags;
import org.thoughtcrime.securesms.util.SpanUtil;
import org.thoughtcrime.securesms.util.TextSecurePreferences;
import org.thoughtcrime.securesms.util.task.ProgressDialogAsyncTask;
import org.whispersystems.libsignal.util.guava.Optional;
import org.whispersystems.signalservice.api.SignalServiceAccountManager;
import org.whispersystems.signalservice.api.payments.FormatterOptions;
import org.whispersystems.signalservice.api.payments.Money;
import org.whispersystems.signalservice.api.push.exceptions.AuthorizationFailedException;
import java.io.IOException;
@@ -54,6 +58,7 @@ public class AdvancedPreferenceFragment extends CorrectedPreferenceFragment {
private static final String DELETE_ACCOUNT = "pref_delete_account";
private static final int PICK_IDENTITY_CONTACT = 1;
private static final int TRANSFER_CURRENCY = 2;
@Override
public void onCreate(Bundle paramBundle) {
@@ -84,7 +89,27 @@ public class AdvancedPreferenceFragment extends CorrectedPreferenceFragment {
Preference deleteAccount = this.findPreference(DELETE_ACCOUNT);
deleteAccount.setOnPreferenceClickListener(preference -> {
getApplicationPreferencesActivity().pushFragment(new DeleteAccountFragment());
Money.MobileCoin latestBalance = SignalStore.paymentsValues().mobileCoinLatestBalance().getFullAmount().requireMobileCoin();
if (!latestBalance.equals(Money.MobileCoin.ZERO)) {
new AlertDialog.Builder(requireContext())
.setTitle(R.string.AdvancedPreferenceFragment__transfer_mob_balance)
.setMessage(getString(R.string.AdvancedPreferenceFragment__you_have_a_balance_of_s, latestBalance.toString(FormatterOptions.defaults())))
.setPositiveButton(R.string.AdvancedPreferenceFragment__transfer, (dialog, which) -> {
Intent intent = new Intent(requireContext(), PaymentsActivity.class);
intent.putExtra(PaymentsActivity.EXTRA_PAYMENTS_STARTING_ACTION, R.id.action_directly_to_paymentsTransfer);
intent.putExtra(PaymentsActivity.EXTRA_STARTING_ARGUMENTS, new PaymentsTransferFragmentArgs.Builder().setFinishOnConfirm(true).build().toBundle());
startActivityForResult(intent, TRANSFER_CURRENCY);
dialog.dismiss();
})
.setNegativeButton(SpanUtil.color(ContextCompat.getColor(requireContext(), R.color.signal_alert_primary), getString(R.string.AdvancedPreferenceFragment__dont_transfer)), (dialog, which) -> {
getApplicationPreferencesActivity().pushFragment(new DeleteAccountFragment());
dialog.dismiss();
})
.show();
} else {
getApplicationPreferencesActivity().pushFragment(new DeleteAccountFragment());
}
return false;
});
}
@@ -123,6 +148,8 @@ public class AdvancedPreferenceFragment extends CorrectedPreferenceFragment {
Log.i(TAG, "Got result: " + resultCode + " for req: " + reqCode);
if (resultCode == Activity.RESULT_OK && reqCode == PICK_IDENTITY_CONTACT) {
handleIdentitySelection(data);
} else if (resultCode == Activity.RESULT_OK && reqCode == TRANSFER_CURRENCY) {
getApplicationPreferencesActivity().pushFragment(new DeleteAccountFragment());
}
}

View File

@@ -1,5 +1,8 @@
package org.thoughtcrime.securesms.preferences;
import android.app.AlertDialog;
import android.content.ClipData;
import android.content.Context;
import android.os.Bundle;
import android.widget.Toast;
@@ -7,6 +10,7 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.preference.PreferenceDataStore;
import org.signal.core.util.concurrent.SignalExecutors;
import org.signal.core.util.logging.Log;
import org.thoughtcrime.securesms.ApplicationPreferencesActivity;
import org.thoughtcrime.securesms.R;
@@ -19,7 +23,9 @@ import org.thoughtcrime.securesms.jobs.RotateProfileKeyJob;
import org.thoughtcrime.securesms.jobs.StorageForcePushJob;
import org.thoughtcrime.securesms.keyvalue.InternalValues;
import org.thoughtcrime.securesms.keyvalue.SignalStore;
import org.thoughtcrime.securesms.payments.DataExportUtil;
import org.thoughtcrime.securesms.util.ConversationUtil;
import org.thoughtcrime.securesms.util.concurrent.SimpleTask;
public class InternalOptionsPreferenceFragment extends CorrectedPreferenceFragment {
private static final String TAG = Log.tag(InternalOptionsPreferenceFragment.class);
@@ -44,6 +50,30 @@ public class InternalOptionsPreferenceFragment extends CorrectedPreferenceFragme
initializeSwitchPreference(preferenceDataStore, InternalValues.GV2_DISABLE_AUTOMIGRATE_NOTIFICATION, SignalStore.internalValues().disableGv1AutoMigrateNotification());
initializeSwitchPreference(preferenceDataStore, InternalValues.FORCE_CENSORSHIP, SignalStore.internalValues().forcedCensorship());
findPreference("pref_copy_payments_data").setOnPreferenceClickListener(preference -> {
new AlertDialog.Builder(getContext())
.setMessage("Local payments history will be copied to the clipboard.\n" +
"It may therefore compromise privacy.\n" +
"However, no private keys will be copied.")
.setPositiveButton("Copy", (dialog, which) -> {
SimpleTask.run(SignalExecutors.UNBOUNDED,
() -> {
Context context = ApplicationDependencies.getApplication();
android.content.ClipboardManager clipboard =
(android.content.ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
String tsv = DataExportUtil.createTsv();
ClipData clip = ClipData.newPlainText(context.getString(R.string.app_name), tsv);
clipboard.setPrimaryClip(clip);
return null;
},
r -> Toast.makeText(getContext(), "Payments have been copied", Toast.LENGTH_SHORT).show()
);
})
.setNegativeButton(android.R.string.cancel, null)
.show();
return true;
});
findPreference("pref_refresh_attributes").setOnPreferenceClickListener(preference -> {
ApplicationDependencies.getJobManager()
.startChain(new RefreshAttributesJob())

View File

@@ -137,7 +137,7 @@ public class StoragePreferenceFragment extends ListSummaryPreferenceFragment {
public @NonNull MappingModelList getSettings() {
KeepMessagesDuration currentDuration = SignalStore.settings().getKeepMessagesDuration();
return Stream.of(KeepMessagesDuration.values())
.map(duration -> new SingleSelectSetting.Item(duration, activity.getString(duration.getStringResource()), duration.equals(currentDuration)))
.map(duration -> new SingleSelectSetting.Item(duration, activity.getString(duration.getStringResource()), null, duration.equals(currentDuration)))
.collect(MappingModelList.toMappingModelList());
}
@@ -187,7 +187,7 @@ public class StoragePreferenceFragment extends ListSummaryPreferenceFragment {
String text = option == 0 ? activity.getString(R.string.preferences_storage__none)
: activity.getString(R.string.preferences_storage__s_messages, NumberFormat.getInstance().format(option));
settings.add(new SingleSelectSetting.Item(option, text, isSelected));
settings.add(new SingleSelectSetting.Item(option, text, null, isSelected));
hasSelection = hasSelection || isSelected;
}

View File

@@ -0,0 +1,59 @@
package org.thoughtcrime.securesms.preferences.widgets;
import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.TextView;
import androidx.preference.Preference;
import androidx.preference.PreferenceViewHolder;
import org.thoughtcrime.securesms.R;
public class PaymentsPreference extends Preference {
private TextView unreadIndicator;
private int unreadCount;
public PaymentsPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
initialize();
}
public PaymentsPreference(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
initialize();
}
public PaymentsPreference(Context context, AttributeSet attrs) {
super(context, attrs);
initialize();
}
public PaymentsPreference(Context context) {
super(context);
initialize();
}
private void initialize() {
setLayoutResource(R.layout.payments_preference);
}
@Override
public void onBindViewHolder(PreferenceViewHolder holder) {
super.onBindViewHolder(holder);
unreadIndicator = holder.itemView.findViewById(R.id.unread_indicator);
setUnreadCount(unreadCount);
}
public void setUnreadCount(int unreadCount) {
this.unreadCount = unreadCount;
if (unreadIndicator != null) {
unreadIndicator.setVisibility(unreadCount > 0 ? View.VISIBLE : View.GONE);
unreadIndicator.setText(String.valueOf(unreadCount));
}
}
}