Skip to content
Snippets Groups Projects
Commit e936e43e authored by unknown's avatar unknown
Browse files

History Backend done

parent f022b141
Branches
No related merge requests found
package com.example.leo.fitnessdiy.Adapter;
import android.support.v7.widget.CardView;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import com.example.leo.fitnessdiy.R;
import com.example.leo.fitnessdiy.model.History;
import java.util.List;
/**
* Created by Leo on 16/02/2018.
*/
public class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerViewAdapter.HistoryViewHolder> {
private List<History> histories;
public RecyclerViewAdapter(List<History> h) {
this.histories = h;
}
@Override
public HistoryViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.card, parent, false);
HistoryViewHolder hvh = new HistoryViewHolder(view);
return hvh;
}
@Override
public void onBindViewHolder(HistoryViewHolder holder, int position) {
holder.sportName.setText(histories.get(position).getSport_name());
holder.sportDate.setText(histories.get(position).getSport_date());
holder.sportStart.setText(histories.get(position).getSport_start());
holder.sportEnd.setText(histories.get(position).getSport_end());
}
@Override
public int getItemCount() {
return histories.size();
}
@Override
public void onAttachedToRecyclerView(RecyclerView recyclerView) {
super.onAttachedToRecyclerView(recyclerView);
}
public static class HistoryViewHolder extends RecyclerView.ViewHolder {
TextView sportName;
TextView sportDate;
TextView sportStart;
TextView sportEnd;
public HistoryViewHolder(View itemView) {
super(itemView);
sportName = (TextView) itemView.findViewById(R.id.sport_name);
sportDate = (TextView) itemView.findViewById(R.id.sport_date);
sportStart = (TextView) itemView.findViewById(R.id.sport_start);
sportEnd = (TextView) itemView.findViewById(R.id.sport_end);
}
}
}
...@@ -4,32 +4,68 @@ package com.example.leo.fitnessdiy; ...@@ -4,32 +4,68 @@ package com.example.leo.fitnessdiy;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
import android.os.Bundle; import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.TextView; import android.widget.TextView;
import com.example.leo.fitnessdiy.Adapter.RecyclerViewAdapter;
import com.example.leo.fitnessdiy.Utilities.NetworkUtils; import com.example.leo.fitnessdiy.Utilities.NetworkUtils;
import com.example.leo.fitnessdiy.model.History;
import com.example.leo.fitnessdiy.routes.api; import com.example.leo.fitnessdiy.routes.api;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.IOException; import java.io.IOException;
import java.net.URL; import java.net.URL;
import java.util.ArrayList;
import java.util.List;
public class HIstoryActivity extends AppCompatActivity { public class HIstoryActivity extends AppCompatActivity {
public static final String TAG = HIstoryActivity.class.getSimpleName(); public static final String TAG = HIstoryActivity.class.getSimpleName();
private TextView mHasil; private RecyclerView mRecyclerView;
private List<History> histories;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_history); setContentView(R.layout.activity_history);
mHasil = (TextView) findViewById(R.id.hasil);
String githubSearchResults = null; String fetchResults = null;
// try {
// githubSearchResults = NetworkUtils.getResponseFromHttpUrl(new URL(api.HISTORY_URL + "1"));
fetchResults = "[{\"id\":\"1\",\"id_user\":\"1\",\"sport_name\":\"jogging\",\"sport_date\":\"2018-02-14\",\"sport_time_start\":\"09:00:00\",\"sport_time_end\":\"11:00:00\",\"created_at\":null,\"updated_at\":null},{\"id\":\"2\",\"id_user\":\"1\",\"sport_name\":\"jogging\",\"sport_date\":\"2018-02-15\",\"sport_time_start\":\"09:00:00\",\"sport_time_end\":\"11:00:00\",\"created_at\":null,\"updated_at\":null},{\"id\":\"3\",\"id_user\":\"1\",\"sport_name\":\"plank\",\"sport_date\":\"2018-02-16\",\"sport_time_start\":\"09:00:00\",\"sport_time_end\":\"09:45:00\",\"created_at\":null,\"updated_at\":null},{\"id\":\"4\",\"id_user\":\"1\",\"sport_name\":\"push-up\",\"sport_date\":\"2018-02-16\",\"sport_time_start\":\"10:00:00\",\"sport_time_end\":\"10:30:00\",\"created_at\":null,\"updated_at\":null}]";
initializeData(fetchResults);
// } catch (IOException e) {
// e.printStackTrace();
// }
mRecyclerView = (RecyclerView) findViewById(R.id.rv_history);
LinearLayoutManager layoutManager = new LinearLayoutManager(this);
mRecyclerView.setLayoutManager(layoutManager);
mRecyclerView.setHasFixedSize(true);
RecyclerViewAdapter rv = new RecyclerViewAdapter(histories);
mRecyclerView.setAdapter(rv);
}
public void initializeData(String data) {
this.histories = new ArrayList<>();
try { try {
githubSearchResults = NetworkUtils.getResponseFromHttpUrl(new URL(api.HISTORY_URL + "1")); JSONArray parser = new JSONArray(data);
mHasil.setText(githubSearchResults); for (int i = 0; i < parser.length(); i++) {
} catch (IOException e) { JSONObject json = parser.getJSONObject(i);
histories.add(new History(json.getString("sport_name"),
json.getString("sport_date"),
json.getString("sport_time_start"),
json.getString("sport_time_end")));
}
} catch (JSONException e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
......
package com.example.leo.fitnessdiy.model;
/**
* Created by Leo on 16/02/2018.
*/
public class History {
private String sport_name;
private String sport_date;
private String sport_start;
private String sport_end;
public History(String name, String date, String start, String end) {
this.sport_name = name;
this.sport_date = date;
this.sport_start = start;
this.sport_end = end;
}
public String getSport_name() {
return sport_name;
}
public void setSport_name(String sport_name) {
this.sport_name = sport_name;
}
public String getSport_date() {
return sport_date;
}
public void setSport_date(String sport_date) {
this.sport_date = sport_date;
}
public String getSport_start() {
return sport_start;
}
public void setSport_start(String sport_start) {
this.sport_start = sport_start;
}
public String getSport_end() {
return sport_end;
}
public void setSport_end(String sport_end) {
this.sport_end = sport_end;
}
}
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
xmlns:card_view="http://schemas.android.com/tools" xmlns:card_view="http://schemas.android.com/tools"
tools:context="com.example.leo.fitnessdiy.HIstoryActivity"> tools:context="com.example.leo.fitnessdiy.HIstoryActivity"
android:orientation="vertical">
<TextView <android.support.v7.widget.RecyclerView
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="match_parent"
android:id="@+id/hasil"/> android:id="@+id/rv_history"/>
</RelativeLayout> </LinearLayout>
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto" xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"> android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="16dp">
<android.support.v7.widget.CardView <TextView
android:id="@+id/cardview" android:layout_width="match_parent"
android:layout_width="match_parent" android:layout_height="wrap_content"
android:layout_height="match_parent" android:id="@+id/sport_name"/>
android:layout_gravity="center"
android:elevation="4dp"
card_view:cardUseCompatPadding="true"
card_view:cardElevation="5dp"
card_view:cardCornerRadius="1dp"
>
<RelativeLayout <TextView
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="wrap_content"
android:id="@+id/sport_date"
android:layout_below="@id/sport_name"/>
<TextView <TextView
android:id="@+id/nama_olahraga" android:layout_width="match_parent"
android:layout_width="match_parent" android:layout_height="wrap_content"
android:layout_height="wrap_content" android:id="@+id/sport_start"
android:paddingLeft="5dp" android:layout_below="@id/sport_date"/>
android:paddingRight="5dp"
android:paddingTop="5dp"
android:textColor="@color/cardview_dark_background"
android:textSize="12sp"
android:textStyle="normal"
android:typeface="sans" />
<TextView <TextView
android:id="@+id/tanggal_olahraga" android:layout_width="match_parent"
android:layout_width="match_parent" android:layout_height="wrap_content"
android:layout_height="wrap_content" android:id="@+id/sport_end"
android:layout_below="@id/nama_olahraga" android:layout_below="@id/sport_start"/>
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:paddingTop="5dp"
android:textColor="@color/cardview_dark_background"
android:textSize="12sp"
android:textStyle="normal"
android:typeface="sans" />
</RelativeLayout>
</android.support.v7.widget.CardView>
</LinearLayout> </RelativeLayout>
\ No newline at end of file \ No newline at end of file
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment