package com.hilton.gitatouille;

import java.util.List;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.nineoldandroids.animation.Animator;
import com.nineoldandroids.animation.AnimatorSet;
import com.nineoldandroids.animation.ObjectAnimator;
import com.nineoldandroids.view.ViewHelper;

public class ProgitListAdapter extends BaseExpandableListAdapter {
    private static final int ANIMATION_DEFAULT_DURATION = 400;
    private static final int ANIMATION_DEFAULT_DELAY = 100;
    private static final String TAG = ProgitListAdapter.class.getName();
    private List<ProGitChapter> mProGitChapters;
    private Context mContext;
    private LayoutInflater mViewFactory;
    
    public ProgitListAdapter(Context ctx) {
        mContext = ctx;
        mProGitChapters = ProGit.getChapters();
        mViewFactory = LayoutInflater.from(ctx);
    }
    
    @Override
    public ProGitSection getChild(int groupPosition, int childPosition) {
        return mProGitChapters.get(groupPosition).getSection(childPosition);
    }

    @Override
    public long getChildId(int groupPosition, int childPosition) {
        return childPosition;
    }

    @Override
    public View getChildView(int groupPosition, int childPosition,
            boolean isLastChild, View convertView, ViewGroup parent) {
        TextView name = null;
        if (convertView == null) {
            name = (TextView) mViewFactory.inflate(R.layout.progit_child_item, null, false);
        } else {
            name = (TextView) convertView;
        }
        name.setText(getChild(groupPosition, childPosition).mName);
        return name;
    }
    
    @Override
    public int getChildrenCount(int groupPosition) {
        return mProGitChapters.get(groupPosition).getSectionCount();
    }

    @Override
    public ProGitChapter getGroup(int groupPosition) {
        return mProGitChapters.get(groupPosition);
    }

    @Override
    public int getGroupCount() {
        return mProGitChapters.size();
    }

    @Override
    public long getGroupId(int groupPosition) {
        return groupPosition;
    }
    
    @Override
    public View getGroupView(int groupPosition, boolean isExpanded,
            View convertView, ViewGroup parent) {
        View root = null;
        if (convertView == null) {
            root = mViewFactory.inflate(R.layout.progit_group_item, null, false);
            Animator flyIn = ObjectAnimator.ofFloat(root, "translationY", 500, 0);
            setupAnimation(groupPosition, root, parent, flyIn);
        } else {
            root = convertView;
        }
        TextView textView = (TextView) root.findViewById(R.id.name);
        textView.setText(getGroup(groupPosition).mName);
        ImageView indicator = (ImageView) root.findViewById(R.id.indicator);
        indicator.setImageResource(isExpanded ? R.drawable.button_tab_to_close : R.drawable.button_tab_to_open);
        return root;
    }

    private void setupAnimation(int position, View view, ViewGroup parent, Animator flyIn) {
        Log.e(TAG, "setupAnimation position " + position);
        ViewHelper.setAlpha(view, 0);
        Animator alpha = ObjectAnimator.ofFloat(view, "alpha", 0, 1);
        AnimatorSet set = new AnimatorSet();
        set.playTogether(flyIn, alpha);
        int delay = ANIMATION_DEFAULT_DELAY;
        set.setStartDelay(position * delay);
        set.setDuration(ANIMATION_DEFAULT_DURATION);
        set.start();
    }
    
    @Override
    public boolean hasStableIds() {
        return true;
    }

    @Override
    public boolean isChildSelectable(int groupPosition, int childPosition) {
        return true;
    }
}

@@ -86,33 +86,8 @@
 xt;%0A
-import android.util.Log;%0A
 impo
@@ -114,24 +114,24 @@
 utInflater;%0A
+
 import andro
@@ -294,392 +294,74 @@
 w;%0A%0A
-import com.nineoldandroids.animation.Animator;%0Aimport com.nineoldandroids.animation.AnimatorSet;%0Aimport com.nineoldandroids.animation.ObjectAnimator;%0Aimport com.nineoldandroids.view.ViewHelper;%0A%0Apublic class ProgitListAdapter extends BaseExpandableListAdapter %7B%0A    private static final int ANIMATION_DEFAULT_DURATION = 400;%0A    private static final int ANIMATION_DEFAULT_DELAY = 100;
+public class ProgitListAdapter extends BaseExpandableListAdapter %7B
 %0A   
@@ -2246,155 +2246,8 @@
 e);%0A
-            Animator flyIn = ObjectAnimator.ofFloat(root, %22translationY%22, 500, 0);%0A            setupAnimation(groupPosition, root, parent, flyIn);%0A
     
@@ -2649,528 +2649,8 @@
  %7D%0A%0A
-    private void setupAnimation(int position, View view, ViewGroup parent, Animator flyIn) %7B%0A        Log.e(TAG, %22setupAnimation position %22 + position);%0A        ViewHelper.setAlpha(view, 0);%0A        Animator alpha = ObjectAnimator.ofFloat(view, %22alpha%22, 0, 1);%0A        AnimatorSet set = new AnimatorSet();%0A        set.playTogether(flyIn, alpha);%0A        int delay = ANIMATION_DEFAULT_DELAY;%0A        set.setStartDelay(position * delay);%0A        set.setDuration(ANIMATION_DEFAULT_DURATION);%0A        set.start();%0A    %7D%0A    %0A
     

Remove animations for expandable list group.