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

@@ -38,10 +38,12 @@ import org.thoughtcrime.securesms.util.SpanUtil;
import org.thoughtcrime.securesms.util.ViewUtil;
import org.thoughtcrime.securesms.util.text.AfterTextChanged;
import org.thoughtcrime.securesms.util.views.SimpleProgressDialog;
import org.whispersystems.libsignal.util.guava.Optional;
public class DeleteAccountFragment extends Fragment {
private ArrayAdapter<String> countrySpinnerAdapter;
private TextView bullets;
private LabeledEditText countryCode;
private LabeledEditText number;
private AsYouTypeFormatter countryFormatter;
@@ -55,10 +57,10 @@ public class DeleteAccountFragment extends Fragment {
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
TextView bullets = view.findViewById(R.id.delete_account_fragment_bullets);
Spinner countrySpinner = view.findViewById(R.id.delete_account_fragment_country_spinner);
View confirm = view.findViewById(R.id.delete_account_fragment_delete);
bullets = view.findViewById(R.id.delete_account_fragment_bullets);
countryCode = view.findViewById(R.id.delete_account_fragment_country_code);
number = view.findViewById(R.id.delete_account_fragment_number);
@@ -67,6 +69,7 @@ public class DeleteAccountFragment extends Fragment {
viewModel.getCountryDisplayName().observe(getViewLifecycleOwner(), this::setCountryDisplay);
viewModel.getRegionCode().observe(getViewLifecycleOwner(), this::handleRegionUpdated);
viewModel.getEvents().observe(getViewLifecycleOwner(), this::handleEvent);
viewModel.getWalletBalance().observe(getViewLifecycleOwner(), this::updateBullets);
initializeNumberInput();
@@ -74,7 +77,6 @@ public class DeleteAccountFragment extends Fragment {
countryCode.getInput().setImeOptions(EditorInfo.IME_ACTION_NEXT);
confirm.setOnClickListener(unused -> viewModel.submit());
bullets.setText(buildBulletsText());
initializeSpinner(countrySpinner);
}
@@ -84,10 +86,21 @@ public class DeleteAccountFragment extends Fragment {
((ApplicationPreferencesActivity) getActivity()).getSupportActionBar().setTitle(R.string.preferences__delete_account);
}
private @NonNull CharSequence buildBulletsText() {
return new SpannableStringBuilder().append(SpanUtil.bullet(getString(R.string.DeleteAccountFragment__delete_your_account_info_and_profile_photo)))
.append("\n")
.append(SpanUtil.bullet(getString(R.string.DeleteAccountFragment__delete_all_your_messages)));
private void updateBullets(@NonNull Optional<String> formattedBalance) {
bullets.setText(buildBulletsText(formattedBalance));
}
private @NonNull CharSequence buildBulletsText(@NonNull Optional<String> formattedBalance) {
SpannableStringBuilder builder = new SpannableStringBuilder().append(SpanUtil.bullet(getString(R.string.DeleteAccountFragment__delete_your_account_info_and_profile_photo)))
.append("\n")
.append(SpanUtil.bullet(getString(R.string.DeleteAccountFragment__delete_all_your_messages)));
if (formattedBalance.isPresent()) {
builder.append("\n");
builder.append(SpanUtil.bullet(getString(R.string.DeleteAccountFragment__delete_s_in_your_payments_account, formattedBalance.get())));
}
return builder;
}
@SuppressLint("ClickableViewAccessibility")

View File

@@ -15,24 +15,28 @@ import com.google.i18n.phonenumbers.NumberParseException;
import com.google.i18n.phonenumbers.PhoneNumberUtil;
import com.google.i18n.phonenumbers.Phonenumber;
import org.signal.core.util.logging.Log;
import org.thoughtcrime.securesms.keyvalue.SignalStore;
import org.thoughtcrime.securesms.payments.Balance;
import org.thoughtcrime.securesms.recipients.Recipient;
import org.thoughtcrime.securesms.util.DefaultValueLiveData;
import org.thoughtcrime.securesms.util.SingleLiveEvent;
import org.whispersystems.signalservice.api.util.PhoneNumberFormatter;
import org.whispersystems.libsignal.util.guava.Optional;
import org.whispersystems.signalservice.api.payments.FormatterOptions;
import org.whispersystems.signalservice.api.payments.Money;
import java.util.List;
public class DeleteAccountViewModel extends ViewModel {
private final DeleteAccountRepository repository;
private final List<Country> allCountries;
private final LiveData<List<Country>> filteredCountries;
private final MutableLiveData<String> regionCode;
private final LiveData<String> countryDisplayName;
private final MutableLiveData<Long> nationalNumber;
private final MutableLiveData<String> query;
private final SingleLiveEvent<EventType> events;
private final DeleteAccountRepository repository;
private final List<Country> allCountries;
private final LiveData<List<Country>> filteredCountries;
private final MutableLiveData<String> regionCode;
private final LiveData<String> countryDisplayName;
private final MutableLiveData<Long> nationalNumber;
private final MutableLiveData<String> query;
private final SingleLiveEvent<EventType> events;
private final LiveData<Optional<String>> walletBalance;
public DeleteAccountViewModel(@NonNull DeleteAccountRepository repository) {
this.repository = repository;
@@ -43,6 +47,12 @@ public class DeleteAccountViewModel extends ViewModel {
this.countryDisplayName = Transformations.map(regionCode, repository::getRegionDisplayName);
this.filteredCountries = Transformations.map(query, q -> Stream.of(allCountries).filter(country -> isMatch(q, country)).toList());
this.events = new SingleLiveEvent<>();
this.walletBalance = Transformations.map(SignalStore.paymentsValues().liveMobileCoinBalance(),
DeleteAccountViewModel::getFormattedWalletBalance);
}
@NonNull LiveData<Optional<String>> getWalletBalance() {
return walletBalance;
}
@NonNull LiveData<List<Country>> getFilteredCountries() {
@@ -128,6 +138,15 @@ public class DeleteAccountViewModel extends ViewModel {
}
}
private static @NonNull Optional<String> getFormattedWalletBalance(@NonNull Balance balance) {
Money amount = balance.getFullAmount();
if (amount.isPositive()) {
return Optional.of(amount.toString(FormatterOptions.defaults()));
} else {
return Optional.absent();
}
}
private static boolean isMatch(@NonNull String query, @NonNull Country country) {
if (TextUtils.isEmpty(query)) {
return true;