Skip to content

Commit

Permalink
fix: fix User unable to set preferred local fiat currency (#299)
Browse files Browse the repository at this point in the history
* fix: fix close button at activity_display_currency.xml

* fix: fix display currency
  • Loading branch information
andhikayuana authored Dec 19, 2024
1 parent 247cd06 commit 2ce1e2f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -414,25 +414,6 @@ public void onBalanceChanged(final long balance) {
updateUI();
}

private static final Map<Language, String> fiat = new HashMap<>();

static {
fiat.put(Language.ENGLISH, "USD");
fiat.put(Language.SPANISH, "EUR");
fiat.put(Language.GERMAN, "EUR");
fiat.put(Language.FRENCH, "EUR");
fiat.put(Language.JAPANESE, "JPY");
fiat.put(Language.INDONESIAN, "USD");
fiat.put(Language.ITALIAN, "EUR");
fiat.put(Language.PORTUGUESE, "EUR");
fiat.put(Language.TURKISH, "EUR");
fiat.put(Language.UKRAINIAN, "EUR");
fiat.put(Language.RUSSIAN, "EUR");
fiat.put(Language.KOREAN, "EUR");
fiat.put(Language.CHINESE_TRADITIONAL, "USD");
fiat.put(Language.CHINESE_SIMPLIFIED, "RMB");
}

public void updateUI() {
BRExecutor.getInstance().forLightWeightBackgroundTasks().execute(() -> {
Thread.currentThread().setName(Thread.currentThread().getName() + ":updateUI");
Expand All @@ -446,13 +427,8 @@ public void updateUI() {
BigDecimal btcAmount = BRExchange.getLitecoinForLitoshis(BreadActivity.this, amount);
final String formattedBTCAmount = BRCurrency.getFormattedCurrencyString(BreadActivity.this, "LTC", btcAmount);

//amount in currency units
Language currentLanguage = LocaleHelper.Companion.getInstance().getCurrentLocale();
String correspondingFiat = fiat.getOrDefault(currentLanguage, "USD");

assert correspondingFiat != null;
final BigDecimal curAmount = BRExchange.getAmountFromLitoshis(BreadActivity.this, correspondingFiat, amount);
final String formattedCurAmount = BRCurrency.getFormattedCurrencyString(BreadActivity.this, correspondingFiat, curAmount);
final BigDecimal curAmount = BRExchange.getAmountFromLitoshis(BreadActivity.this, iso, amount);
final String formattedCurAmount = BRCurrency.getFormattedCurrencyString(BreadActivity.this, iso, curAmount);
runOnUiThread(() -> {
primaryPrice.setText(formattedBTCAmount);
secondaryPrice.setText(String.format("%s", formattedCurAmount));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

import java.math.BigDecimal;
import java.util.Currency;
import java.util.Objects;

import timber.log.Timber;

Expand Down Expand Up @@ -181,7 +182,7 @@ public CurrencyListAdapter(Context mContext) {
@Override
public View getView(int position, View convertView, ViewGroup parent) {

final int tmp = BRSharedPrefs.getCurrencyListPosition(mContext);
// final int tmp = BRSharedPrefs.getCurrencyListPosition(mContext);

if (convertView == null) {
// inflate the layout
Expand All @@ -190,6 +191,7 @@ public View getView(int position, View convertView, ViewGroup parent) {
}
// get the TextView and then set the text (item name) and tag (item ID) values
textViewItem = convertView.findViewById(R.id.currency_item_text);
String isoCached = BRSharedPrefs.getIsoSymbol(mContext);
String iso = getItem(position).code;
Currency c = null;
try {
Expand All @@ -198,9 +200,11 @@ public View getView(int position, View convertView, ViewGroup parent) {
}
textViewItem.setText(c == null ? iso : String.format("%s (%s)", iso, c.getSymbol()));
ImageView checkMark = convertView.findViewById(R.id.currency_checkmark);
Timber.d( "Value of TMP %s", tmp);
Timber.d( "Value of position %s", position);
if (position == tmp) {

Timber.d("timber: isoCached: %s", isoCached);
Timber.d("timber: item iso: %s", iso);

if (Objects.equals(iso, isoCached)) {
checkMark.setVisibility(View.VISIBLE);
} else {
checkMark.setVisibility(View.GONE);
Expand Down
14 changes: 7 additions & 7 deletions app/src/main/res/layout/activity_display_currency.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
android:textColor="@color/almost_black"
android:textSize="@dimen/header"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent" />
app:layout_constraintTop_toTopOf="@id/close_button" />

<TextView
style="@style/BRBoldTextStyle"
Expand Down Expand Up @@ -123,15 +123,15 @@

<ImageButton
android:id="@+id/close_button"
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/bread_margin"
android:background="@drawable/ic_close_white_24dp"
android:src="@drawable/ic_close_black_24dp"
android:backgroundTint="@color/extra_light_blue_background"
android:layout_marginBottom="0dp"
android:layout_marginEnd="16dp"
android:layout_marginTop="0dp"
app:layout_constraintBottom_toBottomOf="@+id/title"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="@+id/title" />
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

0 comments on commit 2ce1e2f

Please sign in to comment.