Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.ftn.timkodzo.niktest;
- import android.support.v7.app.AppCompatActivity;
- import android.os.Bundle;
- import butterknife.internal.Utils;
- public class MainActivity extends AppCompatActivity {
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- Utils.replaceFragment(this, new WorkoutDetailsFragment(), "workout_details");
- }}
- ////////////////////
- package com.ftn.timkodzo.niktest;
- import android.support.v7.widget.RecyclerView;
- import android.util.Log;
- import android.view.LayoutInflater;
- import android.view.View;
- import android.view.ViewGroup;
- import android.widget.ImageView;
- import android.widget.TextView;
- import java.util.List;
- import butterknife.BindView;
- import butterknife.ButterKnife;
- import butterknife.OnClick;
- public class WorkoutDetailsAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
- public static final int VIEW_TYPE_TITLE = 0;
- public static final int VIEW_TYPE_EXERCISE = 1;
- private WorkoutDetailsDataModel dataModel;
- public WorkoutDetailsAdapter(WorkoutDetailsDataModel dataModel){
- this.dataModel = dataModel;
- }
- @Override
- public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
- View view;
- LayoutInflater layoutInflater = LayoutInflater.from(parent.getContext());
- switch (viewType){
- case VIEW_TYPE_TITLE:
- view = layoutInflater.inflate(R.layout.row_workout_details_title, parent, false);
- return new TitleViewHolder(view);
- case VIEW_TYPE_EXERCISE:
- view = layoutInflater.inflate(R.layout.row_workout_details, parent, false);
- return new ExerciseViewHolder(view);
- default:
- Log.wtf("recyclerview", "Enter default in onCreateViewHolder");
- return null;
- }
- }
- public static class TitleViewHolder extends RecyclerView.ViewHolder{
- @BindView(R.id.time)
- TextView time;
- @BindView(R.id.cal) TextView cal;
- @BindView(R.id.title) TextView title;
- @BindView(R.id.description) TextView description;
- public TitleViewHolder(View itemView){
- super(itemView);
- ButterKnife.bind(this, itemView);
- }
- @OnClick(R.id.btn_download)
- protected void onDownloadClicked(){
- }
- @OnClick(R.id.see_details)
- protected void onSeeDetailsClicked(){
- }
- public void render(WorkoutDetailsDataModel dataModel){
- time.setText(dataModel.getTime());
- cal.setText(dataModel.getCal());
- title.setText(dataModel.getTitle());
- description.setText(dataModel.getDescription());
- }
- }
- public static class ExerciseViewHolder extends RecyclerView.ViewHolder{
- @BindView(R.id.image)
- ImageView image;
- @BindView(R.id.exercise_name) TextView exerciseName;
- @BindView(R.id.duration) TextView duration;
- public ExerciseViewHolder(View itemView){
- super(itemView);
- ButterKnife.bind(this, itemView);
- }
- @OnClick(R.id.exercise)
- public void exerciseClicked(){
- }
- public void render(WorkoutDetailsDataModel.ExerciseItemDataModel datamodel){
- image.setImageResource(R.drawable.avatar_icon);
- exerciseName.setText(datamodel.getExerciseName());
- duration.setText(datamodel.getDuration()+" ");
- }
- }
- @Override
- public void onBindViewHolder(RecyclerView.ViewHolder holder, int position, List<Object> payloads) {
- switch (getItemViewType(position)){
- case VIEW_TYPE_TITLE:
- ((TitleViewHolder) holder).render(dataModel);
- return;
- case VIEW_TYPE_EXERCISE:
- ((ExerciseViewHolder) holder).render(dataModel.getExercise(position));
- return;
- default:
- return;
- }
- }
- @Override
- public int getItemViewType(int position) {
- if (dataModel.isItemAtPositionExercise(position))
- return VIEW_TYPE_EXERCISE;
- return VIEW_TYPE_TITLE;
- }
- @Override
- public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
- }
- @Override
- public int getItemCount() {
- return dataModel == null ? 0 : dataModel.getNumberOfElementsToShow();
- }
- }
- ///////////////////////////////
- package com.ftn.timkodzo.niktest;
- import java.util.ArrayList;
- import java.util.List;
- public class WorkoutDetailsDataModel {
- String time;
- String cal;
- String title;
- String description;
- List<ExerciseItemDataModel> exerciseItems;
- public static WorkoutDetailsDataModel newInstance(){
- WorkoutDetailsDataModel dataModel = new WorkoutDetailsDataModel();
- /*dataModel.setTime("36");
- dataModel.setCal("265-290 cal");
- dataModel.setTitle("Body Conditioning \nStrenght + Cardio");
- dataModel.setDescription("Who doesn't like a combo? With eseential mix of cardio plus a bit more, strenght work, this program is designed to give you a wholesome, well rounded workus any day of the week");
- List<ExerciseItemDataModel> exerciseItems = new ArrayList<>(3);
- exerciseItems.add(ExerciseItemDataModel.newInstance("https://media.creativemornings.com/uploads/user/avatar/120448/profile-circle.png", "Run in place", 45));
- exerciseItems.add(ExerciseItemDataModel.newInstance("https://media.creativemornings.com/uploads/user/avatar/120448/profile-circle.png", "One lef floore bridges - left", 15));
- exerciseItems.add(ExerciseItemDataModel.newInstance("https://media.creativemornings.com/uploads/user/avatar/120448/profile-circle.png", "Run in place", 45));
- exerciseItems.add(ExerciseItemDataModel.newInstance("https://media.creativemornings.com/uploads/user/avatar/120448/profile-circle.png", "One lef floore bridges - left", 15));
- exerciseItems.add(ExerciseItemDataModel.newInstance("https://media.creativemornings.com/uploads/user/avatar/120448/profile-circle.png", "Run in place", 45));
- exerciseItems.add(ExerciseItemDataModel.newInstance("https://media.creativemornings.com/uploads/user/avatar/120448/profile-circle.png", "One lef floore bridges - left", 15));
- exerciseItems.add(ExerciseItemDataModel.newInstance("https://media.creativemornings.com/uploads/user/avatar/120448/profile-circle.png", "Run in place", 45));
- exerciseItems.add(ExerciseItemDataModel.newInstance("https://media.creativemornings.com/uploads/user/avatar/120448/profile-circle.png", "One lef floore bridges - left", 15));
- exerciseItems.add(ExerciseItemDataModel.newInstance("https://media.creativemornings.com/uploads/user/avatar/120448/profile-circle.png", "Run in place", 45));
- exerciseItems.add(ExerciseItemDataModel.newInstance("https://media.creativemornings.com/uploads/user/avatar/120448/profile-circle.png", "One lef floore bridges - left", 15));
- dataModel.setExerciseItems(exerciseItems);*/
- return dataModel;
- }
- private WorkoutDetailsDataModel() { }
- public int getNumberOfElementsToShow(){
- return exerciseItems == null ? 1 : exerciseItems.size() + 1;
- }
- public boolean isItemAtPositionExercise(int position) {
- return exerciseItems != null && position>0; //TODO: ako krece od 0, tj. ako je title na poziciji 0
- }
- public ExerciseItemDataModel getExercise(int position){
- return exerciseItems.get(position-1);//TODO: Proveriti da li je to ta pozicija
- }
- public List<ExerciseItemDataModel> getExerciseItems() {
- return exerciseItems;
- }
- public void setExerciseItems(List<ExerciseItemDataModel> exerciseItems) {
- this.exerciseItems = exerciseItems;
- }
- public String getDescription() {
- return description;
- }
- public void setDescription(String description) {
- this.description = description;
- }
- public String getTitle() {
- return title;
- }
- public void setTitle(String title) {
- this.title = title;
- }
- public String getCal() {
- return cal;
- }
- public void setCal(String cal) {
- this.cal = cal;
- }
- public String getTime() {
- return time;
- }
- public void setTime(String time) {
- this.time = time;
- }
- public static class ExerciseItemDataModel{
- String imageUrl;
- String exerciseName;
- int duration;
- public static ExerciseItemDataModel newInstance(String imageUrl, String exerciseName, int duration){
- ExerciseItemDataModel dataModel = new ExerciseItemDataModel();
- dataModel.setImageUrl(imageUrl);
- dataModel.setExerciseName(exerciseName);
- dataModel.setDuration(duration);
- return dataModel;
- }
- private ExerciseItemDataModel(){ }
- public String getImageUrl() {
- return imageUrl;
- }
- public void setImageUrl(String imageUrl) {
- this.imageUrl = imageUrl;
- }
- public String getExerciseName() {
- return exerciseName;
- }
- public void setExerciseName(String exerciseName) {
- this.exerciseName = exerciseName;
- }
- public int getDuration() {
- return duration;
- }
- public void setDuration(int duration) {
- this.duration = duration;
- }
- }
- }
- //////////////////////////
- package com.ftn.timkodzo.niktest;
- import android.app.Fragment;
- import android.os.Bundle;
- import android.support.v7.widget.GridLayoutManager;
- import android.support.v7.widget.LinearLayoutManager;
- import android.support.v7.widget.RecyclerView;
- import android.view.LayoutInflater;
- import android.view.View;
- import android.view.ViewGroup;
- import butterknife.BindView;
- import butterknife.ButterKnife;
- import butterknife.Unbinder;
- public class WorkoutDetailsFragment extends Fragment {
- Unbinder unbinder;
- @BindView(R.id.recyclerView)
- RecyclerView workoutDetailsList;
- @Override
- public View onCreateView(LayoutInflater inflater, ViewGroup container,
- Bundle savedInstanceState) {
- View view = inflater.inflate(R.layout.fragment_workout_details, container, false);
- unbinder = ButterKnife.bind(this, view);
- initRecyclerView();
- renderRecyclerView();
- return view;
- }
- private void initRecyclerView(){
- GridLayoutManager manager = new GridLayoutManager(getActivity(), 2);
- manager.setOrientation(LinearLayoutManager.VERTICAL);
- manager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
- @Override
- public int getSpanSize(int position) {
- WorkoutDetailsAdapter adapter = (WorkoutDetailsAdapter) workoutDetailsList.getAdapter();
- if (adapter == null) return 2;
- return 2;
- }
- });
- workoutDetailsList.setLayoutManager(manager);
- }
- private void renderRecyclerView() {
- WorkoutDetailsDataModel dataModel = WorkoutDetailsDataModel.newInstance();
- WorkoutDetailsAdapter adapter = new WorkoutDetailsAdapter(dataModel);
- workoutDetailsList.setAdapter(adapter);
- }
- @Override
- public void onDetach() {
- super.onDetach();
- unbinder.unbind();
- }
- }
- ///////////////////////////////////
- <?xml version="1.0" encoding="utf-8"?>
- <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:tools="http://schemas.android.com/tools"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:paddingBottom="@dimen/activity_vertical_margin"
- android:paddingLeft="@dimen/activity_horizontal_margin"
- android:paddingRight="@dimen/activity_horizontal_margin"
- android:paddingTop="@dimen/activity_vertical_margin"
- tools:context="com.ftn.timkodzo.niktest.MainActivity">
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="Hello World!" />
- </RelativeLayout>
- ///////////////////
- <?xml version="1.0" encoding="utf-8"?>
- <RelativeLayout
- xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="match_parent">
- <FrameLayout
- android:id="@+id/fragment_container"
- android:layout_width="match_parent"
- android:layout_height="match_parent">
- </FrameLayout>
- </RelativeLayout>
- /////////////////////////
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout
- xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="match_parent">
- <android.support.v7.widget.RecyclerView
- android:id="@+id/recyclerView"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:scrollbars="vertical"/>
- </LinearLayout>
- //////////////////////////////
- <?xml version="1.0" encoding="utf-8"?>
- <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="horizontal"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_centerVertical="true"
- android:background="@drawable/input_data"
- android:paddingTop="@dimen/row_padding"
- android:paddingBottom="@dimen/row_padding"
- android:id="@+id/exercise">
- <ImageView
- android:id="@+id/image"
- android:layout_width="@dimen/image_row_dim"
- android:layout_height="@dimen/image_row_dim"
- android:layout_marginStart="@dimen/image_left_margin"/>
- <TextView
- android:id="@+id/exercise_name"
- style="@style/Text.Heading3.MediumGrey.Settings"
- android:layout_width="wrap_content"
- android:maxLines="1"
- android:ellipsize="end"
- android:layout_marginStart="@dimen/name_left_margin"
- android:layout_centerVertical="true"
- android:layout_toEndOf="@+id/image"
- android:layout_toStartOf="@+id/duration"/>
- <TextView
- android:id="@+id/duration"
- style="@style/Text.Heading1"
- android:textColor="@color/blue"
- android:layout_toStartOf="@+id/unit"
- android:layout_centerVertical="true"/>
- <TextView
- android:id="@+id/unit"
- style="@style/Text.Heading3"
- android:text="@string/sec"
- android:textColor="@color/lightGrey"
- android:layout_marginEnd="@dimen/sec_margin_right"
- android:layout_centerVertical="true"
- android:layout_alignParentEnd="true"
- android:layout_marginStart="@dimen/sec_margin_left"/>
- </RelativeLayout>
- /////////////////////////////////
- <?xml version="1.0" encoding="utf-8"?>
- <RelativeLayout
- xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="match_parent">
- <ImageView
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:scaleType="centerCrop"
- android:src="@drawable/background_girl"/>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="vertical" android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_marginLeft="@dimen/activity_vertical_margin"
- android:layout_marginRight="@dimen/activity_vertical_margin"
- android:layout_alignParentBottom="true">
- <LinearLayout
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:orientation="horizontal">
- <ImageView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:src="@drawable/stopwatch_small_icon"/>
- <TextView
- android:id="@+id/time"
- style="@style/Text"
- android:textSize="12dp"
- android:layout_marginLeft="4dp"/>
- <ImageView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:src="@drawable/cal_icon"
- android:layout_marginLeft="15dp"/>
- <TextView
- android:id="@+id/cal"
- style="@style/Text"
- android:textSize="12dp"
- android:layout_marginLeft="4dp"/>
- </LinearLayout>
- <TextView
- android:id="@+id/title"
- style="@style/Text.Heading1.Black"
- android:layout_marginTop="10dp"/>
- <TextView
- android:id="@+id/description"
- style="@style/Text.Heading2"
- android:layout_marginTop="@dimen/title_top"/>
- <Button
- android:id="@+id/btn_download"
- android:layout_width="match_parent"
- style="@style/Text.Button.Blue"
- android:text="Download"
- android:layout_marginTop="@dimen/button_top" />
- <TextView
- android:id="@+id/see_details"
- android:text="See details"
- style="@style/Text"
- android:textSize="12dp"
- android:layout_gravity="center"
- android:layout_marginTop="@dimen/see_details_margin_top"
- android:paddingBottom="7dp"/>
- <ImageView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:src="@drawable/down_icon"
- android:layout_marginBottom="10dp"
- android:layout_gravity="center"/>
- </LinearLayout>
- </RelativeLayout>
- compile 'com.android.support:recyclerview-v7:+'
- compile 'com.jakewharton:butterknife:8.4.0'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement