package com.reiyu.sleepin;

import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.TimePicker;

import com.parse.ParseException;
import com.parse.ParseObject;
import com.parse.SaveCallback;

/**
 * Created by Satomi on 1/3/16.
 */
public class WakeUpActivity extends FragmentActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.fragment_wake_up);
        Button button = (Button) findViewById(R.id.save_record);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                DatePicker datePicker = (DatePicker) findViewById(R.id.datePicker);
                int  day  = datePicker.getDayOfMonth();
                int  month= datePicker.getMonth();
                int  year = datePicker.getYear();
                String date = year + "/" + month + "/" + day;

                TimePicker tp1 = (TimePicker) findViewById(R.id.go_to_bed);
                TimePicker tp2 = (TimePicker) findViewById(R.id.wake_up);
                tp1.setIs24HourView(true);
                tp1.setIs24HourView(true);
                EditText memoText = (EditText) findViewById(R.id.memo);

                int hour  = tp1.getCurrentHour();
                int  minute = tp1.getCurrentMinute();
                String go_to_bed_time = hour + ":" + minute;
                hour  = tp2.getCurrentHour();
                minute = tp2.getCurrentMinute();
                String wake_up_time = hour + ":" + minute;
                String memo = memoText.getText().toString();

                ParseObject testObject = new ParseObject("SleepRecord");
                testObject.put("date", date);
                testObject.put("go_to_bed", go_to_bed_time);
                testObject.put("wake_up", wake_up_time);
                testObject.put("memo", memo);
                testObject.saveInBackground(new SaveCallback() {
                    public void done(ParseException e) {
                        if (e == null) {
                            Log.e("Sleep Record", "Successfully saved");
                        } else {
                            // Sign up didn't succeed. Look at the ParseException
                            // to figure out what went wrong
                            Log.e("Sleep Record", "Error", e);
                        }
                    }
                });
            }
        });
    }
}
@@ -40,17 +40,135 @@
 oid.
-os.Bundle
+content.Intent;%0Aimport android.content.SharedPreferences;%0Aimport android.os.Bundle;%0Aimport android.preference.PreferenceManager
 ;%0Aim
@@ -585,16 +585,34 @@
 ivity %7B%0A
+    String date;%0A%0A
     @Ove
@@ -1215,31 +1215,24 @@
             
-String 
 date = year 
@@ -1243,15 +1243,21 @@
 %22 + 
+(
 month +
+ 1) +
  %22/%22
@@ -1951,24 +1951,241 @@
 oString();%0A%0A
+                SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(WakeUpActivity.this);%0A                String email = sp.getString(%22@string/email%22, null);%0A%0A                if (email != null) %7B%0A    
             
@@ -2253,32 +2253,36 @@
                 
+  
+  
 testObject.put(%22
@@ -2291,24 +2291,28 @@
 te%22, date);%0A
+    
             
@@ -2368,32 +2368,36 @@
                 
+ 
+   
 testObject.put(%22
@@ -2413,32 +2413,36 @@
  wake_up_time);%0A
+    
                 
@@ -2471,16 +2471,72 @@
  memo);%0A
+                    testObject.put(%22email%22, email);%0A    
         
@@ -2604,32 +2604,36 @@
                 
+   
+ 
 public void done
@@ -2673,24 +2673,28 @@
             
+    
 if (e == nul
@@ -2718,32 +2718,36 @@
                 
+  
+  
 Log.e(%22Sleep Rec
@@ -2771,24 +2771,74 @@
 ly saved%22);%0A
+                                wakeUp(date);%0A    
             
@@ -2858,16 +2858,20 @@
  else %7B%0A
+    
         
@@ -2972,16 +2972,20 @@
         
+   
+ 
 // to fi
@@ -3009,16 +3009,20 @@
 t wrong%0A
+    
         
@@ -3092,34 +3092,42 @@
                 
-%7D%0A
+    %7D%0A    
                 
@@ -3140,32 +3140,36 @@
                 
+    
 %7D);%0A            
@@ -3172,19 +3172,489 @@
     
-%7D%0A        %7D
+    %7D else %7B%0A                    Log.e(%22Sleep Record%22, %22email is null%22);%0A                    startActivity(new Intent(WakeUpActivity.this, SignInActivity.class));%0A                %7D%0A            %7D%0A        %7D);%0A    %7D%0A%0A    private void wakeUp(String date) %7B%0A        SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);%0A        sp.edit().putString(%22@string/record_updated%22, date).commit();%0A%0A        startActivity(new Intent(WakeUpActivity.this, MainActivity.class)
 );%0A 

add email column to identify user and modify month calculation