Merge lp:~openerp-dev/openerp-mobile/trunk-app_rating_feature-sla into lp:openerp-mobile

Proposed by Shailesh Lakum(OpenERP)
Status: Merged
Merged at revision: 159
Proposed branch: lp:~openerp-dev/openerp-mobile/trunk-app_rating_feature-sla
Merge into: lp:openerp-mobile
Diff against target: 130 lines (+100/-1)
2 files modified
src/com/openerp/MainActivity.java (+7/-1)
src/com/openerp/util/OEAppRater.java (+93/-0)
To merge this branch: bzr merge lp:~openerp-dev/openerp-mobile/trunk-app_rating_feature-sla
Reviewer Review Type Date Requested Status
Dharmang Soni (OpenERP) Pending
Review via email: mp+218752@code.launchpad.net

Description of the change

Hello,

Application rating feature added in framework.

- show dialog on 3rd day and 7+ application launch.

Thanks,
Shailesh Lakum

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/com/openerp/MainActivity.java'
2--- src/com/openerp/MainActivity.java 2014-05-06 09:01:46 +0000
3+++ src/com/openerp/MainActivity.java 2014-05-08 07:31:18 +0000
4@@ -62,6 +62,7 @@
5 import com.openerp.support.OEUser;
6 import com.openerp.support.fragment.FragmentListener;
7 import com.openerp.util.Base64Helper;
8+import com.openerp.util.OEAppRater;
9 import com.openerp.util.OnBackButtonPressedListener;
10 import com.openerp.util.PreferenceManager;
11 import com.openerp.util.drawer.DrawerAdatper;
12@@ -121,6 +122,11 @@
13 init();
14 }
15
16+ private void checkForRateApplication() {
17+ OEAppRater oeAppRater = new OEAppRater();
18+ oeAppRater.app_launched(this);
19+ }
20+
21 private void init() {
22 Log.d(TAG, "MainActivity->init()");
23 initDrawerControls();
24@@ -161,7 +167,7 @@
25 initDrawer();
26 }
27 }
28-
29+ checkForRateApplication();
30 }
31
32 private void initDrawerControls() {
33
34=== added file 'src/com/openerp/util/OEAppRater.java'
35--- src/com/openerp/util/OEAppRater.java 1970-01-01 00:00:00 +0000
36+++ src/com/openerp/util/OEAppRater.java 2014-05-08 07:31:18 +0000
37@@ -0,0 +1,93 @@
38+package com.openerp.util;
39+
40+import android.app.AlertDialog;
41+import android.app.Dialog;
42+import android.content.Context;
43+import android.content.DialogInterface;
44+import android.content.Intent;
45+import android.content.SharedPreferences;
46+import android.net.Uri;
47+
48+import com.openerp.R;
49+
50+public class OEAppRater {
51+ private static String app_title = "APP-NAME";
52+ private static String app_pname = "PACKAGE-NAME";
53+
54+ private final static int DAYS_UNTIL_PROMPT = 3;
55+ private final static int LAUNCHES_UNTIL_PROMPT = 7;
56+
57+ public static void app_launched(Context mContext) {
58+ app_title = mContext.getResources().getString(R.string.app_name);
59+ app_pname = mContext.getPackageName();
60+ SharedPreferences prefs = mContext.getSharedPreferences("apprater", 0);
61+ if (prefs.getBoolean("dontshowagain", false)) {
62+ return;
63+ }
64+
65+ SharedPreferences.Editor editor = prefs.edit();
66+ long launch_count = prefs.getLong("launch_count", 0) + 1;
67+ editor.putLong("launch_count", launch_count);
68+ Long date_firstLaunch = prefs.getLong("date_firstlaunch", 0);
69+ if (date_firstLaunch == 0) {
70+ date_firstLaunch = System.currentTimeMillis();
71+ editor.putLong("date_firstlaunch", date_firstLaunch);
72+ }
73+ if (launch_count >= LAUNCHES_UNTIL_PROMPT) {
74+ if (System.currentTimeMillis() >= date_firstLaunch
75+ + (DAYS_UNTIL_PROMPT * 24 * 60 * 60 * 1000)) {
76+ showRateDialog(mContext, editor);
77+ }
78+ }
79+ editor.commit();
80+ }
81+
82+ private static Dialog dialog = null;
83+
84+ public static void showRateDialog(final Context mContext,
85+ final SharedPreferences.Editor editor) {
86+ AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
87+
88+ builder.setTitle("Rate " + app_title);
89+ builder.setIcon(R.drawable.ic_action_starred);
90+ builder.setMessage("If you enjoy using " + app_title
91+ + ", please take a moment to rate it. Thanks for your support!");
92+ builder.setNegativeButton("Rate " + app_title,
93+ new DialogInterface.OnClickListener() {
94+ @Override
95+ public void onClick(DialogInterface dialog, int which) {
96+
97+ Intent intent = new Intent(Intent.ACTION_VIEW, Uri
98+ .parse("market://details?id=" + app_pname));
99+ intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
100+ mContext.startActivity(intent);
101+ if (editor != null) {
102+ editor.putBoolean("dontshowagain", true);
103+ editor.commit();
104+ }
105+ dialog.dismiss();
106+ }
107+ });
108+ builder.setNeutralButton("Remind me later",
109+ new DialogInterface.OnClickListener() {
110+
111+ @Override
112+ public void onClick(DialogInterface dialog, int which) {
113+ dialog.dismiss();
114+ }
115+ });
116+ builder.setPositiveButton("No, thanks",
117+ new DialogInterface.OnClickListener() {
118+ @Override
119+ public void onClick(DialogInterface dialog, int which) {
120+ if (editor != null) {
121+ editor.putBoolean("dontshowagain", true);
122+ editor.commit();
123+ }
124+ dialog.dismiss();
125+ }
126+ });
127+ dialog = builder.create();
128+ dialog.show();
129+ }
130+}