]> git.ktnx.net Git - mobile-ledger.git/blobdiff - app/src/main/java/net/ktnx/mobileledger/App.java
whitespace
[mobile-ledger.git] / app / src / main / java / net / ktnx / mobileledger / App.java
index 68f1b9c43c1e14f6f999c9edbfcf832839d539ce..724627971769db475e7007c799ed1ae81987edf6 100644 (file)
@@ -29,6 +29,8 @@ import net.ktnx.mobileledger.utils.Globals;
 import net.ktnx.mobileledger.utils.Logger;
 import net.ktnx.mobileledger.utils.MobileLedgerDatabase;
 
+import org.jetbrains.annotations.NotNull;
+
 import java.net.Authenticator;
 import java.net.MalformedURLException;
 import java.net.PasswordAuthentication;
@@ -40,10 +42,14 @@ public class App extends Application {
     private MobileLedgerDatabase dbHelper;
     private boolean monthNamesPrepared = false;
     public static SQLiteDatabase getDatabase() {
-        if (instance == null) throw new RuntimeException("Application not created yet");
+        if (instance == null)
+            throw new RuntimeException("Application not created yet");
 
         return instance.getDB();
     }
+    public static void prepareMonthNames() {
+        instance.prepareMonthNames(false);
+    }
     @Override
     public void onCreate() {
         Logger.debug("flow", "App onCreate()");
@@ -53,18 +59,20 @@ public class App extends Application {
         Authenticator.setDefault(new Authenticator() {
             @Override
             protected PasswordAuthentication getPasswordAuthentication() {
-                MobileLedgerProfile p = Data.profile.getValue();
-                if ((p != null) && p.isAuthEnabled()) {
+                MobileLedgerProfile p = Data.getProfile();
+                if (p.isAuthEnabled()) {
                     try {
                         final URL url = new URL(p.getUrl());
                         final String requestingHost = getRequestingHost();
                         final String expectedHost = url.getHost();
                         if (requestingHost.equalsIgnoreCase(expectedHost))
                             return new PasswordAuthentication(p.getAuthUserName(),
-                                    p.getAuthPassword().toCharArray());
-                        else Log.w("http-auth",
-                                String.format("Requesting host [%s] differs from expected [%s]",
-                                        requestingHost, expectedHost));
+                                    p.getAuthPassword()
+                                     .toCharArray());
+                        else
+                            Log.w("http-auth",
+                                    String.format("Requesting host [%s] differs from expected [%s]",
+                                            requestingHost, expectedHost));
                     }
                     catch (MalformedURLException e) {
                         e.printStackTrace();
@@ -75,9 +83,6 @@ public class App extends Application {
             }
         });
     }
-    public static void prepareMonthNames() {
-        instance.prepareMonthNames(false);
-    }
     private void prepareMonthNames(boolean force) {
         if (force || monthNamesPrepared)
             return;
@@ -93,22 +98,21 @@ public class App extends Application {
         super.onTerminate();
     }
     @Override
-    public void onConfigurationChanged(Configuration newConfig) {
+    public void onConfigurationChanged(@NotNull Configuration newConfig) {
         super.onConfigurationChanged(newConfig);
         prepareMonthNames(true);
         Data.refreshCurrencyData(Locale.getDefault());
         Data.locale.setValue(Locale.getDefault());
     }
     public SQLiteDatabase getDB() {
-        if (dbHelper == null) initDb();
-
-        final SQLiteDatabase db = dbHelper.getWritableDatabase();
-        db.execSQL("pragma case_sensitive_like=ON;");
+        if (dbHelper == null)
+            initDb();
 
-        return db;
+        return dbHelper.getWritableDatabase();
     }
     private synchronized void initDb() {
-        if (dbHelper != null) return;
+        if (dbHelper != null)
+            return;
 
         dbHelper = new MobileLedgerDatabase(this);
     }