package com.kickstarter.ui.adapters;

import android.support.annotation.IntDef;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.kickstarter.R;
import com.kickstarter.models.Activity;
import com.kickstarter.presenters.ActivityFeedPresenter;
import com.kickstarter.ui.view_holders.ActivityListViewHolder;
import com.kickstarter.ui.view_holders.FriendBackingViewHolder;
import com.kickstarter.ui.view_holders.FriendFollowViewHolder;
import com.kickstarter.ui.view_holders.ProjectStateChangedPositiveViewHolder;
import com.kickstarter.ui.view_holders.ProjectStateChangedViewHolder;
import com.kickstarter.ui.view_holders.ProjectUpdateViewHolder;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.List;

public class ActivityListAdapter extends RecyclerView.Adapter<ActivityListViewHolder> {
  private List<Activity> activities;
  private ActivityFeedPresenter presenter;

  private static final int FRIEND_BACKING = 0;
  private static final int FRIEND_FOLLOW = 1;
  private static final int PROJECT_STATE_CHANGED = 2;
  private static final int PROJECT_STATE_CHANGED_POSITIVE = 3;
  private static final int PROJECT_UPDATE = 4;

  @IntDef({FRIEND_BACKING, FRIEND_FOLLOW, PROJECT_STATE_CHANGED, PROJECT_STATE_CHANGED_POSITIVE, PROJECT_UPDATE})
  @Retention(RetentionPolicy.SOURCE)
  public @interface ViewType {}

  public ActivityListAdapter(final List<Activity> activities, final ActivityFeedPresenter presenter) {
    this.activities = activities;
    this.presenter = presenter;
  }

  @Override
  public @ViewType int getItemViewType(final int position) {
    final Activity activity = activities.get(position);
    switch(activity.category()) {
      case BACKING:
        return FRIEND_BACKING;
      case FOLLOW:
        return FRIEND_FOLLOW;
      case FAILURE:
      case CANCELLATION:
      case SUSPENSION:
      case RESUME:
        return PROJECT_STATE_CHANGED;
      case LAUNCH:
      case SUCCESS:
        return PROJECT_STATE_CHANGED_POSITIVE;
      case UPDATE:
        return PROJECT_UPDATE;
      default:
        throw new RuntimeException("Unhandled view type for activity: " + activity.toString());
    }
  }

  @Override
  public void onBindViewHolder(final ActivityListViewHolder view_holder, final int i) {
    final Activity activity = activities.get(i);
    view_holder.onBind(activity);
  }

  @Override
  public ActivityListViewHolder onCreateViewHolder(final ViewGroup view_group, final @ViewType int view_type) {
    final LayoutInflater layout_inflater = LayoutInflater.from(view_group.getContext());

    final View view;
    switch (view_type) {
      case FRIEND_BACKING:
        view = layout_inflater.inflate(R.layout.activity_friend_backing_view, view_group, false);
        return new FriendBackingViewHolder(view, presenter);
      case FRIEND_FOLLOW:
        view = layout_inflater.inflate(R.layout.activity_friend_follow_view, view_group, false);
        return new FriendFollowViewHolder(view, presenter);
      case PROJECT_STATE_CHANGED:
        view = layout_inflater.inflate(R.layout.activity_project_state_changed_view, view_group, false);
        return new ProjectStateChangedViewHolder(view, presenter);
      case PROJECT_STATE_CHANGED_POSITIVE:
        view = layout_inflater.inflate(R.layout.activity_project_state_changed_positive_view, view_group, false);
        return new ProjectStateChangedPositiveViewHolder(view, presenter);
      case PROJECT_UPDATE:
        view = layout_inflater.inflate(R.layout.activity_project_update_view, view_group, false);
        return new ProjectUpdateViewHolder(view, presenter);
      default:
        throw new RuntimeException("Unhandled view type: " + view_type);
    }
  }

  @Override
  public int getItemCount() {
    return activities.size();
  }
}

@@ -2351,26 +2351,25 @@
 wHolder view
-_h
+H
 older, final
@@ -2431,26 +2431,25 @@
 i);%0A    view
-_h
+H
 older.onBind
@@ -2544,26 +2544,25 @@
 ewGroup view
-_g
+G
 roup, final 
@@ -2575,26 +2575,25 @@
 ype int view
-_t
+T
 ype) %7B%0A    f
@@ -2614,26 +2614,25 @@
 later layout
-_i
+I
 nflater = La
@@ -2649,26 +2649,25 @@
 er.from(view
-_g
+G
 roup.getCont
@@ -2708,26 +2708,25 @@
 switch (view
-_t
+T
 ype) %7B%0A     
@@ -2760,34 +2760,33 @@
    view = layout
-_i
+I
 nflater.inflate(
@@ -2820,34 +2820,33 @@
 cking_view, view
-_g
+G
 roup, false);%0A  
@@ -2943,34 +2943,33 @@
    view = layout
-_i
+I
 nflater.inflate(
@@ -3002,34 +3002,33 @@
 ollow_view, view
-_g
+G
 roup, false);%0A  
@@ -3132,34 +3132,33 @@
    view = layout
-_i
+I
 nflater.inflate(
@@ -3199,34 +3199,33 @@
 anged_view, view
-_g
+G
 roup, false);%0A  
@@ -3345,34 +3345,33 @@
    view = layout
-_i
+I
 nflater.inflate(
@@ -3421,34 +3421,33 @@
 itive_view, view
-_g
+G
 roup, false);%0A  
@@ -3571,10 +3571,9 @@
 yout
-_i
+I
 nfla
@@ -3631,10 +3631,9 @@
 view
-_g
+G
 roup
@@ -3787,10 +3787,9 @@
 view
-_t
+T
 ype)

Unify naming conventions for variables