Skip to content
Snippets Groups Projects
Commit 29f34b23 authored by Lennart Goedhart's avatar Lennart Goedhart
Browse files

Fix #24. Split Nightscout URL and API Secret into separate preference fields.

Make only the log part of the UI scrolls.
parent 3c24754d
No related branches found
No related tags found
No related merge requests found
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="EntryPointsManager">
<entry_points version="2.0" />
</component>
<component name="NullableNotNullManager">
<option name="myDefaultNullable" value="android.support.annotation.Nullable" />
<option name="myDefaultNotNull" value="android.support.annotation.NonNull" />
......
......@@ -82,6 +82,7 @@
<sourceFolder url="file://$MODULE_DIR$/src/test/shaders" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/blame" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/builds" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/bundles" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dependency-cache" />
......
......@@ -18,6 +18,8 @@ import com.mongodb.ServerAddress;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoCursor;
import com.mongodb.client.MongoDatabase;
import info.nightscout.android.R;
import info.nightscout.android.medtronic.Medtronic640gActivity;
import info.nightscout.android.dexcom.EGVRecord;
import info.nightscout.android.medtronic.MedtronicConstants;
......@@ -57,13 +59,15 @@ import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import ch.qos.logback.classic.Logger;
import static com.mongodb.client.model.Filters.eq;
public class UploadHelper extends AsyncTask<Record, Integer, Long> {
private Logger log = (Logger) LoggerFactory.getLogger(MedtronicReader.class.getName());
private static final String TAG = "DexcomUploadHelper";
private SharedPreferences settings = null;// common application preferences
......@@ -397,29 +401,41 @@ public class UploadHelper extends AsyncTask<Record, Integer, Long> {
}
private void doRESTUpload(SharedPreferences prefs, Record... records) {
String baseURLSettings = prefs.getString("API Base URL", "");
ArrayList<String> baseURIs = new ArrayList<String>();
String apiScheme = "https://";
String apiUrl = "";
String apiSecret = prefs.getString(context.getString(R.string.preference_api_secret), "YOURAPISECRET");
try {
for (String baseURLSetting : baseURLSettings.split(" ")) {
String baseURL = baseURLSetting.trim();
if (baseURL.isEmpty()) continue;
baseURIs.add(baseURL + (baseURL.endsWith("/") ? "" : "/"));
}
} catch (Exception e) {
Log.e(TAG, "Unable to process API Base URL setting: " + baseURLSettings, e);
log.error("Unable to process API Base URL setting: " + baseURLSettings, e);
return;
}
// Add the extra match for "KEY@" to support the previous single field
Pattern p = Pattern.compile("(.*\\/\\/)?(.*@)?([^\\/]*)(.*)");
Matcher m = p.matcher(prefs.getString(context.getString(R.string.preference_nightscout_url), ""));
for (String baseURI : baseURIs) {
try {
doRESTUploadTo(baseURI, records);
} catch (Exception e) {
Log.e(TAG, "Unable to do REST API Upload to: " + baseURI, e);
log.error("Unable to do REST API Upload to: " + baseURI, e);
}
}
if( m.find() ) {
apiUrl = m.group(3);
// Only override apiSecret from URL (the "old" way), if the API secret preference is empty
if( apiSecret.equals("YOURAPISECRET") || apiSecret.equals("") ) {
apiSecret = ( m.group(2) == null ) ? "" : m.group(2).replace("@", "");
}
// Override the URI scheme if it's been provided in the preference)
if( m.group(1) != null && !m.group(1).equals("") ) {
apiScheme = m.group(1);
}
}
// Update the preferences to match what we expect. Only really used from converting from the
// old format to the new format. Aren't we nice for managing backward compatibility?
prefs.edit().putString(context.getString(R.string.preference_api_secret), apiSecret ).apply();
prefs.edit().putString(context.getString(R.string.preference_nightscout_url), String.format("%s%s", apiScheme, apiUrl ) ).apply();
String uploadUrl = String.format("%s%s@%s/api/v1/", apiScheme, apiSecret, apiUrl );
try {
doRESTUploadTo(uploadUrl, records);
} catch (Exception e) {
Log.e(TAG, "Unable to do REST API Upload to: " + uploadUrl, e);
log.error("Unable to do REST API Upload to: " + uploadUrl, e);
}
}
@SuppressWarnings({ "rawtypes", "unchecked" })
private void doRESTUploadTo(String baseURI, Record[] records) {
......
......@@ -5,42 +5,43 @@
android:orientation="vertical"
android:paddingTop="15dp">
<ScrollView
android:id="@+id/demoScroller"
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp">
android:layout_height="wrap_content">
<LinearLayout
android:orientation="vertical"
<TextView
android:id="@+id/demoTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content">
android:layout_height="wrap_content"
android:textSize="50sp"
android:gravity="center"
android:textStyle="bold"
<TextView
android:id="@+id/demoTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="50sp"
android:gravity="center"
android:textStyle="bold"
android:text="@string/hello" />
android:text="@string/hello" />
<TextView
android:id="@+id/demoText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
<TextView
android:id="@+id/demoText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:gravity="left" />
android:gravity="left" />
<ScrollView
android:id="@+id/demoScroller"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp">
<LinearLayout android:id="@+id/container"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
</LinearLayout>
</LinearLayout>
</ScrollView>
</ScrollView>
</LinearLayout>
</LinearLayout>
......
......@@ -113,4 +113,6 @@
<string name="permission_rationale">"Contacts permissions are needed for providing email
completions."
</string>
<string name="preference_nightscout_url">Nightscout URL</string>
<string name="preference_api_secret">API SECRET</string>
</resources>
......@@ -30,12 +30,20 @@
</info.nightscout.android.utils.CustomSwitchPreference>
<EditTextPreference
android:dependency="EnableRESTUpload"
android:title="API Base URL"
android:key="API Base URL"
android:dialogTitle="Enter Base API URL"
android:defaultValue="{YOURAPISECRET}@https://{YOUR.NIGHTSCOUT.SITE}/api/v1/"
android:dialogMessage="This only the base URL, the uploader will automatically append /entries for the POST of CGM data and /gdentries for the POST of glucometer data values">
android:title="Nightscout URL"
android:key="@string/preference_nightscout_url"
android:dialogTitle="Enter Nightscout URL"
android:defaultValue="https://YOUR.NIGHTSCOUT.SITE"
android:dialogMessage="The hostname of your Nightscout site">
</EditTextPreference>
<EditTextPreference
android:dependency="EnableRESTUpload"
android:title="API Secret"
android:key="@string/preference_api_secret"
android:dialogTitle="Enter your Nightscout API secret"
android:defaultValue="YOURAPISECRET"
android:dialogMessage="Your Nightscout API secret">
</EditTextPreference>
<info.nightscout.android.utils.CustomSwitchPreference
android:title="Wifi Hack"
android:key="EnableWifiHack"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment