X-Git-Url: https://git.ktnx.net/?a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fnet%2Fktnx%2Fmobileledger%2Fui%2Fprofiles%2FProfileDetailModel.java;h=92d3ab508dd98930c8fd2fa1a4aec07ef2328312;hb=9662c07481ca878f4e4ff23c2923737241a3f3b4;hp=4cbbfe3d6fda715fa69b0668995aa51f0b61df97;hpb=1059279ca52a15efff01c00a67a2a647fef4a1ba;p=mobile-ledger-staging.git diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/profiles/ProfileDetailModel.java b/app/src/main/java/net/ktnx/mobileledger/ui/profiles/ProfileDetailModel.java index 4cbbfe3d..92d3ab50 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/profiles/ProfileDetailModel.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/profiles/ProfileDetailModel.java @@ -24,7 +24,8 @@ import androidx.lifecycle.MutableLiveData; import androidx.lifecycle.Observer; import androidx.lifecycle.ViewModel; -import net.ktnx.mobileledger.async.SendTransactionTask; +import net.ktnx.mobileledger.App; +import net.ktnx.mobileledger.json.API; import net.ktnx.mobileledger.model.Currency; import net.ktnx.mobileledger.model.HledgerVersion; import net.ktnx.mobileledger.model.MobileLedgerProfile; @@ -53,8 +54,7 @@ public class ProfileDetailModel extends ViewModel { private final MutableLiveData showCommodityByDefault = new MutableLiveData<>(false); private final MutableLiveData showCommentsByDefault = new MutableLiveData<>(true); private final MutableLiveData useAuthentication = new MutableLiveData<>(false); - private final MutableLiveData apiVersion = - new MutableLiveData<>(SendTransactionTask.API.auto); + private final MutableLiveData apiVersion = new MutableLiveData<>(API.auto); private final MutableLiveData url = new MutableLiveData<>(null); private final MutableLiveData authUserName = new MutableLiveData<>(null); private final MutableLiveData authPassword = new MutableLiveData<>(null); @@ -127,7 +127,7 @@ public class ProfileDetailModel extends ViewModel { void observeShowCommodityByDefault(LifecycleOwner lfo, Observer o) { showCommodityByDefault.observe(lfo, o); } - Boolean getUseAuthentication() { + public Boolean getUseAuthentication() { return useAuthentication.getValue(); } void setUseAuthentication(boolean newValue) { @@ -137,14 +137,14 @@ public class ProfileDetailModel extends ViewModel { void observeUseAuthentication(LifecycleOwner lfo, Observer o) { useAuthentication.observe(lfo, o); } - SendTransactionTask.API getApiVersion() { + API getApiVersion() { return apiVersion.getValue(); } - void setApiVersion(SendTransactionTask.API newValue) { + void setApiVersion(API newValue) { if (newValue != apiVersion.getValue()) apiVersion.setValue(newValue); } - void observeApiVersion(LifecycleOwner lfo, Observer o) { + void observeApiVersion(LifecycleOwner lfo, Observer o) { apiVersion.observe(lfo, o); } HledgerVersion getDetectedVersion() { return detectedVersion.getValue(); } @@ -155,7 +155,7 @@ public class ProfileDetailModel extends ViewModel { void observeDetectedVersion(LifecycleOwner lfo, Observer o) { detectedVersion.observe(lfo, o); } - String getUrl() { + public String getUrl() { return url.getValue(); } void setUrl(String newValue) { @@ -169,7 +169,7 @@ public class ProfileDetailModel extends ViewModel { void observeUrl(LifecycleOwner lfo, Observer o) { url.observe(lfo, o); } - String getAuthUserName() { + public String getAuthUserName() { return authUserName.getValue(); } void setAuthUserName(String newValue) { @@ -183,7 +183,7 @@ public class ProfileDetailModel extends ViewModel { void observeUserName(LifecycleOwner lfo, Observer o) { authUserName.observe(lfo, o); } - String getAuthPassword() { + public String getAuthPassword() { return authPassword.getValue(); } void setAuthPassword(String newValue) { @@ -254,7 +254,7 @@ public class ProfileDetailModel extends ViewModel { showCommentsByDefault.setValue(true); showCommodityByDefault.setValue(false); setFutureDates(MobileLedgerProfile.FutureDates.None); - setApiVersion(SendTransactionTask.API.auto); + setApiVersion(API.auto); useAuthentication.setValue(false); authUserName.setValue(""); authPassword.setValue(""); @@ -296,6 +296,7 @@ public class ProfileDetailModel extends ViewModel { this.model = model; } private HledgerVersion detectVersion() { + App.setAuthenticationDataFromProfileModel(model); HttpURLConnection http = null; try { http = NetworkUtil.prepareConnection(model.getUrl(), "version", @@ -334,6 +335,9 @@ public class ProfileDetailModel extends ViewModel { e.printStackTrace(); return null; } + finally { + App.resetAuthenticationData(); + } } @Override public void run() {