Skip to content

Commit

Permalink
Merge pull request #95 from WatchFriends/devHome-Hein-v3.0
Browse files Browse the repository at this point in the history
Home pagina werkt eidelijk
  • Loading branch information
JasperDeSutter authored Nov 6, 2016
2 parents 1517217 + b825eed commit 8bb4760
Show file tree
Hide file tree
Showing 9 changed files with 173 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,77 @@

import android.content.Context;
import android.databinding.DataBindingUtil;
import android.databinding.ObservableArrayList;
import android.media.Image;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.ImageView;
import android.widget.TextView;

import com.squareup.picasso.Picasso;

import nmct.jaspernielsmichielhein.watchfriends.R;
import nmct.jaspernielsmichielhein.watchfriends.databinding.PosterSeriesBinding;
import nmct.jaspernielsmichielhein.watchfriends.helper.Interfaces;
import nmct.jaspernielsmichielhein.watchfriends.model.Series;

public class SeriesAdapter extends ArrayAdapter<Series> {
public class SeriesAdapter extends RecyclerView.Adapter<SeriesAdapter.SeriesViewHolder> {
public Interfaces.onSeriesSelectedListener mListener;

public SeriesAdapter(Context context, ListView listView) {
super(context, R.layout.poster_series);
private Context context;
private ObservableArrayList<Series> series = null;

public SeriesAdapter(ObservableArrayList<Series> series, Context context) {
this.context = context;
this.series = series;
mListener = (Interfaces.onSeriesSelectedListener) context;
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Series selectedSeries = getItem(position);
if (selectedSeries != null) {
mListener.onSeriesSelected(selectedSeries);
}
}
});
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
final PosterSeriesBinding posterSeriesBinding = DataBindingUtil.inflate(LayoutInflater.from(parent.getContext()), R.layout.poster_series, parent, false);
posterSeriesBinding.setSeries(getItem(position));
return posterSeriesBinding.getRoot();
public SeriesViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
PosterSeriesBinding posterSeriesBinding = DataBindingUtil.inflate(LayoutInflater.from(context), R.layout.poster_series, parent, false);
SeriesAdapter.SeriesViewHolder seriesViewHolder = new SeriesAdapter.SeriesViewHolder(posterSeriesBinding);
return seriesViewHolder;
}

@Override
public void onBindViewHolder(SeriesViewHolder holder, int position) {
Series seriesObject = series.get(position);
holder.getPosterSeriesBinding().setSeries(seriesObject);
holder.getPosterSeriesBinding().executePendingBindings();

Picasso.with(context).load(seriesObject.getFullPoster_path()).into(holder.imgSeriesPoster);
//holder.teName.setText(seriesObject.getName());
}

@Override
public int getItemCount() {
return series.size();
}

public class SeriesViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
final PosterSeriesBinding posterSeriesBinding;

public final ImageView imgSeriesPoster;

public SeriesViewHolder(PosterSeriesBinding posterSeriesBinding) {
super(posterSeriesBinding.getRoot());
this.posterSeriesBinding = posterSeriesBinding;
posterSeriesBinding.getRoot().setOnClickListener(this);

imgSeriesPoster = (ImageView) posterSeriesBinding.getRoot().findViewById(R.id.imgSeriesPoster);
}

public PosterSeriesBinding getPosterSeriesBinding() {
return posterSeriesBinding;
}

@Override
public void onClick(View v) {
Series selectedSeries = series.get(getAdapterPosition());
}
}
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,33 @@
package nmct.jaspernielsmichielhein.watchfriends.binder;

import android.databinding.BindingAdapter;
import android.databinding.ObservableArrayList;
import android.databinding.ObservableList;
import android.support.v7.widget.RecyclerView;
import android.widget.ListView;

import nmct.jaspernielsmichielhein.watchfriends.adapter.SeriesAdapter;
import nmct.jaspernielsmichielhein.watchfriends.helper.Utils;
import nmct.jaspernielsmichielhein.watchfriends.model.Series;

