Project

General

Profile

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

magiccube / src / main / java / org / distorted / dialogs / RubikDialogPatternListAdapter.java @ 4debbf44

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2020 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6
// Magic Cube is free software: you can redistribute it and/or modify                            //
7
// it under the terms of the GNU General Public License as published by                          //
8
// the Free Software Foundation, either version 2 of the License, or                             //
9
// (at your option) any later version.                                                           //
10
//                                                                                               //
11
// Magic Cube is distributed in the hope that it will be useful,                                 //
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                 //
14
// GNU General Public License for more details.                                                  //
15
//                                                                                               //
16
// You should have received a copy of the GNU General Public License                             //
17
// along with Magic Cube.  If not, see <http://www.gnu.org/licenses/>.                           //
18
///////////////////////////////////////////////////////////////////////////////////////////////////
19

    
20
package org.distorted.dialogs;
21

    
22
import android.content.Context;
23
import android.view.LayoutInflater;
24
import android.view.View;
25
import android.view.ViewGroup;
26
import android.widget.BaseExpandableListAdapter;
27
import android.widget.TextView;
28

    
29
import org.distorted.patterns.RubikPattern;
30
import org.distorted.main.R;
31

    
32
///////////////////////////////////////////////////////////////////////////////////////////////////
33

    
34
class RubikDialogPatternListAdapter extends BaseExpandableListAdapter
35
  {
36
  private Context mContext;
37
  private int mTab;
38

    
39
///////////////////////////////////////////////////////////////////////////////////////////////////
40

    
41
  public RubikDialogPatternListAdapter(Context context, int tab)
42
    {
43
    mContext = context;
44
    mTab     = tab;
45
    }
46

    
47
///////////////////////////////////////////////////////////////////////////////////////////////////
48

    
49
  @Override
50
  public Object getChild(int groupPosition, int childPosition)
51
    {
52
    RubikPattern pattern = RubikPattern.getInstance();
53
    return pattern.getPatternName(mTab,groupPosition,childPosition);
54
    }
55

    
56
///////////////////////////////////////////////////////////////////////////////////////////////////
57

    
58
  @Override
59
  public long getChildId(int groupPosition, int childPosition)
60
    {
61
    return childPosition;
62
    }
63

    
64
///////////////////////////////////////////////////////////////////////////////////////////////////
65

    
66
  @Override
67
  public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View view, ViewGroup parent)
68
    {
69
    String childName = (String) getChild(groupPosition, childPosition);
70

    
71
    if (view == null)
72
      {
73
      LayoutInflater infalInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
74
      view = infalInflater.inflate(R.layout.dialog_pattern_child_item, null);
75
      }
76

    
77
    TextView sequence = view.findViewById(R.id.sequence);
78
    sequence.setText(mContext.getString(R.string.sq_placeholder,childPosition+1));
79
    TextView childItem = view.findViewById(R.id.childItem);
80
    childItem.setText(childName);
81

    
82
    return view;
83
    }
84

    
85
///////////////////////////////////////////////////////////////////////////////////////////////////
86

    
87
  @Override
88
  public int getChildrenCount(int groupPosition)
89
    {
90
    RubikPattern pattern = RubikPattern.getInstance();
91
    return pattern.getNumPatterns(mTab,groupPosition);
92
    }
93

    
94
///////////////////////////////////////////////////////////////////////////////////////////////////
95

    
96
  @Override
97
  public Object getGroup(int groupPosition)
98
    {
99
    RubikPattern pattern = RubikPattern.getInstance();
100
    return pattern.getCategoryName(mTab,groupPosition);
101
    }
102

    
103
///////////////////////////////////////////////////////////////////////////////////////////////////
104

    
105
  @Override
106
  public int getGroupCount()
107
    {
108
    RubikPattern pattern = RubikPattern.getInstance();
109
    return pattern.getNumCategories(mTab);
110
    }
111

    
112
///////////////////////////////////////////////////////////////////////////////////////////////////
113

    
114
  @Override
115
  public long getGroupId(int groupPosition)
116
    {
117
    return groupPosition;
118
    }
119

    
120
///////////////////////////////////////////////////////////////////////////////////////////////////
121

    
122
  @Override
123
  public View getGroupView(int groupPosition, boolean isLastChild, View view, ViewGroup parent)
124
    {
125
    String groupName = (String) getGroup(groupPosition);
126

    
127
    if (view == null)
128
      {
129
      LayoutInflater inf = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
130
      view = inf.inflate(R.layout.dialog_pattern_group_item, null);
131
      }
132

    
133
    TextView heading = view.findViewById(R.id.heading);
134
    heading.setText(groupName);
135

    
136
    return view;
137
    }
138

    
139
///////////////////////////////////////////////////////////////////////////////////////////////////
140

    
141
  @Override
142
  public boolean hasStableIds()
143
    {
144
    return true;
145
    }
146

    
147
///////////////////////////////////////////////////////////////////////////////////////////////////
148

    
149
  @Override
150
  public boolean isChildSelectable(int groupPosition, int childPosition)
151
    {
152
    return true;
153
    }
154
  }
(6-6/14)