Subversion Repositories SmartDukaan

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
21478 rajender 1
package com.saholic.profittill.navigationdrawer;
2
 
3
import android.app.Activity;
4
import android.content.Context;
5
import android.view.LayoutInflater;
6
import android.view.View;
7
import android.view.ViewGroup;
8
import android.widget.BaseExpandableListAdapter;
9
import android.widget.ImageView;
10
import android.widget.TextView;
11
 
12
import com.saholic.profittill.R;
13
 
14
import java.util.HashMap;
15
import java.util.List;
16
 
17
public class ExpandableNavigationAdapter extends BaseExpandableListAdapter {
18
    private List<ExpandableNavigationItem> parentRecord;
19
    private HashMap<String, List<String>> childRecord;
20
    private LayoutInflater inflater = null;
21
    private Activity mContext;
22
 
23
    public ExpandableNavigationAdapter(Activity context, List<ExpandableNavigationItem> parentList, HashMap<String, List<String>> childList) {
24
        this.parentRecord = parentList;
25
        this.childRecord = childList;
26
        mContext = context;
27
        inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
28
    }
29
 
30
    @Override
31
    public String getChild(int groupPosition, int childPosition) {
32
        return this.childRecord.get(getGroup(groupPosition).getTitle()).get(childPosition);
33
    }
34
 
35
    @Override
36
    public long getChildId(int groupPosition, int childPosition) {
37
        return childPosition;
38
    }
39
 
40
    @Override
41
    public View getChildView(int groupPosition, final int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
42
 
43
        String childConfig = getChild(groupPosition, childPosition);
44
 
45
        ViewHolder holder;
46
        try {
47
            if (convertView == null) {
48
                holder = new ViewHolder();
49
 
50
                convertView = inflater.inflate(R.layout.custom_list_view_child, null);
51
                holder.childTitle = (TextView) convertView.findViewById(R.id.childTitle);
52
                holder.childIcon= (ImageView) convertView.findViewById(R.id.childIcon);
53
                convertView.setTag(holder);
54
            } else {
55
                holder = (ViewHolder) convertView.getTag();
56
            }
57
 
58
            holder.childTitle.setText(childConfig);
59
           /* if(childConfig.equalsIgnoreCase("Amazon")){
60
                holder.childIcon.setBackgroundResource(R.drawable.amazon_store);
61
            }
62
            if(childConfig.equalsIgnoreCase("Flipkart")){
63
                holder.childIcon.setBackgroundResource(R.drawable.flipkart_store);
64
            }
65
            if(childConfig.equalsIgnoreCase("Paytm")){
66
                holder.childIcon.setBackgroundResource(R.drawable.paytm);
67
            }
68
            if(childConfig.equalsIgnoreCase("Saholic")){
69
                holder.childIcon.setBackgroundResource(R.drawable.saholic_store);
70
            }
71
            if(childConfig.equalsIgnoreCase("Snapdeal")){
72
                holder.childIcon.setBackgroundResource(R.drawable.snapdeal_store);
73
            }
74
            if(childConfig.equalsIgnoreCase("Shopclues")){
75
                holder.childIcon.setBackgroundResource(R.drawable.shopclues_store);
76
            }
77
*/
78
            if(childConfig.equalsIgnoreCase("Amazon")){
79
                holder.childIcon.setBackgroundResource(R.drawable.amazon_store);
80
            }
81
            else if(childConfig.equalsIgnoreCase("Flipkart")){
82
                holder.childIcon.setBackgroundResource(R.drawable.flipkart_store);
83
            }
84
            else if(childConfig.equalsIgnoreCase("HomeShop18")){
85
                holder.childIcon.setBackgroundResource(R.drawable.homeshop18);
86
            }
87
            else if(childConfig.equalsIgnoreCase("Paytm")){
88
                holder.childIcon.setBackgroundResource(R.drawable.paytm);
89
            }
90
            else if(childConfig.equalsIgnoreCase("Saholic")){
91
                holder.childIcon.setBackgroundResource(R.drawable.saholic_store);
92
            }
93
            else if(childConfig.equalsIgnoreCase("Snapdeal")){
94
                holder.childIcon.setBackgroundResource(R.drawable.snapdeal_store);
95
            }
96
            else if(childConfig.equalsIgnoreCase("Shopclues")){
97
                holder.childIcon.setBackgroundResource(R.drawable.shopclues_store);
98
            }
99
            else if(childConfig.equalsIgnoreCase("Contact Us")){
100
                holder.childIcon.setBackgroundResource(R.drawable.conatct_us);
101
            }
102
            else if(childConfig.equalsIgnoreCase("How It Works")){
103
                holder.childIcon.setBackgroundResource(R.drawable.how_it_works);
104
            }
105
            else if(childConfig.equalsIgnoreCase("Questions?")){
106
                holder.childIcon.setBackgroundResource(R.drawable.about_us);
107
            }
108
        } catch (Exception e) {
109
        }
110
        return convertView;
111
    }
112
 
113
    @Override
114
    public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
115
 
116
        ExpandableNavigationItem parentSampleTo = parentRecord.get(groupPosition);
117
 
118
        ViewHolder holder;
119
        try {
120
            if (convertView == null) {
121
                convertView = inflater.inflate(R.layout.custom_list_view, null);
122
                holder = new ViewHolder();
123
 
124
                holder.parentTitle = (TextView) convertView.findViewById(R.id.parentTitle);
125
                //holder.parentIcon = (ImageView) convertView.findViewById(R.id.parentIcon);
126
                convertView.setTag(holder);
127
            } else {
128
                holder = (ViewHolder) convertView.getTag();
129
            }
130
 
131
            holder.parentTitle.setText(parentSampleTo.getTitle());
132
            //holder.parentIcon.setBackgroundResource(parentSampleTo.getIcon());
133
            ImageView iconExpand = (ImageView) convertView.findViewById(R.id.icon_expand);
134
            ImageView iconCollapse = (ImageView) convertView.findViewById(R.id.icon_collapse);
135
 
136
            if (isExpanded) {
137
                iconExpand.setVisibility(View.GONE);
138
                iconCollapse.setVisibility(View.VISIBLE);
139
            } else {
140
                iconExpand.setVisibility(View.VISIBLE);
141
                iconCollapse.setVisibility(View.GONE);
142
            }
143
 
144
            if (getChildrenCount(groupPosition) == 0) {
145
                iconExpand.setVisibility(View.GONE);
146
                iconCollapse.setVisibility(View.GONE);
147
            }
148
        } catch (Exception e) {
149
        }
150
        return convertView;
151
    }
152
 
153
    public static class ViewHolder {
154
 
155
        private TextView childTitle;
156
        private TextView parentTitle;
157
        //private ImageView parentIcon;
158
        private ImageView childIcon;
159
 
160
    }
161
 
162
    @Override
163
    public int getChildrenCount(int groupPosition) {
164
        return this.childRecord.get(getGroup(groupPosition).getTitle()).size();
165
    }
166
 
167
    @Override
168
    public ExpandableNavigationItem getGroup(int groupPosition) {
169
        return this.parentRecord.get(groupPosition);
170
    }
171
 
172
    @Override
173
    public int getGroupCount() {
174
        return this.parentRecord.size();
175
    }
176
 
177
    @Override
178
    public long getGroupId(int groupPosition) {
179
        return groupPosition;
180
    }
181
 
182
    @Override
183
    public boolean hasStableIds() {
184
        return false;
185
    }
186
 
187
    @Override
188
    public boolean isChildSelectable(int groupPosition, int childPosition) {
189
        return true;
190
    }
191
}