public class SeriesBinder {
@BindingAdapter("items")
/*@BindingAdapter("items")
public static void setSeries(ListView listView, ObservableList<Series> series) {
if(series != null) {
SeriesAdapter seriesAdapter = new SeriesAdapter(listView.getContext(), listView);
seriesAdapter.addAll(series);
listView.setAdapter(seriesAdapter);
//Utils.setListViewHeightBasedOnChildren(listView);
}
}*/

@BindingAdapter("items")
public static void setSeries(RecyclerView recyclerView, ObservableArrayList<Series> series) {
if(series != null) {
SeriesAdapter seriesAdapter = new SeriesAdapter(series, recyclerView.getContext());
recyclerView.setAdapter(seriesAdapter);
seriesAdapter.notifyDataSetChanged();
//Utils.setListViewHeightBasedOnChildren(listView);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
package nmct.jaspernielsmichielhein.watchfriends.model;

import android.app.Activity;
import android.content.Context;
import android.databinding.ObservableArrayList;
import android.os.Parcel;
import android.os.Parcelable;
import android.widget.ImageView;

import com.squareup.picasso.Picasso;

import nmct.jaspernielsmichielhein.watchfriends.R;

public class Series implements Parcelable {
private String backdrop_path = "";
Expand Down Expand Up @@ -188,6 +195,15 @@ public String getPoster_path() {
return poster_path;
}

public String getFullPoster_path() {

if (poster_path != null && poster_path != "") {
return "https://image.tmdb.org/t/p/w300_and_h450_bestv2" + poster_path;
}

return "https://www.themoviedb.org/assets/e2dd052f141e33392eb749aab2414ec0/images/no-poster-w300_and_h450_bestv2-v2.png";
}

public void setPoster_path(String poster_path) {
this.poster_path = poster_path;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import android.app.Fragment;
import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
Expand All @@ -25,7 +28,12 @@ public static HomeFragment newInstance() {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
FragmentHomeBinding fragmentHomeBinding = DataBindingUtil.inflate(inflater, R.layout.fragment_home, container, false);
fragmentHomeBinding.rvRecommended.setLayoutManager(new LinearLayoutManager(this.getActivity(), LinearLayoutManager.HORIZONTAL, false));
fragmentHomeBinding.rvRecommended.setItemAnimator(new DefaultItemAnimator());
homeFragmentViewModel = new HomeFragmentViewModel(getActivity(), fragmentHomeBinding);

//RecyclerView rvRecommended = (RecyclerView) super.findViewById(R.layout.rvRecommended);

return fragmentHomeBinding.getRoot();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ protected void onCreate(Bundle savedInstanceState) {
toolbarLayout = (CollapsingToolbarLayout) findViewById(R.id.toolbar_layout);
appBarLayout = (AppBarLayout) findViewById(R.id.app_bar);

collapseToolbar();
//collapseToolbar();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
package nmct.jaspernielsmichielhein.watchfriends.viewmodel;

import android.app.Activity;
import android.content.Context;
import android.databinding.BaseObservable;
import android.databinding.Bindable;
import android.databinding.ObservableArrayList;
import android.widget.ImageView;

import com.android.databinding.library.baseAdapters.BR;
import com.squareup.picasso.Picasso;

import nmct.jaspernielsmichielhein.watchfriends.R;
import nmct.jaspernielsmichielhein.watchfriends.databinding.FragmentHomeBinding;
import nmct.jaspernielsmichielhein.watchfriends.databinding.FragmentSeasonBinding;
import nmct.jaspernielsmichielhein.watchfriends.helper.ApiHelper;
Expand All @@ -23,6 +27,9 @@ public class HomeFragmentViewModel extends BaseObservable {
@Bindable
private ObservableArrayList<Series> recommendedByFriends = null;

@Bindable
private ObservableArrayList<Series> popular = null;

public ObservableArrayList<Series> getRecommendedByFriends() {
return recommendedByFriends;
}
Expand All @@ -31,6 +38,14 @@ public void setRecommendedByFriends(ObservableArrayList<Series> recommendedByFri
this.recommendedByFriends = recommendedByFriends;
}

public ObservableArrayList<Series> getPopular() {
return popular;
}

public void setPopular(ObservableArrayList<Series> popular) {
this.popular = popular;
}

public HomeFragmentViewModel(Context context, FragmentHomeBinding fragmentHomeBinding) {
this.context = context;
this.fragmentHomeBinding = fragmentHomeBinding;
Expand All @@ -40,15 +55,24 @@ public void generateFakeData() {
final HomeFragmentViewModel that = this;
fragmentHomeBinding.setViewmodel(that);

int[] ids = {16148, 64095, 248936, 1399, 25778, 14506, 33088, 13687};
int[] ids1 = {16148, 64095, 248936, 1399, 25778, 14506, 33088, 13687};
int[] ids2 = {1399, 1396, 4614, 12908, 45, 456, 2190, 16148};

setRecommendedByFriends(new ObservableArrayList<Series>());
setPopular(new ObservableArrayList<Series>());

fillLists(ids1, recommendedByFriends, "r");
fillLists(ids2, popular, "p");
}

private void fillLists(int[] ids, final ObservableArrayList<Series> seriesToLoad, String karakter) {

for(int id : ids) {
loadSeries(id);
loadSeries(id, seriesToLoad, karakter);
}
}

private void loadSeries(int id) {
private void loadSeries(int id, final ObservableArrayList<Series> seriesToLoad, final String karakter) {
ApiHelper.getMoviedbServiceInstance().getSeries(id).subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.onErrorReturn(new Func1<Throwable, Series>() {
Expand All @@ -61,7 +85,8 @@ public Series call(Throwable throwable) {
@Override
public void call(Series returnedSeries) {
if (returnedSeries != null) {
recommendedByFriends.add(returnedSeries);
seriesToLoad.add(returnedSeries);

notifyPropertyChanged(BR.viewmodel);
}
}
Expand Down
56 changes: 37 additions & 19 deletions WatchFriends/app/src/main/res/layout/fragment_home.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,18 @@
type="nmct.jaspernielsmichielhein.watchfriends.viewmodel.HomeFragmentViewModel" />
</data>

<android.support.design.widget.CoordinatorLayout
android:id="@+id/clMain"
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
android:layout_height="match_parent">

<android.support.v4.widget.NestedScrollView
android:id="@+id/scrollViewDetailsEpisode"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
android:layout_height="match_parent"
android:orientation="vertical">


<RelativeLayout
android:id="@+id/rlRecommended"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
Expand All @@ -37,21 +36,40 @@
android:text="Recommended by friends"
style="?android:attr/listSeparatorTextViewStyle" />

<ListView
android:id="@+id/lvRecommended"
android:layout_width="wrap_content"
android:layout_height="400dp"
<android.support.v7.widget.RecyclerView
android:id="@+id/rvRecommended"
android:layout_width="match_parent"
android:layout_height="435px"
android:layout_below="@id/txtRecommended"
android:layout_gravity="center_vertical"
android:scrollbars="horizontal"
app:items="@{viewmodel.recommendedByFriends}">

</ListView>
app:items="@{viewmodel.recommendedByFriends}" />

</RelativeLayout>

</android.support.v4.widget.NestedScrollView>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="10dp"
android:layout_below="@id/rlRecommended">

</android.support.design.widget.CoordinatorLayout>
<TextView
android:id="@+id/txtPopular"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_alignParentStart="true"
android:layout_alignParentEnd="true"
android:text="Popular"
style="?android:attr/listSeparatorTextViewStyle" />

<android.support.v7.widget.RecyclerView
android:id="@+id/rvPopular"
android:layout_width="match_parent"
android:layout_height="435px"
android:layout_below="@id/txtPopular"
app:items="@{viewmodel.popular}" />

</RelativeLayout>
</LinearLayout>
</ScrollView>
</layout>
17 changes: 12 additions & 5 deletions WatchFriends/app/src/main/res/layout/poster_series.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,23 @@
</data>

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_width="250px"
android:layout_height="435px"
android:orientation="vertical"
android:paddingStart="5dp"
android:paddingEnd="5dp" >

<ImageView
android:id="@+id/imgSeriesPoster"
android:layout_width="250px"
android:layout_height="375px" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@{series.name}" />
android:id="@+id/teName"
android:layout_width="match_parent"
android:layout_height="60px"
android:text="@{series.name}"
android:textAlignment="center"/>

</LinearLayout>

Expand Down
1 change: 1 addition & 0 deletions WatchFriends/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<string name="air_date_icon_description">airDateIcon</string>
<string name="overview_icon_description">overviewIcon</string>
<string name="air_date">Air date: </string>
<string name="friends_who_watched_this_episode">Friends who watched this episode</string>
<string name="friends_watched_episode">Friends who watched this episode</string>
<string name="rating">Rating</string>
<string name="episodes">Episodes</string>
Expand Down

0 comments on commit 8bb4760

Please sign in to comment.