]> git.ktnx.net Git - mobile-ledger.git/commitdiff
locale-aware String.format
authorDamyan Ivanov <dam+mobileledger@ktnx.net>
Sat, 27 Apr 2019 17:16:32 +0000 (20:16 +0300)
committerDamyan Ivanov <dam+mobileledger@ktnx.net>
Sat, 27 Apr 2019 17:16:32 +0000 (20:16 +0300)
these are debugging things, the English locale should be fine

app/src/main/java/net/ktnx/mobileledger/async/RetrieveTransactionsTask.java
app/src/main/java/net/ktnx/mobileledger/model/Data.java
app/src/main/java/net/ktnx/mobileledger/ui/activity/MainActivity.java
app/src/main/java/net/ktnx/mobileledger/ui/activity/ProfileDetailActivity.java
app/src/main/java/net/ktnx/mobileledger/ui/profiles/ProfilesRecyclerViewAdapter.java

index 71bf28234afe40af05f4894427340b7e35cbed06..8d98dc63c89e920ce1128df939f0ee014b33805b 100644 (file)
@@ -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));
                         }
index 27eac04ff8d747da788ce75ed86d00b99ce00cd3..0902ced5f8d1771d9ad8c853321c15fd5c6b5bc9 100644 (file)
@@ -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<String> 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) {
index 8c573210d59980d08cf7d433193707fd3f3e6776..88cc39d0c03f6ae25134ea879d31403e6a7cef35 100644 (file)
@@ -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");
index ad7401de661079b75510f59eab70b5e4c6d79318..40051dac68e4ef9155ea4036ba07fa0b7d56cd81 100644 (file)
@@ -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);
index 3a9dd41d4e16c3d84648ee402c5e584ed1d2b32a..a4221cddc460a3d4deabc91e8bfe70806f1661de 100644 (file)
@@ -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) ? "<NULL>" : currentProfile.getUuid()));
         holder.itemView.setTag(profile);