diff --git a/app/src/main/java/com/example/leo/fitnessdiy/PushupActivity.java b/app/src/main/java/com/example/leo/fitnessdiy/PushupActivity.java index 86fd774d8ffe57da9e5c95c28dc793358efde995..a696836f483bb02016c2462dcc7e5eb8252e29f6 100644 --- a/app/src/main/java/com/example/leo/fitnessdiy/PushupActivity.java +++ b/app/src/main/java/com/example/leo/fitnessdiy/PushupActivity.java @@ -53,15 +53,20 @@ public class PushupActivity extends AppCompatActivity{ SimpleDateFormat formatDate = new SimpleDateFormat("yyyy-MM-dd"); pushup_date = formatDate.format(new Date()); + + user = Integer.toString(mPreferences.getInt(UsersSharedPreferences.ID_USERS, -999)); } public void setPushUpFrequency(String level){ TextView pushUpTask = (TextView)findViewById(R.id.pushUpTask); if(level.equals("begineer")){ + pushup_frequency = ""+30; pushUpTask.setText("Do Push Up 30 times"); }else if(level.equals("intermediate")){ + pushup_frequency = ""+60; pushUpTask.setText("Do Push Up 60 times"); }else if(level.equals("advanced")){ + pushup_frequency = ""+90; pushUpTask.setText("Do Push Up 90 times"); } } @@ -84,7 +89,7 @@ public class PushupActivity extends AppCompatActivity{ SimpleDateFormat formatTime = new SimpleDateFormat("HH:mm:ss"); pushup_time_end = formatTime.format(new Date()); - addPlankHistory(user, pushup_date, pushup_time_start, pushup_time_end, pushup_frequency); + addPushupHistory(user, pushup_date, pushup_time_start, pushup_time_end, pushup_frequency); Log.d(LOG_TAG, "waktu selesai pushup : "+pushup_time_end); } @@ -101,11 +106,12 @@ public class PushupActivity extends AppCompatActivity{ Log.d(LOG_TAG, "waktu mulai pushup : "+pushup_time_start); } - public void addPlankHistory(String user, String pushup_date, String pushup_time_start, + public void addPushupHistory(String user, String pushup_date, String pushup_time_start, String pushup_time_end, String pushup_frequency){ String urlstring = api.ADD_PUSHUP_HISTORY_URL+"user="+user+"&pushup_date="+pushup_date+"&pushup_time_start="+pushup_time_start+ "&pushup_time_end="+pushup_time_end+"&pushup_frequency="+pushup_frequency; + Log.d(LOG_TAG+" (URL) : ", urlstring); if (android.os.Build.VERSION.SDK_INT > 9) { StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); @@ -123,7 +129,7 @@ public class PushupActivity extends AppCompatActivity{ } } catch (MalformedURLException e){ e.printStackTrace(); - }catch (IOException e) { + } catch (IOException e) { e.printStackTrace(); } } diff --git a/app/src/main/java/com/example/leo/fitnessdiy/SitupActivity.java b/app/src/main/java/com/example/leo/fitnessdiy/SitupActivity.java index 74a035cf9bd1481dd48dbdd96e0bfb0bdc8184cf..8759415076279cedba6d48616d3ab73892f738ef 100644 --- a/app/src/main/java/com/example/leo/fitnessdiy/SitupActivity.java +++ b/app/src/main/java/com/example/leo/fitnessdiy/SitupActivity.java @@ -4,18 +4,36 @@ import android.content.Intent; import android.content.SharedPreferences; import android.net.Uri; import android.os.Bundle; +import android.os.StrictMode; import android.support.v7.app.AppCompatActivity; +import android.util.Log; import android.view.View; import android.widget.Button; import android.widget.TextView; import com.example.leo.fitnessdiy.model.UsersSharedPreferences; +import com.example.leo.fitnessdiy.routes.api; + +import java.io.IOException; +import java.io.InputStream; +import java.net.HttpURLConnection; +import java.net.MalformedURLException; +import java.net.URL; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.Scanner; /** * Created by Heil on 2/19/2018. */ public class SitupActivity extends AppCompatActivity{ + private String user; + private String situp_date; + private String situp_time_start; + private String situp_time_end; + private String situp_frequency; + private String LOG_TAG = "SITUP ACTIVITY"; @Override protected void onCreate(Bundle savedInstanceState) { @@ -32,15 +50,22 @@ public class SitupActivity extends AppCompatActivity{ int background = mPreferences.getInt(BACKGROUND_KEY, R.drawable.green_theme); getWindow().getDecorView().setBackground(getResources().getDrawable(background)); + + user = Integer.toString(mPreferences.getInt(UsersSharedPreferences.ID_USERS, -999)); + SimpleDateFormat formatDate = new SimpleDateFormat("yyyy-MM-dd"); + situp_date = formatDate.format(new Date()); } public void setSitUpFrequency(String level){ TextView sitUpTask = (TextView)findViewById(R.id.sitUpTask); if(level.equals("begineer")){ + situp_frequency = ""+30; sitUpTask.setText("Do Sit Up 30 times"); }else if(level.equals("intermediate")){ + situp_frequency = ""+60; sitUpTask.setText("Do Sit Up 60 times"); }else if(level.equals("advanced")){ + situp_frequency = ""+90; sitUpTask.setText("Do Sit Up 90 times"); } } @@ -59,6 +84,11 @@ public class SitupActivity extends AppCompatActivity{ public void taskComplete(View view) { TextView tv = (TextView)findViewById(R.id.sitUpTask); tv.setText("Berhasil"); + + SimpleDateFormat formatTime = new SimpleDateFormat("HH:mm:ss"); + situp_time_end = formatTime.format(new Date()); + Log.d(LOG_TAG, "waktu selesai situp : "+situp_time_end); + addSitupHistory(user, situp_date, situp_time_start, situp_time_end, situp_frequency); } public void taskBegin(View view) { @@ -68,5 +98,37 @@ public class SitupActivity extends AppCompatActivity{ Button button2 = (Button) findViewById(R.id.finish_situp_button); button2.setVisibility(View.VISIBLE); + + SimpleDateFormat formatTime = new SimpleDateFormat("HH:mm:ss"); + situp_time_start = formatTime.format(new Date()); + Log.d(LOG_TAG, "waktu mulai situp : "+situp_time_start); } + + public void addSitupHistory(String user, String situp_date, String situp_time_start, + String situp_time_end, String situp_frequency){ + String urlstring = api.ADD_SITUP_HISTORY_URL+"user="+user+"&situp_date="+situp_date+"&situp_time_start="+situp_time_start+ + "&situp_time_end="+situp_time_end+"&situp_frequency="+situp_frequency; + Log.d(LOG_TAG+" (URL) : ", urlstring); + + if (android.os.Build.VERSION.SDK_INT > 9) { + StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); + StrictMode.setThreadPolicy(policy); + } + try{ + URL url = new URL(urlstring); + HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection(); + + try{ + InputStream in = urlConnection.getInputStream(); + Scanner scanner = new Scanner(in); + } finally { + urlConnection.disconnect(); + } + } catch (MalformedURLException e){ + e.printStackTrace(); + } catch (IOException e){ + e.printStackTrace(); + } + } + } diff --git a/app/src/main/java/com/example/leo/fitnessdiy/routes/api.java b/app/src/main/java/com/example/leo/fitnessdiy/routes/api.java index c0966549b8e2a391775c118bc1c12218146239f4..7c268f6e91ae2209afa80e4a5aebbd440fde5c5e 100644 --- a/app/src/main/java/com/example/leo/fitnessdiy/routes/api.java +++ b/app/src/main/java/com/example/leo/fitnessdiy/routes/api.java @@ -34,4 +34,6 @@ public class api { public static final String ADD_PLANK_HISTORY_URL = BASE_URL + "add_plank_history.php?"; public static final String ADD_PUSHUP_HISTORY_URL = BASE_URL + "add_pushup_history.php?"; + + public static final String ADD_SITUP_HISTORY_URL = BASE_URL + "add_situp_history.php?"; }