diff --git a/wear/build.gradle b/wear/build.gradle index 26779263e2..aa6a9b538d 100644 --- a/wear/build.gradle +++ b/wear/build.gradle @@ -1,5 +1,25 @@ apply plugin: 'com.android.application' +def generateGitBuild = { -> + + StringBuilder stringBuilder = new StringBuilder(); + stringBuilder.append('"') + try { + def stdout = new ByteArrayOutputStream() + exec { + commandLine 'git', 'describe', '--always' + standardOutput = stdout + } + String commitObject = stdout.toString().trim() + stringBuilder.append(commitObject) + } catch (ignored) { + stringBuilder.append('NoGitSystemAvailable') + } + stringBuilder.append('-') + stringBuilder.append((new Date()).format('yyyy.MM.dd')) + stringBuilder.append('"') + return stringBuilder.toString() +} android { compileSdkVersion 23 @@ -11,6 +31,7 @@ android { targetSdkVersion 23 versionCode 1 versionName "1.0.2" + buildConfigField "String", "BUILDVERSION", generateGitBuild() } buildTypes { release { diff --git a/wear/src/main/java/info/nightscout/androidaps/interaction/utils/VersionPreference.java b/wear/src/main/java/info/nightscout/androidaps/interaction/utils/VersionPreference.java new file mode 100644 index 0000000000..3bc05af82d --- /dev/null +++ b/wear/src/main/java/info/nightscout/androidaps/interaction/utils/VersionPreference.java @@ -0,0 +1,31 @@ +package info.nightscout.androidaps.interaction.utils; + +import android.content.Context; +import android.content.SharedPreferences; +import android.preference.PreferenceManager; +import android.support.annotation.NonNull; +import android.util.AttributeSet; +import android.widget.Toast; + +import info.nightscout.androidaps.BuildConfig; +import preference.WearListPreference; + +/** + * Created by adrian on 07/08/17. + */ + +public class VersionPreference extends WearListPreference { + public VersionPreference(Context context, AttributeSet attrs) { + super(context, attrs); + entries = new CharSequence[]{BuildConfig.BUILDVERSION}; + entryValues = new CharSequence[]{BuildConfig.BUILDVERSION}; + } + + @Override public CharSequence getSummary(@NonNull final Context context) { + return BuildConfig.BUILDVERSION; + } + @Override + public void onPreferenceClick(@NonNull Context context) { + Toast.makeText(context, "Build version:" + BuildConfig.BUILDVERSION, Toast.LENGTH_LONG).show(); + } +} diff --git a/wear/src/main/res/xml/preferences.xml b/wear/src/main/res/xml/preferences.xml index aa78611b0c..2d97a82931 100644 --- a/wear/src/main/res/xml/preferences.xml +++ b/wear/src/main/res/xml/preferences.xml @@ -149,4 +149,11 @@ android:title="Wizard Percentage" app:wear_iconOff="@drawable/settings_off" app:wear_iconOn="@drawable/settings_on"/> +