+ public static int retrieveCurrentThemeIdFromDb() {
+ String profileUUID = MLDB.getOption(MLDB.OPT_PROFILE_UUID, null);
+ if (profileUUID == null)
+ return -1;
+
+ SQLiteDatabase db = App.getDatabase();
+ try (Cursor c = db.rawQuery("SELECT theme from profiles where uuid=?",
+ new String[]{profileUUID}))
+ {
+ if (c.moveToNext())
+ return c.getInt(0);
+ }
+
+ return -1;
+ }
+ @Nullable
+ public static MobileLedgerProfile getProfile(String profileUUID) {
+ MobileLedgerProfile profile;
+ try (LockHolder readLock = profilesLocker.lockForReading()) {
+ List<MobileLedgerProfile> prList = profiles.getValue();
+ if ((prList == null) || prList.isEmpty()) {
+ readLock.close();
+ try (LockHolder ignored = profilesLocker.lockForWriting()) {
+ profile = MobileLedgerProfile.loadAllFromDB(profileUUID);
+ }
+ }
+ else {
+ int i = getProfileIndex(profileUUID);
+ if (i == -1)
+ i = 0;
+ profile = prList.get(i);
+ }
+ }
+ return profile;
+ }
+ public synchronized static void scheduleTransactionListRetrieval() {
+ if (retrieveTransactionsTask != null) {
+ Logger.debug("db", "Ignoring request for transaction retrieval - already active");
+ return;
+ }
+ MobileLedgerProfile pr = profile.getValue();
+ if (pr == null) {
+ Logger.debug("ui", "Ignoring refresh -- no current profile");
+ return;
+ }
+
+ retrieveTransactionsTask = new RetrieveTransactionsTask(profile.getValue());
+ Logger.debug("db", "Created a background transaction retrieval task");
+
+ retrieveTransactionsTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
+ }
+ public static synchronized void stopTransactionsRetrieval() {
+ if (retrieveTransactionsTask != null)
+ retrieveTransactionsTask.cancel(false);
+ }
+ public static void transactionRetrievalDone() {
+ retrieveTransactionsTask = null;
+ }
+ public static void refreshCurrencyData(Locale locale) {
+ NumberFormat formatter = NumberFormat.getCurrencyInstance(locale);
+ java.util.Currency currency = formatter.getCurrency();
+ String symbol = currency != null ? currency.getSymbol() : "";
+ Logger.debug("locale", String.format(
+ "Discovering currency symbol position for locale %s (currency is %s; symbol is %s)",
+ locale.toString(), currency != null ? currency.toString() : "<none>", symbol));
+ String formatted = formatter.format(1234.56f);
+ Logger.debug("locale", String.format("1234.56 formats as '%s'", formatted));
+
+ if (formatted.startsWith(symbol)) {
+ currencySymbolPosition.setValue(Currency.Position.before);
+
+ // is the currency symbol directly followed by the first formatted digit?
+ final char canary = formatted.charAt(symbol.length());
+ currencyGap.setValue(canary != '1');
+ }
+ else if (formatted.endsWith(symbol)) {
+ currencySymbolPosition.setValue(Currency.Position.after);
+
+ // is the currency symbol directly preceded bu the last formatted digit?
+ final char canary = formatted.charAt(formatted.length() - symbol.length() - 1);
+ currencyGap.setValue(canary != '6');
+ }
+ else
+ currencySymbolPosition.setValue(Currency.Position.none);
+ }
+
+ public static void observeProfile(LifecycleOwner lifecycleOwner,
+ Observer<MobileLedgerProfile> observer) {
+ profile.observe(lifecycleOwner, observer);
+ }
+ public synchronized static MobileLedgerProfile initProfile() {
+ MobileLedgerProfile currentProfile = profile.getValue();
+ if (currentProfile != null)
+ return currentProfile;
+
+ String profileUUID = MLDB.getOption(MLDB.OPT_PROFILE_UUID, null);
+ MobileLedgerProfile startupProfile = getProfile(profileUUID);
+ if (startupProfile != null)
+ setCurrentProfile(startupProfile);
+ return startupProfile;
+ }
+
+ public static void removeProfileObservers(LifecycleOwner owner) {
+ profile.removeObservers(owner);
+ }
+}
\ No newline at end of file