remove explicit enable checkbox, test login

This commit is contained in:
Milos Kozak 2019-06-07 09:13:29 +02:00
parent 5dbdd5e437
commit 01006b32ce
5 changed files with 18 additions and 33 deletions

View file

@ -22,6 +22,7 @@ import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.plugins.general.careportal.CareportalPlugin;
import info.nightscout.androidaps.plugins.constraints.safety.SafetyPlugin;
import info.nightscout.androidaps.plugins.general.tidepool.TidepoolPlugin;
import info.nightscout.androidaps.plugins.general.tidepool.comm.TidepoolUploader;
import info.nightscout.androidaps.plugins.insulin.InsulinOrefFreePeakPlugin;
import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin;
import info.nightscout.androidaps.plugins.general.nsclient.NSClientPlugin;
@ -194,7 +195,7 @@ public class PreferencesActivity extends PreferenceActivity implements SharedPre
}
if (Config.NSCLIENT) {
PreferenceScreen scrnAdvancedSettings = (PreferenceScreen)findPreference(getString(R.string.key_advancedsettings));
PreferenceScreen scrnAdvancedSettings = (PreferenceScreen) findPreference(getString(R.string.key_advancedsettings));
if (scrnAdvancedSettings != null) {
scrnAdvancedSettings.removePreference(getPreference(getString(R.string.key_statuslights_res_warning)));
scrnAdvancedSettings.removePreference(getPreference(getString(R.string.key_statuslights_res_critical)));
@ -205,6 +206,12 @@ public class PreferencesActivity extends PreferenceActivity implements SharedPre
}
initSummary(getPreferenceScreen());
final Preference tidepoolTestLogin = findPreference("tidepool_test_login");
tidepoolTestLogin.setOnPreferenceClickListener(preference -> {
TidepoolUploader.INSTANCE.testLogin(getActivity());
return false;
});
}
@Override

View file

@ -6,7 +6,6 @@ import info.nightscout.androidaps.Constants
import info.nightscout.androidaps.MainApp
import info.nightscout.androidaps.R
import info.nightscout.androidaps.events.EventNetworkChange
import info.nightscout.androidaps.events.EventNewBG
import info.nightscout.androidaps.interfaces.PluginBase
import info.nightscout.androidaps.interfaces.PluginDescription
import info.nightscout.androidaps.interfaces.PluginType
@ -17,6 +16,7 @@ import info.nightscout.androidaps.plugins.general.tidepool.events.EventTidepoolR
import info.nightscout.androidaps.plugins.general.tidepool.events.EventTidepoolStatus
import info.nightscout.androidaps.plugins.general.tidepool.events.EventTidepoolUpdateGUI
import info.nightscout.androidaps.plugins.general.tidepool.utils.RateLimit
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventAutosensCalculationFinished
import info.nightscout.androidaps.receivers.ChargingStateReceiver
import info.nightscout.androidaps.utils.SP
import info.nightscout.androidaps.utils.T
@ -59,8 +59,8 @@ object TidepoolPlugin : PluginBase(PluginDescription()
@Suppress("UNUSED_PARAMETER")
@Subscribe
fun onStatusEvent(ev: EventNewBG) {
if (enabled()
fun onStatusEvent(ev: EventAutosensCalculationFinished) {
if (isEnabled(PluginType.GENERAL)
&& (!SP.getBoolean(R.string.key_tidepool_only_while_charging, false) || ChargingStateReceiver.isCharging())
&& (!SP.getBoolean(R.string.key_tidepool_only_while_unmetered, false) || wifiConnected)
&& RateLimit.ratelimit("tidepool-new-data-upload", T.mins(4).secs().toInt()))
@ -90,10 +90,6 @@ object TidepoolPlugin : PluginBase(PluginDescription()
wifiConnected = ev.wifiConnected
}
fun enabled(): Boolean {
return isEnabled(PluginType.GENERAL) && SP.getBoolean(R.string.key_cloud_storage_tidepool_enable, false)
}
@Subscribe
fun onStatusEvent(ev: EventTidepoolStatus) {
addToLog(ev)

View file

@ -68,11 +68,6 @@ object TidepoolUploader {
@Synchronized
fun doLogin() {
if (!SP.getBoolean(R.string.key_cloud_storage_tidepool_enable, false)) {
if (L.isEnabled(L.TIDEPOOL))
log.debug("Cannot login as disabled by preference")
return
}
if (connectionStatus == TidepoolUploader.ConnectionStatus.CONNECTED || connectionStatus == TidepoolUploader.ConnectionStatus.CONNECTING) {
if (L.isEnabled(L.TIDEPOOL))
log.debug("Already connected")
@ -103,22 +98,20 @@ object TidepoolUploader {
}
fun testLogin(rootContext: Context) {
var message = "Failed to log into Tidepool.\n" + "Check that your user name and password are correct."
val session = Session(AuthRequestMessage.getAuthRequestHeader(), SESSION_TOKEN_HEADER)
if (session.authHeader != null) {
val call = session.service!!.getLogin(session.authHeader!!)
val response = call.execute()
if (L.isEnabled(L.TIDEPOOL)) log.debug("Header: " + response.code())
message = "Successfully logged into Tidepool."
call.enqueue(TidepoolCallback<AuthReplyMessage>(session, "Login", {
OKDialog.show(rootContext, MainApp.gs(R.string.tidepool), "Successfully logged into Tidepool.", null);
}, {
OKDialog.show(rootContext, MainApp.gs(R.string.tidepool), "Failed to log into Tidepool.\nCheck that your user name and password are correct.", null);
}))
} else {
if (L.isEnabled(L.TIDEPOOL)) log.debug("Cannot do login as user credentials have not been set correctly")
OKDialog.show(rootContext, MainApp.gs(R.string.tidepool), "Cannot do login as user credentials have not been set correctly", null);
}
OKDialog.show(rootContext, MainApp.gs(R.string.tidepool), message, null);
}
@ -168,12 +161,8 @@ object TidepoolUploader {
}
}
@Synchronized
fun doUpload() {
if (!TidepoolPlugin.enabled()) {
if (L.isEnabled(L.TIDEPOOL))
log.debug("Cannot upload - preference disabled")
return
}
if (session == null) {
log.error("Session is null, cannot proceed")
return

View file

@ -1332,9 +1332,7 @@
<string name="key_tidepool_test_login" translatable="false">tidepool_test_login</string>
<string name="key_tidepool_only_while_charging" translatable="false">tidepool_only_while_charging</string>
<string name="key_tidepool_only_while_unmetered" translatable="false">tidepool_only_while_unmetered</string>
<string name="key_cloud_storage_tidepool_enable" translatable="false">cloud_storage_tidepool_enable</string>
<string name="summary_tidepool_upload_screen">Upload data to the Tidepool service</string>
<string name="title_sync_to_tidepool">Sync to Tidepool</string>
<string name="summary_tidepool_username">Your Tidepool login user name, normally your email address</string>
<string name="title_tidepool_username">Login User Name</string>
<string name="summary_tidepool_password">Your Tidepool login password</string>

View file

@ -4,11 +4,6 @@
android:summary="@string/summary_tidepool_upload_screen"
android:title="@string/tidepool">
<SwitchPreference
android:defaultValue="false"
android:key="@string/key_cloud_storage_tidepool_enable"
android:title="@string/title_sync_to_tidepool" />
<EditTextPreference
android:key="@string/key_tidepool_username"
android:summary="@string/summary_tidepool_username"