Project

General

Profile

Download (5.29 KB) Statistics
| Branch: | Tag: | Revision:

magiccube / src / main / java / org / distorted / dialogs / RubikDialogPatternListAdapter.java @ 05c044a5

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2020 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6
// Magic Cube is proprietary software licensed under an EULA which you should have received      //
7
// along with the code. If not, check https://distorted.org/magic/License-Magic-Cube.html        //
8
///////////////////////////////////////////////////////////////////////////////////////////////////
9

    
10
package org.distorted.dialogs;
11

    
12
import android.content.Context;
13
import android.util.TypedValue;
14
import android.view.LayoutInflater;
15
import android.view.View;
16
import android.view.ViewGroup;
17
import android.widget.BaseExpandableListAdapter;
18
import android.widget.TextView;
19

    
20
import org.distorted.main.RubikActivity;
21
import org.distorted.patterns.RubikPattern;
22
import org.distorted.main.R;
23

    
24
///////////////////////////////////////////////////////////////////////////////////////////////////
25

    
26
class RubikDialogPatternListAdapter extends BaseExpandableListAdapter
27
  {
28
  private final Context mContext;
29
  private final int mTab, mWidth;
30

    
31
///////////////////////////////////////////////////////////////////////////////////////////////////
32

    
33
  public RubikDialogPatternListAdapter(Context context, int tab, int width)
34
    {
35
    mContext = context;
36
    mTab     = tab;
37
    mWidth   = width;
38
    }
39

    
40
///////////////////////////////////////////////////////////////////////////////////////////////////
41

    
42
  @Override
43
  public Object getChild(int groupPosition, int childPosition)
44
    {
45
    RubikPattern pattern = RubikPattern.getInstance();
46
    return pattern.getPatternName(mTab,groupPosition,childPosition);
47
    }
48

    
49
///////////////////////////////////////////////////////////////////////////////////////////////////
50

    
51
  @Override
52
  public long getChildId(int groupPosition, int childPosition)
53
    {
54
    return childPosition;
55
    }
56

    
57
///////////////////////////////////////////////////////////////////////////////////////////////////
58

    
59
  @Override
60
  public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View view, ViewGroup parent)
61
    {
62
    String childName = (String) getChild(groupPosition, childPosition);
63

    
64
    if (view == null)
65
      {
66
      LayoutInflater infalInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
67
      view = infalInflater.inflate(R.layout.dialog_pattern_child_item, null);
68
      }
69

    
70
    int size = (int)(mWidth* RubikActivity.PATTERN_CHILD_TEXT);
71

    
72
    TextView childItem = view.findViewById(R.id.child);
73
    childItem.setText(childName);
74
    childItem.setTextSize(TypedValue.COMPLEX_UNIT_PX, size);
75

    
76
    return view;
77
    }
78

    
79
///////////////////////////////////////////////////////////////////////////////////////////////////
80

    
81
  @Override
82
  public int getChildrenCount(int groupPosition)
83
    {
84
    RubikPattern pattern = RubikPattern.getInstance();
85
    return pattern.getNumPatterns(mTab,groupPosition);
86
    }
87

    
88
///////////////////////////////////////////////////////////////////////////////////////////////////
89

    
90
  @Override
91
  public Object getGroup(int groupPosition)
92
    {
93
    RubikPattern pattern = RubikPattern.getInstance();
94
    return pattern.getCategoryName(mTab,groupPosition);
95
    }
96

    
97
///////////////////////////////////////////////////////////////////////////////////////////////////
98

    
99
  @Override
100
  public int getGroupCount()
101
    {
102
    RubikPattern pattern = RubikPattern.getInstance();
103
    return pattern.getNumCategories(mTab);
104
    }
105

    
106
///////////////////////////////////////////////////////////////////////////////////////////////////
107

    
108
  @Override
109
  public long getGroupId(int groupPosition)
110
    {
111
    return groupPosition;
112
    }
113

    
114
///////////////////////////////////////////////////////////////////////////////////////////////////
115

    
116
  @Override
117
  public View getGroupView(int groupPosition, boolean isLastChild, View view, ViewGroup parent)
118
    {
119
    String groupName = (String) getGroup(groupPosition);
120

    
121
    if (view == null)
122
      {
123
      LayoutInflater inf = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
124
      view = inf.inflate(R.layout.dialog_pattern_group_item, null);
125
      }
126

    
127
    int size = (int)(mWidth* RubikActivity.PATTERN_GROUP_TEXT);
128

    
129
    TextView heading = view.findViewById(R.id.heading);
130
    heading.setText(groupName);
131
    heading.setTextSize(TypedValue.COMPLEX_UNIT_PX, size);
132

    
133
    RubikPattern pattern = RubikPattern.getInstance();
134
    int numPatterns = pattern.getNumPatterns(mTab,groupPosition);
135
    TextView counter = view.findViewById(R.id.counter);
136
    counter.setText(String.format("%d", numPatterns));
137
    counter.setTextSize(TypedValue.COMPLEX_UNIT_PX, size);
138

    
139
    return view;
140
    }
141

    
142
///////////////////////////////////////////////////////////////////////////////////////////////////
143

    
144
  @Override
145
  public boolean hasStableIds()
146
    {
147
    return true;
148
    }
149

    
150
///////////////////////////////////////////////////////////////////////////////////////////////////
151

    
152
  @Override
153
  public boolean isChildSelectable(int groupPosition, int childPosition)
154
    {
155
    return true;
156
    }
157
  }
(9-9/23)