show a Rate us button to returning users

This commit is contained in:
tibbi 2016-07-01 15:04:31 +02:00
parent 42226e88d2
commit 9d5277a090
6 changed files with 75 additions and 8 deletions

View file

@ -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();
}
}

View file

@ -6,4 +6,8 @@ public class Constants {
public static final String GET_IMAGE_INTENT = "get_image_intent"; public static final String GET_IMAGE_INTENT = "get_image_intent";
public static final String GET_VIDEO_INTENT = "get_video_intent"; public static final String GET_VIDEO_INTENT = "get_video_intent";
public static final String SET_WALLPAPER_INTENT = "set_wallpaper_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";
} }

View file

@ -1,5 +1,6 @@
package com.simplemobiletools.gallery.activities; package com.simplemobiletools.gallery.activities;
import android.content.ActivityNotFoundException;
import android.content.Intent; import android.content.Intent;
import android.content.res.Resources; import android.content.res.Resources;
import android.net.Uri; import android.net.Uri;
@ -7,9 +8,11 @@ import android.os.Bundle;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
import android.text.Html; import android.text.Html;
import android.text.method.LinkMovementMethod; import android.text.method.LinkMovementMethod;
import android.view.View;
import android.widget.TextView; import android.widget.TextView;
import com.simplemobiletools.gallery.BuildConfig; import com.simplemobiletools.gallery.BuildConfig;
import com.simplemobiletools.gallery.Config;
import com.simplemobiletools.gallery.R; import com.simplemobiletools.gallery.R;
import java.util.Calendar; import java.util.Calendar;
@ -19,9 +22,10 @@ import butterknife.ButterKnife;
import butterknife.OnClick; import butterknife.OnClick;
public class AboutActivity extends AppCompatActivity { public class AboutActivity extends AppCompatActivity {
@BindView(R.id.about_copyright) TextView copyright; @BindView(R.id.about_copyright) TextView mCopyright;
@BindView(R.id.about_version) TextView version; @BindView(R.id.about_version) TextView mVersion;
@BindView(R.id.about_email) TextView emailTV; @BindView(R.id.about_email) TextView mEmailTV;
@BindView(R.id.about_rate_us) View mRateUs;
private static Resources mRes; private static Resources mRes;
@ -35,26 +39,43 @@ public class AboutActivity extends AppCompatActivity {
setupEmail(); setupEmail();
setupVersion(); setupVersion();
setupCopyright(); setupCopyright();
setupRateUs();
} }
private void setupEmail() { private void setupEmail() {
final String email = mRes.getString(R.string.email); final String email = mRes.getString(R.string.email);
final String appName = mRes.getString(R.string.app_name); final String appName = mRes.getString(R.string.app_name);
final String href = "<a href=\"mailto:" + email + "?subject=" + appName + "\">" + email + "</a>"; final String href = "<a href=\"mailto:" + email + "?subject=" + appName + "\">" + email + "</a>";
emailTV.setText(Html.fromHtml(href)); mEmailTV.setText(Html.fromHtml(href));
emailTV.setMovementMethod(LinkMovementMethod.getInstance()); mEmailTV.setMovementMethod(LinkMovementMethod.getInstance());
} }
private void setupVersion() { private void setupVersion() {
final String versionName = BuildConfig.VERSION_NAME; final String versionName = BuildConfig.VERSION_NAME;
final String versionText = String.format(mRes.getString(R.string.version), versionName); final String versionText = String.format(mRes.getString(R.string.version), versionName);
version.setText(versionText); mVersion.setText(versionText);
} }
private void setupCopyright() { private void setupCopyright() {
final int year = Calendar.getInstance().get(Calendar.YEAR); final int year = Calendar.getInstance().get(Calendar.YEAR);
final String copyrightText = String.format(mRes.getString(R.string.copyright), 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) @OnClick(R.id.about_license)

View file

@ -28,6 +28,7 @@ import android.widget.EditText;
import android.widget.GridView; import android.widget.GridView;
import android.widget.TextView; import android.widget.TextView;
import com.simplemobiletools.gallery.Config;
import com.simplemobiletools.gallery.Constants; import com.simplemobiletools.gallery.Constants;
import com.simplemobiletools.gallery.R; import com.simplemobiletools.gallery.R;
import com.simplemobiletools.gallery.Utils; import com.simplemobiletools.gallery.Utils;
@ -121,6 +122,12 @@ public class MainActivity extends AppCompatActivity
mState = mGridView.onSaveInstanceState(); mState = mGridView.onSaveInstanceState();
} }
@Override
protected void onDestroy() {
super.onDestroy();
Config.newInstance(getApplicationContext()).setIsFirstRun(false);
}
private void tryloadGallery() { private void tryloadGallery() {
if (Utils.hasStoragePermission(getApplicationContext())) { if (Utils.hasStoragePermission(getApplicationContext())) {
initializeGallery(); initializeGallery();

View file

@ -29,11 +29,21 @@
android:text="@string/email"/> android:text="@string/email"/>
<TextView <TextView
android:id="@+id/about_license" android:id="@+id/about_rate_us"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_below="@+id/about_email" android:layout_below="@+id/about_email"
android:layout_marginTop="@dimen/activity_margin" android:layout_marginTop="@dimen/activity_margin"
android:paddingTop="@dimen/activity_margin"
android:text="@string/rate_us_underlined"
android:textColor="@color/colorPrimary"/>
<TextView
android:id="@+id/about_license"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/about_rate_us"
android:layout_marginTop="@dimen/activity_margin"
android:paddingBottom="@dimen/activity_margin" android:paddingBottom="@dimen/activity_margin"
android:paddingTop="@dimen/activity_margin" android:paddingTop="@dimen/activity_margin"
android:text="@string/third_party_licences_underlined" android:text="@string/third_party_licences_underlined"

View file

@ -35,6 +35,7 @@
<string name="email_label">Send your feedback or suggestions at:</string> <string name="email_label">Send your feedback or suggestions at:</string>
<string name="email">hello@simplemobiletools.com</string> <string name="email">hello@simplemobiletools.com</string>
<string name="third_party_licences_underlined"><u>Third party licences</u></string> <string name="third_party_licences_underlined"><u>Third party licences</u></string>
<string name="rate_us_underlined"><u>Rate us in the Play Store</u></string>
<string name="follow_us">Follow us at:</string> <string name="follow_us">Follow us at:</string>
<string name="version">v %1$s</string> <string name="version">v %1$s</string>
<string name="copyright">Copyright © Simple Mobile Tools %1$d</string> <string name="copyright">Copyright © Simple Mobile Tools %1$d</string>