Revision 992748ab
Added by Leszek Koltunski almost 5 years ago
| src/main/java/org/distorted/dialogs/RubikDialogTutorialView.java | ||
|---|---|---|
| 22 | 22 |
import android.content.Context; |
| 23 | 23 |
import android.content.res.Resources; |
| 24 | 24 |
import android.graphics.drawable.Drawable; |
| 25 |
import android.os.Bundle; |
|
| 25 | 26 |
import android.util.AttributeSet; |
| 26 | 27 |
import android.util.TypedValue; |
| 27 | 28 |
import android.view.View; |
| 28 | 29 |
import android.widget.Button; |
| 29 | 30 |
import android.widget.FrameLayout; |
| 30 |
import android.widget.ImageView; |
|
| 31 | 31 |
import android.widget.LinearLayout; |
| 32 | 32 |
|
| 33 | 33 |
import androidx.core.content.ContextCompat; |
| 34 | 34 |
import androidx.fragment.app.FragmentActivity; |
| 35 | 35 |
|
| 36 |
import com.google.firebase.analytics.FirebaseAnalytics; |
|
| 37 |
|
|
| 38 |
import org.distorted.main.BuildConfig; |
|
| 36 | 39 |
import org.distorted.main.R; |
| 37 | 40 |
import org.distorted.main.RubikActivity; |
| 38 | 41 |
import org.distorted.objects.ObjectList; |
| ... | ... | |
| 42 | 45 |
|
| 43 | 46 |
public class RubikDialogTutorialView extends FrameLayout |
| 44 | 47 |
{
|
| 45 |
private TutorialList mList; |
|
| 46 |
|
|
| 47 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 48 |
|
|
| 49 | 48 |
public RubikDialogTutorialView(Context context, AttributeSet attrs, int defStyle) |
| 50 | 49 |
{
|
| 51 | 50 |
super(context, attrs, defStyle); |
| ... | ... | |
| 70 | 69 |
Resources res = act.getResources(); |
| 71 | 70 |
String packageName = act.getPackageName(); |
| 72 | 71 |
|
| 73 |
mList = TutorialList.getObject(position);
|
|
| 74 |
ObjectList objList = mList.getObjectList();
|
|
| 75 |
int size = mList.getSize();
|
|
| 72 |
TutorialList list = TutorialList.getObject(position);
|
|
| 73 |
ObjectList objList = list.getObjectList();
|
|
| 74 |
int size = list.getSize();
|
|
| 76 | 75 |
|
| 77 | 76 |
View tab = inflate( act, R.layout.dialog_tutorial_tab, null); |
| 78 | 77 |
LinearLayout layout = tab.findViewById(R.id.tabLayout); |
| 79 | 78 |
|
| 80 |
int numTutorials = mList.getNumTutorials();
|
|
| 79 |
int numTutorials = list.getNumTutorials();
|
|
| 81 | 80 |
|
| 82 | 81 |
for(int i=0; i<numTutorials; i++) |
| 83 | 82 |
{
|
| 84 |
String coun = mList.getTutorialLanguage(i);
|
|
| 85 |
String desc = mList.getTutorialDescription(i);
|
|
| 86 |
String url = mList.getTutorialURL(i);
|
|
| 87 |
String auth = mList.getTutorialAuthor(i);
|
|
| 83 |
String coun = list.getTutorialLanguage(i);
|
|
| 84 |
String desc = list.getTutorialDescription(i);
|
|
| 85 |
String url = list.getTutorialURL(i);
|
|
| 86 |
String auth = list.getTutorialAuthor(i);
|
|
| 88 | 87 |
|
| 89 | 88 |
int countryID = res.getIdentifier( coun, "drawable", packageName); |
| 90 | 89 |
|
| ... | ... | |
| 97 | 96 |
|
| 98 | 97 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 99 | 98 |
|
| 100 |
private View createRow(final RubikActivity act, int countryID, final String desc, final String url, String auth, int height, final ObjectList obj, final int size) |
|
| 99 |
private View createRow(final RubikActivity act, int countryID, final String desc, final String url, |
|
| 100 |
final String auth, int height, final ObjectList obj, final int size) |
|
| 101 | 101 |
{
|
| 102 | 102 |
View row = inflate( act, R.layout.dialog_tutorial_row, null); |
| 103 | 103 |
Button butt = row.findViewById(R.id.tutorialRowButton); |
| 104 | 104 |
|
| 105 | 105 |
int id = countryID!=0 ? countryID : R.drawable.un; |
| 106 |
final String buttText = desc+" ("+auth+")";
|
|
| 106 | 107 |
|
| 107 |
butt.setText(desc+" ("+auth+")");
|
|
| 108 |
butt.setText(buttText);
|
|
| 108 | 109 |
butt.setTextSize(TypedValue.COMPLEX_UNIT_PX, 0.5f*height); |
| 109 | 110 |
butt.setHeight(height); |
| 110 | 111 |
|
| ... | ... | |
| 118 | 119 |
public void onClick(View v) |
| 119 | 120 |
{
|
| 120 | 121 |
act.switchTutorial(url,obj,size); |
| 122 |
analyticsReport(act,desc,auth,obj,size); |
|
| 121 | 123 |
} |
| 122 | 124 |
}); |
| 123 | 125 |
|
| 124 | 126 |
return row; |
| 125 | 127 |
} |
| 128 |
|
|
| 129 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 130 |
|
|
| 131 |
private void analyticsReport(RubikActivity act, String desc, String author, ObjectList obj, int size) |
|
| 132 |
{
|
|
| 133 |
String message = desc+" ("+author+")";
|
|
| 134 |
|
|
| 135 |
if( BuildConfig.DEBUG ) |
|
| 136 |
{
|
|
| 137 |
android.util.Log.d("tutorial", message);
|
|
| 138 |
} |
|
| 139 |
else |
|
| 140 |
{
|
|
| 141 |
FirebaseAnalytics analytics = act.getAnalytics(); |
|
| 142 |
String name = obj.name()+"_"+size; |
|
| 143 |
|
|
| 144 |
if( analytics!=null ) |
|
| 145 |
{
|
|
| 146 |
Bundle bundle = new Bundle(); |
|
| 147 |
bundle.putString(FirebaseAnalytics.Param.CONTENT_TYPE, message); |
|
| 148 |
bundle.putString(FirebaseAnalytics.Param.ITEM_NAME, name); |
|
| 149 |
analytics.logEvent(FirebaseAnalytics.Event.TUTORIAL_BEGIN, bundle); |
|
| 150 |
} |
|
| 151 |
} |
|
| 152 |
} |
|
| 126 | 153 |
} |
Also available in: Unified diff
Report to Google Analytics that we're watching a tutorial.