Project

General

Profile

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

magiccube / src / main / java / org / distorted / dialogs / RubikDialogPatternView.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 androidx.fragment.app.FragmentActivity;
14
import android.util.AttributeSet;
15
import android.view.View;
16
import android.widget.ExpandableListView;
17
import android.widget.FrameLayout;
18

    
19
import org.distorted.objectlib.main.ObjectControl;
20

    
21
import org.distorted.main.R;
22
import org.distorted.main.RubikActivity;
23
import org.distorted.patterns.RubikPattern;
24
import org.distorted.patterns.RubikPatternList;
25
import org.distorted.screens.ScreenList;
26
import org.distorted.screens.RubikScreenPattern;
27

    
28
///////////////////////////////////////////////////////////////////////////////////////////////////
29

    
30
public class RubikDialogPatternView extends FrameLayout
31
  {
32
  private ExpandableListView mListView;
33
  private RubikDialogPatternListAdapter mListAdapter;
34
  private RubikDialogPattern mDialog;
35
  private int mTab, mPos;
36
  private int mExpandedGroup;
37

    
38
///////////////////////////////////////////////////////////////////////////////////////////////////
39

    
40
  public RubikDialogPatternView(Context context, AttributeSet attrs, int defStyle)
41
    {
42
    super(context, attrs, defStyle);
43
    }
44

    
45
///////////////////////////////////////////////////////////////////////////////////////////////////
46

    
47
  public RubikDialogPatternView(Context context, AttributeSet attrs)
48
    {
49
    super(context, attrs);
50
    }
51

    
52
///////////////////////////////////////////////////////////////////////////////////////////////////
53

    
54
  public RubikDialogPatternView(FragmentActivity act, RubikDialogPattern dialog, int position)
55
    {
56
    super(act);
57

    
58
    final RubikActivity ract = (RubikActivity)getContext();
59
    final ObjectControl control = ract.getControl();
60

    
61
    mTab = position;
62
    mDialog = dialog;
63

    
64
    RubikPattern pattern = RubikPattern.getInstance();
65
    mExpandedGroup = pattern.recallExpanded(position);
66

    
67
    View tab = inflate( act, R.layout.dialog_pattern_tab, null);
68

    
69
    mListView = tab.findViewById(R.id.patternListView);
70
    mListAdapter = new RubikDialogPatternListAdapter(act,mTab, ract.getScreenHeightInPixels());
71
    mListView.setAdapter(mListAdapter);
72

    
73
    if( mExpandedGroup>=0 )
74
      {
75
      mListView.expandGroup(mExpandedGroup);
76
      }
77

    
78
    int visible = pattern.recallVisiblePos(mTab);
79
    mListView.setSelectionFromTop(visible,0);
80

    
81
    mListView.setOnChildClickListener(new ExpandableListView.OnChildClickListener()
82
      {
83
      @Override
84
      public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id)
85
        {
86
        RubikPattern pattern = RubikPattern.getInstance();
87
        int[][] moves   = pattern.reInitialize(mTab, groupPosition, childPosition);
88
        int object = RubikPatternList.getObject(mTab);
89
        ract.changeIfDifferent(object,control);
90
        control.initializeObject(moves);
91

    
92
        ScreenList.switchScreen(ract, ScreenList.PATT);
93
        RubikScreenPattern state = (RubikScreenPattern) ScreenList.PATT.getScreenClass();
94
        state.setPattern(ract, mTab, groupPosition, childPosition);
95

    
96
        mDialog.rememberState();
97
        mDialog.dismiss();
98

    
99
        return false;
100
        }
101
      });
102

    
103
    mListView.setOnGroupExpandListener(new ExpandableListView.OnGroupExpandListener()
104
      {
105
      @Override
106
      public void onGroupExpand(int groupPosition)
107
        {
108
        if(mExpandedGroup!=-1 && groupPosition!=mExpandedGroup)
109
          {
110
          mListView.collapseGroup(mExpandedGroup);
111
          }
112

    
113
        mExpandedGroup = groupPosition;
114
        }
115
      });
116

    
117
    addView(tab);
118
    }
119

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

    
122
  int getCurrentCategory()
123
    {
124
    return mPos;
125
    }
126

    
127
///////////////////////////////////////////////////////////////////////////////////////////////////
128

    
129
  int getCurrentVisiblePos()
130
    {
131
    return mListView.getFirstVisiblePosition();
132
    }
133

    
134
///////////////////////////////////////////////////////////////////////////////////////////////////
135

    
136
  int getExpanded()
137
    {
138
    return mExpandedGroup;
139
    }
140
  }
(11-11/23)