Code refactor and Flat, Fit, Full, Circle theme toolbar shadow fixes

This commit is contained in:
= 2020-02-26 22:19:24 +05:30
parent 954dfb6327
commit 724f743627
304 changed files with 3874 additions and 3524 deletions

View file

@ -27,10 +27,12 @@ object HorizontalAdapterHelper {
private const val TYPE_MIDDLE = 2
private const val TYPE_LAST = 3
fun applyMarginToLayoutParams(context: Context,
layoutParams: ViewGroup.MarginLayoutParams, viewType: Int) {
fun applyMarginToLayoutParams(
context: Context,
layoutParams: ViewGroup.MarginLayoutParams, viewType: Int
) {
val listMargin = context.resources
.getDimensionPixelSize(R.dimen.now_playing_top_margin)
.getDimensionPixelSize(R.dimen.now_playing_top_margin)
if (viewType == TYPE_FIRST) {
layoutParams.leftMargin = listMargin
} else if (viewType == TYPE_LAST) {

View file

@ -16,12 +16,7 @@ package code.name.monkey.retromusic.helper
import android.annotation.TargetApi
import android.app.Activity
import android.content.ComponentName
import android.content.ContentResolver
import android.content.Context
import android.content.ContextWrapper
import android.content.Intent
import android.content.ServiceConnection
import android.content.*
import android.database.Cursor
import android.net.Uri
import android.os.Build
@ -36,9 +31,7 @@ import code.name.monkey.retromusic.model.Song
import code.name.monkey.retromusic.service.MusicService
import code.name.monkey.retromusic.util.PreferenceUtil
import java.io.File
import java.util.ArrayList
import java.util.Random
import java.util.WeakHashMap
import java.util.*
object MusicPlayerRemote {
val TAG: String = MusicPlayerRemote::class.java.simpleName
@ -209,7 +202,12 @@ object MusicPlayerRemote {
*/
@JvmStatic
fun openQueue(queue: List<Song>, startPosition: Int, startPlaying: Boolean) {
if (!tryToHandleOpenPlayingQueue(queue, startPosition, startPlaying) && musicService != null) {
if (!tryToHandleOpenPlayingQueue(
queue,
startPosition,
startPlaying
) && musicService != null
) {
musicService?.openQueue(queue, startPosition, startPlaying)
if (PreferenceUtil.getInstance(musicService).isShuffleModeOn)
setShuffleMode(MusicService.SHUFFLE_MODE_NONE)
@ -226,7 +224,12 @@ object MusicPlayerRemote {
startPosition = Random().nextInt(queue.size)
}
if (!tryToHandleOpenPlayingQueue(queue, startPosition, startPlaying) && musicService != null) {
if (!tryToHandleOpenPlayingQueue(
queue,
startPosition,
startPlaying
) && musicService != null
) {
openQueue(queue, startPosition, startPlaying)
setShuffleMode(MusicService.SHUFFLE_MODE_SHUFFLE)
}
@ -419,7 +422,10 @@ object MusicPlayerRemote {
var songFile: File? = null
if (uri.authority != null && uri.authority == "com.android.externalstorage.documents") {
songFile =
File(Environment.getExternalStorageDirectory(), uri.path?.split(":".toRegex(), 2)?.get(1))
File(
Environment.getExternalStorageDirectory(),
uri.path?.split(":".toRegex(), 2)?.get(1)
)
}
if (songFile == null) {
val path = getFilePathFromUri(musicService!!, uri)
@ -453,7 +459,8 @@ object MusicPlayerRemote {
return DocumentsContract.getDocumentId(uri).split(":".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()[1]
}
class ServiceBinder internal constructor(private val mCallback: ServiceConnection?) : ServiceConnection {
class ServiceBinder internal constructor(private val mCallback: ServiceConnection?) :
ServiceConnection {
override fun onServiceConnected(className: ComponentName, service: IBinder) {
val binder = service as MusicService.MusicBinder

View file

@ -20,7 +20,7 @@ import android.os.Bundle
import android.provider.MediaStore
import code.name.monkey.retromusic.loaders.SongLoader
import code.name.monkey.retromusic.model.Song
import java.util.ArrayList
import java.util.*
object SearchQueryHelper {
private const val TITLE_SELECTION = "lower(" + MediaStore.Audio.AudioColumns.TITLE + ") = ?"
@ -41,7 +41,11 @@ object SearchQueryHelper {
SongLoader.makeSongCursor(
context,
ARTIST_SELECTION + AND + ALBUM_SELECTION + AND + TITLE_SELECTION,
arrayOf(artistName.toLowerCase(), albumName.toLowerCase(), titleName.toLowerCase())
arrayOf(
artistName.toLowerCase(),
albumName.toLowerCase(),
titleName.toLowerCase()
)
)
)
}
@ -109,16 +113,34 @@ object SearchQueryHelper {
return songs
}
songs =
SongLoader.getSongs(SongLoader.makeSongCursor(context, ARTIST_SELECTION, arrayOf(query.toLowerCase())))
SongLoader.getSongs(
SongLoader.makeSongCursor(
context,
ARTIST_SELECTION,
arrayOf(query.toLowerCase())
)
)
if (songs.isNotEmpty()) {
return songs
}
songs = SongLoader.getSongs(SongLoader.makeSongCursor(context, ALBUM_SELECTION, arrayOf(query.toLowerCase())))
songs = SongLoader.getSongs(
SongLoader.makeSongCursor(
context,
ALBUM_SELECTION,
arrayOf(query.toLowerCase())
)
)
if (songs.isNotEmpty()) {
return songs
}
songs = SongLoader.getSongs(SongLoader.makeSongCursor(context, TITLE_SELECTION, arrayOf(query.toLowerCase())))
songs = SongLoader.getSongs(
SongLoader.makeSongCursor(
context,
TITLE_SELECTION,
arrayOf(query.toLowerCase())
)
)
return if (songs.isNotEmpty()) {
songs
} else ArrayList()

View file

@ -24,12 +24,12 @@ import java.util.concurrent.Executors;
* on the left side of the stack.
*
* @author Enrique López Mañas <eenriquelopez@gmail.com>
* http://www.neo-tech.es
* <p/>
* Author of the original algorithm: Mario Klingemann <mario.quasimondo.com>
* <p/>
* Based heavily on http://vitiy.info/Code/stackblur.cpp
* See http://vitiy.info/stackblur-algorithm-multi-threaded-blur-for-cpp/
* http://www.neo-tech.es
* <p/>
* Author of the original algorithm: Mario Klingemann <mario.quasimondo.com>
* <p/>
* Based heavily on http://vitiy.info/Code/stackblur.cpp
* See http://vitiy.info/stackblur-algorithm-multi-threaded-blur-for-cpp/
* @copyright: Enrique López Mañas
* @license: Apache License 2.0
*/

View file

@ -39,7 +39,7 @@ object GenreMenuHelper {
}
R.id.action_add_to_playlist -> {
AddToPlaylistDialog.create(getGenreSongs(activity, genre))
.show(activity.supportFragmentManager, "ADD_PLAYLIST")
.show(activity.supportFragmentManager, "ADD_PLAYLIST")
return true
}
R.id.action_add_to_current_playing -> {

View file

@ -37,8 +37,10 @@ import java.util.*
object PlaylistMenuHelper {
fun handleMenuClick(activity: AppCompatActivity,
playlist: Playlist, item: MenuItem): Boolean {
fun handleMenuClick(
activity: AppCompatActivity,
playlist: Playlist, item: MenuItem
): Boolean {
when (item.itemId) {
R.id.action_play -> {
MusicPlayerRemote.openQueue(getPlaylistSongs(activity, playlist), 9, true)
@ -50,7 +52,7 @@ object PlaylistMenuHelper {
}
R.id.action_add_to_playlist -> {
AddToPlaylistDialog.create(getPlaylistSongs(activity, playlist))
.show(activity.supportFragmentManager, "ADD_PLAYLIST")
.show(activity.supportFragmentManager, "ADD_PLAYLIST")
return true
}
R.id.action_add_to_current_playing -> {
@ -59,12 +61,12 @@ object PlaylistMenuHelper {
}
R.id.action_rename_playlist -> {
RenamePlaylistDialog.create(playlist.id.toLong())
.show(activity.supportFragmentManager, "RENAME_PLAYLIST")
.show(activity.supportFragmentManager, "RENAME_PLAYLIST")
return true
}
R.id.action_delete_playlist -> {
DeletePlaylistDialog.create(playlist)
.show(activity.supportFragmentManager, "DELETE_PLAYLIST")
.show(activity.supportFragmentManager, "DELETE_PLAYLIST")
return true
}
R.id.action_save_playlist -> {
@ -75,8 +77,10 @@ object PlaylistMenuHelper {
return false
}
private fun getPlaylistSongs(activity: Activity,
playlist: Playlist): ArrayList<Song> {
private fun getPlaylistSongs(
activity: Activity,
playlist: Playlist
): ArrayList<Song> {
return if (playlist is AbsCustomPlaylist) {
playlist.getSongs(activity)
} else {
@ -84,11 +88,16 @@ object PlaylistMenuHelper {
}
}
private class SavePlaylistAsyncTask internal constructor(context: Context) : WeakContextAsyncTask<Playlist, String, String>(context) {
private class SavePlaylistAsyncTask internal constructor(context: Context) :
WeakContextAsyncTask<Playlist, String, String>(context) {
override fun doInBackground(vararg params: Playlist): String {
return String.format(App.getContext().getString(R.string
.saved_playlist_to), PlaylistsUtil.savePlaylist(App.getContext(), params[0]))
return String.format(
App.getContext().getString(
R.string
.saved_playlist_to
), PlaylistsUtil.savePlaylist(App.getContext(), params[0])
)
}
override fun onPostExecute(string: String) {

View file

@ -60,7 +60,8 @@ object SongMenuHelper {
return true
}
R.id.action_add_to_playlist -> {
AddToPlaylistDialog.create(song).show(activity.supportFragmentManager, "ADD_PLAYLIST")
AddToPlaylistDialog.create(song)
.show(activity.supportFragmentManager, "ADD_PLAYLIST")
return true
}
R.id.action_play_next -> {

View file

@ -25,7 +25,11 @@ import java.util.*
object SongsMenuHelper {
fun handleMenuClick(activity: FragmentActivity, songs: ArrayList<Song>, menuItemId: Int): Boolean {
fun handleMenuClick(
activity: FragmentActivity,
songs: ArrayList<Song>,
menuItemId: Int
): Boolean {
when (menuItemId) {
R.id.action_play_next -> {
MusicPlayerRemote.playNext(songs)
@ -36,11 +40,13 @@ object SongsMenuHelper {
return true
}
R.id.action_add_to_playlist -> {
AddToPlaylistDialog.create(songs).show(activity.supportFragmentManager, "ADD_PLAYLIST")
AddToPlaylistDialog.create(songs)
.show(activity.supportFragmentManager, "ADD_PLAYLIST")
return true
}
R.id.action_delete_from_device -> {
DeleteSongsDialog.create(songs).show(activity.supportFragmentManager, "DELETE_SONGS")
DeleteSongsDialog.create(songs)
.show(activity.supportFragmentManager, "DELETE_SONGS")
return true
}
}