-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactored video listing into separate fragments and adapters, added …
…favorites page.
- Loading branch information
Showing
10 changed files
with
273 additions
and
97 deletions.
There are no files selected for viewing
24 changes: 21 additions & 3 deletions
24
Workoutathome/src/main/java/com/joumaa/workouthome/FavoritesFragment.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,35 @@ | ||
package com.joumaa.workouthome; | ||
|
||
import android.os.Bundle; | ||
import android.support.v4.app.Fragment; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
|
||
import com.joumaa.workouthome.temporary.FavoritesPage; | ||
|
||
/** | ||
* Created by dany on 10/27/13. | ||
*/ | ||
public class FavoritesFragment extends Fragment { | ||
public class FavoritesFragment extends VideoListFragment { | ||
private FavoritesPage page; | ||
|
||
@Override | ||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { | ||
protected View createView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { | ||
return inflater.inflate(R.layout.favorites_fragment, container, false); | ||
} | ||
|
||
@Override | ||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { | ||
View view = super.onCreateView(inflater, container, savedInstanceState); | ||
|
||
page = FavoritesPage.buildTestFavoritesPage(); | ||
int noFavoritesVisibility = View.VISIBLE; | ||
if (page.section.videos.size() > 0) { | ||
configureWithSection(page.section); | ||
noFavoritesVisibility = View.GONE; | ||
} | ||
|
||
|
||
return view; | ||
} | ||
} |
85 changes: 7 additions & 78 deletions
85
Workoutathome/src/main/java/com/joumaa/workouthome/MainFragment.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,99 +1,28 @@ | ||
package com.joumaa.workouthome; | ||
|
||
import android.os.Bundle; | ||
import android.support.v4.app.Fragment; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
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 { | ||
public class MainFragment extends VideoListFragment { | ||
private FeaturedPage featuredPage; | ||
|
||
private ListView listView; | ||
@Override | ||
protected View createView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { | ||
return inflater.inflate(R.layout.main_fragment, container, false); | ||
} | ||
|
||
@Override | ||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { | ||
View view = super.onCreateView(inflater, container, 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); | ||
listView.setAdapter(videoListAdapter); | ||
|
||
configureWithSection(featuredPage.mainSection); | ||
return view; | ||
} | ||
|
||
private void didSelectRowAtIndexPath(int index, View row) { | ||
getFragmentManager() | ||
.beginTransaction() | ||
.replace(R.id.container, VideoInfoFragment.newInstance(Video.buildTestVideo())) | ||
.addToBackStack(null) | ||
.commit(); | ||
} | ||
|
||
private class VideoListAdapter extends BaseAdapter { | ||
LayoutInflater inflater; | ||
|
||
private VideoListAdapter(LayoutInflater inflater) { | ||
this.inflater = inflater; | ||
} | ||
|
||
@Override | ||
public int getCount() { | ||
return featuredPage.mainSection.videos.size(); | ||
} | ||
|
||
@Override | ||
public Video getItem(int i) { | ||
return featuredPage.mainSection.videos.get(i); | ||
} | ||
|
||
@Override | ||
public long getItemId(int i) { | ||
return 0; | ||
} | ||
|
||
@Override | ||
public View getView(final int i, View view, ViewGroup parentViewGroup) { | ||
VideoRow videoRow; | ||
if (view == null) { | ||
view = inflater.inflate(R.layout.video_row, parentViewGroup, false); | ||
videoRow = VideoRow.newInstance(view); | ||
videoRow.playButtonVisible = true; | ||
videoRow.thumbnailHeight = getResources().getDimensionPixelSize(R.dimen.featured_thumbnail_height); | ||
view.setTag(videoRow); | ||
|
||
view.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View view) { | ||
MainFragment.this.didSelectRowAtIndexPath(i, view); | ||
} | ||
}); | ||
} | ||
else { | ||
videoRow = (VideoRow) view.getTag(); | ||
} | ||
|
||
videoRow.configureWithVideo(getItem(i)); | ||
|
||
return view; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
Workoutathome/src/main/java/com/joumaa/workouthome/VideoListAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package com.joumaa.workouthome; | ||
|
||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
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.Section; | ||
import com.joumaa.workouthome.temporary.Video; | ||
|
||
/** | ||
* Created by dany on 10/29/13. | ||
*/ | ||
class VideoListAdapter extends BaseAdapter { | ||
public interface OnVideoClickListener { | ||
void onVideoClicked(int position, View rowView, Video video); | ||
}; | ||
|
||
private ListView listView; | ||
private LayoutInflater inflater; | ||
private Section section; | ||
private OnVideoClickListener onVideoClickListener; | ||
|
||
public VideoListAdapter(ListView listView, LayoutInflater inflater, Section section) { | ||
this.listView = listView; | ||
this.inflater = inflater; | ||
this.section = section; | ||
|
||
// Section header | ||
if (section.title != null && !section.title.isEmpty()) { | ||
View headerView = inflater.inflate(R.layout.list_view_header, listView, false); | ||
SectionHeaderRow headerRow = SectionHeaderRow.newInstance(headerView); | ||
headerRow.configureViewWithSection(section); | ||
listView.addHeaderView(headerView, null, false); | ||
} | ||
|
||
listView.setAdapter(this); | ||
} | ||
|
||
public void setOnVideoClickListener(OnVideoClickListener onVideoClickListener) { | ||
this.onVideoClickListener = onVideoClickListener; | ||
} | ||
|
||
@Override | ||
public int getCount() { | ||
return section.videos.size(); | ||
} | ||
|
||
@Override | ||
public Video getItem(int i) { | ||
return section.videos.get(i); | ||
} | ||
|
||
@Override | ||
public long getItemId(int i) { | ||
return 0; | ||
} | ||
|
||
@Override | ||
public View getView(final int i, View view, ViewGroup parentViewGroup) { | ||
VideoRow videoRow; | ||
final Video video = getItem(i); | ||
if (view == null) { | ||
view = inflater.inflate(R.layout.video_row, parentViewGroup, false); | ||
videoRow = VideoRow.newInstance(view); | ||
videoRow.playButtonVisible = true; | ||
videoRow.thumbnailHeight = listView.getResources().getDimensionPixelSize(R.dimen.featured_thumbnail_height); | ||
view.setTag(videoRow); | ||
|
||
view.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View view) { | ||
if (onVideoClickListener != null) { | ||
onVideoClickListener.onVideoClicked(i, view, video); | ||
} | ||
} | ||
}); | ||
} | ||
else { | ||
videoRow = (VideoRow) view.getTag(); | ||
} | ||
|
||
videoRow.configureWithVideo(video); | ||
|
||
return view; | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
Workoutathome/src/main/java/com/joumaa/workouthome/VideoListFragment.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package com.joumaa.workouthome; | ||
|
||
import android.os.Bundle; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.widget.ListView; | ||
|
||
import com.joumaa.workouthome.temporary.Section; | ||
import com.joumaa.workouthome.temporary.Video; | ||
|
||
/** | ||
* Created by dany on 10/29/13. | ||
*/ | ||
public abstract class VideoListFragment extends WOAHFragment implements VideoListAdapter.OnVideoClickListener { | ||
private ListView listView; | ||
private LayoutInflater inflater; | ||
|
||
@Override | ||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { | ||
this.inflater = inflater; | ||
return super.onCreateView(inflater, container, savedInstanceState); | ||
} | ||
|
||
@Override | ||
public void findViews(View view) { | ||
super.findViews(view); | ||
listView = (ListView) view.findViewById(R.id.listView); | ||
} | ||
|
||
public void configureWithSection(Section section) { | ||
VideoListAdapter videoListAdapter = new VideoListAdapter(listView, inflater, section); | ||
videoListAdapter.setOnVideoClickListener(this); | ||
listView.setAdapter(videoListAdapter); | ||
} | ||
|
||
// On video click listener | ||
|
||
@Override | ||
public void onVideoClicked(int position, View rowView, Video video) { | ||
getFragmentManager() | ||
.beginTransaction() | ||
.replace(R.id.container, VideoInfoFragment.newInstance(Video.buildTestVideo())) | ||
.addToBackStack(null) | ||
.commit(); | ||
} | ||
|
||
public ListView getListView() { | ||
return listView; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
Workoutathome/src/main/java/com/joumaa/workouthome/temporary/FavoritesPage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.joumaa.workouthome.temporary; | ||
|
||
/** | ||
* Created by dany on 10/29/13. | ||
*/ | ||
public class FavoritesPage { | ||
public Section section; | ||
|
||
public static FavoritesPage buildTestFavoritesPage() { | ||
FavoritesPage favoritesPage = new FavoritesPage(); | ||
favoritesPage.section = Section.buildTestSection(); | ||
return favoritesPage; | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.