--- /dev/null
+/*
+ * Copyright © 2019 Damyan Ivanov.
+ * This file is part of MoLe.
+ * MoLe is free software: you can distribute it and/or modify it
+ * under the term of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your opinion), any later version.
+ *
+ * MoLe is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License terms for details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with MoLe. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+package net.ktnx.mobileledger.utils;
+
+abstract public class GetOptCallback {
+ protected abstract void onResult(String result);
+}
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
+import android.os.AsyncTask;
import android.os.Build;
import android.provider.FontsContract;
import android.util.Log;
return default_value;
}
}
+ static public void getOption(String name, String defaultValue, GetOptCallback cb) {
+ AsyncTask<Void, Void, String> t = new AsyncTask<Void, Void, String>() {
+ @Override
+ protected String doInBackground(Void... params) {
+ SQLiteDatabase db = getDatabase();
+ try (Cursor cursor = db
+ .rawQuery("select value from options where profile = ? and name=?",
+ new String[]{NO_PROFILE, name}))
+ {
+ if (cursor.moveToFirst()) {
+ String result = cursor.getString(0);
+
+ if (result == null) result = defaultValue;
+
+ debug("async-db", "option " + name + "=" + result);
+ return result;
+ }
+ else return defaultValue;
+ }
+ catch (Exception e) {
+ debug("db", "returning default value for " + name, e);
+ return defaultValue;
+ }
+ }
+ @Override
+ protected void onPostExecute(String result) {
+ cb.onResult(result);
+ }
+ };
+
+ t.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null);
+ }
static public String getOption(String name, String default_value) {
debug("db", "about to fetch option " + name);
SQLiteDatabase db = getDatabase();