diff --git a/app/src/main/java/guy/rateapplication/MainActivity.java b/app/src/main/java/guy/rateapplication/MainActivity.java index 393e30b..93a25b6 100644 --- a/app/src/main/java/guy/rateapplication/MainActivity.java +++ b/app/src/main/java/guy/rateapplication/MainActivity.java @@ -43,16 +43,27 @@ protected void onCreate(Bundle savedInstanceState) { fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { +// SmartRate.Rate(MainActivity.this +// , "Rate Us" +// , "Tell others what you think about this app" +// , "Continue" +// , "Ask me later" +// , "Never ask again" +// , "Thanks for the feedback" +// , Color.parseColor("#2196F3") +// , 4 +// , 48 +// , 72 +// ); + SmartRate.Rate(MainActivity.this , "Rate Us" , "Tell others what you think about this app" , "Continue" - , "Ask me later" - , "Never ask again" + , "Cancel" , "Thanks for the feedback" , Color.parseColor("#2196F3") , 4 - , 3 ); } }); diff --git a/desc.png b/desc.png index 1ac0799..c25e60e 100644 Binary files a/desc.png and b/desc.png differ diff --git a/desc_s.png b/desc_s.png deleted file mode 100644 index e26309d..0000000 Binary files a/desc_s.png and /dev/null differ diff --git a/description.docx b/description.docx index d914a1f..e6a601b 100644 Binary files a/description.docx and b/description.docx differ diff --git a/screen shot 2.png b/screen shot 2.png new file mode 100644 index 0000000..748726e Binary files /dev/null and b/screen shot 2.png differ diff --git a/smartrate/src/main/java/guy4444/smartrate/SmartRate.java b/smartrate/src/main/java/guy4444/smartrate/SmartRate.java index 2f11146..e6ebf72 100644 --- a/smartrate/src/main/java/guy4444/smartrate/SmartRate.java +++ b/smartrate/src/main/java/guy4444/smartrate/SmartRate.java @@ -23,8 +23,10 @@ public class SmartRate { private static final long DONT_ASK_AGAIN_VALUE = -1; private static final String SP_LIBRARY_NAME = "SP_RATE_LIBRARY"; private static final String SP_KEY_LAST_ASK_TIME = "SP_KEY_LAST_ASK_TIME"; + private static final String SP_KEY_INIT_TIME = "SP_KEY_INIT_TIME"; private static int selectedStar = 1; - private static final long DEFAULT_TIME_BETWEEN_DIALOG_MS = 1000l * 60 * 60 * 24 * 3; // 3 days + private static final long DEFAULT_TIME_BETWEEN_DIALOG_MS = 1000l * 60 * 60 * 24 * 6; // 3 days + private static final long DEFAULT_DELAY_TO_ACTIVATE_MS = 1000l * 60 * 60 * 24 * 3; // 3 days private static String DEFAULT_TEXT_TITLE = "Rate Us"; private static String DEFAULT_TEXT_CONTENT = "Tell others what you think about this app"; private static String DEFAULT_TEXT_OK = "Continue"; @@ -32,6 +34,29 @@ public class SmartRate { private static String DEFAULT_TEXT_STOP = "Never ask again"; private static String DEFAULT_TEXT_THANKS = "Thanks for the feedback"; + public static void Rate( + final Activity activity + , final String _title + , final String _content + , final String _ok_text + , final String _cancel_text + , final String _thanksForFeedback + , final int mainColor + , final int openStoreFromXStars + ) { + Rate(activity + , _title + , _content + , _ok_text + , _cancel_text + , "" + , _thanksForFeedback + , mainColor + , openStoreFromXStars + , -1 + , -1); + } + public static void Rate( final Activity activity , final String _title @@ -43,27 +68,41 @@ public static void Rate( , final int mainColor , final int openStoreFromXStars , final int _hoursBetweenCalls + , final int _hoursDelayToActivate ) { + final String title = (_title != null && !_title.equals("")) ? _title : DEFAULT_TEXT_TITLE; + final String content = (_content != null && !_content.equals("")) ? _content : DEFAULT_TEXT_CONTENT; + final String ok_text = (_ok_text != null && !_ok_text.equals("")) ? _ok_text : DEFAULT_TEXT_OK; + final String later_text = (_later_text != null && !_later_text.equals("")) ? _later_text : DEFAULT_TEXT_LATER; + final String stop_text = (_stop_text != null && !_stop_text.equals("")) ? _stop_text : DEFAULT_TEXT_STOP; + final String thanksForFeedback = (_thanksForFeedback != null && !_thanksForFeedback.equals("")) ? _thanksForFeedback : DEFAULT_TEXT_THANKS; + final long timeBetweenCalls_Ms = (_hoursBetweenCalls >= 1 && _hoursBetweenCalls < 366 * 24) ? 1000l * 60 * 60 * _hoursBetweenCalls : DEFAULT_TIME_BETWEEN_DIALOG_MS; + final long timeDelayToActivate_Ms = (_hoursDelayToActivate >= 1 && _hoursDelayToActivate < 366 * 24) ? 1000l * 60 * 60 * _hoursDelayToActivate : DEFAULT_DELAY_TO_ACTIVATE_MS; + + + if (_hoursBetweenCalls != -1 && _hoursDelayToActivate != -1) { + // no force asking mode + long initTime = getInitTime(activity); + if (initTime == 0) { + setInitTime(activity, System.currentTimeMillis()); + return; + } + if (System.currentTimeMillis() < initTime + timeDelayToActivate_Ms) { + return; + } - final String title = (_title!=null && !_title.equals("")) ? _title : DEFAULT_TEXT_TITLE; - final String content = (_content!=null && !_content.equals("")) ? _content : DEFAULT_TEXT_CONTENT; - final String ok_text = (_ok_text!=null && !_ok_text.equals("")) ? _ok_text : DEFAULT_TEXT_OK; - final String later_text = (_later_text!=null && !_later_text.equals("")) ? _later_text : DEFAULT_TEXT_LATER; - final String stop_text = (_stop_text!=null && !_stop_text.equals("")) ? _stop_text : DEFAULT_TEXT_STOP; - final String thanksForFeedback = (_thanksForFeedback!=null && !_thanksForFeedback.equals("")) ? _thanksForFeedback : DEFAULT_TEXT_THANKS; - final long timeBetweenCalls_Ms = (_hoursBetweenCalls >=1 && _hoursBetweenCalls < 366*24) ? 1000l * 60 * 60 *_hoursBetweenCalls : DEFAULT_TIME_BETWEEN_DIALOG_MS; - - if (getLastAskTime(activity) == DONT_ASK_AGAIN_VALUE) { - // user already rate or click on never ask button - return; - } - if (System.currentTimeMillis() < getLastAskTime(activity) + timeBetweenCalls_Ms) { - // There was not enough time between the calls. - return; + if (getLastAskTime(activity) == DONT_ASK_AGAIN_VALUE) { + // user already rate or click on never ask button + return; + } + if (System.currentTimeMillis() < getLastAskTime(activity) + timeBetweenCalls_Ms) { + // There was not enough time between the calls. + return; + } } - saveLastAskTime(activity, System.currentTimeMillis()); + setLastAskTime(activity, System.currentTimeMillis()); AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(activity); LayoutInflater inflater = activity.getLayoutInflater(); @@ -131,22 +170,20 @@ public void onClick(View v) { alert_BTN_star_5.setOnClickListener(starsClickListener); - alert_LBL_title.setText(title); alert_LBL_content.setText(content); - - if (ok_text!=null && !ok_text.equals("")) { + if (ok_text != null && !ok_text.equals("")) { alert_BTN_ok.setText(ok_text); alert_BTN_ok.setText("?/5\n" + ok_text); alert_BTN_ok.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { - saveLastAskTime(activity, DONT_ASK_AGAIN_VALUE); + setLastAskTime(activity, DONT_ASK_AGAIN_VALUE); int _openStoreFrom_Stars = openStoreFromXStars; - if (openStoreFromXStars < 1 || openStoreFromXStars > 5) { + if (openStoreFromXStars < 1 || openStoreFromXStars > 5) { _openStoreFrom_Stars = 1; } if (selectedStar >= _openStoreFrom_Stars) { @@ -157,13 +194,12 @@ public void onClick(View view) { alertDialog.dismiss(); } }); - } - else { + } else { alert_BTN_ok.setVisibility(View.INVISIBLE); } alert_BTN_ok.setEnabled(false); - if (later_text!=null && !later_text.equals("")) { + if (later_text != null && !later_text.equals("")) { alert_BTN_later.setText(later_text); alert_BTN_later.setOnClickListener(new View.OnClickListener() { @Override @@ -172,25 +208,29 @@ public void onClick(View view) { alertDialog.dismiss(); } }); - } - else { + } else { alert_BTN_later.setVisibility(View.INVISIBLE); } - if (stop_text!=null && !stop_text.equals("")) { + if (stop_text != null && !stop_text.equals("")) { alert_BTN_stop.setText(stop_text); alert_BTN_stop.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { - saveLastAskTime(activity, DONT_ASK_AGAIN_VALUE); + setLastAskTime(activity, DONT_ASK_AGAIN_VALUE); alertDialog.dismiss(); } }); - } - else { + } else { alert_BTN_stop.setVisibility(View.INVISIBLE); } + + if (_hoursBetweenCalls == -1 && _hoursDelayToActivate == -1) { + // force asking mode + alert_BTN_stop.setVisibility(View.GONE); + } + alertDialog.show(); } @@ -210,30 +250,42 @@ private static long getLastAskTime(Activity activity) { return val; } - private static void saveLastAskTime(Activity activity, long time) { + private static void setLastAskTime(Activity activity, long time) { SharedPreferences.Editor editor = activity.getSharedPreferences(SP_LIBRARY_NAME, Context.MODE_PRIVATE).edit(); editor.putLong(SP_KEY_LAST_ASK_TIME, time); editor.apply(); } + private static long getInitTime(Activity activity) { + SharedPreferences sharedPreferences = activity.getSharedPreferences(SP_LIBRARY_NAME, Context.MODE_PRIVATE); + long val = sharedPreferences.getLong(SP_KEY_INIT_TIME, 0); + return val; + } + + private static void setInitTime(Activity activity, long time) { + SharedPreferences.Editor editor = activity.getSharedPreferences(SP_LIBRARY_NAME, Context.MODE_PRIVATE).edit(); + editor.putLong(SP_KEY_INIT_TIME, time); + editor.apply(); + } + private static String shadeColor(String color, int percent) { - int R = Integer.parseInt(color.substring(1,3),16); - int G = Integer.parseInt(color.substring(3,5),16); - int B = Integer.parseInt(color.substring(5,7),16); + int R = Integer.parseInt(color.substring(1, 3), 16); + int G = Integer.parseInt(color.substring(3, 5), 16); + int B = Integer.parseInt(color.substring(5, 7), 16); R = R * (100 + percent) / 100; G = G * (100 + percent) / 100; B = B * (100 + percent) / 100; - R = (R<255)?R:255; - G = (G<255)?G:255; - B = (B<255)?B:255; + R = (R < 255) ? R : 255; + G = (G < 255) ? G : 255; + B = (B < 255) ? B : 255; - String RR = (Integer.toString(R, 16).length()==1) ? "0" + Integer.toString(R, 16) : Integer.toString(R, 16); - String GG = (Integer.toString(G, 16).length()==1) ? "0" + Integer.toString(G, 16) : Integer.toString(G, 16); - String BB = (Integer.toString(B, 16).length()==1) ? "0" + Integer.toString(B, 16) : Integer.toString(B, 16); + String RR = (Integer.toString(R, 16).length() == 1) ? "0" + Integer.toString(R, 16) : Integer.toString(R, 16); + String GG = (Integer.toString(G, 16).length() == 1) ? "0" + Integer.toString(G, 16) : Integer.toString(G, 16); + String BB = (Integer.toString(B, 16).length() == 1) ? "0" + Integer.toString(B, 16) : Integer.toString(B, 16); - return "#"+RR+GG+BB; + return "#" + RR + GG + BB; } }