Project

General

Profile

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

magiccube / src / main / java / org / distorted / dialogs / RubikDialogTutorialView.java @ eaf87d1d

1 234a7582 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
package org.distorted.dialogs;
21
22
import android.content.Context;
23 b91d4033 Leszek Koltunski
import android.content.res.Resources;
24 992748ab Leszek Koltunski
import android.os.Bundle;
25 234a7582 Leszek Koltunski
import android.util.AttributeSet;
26 b91d4033 Leszek Koltunski
import android.util.TypedValue;
27 234a7582 Leszek Koltunski
import android.view.View;
28 b91d4033 Leszek Koltunski
import android.widget.Button;
29 234a7582 Leszek Koltunski
import android.widget.FrameLayout;
30 ef1f3e34 Leszek Koltunski
import android.widget.ImageView;
31 b91d4033 Leszek Koltunski
import android.widget.LinearLayout;
32 ef1f3e34 Leszek Koltunski
import android.widget.TextView;
33 234a7582 Leszek Koltunski
34
import androidx.fragment.app.FragmentActivity;
35
36 992748ab Leszek Koltunski
import com.google.firebase.analytics.FirebaseAnalytics;
37
38
import org.distorted.main.BuildConfig;
39 234a7582 Leszek Koltunski
import org.distorted.main.R;
40
import org.distorted.main.RubikActivity;
41 79bf5d8b Leszek Koltunski
import org.distorted.objects.ObjectList;
42 eaf87d1d Leszek Koltunski
import org.distorted.tutorials.TutorialList;
43 234a7582 Leszek Koltunski
44
///////////////////////////////////////////////////////////////////////////////////////////////////
45
46
public class RubikDialogTutorialView extends FrameLayout
47
  {
48
  public RubikDialogTutorialView(Context context, AttributeSet attrs, int defStyle)
49
    {
50
    super(context, attrs, defStyle);
51
    }
52
53
///////////////////////////////////////////////////////////////////////////////////////////////////
54
55
  public RubikDialogTutorialView(Context context, AttributeSet attrs)
56
    {
57
    super(context, attrs);
58
    }
59
60
///////////////////////////////////////////////////////////////////////////////////////////////////
61
62 ef1f3e34 Leszek Koltunski
  public RubikDialogTutorialView(FragmentActivity act, int width, int position)
63 234a7582 Leszek Koltunski
    {
64
    super(act);
65
66 ef1f3e34 Leszek Koltunski
    int widthT = (int)(width* RubikActivity.TUTORIAL_ITEM_TEXT);
67 234a7582 Leszek Koltunski
68 b91d4033 Leszek Koltunski
    RubikActivity ract = (RubikActivity)getContext();
69
    Resources res = act.getResources();
70
    String packageName = act.getPackageName();
71
72 992748ab Leszek Koltunski
    TutorialList list  = TutorialList.getObject(position);
73
    ObjectList objList = list.getObjectList();
74
    int size           = list.getSize();
75 234a7582 Leszek Koltunski
76
    View tab = inflate( act, R.layout.dialog_tutorial_tab, null);
77 b91d4033 Leszek Koltunski
    LinearLayout layout = tab.findViewById(R.id.tabLayout);
78 234a7582 Leszek Koltunski
79 992748ab Leszek Koltunski
    int numTutorials = list.getNumTutorials();
80 234a7582 Leszek Koltunski
81 b91d4033 Leszek Koltunski
    for(int i=0; i<numTutorials; i++)
82
      {
83 992748ab Leszek Koltunski
      String coun = list.getTutorialLanguage(i);
84
      String desc = list.getTutorialDescription(i);
85
      String url  = list.getTutorialURL(i);
86
      String auth = list.getTutorialAuthor(i);
87 b91d4033 Leszek Koltunski
88
      int countryID = res.getIdentifier( coun, "drawable", packageName);
89
90 ef1f3e34 Leszek Koltunski
      View row = createRow(ract,countryID,desc,url,auth,widthT,objList,size);
91 b91d4033 Leszek Koltunski
      layout.addView(row);
92
      }
93 234a7582 Leszek Koltunski
94
    addView(tab);
95
    }
96 b91d4033 Leszek Koltunski
97
///////////////////////////////////////////////////////////////////////////////////////////////////
98
99 992748ab Leszek Koltunski
  private View createRow(final RubikActivity act, int countryID, final String desc, final String url,
100 ef1f3e34 Leszek Koltunski
                         final String auth, int width, final ObjectList obj, final int size)
101 b91d4033 Leszek Koltunski
    {
102
    View row = inflate( act, R.layout.dialog_tutorial_row, null);
103 ef1f3e34 Leszek Koltunski
    Button butt = row.findViewById(R.id.tutorialButton);
104 b91d4033 Leszek Koltunski
105 ef1f3e34 Leszek Koltunski
    butt.setText(R.string.view);
106
    butt.setTextSize(TypedValue.COMPLEX_UNIT_PX, 0.5f*width);
107
    butt.setHeight(width);
108 b91d4033 Leszek Koltunski
109
    butt.setOnClickListener( new View.OnClickListener()
110
      {
111
      @Override
112
      public void onClick(View v)
113
        {
114 79bf5d8b Leszek Koltunski
        act.switchTutorial(url,obj,size);
115 992748ab Leszek Koltunski
        analyticsReport(act,desc,auth,obj,size);
116 b91d4033 Leszek Koltunski
        }
117
      });
118
119 ef1f3e34 Leszek Koltunski
    ImageView image = row.findViewById(R.id.tutorialCountry);
120
    int id = countryID!=0 ? countryID : R.drawable.un;
121
    image.setImageResource(id);
122
123
    TextView author = row.findViewById(R.id.tutorialAuthor);
124
    author.setTextSize(TypedValue.COMPLEX_UNIT_PX, 0.5f*width);
125
    author.setText(auth);
126
127
    TextView title  = row.findViewById(R.id.tutorialTitle);
128
    title.setTextSize(TypedValue.COMPLEX_UNIT_PX, 0.5f*width);
129
    title.setText(desc);
130
131 b91d4033 Leszek Koltunski
    return row;
132
    }
133 992748ab Leszek Koltunski
134
///////////////////////////////////////////////////////////////////////////////////////////////////
135
136
  private void analyticsReport(RubikActivity act, String desc, String author, ObjectList obj, int size)
137
    {
138
    String message = desc+" ("+author+")";
139
140
    if( BuildConfig.DEBUG )
141
       {
142
       android.util.Log.d("tutorial", message);
143
       }
144
    else
145
      {
146
      FirebaseAnalytics analytics = act.getAnalytics();
147
      String name = obj.name()+"_"+size;
148
149
      if( analytics!=null )
150
        {
151
        Bundle bundle = new Bundle();
152
        bundle.putString(FirebaseAnalytics.Param.CONTENT_TYPE, message);
153
        bundle.putString(FirebaseAnalytics.Param.ITEM_NAME, name);
154
        analytics.logEvent(FirebaseAnalytics.Event.TUTORIAL_BEGIN, bundle);
155
        }
156
      }
157
    }
158 234a7582 Leszek Koltunski
  }