From ac27cdf57cac82a8037b3dd74fe5d9ab6f8cbdec Mon Sep 17 00:00:00 2001 From: nessup Date: Mon, 28 Oct 2013 23:34:01 -0700 Subject: [PATCH] Finished basic layout of discovery page. --- .../joumaa/workouthome/DiscoverFragment.java | 62 +++++++++++++++++- .../com/joumaa/workouthome/MainActivity.java | 8 ++- .../com/joumaa/workouthome/MainFragment.java | 13 +++- .../workouthome/model/SectionHeaderRow.java | 37 +++++++++++ .../joumaa/workouthome/model/VideoRow.java | 17 ++++- .../workouthome/temporary/DiscoverPage.java | 20 ++++++ .../workouthome/temporary/FeaturedPage.java | 14 ++++ .../joumaa/workouthome/temporary/Section.java | 26 ++++++++ .../main/res/drawable-xhdpi/arrow_right.png | Bin 0 -> 788 bytes .../src/main/res/layout/discover_fragment.xml | 34 ++++++++-- .../src/main/res/layout/list_view_header.xml | 38 +++++++++-- .../src/main/res/layout/video_row.xml | 3 +- Workoutathome/src/main/res/values/colors.xml | 1 + Workoutathome/src/main/res/values/dimens.xml | 4 +- 14 files changed, 261 insertions(+), 16 deletions(-) create mode 100644 Workoutathome/src/main/java/com/joumaa/workouthome/model/SectionHeaderRow.java create mode 100644 Workoutathome/src/main/java/com/joumaa/workouthome/temporary/DiscoverPage.java create mode 100644 Workoutathome/src/main/java/com/joumaa/workouthome/temporary/FeaturedPage.java create mode 100644 Workoutathome/src/main/java/com/joumaa/workouthome/temporary/Section.java create mode 100644 Workoutathome/src/main/res/drawable-xhdpi/arrow_right.png diff --git a/Workoutathome/src/main/java/com/joumaa/workouthome/DiscoverFragment.java b/Workoutathome/src/main/java/com/joumaa/workouthome/DiscoverFragment.java index 981bd31..550950a 100644 --- a/Workoutathome/src/main/java/com/joumaa/workouthome/DiscoverFragment.java +++ b/Workoutathome/src/main/java/com/joumaa/workouthome/DiscoverFragment.java @@ -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 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(); + 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++; + } } } \ No newline at end of file diff --git a/Workoutathome/src/main/java/com/joumaa/workouthome/MainActivity.java b/Workoutathome/src/main/java/com/joumaa/workouthome/MainActivity.java index 775b45a..8befc8c 100644 --- a/Workoutathome/src/main/java/com/joumaa/workouthome/MainActivity.java +++ b/Workoutathome/src/main/java/com/joumaa/workouthome/MainActivity.java @@ -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; @@ -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; } diff --git a/Workoutathome/src/main/java/com/joumaa/workouthome/MainFragment.java b/Workoutathome/src/main/java/com/joumaa/workouthome/MainFragment.java index a058fd2..b574c62 100644 --- a/Workoutathome/src/main/java/com/joumaa/workouthome/MainFragment.java +++ b/Workoutathome/src/main/java/com/joumaa/workouthome/MainFragment.java @@ -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); @@ -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 @@ -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() { diff --git a/Workoutathome/src/main/java/com/joumaa/workouthome/model/SectionHeaderRow.java b/Workoutathome/src/main/java/com/joumaa/workouthome/model/SectionHeaderRow.java new file mode 100644 index 0000000..ae2f018 --- /dev/null +++ b/Workoutathome/src/main/java/com/joumaa/workouthome/model/SectionHeaderRow.java @@ -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); + } +} diff --git a/Workoutathome/src/main/java/com/joumaa/workouthome/model/VideoRow.java b/Workoutathome/src/main/java/com/joumaa/workouthome/model/VideoRow.java index ee6a142..dda7ea4 100644 --- a/Workoutathome/src/main/java/com/joumaa/workouthome/model/VideoRow.java +++ b/Workoutathome/src/main/java/com/joumaa/workouthome/model/VideoRow.java @@ -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; @@ -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() { @@ -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; @@ -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); + } } } diff --git a/Workoutathome/src/main/java/com/joumaa/workouthome/temporary/DiscoverPage.java b/Workoutathome/src/main/java/com/joumaa/workouthome/temporary/DiscoverPage.java new file mode 100644 index 0000000..abc564f --- /dev/null +++ b/Workoutathome/src/main/java/com/joumaa/workouthome/temporary/DiscoverPage.java @@ -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
sections; + + public static DiscoverPage buildTestDiscoverPage() { + DiscoverPage discoverPage = new DiscoverPage(); + + discoverPage.sections = new ArrayList
(); + discoverPage.sections.add(Section.buildTestSection()); + discoverPage.sections.add(Section.buildTestSection()); + + return discoverPage; + } +} diff --git a/Workoutathome/src/main/java/com/joumaa/workouthome/temporary/FeaturedPage.java b/Workoutathome/src/main/java/com/joumaa/workouthome/temporary/FeaturedPage.java new file mode 100644 index 0000000..e84f4af --- /dev/null +++ b/Workoutathome/src/main/java/com/joumaa/workouthome/temporary/FeaturedPage.java @@ -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; + } +} diff --git a/Workoutathome/src/main/java/com/joumaa/workouthome/temporary/Section.java b/Workoutathome/src/main/java/com/joumaa/workouthome/temporary/Section.java new file mode 100644 index 0000000..1388a44 --- /dev/null +++ b/Workoutathome/src/main/java/com/joumaa/workouthome/temporary/Section.java @@ -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