Removed unwanted resources

This commit is contained in:
h4h13 2019-10-26 19:16:01 +05:30
parent cddf9db608
commit 914b2316c3
9 changed files with 8 additions and 143 deletions

View file

@ -0,0 +1,91 @@
/*
* Copyright (c) 2019 Hemanth Savarala.
*
* Licensed under the GNU General Public License v3
*
* This is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by
* the Free Software Foundation either version 3 of the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*/
package code.name.monkey.retromusic.util
import android.content.Context
import android.content.Intent
import android.content.SharedPreferences
import android.graphics.Color
import android.net.Uri
import code.name.monkey.retromusic.R
import com.afollestad.materialdialogs.LayoutMode
import com.afollestad.materialdialogs.MaterialDialog
import com.afollestad.materialdialogs.WhichButton
import com.afollestad.materialdialogs.actions.getActionButton
import com.afollestad.materialdialogs.bottomsheets.BottomSheet
object AppRater {
private const val DO_NOT_SHOW_AGAIN = "do_not_show_again"// Package Name
private const val APP_RATING = "app_rating"// Package Name
private const val LAUNCH_COUNT = "launch_count"// Package Name
private const val DATE_FIRST_LAUNCH = "date_first_launch"// Package Name
private const val DAYS_UNTIL_PROMPT = 3//Min number of days
private const val LAUNCHES_UNTIL_PROMPT = 5//Min number of launches
fun appLaunched(context: Context) {
val prefs = context.getSharedPreferences(APP_RATING, 0)
if (prefs.getBoolean(DO_NOT_SHOW_AGAIN, false)) {
return
}
val editor = prefs.edit()
// Increment launch counter
val launchCount = prefs.getLong(LAUNCH_COUNT, 0) + 1
editor.putLong(LAUNCH_COUNT, launchCount)
// Get date of first launch
var dateFirstLaunch = prefs.getLong(DATE_FIRST_LAUNCH, 0)
if (dateFirstLaunch == 0L) {
dateFirstLaunch = System.currentTimeMillis()
editor.putLong(DATE_FIRST_LAUNCH, dateFirstLaunch)
}
// Wait at least n days before opening
if (launchCount >= LAUNCHES_UNTIL_PROMPT) {
if (System.currentTimeMillis() >= dateFirstLaunch + DAYS_UNTIL_PROMPT * 24 * 60 * 60 * 1000) {
showRateDialog(context, editor)
}
}
editor.commit()
}
private fun showRateDialog(context: Context, editor: SharedPreferences.Editor) {
MaterialDialog(context, BottomSheet(LayoutMode.WRAP_CONTENT))
.show {
cornerRadius(PreferenceUtil.getInstance(context).dialogCorner)
title(text = "Rate this App")
message(text = "If you enjoy using Retro Music, please take a moment to rate it. Thanks for your support!")
positiveButton(R.string.app_name) {
context.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=${context.packageName}")))
editor.putBoolean(DO_NOT_SHOW_AGAIN, true)
editor.commit()
dismiss()
}
negativeButton(text = "Later") {
dismiss()
}
neutralButton(text = " No thanks") {
editor.putBoolean(DO_NOT_SHOW_AGAIN, true)
editor.commit()
dismiss()
}
getActionButton(WhichButton.POSITIVE).updateTextColor(Color.RED)
}
}
}