Project

General

Profile

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

magiccube / src / main / java / org / distorted / dialogs / RubikDialogTutorialView.java @ 3f7a4363

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.content.res.Resources;
24
import android.os.Bundle;
25
import android.util.AttributeSet;
26
import android.util.TypedValue;
27
import android.view.View;
28
import android.widget.Button;
29
import android.widget.FrameLayout;
30
import android.widget.ImageView;
31
import android.widget.LinearLayout;
32
import android.widget.TextView;
33

    
34
import androidx.fragment.app.FragmentActivity;
35

    
36
import com.google.firebase.analytics.FirebaseAnalytics;
37

    
38
import org.distorted.objectlib.main.ObjectList;
39

    
40
import org.distorted.main.BuildConfig;
41
import org.distorted.main.R;
42
import org.distorted.main.RubikActivity;
43
import org.distorted.tutorials.TutorialList;
44

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

    
47
public class RubikDialogTutorialView extends FrameLayout
48
  {
49
  private boolean mCanClick;
50

    
51
///////////////////////////////////////////////////////////////////////////////////////////////////
52

    
53
  public RubikDialogTutorialView(Context context, AttributeSet attrs, int defStyle)
54
    {
55
    super(context, attrs, defStyle);
56
    }
57

    
58
///////////////////////////////////////////////////////////////////////////////////////////////////
59

    
60
  public RubikDialogTutorialView(Context context, AttributeSet attrs)
61
    {
62
    super(context, attrs);
63
    }
64

    
65
///////////////////////////////////////////////////////////////////////////////////////////////////
66

    
67
  public RubikDialogTutorialView(FragmentActivity act, int width, int position)
68
    {
69
    super(act);
70

    
71
    clickPossible(true);
72
    int widthT = (int)(width* RubikActivity.TUTORIAL_ITEM_TEXT);
73

    
74
    RubikActivity ract = (RubikActivity)getContext();
75
    Resources res = act.getResources();
76
    String packageName = act.getPackageName();
77

    
78
    TutorialList list  = TutorialList.getObject(position);
79
    ObjectList objList = list.getObjectList();
80
    int size           = list.getSize();
81

    
82
    View tab = inflate( act, R.layout.dialog_tutorial_tab, null);
83
    LinearLayout layout = tab.findViewById(R.id.tabLayout);
84

    
85
    int numTutorials = list.getNumTutorials();
86

    
87
    for(int i=0; i<numTutorials; i++)
88
      {
89
      String coun = list.getTutorialLanguage(i);
90
      String desc = list.getTutorialDescription(i);
91
      String url  = list.getTutorialURL(i);
92
      String auth = list.getTutorialAuthor(i);
93

    
94
      int countryID = res.getIdentifier( coun, "drawable", packageName);
95

    
96
      View row = createRow(ract,countryID,desc,url,auth,widthT,objList,size);
97
      layout.addView(row);
98
      }
99

    
100
    addView(tab);
101
    }
102

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

    
105
  void clickPossible(boolean click)
106
    {
107
    mCanClick = click;
108
    }
109

    
110
///////////////////////////////////////////////////////////////////////////////////////////////////
111

    
112
  private View createRow(final RubikActivity act, int countryID, final String desc, final String url,
113
                         final String auth, int width, final ObjectList obj, final int size)
114
    {
115
    View row = inflate( act, R.layout.dialog_tutorial_row, null);
116
    Button butt = row.findViewById(R.id.tutorialButton);
117

    
118
    butt.setText(R.string.view);
119
    butt.setTextSize(TypedValue.COMPLEX_UNIT_PX, 0.5f*width);
120
    butt.setHeight(width);
121

    
122
    butt.setOnClickListener( new View.OnClickListener()
123
      {
124
      @Override
125
      public void onClick(View v)
126
        {
127
        if( mCanClick )
128
          {
129
          act.switchTutorial(url,obj,size);
130
          analyticsReport(act,desc,auth,obj,size);
131
          clickPossible(false);
132
          }
133
        }
134
      });
135

    
136
    ImageView image = row.findViewById(R.id.tutorialCountry);
137
    int id = countryID!=0 ? countryID : R.drawable.un;
138
    image.setImageResource(id);
139

    
140
    TextView author = row.findViewById(R.id.tutorialAuthor);
141
    author.setTextSize(TypedValue.COMPLEX_UNIT_PX, 0.5f*width);
142
    author.setText(auth);
143

    
144
    TextView title  = row.findViewById(R.id.tutorialTitle);
145
    title.setTextSize(TypedValue.COMPLEX_UNIT_PX, 0.5f*width);
146
    title.setText(desc);
147

    
148
    return row;
149
    }
150

    
151
///////////////////////////////////////////////////////////////////////////////////////////////////
152

    
153
  private void analyticsReport(RubikActivity act, String desc, String author, ObjectList obj, int size)
154
    {
155
    String message = desc+" ("+author+")";
156

    
157
    if( BuildConfig.DEBUG )
158
       {
159
       android.util.Log.d("tutorial", message);
160
       }
161
    else
162
      {
163
      FirebaseAnalytics analytics = act.getAnalytics();
164
      String name = obj.name()+"_"+size;
165

    
166
      if( analytics!=null )
167
        {
168
        Bundle bundle = new Bundle();
169
        bundle.putString(FirebaseAnalytics.Param.CONTENT_TYPE, message);
170
        bundle.putString(FirebaseAnalytics.Param.ITEM_NAME, name);
171
        analytics.logEvent(FirebaseAnalytics.Event.TUTORIAL_BEGIN, bundle);
172
        }
173
      }
174
    }
175
  }
(19-19/19)