Android Open Source - android-javarx-example Movie Adapter






From Project

Back to project page android-javarx-example.

License

The source code is released under:

Apache License

If you think the Android project android-javarx-example 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.bnsantos.movies.adapter;
/*  w  w  w.  jav a 2s  .co  m*/
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bnsantos.movies.R;
import com.bnsantos.movies.model.Movie;
import com.squareup.picasso.Picasso;

/**
 * Created by bruno on 14/11/14.
 */
public class MovieAdapter extends ArrayAdapter<Movie> {

    public MovieAdapter(Context context, int resource) {
        super(context, resource);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = LayoutInflater.from(getContext()).inflate(R.layout.adapter_movie, parent, false);
            TextView title = (TextView) convertView.findViewById(R.id.movieTitle);
            TextView score = (TextView) convertView.findViewById(R.id.movieScore);
            TextView rating = (TextView) convertView.findViewById(R.id.movieRating);
            ImageView poster = (ImageView) convertView.findViewById(R.id.moviePoster);
            convertView.setTag(new ViewHolder(title, score, rating, poster));
        }
        ViewHolder viewHolder = (ViewHolder) convertView.getTag();
        final Movie movie = getItem(position);

        viewHolder.title.setText(movie.getTitle());
        viewHolder.rating.setText(getContext().getString(R.string.movie_rating, movie.getMpaa_rating()));
        viewHolder.score.setText(getContext().getString(R.string.movie_score, Integer.toString(movie.getRatings().getCritics_score())));
        Picasso.with(getContext()).load(movie.getPosters().getDetailed()).fit().into(viewHolder.poster);
        viewHolder.poster.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent i = new Intent(Intent.ACTION_VIEW);
                i.setData(Uri.parse(movie.getLinks().getAlternate()));
                getContext().startActivity(i);
            }
        });

        return convertView;
    }

    private class ViewHolder {
        public final TextView title;
        public final TextView score;
        public final TextView rating;
        public final ImageView poster;

        private ViewHolder(TextView title, TextView score, TextView rating, ImageView poster) {
            this.title = title;
            this.score = score;
            this.rating = rating;
            this.poster = poster;
        }
    }
}




Java Source Code List

com.bnsantos.movies.App.java
com.bnsantos.movies.MovieServiceTest.java
com.bnsantos.movies.MoviesTestRunner.java
com.bnsantos.movies.TestSuite.java
com.bnsantos.movies.TestUtils.java
com.bnsantos.movies.Utils.java
com.bnsantos.movies.activities.MainActivity.java
com.bnsantos.movies.adapter.MovieAdapter.java
com.bnsantos.movies.cache.MovieCaching.java
com.bnsantos.movies.cache.PersistentManager.java
com.bnsantos.movies.model.Links.java
com.bnsantos.movies.model.MovieListType.java
com.bnsantos.movies.model.MovieResponse.java
com.bnsantos.movies.model.Movie.java
com.bnsantos.movies.model.Posters.java
com.bnsantos.movies.model.Ratings.java
com.bnsantos.movies.model.ReleaseDates.java
com.bnsantos.movies.providers.LazyMovieProvider.java
com.bnsantos.movies.providers.MovieProvider.java
com.bnsantos.movies.providers.SubjectMovieProvider.java
com.bnsantos.movies.services.MovieService.java
com.bnsantos.movies.services.RestErrorHandler.java