Android Open Source - iwannawatch-android Dynamic Movies Adapter






From Project

Back to project page iwannawatch-android.

License

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.

Java Source Code

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();
            }
        };
    }
}




Java Source Code List

com.meoyawn.iwannawatch.AppModule.java
com.meoyawn.iwannawatch.App.java
com.meoyawn.iwannawatch.CrashReportingTree.java
com.meoyawn.iwannawatch.DynamicHeightImageView.java
com.meoyawn.iwannawatch.MainActivity.java
com.meoyawn.iwannawatch.MainFragment.java
com.meoyawn.iwannawatch.MovieView.java
com.meoyawn.iwannawatch.adapters.BaseMoviesAdapter.java
com.meoyawn.iwannawatch.adapters.CursorMoviesAdapter.java
com.meoyawn.iwannawatch.adapters.DynamicMoviesAdapter.java
com.meoyawn.iwannawatch.doers.DatabaseHelper.java
com.meoyawn.iwannawatch.doers.TheMovieDbApi.java
com.meoyawn.iwannawatch.models.Movie.java
com.meoyawn.iwannawatch.models.Search.java
com.meoyawn.iwannawatch.qualifiers.Delete.java
com.meoyawn.iwannawatch.qualifiers.Done.java