[Cleanup] Fixing Warnings

This commit is contained in:
Prathamesh More 2021-11-27 14:06:49 +05:30
parent 1fdd537253
commit fa976b1cba
68 changed files with 242 additions and 498 deletions

View file

@ -126,7 +126,7 @@ dependencies {
def retrofit_version = '2.9.0'
implementation "com.squareup.retrofit2:retrofit:$retrofit_version"
implementation "com.squareup.retrofit2:converter-gson:$retrofit_version"
implementation 'com.squareup.okhttp3:logging-interceptor:5.0.0-alpha.2'
implementation 'com.squareup.okhttp3:logging-interceptor:5.0.0-alpha.3'
def material_dialog_version = "3.3.0"
implementation "com.afollestad.material-dialogs:core:$material_dialog_version"

View file

@ -132,7 +132,7 @@ abstract class AbsBaseActivity : AbsThemeActivity() {
permissionDeniedMessage!!,
Snackbar.LENGTH_INDEFINITE
)
.setAction(code.name.monkey.retromusic.R.string.action_grant) { requestPermissions() }
.setAction(R.string.action_grant) { requestPermissions() }
.setActionTextColor(ThemeStore.accentColor(this)).show()
} else {
// User has deny permission and checked never show permission dialog so you can redirect to Application settings page
@ -140,7 +140,7 @@ abstract class AbsBaseActivity : AbsThemeActivity() {
snackBarContainer,
permissionDeniedMessage!!,
Snackbar.LENGTH_INDEFINITE
).setAction(code.name.monkey.retromusic.R.string.action_settings) {
).setAction(R.string.action_settings) {
val intent = Intent()
intent.action = Settings.ACTION_APPLICATION_DETAILS_SETTINGS
val uri = Uri.fromParts(

View file

@ -14,7 +14,6 @@
*/
package code.name.monkey.retromusic.adapter
import android.os.Handler
import android.os.SystemClock
import android.view.LayoutInflater
import android.view.View
@ -25,8 +24,6 @@ import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.AppCompatTextView
import androidx.core.os.bundleOf
import androidx.fragment.app.findFragment
import androidx.lifecycle.findViewTreeLifecycleOwner
import androidx.lifecycle.lifecycleScope
import androidx.navigation.findNavController
import androidx.navigation.fragment.FragmentNavigatorExtras
import androidx.recyclerview.widget.GridLayoutManager
@ -49,7 +46,6 @@ import code.name.monkey.retromusic.interfaces.IGenreClickListener
import code.name.monkey.retromusic.model.*
import code.name.monkey.retromusic.util.PreferenceUtil
import com.google.android.material.card.MaterialCardView
import kotlinx.coroutines.delay
class HomeAdapter(
private val activity: AppCompatActivity
@ -204,7 +200,7 @@ class HomeAdapter(
if (SystemClock.elapsedRealtime() - mLastClickTime < 1000){
return@setOnClickListener
}
mLastClickTime = SystemClock.elapsedRealtime();
mLastClickTime = SystemClock.elapsedRealtime()
MusicPlayerRemote.playNext((home.arrayList as List<Song>).subList(0, 8))
if (!MusicPlayerRemote.isPlaying) {
MusicPlayerRemote.playNextSong()

View file

@ -27,13 +27,13 @@ import code.name.monkey.retromusic.R
import code.name.monkey.retromusic.activities.MainActivity
import code.name.monkey.retromusic.fragments.AlbumCoverStyle
import code.name.monkey.retromusic.fragments.NowPlayingScreen.*
import code.name.monkey.retromusic.fragments.base.goToLyrics
import code.name.monkey.retromusic.glide.GlideApp
import code.name.monkey.retromusic.glide.RetroGlideExtension
import code.name.monkey.retromusic.glide.RetroMusicColoredTarget
import code.name.monkey.retromusic.misc.CustomFragmentStatePagerAdapter
import code.name.monkey.retromusic.model.Song
import code.name.monkey.retromusic.util.MusicUtil
import code.name.monkey.retromusic.util.NavigationUtil
import code.name.monkey.retromusic.util.PreferenceUtil
import code.name.monkey.retromusic.util.color.MediaNotificationProcessor
import com.google.android.material.bottomsheet.BottomSheetBehavior.STATE_EXPANDED
@ -127,7 +127,8 @@ class AlbumCoverPagerAdapter(
setTitle(song.title)
setMessage(if (data.isNullOrEmpty()) "No lyrics found" else data)
setNegativeButton(R.string.synced_lyrics) { _, _ ->
NavigationUtil.goToLyrics(requireActivity())
goToLyrics(requireActivity())
}
show()
}

View file

@ -188,7 +188,7 @@ class PlayingQueueAdapter(
private const val UP_NEXT = 2
}
override fun onSwipeItem(holder: ViewHolder, position: Int, result: Int): SwipeResultAction? {
override fun onSwipeItem(holder: ViewHolder, position: Int, result: Int): SwipeResultAction {
return if (result == SwipeableItemConstants.RESULT_CANCELED) {
SwipeResultActionDefault()
} else {

View file

@ -42,6 +42,6 @@ class LastAddedShortcutType(context: Context) : BaseShortcutType(context) {
companion object {
val id: String
get() = BaseShortcutType.ID_PREFIX + "last_added"
get() = ID_PREFIX + "last_added"
}
}

View file

@ -40,6 +40,6 @@ class TopTracksShortcutType(context: Context) : BaseShortcutType(context) {
companion object {
val id: String
get() = BaseShortcutType.ID_PREFIX + "top_tracks"
get() = ID_PREFIX + "top_tracks"
}
}

View file

@ -62,7 +62,7 @@ class AppWidgetBig : BaseAppWidget() {
context,
R.drawable.ic_skip_next,
MaterialValueHelper.getPrimaryTextColor(context, false)
)!!, 1f
), 1f
)
)
appWidgetView.setImageViewBitmap(
@ -71,16 +71,16 @@ class AppWidgetBig : BaseAppWidget() {
context,
R.drawable.ic_skip_previous,
MaterialValueHelper.getPrimaryTextColor(context, false)
)!!, 1f
), 1f
)
)
appWidgetView.setImageViewBitmap(
R.id.button_toggle_play_pause, BaseAppWidget.createBitmap(
R.id.button_toggle_play_pause, createBitmap(
RetroUtil.getTintedVectorDrawable(
context,
R.drawable.ic_play_arrow_white_32dp,
MaterialValueHelper.getPrimaryTextColor(context, false)
)!!, 1f
), 1f
)
)
@ -127,7 +127,7 @@ class AppWidgetBig : BaseAppWidget() {
service,
playPauseRes,
primaryColor
)!!, 1f
), 1f
)
)
@ -138,7 +138,7 @@ class AppWidgetBig : BaseAppWidget() {
service,
R.drawable.ic_skip_next,
primaryColor
)!!, 1f
), 1f
)
)
appWidgetView.setImageViewBitmap(
@ -147,7 +147,7 @@ class AppWidgetBig : BaseAppWidget() {
service,
R.drawable.ic_skip_previous,
primaryColor
)!!, 1f
), 1f
)
)
@ -156,7 +156,7 @@ class AppWidgetBig : BaseAppWidget() {
// Load the album cover async and push the update on completion
val p = RetroUtil.getScreenSize(service)
val widgetImageSize = Math.min(p.x, p.y)
val widgetImageSize = p.x.coerceAtMost(p.y)
val appContext = service.applicationContext
service.runOnUiThread {
if (target != null) {

View file

@ -60,7 +60,7 @@ class AppWidgetCard : BaseAppWidget() {
context,
R.drawable.ic_skip_next,
secondaryColor
)!!, 1f
), 1f
)
)
appWidgetView.setImageViewBitmap(
@ -69,7 +69,7 @@ class AppWidgetCard : BaseAppWidget() {
context,
R.drawable.ic_skip_previous,
secondaryColor
)!!, 1f
), 1f
)
)
appWidgetView.setImageViewBitmap(
@ -78,7 +78,7 @@ class AppWidgetCard : BaseAppWidget() {
context,
R.drawable.ic_play_arrow_white_32dp,
secondaryColor
)!!, 1f
), 1f
)
)
@ -113,7 +113,7 @@ class AppWidgetCard : BaseAppWidget() {
service,
playPauseRes,
MaterialValueHelper.getSecondaryTextColor(service, true)
)!!, 1f
), 1f
)
)
@ -124,7 +124,7 @@ class AppWidgetCard : BaseAppWidget() {
service,
R.drawable.ic_skip_next,
MaterialValueHelper.getSecondaryTextColor(service, true)
)!!, 1f
), 1f
)
)
appWidgetView.setImageViewBitmap(
@ -133,7 +133,7 @@ class AppWidgetCard : BaseAppWidget() {
service,
R.drawable.ic_skip_previous,
MaterialValueHelper.getSecondaryTextColor(service, true)
)!!, 1f
), 1f
)
)

View file

