Skip to content

Commit

Permalink
Finished basic layout of discovery page.
Browse files Browse the repository at this point in the history
  • Loading branch information
nessup committed Oct 29, 2013
1 parent 6b64da1 commit ac27cdf
Show file tree
Hide file tree
Showing 14 changed files with 261 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,72 @@
import android.view.View;
import android.view.ViewGroup;

import com.joumaa.workouthome.model.SectionHeaderRow;
import com.joumaa.workouthome.model.VideoRow;
import com.joumaa.workouthome.temporary.DiscoverPage;
import com.joumaa.workouthome.temporary.Section;
import com.joumaa.workouthome.temporary.Video;

import java.util.ArrayList;

/**
* Created by dany on 10/27/13.
*/
public class DiscoverFragment extends Fragment {
private DiscoverPage discoverPage;

private LayoutInflater layoutInflater;
private ViewGroup view;
private ArrayList<ViewGroup> columns;

public static DiscoverFragment newInstance(DiscoverPage discoverPage) {
DiscoverFragment fragment = new DiscoverFragment();
fragment.discoverPage = discoverPage;
return fragment;
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.discover_fragment, container, false);
layoutInflater = inflater;

View view = inflater.inflate(R.layout.discover_fragment, container, false);

findViews(view);
configureUI();

return view;
}

private void findViews(View view) {
this.view = (ViewGroup) view;

columns = new ArrayList<ViewGroup>();
for (int i = 0; i < this.view.getChildCount(); i++) {
columns.add((ViewGroup) this.view.getChildAt(i));
}
}

