Added App rater
This commit is contained in:
parent
07b1559350
commit
b665ffd25f
14 changed files with 322 additions and 31 deletions
|
@ -19,6 +19,7 @@ import code.name.monkey.retromusic.loaders.AlbumLoader
|
|||
import code.name.monkey.retromusic.loaders.ArtistLoader
|
||||
import code.name.monkey.retromusic.loaders.PlaylistSongsLoader
|
||||
import code.name.monkey.retromusic.service.MusicService
|
||||
import code.name.monkey.retromusic.transform.AppRater
|
||||
import code.name.monkey.retromusic.util.PreferenceUtil
|
||||
import io.reactivex.disposables.CompositeDisposable
|
||||
import java.util.*
|
||||
|
@ -69,10 +70,7 @@ class MainActivity : AbsSlidingMusicPanelActivity(), SharedPreferences.OnSharedP
|
|||
}
|
||||
|
||||
checkShowChangelog()
|
||||
|
||||
/*if (!App.isProVersion && !PreferenceManager.getDefaultSharedPreferences(this).getBoolean("shown", false)) {
|
||||
showPromotionalOffer()
|
||||
}*/
|
||||
AppRater.appLaunched(this);
|
||||
}
|
||||
|
||||
private fun checkShowChangelog() {
|
||||
|
|
|
@ -20,6 +20,8 @@ import com.simplecityapps.recyclerview_fastscroll.views.FastScrollRecyclerView
|
|||
import java.io.File
|
||||
import java.text.DecimalFormat
|
||||
import java.util.*
|
||||
import kotlin.math.log10
|
||||
import kotlin.math.pow
|
||||
|
||||
|
||||
class SongFileAdapter(
|
||||
|
@ -174,10 +176,10 @@ class SongFileAdapter(
|
|||
private const val FOLDER = 1
|
||||
|
||||
fun readableFileSize(size: Long): String {
|
||||
if (size <= 0) return size.toString() + " B"
|
||||
if (size <= 0) return "$size B"
|
||||
val units = arrayOf("B", "KB", "MB", "GB", "TB")
|
||||
val digitGroups = (Math.log10(size.toDouble()) / Math.log10(1024.0)).toInt()
|
||||
return DecimalFormat("#,##0.##").format(size / Math.pow(1024.0, digitGroups.toDouble())) + " " + units[digitGroups]
|
||||
val digitGroups = (log10(size.toDouble()) / log10(1024.0)).toInt()
|
||||
return DecimalFormat("#,##0.##").format(size / 1024.0.pow(digitGroups.toDouble())) + " " + units[digitGroups]
|
||||
}
|
||||
}
|
||||
}
|
|
@ -143,21 +143,24 @@ class ColorFragment : AbsPlayerFragment() {
|
|||
|
||||
}
|
||||
|
||||
override fun onResourceReady(resource: BitmapPaletteWrapper, glideAnimation: GlideAnimation<in BitmapPaletteWrapper>?) {
|
||||
override fun onResourceReady(resource: BitmapPaletteWrapper?, glideAnimation: GlideAnimation<in BitmapPaletteWrapper>?) {
|
||||
super.onResourceReady(resource, glideAnimation)
|
||||
val background = resource.palette.getColor()
|
||||
resource?.let {
|
||||
val background = resource.palette.getColor()
|
||||
|
||||
|
||||
val palette = resource.palette
|
||||
val swatch = RetroColorUtil.getSwatch(palette)
|
||||
val palette = resource.palette
|
||||
val swatch = RetroColorUtil.getSwatch(palette)
|
||||
|
||||
val textColor = RetroColorUtil.getTextColor(palette)
|
||||
val backgroundColor = swatch.rgb
|
||||
val textColor = RetroColorUtil.getTextColor(palette)
|
||||
val backgroundColor = swatch.rgb
|
||||
|
||||
setColors(backgroundColor, textColor)
|
||||
}
|
||||
|
||||
setColors(backgroundColor, textColor)
|
||||
}
|
||||
|
||||
override fun onLoadFailed(e: Exception, errorDrawable: Drawable?) {
|
||||
override fun onLoadFailed(e: Exception?, errorDrawable: Drawable?) {
|
||||
super.onLoadFailed(e, errorDrawable)
|
||||
val backgroundColor = defaultFooterColor
|
||||
val textColor = if (ColorUtil.isColorLight(defaultFooterColor))
|
||||
|
|
|
@ -21,8 +21,7 @@ import code.name.monkey.retromusic.R
|
|||
import code.name.monkey.retromusic.glide.palette.BitmapPaletteTarget
|
||||
import code.name.monkey.retromusic.glide.palette.BitmapPaletteWrapper
|
||||
import code.name.monkey.retromusic.util.PreferenceUtil
|
||||
import code.name.monkey.retromusic.util.RetroColorUtil.getColor
|
||||
import code.name.monkey.retromusic.util.RetroColorUtil.getDominantColor
|
||||
import code.name.monkey.retromusic.util.RetroColorUtil
|
||||
import com.bumptech.glide.request.animation.GlideAnimation
|
||||
|
||||
|
||||
|
@ -34,22 +33,47 @@ abstract class RetroMusicColoredTarget(view: ImageView) : BitmapPaletteTarget(vi
|
|||
protected val albumArtistFooterColor: Int
|
||||
get() = ATHUtil.resolveColor(getView().context, R.attr.cardBackgroundColor)
|
||||
|
||||
override fun onLoadFailed(e: Exception, errorDrawable: Drawable?) {
|
||||
abstract fun onColorReady(color: Int)
|
||||
|
||||
override fun onLoadFailed(e: Exception?, errorDrawable: Drawable?) {
|
||||
super.onLoadFailed(e, errorDrawable)
|
||||
onColorReady(defaultFooterColor)
|
||||
}
|
||||
|
||||
override fun onResourceReady(resource: BitmapPaletteWrapper,
|
||||
glideAnimation: GlideAnimation<in BitmapPaletteWrapper>?) {
|
||||
override fun onResourceReady(resource: BitmapPaletteWrapper?, glideAnimation: GlideAnimation<in BitmapPaletteWrapper>?) {
|
||||
super.onResourceReady(resource, glideAnimation)
|
||||
|
||||
val defaultColor = defaultFooterColor
|
||||
|
||||
onColorReady(if (PreferenceUtil.getInstance(getView().context).isDominantColor)
|
||||
getDominantColor(resource.bitmap, defaultColor)
|
||||
else
|
||||
getColor(resource.palette, defaultColor))
|
||||
resource?.let {
|
||||
onColorReady(if (PreferenceUtil.getInstance(getView().context).isDominantColor)
|
||||
RetroColorUtil.getDominantColor(it.bitmap, defaultColor)
|
||||
else
|
||||
RetroColorUtil.getColor(it.palette, defaultColor))
|
||||
}
|
||||
}
|
||||
|
||||
abstract fun onColorReady(color: Int)
|
||||
/* protected val defaultFooterColor: Int
|
||||
get() = ATHUtil.resolveColor(getView().context, R.attr.defaultFooterColor)
|
||||
|
||||
protected val albumArtistFooterColor: Int
|
||||
get() = ATHUtil.resolveColor(getView().context, R.attr.cardBackgroundColor)
|
||||
|
||||
override fun onLoadFailed(e: Exception, errorDrawable: Drawable?) {
|
||||
super.onLoadFailed(e, errorDrawable)
|
||||
onColorReady(defaultFooterColor)
|
||||
}
|
||||
|
||||
override fun onResourceReady(resource: BitmapPaletteWrapper,
|
||||
glideAnimation: GlideAnimation<in BitmapPaletteWrapper>?) {
|
||||
super.onResourceReady(resource, glideAnimation)
|
||||
|
||||
val defaultColor = defaultFooterColor
|
||||
|
||||
onColorReady(if (PreferenceUtil.getInstance(getView().context).isDominantColor)
|
||||
getDominantColor(resource.bitmap, defaultColor)
|
||||
else
|
||||
getColor(resource.palette, defaultColor))
|
||||
}
|
||||
|
||||
abstract fun onColorReady(color: Int)*/
|
||||
}
|
||||
|
|
|
@ -0,0 +1,99 @@
|
|||
/*
|
||||
* 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.transform
|
||||
|
||||
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 code.name.monkey.retromusic.util.PreferenceUtil
|
||||
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 APP_TITLE = "Retro music"// App Name
|
||||
private const val APP_PNAME = "code.name.monkey.retromusic"// Package Name
|
||||
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
|
||||
print("LAUNCH COUNT: $launchCount")
|
||||
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}")))
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fun MaterialDialog.colorButtons(): MaterialDialog {
|
||||
getActionButton(WhichButton.NEGATIVE).updateTextColor(Color.RED)
|
||||
return this
|
||||
}
|
|
@ -38,6 +38,7 @@ import code.name.monkey.appthemehelper.util.MaterialValueHelper
|
|||
import code.name.monkey.retromusic.R
|
||||
import com.simplecityapps.recyclerview_fastscroll.views.FastScrollRecyclerView
|
||||
|
||||
|
||||
object ViewUtil {
|
||||
|
||||
const val RETRO_MUSIC_ANIM_TIME = 1000
|
||||
|
@ -121,6 +122,7 @@ object ViewUtil {
|
|||
recyclerView.setThumbColor(accentColor)
|
||||
recyclerView.setTrackColor(Color.TRANSPARENT)
|
||||
recyclerView.setTrackColor(ColorUtil.withAlpha(ATHUtil.resolveColor(context, R.attr.colorControlNormal), 0.12f));
|
||||
|
||||
}
|
||||
|
||||
fun convertDpToPixel(dp: Float, resources: Resources): Float {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue