Android Open Source - filmster Movie List Item Holder






From Project

Back to project page filmster.

License

The source code is released under:

Apache License

If you think the Android project filmster 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.doodeec.filmster.MovieList;
/* www.  j  a  v a 2 s. c om*/
import android.graphics.Bitmap;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.doodeec.filmster.Helper;
import com.doodeec.filmster.R;

/**
 * Created by Dusan Doodeec Bartos on 27.10.2014.
 *
 * Movie item - holder pattern
 */
public class MovieListItemHolder {

    private TextView mTitleView;
    private TextView mYearView;
    private TextView mRatingView;
    private ImageView mPosterView;

    public MovieListItemHolder(View view) {
        mTitleView = (TextView) view.findViewById(R.id.movie_title);
        mYearView = (TextView) view.findViewById(R.id.movie_year);
        mRatingView = (TextView) view.findViewById(R.id.movie_rating);
        mPosterView = (ImageView) view.findViewById(R.id.movie_poster);

        if (mTitleView == null || mYearView == null || mRatingView == null || mPosterView == null) {
            throw new AssertionError("Movie holder does not have required structure");
        }
    }

    public void setTitle(String title) {
        mTitleView.setText(title);
    }

    public void setYear(Integer year) {
        if (year != null) {
            mYearView.setText(String.valueOf(year));
        } else {
            mYearView.setText(Helper.EMPTY_STRING);
        }
    }

    public void setRating(Integer rating) {
        if (rating != null) {
            mRatingView.setText(String.format(Helper.getString(R.string.movie_rating), rating));
            mRatingView.setTextColor(Helper.getColor(getRatingColor(rating)));
        } else {
            mRatingView.setText(Helper.EMPTY_STRING);
        }
    }

    public void setThumbnail(Bitmap thumbnail) {
        if (thumbnail != null) {
            mPosterView.setImageBitmap(thumbnail);
            mPosterView.setVisibility(View.VISIBLE);
        } else {
            mPosterView.setVisibility(View.GONE);
        }
    }

    /**
     * Color of rating number adapts to its value, to be visually marked in the list
     * 0  - 19 %   - red (bullshit)
     * 20 - 39 %   - orange (wtf)
     * 40 - 79 %   - blue (not bad)
     * 80 - 100 %  - green (blockbuster)
     *
     * @param rating rating in percent
     * @return color resource id
     */
    private int getRatingColor(int rating) {
        switch ((int) Math.floor(rating / 20)) {
            case 0:
                return R.color.ruby_deep;
            case 1:
                return R.color.amber_deep;
            case 4:
                return R.color.emerald_deep;
            case 5:
                return R.color.emerald;
            default:
                return R.color.azure_deep;
        }
    }
}




Java Source Code List

com.doodeec.filmster.HelperSpec.java
com.doodeec.filmster.Helper.java
com.doodeec.filmster.ImageCacheSpec.java
com.doodeec.filmster.ImageCache.java
com.doodeec.filmster.MainActivity.java
com.doodeec.filmster.Mock.java
com.doodeec.filmster.ApplicationState.AppStateSpec.java
com.doodeec.filmster.ApplicationState.AppState.java
com.doodeec.filmster.ApplicationState.ConnectionStateChange.java
com.doodeec.filmster.Model.JSONParserSpec.java
com.doodeec.filmster.Model.JSONParser.java
com.doodeec.filmster.Model.MovieDefinitionKeys.java
com.doodeec.filmster.Model.MovieSpec.java
com.doodeec.filmster.Model.Movie.java
com.doodeec.filmster.MovieDetail.MovieDetailFragmentSpec.java
com.doodeec.filmster.MovieDetail.MovieDetailFragment.java
com.doodeec.filmster.MovieList.MovieListActivityInterface.java
com.doodeec.filmster.MovieList.MovieListAdapterSpec.java
com.doodeec.filmster.MovieList.MovieListAdapter.java
com.doodeec.filmster.MovieList.MovieListFragmentSpec.java
com.doodeec.filmster.MovieList.MovieListFragment.java
com.doodeec.filmster.MovieList.MovieListItemHolderSpec.java
com.doodeec.filmster.MovieList.MovieListItemHolder.java
com.doodeec.filmster.Provider.DbHelperSpec.java
com.doodeec.filmster.Provider.DbHelper.java
com.doodeec.filmster.Provider.MovieEntry.java
com.doodeec.filmster.Provider.MovieProviderSpec.java
com.doodeec.filmster.Provider.MovieProvider.java
com.doodeec.filmster.ServerCommunicator.ResourceServiceSpec.java
com.doodeec.filmster.ServerCommunicator.ResourceService.java
com.doodeec.filmster.ServerCommunicator.ResponseListener.BitmapServerResponseListener.java
com.doodeec.filmster.ServerCommunicator.ResponseListener.JSONServerResponseListener.java
com.doodeec.filmster.ServerCommunicator.ResponseListener.ServerResponseListener.java
com.doodeec.filmster.ServerCommunicator.ServerRequest.ErrorResponseSpec.java
com.doodeec.filmster.ServerCommunicator.ServerRequest.ErrorResponse.java
com.doodeec.filmster.ServerCommunicator.ServerRequest.ServerRequestInterface.java
com.doodeec.filmster.ServerCommunicator.ServerRequest.ServerRequestSpec.java
com.doodeec.filmster.ServerCommunicator.ServerRequest.ServerRequest.java