@ -61,7 +61,7 @@ class AppWidgetClassic : BaseAppWidget() {
context,
R.drawable.ic_skip_next,
MaterialValueHelper.getSecondaryTextColor(context, true)
)!!, 1f
), 1f
)
)
appWidgetView.setImageViewBitmap(
@ -71,7 +71,7 @@ class AppWidgetClassic : BaseAppWidget() {
context,
R.drawable.ic_skip_previous,
MaterialValueHelper.getSecondaryTextColor(context, true)
)!!, 1f
), 1f
)
)
appWidgetView.setImageViewBitmap(
@ -81,7 +81,7 @@ class AppWidgetClassic : BaseAppWidget() {
context,
R.drawable.ic_play_arrow_white_32dp,
MaterialValueHelper.getSecondaryTextColor(context, true)
)!!, 1f
), 1f
)
)

View file

@ -59,7 +59,7 @@ class AppWidgetSmall : BaseAppWidget() {
context,
R.drawable.ic_skip_next,
MaterialValueHelper.getSecondaryTextColor(context, true)
)!!, 1f
), 1f
)
)
appWidgetView.setImageViewBitmap(
@ -69,7 +69,7 @@ class AppWidgetSmall : BaseAppWidget() {
context,
R.drawable.ic_skip_previous,
MaterialValueHelper.getSecondaryTextColor(context, true)
)!!, 1f
), 1f
)
)
appWidgetView.setImageViewBitmap(
@ -79,7 +79,7 @@ class AppWidgetSmall : BaseAppWidget() {
context,
R.drawable.ic_play_arrow_white_32dp,
MaterialValueHelper.getSecondaryTextColor(context, true)
)!!, 1f
), 1f
)
)
@ -161,7 +161,7 @@ class AppWidgetSmall : BaseAppWidget() {
R.id.button_toggle_play_pause, createBitmap(
RetroUtil.getTintedVectorDrawable(
service, playPauseRes, color
)!!, 1f
), 1f
)
)
@ -170,14 +170,14 @@ class AppWidgetSmall : BaseAppWidget() {
R.id.button_next, createBitmap(
RetroUtil.getTintedVectorDrawable(
service, R.drawable.ic_skip_next, color
)!!, 1f
), 1f
)
)
appWidgetView.setImageViewBitmap(
R.id.button_prev, createBitmap(
RetroUtil.getTintedVectorDrawable(
service, R.drawable.ic_skip_previous, color
)!!, 1f
), 1f
)
)

View file

@ -18,7 +18,6 @@ import android.app.PendingIntent
import android.content.ComponentName
import android.content.Context
import android.content.Intent
import android.provider.MediaStore
import android.text.TextUtils
import android.view.View
import android.widget.RemoteViews
@ -43,7 +42,7 @@ class AppWidgetText : BaseAppWidget() {
context, R.drawable.ic_skip_next, ContextCompat.getColor(
context, R.color.md_white_1000
)
)!!, 1f
), 1f
)
)
appWidgetView.setImageViewBitmap(
@ -52,7 +51,7 @@ class AppWidgetText : BaseAppWidget() {
context, R.drawable.ic_skip_previous, ContextCompat.getColor(
context, R.color.md_white_1000
)
)!!, 1f
), 1f
)
)
appWidgetView.setImageViewBitmap(
@ -61,7 +60,7 @@ class AppWidgetText : BaseAppWidget() {
context, R.drawable.ic_play_arrow_white_32dp, ContextCompat.getColor(
context, R.color.md_white_1000
)
)!!, 1f
), 1f
)
)
@ -137,7 +136,7 @@ class AppWidgetText : BaseAppWidget() {
App.getContext(), playPauseRes, ContextCompat.getColor(
App.getContext(), R.color.md_white_1000
)
)!!, 1f
), 1f
)
)
appWidgetView.setImageViewBitmap(
@ -148,7 +147,7 @@ class AppWidgetText : BaseAppWidget() {
ContextCompat.getColor(
App.getContext(), R.color.md_white_1000
)
)!!, 1f
), 1f
)
)
appWidgetView.setImageViewBitmap(
@ -159,7 +158,7 @@ class AppWidgetText : BaseAppWidget() {
ContextCompat.getColor(
App.getContext(), R.color.md_white_1000
)
)!!, 1f
), 1f
)
)

View file

