Advertisement
Guest User

Untitled

a guest
Jan 15th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 20.72 KB | None | 0 0
  1. package com.ftn.timkodzo.niktest;
  2.  
  3. import android.support.v7.app.AppCompatActivity;
  4. import android.os.Bundle;
  5.  
  6. import butterknife.internal.Utils;
  7.  
  8. public class MainActivity extends AppCompatActivity {
  9.  
  10. @Override
  11. protected void onCreate(Bundle savedInstanceState) {
  12. super.onCreate(savedInstanceState);
  13. setContentView(R.layout.activity_main);
  14.  
  15. Utils.replaceFragment(this, new WorkoutDetailsFragment(), "workout_details");
  16. }}
  17.  
  18.  
  19. ////////////////////
  20.  
  21. package com.ftn.timkodzo.niktest;
  22.  
  23. import android.support.v7.widget.RecyclerView;
  24. import android.util.Log;
  25. import android.view.LayoutInflater;
  26. import android.view.View;
  27. import android.view.ViewGroup;
  28. import android.widget.ImageView;
  29. import android.widget.TextView;
  30.  
  31. import java.util.List;
  32.  
  33. import butterknife.BindView;
  34. import butterknife.ButterKnife;
  35. import butterknife.OnClick;
  36.  
  37. public class WorkoutDetailsAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
  38.  
  39. public static final int VIEW_TYPE_TITLE = 0;
  40. public static final int VIEW_TYPE_EXERCISE = 1;
  41.  
  42. private WorkoutDetailsDataModel dataModel;
  43.  
  44. public WorkoutDetailsAdapter(WorkoutDetailsDataModel dataModel){
  45. this.dataModel = dataModel;
  46. }
  47.  
  48. @Override
  49. public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
  50. View view;
  51. LayoutInflater layoutInflater = LayoutInflater.from(parent.getContext());
  52. switch (viewType){
  53. case VIEW_TYPE_TITLE:
  54. view = layoutInflater.inflate(R.layout.row_workout_details_title, parent, false);
  55. return new TitleViewHolder(view);
  56. case VIEW_TYPE_EXERCISE:
  57. view = layoutInflater.inflate(R.layout.row_workout_details, parent, false);
  58. return new ExerciseViewHolder(view);
  59. default:
  60. Log.wtf("recyclerview", "Enter default in onCreateViewHolder");
  61. return null;
  62. }
  63. }
  64.  
  65.  
  66. public static class TitleViewHolder extends RecyclerView.ViewHolder{
  67. @BindView(R.id.time)
  68. TextView time;
  69. @BindView(R.id.cal) TextView cal;
  70. @BindView(R.id.title) TextView title;
  71. @BindView(R.id.description) TextView description;
  72.  
  73. public TitleViewHolder(View itemView){
  74. super(itemView);
  75. ButterKnife.bind(this, itemView);
  76. }
  77.  
  78. @OnClick(R.id.btn_download)
  79. protected void onDownloadClicked(){
  80.  
  81. }
  82.  
  83. @OnClick(R.id.see_details)
  84. protected void onSeeDetailsClicked(){
  85.  
  86. }
  87.  
  88. public void render(WorkoutDetailsDataModel dataModel){
  89. time.setText(dataModel.getTime());
  90. cal.setText(dataModel.getCal());
  91. title.setText(dataModel.getTitle());
  92. description.setText(dataModel.getDescription());
  93. }
  94.  
  95. }
  96.  
  97. public static class ExerciseViewHolder extends RecyclerView.ViewHolder{
  98. @BindView(R.id.image)
  99. ImageView image;
  100. @BindView(R.id.exercise_name) TextView exerciseName;
  101. @BindView(R.id.duration) TextView duration;
  102.  
  103.  
  104. public ExerciseViewHolder(View itemView){
  105. super(itemView);
  106. ButterKnife.bind(this, itemView);
  107. }
  108.  
  109. @OnClick(R.id.exercise)
  110. public void exerciseClicked(){
  111.  
  112. }
  113.  
  114. public void render(WorkoutDetailsDataModel.ExerciseItemDataModel datamodel){
  115. image.setImageResource(R.drawable.avatar_icon);
  116. exerciseName.setText(datamodel.getExerciseName());
  117. duration.setText(datamodel.getDuration()+" ");
  118. }
  119. }
  120.  
  121. @Override
  122. public void onBindViewHolder(RecyclerView.ViewHolder holder, int position, List<Object> payloads) {
  123. switch (getItemViewType(position)){
  124. case VIEW_TYPE_TITLE:
  125. ((TitleViewHolder) holder).render(dataModel);
  126. return;
  127. case VIEW_TYPE_EXERCISE:
  128. ((ExerciseViewHolder) holder).render(dataModel.getExercise(position));
  129. return;
  130. default:
  131. return;
  132. }
  133. }
  134.  
  135. @Override
  136. public int getItemViewType(int position) {
  137. if (dataModel.isItemAtPositionExercise(position))
  138. return VIEW_TYPE_EXERCISE;
  139. return VIEW_TYPE_TITLE;
  140. }
  141.  
  142. @Override
  143. public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
  144.  
  145. }
  146.  
  147. @Override
  148. public int getItemCount() {
  149. return dataModel == null ? 0 : dataModel.getNumberOfElementsToShow();
  150. }
  151. }
  152.  
  153. ///////////////////////////////
  154.  
  155.  
  156. package com.ftn.timkodzo.niktest;
  157.  
  158. import java.util.ArrayList;
  159. import java.util.List;
  160.  
  161. public class WorkoutDetailsDataModel {
  162.  
  163. String time;
  164. String cal;
  165. String title;
  166. String description;
  167. List<ExerciseItemDataModel> exerciseItems;
  168.  
  169. public static WorkoutDetailsDataModel newInstance(){
  170. WorkoutDetailsDataModel dataModel = new WorkoutDetailsDataModel();
  171. /*dataModel.setTime("36");
  172. dataModel.setCal("265-290 cal");
  173. dataModel.setTitle("Body Conditioning \nStrenght + Cardio");
  174. 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");
  175. List<ExerciseItemDataModel> exerciseItems = new ArrayList<>(3);
  176. exerciseItems.add(ExerciseItemDataModel.newInstance("https://media.creativemornings.com/uploads/user/avatar/120448/profile-circle.png", "Run in place", 45));
  177. exerciseItems.add(ExerciseItemDataModel.newInstance("https://media.creativemornings.com/uploads/user/avatar/120448/profile-circle.png", "One lef floore bridges - left", 15));
  178. exerciseItems.add(ExerciseItemDataModel.newInstance("https://media.creativemornings.com/uploads/user/avatar/120448/profile-circle.png", "Run in place", 45));
  179. exerciseItems.add(ExerciseItemDataModel.newInstance("https://media.creativemornings.com/uploads/user/avatar/120448/profile-circle.png", "One lef floore bridges - left", 15));
  180. exerciseItems.add(ExerciseItemDataModel.newInstance("https://media.creativemornings.com/uploads/user/avatar/120448/profile-circle.png", "Run in place", 45));
  181. exerciseItems.add(ExerciseItemDataModel.newInstance("https://media.creativemornings.com/uploads/user/avatar/120448/profile-circle.png", "One lef floore bridges - left", 15));
  182. exerciseItems.add(ExerciseItemDataModel.newInstance("https://media.creativemornings.com/uploads/user/avatar/120448/profile-circle.png", "Run in place", 45));
  183. exerciseItems.add(ExerciseItemDataModel.newInstance("https://media.creativemornings.com/uploads/user/avatar/120448/profile-circle.png", "One lef floore bridges - left", 15));
  184. exerciseItems.add(ExerciseItemDataModel.newInstance("https://media.creativemornings.com/uploads/user/avatar/120448/profile-circle.png", "Run in place", 45));
  185. exerciseItems.add(ExerciseItemDataModel.newInstance("https://media.creativemornings.com/uploads/user/avatar/120448/profile-circle.png", "One lef floore bridges - left", 15));
  186. dataModel.setExerciseItems(exerciseItems);*/
  187. return dataModel;
  188. }
  189.  
  190. private WorkoutDetailsDataModel() { }
  191.  
  192. public int getNumberOfElementsToShow(){
  193. return exerciseItems == null ? 1 : exerciseItems.size() + 1;
  194. }
  195.  
  196. public boolean isItemAtPositionExercise(int position) {
  197. return exerciseItems != null && position>0; //TODO: ako krece od 0, tj. ako je title na poziciji 0
  198. }
  199.  
  200. public ExerciseItemDataModel getExercise(int position){
  201. return exerciseItems.get(position-1);//TODO: Proveriti da li je to ta pozicija
  202. }
  203.  
  204. public List<ExerciseItemDataModel> getExerciseItems() {
  205. return exerciseItems;
  206. }
  207.  
  208. public void setExerciseItems(List<ExerciseItemDataModel> exerciseItems) {
  209. this.exerciseItems = exerciseItems;
  210. }
  211.  
  212. public String getDescription() {
  213. return description;
  214. }
  215.  
  216. public void setDescription(String description) {
  217. this.description = description;
  218. }
  219.  
  220. public String getTitle() {
  221. return title;
  222. }
  223.  
  224. public void setTitle(String title) {
  225. this.title = title;
  226. }
  227.  
  228. public String getCal() {
  229. return cal;
  230. }
  231.  
  232. public void setCal(String cal) {
  233. this.cal = cal;
  234. }
  235. public String getTime() {
  236. return time;
  237. }
  238.  
  239. public void setTime(String time) {
  240. this.time = time;
  241. }
  242.  
  243. public static class ExerciseItemDataModel{
  244. String imageUrl;
  245. String exerciseName;
  246. int duration;
  247.  
  248. public static ExerciseItemDataModel newInstance(String imageUrl, String exerciseName, int duration){
  249. ExerciseItemDataModel dataModel = new ExerciseItemDataModel();
  250. dataModel.setImageUrl(imageUrl);
  251. dataModel.setExerciseName(exerciseName);
  252. dataModel.setDuration(duration);
  253. return dataModel;
  254. }
  255.  
  256. private ExerciseItemDataModel(){ }
  257.  
  258. public String getImageUrl() {
  259. return imageUrl;
  260. }
  261.  
  262. public void setImageUrl(String imageUrl) {
  263. this.imageUrl = imageUrl;
  264. }
  265.  
  266. public String getExerciseName() {
  267. return exerciseName;
  268. }
  269.  
  270. public void setExerciseName(String exerciseName) {
  271. this.exerciseName = exerciseName;
  272. }
  273.  
  274. public int getDuration() {
  275. return duration;
  276. }
  277.  
  278. public void setDuration(int duration) {
  279. this.duration = duration;
  280. }
  281. }
  282. }
  283.  
  284. //////////////////////////
  285.  
  286. package com.ftn.timkodzo.niktest;
  287.  
  288. import android.app.Fragment;
  289. import android.os.Bundle;
  290. import android.support.v7.widget.GridLayoutManager;
  291. import android.support.v7.widget.LinearLayoutManager;
  292. import android.support.v7.widget.RecyclerView;
  293. import android.view.LayoutInflater;
  294. import android.view.View;
  295. import android.view.ViewGroup;
  296.  
  297. import butterknife.BindView;
  298. import butterknife.ButterKnife;
  299. import butterknife.Unbinder;
  300.  
  301. public class WorkoutDetailsFragment extends Fragment {
  302.  
  303. Unbinder unbinder;
  304.  
  305. @BindView(R.id.recyclerView)
  306. RecyclerView workoutDetailsList;
  307.  
  308. @Override
  309. public View onCreateView(LayoutInflater inflater, ViewGroup container,
  310. Bundle savedInstanceState) {
  311. View view = inflater.inflate(R.layout.fragment_workout_details, container, false);
  312. unbinder = ButterKnife.bind(this, view);
  313. initRecyclerView();
  314. renderRecyclerView();
  315. return view;
  316. }
  317.  
  318. private void initRecyclerView(){
  319. GridLayoutManager manager = new GridLayoutManager(getActivity(), 2);
  320. manager.setOrientation(LinearLayoutManager.VERTICAL);
  321. manager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
  322. @Override
  323. public int getSpanSize(int position) {
  324. WorkoutDetailsAdapter adapter = (WorkoutDetailsAdapter) workoutDetailsList.getAdapter();
  325. if (adapter == null) return 2;
  326.  
  327. return 2;
  328. }
  329. });
  330.  
  331. workoutDetailsList.setLayoutManager(manager);
  332. }
  333. private void renderRecyclerView() {
  334. WorkoutDetailsDataModel dataModel = WorkoutDetailsDataModel.newInstance();
  335. WorkoutDetailsAdapter adapter = new WorkoutDetailsAdapter(dataModel);
  336. workoutDetailsList.setAdapter(adapter);
  337. }
  338. @Override
  339. public void onDetach() {
  340. super.onDetach();
  341. unbinder.unbind();
  342. }
  343. }
  344.  
  345. ///////////////////////////////////
  346.  
  347.  
  348. <?xml version="1.0" encoding="utf-8"?>
  349. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  350. xmlns:tools="http://schemas.android.com/tools"
  351. android:layout_width="match_parent"
  352. android:layout_height="match_parent"
  353. android:paddingBottom="@dimen/activity_vertical_margin"
  354. android:paddingLeft="@dimen/activity_horizontal_margin"
  355. android:paddingRight="@dimen/activity_horizontal_margin"
  356. android:paddingTop="@dimen/activity_vertical_margin"
  357. tools:context="com.ftn.timkodzo.niktest.MainActivity">
  358.  
  359. <TextView
  360. android:layout_width="wrap_content"
  361. android:layout_height="wrap_content"
  362. android:text="Hello World!" />
  363. </RelativeLayout>
  364.  
  365.  
  366. ///////////////////
  367.  
  368. <?xml version="1.0" encoding="utf-8"?>
  369. <RelativeLayout
  370. xmlns:android="http://schemas.android.com/apk/res/android"
  371. android:layout_width="match_parent"
  372. android:layout_height="match_parent">
  373. <FrameLayout
  374. android:id="@+id/fragment_container"
  375. android:layout_width="match_parent"
  376. android:layout_height="match_parent">
  377. </FrameLayout>
  378. </RelativeLayout>
  379.  
  380. /////////////////////////
  381.  
  382. <?xml version="1.0" encoding="utf-8"?>
  383. <LinearLayout
  384. xmlns:android="http://schemas.android.com/apk/res/android"
  385. android:layout_width="match_parent"
  386. android:layout_height="match_parent">
  387.  
  388. <android.support.v7.widget.RecyclerView
  389. android:id="@+id/recyclerView"
  390. android:layout_width="match_parent"
  391. android:layout_height="match_parent"
  392. android:scrollbars="vertical"/>
  393. </LinearLayout>
  394.  
  395. //////////////////////////////
  396.  
  397. <?xml version="1.0" encoding="utf-8"?>
  398. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  399. android:orientation="horizontal"
  400. android:layout_width="match_parent"
  401. android:layout_height="wrap_content"
  402. android:layout_centerVertical="true"
  403. android:background="@drawable/input_data"
  404. android:paddingTop="@dimen/row_padding"
  405. android:paddingBottom="@dimen/row_padding"
  406. android:id="@+id/exercise">
  407.  
  408. <ImageView
  409. android:id="@+id/image"
  410. android:layout_width="@dimen/image_row_dim"
  411. android:layout_height="@dimen/image_row_dim"
  412. android:layout_marginStart="@dimen/image_left_margin"/>
  413.  
  414. <TextView
  415. android:id="@+id/exercise_name"
  416. style="@style/Text.Heading3.MediumGrey.Settings"
  417. android:layout_width="wrap_content"
  418. android:maxLines="1"
  419. android:ellipsize="end"
  420. android:layout_marginStart="@dimen/name_left_margin"
  421. android:layout_centerVertical="true"
  422. android:layout_toEndOf="@+id/image"
  423. android:layout_toStartOf="@+id/duration"/>
  424. <TextView
  425. android:id="@+id/duration"
  426. style="@style/Text.Heading1"
  427. android:textColor="@color/blue"
  428. android:layout_toStartOf="@+id/unit"
  429. android:layout_centerVertical="true"/>
  430.  
  431. <TextView
  432. android:id="@+id/unit"
  433. style="@style/Text.Heading3"
  434. android:text="@string/sec"
  435. android:textColor="@color/lightGrey"
  436. android:layout_marginEnd="@dimen/sec_margin_right"
  437. android:layout_centerVertical="true"
  438. android:layout_alignParentEnd="true"
  439. android:layout_marginStart="@dimen/sec_margin_left"/>
  440. </RelativeLayout>
  441.  
  442. /////////////////////////////////
  443.  
  444. <?xml version="1.0" encoding="utf-8"?>
  445. <RelativeLayout
  446. xmlns:android="http://schemas.android.com/apk/res/android"
  447. android:layout_width="match_parent"
  448. android:layout_height="match_parent">
  449.  
  450. <ImageView
  451. android:layout_width="match_parent"
  452. android:layout_height="match_parent"
  453. android:scaleType="centerCrop"
  454. android:src="@drawable/background_girl"/>
  455.  
  456. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  457. android:orientation="vertical" android:layout_width="match_parent"
  458. android:layout_height="wrap_content"
  459. android:layout_marginLeft="@dimen/activity_vertical_margin"
  460. android:layout_marginRight="@dimen/activity_vertical_margin"
  461. android:layout_alignParentBottom="true">
  462.  
  463. <LinearLayout
  464. android:layout_width="wrap_content"
  465. android:layout_height="wrap_content"
  466. android:orientation="horizontal">
  467.  
  468. <ImageView
  469. android:layout_width="wrap_content"
  470. android:layout_height="wrap_content"
  471. android:src="@drawable/stopwatch_small_icon"/>
  472.  
  473. <TextView
  474. android:id="@+id/time"
  475. style="@style/Text"
  476. android:textSize="12dp"
  477. android:layout_marginLeft="4dp"/>
  478.  
  479. <ImageView
  480. android:layout_width="wrap_content"
  481. android:layout_height="wrap_content"
  482. android:src="@drawable/cal_icon"
  483. android:layout_marginLeft="15dp"/>
  484.  
  485. <TextView
  486. android:id="@+id/cal"
  487. style="@style/Text"
  488. android:textSize="12dp"
  489. android:layout_marginLeft="4dp"/>
  490. </LinearLayout>
  491. <TextView
  492. android:id="@+id/title"
  493. style="@style/Text.Heading1.Black"
  494. android:layout_marginTop="10dp"/>
  495.  
  496. <TextView
  497. android:id="@+id/description"
  498. style="@style/Text.Heading2"
  499. android:layout_marginTop="@dimen/title_top"/>
  500.  
  501. <Button
  502. android:id="@+id/btn_download"
  503. android:layout_width="match_parent"
  504. style="@style/Text.Button.Blue"
  505. android:text="Download"
  506. android:layout_marginTop="@dimen/button_top" />
  507.  
  508. <TextView
  509. android:id="@+id/see_details"
  510. android:text="See details"
  511. style="@style/Text"
  512. android:textSize="12dp"
  513. android:layout_gravity="center"
  514. android:layout_marginTop="@dimen/see_details_margin_top"
  515. android:paddingBottom="7dp"/>
  516.  
  517. <ImageView
  518. android:layout_width="wrap_content"
  519. android:layout_height="wrap_content"
  520. android:src="@drawable/down_icon"
  521. android:layout_marginBottom="10dp"
  522. android:layout_gravity="center"/>
  523. </LinearLayout>
  524. </RelativeLayout>
  525.  
  526. compile 'com.android.support:recyclerview-v7:+'
  527. compile 'com.jakewharton:butterknife:8.4.0'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement