<commit_before>package com.darsh.couponstracker.ui.adapter;

import android.app.Activity;
import android.content.Context;
import android.database.Cursor;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.CardView;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.darsh.couponstracker.R;
import com.darsh.couponstracker.logger.DebugLog;
import com.darsh.couponstracker.data.model.Coupon;
import com.darsh.couponstracker.controller.util.Utilities;

/**
 * Created by darshan on 23/3/17.
 */

public class CouponListCursorAdapter extends RecyclerView.Adapter<CouponListCursorAdapter.ViewHolder> {
    private Context context;
    private Cursor cursor;

    private OnCursorCouponClickListener onCursorCouponClickListener;

    public CouponListCursorAdapter(Activity activity) {
        context = activity.getApplicationContext();
        onCursorCouponClickListener = (OnCursorCouponClickListener) activity;
    }

    public void setCursor(Cursor cursor) {
        DebugLog.logMethod();
        this.cursor = cursor;
        notifyDataSetChanged();
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        CardView cardView = (CardView) LayoutInflater.from(parent.getContext())
                .inflate(R.layout.recycler_view_item_coupon, parent, false);
        return new ViewHolder(cardView);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        cursor.moveToPosition(position);
        Coupon coupon = Coupon.getCoupon(cursor);

        holder.merchant.setText(coupon.merchant);
        holder.category.setText(coupon.category);
        holder.validUntil.setText(Utilities.getStringDate(coupon.validUntil));
        holder.couponCode.setText(coupon.couponCode);

        // Coupon has been used
        if (coupon.state == 1) {
            holder.imageViewCouponState.setImageDrawable(
                    ContextCompat.getDrawable(context, R.drawable.ic_check_circle_green_24dp)
            );
            holder.textViewCouponState.setText(context.getString(R.string.coupon_state_used));
            holder.textViewCouponState.setTextColor(ContextCompat.getColor(context, R.color.material_green_700));
            return;
        }

        // Coupon is still valid
        if (coupon.validUntil >= Utilities.getLongDateToday()) {
            holder.imageViewCouponState.setImageDrawable(
                    ContextCompat.getDrawable(context, R.drawable.ic_add_shopping_cart_orange_24dp)
            );
            holder.imageViewCouponState.setColorFilter(R.color.material_orange_900);<commit_msg>Remove color filter in CouponListCursorAdapter<commit_after>package com.darsh.couponstracker.ui.adapter;

import android.app.Activity;
import android.content.Context;
import android.database.Cursor;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.CardView;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.darsh.couponstracker.R;
import com.darsh.couponstracker.controller.util.Utilities;
import com.darsh.couponstracker.data.model.Coupon;
import com.darsh.couponstracker.logger.DebugLog;

/**
 * Created by darshan on 23/3/17.
 */

public class CouponListCursorAdapter extends RecyclerView.Adapter<CouponListCursorAdapter.ViewHolder> {
    private Context context;
    private Cursor cursor;

    private OnCursorCouponClickListener onCursorCouponClickListener;

    public CouponListCursorAdapter(Activity activity) {
        context = activity.getApplicationContext();
        onCursorCouponClickListener = (OnCursorCouponClickListener) activity;
    }

    public void setCursor(Cursor cursor) {
        DebugLog.logMethod();
        this.cursor = cursor;
        notifyDataSetChanged();
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        CardView cardView = (CardView) LayoutInflater.from(parent.getContext())
                .inflate(R.layout.recycler_view_item_coupon, parent, false);
        return new ViewHolder(cardView);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        cursor.moveToPosition(position);
        Coupon coupon = Coupon.getCoupon(cursor);

        holder.merchant.setText(coupon.merchant);
        holder.category.setText(coupon.category);
        holder.validUntil.setText(Utilities.getStringDate(coupon.validUntil));
        holder.couponCode.setText(coupon.couponCode);

        // Coupon has been used
        if (coupon.state == 1) {
            holder.imageViewCouponState.setImageDrawable(
                    ContextCompat.getDrawable(context, R.drawable.ic_check_circle_green_24dp)
            );
            holder.textViewCouponState.setText(context.getString(R.string.coupon_state_used));
            holder.textViewCouponState.setTextColor(ContextCompat.getColor(context, R.color.material_green_700));
            return;
        }

        // Coupon is still valid
        if (coupon.validUntil >= Utilities.getLongDateToday()) {
            holder.imageViewCouponState.setImageDrawable(
                    ContextCompat.getDrawable(context, R.drawable.ic_add_shopping_cart_orange_24dp)
            );
{'fraction_non_alphanumeric': 0.08895705521472393, 'fraction_numerical': 0.0063154095994225916, 'mean_word_length': 3.5434426229508196, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7663782', 'n_tokens_mistral': 1607, 'n_tokens_neox': 1592, 'n_words': 250}