File tree Expand file tree Collapse file tree 1 file changed +10
-3
lines changed
app/src/main/java/com/example/deco3801project Expand file tree Collapse file tree 1 file changed +10
-3
lines changed Original file line number Diff line number Diff line change @@ -366,7 +366,6 @@ protected void onNewIntent(Intent intent) {
366366 BluetoothAdapter bAdapter = BluetoothAdapter .getDefaultAdapter ();
367367 BluetoothDevice bDevice = bAdapter .getRemoteDevice (mac );
368368 try {
369- Toast .makeText (context , "Connect starts" , Toast .LENGTH_LONG ).show ();
370369 new ConnectThread (bDevice );
371370 } catch (IOException e ) {
372371 e .printStackTrace ();
@@ -420,12 +419,20 @@ public void receive() throws IOException {
420419 InputStream mmInputStream = socket .getInputStream ();
421420 byte [] buffer = new byte [256 ];
422421 int bytes ;
423-
422+ SharedPreferences . Editor edit = pref . edit ();
424423 try {
425424 bytes = mmInputStream .read (buffer );
426425 String readMessage = new String (buffer , 0 , bytes );
427426 Toast .makeText (context , readMessage , Toast .LENGTH_LONG ).show ();
428-
427+ if (!pref .contains ("firstReading" )) {
428+ edit .putInt ("firstReading" , Integer .parseInt (readMessage ));
429+ } else {
430+ int firstReading = pref .getInt ("firstReading" , 0 );
431+ int result = firstReading - Integer .parseInt (readMessage );
432+ logIntakeHelper (result );
433+ edit .remove ("firstReading" );
434+ }
435+ edit .apply ();
429436 socket .close ();
430437 } catch (IOException e ) {
431438 finish ();
You can’t perform that action at this time.
0 commit comments