2222
2323import android .os .Bundle ;
2424import android .support .design .widget .Snackbar ;
25+ import android .support .design .widget .TextInputLayout ;
26+ import android .support .v7 .app .AppCompatActivity ;
27+ import android .support .v7 .widget .AppCompatButton ;
2528import android .support .v7 .widget .Toolbar ;
2629import android .view .View ;
2730import android .widget .AdapterView ;
@@ -49,6 +52,8 @@ public class AddGlucoseActivity extends AddReadingActivity {
4952 private TextView readingTextView ;
5053 private EditText typeCustomEditText ;
5154 private EditText notesEditText ;
55+ private AppCompatButton addFreeStyleButton ;
56+ private TextInputLayout readingInputLayout ;
5257 private LabelledSpinner readingTypeSpinner ;
5358 private boolean isCustomType = false ;
5459
@@ -74,6 +79,8 @@ protected void onCreate(Bundle savedInstanceState) {
7479 readingTypeSpinner .setItemsArray (R .array .dialog_add_measured_list );
7580 readingTextView = (TextView ) findViewById (R .id .glucose_add_concentration );
7681 typeCustomEditText = (EditText ) findViewById (R .id .glucose_type_custom );
82+ readingInputLayout = (TextInputLayout ) findViewById (R .id .glucose_add_concentration_layout );
83+ addFreeStyleButton = (AppCompatButton ) findViewById (R .id .glucose_add_freestyle_button );
7784 notesEditText = (EditText ) findViewById (R .id .glucose_add_notes );
7885
7986 this .createDateTimeViewAndListener ();
@@ -138,7 +145,38 @@ public void onNothingChosen(View labelledSpinner, AdapterView<?> adapterView) {
138145 presenter .updateSpinnerTypeTime ();
139146 }
140147
141- this .getDoneFAB ().postDelayed (this .getFabAnimationRunnable (), 600 );
148+ this .getDoneFAB ().postDelayed (this .getFabAnimationRunnable (), 600 )
149+
150+ // Check if activity was started from a NFC sensor
151+ if (getIntent ().getExtras () != null ) {
152+ Bundle p ;
153+ String reading ;
154+
155+ p = getIntent ().getExtras ();
156+ reading = p .getString ("reading" );
157+ if (reading !=null ) {
158+ // If yes, first convert the decimal value from Freestyle to Integer
159+ double d = Double .parseDouble (reading );
160+ int glucoseValue = (int ) d ;
161+ readingTextView .setText (glucoseValue + "" );
162+ readingInputLayout .setErrorEnabled (true );
163+ readingInputLayout .setError (getResources ().getString (R .string .dialog_add_glucose_freestylelibre_added ));
164+ addFreeStyleButton .setVisibility (View .GONE );
165+
166+ addAnalyticsEvent ();
167+ }
168+ }
169+
170+ // Check if FreeStyle support is enabled in Preferences
171+ if (presenter .isFreeStyleLibreEnabled ()) {
172+ addFreeStyleButton .setVisibility (View .VISIBLE );
173+ addFreeStyleButton .setOnClickListener (new View .OnClickListener () {
174+ @ Override
175+ public void onClick (View view ) {
176+ startLibreActivity ();
177+ }
178+ });
179+ }
142180 }
143181
144182 private void addAnalyticsEvent () {
@@ -172,6 +210,10 @@ public void showErrorMessage() {
172210 Snackbar .make (rootLayout , getString (R .string .dialog_error2 ), Snackbar .LENGTH_SHORT ).show ();
173211 }
174212
213+ public void startLibreActivity () {
214+ Intent intent = new Intent (this , FreestyleLibreActivity .class );
215+ startActivity (intent );
216+ }
175217
176218 public void showDuplicateErrorMessage () {
177219 View rootLayout = findViewById (android .R .id .content );
@@ -193,4 +235,5 @@ public void onTimeSet(RadialPickerLayout view, int hourOfDay, int minute, int se
193235 DecimalFormat df = new DecimalFormat ("00" );
194236 updateSpinnerTypeHour (Integer .parseInt (df .format (hourOfDay )));
195237 }
238+
196239}
0 commit comments