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.magic;
|
21
|
|
22
|
import android.support.annotation.NonNull;
|
23
|
import android.support.v4.app.FragmentActivity;
|
24
|
import android.support.v4.view.PagerAdapter;
|
25
|
import android.support.v4.view.ViewPager;
|
26
|
import android.view.View;
|
27
|
import android.view.ViewGroup;
|
28
|
|
29
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
30
|
|
31
|
class RubikScoresViewPager extends PagerAdapter implements RubikScoresDownloader.Receiver
|
32
|
{
|
33
|
private FragmentActivity mAct;
|
34
|
private RubikScoresView[] mViews;
|
35
|
|
36
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
37
|
|
38
|
RubikScoresViewPager(FragmentActivity act, ViewPager viewPager)
|
39
|
{
|
40
|
mAct = act;
|
41
|
mViews = new RubikScoresView[getCount()];
|
42
|
viewPager.setAdapter(this);
|
43
|
viewPager.setOffscreenPageLimit( RubikSize.LENGTH-1 );
|
44
|
}
|
45
|
|
46
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
47
|
|
48
|
public void receive(final String[][][][] scores)
|
49
|
{
|
50
|
mAct.runOnUiThread(new Runnable()
|
51
|
{
|
52
|
@Override
|
53
|
public void run()
|
54
|
{
|
55
|
for(int i=0; i<RubikSize.LENGTH; i++)
|
56
|
{
|
57
|
mViews[i].prepareView(mAct,scores[i]);
|
58
|
}
|
59
|
}
|
60
|
});
|
61
|
}
|
62
|
|
63
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
64
|
|
65
|
@Override
|
66
|
@NonNull
|
67
|
public Object instantiateItem(@NonNull ViewGroup collection, int position)
|
68
|
{
|
69
|
mViews[position] = new RubikScoresView(mAct,position);
|
70
|
collection.addView(mViews[position]);
|
71
|
|
72
|
boolean allCreated = true;
|
73
|
|
74
|
for(int i=0; i<RubikSize.LENGTH; i++)
|
75
|
{
|
76
|
if( mViews[i]==null )
|
77
|
{
|
78
|
allCreated = false;
|
79
|
break;
|
80
|
}
|
81
|
}
|
82
|
|
83
|
if( allCreated )
|
84
|
{
|
85
|
RubikScoresDownloader downloader = new RubikScoresDownloader();
|
86
|
downloader.download(this);
|
87
|
}
|
88
|
|
89
|
return mViews[position];
|
90
|
}
|
91
|
|
92
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
93
|
|
94
|
@Override
|
95
|
public void destroyItem(ViewGroup collection, int position, @NonNull Object view)
|
96
|
{
|
97
|
collection.removeView((View) view);
|
98
|
}
|
99
|
|
100
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
101
|
|
102
|
@Override
|
103
|
public int getCount()
|
104
|
{
|
105
|
return RubikSize.LENGTH;
|
106
|
}
|
107
|
|
108
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
109
|
|
110
|
@Override
|
111
|
public boolean isViewFromObject(@NonNull View view, @NonNull Object object)
|
112
|
{
|
113
|
return view == object;
|
114
|
}
|
115
|
}
|