1 |
234a7582
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2 |
|
|
// Copyright 2020 Leszek Koltunski //
|
3 |
|
|
// //
|
4 |
|
|
// This file is part of Magic Cube. //
|
5 |
|
|
// //
|
6 |
68191e7d
|
Leszek Koltunski
|
// 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 |
234a7582
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
9 |
|
|
|
10 |
|
|
package org.distorted.dialogs;
|
11 |
|
|
|
12 |
|
|
import android.content.Context;
|
13 |
b91d4033
|
Leszek Koltunski
|
import android.content.res.Resources;
|
14 |
992748ab
|
Leszek Koltunski
|
import android.os.Bundle;
|
15 |
234a7582
|
Leszek Koltunski
|
import android.util.AttributeSet;
|
16 |
b91d4033
|
Leszek Koltunski
|
import android.util.TypedValue;
|
17 |
234a7582
|
Leszek Koltunski
|
import android.view.View;
|
18 |
b91d4033
|
Leszek Koltunski
|
import android.widget.Button;
|
19 |
234a7582
|
Leszek Koltunski
|
import android.widget.FrameLayout;
|
20 |
ef1f3e34
|
Leszek Koltunski
|
import android.widget.ImageView;
|
21 |
b91d4033
|
Leszek Koltunski
|
import android.widget.LinearLayout;
|
22 |
ef1f3e34
|
Leszek Koltunski
|
import android.widget.TextView;
|
23 |
234a7582
|
Leszek Koltunski
|
|
24 |
|
|
import androidx.fragment.app.FragmentActivity;
|
25 |
|
|
|
26 |
992748ab
|
Leszek Koltunski
|
import com.google.firebase.analytics.FirebaseAnalytics;
|
27 |
|
|
|
28 |
|
|
import org.distorted.main.BuildConfig;
|
29 |
234a7582
|
Leszek Koltunski
|
import org.distorted.main.R;
|
30 |
|
|
import org.distorted.main.RubikActivity;
|
31 |
804293f0
|
Leszek Koltunski
|
import org.distorted.objectlib.json.JsonReader;
|
32 |
d433b50e
|
Leszek Koltunski
|
import org.distorted.objects.RubikObject;
|
33 |
|
|
import org.distorted.objects.RubikObjectList;
|
34 |
804293f0
|
Leszek Koltunski
|
|
35 |
|
|
import java.io.InputStream;
|
36 |
234a7582
|
Leszek Koltunski
|
|
37 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
38 |
|
|
|
39 |
|
|
public class RubikDialogTutorialView extends FrameLayout
|
40 |
|
|
{
|
41 |
1db2a539
|
Leszek Koltunski
|
public static final float PANE_HEIGHT = 0.06f;
|
42 |
a84c3a25
|
Leszek Koltunski
|
private boolean mCanClick;
|
43 |
|
|
|
44 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
45 |
|
|
|
46 |
234a7582
|
Leszek Koltunski
|
public RubikDialogTutorialView(Context context, AttributeSet attrs, int defStyle)
|
47 |
|
|
{
|
48 |
|
|
super(context, attrs, defStyle);
|
49 |
|
|
}
|
50 |
|
|
|
51 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
52 |
|
|
|
53 |
|
|
public RubikDialogTutorialView(Context context, AttributeSet attrs)
|
54 |
|
|
{
|
55 |
|
|
super(context, attrs);
|
56 |
|
|
}
|
57 |
|
|
|
58 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
59 |
|
|
|
60 |
1db2a539
|
Leszek Koltunski
|
public RubikDialogTutorialView(FragmentActivity act, int height, int position)
|
61 |
234a7582
|
Leszek Koltunski
|
{
|
62 |
|
|
super(act);
|
63 |
|
|
|
64 |
314e9ff0
|
Leszek Koltunski
|
int objectOrdinal = RubikObjectList.getObjectOrdinal(position);
|
65 |
|
|
RubikObject robject = RubikObjectList.getObject(objectOrdinal);
|
66 |
|
|
InputStream jsonStream = robject==null ? null : robject.getExtrasStream(act);
|
67 |
804293f0
|
Leszek Koltunski
|
String[][] tutorials=null;
|
68 |
|
|
|
69 |
|
|
if( jsonStream!=null )
|
70 |
|
|
{
|
71 |
c020555e
|
Leszek Koltunski
|
try
|
72 |
|
|
{
|
73 |
5305fdc8
|
Leszek Koltunski
|
JsonReader reader = new JsonReader();
|
74 |
c020555e
|
Leszek Koltunski
|
reader.parseJsonTutorial(jsonStream);
|
75 |
|
|
tutorials = reader.getTutorials();
|
76 |
|
|
}
|
77 |
05c044a5
|
Leszek Koltunski
|
catch(Exception ignored) { }
|
78 |
804293f0
|
Leszek Koltunski
|
}
|
79 |
|
|
|
80 |
|
|
if( tutorials!=null )
|
81 |
|
|
{
|
82 |
|
|
clickPossible(true);
|
83 |
1db2a539
|
Leszek Koltunski
|
int size = (int)(height*PANE_HEIGHT);
|
84 |
234a7582
|
Leszek Koltunski
|
|
85 |
804293f0
|
Leszek Koltunski
|
RubikActivity ract = (RubikActivity)getContext();
|
86 |
|
|
Resources res = act.getResources();
|
87 |
|
|
String packageName = act.getPackageName();
|
88 |
b91d4033
|
Leszek Koltunski
|
|
89 |
804293f0
|
Leszek Koltunski
|
View tab = inflate( act, R.layout.dialog_tutorial_tab, null);
|
90 |
|
|
LinearLayout layout = tab.findViewById(R.id.tabLayout);
|
91 |
234a7582
|
Leszek Koltunski
|
|
92 |
804293f0
|
Leszek Koltunski
|
int colorB = getResources().getColor(R.color.light_grey);
|
93 |
|
|
int colorT = getResources().getColor(R.color.white);
|
94 |
234a7582
|
Leszek Koltunski
|
|
95 |
804293f0
|
Leszek Koltunski
|
for (String[] tutorial : tutorials)
|
96 |
|
|
{
|
97 |
|
|
String coun = tutorial[0];
|
98 |
|
|
String url = tutorial[1];
|
99 |
|
|
String desc = tutorial[2];
|
100 |
|
|
String auth = tutorial[3];
|
101 |
6bc01aa4
|
Leszek Koltunski
|
|
102 |
804293f0
|
Leszek Koltunski
|
int countryID = res.getIdentifier(coun, "drawable", packageName);
|
103 |
b91d4033
|
Leszek Koltunski
|
|
104 |
1db2a539
|
Leszek Koltunski
|
View row = createRow(ract, countryID, desc, url, auth, size, objectOrdinal, colorB, colorT);
|
105 |
804293f0
|
Leszek Koltunski
|
layout.addView(row);
|
106 |
|
|
}
|
107 |
b91d4033
|
Leszek Koltunski
|
|
108 |
804293f0
|
Leszek Koltunski
|
addView(tab);
|
109 |
b91d4033
|
Leszek Koltunski
|
}
|
110 |
234a7582
|
Leszek Koltunski
|
}
|
111 |
b91d4033
|
Leszek Koltunski
|
|
112 |
a84c3a25
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
113 |
|
|
|
114 |
|
|
void clickPossible(boolean click)
|
115 |
|
|
{
|
116 |
|
|
mCanClick = click;
|
117 |
|
|
}
|
118 |
|
|
|
119 |
b91d4033
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
120 |
|
|
|
121 |
992748ab
|
Leszek Koltunski
|
private View createRow(final RubikActivity act, int countryID, final String desc, final String url,
|
122 |
d433b50e
|
Leszek Koltunski
|
final String auth, int size, final int obj, int colorB, int colorT)
|
123 |
b91d4033
|
Leszek Koltunski
|
{
|
124 |
b6cce523
|
Leszek Koltunski
|
float textSize = 0.43f*size;
|
125 |
b91d4033
|
Leszek Koltunski
|
View row = inflate( act, R.layout.dialog_tutorial_row, null);
|
126 |
|
|
|
127 |
cb6d9c37
|
Leszek Koltunski
|
LinearLayout layout = row.findViewById(R.id.tutorialLayout);
|
128 |
|
|
layout.setMinimumHeight(size);
|
129 |
|
|
|
130 |
|
|
Button butt = row.findViewById(R.id.tutorialButton);
|
131 |
ef1f3e34
|
Leszek Koltunski
|
butt.setText(R.string.view);
|
132 |
6bc01aa4
|
Leszek Koltunski
|
butt.setTextColor(colorT);
|
133 |
|
|
butt.setBackgroundColor(colorB);
|
134 |
cb6d9c37
|
Leszek Koltunski
|
butt.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
|
135 |
|
|
butt.setHeight(size);
|
136 |
b91d4033
|
Leszek Koltunski
|
|
137 |
|
|
butt.setOnClickListener( new View.OnClickListener()
|
138 |
|
|
{
|
139 |
|
|
@Override
|
140 |
|
|
public void onClick(View v)
|
141 |
|
|
{
|
142 |
a84c3a25
|
Leszek Koltunski
|
if( mCanClick )
|
143 |
|
|
{
|
144 |
7ac0ee88
|
Leszek Koltunski
|
act.switchTutorial(url,obj);
|
145 |
|
|
analyticsReport(act,desc,auth,obj);
|
146 |
a84c3a25
|
Leszek Koltunski
|
clickPossible(false);
|
147 |
|
|
}
|
148 |
b91d4033
|
Leszek Koltunski
|
}
|
149 |
|
|
});
|
150 |
|
|
|
151 |
ef1f3e34
|
Leszek Koltunski
|
ImageView image = row.findViewById(R.id.tutorialCountry);
|
152 |
05c044a5
|
Leszek Koltunski
|
int id = countryID!=0 ? countryID : org.distorted.flags.R.drawable.unknown;
|
153 |
ef1f3e34
|
Leszek Koltunski
|
image.setImageResource(id);
|
154 |
|
|
|
155 |
|
|
TextView author = row.findViewById(R.id.tutorialAuthor);
|
156 |
cb6d9c37
|
Leszek Koltunski
|
author.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
|
157 |
ef1f3e34
|
Leszek Koltunski
|
author.setText(auth);
|
158 |
|
|
|
159 |
|
|
TextView title = row.findViewById(R.id.tutorialTitle);
|
160 |
cb6d9c37
|
Leszek Koltunski
|
title.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
|
161 |
ef1f3e34
|
Leszek Koltunski
|
title.setText(desc);
|
162 |
|
|
|
163 |
b91d4033
|
Leszek Koltunski
|
return row;
|
164 |
|
|
}
|
165 |
992748ab
|
Leszek Koltunski
|
|
166 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
167 |
|
|
|
168 |
d433b50e
|
Leszek Koltunski
|
private void analyticsReport(RubikActivity act, String desc, String author, int obj)
|
169 |
992748ab
|
Leszek Koltunski
|
{
|
170 |
|
|
String message = desc+" ("+author+")";
|
171 |
|
|
|
172 |
|
|
if( BuildConfig.DEBUG )
|
173 |
|
|
{
|
174 |
|
|
android.util.Log.d("tutorial", message);
|
175 |
|
|
}
|
176 |
|
|
else
|
177 |
|
|
{
|
178 |
|
|
FirebaseAnalytics analytics = act.getAnalytics();
|
179 |
|
|
|
180 |
|
|
if( analytics!=null )
|
181 |
|
|
{
|
182 |
d433b50e
|
Leszek Koltunski
|
RubikObject object = RubikObjectList.getObject(obj);
|
183 |
|
|
|
184 |
992748ab
|
Leszek Koltunski
|
Bundle bundle = new Bundle();
|
185 |
|
|
bundle.putString(FirebaseAnalytics.Param.CONTENT_TYPE, message);
|
186 |
84d746d7
|
Leszek Koltunski
|
bundle.putString(FirebaseAnalytics.Param.ITEM_NAME, object==null ? "NULL" : object.getLowerName() );
|
187 |
992748ab
|
Leszek Koltunski
|
analytics.logEvent(FirebaseAnalytics.Event.TUTORIAL_BEGIN, bundle);
|
188 |
|
|
}
|
189 |
|
|
}
|
190 |
|
|
}
|
191 |
234a7582
|
Leszek Koltunski
|
}
|