33import android .app .Activity ;
44import android .content .Intent ;
55import android .os .Bundle ;
6+ import android .util .Log ;
7+ import android .util .Pair ;
68import android .view .View ;
79import android .view .ViewTreeObserver ;
810import android .view .Window ;
911import android .widget .Button ;
12+ import android .widget .ExpandableListView ;
1013import android .widget .ListView ;
11- import android .widget .TextView ;
14+ import android .widget .SimpleExpandableListAdapter ;
1215
1316import com .blogspot .e_kanivets .moneytracker .R ;
1417import com .blogspot .e_kanivets .moneytracker .adapter .ReportItemAdapter ;
1518import com .blogspot .e_kanivets .moneytracker .helper .MTHelper ;
19+ import com .blogspot .e_kanivets .moneytracker .model .Record ;
1620import com .blogspot .e_kanivets .moneytracker .model .Report ;
1721
22+ import java .util .ArrayList ;
23+ import java .util .HashMap ;
24+ import java .util .List ;
25+ import java .util .Map ;
26+
1827/**
1928 * Created by eugene on 11/09/14.
2029 */
2130public class ReportActivity extends Activity {
2231
32+ private static final String TAG = ReportActivity .class .getSimpleName ();
33+ private static final String TITLE_PARAM_NAME = "title" ;
34+
2335 private Activity activity ;
36+ private Report report ;
2437
2538 private ListView listView ;
39+ private ExpandableListView expandableListView ;
2640
2741 @ Override
2842 protected void onCreate (Bundle savedInstanceState ) {
@@ -31,16 +45,19 @@ protected void onCreate(Bundle savedInstanceState) {
3145 setContentView (R .layout .activity_report );
3246
3347 activity = this ;
48+ report = new Report (MTHelper .getInstance ().getRecords ());
3449
35- Button btnThankAuthor ;
50+ initViews ();
51+ }
3652
37- btnThankAuthor = ( Button ) findViewById ( R . id . btn_thank_author );
53+ private void initViews () {
3854 listView = (ListView ) findViewById (R .id .listView );
55+ expandableListView = (ExpandableListView ) findViewById (R .id .expandableListView );
3956
4057 /*tvTitle.setText("REPORT (" + MTHelper.getInstance().getFirstDay() + " - "
4158 + MTHelper.getInstance().getLastDay() + ")");*/
4259
43- btnThankAuthor .setOnClickListener (new View .OnClickListener () {
60+ findViewById ( R . id . btn_thank_author ) .setOnClickListener (new View .OnClickListener () {
4461 @ Override
4562 public void onClick (View view ) {
4663 Intent intent = new Intent (ReportActivity .this , ThankAuthorActivity .class );
@@ -57,11 +74,77 @@ public void onClick(View view) {
5774
5875 @ Override
5976 public void onGlobalLayout () {
60- if (isFirst ) {
77+ if (isFirst ) {
6178 isFirst = false ;
62- listView .setSelection (listView .getCount ()- 1 );
79+ listView .setSelection (listView .getCount () - 1 );
6380 }
6481 }
6582 });
83+
84+ initExpandableListView ();
85+ }
86+
87+ private void initExpandableListView () {
88+ /* List for groups */
89+ List <Map <String , String >> groupData ;
90+
91+ /* List for child items */
92+ List <Map <String , String >> childDataItem ;
93+
94+ /* List for childDataItems */
95+ List <List <Map <String , String >>> childData ;
96+
97+ /* Buffer map for names of values */
98+ Map <String , String > m ;
99+
100+ /* Fill the group list */
101+ groupData = new ArrayList <Map <String , String >>();
102+ for (Pair <String , Integer > item : report .getReportList ()) {
103+ /* Fill up attribute names for each group */
104+ m = new HashMap <String , String >();
105+ m .put (TITLE_PARAM_NAME , item .first );
106+
107+ groupData .add (m );
108+ }
109+
110+ /* List of attributes of groups for reading */
111+ String groupFrom [] = new String []{TITLE_PARAM_NAME };
112+ /* List of view IDs for information insertion */
113+ int groupTo [] = new int []{android .R .id .text1 };
114+
115+ /* Create list for childDataItems */
116+ childData = new ArrayList <List <Map <String , String >>>();
117+
118+ for (Map <String , String > group : groupData ) {
119+ childDataItem = new ArrayList <Map <String , String >>();
120+ /* Fill up attribute names for each child item */
121+ for (Record record : MTHelper .getInstance ().getRecords ()) {
122+ if (record .getCategory ().equals (group .get (TITLE_PARAM_NAME ))) {
123+ Log .d (TAG , record .getCategory ());
124+ m = new HashMap <String , String >();
125+ m .put (TITLE_PARAM_NAME , record .getTitle ());
126+ childDataItem .add (m );
127+ }
128+ }
129+
130+ /* Add childDataItem to common childData */
131+ childData .add (childDataItem );
132+ }
133+
134+ /* List of attributes of childItems for reading */
135+ String childFrom [] = new String []{TITLE_PARAM_NAME };
136+ /* List of view IDs for information insertion */
137+ int childTo [] = new int []{android .R .id .text1 };
138+
139+ expandableListView .setAdapter (new SimpleExpandableListAdapter (
140+ activity ,
141+ groupData ,
142+ android .R .layout .simple_expandable_list_item_1 ,
143+ groupFrom ,
144+ groupTo ,
145+ childData ,
146+ android .R .layout .simple_list_item_1 ,
147+ childFrom ,
148+ childTo ));
66149 }
67150}
0 commit comments