Skip to content

Commit c5b4d6e

Browse files
committed
show a Rate us button to returning users
1 parent c9bcd2e commit c5b4d6e

File tree

6 files changed

+73
-4
lines changed

6 files changed

+73
-4
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.simplemobiletools.flashlight;
2+
3+
import android.content.Context;
4+
import android.content.SharedPreferences;
5+
6+
import com.simplemobiletools.flashlight.activities.Constants;
7+
8+
public class Config {
9+
private SharedPreferences mPrefs;
10+
11+
public static Config newInstance(Context context) {
12+
return new Config(context);
13+
}
14+
15+
public Config(Context context) {
16+
mPrefs = context.getSharedPreferences(Constants.PREFS_KEY, Context.MODE_PRIVATE);
17+
}
18+
19+
public boolean getIsFirstRun() {
20+
return mPrefs.getBoolean(Constants.IS_FIRST_RUN, true);
21+
}
22+
23+
public void setIsFirstRun(boolean firstRun) {
24+
mPrefs.edit().putBoolean(Constants.IS_FIRST_RUN, firstRun).apply();
25+
}
26+
}

app/src/main/java/com/simplemobiletools/flashlight/activities/AboutActivity.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
package com.simplemobiletools.flashlight.activities;
22

3+
import android.content.ActivityNotFoundException;
34
import android.content.Intent;
45
import android.content.res.Resources;
56
import android.net.Uri;
67
import android.os.Bundle;
78
import android.support.v7.app.AppCompatActivity;
89
import android.text.Html;
910
import android.text.method.LinkMovementMethod;
11+
import android.view.View;
1012
import android.widget.TextView;
1113

1214
import com.simplemobiletools.flashlight.BuildConfig;
15+
import com.simplemobiletools.flashlight.Config;
1316
import com.simplemobiletools.flashlight.R;
1417

1518
import java.util.Calendar;
@@ -22,6 +25,7 @@ public class AboutActivity extends AppCompatActivity {
2225
@BindView(R.id.about_copyright) TextView mCopyright;
2326
@BindView(R.id.about_version) TextView mVersion;
2427
@BindView(R.id.about_email) TextView mEmailTV;
28+
@BindView(R.id.about_rate_us) View mRateUs;
2529

2630
private static Resources mRes;
2731

@@ -35,6 +39,7 @@ protected void onCreate(Bundle savedInstanceState) {
3539
setupEmail();
3640
setupVersion();
3741
setupCopyright();
42+
setupRateUs();
3843
}
3944

4045
private void setupEmail() {
@@ -57,6 +62,22 @@ private void setupCopyright() {
5762
mCopyright.setText(copyrightText);
5863
}
5964

65+
private void setupRateUs() {
66+
if (Config.newInstance(getApplicationContext()).getIsFirstRun()) {
67+
mRateUs.setVisibility(View.GONE);
68+
}
69+
}
70+
71+
@OnClick(R.id.about_rate_us)
72+
public void rateUsClicked() {
73+
final Uri uri = Uri.parse("market://details?id=" + getPackageName());
74+
try {
75+
startActivity(new Intent(Intent.ACTION_VIEW, uri));
76+
} catch (ActivityNotFoundException ignored) {
77+
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://play.google.com/store/apps/details?id=" + getPackageName())));
78+
}
79+
}
80+
6081
@OnClick(R.id.about_license)
6182
public void licenseClicked() {
6283
final Intent intent = new Intent(getApplicationContext(), LicenseActivity.class);
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.simplemobiletools.flashlight.activities;
2+
3+
public class Constants {
4+
// shared preferences
5+
public static final String PREFS_KEY = "Flashlight";
6+
public static final String IS_FIRST_RUN = "is_first_run";
7+
}

app/src/main/java/com/simplemobiletools/flashlight/activities/MainActivity.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import android.widget.ImageView;
1111

1212
import com.simplemobiletools.flashlight.BusProvider;
13+
import com.simplemobiletools.flashlight.Config;
1314
import com.simplemobiletools.flashlight.Events;
1415
import com.simplemobiletools.flashlight.MyCameraImpl;
1516
import com.simplemobiletools.flashlight.R;
@@ -90,8 +91,11 @@ protected void onStop() {
9091
@Override
9192
protected void onDestroy() {
9293
super.onDestroy();
93-
mCameraImpl.releaseCamera();
94-
mCameraImpl = null;
94+
Config.newInstance(getApplicationContext()).setIsFirstRun(false);
95+
if (mCameraImpl != null) {
96+
mCameraImpl.releaseCamera();
97+
mCameraImpl = null;
98+
}
9599
}
96100

97101
@Subscribe

app/src/main/res/layout/activity_about.xml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,21 @@
2929
android:text="@string/email"/>
3030

3131
<TextView
32-
android:id="@+id/about_license"
32+
android:id="@+id/about_rate_us"
3333
android:layout_width="match_parent"
3434
android:layout_height="wrap_content"
3535
android:layout_below="@+id/about_email"
3636
android:layout_marginTop="@dimen/activity_margin"
37+
android:paddingTop="@dimen/activity_margin"
38+
android:text="@string/rate_us_underlined"
39+
android:textColor="@color/colorPrimary"/>
40+
41+
<TextView
42+
android:id="@+id/about_license"
43+
android:layout_width="match_parent"
44+
android:layout_height="wrap_content"
45+
android:layout_below="@+id/about_rate_us"
46+
android:layout_marginTop="@dimen/activity_margin"
3747
android:paddingBottom="@dimen/activity_margin"
3848
android:paddingTop="@dimen/activity_margin"
3949
android:text="@string/third_party_licences_underlined"
@@ -78,6 +88,6 @@
7888
android:layout_height="wrap_content"
7989
android:layout_alignParentBottom="true"
8090
android:gravity="center_horizontal"
81-
android:text="Copyright © Simple Mobile Tools 2000"/>
91+
android:text="Copyright © Simple Mobile Tools 2016"/>
8292

8393
</RelativeLayout>

app/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<string name="email_label">Send your feedback or suggestions at:</string>
99
<string name="email">hello@simplemobiletools.com</string>
1010
<string name="third_party_licences_underlined"><u>Third party licences</u></string>
11+
<string name="rate_us_underlined"><u>Rate us in the Play Store</u></string>
1112
<string name="follow_us">Follow us at:</string>
1213
<string name="version">v %1$s</string>
1314
<string name="copyright">Copyright © Simple Mobile Tools %1$d</string>

0 commit comments

Comments
 (0)