Skip to content

Commit

Permalink
Merge pull request #131 from WatchFriends/devNiels
Browse files Browse the repository at this point in the history
Fragments improvements
  • Loading branch information
mickverm authored Dec 5, 2016
2 parents eca75c1 + c3aece6 commit b367c2a
Show file tree
Hide file tree
Showing 13 changed files with 150 additions and 83 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
public class SimilarSeriesBinder {
@BindingAdapter("items")
public static void setSimilarSeries(RecyclerView recyclerView, ObservableArrayList<Series> similarSeries) {
if(similarSeries != null) {
if(similarSeries != null && similarSeries.size() != 0) {
SeriesAdapter seriesAdapter = new SeriesAdapter(recyclerView.getContext(), similarSeries);
recyclerView.setAdapter(seriesAdapter);
seriesAdapter.notifyDataSetChanged();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ public class Episode extends BaseObservable implements Parcelable {
private int vote_count = 0;

public String getAir_date() {
if (air_date == null || air_date.equals("")) {
return "Not available";
}
return air_date;
}

Expand All @@ -40,6 +43,9 @@ public void setEpisode_number(int episode_number) {
}

public String getName() {
if (name.equals("")) {
return getShortcode();
}
return name;
}

Expand All @@ -48,6 +54,9 @@ public void setName(String name) {
}

public String getOverview() {
if (overview.equals("")) {
return "Not available";
}
return overview;
}

Expand Down Expand Up @@ -133,11 +142,11 @@ public void initExtraFields() {
setRating((float) getVote_average() / 2);
}

public void makeImage_uri() {
private void makeImage_uri() {
setImage_uri(Uri.parse(Contract.MOVIEDB_IMAGE_BASE_URL + getStill_path()));
}

public void makeShortcode() {
private void makeShortcode() {
setShortcode(SeriesHelper.getShortcode(this.getSeason_number(), this.getEpisode_number()));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public class Season extends BaseObservable implements Parcelable {
private int episode_count = 0;
private String overview = "";
private String name = "";
private Uri image_uri;
private int id = 0;
private String poster_path = "";
private int season_number = 0;
Expand All @@ -28,6 +29,9 @@ public void set_id(String _id) {
}

public String getAir_date() {
if (air_date == null || air_date.equals("")) {
return "Not available";
}
return air_date;
}

Expand Down Expand Up @@ -59,7 +63,18 @@ public void setId(int id) {
this.id = id;
}

public Uri getImage_uri() {
return image_uri;
}

public void setImage_uri(Uri image_uri) {
this.image_uri = image_uri;
}

public String getOverview() {
if (overview.equals("")) {
return "Not available";
}
return overview;
}

Expand All @@ -68,6 +83,9 @@ public void setOverview(String overview) {
}

public String getName() {
if (overview.equals("")) {
return "Season " + getSeason_number();
}
return name;
}

Expand All @@ -91,8 +109,12 @@ public void setSeason_number(int season_number) {
this.season_number = season_number;
}

public Uri getImage_uri() {
return Uri.parse(Contract.MOVIEDB_IMAGE_BASE_URL + getPoster_path());
public void initExtraFields() {
makeImage_uri();
}

private void makeImage_uri() {
setImage_uri(Uri.parse(Contract.MOVIEDB_IMAGE_BASE_URL + getPoster_path()));
}

// PARCELABLE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.squareup.picasso.Picasso;

import nmct.jaspernielsmichielhein.watchfriends.R;
import nmct.jaspernielsmichielhein.watchfriends.api.SimilarSeriesResult;
import nmct.jaspernielsmichielhein.watchfriends.helper.Contract;

import java.util.Arrays;
Expand Down Expand Up @@ -46,6 +47,7 @@ public class Series implements Parcelable {
private float rating = 0;
private ObservableArrayList<Season> seasons = new ObservableArrayList<Season>();
private String showed_on = "";
private SimilarSeriesResult similar;
private String status = "";
private String time_period = "";
private String type = "";
Expand Down Expand Up @@ -100,6 +102,24 @@ public void setFirst_air_date(String first_air_date) {
this.first_air_date = first_air_date;
}

public String getFullBackdrop_path() {

if (poster_path != null && poster_path != "") {
return Contract.MOVIEDB_IMAGE_BASE_URL + backdrop_path;
}

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

public String getFullPoster_path() {

if (poster_path != null && poster_path != "") {
return Contract.MOVIEDB_IMAGE_BASE_URL + poster_path;
}

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

public ObservableArrayList<Genre> getGenres() {
return genres;
}
Expand All @@ -109,6 +129,9 @@ public void setGenres(ObservableArrayList<Genre> genres) {
}

public String getHomepage() {
if (homepage.equals("")) {
return "Not available";
}
return homepage;
}

Expand Down Expand Up @@ -232,24 +255,6 @@ public String getPoster_path() {
return poster_path;
}

public String getFullPoster_path() {

if (poster_path != null && poster_path != "") {
return Contract.MOVIEDB_IMAGE_BASE_URL + poster_path;
}

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

public String getFullBackdrop_path() {

if (poster_path != null && poster_path != "") {
return Contract.MOVIEDB_IMAGE_BASE_URL + backdrop_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 Expand Up @@ -286,6 +291,14 @@ public void setShowed_on(String showed_on) {
this.showed_on = showed_on;
}

public SimilarSeriesResult getSimilar() {
return similar;
}

public void setSimilar(SimilarSeriesResult similar) {
this.similar = similar;
}

public String getStatus() {
return status;
}
Expand Down Expand Up @@ -408,9 +421,7 @@ public void makeShowed_on() {
}

public void makeTime_period() {

if (getStatus() != null) {

if (getStatus() != null && getFirst_air_date() != null && getLast_air_date() != null) {
if (getStatus().equals("Ended")) {
setTime_period(getFirst_air_date().substring(0, 4) + " - " + getLast_air_date().substring(0, 3));
} else if (getStatus().equals("")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ public boolean onNavigationItemSelected(MenuItem item) {
case R.id.nav_watching:
break;
case R.id.nav_watchlist:
ApiHelper.subscribe(movieDBService.getSeries(63174),
ApiHelper.subscribe(movieDBService.getSeries(11431),
new Action1<Series>() {
@Override
public void call(Series series) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@ public class SeriesFragment extends Fragment {

private Series series = null;

public SeriesFragment() { }
public SeriesFragment() {
}

public static SeriesFragment newInstance(Series series) {
Bundle args = new Bundle();
args.putParcelable(ARG_series,series);
args.putParcelable(ARG_series, series);

SeriesFragment fragment = new SeriesFragment();
fragment.setArguments(args);
Expand All @@ -40,7 +41,7 @@ public void onCreate(Bundle savedInstanceState) {
if (arguments != null) {
series = arguments.getParcelable(ARG_series);
series.initExtraFields();
if(series.getStatus() != null && series.getSeasons().get(0).getSeason_number() == 0) {
if (series.getStatus() != null && series.getSeasons().size() != 0 && series.getSeasons().get(0).getSeason_number() == 0) {
series.getSeasons().remove(0);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,12 @@ public void loadSeason() {
ApiHelper.subscribe(ApiMovieDbHelper.getMoviedbServiceInstance().getSeason(seriesId, seasonNumber),
new Action1<Season>() {
@Override
public void call(Season season) {
setSeason(season);
public void call(Season returnedSeason) {
setSeason(returnedSeason);
season.initExtraFields();
if (season.getEpisodes().size() == 0) {
fragmentSeasonBinding.txtNoEpisodes.setVisibility(View.VISIBLE);
}
fragmentSeasonBinding.setViewmodel(that);
notifyPropertyChanged(BR.viewmodel);
setHeader();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ public SeriesFragmentViewModel(Context context, FragmentSeriesBinding fragmentSe
this.context = context;
this.fragmentSeriesBinding = fragmentSeriesBinding;
this.series = series;
this.similarSeries = series.getSimilar().getResults();
if (series.getSeasons().size() == 0) {
fragmentSeriesBinding.txtNoSeasons.setVisibility(View.VISIBLE);
}
if (series.getSimilar().getResults().size() == 0) {
fragmentSeriesBinding.txtNoSimilar.setVisibility(View.VISIBLE);
fragmentSeriesBinding.rvSimilar.setVisibility(View.GONE);
}
if (context instanceof Interfaces.headerChangedListener) {
listener = (Interfaces.headerChangedListener) context;
} else {
Expand All @@ -67,7 +75,6 @@ public void loadSeries() {
fragmentSeriesBinding.setViewmodel(this);
notifyPropertyChanged(BR.viewmodel);
setHeader();
loadSimilarSeries();
}

private void setHeader() {
Expand Down Expand Up @@ -104,33 +111,4 @@ public void onClick(View v) {
});
}

private void loadSimilarSeries() {
setSimilarSeries(new ObservableArrayList<Series>());
ApiHelper.subscribe(ApiMovieDbHelper.getMoviedbServiceInstance().getSimilarSeries(series.getId()),
new Action1<SimilarSeriesResult>() {
@Override
public void call(SimilarSeriesResult similarSeriesResult) {
ObservableArrayList<Series> series = similarSeriesResult.getResults();
int maxTeller = 5;

if (series.size() < 5) {
maxTeller = series.size();
}

if (series.size() != 0) {
for (int i = 0; i < maxTeller; i++) {
ApiHelper.subscribe(
ApiMovieDbHelper.getMoviedbServiceInstance().getSeries(series.get(i).getId()),
new Action1<Series>() {
@Override
public void call(Series series) {
similarSeries.add(series);
notifyPropertyChanged(BR.viewmodel);
}
});
}
}
}
});
}
}
4 changes: 2 additions & 2 deletions WatchFriends/app/src/main/res/layout/fragment_episode.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginEnd="10dp"
android:contentDescription="@string/air_date_icon_description"
android:contentDescription="@string/icon_description"
android:src="@drawable/ic_date_range_white_24dp" />

<TextView
Expand Down Expand Up @@ -79,7 +79,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="10dp"
android:contentDescription="@string/overview_icon_description"
android:contentDescription="@string/icon_description"
android:src="@drawable/ic_info_outline_white_24dp" />

<TextView
Expand Down
15 changes: 12 additions & 3 deletions WatchFriends/app/src/main/res/layout/fragment_season.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginEnd="10dp"
android:contentDescription="@string/air_date_icon_description"
android:contentDescription="@string/icon_description"
android:src="@drawable/ic_date_range_white_24dp" />

<TextView
Expand Down Expand Up @@ -80,7 +80,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="10dp"
android:contentDescription="@string/overview_icon_description"
android:contentDescription="@string/icon_description"
android:src="@drawable/ic_info_outline_white_24dp" />

<TextView
Expand Down Expand Up @@ -112,11 +112,20 @@

</LinearLayout>

<TextView
android:id="@+id/txtNoEpisodes"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/no_episodes_available"
android:layout_below="@id/llEpisodes"
android:layout_marginBottom="5dp"
android:visibility="gone"/>

<ListView
android:id="@+id/lvEpisodes"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_below="@id/llEpisodes"
android:layout_below="@id/txtNoEpisodes"
android:layout_marginBottom="10dp"
app:items="@{viewmodel.getSeason().episodes}" >

Expand Down
Loading

0 comments on commit b367c2a

Please sign in to comment.