@ -11,6 +11,7 @@ import com.google.android.gms.cast.MediaInfo.STREAM_TYPE_BUFFERED
import com.google.android.gms.cast.MediaMetadata.*
import com.google.android.gms.cast.framework.CastSession
import com.google.android.gms.common.images.WebImage
import org.json.JSONObject
import java.net.MalformedURLException
import java.net.URL
@ -41,7 +42,7 @@ object CastHelper {
position,
MediaStatus.REPEAT_MODE_REPEAT_OFF,
progress,
null
JSONObject()
)
} catch (e: Exception) {
e.printStackTrace()

View file

@ -13,7 +13,7 @@ class ExpandedControlsActivity : ExpandedControllerActivity() {
override fun onCreateOptionsMenu(menu: Menu?): Boolean {
super.onCreateOptionsMenu(menu)
menuInflater.inflate(R.menu.menu_cast, menu)
CastButtonFactory.setUpMediaRouteButton(this, menu, R.id.action_cast)
CastButtonFactory.setUpMediaRouteButton(this, menu!!, R.id.action_cast)
return true
}
}

View file

@ -17,7 +17,7 @@ class RetroWebServer(val context: Context) : NanoHTTPD(SERVER_PORT) {
const val PART_COVER_ART = "coverart"
const val PART_SONG = "song"
const val PARAM_ID = "id"
var mRetroWebServer: RetroWebServer? = null
private var mRetroWebServer: RetroWebServer? = null
fun getInstance(context: Context): RetroWebServer {
if (mRetroWebServer == null) {
mRetroWebServer = RetroWebServer(context)

View file

@ -139,7 +139,7 @@ class DeleteSongsDialog : DialogFragment() {
}
}
fun reloadTabs() {
private fun reloadTabs() {
libraryViewModel.forceReload(ReloadType.Songs)
libraryViewModel.forceReload(ReloadType.HomeSections)
libraryViewModel.forceReload(ReloadType.Artists)

View file

@ -78,7 +78,7 @@ fun isBlack(fArr: FloatArray): Boolean {
fun isNearRedLine(fArr: FloatArray): Boolean {
val f = fArr[0]
return f >= 10.0f && f <= 37.0f && fArr[1] <= 0.82f
return f in 10.0f..37.0f && fArr[1] <= 0.82f
}
fun isDark(@ColorInt i: Int): Boolean {

View file

@ -43,7 +43,7 @@ class LibraryViewModel(
private val legacyPlaylists = MutableLiveData<List<Playlist>>()
private val genres = MutableLiveData<List<Genre>>()
private val searchResults = MutableLiveData<List<Any>>()
private val fabMargin = MutableLiveData<Int>(0)
private val fabMargin = MutableLiveData(0)
val paletteColor: LiveData<Int> = _paletteColor
init {
@ -227,7 +227,7 @@ class LibraryViewModel(
repository.deleteRoomPlaylist(playlists)
}
suspend fun albumById(id: Long) = repository.albumById(id)
fun albumById(id: Long) = repository.albumById(id)
suspend fun artistById(id: Long) = repository.artistById(id)
suspend fun favoritePlaylist() = repository.favoritePlaylist()
suspend fun isFavoriteSong(song: SongEntity) = repository.isFavoriteSong(song)

View file

@ -405,9 +405,8 @@ class AlbumDetailsFragment : AbsMainActivityFragment(R.layout.fragment_album_det
binding.albumCoverContainer,
"${getString(R.string.transition_album_art)}_${album.id}"
)
startActivityForResult(
intent,
TAG_EDITOR_REQUEST, options.toBundle()
startActivity(
intent, options.toBundle()
)
return true
}
@ -499,8 +498,4 @@ class AlbumDetailsFragment : AbsMainActivityFragment(R.layout.fragment_album_det
super.onDestroyView()
_binding = null
}
companion object {
const val TAG_EDITOR_REQUEST = 9002
}
}

View file

@ -70,7 +70,7 @@ class BackupFragment : Fragment(R.layout.fragment_backup), BackupAdapter.BackupC
}
private fun checkIsEmpty() {
val isEmpty = backupAdapter!!.itemCount == 0
val isEmpty = backupAdapter?.itemCount == 0
binding.backupTitle.isVisible = !isEmpty
binding.backupRecyclerview.isVisible = !isEmpty
}

View file

@ -41,7 +41,6 @@ import code.name.monkey.retromusic.adapter.StorageAdapter
import code.name.monkey.retromusic.adapter.StorageClickListener
import code.name.monkey.retromusic.databinding.FragmentFolderBinding
import code.name.monkey.retromusic.extensions.drawNextToNavbar
import code.name.monkey.retromusic.extensions.navigate
import code.name.monkey.retromusic.extensions.surfaceColor
import code.name.monkey.retromusic.fragments.base.AbsMainActivityFragment
import code.name.monkey.retromusic.fragments.folder.FoldersFragment.ListPathsAsyncTask.OnPathsListedCallback
@ -725,9 +724,10 @@ class FoldersFragment : AbsMainActivityFragment(R.layout.fragment_folder),
}
abstract class ListingFilesDialogAsyncTask<Params, Progress, Result> :
DialogAsyncTask<Params, Progress, Result> {
internal constructor(context: Context?) : super(context)
abstract class ListingFilesDialogAsyncTask<Params, Progress, Result> internal constructor(
context: Context?
) :
DialogAsyncTask<Params, Progress, Result>(context) {
override fun createDialog(context: Context): Dialog {
return MaterialAlertDialogBuilder(context)

View file

@ -162,30 +162,26 @@ open class MiniPlayerFragment : AbsMusicServiceFragment(R.layout.fragment_mini_p
class FlingPlayBackController(context: Context) : View.OnTouchListener {
private var flingPlayBackController: GestureDetector
init {
flingPlayBackController = GestureDetector(context,
object : GestureDetector.SimpleOnGestureListener() {
override fun onFling(
e1: MotionEvent,
e2: MotionEvent,
velocityX: Float,
velocityY: Float
): Boolean {
if (abs(velocityX) > abs(velocityY)) {
if (velocityX < 0) {
MusicPlayerRemote.playNextSong()
return true
} else if (velocityX > 0) {
MusicPlayerRemote.playPreviousSong()
return true
}
private var flingPlayBackController = GestureDetector(context,
object : GestureDetector.SimpleOnGestureListener() {
override fun onFling(
e1: MotionEvent,
e2: MotionEvent,
velocityX: Float,
velocityY: Float
): Boolean {
if (abs(velocityX) > abs(velocityY)) {
if (velocityX < 0) {
MusicPlayerRemote.playNextSong()
return true
} else if (velocityX > 0) {
MusicPlayerRemote.playPreviousSong()
return true
}
return false
}
})
}
return false
}
})
@SuppressLint("ClickableViewAccessibility")
override fun onTouch(v: View, event: MotionEvent): Boolean {

View file

@ -32,6 +32,7 @@ import code.name.monkey.retromusic.databinding.FragmentPlayerAlbumCoverBinding
import code.name.monkey.retromusic.fragments.NowPlayingScreen.*
import code.name.monkey.retromusic.fragments.base.AbsMusicServiceFragment
import code.name.monkey.retromusic.fragments.base.AbsPlayerFragment
import code.name.monkey.retromusic.fragments.base.goToLyrics
import code.name.monkey.retromusic.helper.MusicPlayerRemote
import code.name.monkey.retromusic.helper.MusicProgressViewUpdateHelper
import code.name.monkey.retromusic.model.lyrics.AbsSynchronizedLyrics
@ -39,7 +40,6 @@ import code.name.monkey.retromusic.model.lyrics.Lyrics
import code.name.monkey.retromusic.transform.CarousalPagerTransformer
import code.name.monkey.retromusic.transform.ParallaxPagerTransformer
import code.name.monkey.retromusic.util.LyricUtil
import code.name.monkey.retromusic.util.NavigationUtil
import code.name.monkey.retromusic.util.PreferenceUtil
import code.name.monkey.retromusic.util.color.MediaNotificationProcessor
import kotlinx.coroutines.Dispatchers
@ -214,7 +214,7 @@ class PlayerAlbumCoverFragment : AbsMusicServiceFragment(R.layout.fragment_playe
}
// Go to lyrics activity when clicked lyrics
binding.playerLyricsLine2.setOnClickListener {
NavigationUtil.goToLyrics(requireActivity())
goToLyrics(requireActivity())
}
}

View file

@ -63,7 +63,7 @@ class CirclePlayerFragment : AbsPlayerFragment(R.layout.fragment_circle_player),
private lateinit var progressViewUpdateHelper: MusicProgressViewUpdateHelper
private var audioVolumeObserver: AudioVolumeObserver? = null
private val audioManager: AudioManager?
private val audioManager: AudioManager
get() = requireContext().getSystemService(Context.AUDIO_SERVICE) as AudioManager
private var _binding: FragmentCirclePlayerBinding? = null
@ -239,7 +239,7 @@ class CirclePlayerFragment : AbsPlayerFragment(R.layout.fragment_circle_player),
override fun onProgressChanged(seekArc: SeekArc?, progress: Int, fromUser: Boolean) {
val audioManager = audioManager
audioManager?.setStreamVolume(AudioManager.STREAM_MUSIC, progress, 0)
audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, progress, 0)
}
override fun onStartTrackingTouch(seekArc: SeekArc?) {

View file

@ -247,7 +247,7 @@ class ClassicPlayerFragment : AbsPlayerFragment(R.layout.fragment_classic_player
updateQueue()
}
override fun playerToolbar(): Toolbar? {
override fun playerToolbar(): Toolbar {
return binding.playerToolbar
}

View file

@ -316,7 +316,7 @@ class FullPlaybackControlsFragment :
fun updateIsFavorite(animate: Boolean = false) {
lifecycleScope.launch(Dispatchers.IO) {
val playlist: PlaylistEntity? = libraryViewModel.favoritePlaylist()
val playlist: PlaylistEntity = libraryViewModel.favoritePlaylist()
if (playlist != null) {
val song: SongEntity =
MusicPlayerRemote.currentSong.toSongEntity(playlist.playListId)
@ -327,7 +327,7 @@ class FullPlaybackControlsFragment :
} else {
if (isFavorite) R.drawable.ic_favorite else R.drawable.ic_favorite_border
}
val drawable: Drawable? = RetroUtil.getTintedVectorDrawable(
val drawable: Drawable = RetroUtil.getTintedVectorDrawable(
requireContext(),
icon,
Color.WHITE
@ -347,7 +347,7 @@ class FullPlaybackControlsFragment :
private fun toggleFavorite(song: Song) {
lifecycleScope.launch(Dispatchers.IO) {
val playlist: PlaylistEntity? = libraryViewModel.favoritePlaylist()
val playlist: PlaylistEntity = libraryViewModel.favoritePlaylist()
if (playlist != null) {
val songEntity = song.toSongEntity(playlist.playListId)
val isFavorite = libraryViewModel.isFavoriteSong(songEntity).isNotEmpty()

View file

@ -281,7 +281,7 @@ class GradientPlayerFragment : AbsPlayerFragment(R.layout.fragment_gradient_play
private fun updateIsFavoriteIcon(animate: Boolean = false) {
lifecycleScope.launch(Dispatchers.IO) {
val playlist: PlaylistEntity? = libraryViewModel.favoritePlaylist()
val playlist: PlaylistEntity = libraryViewModel.favoritePlaylist()
if (playlist != null) {
val song: SongEntity =
MusicPlayerRemote.currentSong.toSongEntity(playlist.playListId)

View file

@ -26,7 +26,7 @@ object M3UWriter : M3UConstants {
fun write(
dir: File,
playlist: Playlist
): File? {
): File {
if (!dir.exists()) dir.mkdirs()
val file = File(dir, playlist.name + "." + M3UConstants.EXTENSION)
val songs = playlist.getSongs()

View file

@ -16,6 +16,7 @@ package code.name.monkey.retromusic.helper
import android.os.Handler
import android.os.Message
import kotlin.math.max
class MusicProgressViewUpdateHelper : Handler {
@ -62,7 +63,7 @@ class MusicProgressViewUpdateHelper : Handler {
val remainingMillis = intervalPlaying - progressMillis % intervalPlaying
return Math.max(MIN_INTERVAL, remainingMillis)
return max(MIN_INTERVAL, remainingMillis)
}
private fun queueNextRefresh(delay: Long) {

View file

@ -134,7 +134,7 @@ class SortOrder {
companion object {
/* Artist song sort order A-Z */
const val SONG_A_Z = MediaStore.Audio.Media.DEFAULT_SORT_ORDER
private const val SONG_A_Z = MediaStore.Audio.Media.DEFAULT_SORT_ORDER
/* Artist song sort order Z-A */
const val SONG_Z_A = "$SONG_A_Z DESC"

View file

@ -76,8 +76,8 @@ public class StackBlur {
original.getPixels(currentPixels, 0, w, 0, 0, w, h);
int cores = EXECUTOR_THREADS;
ArrayList<BlurTask> horizontal = new ArrayList<BlurTask>(cores);
ArrayList<BlurTask> vertical = new ArrayList<BlurTask>(cores);
ArrayList<BlurTask> horizontal = new ArrayList<>(cores);
ArrayList<BlurTask> vertical = new ArrayList<>(cores);
for (int i = 0; i < cores; i++) {
horizontal.add(new BlurTask(currentPixels, w, h, (int) radius, cores, i, 1));
vertical.add(new BlurTask(currentPixels, w, h, (int) radius, cores, i, 2));
@ -158,7 +158,7 @@ public class StackBlur {
for (x = 0; x < w; x++) {
src[dst_i] =
(int)
((src[dst_i] & 0xFFFFFFFF)
((src[dst_i])
| ((((sum_r * mul_sum) >>> shr_sum) & 0xff) << 16)
| ((((sum_g * mul_sum) >>> shr_sum) & 0xff) << 8)
| ((((sum_b * mul_sum) >>> shr_sum) & 0xff)));
@ -245,7 +245,7 @@ public class StackBlur {
for (y = 0; y < h; y++) {
src[dst_i] =
(int)
((src[dst_i] & 0xFFFFFFFF)
((src[dst_i])
| ((((sum_r * mul_sum) >>> shr_sum) & 0xff) << 16)
| ((((sum_g * mul_sum) >>> shr_sum) & 0xff) << 8)
| ((((sum_b * mul_sum) >>> shr_sum) & 0xff)));

View file

@ -1,138 +0,0 @@
package code.name.monkey.retromusic.lyrics;
import android.content.Context;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* Desc : 歌词解析 Author : Lauzy Date : 2017/10/13 Blog : http://www.jianshu.com/u/e76853f863a9 Email :
* freedompaladin@gmail.com
*/
public class LrcHelper {
private static final String CHARSET = "utf-8";
// [03:56.00][03:18.00][02:06.00][01:07.00]原谅我这一生不羁放纵爱自由
private static final String LINE_REGEX = "((\\[\\d{2}:\\d{2}\\.\\d{2}])+)(.*)";
private static final String TIME_REGEX = "\\[(\\d{2}):(\\d{2})\\.(\\d{2})]";
public static List<Lrc> parseLrcFromAssets(Context context, String fileName) {
try {
return parseInputStream(context.getResources().getAssets().open(fileName));
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
public static List<Lrc> parseLrcFromFile(File file) {
try {
return parseInputStream(new FileInputStream(file));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
return null;
}
private static List<Lrc> parseInputStream(InputStream inputStream) {
List<Lrc> lrcs = new ArrayList<>();
InputStreamReader isr = null;
BufferedReader br = null;
try {
isr = new InputStreamReader(inputStream, CHARSET);
br = new BufferedReader(isr);
String line;
while ((line = br.readLine()) != null) {
List<Lrc> lrcList = parseLrc(line);
if (lrcList != null && lrcList.size() != 0) {
lrcs.addAll(lrcList);
}
}
sortLrcs(lrcs);
return lrcs;
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (isr != null) {
isr.close();
}
if (br != null) {
br.close();
}
} catch (IOException e1) {
e1.printStackTrace();
}
}
return lrcs;
}
private static void sortLrcs(List<Lrc> lrcs) {
Collections.sort(
lrcs,
new Comparator<Lrc>() {
@Override
public int compare(Lrc o1, Lrc o2) {
return (int) (o1.getTime() - o2.getTime());
}
});
}
private static List<Lrc> parseLrc(String lrcLine) {
if (lrcLine.trim().isEmpty()) {
return null;
}
List<Lrc> lrcs = new ArrayList<>();
Matcher matcher = Pattern.compile(LINE_REGEX).matcher(lrcLine);
if (!matcher.matches()) {
return null;
}
String time = matcher.group(1);
String content = matcher.group(3);
Matcher timeMatcher = Pattern.compile(TIME_REGEX).matcher(time);
while (timeMatcher.find()) {
String min = timeMatcher.group(1);
String sec = timeMatcher.group(2);
String mil = timeMatcher.group(3);
Lrc lrc = new Lrc();
if (content != null && content.length() != 0) {
lrc.setTime(
Long.parseLong(min) * 60 * 1000
+ Long.parseLong(sec) * 1000
+ Long.parseLong(mil) * 10);
lrc.setText(content);
lrcs.add(lrc);
}
}
return lrcs;
}
public static String formatTime(long time) {
int min = (int) (time / 60000);
int sec = (int) (time / 1000 % 60);
return adjustFormat(min) + ":" + adjustFormat(sec);
}
private static String adjustFormat(int time) {
if (time < 10) {
return "0" + time;
}
return time + "";
}
}

View file

@ -78,8 +78,8 @@ public abstract class CustomFragmentStatePagerAdapter extends PagerAdapter {
private final FragmentManager mFragmentManager;
private FragmentTransaction mCurTransaction = null;
private final ArrayList<Fragment.SavedState> mSavedState = new ArrayList<Fragment.SavedState>();
private final ArrayList<Fragment> mFragments = new ArrayList<Fragment>();
private final ArrayList<Fragment.SavedState> mSavedState = new ArrayList<>();
private final ArrayList<Fragment> mFragments = new ArrayList<>();
private Fragment mCurrentPrimaryItem = null;
public CustomFragmentStatePagerAdapter(FragmentManager fm) {
@ -212,8 +212,8 @@ public abstract class CustomFragmentStatePagerAdapter extends PagerAdapter {
mSavedState.clear();
mFragments.clear();
if (fss != null) {
for (int i = 0; i < fss.length; i++) {
mSavedState.add((Fragment.SavedState) fss[i]);
for (Parcelable parcelable : fss) {
mSavedState.add((Fragment.SavedState) parcelable);
}
}
Iterable<String> keys = bundle.keySet();

View file

@ -148,7 +148,7 @@ class AlbumCoverStylePreferenceDialog : DialogFragment(),
return view === instace
}
override fun getPageTitle(position: Int): CharSequence? {
override fun getPageTitle(position: Int): CharSequence {
return context.getString(values()[position].titleRes)
}
}

View file

@ -153,7 +153,7 @@ private class NowPlayingScreenAdapter(private val context: Context) : PagerAdapt
return view === instance
}
override fun getPageTitle(position: Int): CharSequence? {
override fun getPageTitle(position: Int): CharSequence {
return context.getString(values()[position].titleRes)
}
}

View file

@ -84,30 +84,23 @@ public class HistoryStore extends SQLiteOpenHelper {
database.insert(RecentStoreColumns.NAME, null, values);
// if our db is too large, delete the extra items
Cursor oldest = null;
try {
oldest =
database.query(
RecentStoreColumns.NAME,
new String[] {RecentStoreColumns.TIME_PLAYED},
null,
null,
null,
null,
RecentStoreColumns.TIME_PLAYED + " ASC");
try (Cursor oldest = database.query(
RecentStoreColumns.NAME,
new String[]{RecentStoreColumns.TIME_PLAYED},
null,
null,
null,
null,
RecentStoreColumns.TIME_PLAYED + " ASC")) {
if (oldest != null && oldest.getCount() > MAX_ITEMS_IN_DB) {
oldest.moveToPosition(oldest.getCount() - MAX_ITEMS_IN_DB);
long timeOfRecordToKeep = oldest.getLong(0);
database.delete(
RecentStoreColumns.NAME,
RecentStoreColumns.TIME_PLAYED + " < ?",
new String[] {String.valueOf(timeOfRecordToKeep)});
}
} finally {
if (oldest != null) {
oldest.close();
RecentStoreColumns.NAME,
RecentStoreColumns.TIME_PLAYED + " < ?",
new String[]{String.valueOf(timeOfRecordToKeep)});
}
}
} finally {

View file

@ -40,14 +40,11 @@ public class SongPlayCountStore extends SQLiteOpenHelper {
@NonNull
private static final Interpolator sInterpolator = new AccelerateInterpolator(1.5f);
// how high to multiply the interpolation curve
@SuppressWarnings("FieldCanBeLocal")
private static final int INTERPOLATOR_HEIGHT = 50;
// how high the base value is. The ratio of the Height to Base is what really matters
@SuppressWarnings("FieldCanBeLocal")
private static final int INTERPOLATOR_BASE = 25;
@SuppressWarnings("FieldCanBeLocal")
private static final int ONE_WEEK_IN_MS = 1000 * 60 * 60 * 24 * 7;
@NonNull
@ -257,7 +254,7 @@ public class SongPlayCountStore extends SQLiteOpenHelper {
for (int i = 0; i < NUM_WEEKS - weekDiff; i++) {
playCounts[i + weekDiff] = cursor.getInt(getColumnIndexForWeek(i));
}
} else if (weekDiff < 0) {
} else {
// time is shifted backwards (by user) - nor typical behavior but we
// will still handle it

View file

@ -75,7 +75,7 @@ class RealTopPlayedRepository(
val notRecentlyPlayedSongs = songRepository.songs(
makeNotRecentTracksCursorAndClearUpDatabase()
)
allSongs.removeAll(playedSongs)
allSongs.removeAll(playedSongs.toSet())
allSongs.addAll(notRecentlyPlayedSongs)
return allSongs
}

View file

@ -245,7 +245,6 @@ public class MusicService extends MediaBrowserServiceCompat
private List<Song> originalPlayingQueue = new ArrayList<>();
private List<Song> playingQueue = new ArrayList<>();
private boolean pausedByTransientLossOfFocus;
private AudioVolumeObserver audioVolumeObserver = null;
private final BroadcastReceiver becomingNoisyReceiver =
new BroadcastReceiver() {
@ -453,7 +452,7 @@ public class MusicService extends MediaBrowserServiceCompat
.registerContentObserver(
MediaStore.Audio.Playlists.INTERNAL_CONTENT_URI, true, mediaStoreObserver);
audioVolumeObserver = new AudioVolumeObserver(this);
AudioVolumeObserver audioVolumeObserver = new AudioVolumeObserver(this);
audioVolumeObserver.register(AudioManager.STREAM_MUSIC, this);
PreferenceUtil.INSTANCE.registerOnSharedPreferenceChangedListener(this);

View file

@ -38,6 +38,6 @@ class ThrottledSeekHandler(
companion object {
// milliseconds to throttle before calling run() to aggregate events
private val THROTTLE: Long = 500
private const val THROTTLE: Long = 500
}
}

View file

@ -54,7 +54,7 @@ class PlayingNotificationImpl : PlayingNotification(), KoinComponent {
stopped = false
GlobalScope.launch {
val song = service.currentSong
val playlist: PlaylistEntity? = MusicUtil.repository.favoritePlaylist()
val playlist: PlaylistEntity = MusicUtil.repository.favoritePlaylist()
val isPlaying = service.isPlaying
val isFavorite = if (playlist != null) {
val songEntity = song.toSongEntity(playlist.playListId)

View file

@ -183,21 +183,21 @@ class PlayingNotificationOreo : PlayingNotification() {
service,
R.drawable.ic_close,
primary
)!!, NOTIFICATION_CONTROLS_SIZE_MULTIPLIER
), NOTIFICATION_CONTROLS_SIZE_MULTIPLIER
)
val prev = createBitmap(
RetroUtil.getTintedVectorDrawable(
service,
R.drawable.ic_skip_previous_round_white_32dp,
primary
)!!, NOTIFICATION_CONTROLS_SIZE_MULTIPLIER
), NOTIFICATION_CONTROLS_SIZE_MULTIPLIER
)
val next = createBitmap(
RetroUtil.getTintedVectorDrawable(
service,
R.drawable.ic_skip_next_round_white_32dp,
primary
)!!, NOTIFICATION_CONTROLS_SIZE_MULTIPLIER
), NOTIFICATION_CONTROLS_SIZE_MULTIPLIER
)
val playPause = createBitmap(
RetroUtil.getTintedVectorDrawable(
@ -206,7 +206,7 @@ class PlayingNotificationOreo : PlayingNotification() {
R.drawable.ic_pause_white_48dp
else
R.drawable.ic_play_arrow_white_48dp, primary
)!!, NOTIFICATION_CONTROLS_SIZE_MULTIPLIER
), NOTIFICATION_CONTROLS_SIZE_MULTIPLIER
)
notificationLayout.setTextColor(R.id.title, primary)
@ -233,7 +233,7 @@ class PlayingNotificationOreo : PlayingNotification() {
service,
R.drawable.ic_notification,
secondary
)!!, 0.6f
), 0.6f
)
)
notificationLayoutBig.setImageViewBitmap(
@ -243,7 +243,7 @@ class PlayingNotificationOreo : PlayingNotification() {
service,
R.drawable.ic_notification,
secondary
)!!, 0.6f
), 0.6f
)
)

View file

@ -16,26 +16,32 @@ package code.name.monkey.retromusic.transform
import android.view.View
import androidx.viewpager.widget.ViewPager
import kotlin.math.abs
class DepthTransformation : ViewPager.PageTransformer {
override fun transformPage(page: View, position: Float) {
if (position < -1) { // [-Infinity,-1)
// This page is way off-screen to the left.
page.alpha = 0f
} else if (position <= 0) { // [-1,0]
page.alpha = 1f
page.translationX = 0f
page.scaleX = 1f
page.scaleY = 1f
} else if (position <= 1) { // (0,1]
page.translationX = -position * page.width
page.alpha = 1 - Math.abs(position)
page.scaleX = 1 - Math.abs(position)
page.scaleY = 1 - Math.abs(position)
} else { // (1,+Infinity]
// This page is way off-screen to the right.
page.alpha = 0f
when {
position < -1 -> { // [-Infinity,-1)
// This page is way off-screen to the left.
page.alpha = 0f
}
position <= 0 -> { // [-1,0]
page.alpha = 1f
page.translationX = 0f
page.scaleX = 1f
page.scaleY = 1f
}
position <= 1 -> { // (0,1]
page.translationX = -position * page.width
page.alpha = 1 - abs(position)
page.scaleX = 1 - abs(position)
page.scaleY = 1 - abs(position)
}
else -> { // (1,+Infinity]
// This page is way off-screen to the right.
page.alpha = 0f
}
}
}
}

View file

@ -16,6 +16,7 @@ package code.name.monkey.retromusic.transform
import android.view.View
import androidx.viewpager.widget.ViewPager
import kotlin.math.abs
class HorizontalFlipTransformation : ViewPager.PageTransformer {
override fun transformPage(page: View, position: Float) {
@ -36,11 +37,11 @@ class HorizontalFlipTransformation : ViewPager.PageTransformer {
} else if (position <= 0) { // [-1,0]
page.alpha = 1f
page.rotationX = 180 * (1 - Math.abs(position) + 1)
page.rotationX = 180 * (1 - abs(position) + 1)
} else if (position <= 1) { // (0,1]
page.alpha = 1f
page.rotationX = -180 * (1 - Math.abs(position) + 1)
page.rotationX = -180 * (1 - abs(position) + 1)
} else { // (1,+Infinity]
// This page is way off-screen to the right.

View file

@ -16,6 +16,8 @@ package code.name.monkey.retromusic.transform
import android.view.View
import androidx.viewpager.widget.ViewPager
import kotlin.math.abs
import kotlin.math.max
/**
* @author Hemanth S (h4h13).
@ -33,7 +35,7 @@ class NormalPageTransformer : ViewPager.PageTransformer {
view.scaleY = 0.7f
} else if (position <= 1) { // [-1,1]
// Modify the default slide transition to shrink the page as well
val scaleFactor = Math.max(MIN_SCALE, 1 - Math.abs(position))
val scaleFactor = max(MIN_SCALE, 1 - abs(position))
val vertMargin = pageHeight * (1 - scaleFactor) / 2
val horzMargin = pageWidth * (1 - scaleFactor) / 2
if (position < 0) {
@ -57,7 +59,7 @@ class NormalPageTransformer : ViewPager.PageTransformer {
}
companion object {
private val MIN_SCALE = 0.85f
private val MIN_ALPHA = 0.5f
private const val MIN_SCALE = 0.85f
private const val MIN_ALPHA = 0.5f
}
}

View file

@ -16,6 +16,7 @@ package code.name.monkey.retromusic.transform
import android.view.View
import androidx.viewpager.widget.ViewPager
import kotlin.math.abs
class VerticalFlipTransformation : ViewPager.PageTransformer {
override fun transformPage(page: View, position: Float) {
@ -36,11 +37,11 @@ class VerticalFlipTransformation : ViewPager.PageTransformer {
} else if (position <= 0) { // [-1,0]
page.alpha = 1f
page.rotationY = 180 * (1 - Math.abs(position) + 1)
page.rotationY = 180 * (1 - abs(position) + 1)
} else if (position <= 1) { // (0,1]
page.alpha = 1f
page.rotationY = -180 * (1 - Math.abs(position) + 1)
page.rotationY = -180 * (1 - abs(position) + 1)
} else { // (1,+Infinity]
// This page is way off-screen to the right.

View file

@ -348,7 +348,7 @@ object MusicUtil : KoinComponent {
val repository = get<Repository>()
fun toggleFavorite(context: Context, song: Song) {
GlobalScope.launch {
val playlist: PlaylistEntity? = repository.favoritePlaylist()
val playlist: PlaylistEntity = repository.favoritePlaylist()
if (playlist != null) {
val songEntity = song.toSongEntity(playlist.playListId)
val isFavorite = repository.isFavoriteSong(songEntity).isNotEmpty()
@ -529,7 +529,7 @@ object MusicUtil : KoinComponent {
val pendingIntent = MediaStore.createDeleteRequest(activity.contentResolver, songs.map {
getSongFileUri(it.id)
})
activity.startIntentSenderForResult(pendingIntent.intentSender, 45, null, 0, 0, 0, null);
activity.startIntentSenderForResult(pendingIntent.intentSender, 45, null, 0, 0, 0, null)
}
fun songByGenre(genreId: Long): Song {

View file

@ -20,12 +20,10 @@ import android.content.Intent
import android.media.audiofx.AudioEffect
import android.widget.Toast
import androidx.core.app.ActivityCompat
import androidx.navigation.findNavController
import code.name.monkey.retromusic.R
import code.name.monkey.retromusic.activities.*
import code.name.monkey.retromusic.activities.bugreport.BugReportActivity
import code.name.monkey.retromusic.helper.MusicPlayerRemote.audioSessionId
import com.google.android.material.bottomsheet.BottomSheetBehavior
object NavigationUtil {
fun bugReport(activity: Activity) {
@ -40,21 +38,6 @@ object NavigationUtil {
ActivityCompat.startActivity(activity, Intent(activity, LicenseActivity::class.java), null)
}
fun goToLyrics(activity: Activity) {
if (activity !is MainActivity) return
activity.apply {
//Hide Bottom Bar First, else Bottom Sheet doesn't collapse fully
setBottomNavVisibility(false)
if (getBottomSheetBehavior().state == BottomSheetBehavior.STATE_EXPANDED) {
collapsePanel()
}
findNavController(R.id.fragment_container).navigate(
R.id.lyrics_fragment
)
}
}
fun goToProVersion(context: Context) {
ActivityCompat.startActivity(context, Intent(context, PurchaseActivity::class.java), null)
}

View file

@ -208,11 +208,11 @@ class PackageValidator(
private fun getSignature(packageInfo: PackageInfo): String? {
// Security best practices dictate that an app should be signed with exactly one (1)
// signature. Because of this, if there are multiple signatures, reject it.
if (packageInfo.signatures == null || packageInfo.signatures.size != 1) {
return null
return if (packageInfo.signatures == null || packageInfo.signatures.size != 1) {
null
} else {
val certificate = packageInfo.signatures[0].toByteArray()
return getSignatureSha256(certificate)
getSignatureSha256(certificate)
}
}

View file

@ -36,7 +36,6 @@ import java.util.List;
import code.name.monkey.retromusic.R;
import code.name.monkey.retromusic.db.PlaylistWithSongs;
import code.name.monkey.retromusic.helper.M3UConstants;
import code.name.monkey.retromusic.helper.M3UWriter;
import code.name.monkey.retromusic.model.Playlist;
import code.name.monkey.retromusic.model.PlaylistSong;

View file

@ -188,7 +188,7 @@ public class RetroColorUtil {
public static int getDominantColor(Bitmap bitmap, int defaultFooterColor) {
List<Palette.Swatch> swatchesTemp = Palette.from(bitmap).generate().getSwatches();
List<Palette.Swatch> swatches = new ArrayList<Palette.Swatch>(swatchesTemp);
List<Palette.Swatch> swatches = new ArrayList<>(swatchesTemp);
Collections.sort(
swatches, (swatch1, swatch2) -> swatch2.getPopulation() - swatch1.getPopulation());
return swatches.size() > 0 ? swatches.get(0).getRgb() : defaultFooterColor;

View file

@ -40,7 +40,7 @@ import androidx.annotation.ColorInt;
import androidx.annotation.DrawableRes;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.vectordrawable.graphics.drawable.VectorDrawableCompat;
import androidx.core.content.res.ResourcesCompat;
import java.net.InetAddress;
import java.net.NetworkInterface;
@ -127,14 +127,14 @@ public class RetroUtil {
return result;
}
@Nullable
@NonNull
public static Drawable getTintedVectorDrawable(
@NonNull Context context, @DrawableRes int id, @ColorInt int color) {
return TintHelper.createTintedDrawable(
getVectorDrawable(context.getResources(), id, context.getTheme()), color);
}
@Nullable
@NonNull
public static Drawable getTintedVectorDrawable(
@NonNull Resources res,
@DrawableRes int resId,
@ -146,10 +146,7 @@ public class RetroUtil {
@Nullable
public static Drawable getVectorDrawable(
@NonNull Resources res, @DrawableRes int resId, @Nullable Resources.Theme theme) {
if (Build.VERSION.SDK_INT >= 21) {
return res.getDrawable(resId, theme);
}
return VectorDrawableCompat.create(res, resId, theme);
return ResourcesCompat.getDrawable(res, resId, theme);
}
public static void hideSoftKeyboard(@Nullable Activity activity) {

View file

@ -75,11 +75,9 @@ public class MediaNotificationProcessor {
*/
private static final int LIGHTNESS_TEXT_DIFFERENCE_DARK = -10;
private static final String TAG = "ColorPicking";
private float[] mFilteredBackgroundHsl = null;
private final Palette.Filter mBlackWhiteFilter =
(rgb, hsl) -> !isWhiteOrBlack(hsl);
private boolean mIsLowPriority;
private int backgroundColor;
private int secondaryTextColor;
private int primaryTextColor;
@ -376,10 +374,6 @@ public class MediaNotificationProcessor {
return hslColor[2] >= WHITE_MIN_LIGHTNESS;
}
public void setIsLowPriority(boolean isLowPriority) {
mIsLowPriority = isLowPriority;
}
private void ensureColors(int backgroundColor, int mForegroundColor) {
{
double backLum = NotificationColorUtil.calculateLuminance(backgroundColor);

View file

@ -55,7 +55,7 @@ public class NotificationColorUtil {
private final ImageUtils mImageUtils = new ImageUtils();
private final WeakHashMap<Bitmap, Pair<Boolean, Integer>> mGrayscaleBitmapCache =
new WeakHashMap<Bitmap, Pair<Boolean, Integer>>();
new WeakHashMap<>();
private final int mGrayscaleIconMaxSize; // @dimen/notification_large_icon_width (64dp)
@ -831,11 +831,11 @@ public class NotificationColorUtil {
}
private static int constrain(int amount, int low, int high) {
return amount < low ? low : (amount > high ? high : amount);
return amount < low ? low : (Math.min(amount, high));
}
private static float constrain(float amount, float low, float high) {
return amount < low ? low : (amount > high ? high : amount);
return amount < low ? low : (Math.min(amount, high));
}
private static double pivotXyzComponent(double component) {

View file

@ -39,9 +39,7 @@ public class SeekArc extends View {
private static final String TAG = SeekArc.class.getSimpleName();
private static final int INVALID_PROGRESS_VALUE = -1;
// The initial rotational offset -90 means we start at 12 o'clock
private final int mAngleOffset = -90;
private Paint mArcPaint;
private Paint mArcPaint;
// Internal variables
private int mArcRadius = 0;
private final RectF mArcRect = new RectF();
@ -77,8 +75,7 @@ public class SeekArc extends View {
private int mThumbXPos;
private int mThumbYPos;
private double mTouchAngle;
private float mTouchIgnoreRadius;
private float mTouchIgnoreRadius;
/** Enable touch inside the SeekArc */
private boolean mTouchInside = true;
@ -243,8 +240,8 @@ public class SeekArc extends View {
}
public void setTouchInSide(boolean isEnabled) {
int thumbHalfheight = (int) mThumb.getIntrinsicHeight() / 2;
int thumbHalfWidth = (int) mThumb.getIntrinsicWidth() / 2;
int thumbHalfheight = mThumb.getIntrinsicHeight() / 2;
int thumbHalfWidth = mThumb.getIntrinsicWidth() / 2;
mTouchInside = isEnabled;
if (mTouchInside) {
mTouchIgnoreRadius = (float) mArcRadius / 4;
@ -271,7 +268,9 @@ public class SeekArc extends View {
}
// Draw the arcs
final int arcStart = mStartAngle + mAngleOffset + mRotation;
// The initial rotational offset -90 means we start at 12 o'clock
int mAngleOffset = -90;
final int arcStart = mStartAngle + mAngleOffset + mRotation;
final int arcSweep = mSweepAngle;
canvas.drawArc(mArcRect, arcStart, arcSweep, false, mArcPaint);
canvas.drawArc(mArcRect, arcStart, mProgressSweep, false, mProgressPaint);
@ -368,8 +367,8 @@ public class SeekArc extends View {
mThumb = thumb;
}
thumbHalfheight = (int) mThumb.getIntrinsicHeight() / 2;
thumbHalfWidth = (int) mThumb.getIntrinsicWidth() / 2;
thumbHalfheight = mThumb.getIntrinsicHeight() / 2;
thumbHalfWidth = mThumb.getIntrinsicWidth() / 2;
mThumb.setBounds(-thumbHalfWidth, -thumbHalfheight, thumbHalfWidth, thumbHalfheight);
mMax = a.getInteger(R.styleable.SeekArc_max, mMax);
@ -390,16 +389,16 @@ public class SeekArc extends View {
a.recycle();
}
mProgress = (mProgress > mMax) ? mMax : mProgress;
mProgress = (mProgress < 0) ? 0 : mProgress;
mProgress = Math.min(mProgress, mMax);
mProgress = Math.max(mProgress, 0);
mSweepAngle = (mSweepAngle > 360) ? 360 : mSweepAngle;
mSweepAngle = (mSweepAngle < 0) ? 0 : mSweepAngle;
mSweepAngle = Math.min(mSweepAngle, 360);
mSweepAngle = Math.max(mSweepAngle, 0);
mProgressSweep = (float) mProgress / mMax * mSweepAngle;
mStartAngle = (mStartAngle > 360) ? 0 : mStartAngle;
mStartAngle = (mStartAngle < 0) ? 0 : mStartAngle;
mStartAngle = Math.max(mStartAngle, 0);
mArcPaint = new Paint();
mArcPaint.setColor(arcColor);
@ -442,7 +441,7 @@ public class SeekArc extends View {
return;
}
setPressed(true);
mTouchAngle = getTouchDegrees(event.getX(), event.getY());
double mTouchAngle = getTouchDegrees(event.getX(), event.getY());
int progress = getProgressForAngle(mTouchAngle);
onProgressRefresh(progress, true);
}

View file

@ -2,14 +2,9 @@ package code.name.monkey.retromusic.views.insets
import android.content.Context
import android.util.AttributeSet
import android.view.WindowInsets
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.core.view.WindowInsetsCompat
import code.name.monkey.retromusic.extensions.drawAboveSystemBarsWithPadding
import code.name.monkey.retromusic.extensions.recordInitialPaddingForView
import code.name.monkey.retromusic.extensions.requestApplyInsetsWhenAttached
import code.name.monkey.retromusic.util.RetroUtil
import com.afollestad.materialdialogs.utils.MDUtil.updatePadding
class InsetsConstraintLayout @JvmOverloads constructor(
context: Context,

View file

@ -4,7 +4,8 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
android:fitsSystemWindows="true"
android:transitionGroup="true">
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/appBarLayout"

View file

@ -4,8 +4,7 @@
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/scrollView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:transitionGroup="true">
android:layout_height="wrap_content">
<LinearLayout
android:id="@+id/container"

View file

@ -1,2 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<resources></resources>

View file

@ -74,7 +74,7 @@ object ATH {
setActivityToolbarColor(activity, toolbar, ThemeStore.primaryColor(activity))
}
fun setActivityToolbarColor(
private fun setActivityToolbarColor(
activity: Activity, toolbar: Toolbar?,
color: Int
) {

View file

@ -23,7 +23,7 @@ open class ATHActivity : AppCompatActivity() {
}
}
fun onThemeChanged() {
private fun onThemeChanged() {
postRecreate()
}

View file

@ -56,7 +56,7 @@ public class ATEPreferenceDialogFragment extends DialogFragment implements Dialo
} else {
DialogPreference.TargetFragment fragment = (DialogPreference.TargetFragment) rawFragment;
String key = this.getArguments().getString(ARG_KEY);
this.mPreference = (DialogPreference) fragment.findPreference(key);
this.mPreference = fragment.findPreference(key);
}
}
@ -96,7 +96,7 @@ public class ATEPreferenceDialogFragment extends DialogFragment implements Dialo
}
@Override
public void onDismiss(DialogInterface dialog) {
public void onDismiss(@NonNull DialogInterface dialog) {
super.onDismiss(dialog);
Log.i(TAG, "onDismiss: " + mWhichButtonClicked);
onDialogClosed(mWhichButtonClicked == DialogInterface.BUTTON_POSITIVE);

View file

@ -3,6 +3,7 @@ package code.name.monkey.appthemehelper.util
import android.graphics.Color
import androidx.annotation.ColorInt
import androidx.annotation.FloatRange
import kotlin.math.*
object ColorUtil {
fun desaturateColor(color: Int, ratio: Float): Int {
@ -59,7 +60,7 @@ object ColorUtil {
@ColorInt
fun adjustAlpha(@ColorInt color: Int, @FloatRange(from = 0.0, to = 1.0) factor: Float): Int {
val alpha = Math.round(Color.alpha(color) * factor)
val alpha = (Color.alpha(color) * factor).roundToInt()
val red = Color.red(color)
val green = Color.green(color)
val blue = Color.blue(color)
@ -68,7 +69,7 @@ object ColorUtil {
@ColorInt
fun withAlpha(@ColorInt baseColor: Int, @FloatRange(from = 0.0, to = 1.0) alpha: Float): Int {
val a = Math.min(255, Math.max(0, (alpha * 255).toInt())) shl 24
val a = min(255, max(0, (alpha * 255).toInt())) shl 24
val rgb = 0x00ffffff and baseColor
return a + rgb
}
@ -100,15 +101,15 @@ object ColorUtil {
}
fun isColorSaturated(@ColorInt color: Int): Boolean {
val max = Math.max(
val max = max(
0.299 * Color.red(color),
Math.max(0.587 * Color.green(color), 0.114 * Color.blue(color))
max(0.587 * Color.green(color), 0.114 * Color.blue(color))
)
val min = Math.min(
val min = min(
0.299 * Color.red(color),
Math.min(0.587 * Color.green(color), 0.114 * Color.blue(color))
min(0.587 * Color.green(color), 0.114 * Color.blue(color))
)
val diff = Math.abs(max - min)
val diff = abs(max - min)
return diff > 20
}
@ -121,10 +122,10 @@ object ColorUtil {
)
}
fun getDifference(@ColorInt color1: Int, @ColorInt color2: Int): Double {
var diff = Math.abs(0.299 * (Color.red(color1) - Color.red(color2)))
diff += Math.abs(0.587 * (Color.green(color1) - Color.green(color2)))
diff += Math.abs(0.114 * (Color.blue(color1) - Color.blue(color2)))
private fun getDifference(@ColorInt color1: Int, @ColorInt color2: Int): Double {
var diff = abs(0.299 * (Color.red(color1) - Color.red(color2)))
diff += abs(0.587 * (Color.green(color1) - Color.green(color2)))
diff += abs(0.114 * (Color.blue(color1) - Color.blue(color2)))
return diff
}

View file

@ -6,7 +6,6 @@ import android.content.res.ColorStateList;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.RippleDrawable;
import android.os.Build;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
@ -149,40 +148,14 @@ public final class TintHelper {
useDarker ? R.color.ate_control_normal_dark : R.color.ate_control_normal_light),
color
});
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
radioButton.setButtonTintList(sl);
} else {
Drawable d = createTintedDrawable(
ContextCompat.getDrawable(radioButton.getContext(), R.drawable.abc_btn_radio_material), sl);
radioButton.setButtonDrawable(d);
}
radioButton.setButtonTintList(sl);
}
public static void setTint(@NonNull SeekBar seekBar, @ColorInt int color, boolean useDarker) {
final ColorStateList s1 = getDisabledColorStateList(color, ContextCompat.getColor(seekBar.getContext(),
useDarker ? R.color.ate_control_disabled_dark : R.color.ate_control_disabled_light));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
seekBar.setThumbTintList(s1);
seekBar.setProgressTintList(s1);
} else if (Build.VERSION.SDK_INT > Build.VERSION_CODES.GINGERBREAD_MR1) {
Drawable progressDrawable = createTintedDrawable(seekBar.getProgressDrawable(), s1);
seekBar.setProgressDrawable(progressDrawable);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
Drawable thumbDrawable = createTintedDrawable(seekBar.getThumb(), s1);
seekBar.setThumb(thumbDrawable);
}
} else {
PorterDuff.Mode mode = PorterDuff.Mode.SRC_IN;
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.GINGERBREAD_MR1) {
mode = PorterDuff.Mode.MULTIPLY;
}
if (seekBar.getIndeterminateDrawable() != null) {
seekBar.getIndeterminateDrawable().setColorFilter(color, mode);
}
if (seekBar.getProgressDrawable() != null) {
seekBar.getProgressDrawable().setColorFilter(color, mode);
}
}
seekBar.setThumbTintList(s1);
seekBar.setProgressTintList(s1);
}
public static void setTint(@NonNull ProgressBar progressBar, @ColorInt int color) {
@ -191,23 +164,10 @@ public final class TintHelper {
public static void setTint(@NonNull ProgressBar progressBar, @ColorInt int color, boolean skipIndeterminate) {
ColorStateList sl = ColorStateList.valueOf(color);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
progressBar.setProgressTintList(sl);
progressBar.setSecondaryProgressTintList(sl);
if (!skipIndeterminate) {
progressBar.setIndeterminateTintList(sl);
}
} else {
PorterDuff.Mode mode = PorterDuff.Mode.SRC_IN;
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.GINGERBREAD_MR1) {
mode = PorterDuff.Mode.MULTIPLY;
}
if (!skipIndeterminate && progressBar.getIndeterminateDrawable() != null) {
progressBar.getIndeterminateDrawable().setColorFilter(color, mode);
}
if (progressBar.getProgressDrawable() != null) {
progressBar.getProgressDrawable().setColorFilter(color, mode);
}
progressBar.setProgressTintList(sl);
progressBar.setSecondaryProgressTintList(sl);
if (!skipIndeterminate) {
progressBar.setIndeterminateTintList(sl);
}
}
@ -225,7 +185,7 @@ public final class TintHelper {
});
if (editText instanceof AppCompatEditText) {
((AppCompatEditText) editText).setSupportBackgroundTintList(editTextColorStateList);
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
} else {
editText.setBackgroundTintList(editTextColorStateList);
}
setCursorTint(editText, color);
@ -243,13 +203,7 @@ public final class TintHelper {
useDarker ? R.color.ate_control_normal_dark : R.color.ate_control_normal_light),
color
});
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
box.setButtonTintList(sl);
} else {
Drawable drawable = createTintedDrawable(
ContextCompat.getDrawable(box.getContext(), R.drawable.abc_btn_check_material), sl);
box.setButtonDrawable(drawable);
}
box.setButtonTintList(sl);
}
public static void setTint(@NonNull ImageView image, @ColorInt int color) {
@ -257,9 +211,6 @@ public final class TintHelper {
}
public static void setTint(@NonNull Switch switchView, @ColorInt int color, boolean useDarker) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
return;
}
if (switchView.getTrackDrawable() != null) {
switchView.setTrackDrawable(modifySwitchDrawable(switchView.getContext(),
switchView.getTrackDrawable(), color, false, false, useDarker));
@ -286,7 +237,6 @@ public final class TintHelper {
setTintAuto(view, color, background, ATHUtil.INSTANCE.isWindowBackgroundDark(view.getContext()));
}
@SuppressWarnings("deprecation")
public static void setTintAuto(final @NonNull View view, final @ColorInt int color,
boolean background, final boolean isDark) {
if (!background) {
@ -312,8 +262,7 @@ public final class TintHelper {
background = true;
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP &&
!background && view.getBackground() instanceof RippleDrawable) {
if (!background && view.getBackground() instanceof RippleDrawable) {
// Ripples for the above views (e.g. when you tap and hold a switch or checkbox)
RippleDrawable rd = (RippleDrawable) view.getBackground();
@SuppressLint("PrivateResource") final int unchecked = ContextCompat.getColor(view.getContext(),
@ -348,7 +297,6 @@ public final class TintHelper {
}
}
@SuppressWarnings("deprecation")
public static void setTintSelector(@NonNull View view, @ColorInt final int color, final boolean darker,
final boolean useDarkTheme) {
final boolean isColorLight = ColorUtil.INSTANCE.isColorLight(color);
@ -363,8 +311,7 @@ public final class TintHelper {
final ColorStateList sl;
if (view instanceof Button) {
sl = getDisabledColorStateList(color, disabled);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP &&
view.getBackground() instanceof RippleDrawable) {
if (view.getBackground() instanceof RippleDrawable) {
RippleDrawable rd = (RippleDrawable) view.getBackground();
rd.setColor(ColorStateList.valueOf(rippleColor));
}

View file

@ -5,7 +5,6 @@ import android.content.Context;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffColorFilter;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
@ -17,6 +16,7 @@ import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.RadioButton;
import androidx.annotation.CheckResult;
import androidx.annotation.ColorInt;
import androidx.annotation.NonNull;
@ -35,11 +35,13 @@ import androidx.appcompat.widget.AppCompatImageView;
import androidx.appcompat.widget.Toolbar;
import androidx.appcompat.widget.ToolbarWidgetWrapper;
import androidx.core.graphics.drawable.DrawableCompat;
import code.name.monkey.appthemehelper.R;
import code.name.monkey.appthemehelper.ThemeStore;
import java.lang.reflect.Field;
import java.util.ArrayList;
import code.name.monkey.appthemehelper.R;
import code.name.monkey.appthemehelper.ThemeStore;
public final class ToolbarContentTintHelper {
public static class InternalToolbarContentTintUtil {
@ -92,30 +94,27 @@ public final class ToolbarContentTintHelper {
if (toolbar == null) {
return;
}
toolbar.post(new Runnable() {
@Override
public void run() {
try {
Field f1 = Toolbar.class.getDeclaredField("mMenuView");
f1.setAccessible(true);
ActionMenuView actionMenuView = (ActionMenuView) f1.get(toolbar);
Field f2 = ActionMenuView.class.getDeclaredField("mPresenter");
f2.setAccessible(true);
toolbar.post(() -> {
try {
Field f1 = Toolbar.class.getDeclaredField("mMenuView");
f1.setAccessible(true);
ActionMenuView actionMenuView = (ActionMenuView) f1.get(toolbar);
Field f2 = ActionMenuView.class.getDeclaredField("mPresenter");
f2.setAccessible(true);
// Actually ActionMenuPresenter
BaseMenuPresenter presenter = (BaseMenuPresenter) f2.get(actionMenuView);
Field f3 = presenter.getClass().getDeclaredField("mOverflowPopup");
f3.setAccessible(true);
MenuPopupHelper overflowMenuPopupHelper = (MenuPopupHelper) f3.get(presenter);
setTintForMenuPopupHelper(context, overflowMenuPopupHelper, color);
// Actually ActionMenuPresenter
BaseMenuPresenter presenter = (BaseMenuPresenter) f2.get(actionMenuView);
Field f3 = presenter.getClass().getDeclaredField("mOverflowPopup");
f3.setAccessible(true);
MenuPopupHelper overflowMenuPopupHelper = (MenuPopupHelper) f3.get(presenter);
setTintForMenuPopupHelper(context, overflowMenuPopupHelper, color);
Field f4 = presenter.getClass().getDeclaredField("mActionButtonPopup");
f4.setAccessible(true);
MenuPopupHelper subMenuPopupHelper = (MenuPopupHelper) f4.get(presenter);
setTintForMenuPopupHelper(context, subMenuPopupHelper, color);
} catch (Exception e) {
e.printStackTrace();
}
Field f4 = presenter.getClass().getDeclaredField("mActionButtonPopup");
f4.setAccessible(true);
MenuPopupHelper subMenuPopupHelper = (MenuPopupHelper) f4.get(presenter);
setTintForMenuPopupHelper(context, subMenuPopupHelper, color);
} catch (Exception e) {
e.printStackTrace();
}
});
}
@ -172,28 +171,19 @@ public final class ToolbarContentTintHelper {
CheckBox check = (CheckBox) checkboxField.get(iv);
if (check != null) {
TintHelper.setTint(check, color, isDark);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
check.setBackground(null);
}
check.setBackground(null);
}
RadioButton radioButton = (RadioButton) radioButtonField.get(iv);
if (radioButton != null) {
TintHelper.setTint(radioButton, color, isDark);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
radioButton.setBackground(null);
}
radioButton.setBackground(null);
}
}
} catch (Exception e) {
e.printStackTrace();
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
listView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
} else {
//noinspection deprecation
listView.getViewTreeObserver().removeGlobalOnLayoutListener(this);
}
listView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
}
});
}
@ -202,7 +192,6 @@ public final class ToolbarContentTintHelper {
}
}
@SuppressWarnings("unchecked")
public static void tintMenu(@NonNull Toolbar toolbar, @Nullable Menu menu,
final @ColorInt int color) {
try {
@ -338,13 +327,8 @@ public final class ToolbarContentTintHelper {
//Important to set the color filter in seperate thread, by adding it to the message queue
//Won't work otherwise.
innerView.post(new Runnable() {
@Override
public void run() {
((ActionMenuItemView) innerView).getCompoundDrawables()[finalK]
.setColorFilter(colorFilter);
}
});
innerView.post(() -> ((ActionMenuItemView) innerView).getCompoundDrawables()[finalK]
.setColorFilter(colorFilter));
}
}
}
@ -363,7 +347,7 @@ public final class ToolbarContentTintHelper {
@Nullable
public static Toolbar getSupportActionBarView(@Nullable ActionBar ab) {
if (ab == null || !(ab instanceof WindowDecorActionBar)) {
if (!(ab instanceof WindowDecorActionBar)) {
return null;
}
try {
@ -411,7 +395,6 @@ public final class ToolbarContentTintHelper {
secondaryTextColor, menuWidgetColor);
}
@SuppressWarnings("unchecked")
public static void setToolbarContentColor(@NonNull Context context,
Toolbar toolbar,
@Nullable Menu menu,
@ -577,7 +560,7 @@ public final class ToolbarContentTintHelper {
viewTreeObserver.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
final ArrayList<View> outViews = new ArrayList<View>();
final ArrayList<View> outViews = new ArrayList<>();
decorView.findViewsWithText(outViews, overflowDescription,
View.FIND_VIEWS_WITH_CONTENT_DESCRIPTION);
if (outViews.isEmpty()) {
@ -605,7 +588,7 @@ public final class ToolbarContentTintHelper {
final View actionView = item.getActionView();
final View expandActivitiesButton = actionView.findViewById(R.id.expand_activities_button);
if (expandActivitiesButton != null) {
final ImageView image = (ImageView) expandActivitiesButton.findViewById(R.id.image);
final ImageView image = expandActivitiesButton.findViewById(R.id.image);
if (image != null) {
final Drawable drawable = image.getDrawable();
final Drawable wrapped = DrawableCompat.wrap(drawable);

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<ATESwitch xmlns:android="http://schemas.android.com/apk/res/android"
<code.name.monkey.appthemehelper.common.views.ATESwitch xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="m3_accent_color">@android:color/system_accent1_200</color>
<color name="m3_selection_color">@android:color/system_accent1_800</color>
<color name="m3_selection_color">@android:color/system_accent1_500</color>
</resources>

View file

@ -1,2 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<resources></resources>