]> git.ktnx.net Git - mobile-ledger.git/commitdiff
remove context parameter from MLDB.getWritableDB
authorDamyan Ivanov <dam+mobileledger@ktnx.net>
Wed, 2 Jan 2019 20:33:12 +0000 (20:33 +0000)
committerDamyan Ivanov <dam+mobileledger@ktnx.net>
Wed, 2 Jan 2019 20:33:12 +0000 (20:33 +0000)
app/src/main/AndroidManifest.xml
app/src/main/java/net/ktnx/mobileledger/async/RetrieveAccountsTask.java
app/src/main/java/net/ktnx/mobileledger/async/RetrieveTransactionsTask.java
app/src/main/java/net/ktnx/mobileledger/ui/account_summary/AccountSummaryFragment.java
app/src/main/java/net/ktnx/mobileledger/utils/MLDB.java

index 5ab5cdc6207e7a74ce2c72bd32f56705621b63c0..5f324207c644e721f4eb91db090df304b7a8d0a6 100644 (file)
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="utf-8"?>
 <!--
 <?xml version="1.0" encoding="utf-8"?>
 <!--
-  ~ Copyright © 2018 Damyan Ivanov.
+  ~ Copyright © 2019 Damyan Ivanov.
   ~ This file is part of Mobile-Ledger.
   ~ Mobile-Ledger is free software: you can distribute it and/or modify it
   ~ under the term of the GNU General Public License as published by
   ~ This file is part of Mobile-Ledger.
   ~ Mobile-Ledger is free software: you can distribute it and/or modify it
   ~ under the term of the GNU General Public License as published by
@@ -32,7 +32,7 @@
         android:theme="@style/AppTheme">
         <activity
             android:name=".ui.activity.MainActivity"
         android:theme="@style/AppTheme">
         <activity
             android:name=".ui.activity.MainActivity"
-            android:label="@string/account_summary_title"
+            android:label="@string/app_name"
             android:theme="@style/AppTheme.NoActionBar">
             <intent-filter>
                 <action android:name="android.intent.action.MAIN" />
             android:theme="@style/AppTheme.NoActionBar">
             <intent-filter>
                 <action android:name="android.intent.action.MAIN" />