private void configureUI() {
int i = 0;
ViewGroup parentContainer = null;
for (Section section : discoverPage.sections) {
parentContainer = columns.get(i % columns.size());

View headerView = layoutInflater.inflate(R.layout.list_view_header, parentContainer, false);
SectionHeaderRow headerRow = SectionHeaderRow.newInstance(headerView);
headerRow.configureViewWithSection(section);
parentContainer.addView(headerView);

for (Video video : section.videos) {
View videoView = layoutInflater.inflate(R.layout.video_row, parentContainer, false);
VideoRow videoRow = VideoRow.newInstance(videoView);
videoRow.titleFontSize = getResources().getDimension(R.dimen.small_title);
videoRow.subtitleFontSize = getResources().getDimension(R.dimen.small_subtitle);
videoRow.configureWithVideo(video);
parentContainer.addView(videoView);
}

i++;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import android.widget.ImageView;
import android.widget.TextView;

import com.joumaa.workouthome.temporary.DiscoverPage;

public class MainActivity extends FragmentActivity {

public static final int MAIN_FRAGMENT = 0;
Expand Down Expand Up @@ -38,7 +40,11 @@ protected void onCreate(Bundle savedInstanceState) {
}

private void setupFragments() {
Fragment[] newFragments = {new MainFragment(), new DiscoverFragment(), new FavoritesFragment()};
Fragment[] newFragments = {
new MainFragment(),
DiscoverFragment.newInstance(DiscoverPage.buildTestDiscoverPage()),
new FavoritesFragment()
};
fragments = newFragments;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,30 @@
import android.widget.BaseAdapter;
import android.widget.ListView;

import com.joumaa.workouthome.model.SectionHeaderRow;
import com.joumaa.workouthome.model.VideoRow;
import com.joumaa.workouthome.temporary.FeaturedPage;
import com.joumaa.workouthome.temporary.Video;

/**
* Created by dany on 10/27/13.
*/
public class MainFragment extends Fragment {
private FeaturedPage featuredPage;

private ListView listView;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
featuredPage = FeaturedPage.buildTestFeaturedPage();

View view = inflater.inflate(R.layout.main_fragment, container, false);

listView = (ListView) view.findViewById(R.id.listView);

View headerView = inflater.inflate(R.layout.list_view_header, listView, false);
SectionHeaderRow headerRow = SectionHeaderRow.newInstance(headerView);
headerRow.configureViewWithSection(featuredPage.mainSection);
listView.addHeaderView(headerView, null, false);

VideoListAdapter videoListAdapter = new VideoListAdapter(inflater);
Expand All @@ -49,12 +57,12 @@ private VideoListAdapter(LayoutInflater inflater) {

@Override
public int getCount() {
return 5;
return featuredPage.mainSection.videos.size();
}

@Override
public Video getItem(int i) {
return Video.buildTestVideo();
return featuredPage.mainSection.videos.get(i);
}

@Override
Expand All @@ -68,6 +76,7 @@ public View getView(final int i, View view, ViewGroup parentViewGroup) {
if (view == null) {
view = inflater.inflate(R.layout.video_row, parentViewGroup, false);
videoRow = VideoRow.newInstance(view);
videoRow.playButtonVisible = true;
view.setTag(videoRow);

view.setOnClickListener(new View.OnClickListener() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.joumaa.workouthome.model;

import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.joumaa.workouthome.R;
import com.joumaa.workouthome.temporary.Section;

/**
* Created by dany on 10/28/13.
*/
public class SectionHeaderRow {
public TextView titleView;
public TextView seeMoreText;
public ImageView seeMoreImage;

public static SectionHeaderRow newInstance(View view) {
SectionHeaderRow sectionHeaderRow = new SectionHeaderRow();
sectionHeaderRow.findViews(view);
return sectionHeaderRow;
}

private void findViews(View view) {
titleView = (TextView) view.findViewById(R.id.headerTitle);
seeMoreText = (TextView) view.findViewById(R.id.seeAllText);
seeMoreImage = (ImageView) view.findViewById(R.id.seeAllIcon);
}

public void configureViewWithSection(Section section) {
titleView.setText(section.title);

int seeMoreVisibility = section.hasMore ? View.VISIBLE : View.GONE;
seeMoreText.setVisibility(seeMoreVisibility);
seeMoreImage.setVisibility(seeMoreVisibility);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ public class VideoRow {
public static final int WORKOUT_DIFFICULTY_MEDIUM = 2;
public static final int WORKOUT_DIFFICULTY_HARD = 3;

public boolean playButtonVisible;
public float titleFontSize;
public float subtitleFontSize;

public TextView titleView;
public ImageButton playButton;
public ImageView durationIcon;
Expand Down Expand Up @@ -45,6 +49,9 @@ private void findViews(View parentView) {
public void configureWithVideo(Video video) {
// Title
titleView.setText(video.getTitle());
if (titleFontSize > 0) {
titleView.setTextSize(titleFontSize);
}

// Play button
playButton.setOnClickListener(new View.OnClickListener() {
Expand All @@ -53,8 +60,9 @@ public void onClick(View view) {
// todo: play a video
}
});
playButton.setVisibility(playButtonVisible ? View.VISIBLE : View.GONE);

// Video duration icon
// Video duration
int durationResourceId;
if (video.getDuration() > 60 * 15) {
durationResourceId = R.drawable.clock_red;
Expand Down Expand Up @@ -88,5 +96,12 @@ else if(video.getDifficulty() == WORKOUT_DIFFICULTY_MEDIUM) {
// Number of favorites
// todo: make heart red if this user liked it
favoritesInfo.setText(video.getFavorites());

// Subtitle font sizes
if (subtitleFontSize > 0) {
durationInfo.setTextSize(subtitleFontSize);
difficultyInfo.setTextSize(subtitleFontSize);
favoritesInfo.setTextSize(subtitleFontSize);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.joumaa.workouthome.temporary;

import java.util.ArrayList;

/**
* Created by dany on 10/28/13.
*/
public class DiscoverPage {
public ArrayList<Section> sections;

public static DiscoverPage buildTestDiscoverPage() {
DiscoverPage discoverPage = new DiscoverPage();

discoverPage.sections = new ArrayList<Section>();
discoverPage.sections.add(Section.buildTestSection());
discoverPage.sections.add(Section.buildTestSection());

return discoverPage;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.joumaa.workouthome.temporary;

/**
* Created by dany on 10/28/13.
*/
public class FeaturedPage {
public Section mainSection;

public static FeaturedPage buildTestFeaturedPage() {
FeaturedPage page = new FeaturedPage();
page.mainSection = Section.buildTestSection();
return page;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.joumaa.workouthome.temporary;

import java.util.ArrayList;

/**
* Created by dany on 10/28/13.
*/
public class Section {
public String title;
public ArrayList<Video> videos;
public boolean hasMore;

public static Section buildTestSection() {
Section section = new Section();
section.title = "Most awesome workouts";

section.videos = new ArrayList<Video>();
section.videos.add(Video.buildTestVideo());
section.videos.add(Video.buildTestVideo());
section.videos.add(Video.buildTestVideo());

section.hasMore = true;

return section;
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 30 additions & 4 deletions Workoutathome/src/main/res/layout/discover_fragment.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,33 @@
<?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">
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/columnsContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:gravity="center_horizontal"
android:background="@color/fragment_background"
>

</RelativeLayout>
<LinearLayout
android:id="@+id/column1"
android:layout_height="wrap_content"
android:layout_width="320dp"
android:orientation="vertical"
>

</LinearLayout>

<LinearLayout
android:id="@+id/column2"
android:layout_height="wrap_content"
android:layout_width="320dp"
android:layout_marginLeft="20dp"
android:orientation="vertical"
android:layout_toRightOf="@id/column1"
>

</LinearLayout>

</LinearLayout>
38 changes: 33 additions & 5 deletions Workoutathome/src/main/res/layout/list_view_header.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>

<FrameLayout
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
Expand All @@ -9,12 +9,40 @@
>

<TextView
android:id="@+id/headerTitle"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:textColor="#808080"
android:layout_gravity="center_vertical"
android:text="Featured Workouts"
android:textColor="@color/list_view_header"
android:text="Featured Workouts blah blah"
android:textSize="24sp"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="@+id/seeAllIcon"
android:lines="1"
android:ellipsize="end"
/>

</FrameLayout>
<TextView
android:id="@+id/seeAllText"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="See all"
android:textColor="@color/list_view_header"
android:layout_alignParentRight="true"
android:textSize="16sp"
android:layout_alignBaseline="@id/headerTitle"
android:visibility="gone"
/>

<ImageView
android:id="@id/seeAllIcon"
android:layout_height="22dp"
android:layout_width="22dp"
android:layout_toLeftOf="@id/seeAllText"
android:layout_marginRight="10dp"
android:src="@drawable/arrow_right"
android:layout_centerVertical="true"
android:visibility="gone"
/>

</RelativeLayout>
Loading

0 comments on commit ac27cdf

Please sign in to comment.