1 |
e108b57e
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
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 |
1f9772f3
|
Leszek Koltunski
|
package org.distorted.dialogs;
|
21 |
e108b57e
|
Leszek Koltunski
|
|
22 |
66e777b0
|
Leszek Koltunski
|
import androidx.annotation.NonNull;
|
23 |
|
|
import androidx.fragment.app.FragmentActivity;
|
24 |
|
|
import androidx.viewpager.widget.PagerAdapter;
|
25 |
|
|
import androidx.viewpager.widget.ViewPager;
|
26 |
e108b57e
|
Leszek Koltunski
|
import android.view.View;
|
27 |
|
|
import android.view.ViewGroup;
|
28 |
|
|
|
29 |
|
|
import org.distorted.patterns.RubikPattern;
|
30 |
b498f3f6
|
Leszek Koltunski
|
import org.distorted.patterns.RubikPatternList;
|
31 |
e108b57e
|
Leszek Koltunski
|
|
32 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
33 |
|
|
|
34 |
|
|
class RubikDialogPatternPagerAdapter extends PagerAdapter
|
35 |
|
|
{
|
36 |
3f7a4363
|
Leszek Koltunski
|
private final FragmentActivity mAct;
|
37 |
|
|
private final RubikDialogPatternView[] mViews;
|
38 |
|
|
private final RubikDialogPattern mDialog;
|
39 |
|
|
private final int mNumTabs;
|
40 |
e108b57e
|
Leszek Koltunski
|
|
41 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
42 |
|
|
|
43 |
|
|
RubikDialogPatternPagerAdapter(FragmentActivity act, ViewPager viewPager, RubikDialogPattern dialog)
|
44 |
|
|
{
|
45 |
|
|
mAct = act;
|
46 |
|
|
mDialog = dialog;
|
47 |
b498f3f6
|
Leszek Koltunski
|
mNumTabs = RubikPatternList.NUM_OBJECTS;
|
48 |
e108b57e
|
Leszek Koltunski
|
mViews = new RubikDialogPatternView[mNumTabs];
|
49 |
|
|
|
50 |
|
|
viewPager.setAdapter(this);
|
51 |
|
|
viewPager.setOffscreenPageLimit(mNumTabs-1);
|
52 |
|
|
}
|
53 |
|
|
|
54 |
044529c1
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
55 |
|
|
|
56 |
c715128d
|
Leszek Koltunski
|
void rememberState()
|
57 |
044529c1
|
Leszek Koltunski
|
{
|
58 |
|
|
RubikPattern pattern = RubikPattern.getInstance();
|
59 |
|
|
|
60 |
|
|
for(int i=0; i<mNumTabs; i++)
|
61 |
|
|
{
|
62 |
|
|
int cat = mViews[i].getCurrentCategory();
|
63 |
054fbee1
|
Leszek Koltunski
|
int pos = mViews[i].getCurrentVisiblePos();
|
64 |
|
|
int exp = mViews[i].getExpanded();
|
65 |
|
|
pattern.rememberState(i,cat,pos,exp);
|
66 |
044529c1
|
Leszek Koltunski
|
}
|
67 |
|
|
}
|
68 |
|
|
|
69 |
e108b57e
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
70 |
|
|
|
71 |
|
|
@Override
|
72 |
|
|
@NonNull
|
73 |
|
|
public Object instantiateItem(@NonNull ViewGroup collection, final int position)
|
74 |
|
|
{
|
75 |
3a9d19ed
|
Leszek Koltunski
|
mViews[position] = new RubikDialogPatternView(mAct, mDialog, position);
|
76 |
e108b57e
|
Leszek Koltunski
|
collection.addView(mViews[position]);
|
77 |
|
|
|
78 |
|
|
return mViews[position];
|
79 |
|
|
}
|
80 |
|
|
|
81 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
82 |
|
|
|
83 |
|
|
@Override
|
84 |
|
|
public void destroyItem(ViewGroup collection, int position, @NonNull Object view)
|
85 |
|
|
{
|
86 |
|
|
collection.removeView((View) view);
|
87 |
|
|
}
|
88 |
|
|
|
89 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
90 |
|
|
|
91 |
|
|
@Override
|
92 |
|
|
public int getCount()
|
93 |
|
|
{
|
94 |
|
|
return mNumTabs;
|
95 |
|
|
}
|
96 |
|
|
|
97 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
98 |
|
|
|
99 |
|
|
@Override
|
100 |
|
|
public boolean isViewFromObject(@NonNull View view, @NonNull Object object)
|
101 |
|
|
{
|
102 |
|
|
return view == object;
|
103 |
|
|
}
|
104 |
|
|
}
|