From: Damyan Ivanov Date: Sat, 27 Apr 2019 17:16:32 +0000 (+0300) Subject: locale-aware String.format X-Git-Tag: v0.10.0~70 X-Git-Url: https://git.ktnx.net/?p=mobile-ledger.git;a=commitdiff_plain;h=23b8360d4f884bbdb20cc2de1825486ef42f37d6 locale-aware String.format these are debugging things, the English locale should be fine --- diff --git a/app/src/main/java/net/ktnx/mobileledger/async/RetrieveTransactionsTask.java b/app/src/main/java/net/ktnx/mobileledger/async/RetrieveTransactionsTask.java index 71bf2823..8d98dc63 100644 --- a/app/src/main/java/net/ktnx/mobileledger/async/RetrieveTransactionsTask.java +++ b/app/src/main/java/net/ktnx/mobileledger/async/RetrieveTransactionsTask.java @@ -50,6 +50,7 @@ import java.nio.charset.StandardCharsets; import java.text.ParseException; import java.util.ArrayList; import java.util.HashMap; +import java.util.Locale; import java.util.Stack; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -267,7 +268,8 @@ public class RetrieveTransactionsTask if (m.find()) { transactionId = Integer.valueOf(m.group(1)); state = ParserState.EXPECTING_TRANSACTION_DESCRIPTION; - L(String.format("found transaction %d → expecting description", + L(String.format(Locale.ENGLISH, + "found transaction %d → expecting description", transactionId)); progress.setProgress(++processedTransactionCount); if (maxTransactionId < transactionId) @@ -304,9 +306,9 @@ public class RetrieveTransactionsTask return String.format("Error parsing date '%s'", date); } state = ParserState.EXPECTING_TRANSACTION_DETAILS; - L(String.format("transaction %d created for %s (%s) →" + - " expecting details", transactionId, date, - m.group(2))); + L(String.format(Locale.ENGLISH, + "transaction %d created for %s (%s) →" + + " expecting details", transactionId, date, m.group(2))); } break; @@ -357,8 +359,8 @@ public class RetrieveTransactionsTask transaction.addAccount( new LedgerTransactionAccount(acc_name, Float.valueOf(amount), currency)); - L(String.format("%d: %s = %s", transaction.getId(), - acc_name, amount)); + L(String.format(Locale.ENGLISH, "%d: %s = %s", + transaction.getId(), acc_name, amount)); } else throw new IllegalStateException(String.format( "Can't parse transaction %d " + "details: %s", @@ -528,14 +530,14 @@ public class RetrieveTransactionsTask if (transactionOrder == DetectedTransactionOrder.UNKNOWN) { if (orderAccumulator > 30) { transactionOrder = DetectedTransactionOrder.FILE; - debug("rtt", String.format( + debug("rtt", String.format(Locale.ENGLISH, "Detected native file order after %d transactions (factor %d)", processedTransactionCount, orderAccumulator)); progress.setTotal(Data.transactions.size()); } else if (orderAccumulator < -30) { transactionOrder = DetectedTransactionOrder.REVERSE_CHRONOLOGICAL; - debug("rtt", String.format( + debug("rtt", String.format(Locale.ENGLISH, "Detected reverse chronological order after %d transactions (factor %d)", processedTransactionCount, orderAccumulator)); } diff --git a/app/src/main/java/net/ktnx/mobileledger/model/Data.java b/app/src/main/java/net/ktnx/mobileledger/model/Data.java index 27eac04f..0902ced5 100644 --- a/app/src/main/java/net/ktnx/mobileledger/model/Data.java +++ b/app/src/main/java/net/ktnx/mobileledger/model/Data.java @@ -27,6 +27,7 @@ import net.ktnx.mobileledger.utils.ObservableValue; import java.util.ArrayList; import java.util.Date; +import java.util.Locale; import java.util.concurrent.atomic.AtomicInteger; import androidx.lifecycle.MutableLiveData; @@ -47,12 +48,16 @@ public final class Data { public static MutableLiveData accountFilter = new MutableLiveData<>(); public static void backgroundTaskStarted() { int cnt = backgroundTaskCount.incrementAndGet(); - debug("data", String.format("background task count is %d after incrementing", cnt)); + debug("data", + String.format(Locale.ENGLISH, "background task count is %d after incrementing", + cnt)); backgroundTasksRunning.postValue(cnt > 0); } public static void backgroundTaskFinished() { int cnt = backgroundTaskCount.decrementAndGet(); - debug("data", String.format("background task count is %d after decrementing", cnt)); + debug("data", + String.format(Locale.ENGLISH, "background task count is %d after decrementing", + cnt)); backgroundTasksRunning.postValue(cnt > 0); } public static void setCurrentProfile(MobileLedgerProfile newProfile) { diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/activity/MainActivity.java b/app/src/main/java/net/ktnx/mobileledger/ui/activity/MainActivity.java index 8c573210..88cc39d0 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/activity/MainActivity.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/activity/MainActivity.java @@ -56,6 +56,7 @@ import net.ktnx.mobileledger.ui.transaction_list.TransactionListFragment; import net.ktnx.mobileledger.ui.transaction_list.TransactionListViewModel; import net.ktnx.mobileledger.utils.Colors; import net.ktnx.mobileledger.utils.LockHolder; +import net.ktnx.mobileledger.utils.Logger; import net.ktnx.mobileledger.utils.MLDB; import org.jetbrains.annotations.NotNull; @@ -65,6 +66,7 @@ import java.text.DateFormat; import java.util.ArrayList; import java.util.Date; import java.util.List; +import java.util.Locale; import java.util.Observer; import androidx.appcompat.app.ActionBarDrawerToggle; @@ -321,9 +323,9 @@ public class MainActivity extends ProfileThemedActivity { long now = new Date().getTime(); if ((lastUpdate == null) || (now > (lastUpdate.getTime() + (24 * 3600 * 1000)))) { if (lastUpdate == null) debug("db::", "WEB data never fetched. scheduling a fetch"); - else debug("db", - String.format("WEB data last fetched at %1.3f and now is %1.3f. re-fetching", - lastUpdate.getTime() / 1000f, now / 1000f)); + else debug("db", String.format(Locale.ENGLISH, + "WEB data last fetched at %1.3f and now is %1.3f. re-fetching", + lastUpdate.getTime() / 1000f, now / 1000f)); scheduleTransactionListRetrieval(); } @@ -558,7 +560,7 @@ public class MainActivity extends ProfileThemedActivity { mBackMeansToAccountList = false; } else { - debug("fragments", String.format("manager stack: %d", + debug("fragments", String.format(Locale.ENGLISH, "manager stack: %d", fragmentManager.getBackStackEntryCount())); super.onBackPressed(); @@ -569,7 +571,7 @@ public class MainActivity extends ProfileThemedActivity { final MobileLedgerProfile profile = Data.profile.get(); long last_update = (profile != null) ? profile.getLongOption(MLDB.OPT_LAST_SCRAPE, 0L) : 0; - debug("transactions", String.format("Last update = %d", last_update)); + debug("transactions", String.format(Locale.ENGLISH, "Last update = %d", last_update)); if (last_update == 0) { Data.lastUpdateDate.postValue(null); } @@ -806,7 +808,7 @@ public class MainActivity extends ProfileThemedActivity { @NotNull @Override public Fragment getItem(int position) { - debug("main", String.format("Switching to fragment %d", position)); + debug("main", String.format(Locale.ENGLISH, "Switching to fragment %d", position)); switch (position) { case 0: // debug("flow", "Creating account summary fragment"); diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/activity/ProfileDetailActivity.java b/app/src/main/java/net/ktnx/mobileledger/ui/activity/ProfileDetailActivity.java index ad7401de..40051dac 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/activity/ProfileDetailActivity.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/activity/ProfileDetailActivity.java @@ -26,6 +26,8 @@ import net.ktnx.mobileledger.model.MobileLedgerProfile; import net.ktnx.mobileledger.ui.profiles.ProfileDetailFragment; import net.ktnx.mobileledger.utils.Colors; +import java.util.Locale; + import androidx.appcompat.app.ActionBar; import androidx.appcompat.widget.Toolbar; @@ -49,8 +51,8 @@ public class ProfileDetailActivity extends CrashReportingActivity { if (profile == null) throw new AssertionError( String.format("Can't get profile " + "(index:%d) from the global list", index)); - debug("profiles", String.format("Editing profile %s (%s); hue=%d", profile.getName(), - profile.getUuid(), profile.getThemeId())); + debug("profiles", String.format(Locale.ENGLISH, "Editing profile %s (%s); hue=%d", + profile.getName(), profile.getUuid(), profile.getThemeId())); } super.onCreate(savedInstanceState); diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/profiles/ProfilesRecyclerViewAdapter.java b/app/src/main/java/net/ktnx/mobileledger/ui/profiles/ProfilesRecyclerViewAdapter.java index 3a9dd41d..a4221cdd 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/profiles/ProfilesRecyclerViewAdapter.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/profiles/ProfilesRecyclerViewAdapter.java @@ -37,6 +37,7 @@ import net.ktnx.mobileledger.utils.Colors; import net.ktnx.mobileledger.utils.ObservableValue; import java.util.Collections; +import java.util.Locale; import java.util.Observer; import androidx.annotation.NonNull; @@ -173,7 +174,7 @@ public class ProfilesRecyclerViewAdapter public void onBindViewHolder(@NonNull final ProfileListViewHolder holder, int position) { final MobileLedgerProfile profile = Data.profiles.get(position); final MobileLedgerProfile currentProfile = Data.profile.get(); - debug("profiles", String.format("pos %d: %s, current: %s", position, profile.getUuid(), + debug("profiles", String.format(Locale.ENGLISH,"pos %d: %s, current: %s", position, profile.getUuid(), (currentProfile == null) ? "" : currentProfile.getUuid())); holder.itemView.setTag(profile);