* 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
* 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
import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModel;
import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModel;
public class ProfileDetailModel extends ViewModel {
private static final String HTTPS_URL_START = "https://";
private final MutableLiveData<String> profileName = new MutableLiveData<>();
public class ProfileDetailModel extends ViewModel {
private static final String HTTPS_URL_START = "https://";
private final MutableLiveData<String> profileName = new MutableLiveData<>();
private final MutableLiveData<Integer> themeId = new MutableLiveData<>(-1);
private final MutableLiveData<HledgerVersion> detectedVersion = new MutableLiveData<>(null);
private final MutableLiveData<Boolean> detectingHledgerVersion = new MutableLiveData<>(false);
private final MutableLiveData<Integer> themeId = new MutableLiveData<>(-1);
private final MutableLiveData<HledgerVersion> detectedVersion = new MutableLiveData<>(null);
private final MutableLiveData<Boolean> detectingHledgerVersion = new MutableLiveData<>(false);
public int initialThemeHue = Colors.DEFAULT_HUE_DEG;
private VersionDetectionThread versionDetectionThread;
public ProfileDetailModel() {
public int initialThemeHue = Colors.DEFAULT_HUE_DEG;
private VersionDetectionThread versionDetectionThread;
public ProfileDetailModel() {
profileName.setValue(mProfile.getName());
postingPermitted.setValue(mProfile.permitPosting());
showCommentsByDefault.setValue(mProfile.getShowCommentsByDefault());
profileName.setValue(mProfile.getName());
postingPermitted.setValue(mProfile.permitPosting());
showCommentsByDefault.setValue(mProfile.getShowCommentsByDefault());
apiVersion.setValue(API.valueOf(mProfile.getApiVersion()));
url.setValue(mProfile.getUrl());
useAuthentication.setValue(mProfile.useAuthentication());
apiVersion.setValue(API.valueOf(mProfile.getApiVersion()));
url.setValue(mProfile.getUrl());
useAuthentication.setValue(mProfile.useAuthentication());
profileName.setValue(null);
url.setValue(HTTPS_URL_START);
postingPermitted.setValue(true);
profileName.setValue(null);
url.setValue(HTTPS_URL_START);
postingPermitted.setValue(true);
mProfile.setName(profileName.getValue());
mProfile.setUrl(url.getValue());
mProfile.setPermitPosting(postingPermitted.getValue());
mProfile.setName(profileName.getValue());
mProfile.setUrl(url.getValue());
mProfile.setPermitPosting(postingPermitted.getValue());
- mProfile.setDetectedVersionPre_1_19(version.isPre_1_20_1());
- mProfile.setDetectedVersionMajor(version.getMajor());
- mProfile.setDetectedVersionMinor(version.getMinor());
+ mProfile.setDetectedVersionPre_1_19(version != null && version.isPre_1_20_1());
+ mProfile.setDetectedVersionMajor(version != null ? version.getMajor() : -1);
+ mProfile.setDetectedVersionMinor(version != null ? version.getMinor() : -1);
static class VersionDetectionThread extends Thread {
static final int TARGET_PROCESS_DURATION = 1000;
private final Pattern versionPattern =
static class VersionDetectionThread extends Thread {
static final int TARGET_PROCESS_DURATION = 1000;
private final Pattern versionPattern =