Skip to content

Commit

Permalink
Filter selected option
Browse files Browse the repository at this point in the history
  • Loading branch information
SrMonedero committed Dec 6, 2018
1 parent 538c3fb commit aef6e2f
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 5 deletions.
3 changes: 2 additions & 1 deletion AndroidManifest.xml
Expand Up @@ -34,7 +34,8 @@
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/Theme.CastVideosTheme"
android:name=".JarriOnApplication">
android:name=".JarriOnApplication"
android:usesCleartextTraffic="true">

<activity
android:name="com.google.sample.cast.refplayer.ui.channel.view.ChannelActivity"
Expand Down
Expand Up @@ -12,6 +12,7 @@ public class ChannelDataModel {
private String sourceJsonURL;
private String title;
private String website;
private int channeltype;

public int getId() {
return id;
Expand Down Expand Up @@ -68,4 +69,8 @@ public String getDisplayURL() {
}
return result;
}

public int getChanneltype() {
return channeltype;
}
}
Expand Up @@ -20,6 +20,7 @@ public Channel map(ChannelDataModel source) {
.mosaicCoverURL(source.getMosaicURL())
.coverURL(source.getDisplayURL())
.jsonURL(source.getSourceJsonURL())
.channelType(source.getChanneltype())
.build();
}

Expand Down
12 changes: 12 additions & 0 deletions src/com/google/sample/cast/refplayer/domain/model/Channel.java
Expand Up @@ -6,6 +6,7 @@ public class Channel {
private String coverURL;
private String mosaicCoverURL;
private String jsonURL;
private int channelType;

public String getId() {
return id;
Expand All @@ -27,12 +28,17 @@ public String getJsonURL() {
return jsonURL;
}

public int getChannelType() {
return channelType;
}

private Channel(Builder builder) {
id = builder.id;
name = builder.name;
coverURL = builder.coverURL;
mosaicCoverURL = builder.mosaicCoverURL;
jsonURL = builder.jsonURL;
channelType = builder.channelType;
}

public static final class Builder {
Expand All @@ -41,6 +47,7 @@ public static final class Builder {
private String coverURL;
private String mosaicCoverURL;
private String jsonURL;
private int channelType;

public Builder() {
}
Expand Down Expand Up @@ -73,5 +80,10 @@ public Builder jsonURL(String val) {
jsonURL = val;
return this;
}

public Builder channelType(int val) {
channelType = val;
return this;
}
}
}
Expand Up @@ -6,6 +6,7 @@ public class ChannelListItemViewModel {
private String coverURL;
private String mosaicCoverURL;
private String jsonURL;
private int channelType;

public String getId() {
return id;
Expand All @@ -27,12 +28,17 @@ public String getMosaicCoverURL() {
return mosaicCoverURL;
}

public int getChannelType() {
return channelType;
}

private ChannelListItemViewModel(Builder builder) {
id = builder.id;
name = builder.name;
coverURL = builder.coverURL;
mosaicCoverURL = builder.mosaicCoverURL;
jsonURL = builder.jsonURL;
channelType = builder.channelType;
}

public static final class Builder {
Expand All @@ -41,6 +47,7 @@ public static final class Builder {
private String coverURL;
private String mosaicCoverURL;
private String jsonURL;
private int channelType;

public Builder() {
}
Expand Down Expand Up @@ -70,6 +77,11 @@ public Builder jsonURL(String val) {
return this;
}

public Builder channelType(int val) {
channelType = val;
return this;
}

public ChannelListItemViewModel build() {
return new ChannelListItemViewModel(this);
}
Expand Down
Expand Up @@ -20,6 +20,7 @@ public ChannelListItemViewModel map(Channel source) {
.coverURL(source.getCoverURL())
.mosaicCoverURL(source.getMosaicCoverURL())
.jsonURL(source.getJsonURL())
.channelType(source.getChannelType())
.build();
}

Expand Down
Expand Up @@ -13,17 +13,20 @@

public class ChannelListAdapter extends RecyclerView.Adapter<ChannelListItemViewHolder> {
private final List<ChannelListItemViewModel> stations;
private final List<ChannelListItemViewModel> filteredStations;
private final ChannelListItemClickListener channelListItemClickListener;
private int filter = 0;

public ChannelListAdapter(ChannelListItemClickListener channelListItemClickListener) {
this.stations = new ArrayList<>();
this.filteredStations = new ArrayList<>();
this.channelListItemClickListener = channelListItemClickListener;
}

public void setStations(List<ChannelListItemViewModel> stations) {
this.stations.clear();
this.stations.addAll(stations);
notifyDataSetChanged();
updateFilter();
}

@Override
Expand All @@ -36,12 +39,31 @@ public ChannelListItemViewHolder onCreateViewHolder(ViewGroup parent, int viewTy

@Override
public void onBindViewHolder(ChannelListItemViewHolder holder, int position) {
ChannelListItemViewModel station = stations.get(position);
ChannelListItemViewModel station = filteredStations.get(position);
holder.bind(station, channelListItemClickListener);
}

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

public void setFilter(int filter) {
this.filter = filter;
updateFilter();
}

private void updateFilter() {
this.filteredStations.clear();
if (filter == 0) {
this.filteredStations.addAll(stations);
} else {
for (int i = 0; i < stations.size(); i++) {
if (stations.get(i).getChannelType() == filter) {
this.filteredStations.add(stations.get(i));
}
}
}
notifyDataSetChanged();
}
}
Expand Up @@ -118,6 +118,6 @@ public void onItemClick(ChannelListItemViewModel channelListItemViewModel) {
}

public void filter(int filter) {
Toast.makeText(getContext(), "selected option" + filter, Toast.LENGTH_SHORT).show();
channelListAdapter.setFilter(filter);
}
}

0 comments on commit aef6e2f

Please sign in to comment.