Back to project page iwannawatch-android.
The source code is released under:
MIT License
If you think the Android project iwannawatch-android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.meoyawn.iwannawatch.adapters; /* w w w . j a v a2 s .c om*/ import android.content.Context; import android.text.TextUtils; import android.view.LayoutInflater; import android.widget.Filter; import com.meoyawn.iwannawatch.R; import com.meoyawn.iwannawatch.doers.TheMovieDbApi; import com.meoyawn.iwannawatch.models.Movie; import com.meoyawn.iwannawatch.models.Search; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; /** * Created by adel on 3/1/14 */ public class DynamicMoviesAdapter extends BaseMoviesAdapter { final TheMovieDbApi theMovieDbApi; @Nullable Movie[] movies; public DynamicMoviesAdapter(Context context, LayoutInflater inflater, @NotNull TheMovieDbApi theMovieDbApi) { super(context, inflater); this.theMovieDbApi = theMovieDbApi; } @Override public int getCount() { return movies != null ? movies.length : 0; } @Override @Nullable public Movie getItem(int position) { return movies != null ? movies[position] : null; } @Override protected int getItemLayoutRes() { return R.layout.movie_item_list; } @Override public Filter getFilter() { return new Filter() { static final int EMPTY = 0; @Override protected FilterResults performFiltering(CharSequence constraint) { FilterResults filterResults = new FilterResults(); if (!TextUtils.isEmpty(constraint)) { Search search = theMovieDbApi.search(constraint) .toBlockingObservable() .first(); filterResults.values = search.results; filterResults.count = search.results.length; } else { filterResults.count = EMPTY; } return filterResults; } @Override protected void publishResults(CharSequence constraint, FilterResults results) { movies = (Movie[]) results.values; notifyDataSetChanged(); } }; } }