1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
|
package com.mapswithme.maps.ads;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v7.app.AlertDialog;
import android.text.format.DateUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.RatingBar;
import android.widget.TextView;
import com.mapswithme.maps.BuildConfig;
import com.mapswithme.maps.MwmApplication;
import com.mapswithme.maps.R;
import com.mapswithme.maps.base.BaseMwmDialogFragment;
import com.mapswithme.util.Constants;
import com.mapswithme.util.UiUtils;
import com.mapswithme.util.Utils;
import com.mapswithme.util.statistics.AlohaHelper;
import com.mapswithme.util.statistics.Statistics;
import com.nineoldandroids.animation.Animator;
import com.nineoldandroids.animation.ObjectAnimator;
public class RateStoreDialogFragment extends BaseMwmDialogFragment implements View.OnClickListener
{
private float mRating;
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState)
{
final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
final LayoutInflater inflater = getActivity().getLayoutInflater();
final View root = inflater.inflate(R.layout.fragment_google_play_dialog, null);
builder.
setView(root).
setNegativeButton(getString(R.string.remind_me_later), new DialogInterface.OnClickListener()
{
@Override
public void onClick(DialogInterface dialog, int which)
{
Statistics.INSTANCE.trackSimpleNamedEvent(Statistics.EventName.RATE_DIALOG_LATER);
}
});
final RatingBar rateBar = (RatingBar) root.findViewById(R.id.rb__play_rate);
rateBar.setOnRatingBarChangeListener(new RatingBar.OnRatingBarChangeListener()
{
@Override
public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromUser)
{
Statistics.INSTANCE.trackRatingDialog(rating);
mRating = rating;
if (rating >= BuildConfig.RATING_THRESHOLD)
{
LikesManager.setRatingApplied(RateStoreDialogFragment.class, true);
dismiss();
Utils.openAppInMarket(getActivity(), BuildConfig.REVIEW_URL);
}
else
{
ObjectAnimator animator = ObjectAnimator.ofFloat(rateBar, "alpha", 1.0f, 0.0f);
animator.addListener(new UiUtils.SimpleNineoldAnimationListener()
{
@Override
public void onAnimationEnd(Animator animation)
{
final Button button = (Button) root.findViewById(R.id.btn__explain_bad_rating);
button.setVisibility(View.VISIBLE);
button.setOnClickListener(RateStoreDialogFragment.this);
((TextView) root.findViewById(R.id.tv__title)).setText(getString(R.string.rating_thanks));
((TextView) root.findViewById(R.id.tv__subtitle)).setText(getString(R.string.rating_share_ideas));
root.findViewById(R.id.v__divider).setVisibility(View.VISIBLE);
rateBar.setVisibility(View.GONE);
super.onAnimationEnd(animation);
}
});
animator.start();
}
}
});
return builder.create();
}
@Override
public void onCancel(DialogInterface dialog)
{
super.onCancel(dialog);
Statistics.INSTANCE.trackSimpleNamedEvent(Statistics.EventName.RATE_DIALOG_LATER);
}
@Override
public void onClick(View v)
{
switch (v.getId())
{
case R.id.btn__explain_bad_rating:
LikesManager.setRatingApplied(GooglePlusDialogFragment.class, true);
dismiss();
final Intent intent = new Intent(Intent.ACTION_SENDTO);
final PackageInfo info;
long installTime = 0;
try
{
info = MwmApplication.get().getPackageManager().getPackageInfo(BuildConfig.APPLICATION_ID, 0);
installTime = info.firstInstallTime;
} catch (PackageManager.NameNotFoundException e)
{
e.printStackTrace();
}
intent.setData(Utils.buildMailUri(Constants.Url.MAIL_MAPSME_RATING, getString(R.string.rating_just_rated) + ": " + mRating,
"OS : " + Build.VERSION.SDK_INT + "\n" + "Version : " + BuildConfig.APPLICATION_ID + " " + BuildConfig.VERSION_NAME + "\n" +
getString(R.string.rating_user_since, DateUtils.formatDateTime(getActivity(), installTime, 0)) + "\n\n"));
try
{
startActivity(intent);
} catch (android.content.ActivityNotFoundException e)
{
AlohaHelper.logException(e);
}
break;
}
}
}
|