2 * Copyright © 2021 Damyan Ivanov.
3 * This file is part of MoLe.
4 * MoLe is free software: you can distribute it and/or modify it
5 * under the term of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your opinion), any later version.
9 * MoLe is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License terms for details.
14 * You should have received a copy of the GNU General Public License
15 * along with MoLe. If not, see <https://www.gnu.org/licenses/>.
18 package net.ktnx.mobileledger.backup;
20 import android.content.Context;
21 import android.net.Uri;
23 import net.ktnx.mobileledger.dao.ProfileDAO;
24 import net.ktnx.mobileledger.db.DB;
25 import net.ktnx.mobileledger.db.Profile;
26 import net.ktnx.mobileledger.model.Data;
27 import net.ktnx.mobileledger.utils.Misc;
29 import java.io.FileInputStream;
30 import java.io.FileNotFoundException;
31 import java.io.IOException;
33 public class ConfigReader extends ConfigIO {
34 private final OnDoneListener onDoneListener;
35 private RawConfigReader r;
36 public ConfigReader(Context context, Uri uri, OnErrorListener onErrorListener,
37 OnDoneListener onDoneListener) throws FileNotFoundException {
38 super(context, uri, onErrorListener);
40 this.onDoneListener = onDoneListener;
43 protected String getStreamMode() {
47 protected void initStream() {
48 RawConfigReader r = new RawConfigReader(new FileInputStream(pfd.getFileDescriptor()));
51 protected void processStream() throws IOException {
54 String currentProfile = r.getCurrentProfile();
56 if (Data.getProfile() == null) {
58 final ProfileDAO dao = DB.get()
60 if (currentProfile != null)
61 p = dao.getByUuidSync(currentProfile);
67 Data.postCurrentProfile(p);
70 if (onDoneListener != null)
71 Misc.onMainThread(onDoneListener::done);
73 abstract static public class OnDoneListener {
74 public abstract void done();