From b665ffd25f42747231e43955fcdb9c9538e032a3 Mon Sep 17 00:00:00 2001 From: h4h13 Date: Mon, 23 Sep 2019 00:26:40 +0530 Subject: [PATCH] Added App rater --- app/build.gradle | 2 +- app/src/main/assets/contributors.json | 2 +- .../retromusic/activities/MainActivity.kt | 6 +- .../retromusic/adapter/SongFileAdapter.kt | 8 +- .../fragments/player/color/ColorFragment.kt | 19 ++-- .../glide/RetroMusicColoredTarget.kt | 46 ++++++--- .../monkey/retromusic/transform/AppRater.kt | 99 +++++++++++++++++++ .../name/monkey/retromusic/util/ViewUtil.kt | 2 + app/src/main/res/drawable/line.xml | 25 +++++ app/src/main/res/drawable/line_drawable.xml | 23 +++++ app/src/main/res/drawable/thumb.xml | 25 +++++ app/src/main/res/drawable/thumb_drawable.xml | 19 ++++ app/src/main/res/layout/app_rating.xml | 74 ++++++++++++++ .../fragment_main_activity_recycler_view.xml | 3 - 14 files changed, 322 insertions(+), 31 deletions(-) create mode 100644 app/src/main/java/code/name/monkey/retromusic/transform/AppRater.kt create mode 100644 app/src/main/res/drawable/line.xml create mode 100644 app/src/main/res/drawable/line_drawable.xml create mode 100644 app/src/main/res/drawable/thumb.xml create mode 100644 app/src/main/res/drawable/thumb_drawable.xml create mode 100644 app/src/main/res/layout/app_rating.xml diff --git a/app/build.gradle b/app/build.gradle index a0453026..17f11287 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -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' diff --git a/app/src/main/assets/contributors.json b/app/src/main/assets/contributors.json index e9814ce2..858281b4 100644 --- a/app/src/main/assets/contributors.json +++ b/app/src/main/assets/contributors.json @@ -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" }, { diff --git a/app/src/main/java/code/name/monkey/retromusic/activities/MainActivity.kt b/app/src/main/java/code/name/monkey/retromusic/activities/MainActivity.kt index 5efbc752..d3644d71 100644 --- a/app/src/main/java/code/name/monkey/retromusic/activities/MainActivity.kt +++ b/app/src/main/java/code/name/monkey/retromusic/activities/MainActivity.kt @@ -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() { diff --git a/app/src/main/java/code/name/monkey/retromusic/adapter/SongFileAdapter.kt b/app/src/main/java/code/name/monkey/retromusic/adapter/SongFileAdapter.kt index 8672dfbf..1e92801d 100644 --- a/app/src/main/java/code/name/monkey/retromusic/adapter/SongFileAdapter.kt +++ b/app/src/main/java/code/name/monkey/retromusic/adapter/SongFileAdapter.kt @@ -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] } } } \ No newline at end of file diff --git a/app/src/main/java/code/name/monkey/retromusic/fragments/player/color/ColorFragment.kt b/app/src/main/java/code/name/monkey/retromusic/fragments/player/color/ColorFragment.kt index 8759262d..a29092d9 100644 --- a/app/src/main/java/code/name/monkey/retromusic/fragments/player/color/ColorFragment.kt +++ b/app/src/main/java/code/name/monkey/retromusic/fragments/player/color/ColorFragment.kt @@ -143,21 +143,24 @@ class ColorFragment : AbsPlayerFragment() { } - override fun onResourceReady(resource: BitmapPaletteWrapper, glideAnimation: GlideAnimation?) { + override fun onResourceReady(resource: BitmapPaletteWrapper?, glideAnimation: GlideAnimation?) { 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)) diff --git a/app/src/main/java/code/name/monkey/retromusic/glide/RetroMusicColoredTarget.kt b/app/src/main/java/code/name/monkey/retromusic/glide/RetroMusicColoredTarget.kt index 67bbb533..e7aa3ed1 100644 --- a/app/src/main/java/code/name/monkey/retromusic/glide/RetroMusicColoredTarget.kt +++ b/app/src/main/java/code/name/monkey/retromusic/glide/RetroMusicColoredTarget.kt @@ -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?) { + override fun onResourceReady(resource: BitmapPaletteWrapper?, glideAnimation: GlideAnimation?) { 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?) { + 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)*/ } diff --git a/app/src/main/java/code/name/monkey/retromusic/transform/AppRater.kt b/app/src/main/java/code/name/monkey/retromusic/transform/AppRater.kt new file mode 100644 index 00000000..77c6cf53 --- /dev/null +++ b/app/src/main/java/code/name/monkey/retromusic/transform/AppRater.kt @@ -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 +} \ No newline at end of file diff --git a/app/src/main/java/code/name/monkey/retromusic/util/ViewUtil.kt b/app/src/main/java/code/name/monkey/retromusic/util/ViewUtil.kt index 579fff37..0ce0f246 100644 --- a/app/src/main/java/code/name/monkey/retromusic/util/ViewUtil.kt +++ b/app/src/main/java/code/name/monkey/retromusic/util/ViewUtil.kt @@ -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 { diff --git a/app/src/main/res/drawable/line.xml b/app/src/main/res/drawable/line.xml new file mode 100644 index 00000000..9cefcb55 --- /dev/null +++ b/app/src/main/res/drawable/line.xml @@ -0,0 +1,25 @@ + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/line_drawable.xml b/app/src/main/res/drawable/line_drawable.xml new file mode 100644 index 00000000..9127b499 --- /dev/null +++ b/app/src/main/res/drawable/line_drawable.xml @@ -0,0 +1,23 @@ + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/thumb.xml b/app/src/main/res/drawable/thumb.xml new file mode 100644 index 00000000..28de2fc8 --- /dev/null +++ b/app/src/main/res/drawable/thumb.xml @@ -0,0 +1,25 @@ + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/thumb_drawable.xml b/app/src/main/res/drawable/thumb_drawable.xml new file mode 100644 index 00000000..e2368146 --- /dev/null +++ b/app/src/main/res/drawable/thumb_drawable.xml @@ -0,0 +1,19 @@ + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/app_rating.xml b/app/src/main/res/layout/app_rating.xml new file mode 100644 index 00000000..5bdcd9d1 --- /dev/null +++ b/app/src/main/res/layout/app_rating.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_main_activity_recycler_view.xml b/app/src/main/res/layout/fragment_main_activity_recycler_view.xml index a3b60933..eedfff89 100644 --- a/app/src/main/res/layout/fragment_main_activity_recycler_view.xml +++ b/app/src/main/res/layout/fragment_main_activity_recycler_view.xml @@ -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" />