Search in sources :

Example 1 with FormatterOptions

use of org.whispersystems.signalservice.api.payments.FormatterOptions in project Signal-Android by WhisperSystems.

the class ConfirmPaymentFragment method createList.

@NonNull
private MappingModelList createList(@NonNull ConfirmPaymentState state) {
    MappingModelList list = new MappingModelList();
    FormatterOptions options = FormatterOptions.defaults();
    switch(state.getFeeStatus()) {
        case STILL_LOADING:
        case ERROR:
            list.add(new ConfirmPaymentAdapter.LoadingItem());
            break;
        case NOT_SET:
        case SET:
            list.add(new ConfirmPaymentAdapter.LineItem(getToPayeeDescription(requireContext(), state), state.getAmount().toString(options)));
            if (state.getExchange() != null) {
                list.add(new ConfirmPaymentAdapter.LineItem(getString(R.string.ConfirmPayment__estimated_s, state.getExchange().getCurrency().getCurrencyCode()), FiatMoneyUtil.format(getResources(), state.getExchange(), FiatMoneyUtil.formatOptions().withDisplayTime(false))));
            }
            list.add(new ConfirmPaymentAdapter.LineItem(getString(R.string.ConfirmPayment__network_fee), state.getFee().toString(options)));
            list.add(new ConfirmPaymentAdapter.Divider());
            list.add(new ConfirmPaymentAdapter.TotalLineItem(getString(R.string.ConfirmPayment__total_amount), state.getTotal().toString(options)));
    }
    list.add(new ConfirmPaymentAdapter.ConfirmPaymentStatus(state.getStatus(), state.getFeeStatus(), state.getBalance()));
    return list;
}
Also used : FormatterOptions(org.whispersystems.signalservice.api.payments.FormatterOptions) MappingModelList(org.thoughtcrime.securesms.util.adapter.mapping.MappingModelList) NonNull(androidx.annotation.NonNull)

Example 2 with FormatterOptions

use of org.whispersystems.signalservice.api.payments.FormatterOptions in project Signal-Android by signalapp.

the class ConfirmPaymentFragment method createList.

@NonNull
private MappingModelList createList(@NonNull ConfirmPaymentState state) {
    MappingModelList list = new MappingModelList();
    FormatterOptions options = FormatterOptions.defaults();
    switch(state.getFeeStatus()) {
        case STILL_LOADING:
        case ERROR:
            list.add(new ConfirmPaymentAdapter.LoadingItem());
            break;
        case NOT_SET:
        case SET:
            list.add(new ConfirmPaymentAdapter.LineItem(getToPayeeDescription(requireContext(), state), state.getAmount().toString(options)));
            if (state.getExchange() != null) {
                list.add(new ConfirmPaymentAdapter.LineItem(getString(R.string.ConfirmPayment__estimated_s, state.getExchange().getCurrency().getCurrencyCode()), FiatMoneyUtil.format(getResources(), state.getExchange(), FiatMoneyUtil.formatOptions().withDisplayTime(false))));
            }
            list.add(new ConfirmPaymentAdapter.LineItem(getString(R.string.ConfirmPayment__network_fee), state.getFee().toString(options)));
            list.add(new ConfirmPaymentAdapter.Divider());
            list.add(new ConfirmPaymentAdapter.TotalLineItem(getString(R.string.ConfirmPayment__total_amount), state.getTotal().toString(options)));
    }
    list.add(new ConfirmPaymentAdapter.ConfirmPaymentStatus(state.getStatus(), state.getFeeStatus(), state.getBalance()));
    return list;
}
Also used : FormatterOptions(org.whispersystems.signalservice.api.payments.FormatterOptions) MappingModelList(org.thoughtcrime.securesms.util.adapter.mapping.MappingModelList) NonNull(androidx.annotation.NonNull)

Example 3 with FormatterOptions

use of org.whispersystems.signalservice.api.payments.FormatterOptions in project Signal-Android by WhisperSystems.

the class MoneyView method init.

public void init(@NonNull Context context, @Nullable AttributeSet attrs) {
    FormatterOptions.Builder builder = FormatterOptions.builder(Locale.getDefault());
    TypedArray styledAttributes = context.obtainStyledAttributes(attrs, R.styleable.MoneyView, 0, 0);
    if (styledAttributes.getBoolean(R.styleable.MoneyView_always_show_sign, false)) {
        builder.alwaysPrefixWithSign();
    }
    formatterOptions = builder.withoutSpaceBeforeUnit().build();
    String value = styledAttributes.getString(R.styleable.MoneyView_money);
    if (value != null) {
        try {
            setMoney(Money.parse(value));
        } catch (Money.ParseException e) {
            throw new AssertionError("Invalid money format", e);
        }
    }
    styledAttributes.recycle();
}
Also used : Money(org.whispersystems.signalservice.api.payments.Money) FormatterOptions(org.whispersystems.signalservice.api.payments.FormatterOptions) TypedArray(android.content.res.TypedArray) SpannableString(android.text.SpannableString)

Example 4 with FormatterOptions

use of org.whispersystems.signalservice.api.payments.FormatterOptions in project Signal-Android by signalapp.

the class MoneyView method init.

public void init(@NonNull Context context, @Nullable AttributeSet attrs) {
    FormatterOptions.Builder builder = FormatterOptions.builder(Locale.getDefault());
    TypedArray styledAttributes = context.obtainStyledAttributes(attrs, R.styleable.MoneyView, 0, 0);
    if (styledAttributes.getBoolean(R.styleable.MoneyView_always_show_sign, false)) {
        builder.alwaysPrefixWithSign();
    }
    formatterOptions = builder.withoutSpaceBeforeUnit().build();
    String value = styledAttributes.getString(R.styleable.MoneyView_money);
    if (value != null) {
        try {
            setMoney(Money.parse(value));
        } catch (Money.ParseException e) {
            throw new AssertionError("Invalid money format", e);
        }
    }
    styledAttributes.recycle();
}
Also used : Money(org.whispersystems.signalservice.api.payments.Money) FormatterOptions(org.whispersystems.signalservice.api.payments.FormatterOptions) TypedArray(android.content.res.TypedArray) SpannableString(android.text.SpannableString)

Aggregations

FormatterOptions (org.whispersystems.signalservice.api.payments.FormatterOptions)4 TypedArray (android.content.res.TypedArray)2 SpannableString (android.text.SpannableString)2 NonNull (androidx.annotation.NonNull)2 MappingModelList (org.thoughtcrime.securesms.util.adapter.mapping.MappingModelList)2 Money (org.whispersystems.signalservice.api.payments.Money)2