index 59362fad7188d4f850ddca972baf6e2e32c93d1b..83f15fb7e7dec9258a7e35cef6829c2d4bca9167 100644 (file)
@@ -1,5 +1,5 @@
 /*
 /*
- * Copyright © 2018 Damyan Ivanov.
+ * Copyright © 2019 Damyan Ivanov.
  * This file is part of Mobile-Ledger.
  * Mobile-Ledger is free software: you can distribute it and/or modify it
  * under the term of the GNU General Public License as published by
  * This file is part of Mobile-Ledger.
  * Mobile-Ledger is free software: you can distribute it and/or modify it
  * under the term of the GNU General Public License as published by
@@ -21,9 +21,9 @@ import android.content.SharedPreferences;
 import android.database.sqlite.SQLiteDatabase;
 import android.util.Log;
 
 import android.database.sqlite.SQLiteDatabase;
 import android.util.Log;
 
-import net.ktnx.mobileledger.ui.account_summary.AccountSummaryFragment;
 import net.ktnx.mobileledger.R;
 import net.ktnx.mobileledger.model.LedgerAccount;
 import net.ktnx.mobileledger.R;
 import net.ktnx.mobileledger.model.LedgerAccount;
+import net.ktnx.mobileledger.ui.account_summary.AccountSummaryFragment;
 import net.ktnx.mobileledger.utils.MLDB;
 import net.ktnx.mobileledger.utils.NetworkUtil;
 
 import net.ktnx.mobileledger.utils.MLDB;
 import net.ktnx.mobileledger.utils.NetworkUtil;
 
@@ -57,7 +57,7 @@ public class RetrieveAccountsTask extends android.os.AsyncTask<Void, Integer, Vo
         try {
             HttpURLConnection http = NetworkUtil.prepare_connection(pref, "add");
             publishProgress(0);
         try {
             HttpURLConnection http = NetworkUtil.prepare_connection(pref, "add");
             publishProgress(0);
-            try (SQLiteDatabase db = MLDB.getWritableDatabase(mContext.get().getActivity())) {
+            try (SQLiteDatabase db = MLDB.getWritableDatabase()) {
                 try (InputStream resp = http.getInputStream()) {
                     Log.d("update_accounts", String.valueOf(http.getResponseCode()));
                     if (http.getResponseCode() != 200) {
                 try (InputStream resp = http.getInputStream()) {
                     Log.d("update_accounts", String.valueOf(http.getResponseCode()));
                     if (http.getResponseCode() != 200) {
index b8a341344fb478ab5d5202173c02a1b257e26923..e3f50cc37f67a5e555f7284a47a74fd7daedd6e5 100644 (file)
@@ -1,5 +1,5 @@
 /*
 /*
- * Copyright © 2018 Damyan Ivanov.
+ * Copyright © 2019 Damyan Ivanov.
  * This file is part of Mobile-Ledger.
  * Mobile-Ledger is free software: you can distribute it and/or modify it
  * under the term of the GNU General Public License as published by
  * This file is part of Mobile-Ledger.
  * Mobile-Ledger is free software: you can distribute it and/or modify it
  * under the term of the GNU General Public License as published by
@@ -102,7 +102,7 @@ public class RetrieveTransactionsTask extends
             publishProgress(progress);
             TransactionListFragment ctx = getContext();
             if (ctx == null) return null;
             publishProgress(progress);
             TransactionListFragment ctx = getContext();
             if (ctx == null) return null;
-            try (SQLiteDatabase db = MLDB.getWritableDatabase(ctx.getActivity())) {
+            try (SQLiteDatabase db = MLDB.getWritableDatabase()) {
                 try (InputStream resp = http.getInputStream()) {
                     if (http.getResponseCode() != 200) throw new IOException(
                             String.format("HTTP error %d", http.getResponseCode()));
                 try (InputStream resp = http.getInputStream()) {
                     if (http.getResponseCode() != 200) throw new IOException(
                             String.format("HTTP error %d", http.getResponseCode()));
@@ -251,7 +251,7 @@ public class RetrieveTransactionsTask extends
 
             if (success && !isCancelled()) {
                 Log.d("db", "Updating transaction list stamp");
 
             if (success && !isCancelled()) {
                 Log.d("db", "Updating transaction list stamp");
-                MLDB.set_option_value(ctx.getActivity(), MLDB.OPT_TRANSACTION_LIST_STAMP,
+                MLDB.set_option_value(MLDB.OPT_TRANSACTION_LIST_STAMP,
                         new Date().getTime());
                 ctx.model.reloadTransactions(ctx);
             }
                         new Date().getTime());
                 ctx.model.reloadTransactions(ctx);
             }
index 7ea680f51de4efa9d07d679fccccc4c0428d48e9..2d494af98afac869e725faa1dcf8fd63a2b47459 100644 (file)
@@ -1,5 +1,5 @@
 /*
 /*
- * Copyright © 2018 Damyan Ivanov.
+ * Copyright © 2019 Damyan Ivanov.
  * This file is part of Mobile-Ledger.
  * Mobile-Ledger is free software: you can distribute it and/or modify it
  * under the term of the GNU General Public License as published by
  * This file is part of Mobile-Ledger.
  * Mobile-Ledger is free software: you can distribute it and/or modify it
  * under the term of the GNU General Public License as published by
@@ -39,9 +39,9 @@ import android.view.View;
 import android.view.ViewGroup;
 
 import net.ktnx.mobileledger.R;
 import android.view.ViewGroup;
 
 import net.ktnx.mobileledger.R;
-import net.ktnx.mobileledger.ui.RecyclerItemListener;
 import net.ktnx.mobileledger.async.RetrieveAccountsTask;
 import net.ktnx.mobileledger.model.LedgerAccount;
 import net.ktnx.mobileledger.async.RetrieveAccountsTask;
 import net.ktnx.mobileledger.model.LedgerAccount;
+import net.ktnx.mobileledger.ui.RecyclerItemListener;
 import net.ktnx.mobileledger.ui.activity.MainActivity;
 import net.ktnx.mobileledger.utils.MLDB;
 
 import net.ktnx.mobileledger.ui.activity.MainActivity;
 import net.ktnx.mobileledger.utils.MLDB;
 
@@ -154,7 +154,7 @@ public class AccountSummaryFragment extends Fragment {
 
     }
     private void prepare_db() {
 
     }
     private void prepare_db() {
-        account_list_last_updated = MLDB.get_option_value(mActivity, "last_refresh", (long) 0);
+        account_list_last_updated = MLDB.get_option_value("last_refresh", (long) 0);
     }
 
     private void update_accounts(boolean force) {
     }
 
     private void update_accounts(boolean force) {
@@ -182,7 +182,7 @@ public class AccountSummaryFragment extends Fragment {
             Snackbar.make(swiper, err_text, Snackbar.LENGTH_LONG).show();
         }
         else {
             Snackbar.make(swiper, err_text, Snackbar.LENGTH_LONG).show();
         }
         else {
-            MLDB.set_option_value(mActivity, "last_refresh", new Date().getTime());
+            MLDB.set_option_value("last_refresh", new Date().getTime());
             update_account_table();
         }
     }
             update_account_table();
         }
     }
index b42f1613f5704dfb52bf24ba08ad606873180683..c11ea8486182839e89c3667ee23d5acc82e1aea8 100644 (file)
@@ -1,5 +1,5 @@
 /*
 /*
- * Copyright © 2018 Damyan Ivanov.
+ * Copyright © 2019 Damyan Ivanov.
  * This file is part of Mobile-Ledger.
  * Mobile-Ledger is free software: you can distribute it and/or modify it
  * under the term of the GNU General Public License as published by
  * This file is part of Mobile-Ledger.
  * Mobile-Ledger is free software: you can distribute it and/or modify it
  * under the term of the GNU General Public License as published by
@@ -66,11 +66,11 @@ public final class MLDB {
     public static SQLiteDatabase getReadableDatabase() {
         return getDatabase(READ);
     }
     public static SQLiteDatabase getReadableDatabase() {
         return getDatabase(READ);
     }
-    public static SQLiteDatabase getWritableDatabase(Context context) {
+    public static SQLiteDatabase getWritableDatabase() {
         return getDatabase(WRITE);
     }
         return getDatabase(WRITE);
     }
-    static public int get_option_value(Context context, String name, int default_value) {
-        String s = get_option_value(context, name, String.valueOf(default_value));
+    static public int get_option_value(String name, int default_value) {
+        String s = get_option_value(name, String.valueOf(default_value));
         try {
             return Integer.parseInt(s);
         }
         try {
             return Integer.parseInt(s);
         }
@@ -79,8 +79,8 @@ public final class MLDB {
             return default_value;
         }
     }
             return default_value;
         }
     }
-    static public long get_option_value(Context context, String name, long default_value) {
-        String s = get_option_value(context, name, String.valueOf(default_value));
+    static public long get_option_value(String name, long default_value) {
+        String s = get_option_value(name, String.valueOf(default_value));
         try {
             return Long.parseLong(s);
         }
         try {
             return Long.parseLong(s);
         }
@@ -89,7 +89,7 @@ public final class MLDB {
             return default_value;
         }
     }
             return default_value;
         }
     }
-    static public String get_option_value(Context context, String name, String default_value) {
+    static public String get_option_value(String name, String default_value) {
         Log.d("db", "about to fetch option " + name);
         try (SQLiteDatabase db = getReadableDatabase()) {
             try (Cursor cursor = db
         Log.d("db", "about to fetch option " + name);
         try (SQLiteDatabase db = getReadableDatabase()) {
             try (Cursor cursor = db
@@ -111,15 +111,15 @@ public final class MLDB {
             }
         }
     }
             }
         }
     }
-    static public void set_option_value(Context context, String name, String value) {
+    static public void set_option_value(String name, String value) {
         Log.d("db", "setting option " + name + "=" + value);
         Log.d("db", "setting option " + name + "=" + value);
-        try (SQLiteDatabase db = getWritableDatabase(context)) {
+        try (SQLiteDatabase db = getWritableDatabase()) {
             db.execSQL("insert or replace into options(name, value) values(?, ?);",
                     new String[]{name, value});
         }
     }
             db.execSQL("insert or replace into options(name, value) values(?, ?);",
                     new String[]{name, value});
         }
     }
-    static public void set_option_value(Context context, String name, long value) {
-        set_option_value(context, name, String.valueOf(value));
+    static public void set_option_value(String name, long value) {
+        set_option_value(name, String.valueOf(value));
     }
     @TargetApi(Build.VERSION_CODES.N)
     public static void hook_autocompletion_adapter(final Context context,
     }
     @TargetApi(Build.VERSION_CODES.N)
     public static void hook_autocompletion_adapter(final Context context,