From 21d59f02744ea859abe6605a552f270f17d1150e Mon Sep 17 00:00:00 2001 From: h4h13 Date: Wed, 6 May 2020 18:16:07 +0530 Subject: [PATCH] Added premium show --- .../retromusic/activities/MainActivity.java | 2 + .../monkey/retromusic/util/PremiumShow.kt | 37 +++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 app/src/main/java/code/name/monkey/retromusic/util/PremiumShow.kt diff --git a/app/src/main/java/code/name/monkey/retromusic/activities/MainActivity.java b/app/src/main/java/code/name/monkey/retromusic/activities/MainActivity.java index 443b3ecf..4e661631 100644 --- a/app/src/main/java/code/name/monkey/retromusic/activities/MainActivity.java +++ b/app/src/main/java/code/name/monkey/retromusic/activities/MainActivity.java @@ -93,6 +93,7 @@ import code.name.monkey.retromusic.service.MusicService; import code.name.monkey.retromusic.util.AppRater; import code.name.monkey.retromusic.util.NavigationUtil; import code.name.monkey.retromusic.util.PreferenceUtil; +import code.name.monkey.retromusic.util.PremiumShow; import code.name.monkey.retromusic.util.RetroColorUtil; import code.name.monkey.retromusic.util.RetroUtil; @@ -184,6 +185,7 @@ public class MainActivity extends AbsSlidingMusicPanelActivity //checkShowChangelog(); AppRater.appLaunched(this); + //PremiumShow.launch(this); setupToolbar(); checkUpdate(); } diff --git a/app/src/main/java/code/name/monkey/retromusic/util/PremiumShow.kt b/app/src/main/java/code/name/monkey/retromusic/util/PremiumShow.kt new file mode 100644 index 00000000..32adff22 --- /dev/null +++ b/app/src/main/java/code/name/monkey/retromusic/util/PremiumShow.kt @@ -0,0 +1,37 @@ +package code.name.monkey.retromusic.util + +import android.content.Context +import android.content.Intent +import androidx.core.app.ActivityCompat +import code.name.monkey.retromusic.App +import code.name.monkey.retromusic.activities.PurchaseActivity + +object PremiumShow { + private const val PREF_NAME = "premium_show" + private const val LAUNCH_COUNT = "launch_count" + private const val DATE_FIRST_LAUNCH = "date_first_launch" + @JvmStatic + fun launch(context: Context) { + val pref = context.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE) + if (App.isProVersion()) { + return + } + val prefEditor = pref.edit() + val launchCount = pref.getLong(LAUNCH_COUNT, 0) + 1 + prefEditor.putLong(LAUNCH_COUNT, launchCount) + + var dateLaunched = pref.getLong(DATE_FIRST_LAUNCH, 0) + if (dateLaunched == 0L) { + dateLaunched = System.currentTimeMillis() + prefEditor.putLong(DATE_FIRST_LAUNCH, dateLaunched) + } + if (System.currentTimeMillis() >= dateLaunched + 2 * 24 * 60 * 60 * 1000) { + ActivityCompat.startActivity( + context, + Intent(context, PurchaseActivity::class.java), + null + ) + } + prefEditor.apply() + } +} \ No newline at end of file