1
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2
|
// Copyright 2023 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
|
|
11
|
package org.distorted.dialogs;
|
12
|
|
13
|
import android.content.Context;
|
14
|
import android.util.TypedValue;
|
15
|
import android.view.LayoutInflater;
|
16
|
import android.view.View;
|
17
|
import android.view.ViewGroup;
|
18
|
import android.widget.BaseExpandableListAdapter;
|
19
|
import android.widget.TextView;
|
20
|
import org.distorted.objectlib.patterns.RubikPattern;
|
21
|
import org.distorted.main.R;
|
22
|
|
23
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
24
|
|
25
|
class RubikDialogPatternListAdapter extends BaseExpandableListAdapter
|
26
|
{
|
27
|
private static final float PATTERN_CHILD_TEXT = 0.038f;
|
28
|
private static final float PATTERN_GROUP_TEXT = 0.060f;
|
29
|
private final Context mContext;
|
30
|
private final int mTab, mWidth;
|
31
|
|
32
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
33
|
|
34
|
public RubikDialogPatternListAdapter(Context context, int tab, int width)
|
35
|
{
|
36
|
mContext = context;
|
37
|
mTab = tab;
|
38
|
mWidth = width;
|
39
|
}
|
40
|
|
41
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
42
|
|
43
|
@Override
|
44
|
public Object getChild(int groupPosition, int childPosition)
|
45
|
{
|
46
|
RubikPattern pattern = RubikPattern.getInstance();
|
47
|
return pattern.getPatternName(mTab,groupPosition,childPosition);
|
48
|
}
|
49
|
|
50
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
51
|
|
52
|
@Override
|
53
|
public long getChildId(int groupPosition, int childPosition)
|
54
|
{
|
55
|
return childPosition;
|
56
|
}
|
57
|
|
58
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
59
|
|
60
|
@Override
|
61
|
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View view, ViewGroup parent)
|
62
|
{
|
63
|
String childName = (String) getChild(groupPosition, childPosition);
|
64
|
|
65
|
if (view == null)
|
66
|
{
|
67
|
LayoutInflater infalInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
68
|
view = infalInflater.inflate(R.layout.dialog_pattern_child_item, null);
|
69
|
}
|
70
|
|
71
|
int size = (int)(mWidth*PATTERN_CHILD_TEXT);
|
72
|
TextView childItem = view.findViewById(R.id.child);
|
73
|
childItem.setText(childName);
|
74
|
childItem.setTextSize(TypedValue.COMPLEX_UNIT_PX, size);
|
75
|
return view;
|
76
|
}
|
77
|
|
78
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
79
|
|
80
|
@Override
|
81
|
public int getChildrenCount(int groupPosition)
|
82
|
{
|
83
|
RubikPattern pattern = RubikPattern.getInstance();
|
84
|
return pattern.getNumPatterns(mTab,groupPosition);
|
85
|
}
|
86
|
|
87
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
88
|
|
89
|
@Override
|
90
|
public Object getGroup(int groupPosition)
|
91
|
{
|
92
|
RubikPattern pattern = RubikPattern.getInstance();
|
93
|
return pattern.getCategoryName(mTab,groupPosition);
|
94
|
}
|
95
|
|
96
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
97
|
|
98
|
@Override
|
99
|
public int getGroupCount()
|
100
|
{
|
101
|
RubikPattern pattern = RubikPattern.getInstance();
|
102
|
return pattern.getNumCategories(mTab);
|
103
|
}
|
104
|
|
105
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
106
|
|
107
|
@Override
|
108
|
public long getGroupId(int groupPosition)
|
109
|
{
|
110
|
return groupPosition;
|
111
|
}
|
112
|
|
113
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
114
|
|
115
|
@Override
|
116
|
public View getGroupView(int groupPosition, boolean isLastChild, View view, ViewGroup parent)
|
117
|
{
|
118
|
String groupName = (String) getGroup(groupPosition);
|
119
|
|
120
|
if (view == null)
|
121
|
{
|
122
|
LayoutInflater inf = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
123
|
view = inf.inflate(R.layout.dialog_pattern_group_item, null);
|
124
|
}
|
125
|
|
126
|
int size = (int)(mWidth*PATTERN_GROUP_TEXT);
|
127
|
TextView heading = view.findViewById(R.id.heading);
|
128
|
heading.setText(groupName);
|
129
|
heading.setTextSize(TypedValue.COMPLEX_UNIT_PX, size);
|
130
|
RubikPattern pattern = RubikPattern.getInstance();
|
131
|
int numPatterns = pattern.getNumPatterns(mTab,groupPosition);
|
132
|
TextView counter = view.findViewById(R.id.counter);
|
133
|
counter.setText(String.format("%d", numPatterns));
|
134
|
counter.setTextSize(TypedValue.COMPLEX_UNIT_PX, size);
|
135
|
return view;
|
136
|
}
|
137
|
|
138
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
139
|
|
140
|
@Override
|
141
|
public boolean hasStableIds()
|
142
|
{
|
143
|
return true;
|
144
|
}
|
145
|
|
146
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
147
|
|
148
|
@Override
|
149
|
public boolean isChildSelectable(int groupPosition, int childPosition)
|
150
|
{
|
151
|
return true;
|
152
|
}
|
153
|
}
|