X-Git-Url: https://git.ktnx.net/?p=mobile-ledger.git;a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fnet%2Fktnx%2Fmobileledger%2Fasync%2FConfigIO.java;fp=app%2Fsrc%2Fmain%2Fjava%2Fnet%2Fktnx%2Fmobileledger%2Fasync%2FConfigIO.java;h=0000000000000000000000000000000000000000;hp=43aa83ea4e97d5f25dfc38846a0cc85b7bb90645;hb=41d543229f3231469247e10ec6c197920c0e8bc4;hpb=833544eb24cb630dc1ce221e4aa3dedb3f6341e3 diff --git a/app/src/main/java/net/ktnx/mobileledger/async/ConfigIO.java b/app/src/main/java/net/ktnx/mobileledger/async/ConfigIO.java deleted file mode 100644 index 43aa83ea..00000000 --- a/app/src/main/java/net/ktnx/mobileledger/async/ConfigIO.java +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Copyright © 2021 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 . - */ - -package net.ktnx.mobileledger.async; - -import android.content.Context; -import android.net.Uri; -import android.os.ParcelFileDescriptor; -import android.util.Log; - -import net.ktnx.mobileledger.utils.Misc; - -import java.io.FileNotFoundException; -import java.io.IOException; - -abstract class ConfigIO extends Thread { - protected final OnErrorListener onErrorListener; - protected ParcelFileDescriptor pfd; - ConfigIO(Context context, Uri uri, OnErrorListener onErrorListener) - throws FileNotFoundException { - this.onErrorListener = onErrorListener; - pfd = context.getContentResolver() - .openFileDescriptor(uri, getStreamMode()); - - initStream(); - } - abstract protected String getStreamMode(); - - abstract protected void initStream(); - - abstract protected void processStream() throws IOException; - @Override - public void run() { - try { - processStream(); - } - catch (Exception e) { - Log.e("cfg-json", "Error processing settings as JSON", e); - if (onErrorListener != null) - Misc.onMainThread(() -> onErrorListener.error(e)); - } - finally { - try { - pfd.close(); - } - catch (Exception e) { - Log.e("cfg-json", "Error closing file descriptor", e); - } - } - } - protected static class Keys { - static final String ACCOUNTS = "accounts"; - static final String AMOUNT = "amount"; - static final String AMOUNT_GROUP = "amountGroup"; - static final String API_VER = "apiVersion"; - static final String AUTH_PASS = "authPass"; - static final String AUTH_USER = "authUser"; - static final String CAN_POST = "permitPosting"; - static final String COLOUR = "colour"; - static final String COMMENT = "comment"; - static final String COMMENT_GROUP = "commentMatchGroup"; - static final String COMMODITIES = "commodities"; - static final String CURRENCY = "commodity"; - static final String CURRENCY_GROUP = "commodityGroup"; - static final String CURRENT_PROFILE = "currentProfile"; - static final String DATE_DAY = "dateDay"; - static final String DATE_DAY_GROUP = "dateDayMatchGroup"; - static final String DATE_MONTH = "dateMonth"; - static final String DATE_MONTH_GROUP = "dateMonthMatchGroup"; - static final String DATE_YEAR = "dateYear"; - static final String DATE_YEAR_GROUP = "dateYearMatchGroup"; - static final String DEFAULT_COMMODITY = "defaultCommodity"; - static final String FUTURE_DATES = "futureDates"; - static final String HAS_GAP = "hasGap"; - static final String IS_FALLBACK = "isFallback"; - static final String NAME = "name"; - static final String NAME_GROUP = "nameMatchGroup"; - static final String NEGATE_AMOUNT = "negateAmount"; - static final String POSITION = "position"; - static final String PREF_ACCOUNT = "preferredAccountsFilter"; - static final String PROFILES = "profiles"; - static final String REGEX = "regex"; - static final String SHOW_COMMENTS = "showCommentsByDefault"; - static final String SHOW_COMMODITY = "showCommodityByDefault"; - static final String TEMPLATES = "templates"; - static final String TEST_TEXT = "testText"; - static final String TRANSACTION = "description"; - static final String TRANSACTION_GROUP = "descriptionMatchGroup"; - static final String URL = "url"; - static final String USE_AUTH = "useAuth"; - static final String UUID = "uuid"; - } - - abstract static public class OnErrorListener { - public abstract void error(Exception e); - } -}