diff --git a/app/build.gradle b/app/build.gradle
index 73eaee3179..d2d6dfecbb 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -160,6 +160,8 @@ android {
unitTests.returnDefaultValues = true
unitTests.includeAndroidResources = true
}
+
+ useLibrary "org.apache.http.legacy"
}
allprojects {
diff --git a/app/src/main/java/info/nightscout/androidaps/MainActivity.java b/app/src/main/java/info/nightscout/androidaps/MainActivity.java
index adc4cf5a02..adfa8f5e6e 100644
--- a/app/src/main/java/info/nightscout/androidaps/MainActivity.java
+++ b/app/src/main/java/info/nightscout/androidaps/MainActivity.java
@@ -63,6 +63,7 @@ import info.nightscout.utils.LogDialog;
import info.nightscout.utils.OKDialog;
import info.nightscout.utils.PasswordProtection;
import info.nightscout.utils.SP;
+import info.nightscout.utils.VersionChecker;
public class MainActivity extends AppCompatActivity {
private static Logger log = LoggerFactory.getLogger(L.CORE);
@@ -118,6 +119,7 @@ public class MainActivity extends AppCompatActivity {
public void onPageScrollStateChanged(int state) {
}
});
+ VersionChecker.check();
}
private void checkPluginPreferences(ViewPager viewPager) {
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/notifications/Notification.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/notifications/Notification.java
index 036faf4a6f..0112963051 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/notifications/Notification.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/notifications/Notification.java
@@ -66,6 +66,7 @@ public class Notification {
public static final int PERMISSION_SMS = 38;
public static final int MAXIMUM_BASAL_VALUE_REPLACED = 39;
public static final int NSMALFUNCTION = 40;
+ public static final int NEWVERSIONDETECTED = 41;
public int id;
diff --git a/app/src/main/java/info/nightscout/utils/VersionChecker.java b/app/src/main/java/info/nightscout/utils/VersionChecker.java
new file mode 100644
index 0000000000..34538820bc
--- /dev/null
+++ b/app/src/main/java/info/nightscout/utils/VersionChecker.java
@@ -0,0 +1,97 @@
+package info.nightscout.utils;
+
+import android.net.ConnectivityManager;
+import android.net.NetworkInfo;
+
+import org.apache.http.HttpResponse;
+import org.apache.http.client.HttpClient;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.impl.client.DefaultHttpClient;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import info.nightscout.androidaps.BuildConfig;
+import info.nightscout.androidaps.MainApp;
+import info.nightscout.androidaps.R;
+import info.nightscout.androidaps.logging.L;
+import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
+import info.nightscout.androidaps.plugins.Overview.notifications.Notification;
+
+import static android.content.Context.CONNECTIVITY_SERVICE;
+
+public class VersionChecker {
+ private static Logger log = LoggerFactory.getLogger(L.CORE);
+
+ public static void check() {
+ if (isConnected())
+ new Thread(() -> {
+ HttpClient client = new DefaultHttpClient();
+ HttpGet request = new HttpGet("https://raw.githubusercontent.com/MilosKozak/AndroidAPS/master/app/build.gradle");
+ HttpResponse response;
+
+ try {
+ response = client.execute(request);
+ InputStream inputStream = response.getEntity().getContent();
+
+ if (inputStream != null) {
+ String result = findLine(inputStream);
+ if (result != null) {
+ result = result.replace("version", "").replace("\"", "").replace("\\s+", "").trim();
+ int compare = result.compareTo(BuildConfig.VERSION_NAME.replace("\"", ""));
+ if (compare == 0) {
+ log.debug("Version equal to master");
+ return;
+ } else if (compare > 0) {
+ log.debug("Version outdated. Found " + result);
+ Notification notification = new Notification(Notification.NEWVERSIONDETECTED, String.format(MainApp.gs(R.string.versionavailable), result), Notification.LOW);
+ MainApp.bus().post(new EventNewNotification(notification));
+ return;
+ } else {
+ log.debug("Version newer than master. Are you developer?");
+ return;
+ }
+ }
+ }
+
+ log.debug("Github master version not found");
+
+ } catch (IOException e) {
+ e.printStackTrace();
+ log.debug("Github master version check error");
+ }
+ }).start();
+ else
+ log.debug("Github master version no checked. No connectivity");
+ }
+
+ // convert inputstream to String
+ private static String findLine(InputStream inputStream) throws IOException {
+ BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
+ String line;
+ String regex = "(.*)version(.*)\"(\\d+)\\.(\\d+)\"(.*)";
+ Pattern p = Pattern.compile(regex);
+
+ while ((line = bufferedReader.readLine()) != null) {
+ Matcher m = p.matcher(line);
+ if (m.matches())
+ return line;
+ }
+ inputStream.close();
+ return null;
+ }
+
+ // check network connection
+ public static boolean isConnected() {
+ ConnectivityManager connMgr = (ConnectivityManager) MainApp.instance().getApplicationContext().getSystemService(CONNECTIVITY_SERVICE);
+ NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
+ return networkInfo != null && networkInfo.isConnected();
+ }
+
+}
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 61ebacac5a..114f467a27 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -1171,6 +1171,7 @@
Log settings
Reset to defaults
NSClient malfunction. Consider NS and NSClient restart.
+ Version %1$s available
- %1$d day