From 9d5277a090142cedc4739fd85f5317180e7b16e0 Mon Sep 17 00:00:00 2001 From: tibbi Date: Fri, 1 Jul 2016 15:04:31 +0200 Subject: [PATCH] show a Rate us button to returning users --- .../com/simplemobiletools/gallery/Config.java | 24 +++++++++++++ .../simplemobiletools/gallery/Constants.java | 4 +++ .../gallery/activities/AboutActivity.java | 35 +++++++++++++++---- .../gallery/activities/MainActivity.java | 7 ++++ app/src/main/res/layout/activity_about.xml | 12 ++++++- app/src/main/res/values/strings.xml | 1 + 6 files changed, 75 insertions(+), 8 deletions(-) create mode 100644 app/src/main/java/com/simplemobiletools/gallery/Config.java diff --git a/app/src/main/java/com/simplemobiletools/gallery/Config.java b/app/src/main/java/com/simplemobiletools/gallery/Config.java new file mode 100644 index 000000000..0ef710f48 --- /dev/null +++ b/app/src/main/java/com/simplemobiletools/gallery/Config.java @@ -0,0 +1,24 @@ +package com.simplemobiletools.gallery; + +import android.content.Context; +import android.content.SharedPreferences; + +public class Config { + private SharedPreferences mPrefs; + + public static Config newInstance(Context context) { + return new Config(context); + } + + public Config(Context context) { + mPrefs = context.getSharedPreferences(Constants.PREFS_KEY, Context.MODE_PRIVATE); + } + + public boolean getIsFirstRun() { + return mPrefs.getBoolean(Constants.IS_FIRST_RUN, true); + } + + public void setIsFirstRun(boolean firstRun) { + mPrefs.edit().putBoolean(Constants.IS_FIRST_RUN, firstRun).apply(); + } +} diff --git a/app/src/main/java/com/simplemobiletools/gallery/Constants.java b/app/src/main/java/com/simplemobiletools/gallery/Constants.java index b71a0626e..7970fc76b 100644 --- a/app/src/main/java/com/simplemobiletools/gallery/Constants.java +++ b/app/src/main/java/com/simplemobiletools/gallery/Constants.java @@ -6,4 +6,8 @@ public class Constants { public static final String GET_IMAGE_INTENT = "get_image_intent"; public static final String GET_VIDEO_INTENT = "get_video_intent"; public static final String SET_WALLPAPER_INTENT = "set_wallpaper_intent"; + + // shared preferences + public static final String PREFS_KEY = "gallery"; + public static final String IS_FIRST_RUN = "is_first_run"; } diff --git a/app/src/main/java/com/simplemobiletools/gallery/activities/AboutActivity.java b/app/src/main/java/com/simplemobiletools/gallery/activities/AboutActivity.java index 56d92989d..3a513cd08 100644 --- a/app/src/main/java/com/simplemobiletools/gallery/activities/AboutActivity.java +++ b/app/src/main/java/com/simplemobiletools/gallery/activities/AboutActivity.java @@ -1,5 +1,6 @@ package com.simplemobiletools.gallery.activities; +import android.content.ActivityNotFoundException; import android.content.Intent; import android.content.res.Resources; import android.net.Uri; @@ -7,9 +8,11 @@ import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.text.Html; import android.text.method.LinkMovementMethod; +import android.view.View; import android.widget.TextView; import com.simplemobiletools.gallery.BuildConfig; +import com.simplemobiletools.gallery.Config; import com.simplemobiletools.gallery.R; import java.util.Calendar; @@ -19,9 +22,10 @@ import butterknife.ButterKnife; import butterknife.OnClick; public class AboutActivity extends AppCompatActivity { - @BindView(R.id.about_copyright) TextView copyright; - @BindView(R.id.about_version) TextView version; - @BindView(R.id.about_email) TextView emailTV; + @BindView(R.id.about_copyright) TextView mCopyright; + @BindView(R.id.about_version) TextView mVersion; + @BindView(R.id.about_email) TextView mEmailTV; + @BindView(R.id.about_rate_us) View mRateUs; private static Resources mRes; @@ -35,26 +39,43 @@ public class AboutActivity extends AppCompatActivity { setupEmail(); setupVersion(); setupCopyright(); + setupRateUs(); } private void setupEmail() { final String email = mRes.getString(R.string.email); final String appName = mRes.getString(R.string.app_name); final String href = "" + email + ""; - emailTV.setText(Html.fromHtml(href)); - emailTV.setMovementMethod(LinkMovementMethod.getInstance()); + mEmailTV.setText(Html.fromHtml(href)); + mEmailTV.setMovementMethod(LinkMovementMethod.getInstance()); } private void setupVersion() { final String versionName = BuildConfig.VERSION_NAME; final String versionText = String.format(mRes.getString(R.string.version), versionName); - version.setText(versionText); + mVersion.setText(versionText); } private void setupCopyright() { final int year = Calendar.getInstance().get(Calendar.YEAR); final String copyrightText = String.format(mRes.getString(R.string.copyright), year); - copyright.setText(copyrightText); + mCopyright.setText(copyrightText); + } + + private void setupRateUs() { + if (Config.newInstance(getApplicationContext()).getIsFirstRun()) { + mRateUs.setVisibility(View.GONE); + } + } + + @OnClick(R.id.about_rate_us) + public void rateUsClicked() { + final Uri uri = Uri.parse("market://details?id=" + getPackageName()); + try { + startActivity(new Intent(Intent.ACTION_VIEW, uri)); + } catch (ActivityNotFoundException ignored) { + startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://play.google.com/store/apps/details?id=" + getPackageName()))); + } } @OnClick(R.id.about_license) diff --git a/app/src/main/java/com/simplemobiletools/gallery/activities/MainActivity.java b/app/src/main/java/com/simplemobiletools/gallery/activities/MainActivity.java index 000fa5f23..d33e9446e 100644 --- a/app/src/main/java/com/simplemobiletools/gallery/activities/MainActivity.java +++ b/app/src/main/java/com/simplemobiletools/gallery/activities/MainActivity.java @@ -28,6 +28,7 @@ import android.widget.EditText; import android.widget.GridView; import android.widget.TextView; +import com.simplemobiletools.gallery.Config; import com.simplemobiletools.gallery.Constants; import com.simplemobiletools.gallery.R; import com.simplemobiletools.gallery.Utils; @@ -121,6 +122,12 @@ public class MainActivity extends AppCompatActivity mState = mGridView.onSaveInstanceState(); } + @Override + protected void onDestroy() { + super.onDestroy(); + Config.newInstance(getApplicationContext()).setIsFirstRun(false); + } + private void tryloadGallery() { if (Utils.hasStoragePermission(getApplicationContext())) { initializeGallery(); diff --git a/app/src/main/res/layout/activity_about.xml b/app/src/main/res/layout/activity_about.xml index 344a5a0d9..e74fcd06b 100644 --- a/app/src/main/res/layout/activity_about.xml +++ b/app/src/main/res/layout/activity_about.xml @@ -29,11 +29,21 @@ android:text="@string/email"/> + + Send your feedback or suggestions at: hello@simplemobiletools.com Third party licences + Rate us in the Play Store Follow us at: v %1$s Copyright © Simple Mobile Tools %1$d