Added App rater
This commit is contained in:
parent
07b1559350
commit
b665ffd25f
14 changed files with 322 additions and 31 deletions
|
@ -145,7 +145,7 @@ dependencies {
|
|||
implementation 'org.eclipse.mylyn.github:org.eclipse.egit.github.core:3.4.0.201406110918-r'
|
||||
|
||||
implementation 'com.github.ksoichiro:android-observablescrollview:1.6.0'
|
||||
implementation 'com.github.kabouzeid:RecyclerView-FastScroll:1.0.16-kmod'
|
||||
implementation 'com.github.kabouzeid:recyclerview-fastscroll:1.9-kmod'
|
||||
implementation 'com.github.kabouzeid:AndroidSlidingUpPanel:3.3.3-kmod'
|
||||
|
||||
implementation 'com.github.AdrienPoupa:jaudiotagger:2.2.3'
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
{
|
||||
"name": "Gaming Inc.",
|
||||
"summary": "Telegram group maintainer",
|
||||
"link": "https://t.me/Gaming_Inc",
|
||||
"link": "https://www.gaminginc.tk/",
|
||||
"profile_image": "https://i.imgur.com/pfvN7d9.png"
|
||||
},
|
||||
{
|
||||
|
|
|
@ -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 {
|
||||
|
|
25
app/src/main/res/drawable/line.xml
Normal file
25
app/src/main/res/drawable/line.xml
Normal file
|
@ -0,0 +1,25 @@
|
|||
<?xml version="1.0" encoding="utf-8"?><!--
|
||||
~ 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.
|
||||
-->
|
||||
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="rectangle">
|
||||
|
||||
<solid android:color="@android:color/darker_gray" />
|
||||
|
||||
<padding
|
||||
android:bottom="10dp"
|
||||
android:left="10dp"
|
||||
android:right="10dp"
|
||||
android:top="10dp" />
|
||||
</shape>
|
23
app/src/main/res/drawable/line_drawable.xml
Normal file
23
app/src/main/res/drawable/line_drawable.xml
Normal file
|
@ -0,0 +1,23 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
~ 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.
|
||||
-->
|
||||
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item
|
||||
android:state_pressed="true"
|
||||
android:drawable="@drawable/line"/>
|
||||
|
||||
<item
|
||||
android:drawable="@drawable/line"/>
|
||||
</selector>
|
25
app/src/main/res/drawable/thumb.xml
Normal file
25
app/src/main/res/drawable/thumb.xml
Normal file
|
@ -0,0 +1,25 @@
|
|||
<?xml version="1.0" encoding="utf-8"?><!--
|
||||
~ 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.
|
||||
-->
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="rectangle">
|
||||
|
||||
<corners android:radius="44dp" />
|
||||
|
||||
<padding
|
||||
android:paddingLeft="22dp"
|
||||
android:paddingRight="22dp" />
|
||||
|
||||
<solid android:color="@color/md_red_400" />
|
||||
|
||||
</shape>
|
19
app/src/main/res/drawable/thumb_drawable.xml
Normal file
19
app/src/main/res/drawable/thumb_drawable.xml
Normal file
|
@ -0,0 +1,19 @@
|
|||
<?xml version="1.0" encoding="utf-8"?><!--
|
||||
~ 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.
|
||||
-->
|
||||
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:drawable="@drawable/thumb" android:state_pressed="true" />
|
||||
|
||||
<item android:drawable="@drawable/thumb" />
|
||||
</selector>
|
74
app/src/main/res/layout/app_rating.xml
Normal file
74
app/src/main/res/layout/app_rating.xml
Normal file
|
@ -0,0 +1,74 @@
|
|||
<?xml version="1.0" encoding="utf-8"?><!--
|
||||
~ 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.
|
||||
-->
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<code.name.monkey.appthemehelper.common.views.BaselineGridTextView
|
||||
android:id="@+id/text"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="16dp"
|
||||
android:text="If you enjoy using Retro Music, please take a moment to rate it. Thanks for your support!"
|
||||
android:textAppearance="@style/TextAppearance.MaterialComponents.Headline6"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
tools:layout_editor_absoluteY="100dp">
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/rateButton"
|
||||
style="@style/Widget.MaterialComponents.Button.TextButton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Rate"
|
||||
app:backgroundTint="@color/md_red_400"
|
||||
app:cornerRadius="8dp"
|
||||
tools:layout_editor_absoluteX="1dp" />
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/laterButton"
|
||||
style="@style/Widget.MaterialComponents.Button.OutlinedButton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="16dp"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:text="May be later"
|
||||
android:textColor="@color/md_red_400"
|
||||
app:cornerRadius="8dp"
|
||||
app:layout_constraintLeft_toRightOf="@id/rateButton"
|
||||
app:strokeColor="@color/md_red_400"
|
||||
app:strokeWidth="1dp" />
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/noButton"
|
||||
style="@style/Widget.MaterialComponents.Button.UnelevatedButton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="16dp"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:text="No thanks"
|
||||
android:textColor="@color/md_red_400"
|
||||
app:cornerRadius="8dp"
|
||||
app:layout_constraintLeft_toRightOf="@id/laterButton" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
|
@ -11,9 +11,6 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:clipToPadding="false"
|
||||
app:fastScrollPopupBackgroundSize="48dp"
|
||||
app:fastScrollPopupTextSize="18sp"
|
||||
app:fastScrollHorizontalThumbDrawable="@drawable/button_background"
|
||||
android:layoutAnimation="@anim/layout_animation_fall_down"
|
||||
android:scrollbars="none" />
|
||||
|
||||
|
|
Loading…
Reference in a new issue