package com.newsblur.view;

import android.content.Context;
import android.content.res.Resources;
import android.text.style.ForegroundColorSpan;
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.newsblur.R;
import com.newsblur.domain.UserDetails;
import com.newsblur.domain.ActivityDetails;
import com.newsblur.domain.ActivityDetails.Category;
import com.newsblur.network.APIConstants;
import com.newsblur.util.FeedUtils;
import com.newsblur.util.UIUtils;

public abstract class ActivityDetailsAdapter extends ArrayAdapter<ActivityDetails> {

    private LayoutInflater inflater;
    protected final String ago;
    protected ForegroundColorSpan linkColor, contentColor, quoteColor;
    protected UserDetails currentUserDetails;
    protected final boolean userIsYou;

    public ActivityDetailsAdapter(final Context context, UserDetails user) {
        super(context, R.id.row_activity_text);
        inflater = LayoutInflater.from(context);

        currentUserDetails = user;

        Resources resources = context.getResources();
        ago = resources.getString(R.string.profile_ago);

        linkColor = new ForegroundColorSpan(UIUtils.getThemedColor(context, R.attr.linkText, android.R.attr.textColor));
        contentColor = new ForegroundColorSpan(UIUtils.getThemedColor(context, R.attr.defaultText, android.R.attr.textColor));
        quoteColor = new ForegroundColorSpan(UIUtils.getThemedColor(context, R.attr.storySnippetText, android.R.attr.textColor));

        userIsYou = user.userId == null;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view = null;
        if (convertView == null) {
            view = inflater.inflate(R.layout.row_activity, null);
        } else {
            view = convertView;
        }
        final ActivityDetails activity = getItem(position);

        TextView activityText = (TextView) view.findViewById(R.id.row_activity_text);
        TextView activityTime = (TextView) view.findViewById(R.id.row_activity_time);
        ImageView imageView = (ImageView) view.findViewById(R.id.row_activity_icon);

        activityTime.setText(activity.timeSince.toUpperCase() + " " + ago);
        if (activity.category == Category.FEED_SUBSCRIPTION) {
            FeedUtils.iconLoader.displayImage(APIConstants.S3_URL_FEED_ICONS + activity.feedId + ".png", imageView, 5, false);
        } else if (activity.category == Category.SHARED_STORY) {
            FeedUtils.iconLoader.displayImage(currentUserDetails.photoUrl, imageView, 10f, false);
        } else if (activity.category == Category.STAR) {
            imageView.setImageResource(R.drawable.clock);
        } else if (activity.user != null) {
            FeedUtils.iconLoader.displayImage(activity.user.photoUrl, imageView, 5, false);
        } else {
            imageView.setImageResource(R.drawable.logo);
        }

        activityText.setText(getTextForActivity(activity));
        return view;
    }

    protected abstract CharSequence getTextForActivity(ActivityDetails activity);
}

@@ -1020,18 +1020,22 @@
 text, R.
-id
+layout
 .row_act
@@ -1031,39 +1031,93 @@
 out.row_activity
-_text);
+); // final argument seems unused since we override getView()
 %0A        inflate

fix lint warning