code clean
This commit is contained in:
parent
03df684c7e
commit
cc855d22fc
2 changed files with 55 additions and 53 deletions
|
@ -50,6 +50,7 @@ import code.name.monkey.retromusic.TOGGLE_SEPARATE_LINE
|
||||||
import code.name.monkey.retromusic.TOGGLE_VOLUME
|
import code.name.monkey.retromusic.TOGGLE_VOLUME
|
||||||
import code.name.monkey.retromusic.USER_NAME
|
import code.name.monkey.retromusic.USER_NAME
|
||||||
import code.name.monkey.retromusic.activities.base.AbsSlidingMusicPanelActivity
|
import code.name.monkey.retromusic.activities.base.AbsSlidingMusicPanelActivity
|
||||||
|
import code.name.monkey.retromusic.extensions.extra
|
||||||
import code.name.monkey.retromusic.extensions.findNavController
|
import code.name.monkey.retromusic.extensions.findNavController
|
||||||
import code.name.monkey.retromusic.helper.MusicPlayerRemote
|
import code.name.monkey.retromusic.helper.MusicPlayerRemote
|
||||||
import code.name.monkey.retromusic.helper.SearchQueryHelper.getSongs
|
import code.name.monkey.retromusic.helper.SearchQueryHelper.getSongs
|
||||||
|
@ -67,7 +68,6 @@ class MainActivity : AbsSlidingMusicPanelActivity(), OnSharedPreferenceChangeLis
|
||||||
companion object {
|
companion object {
|
||||||
const val TAG = "MainActivity"
|
const val TAG = "MainActivity"
|
||||||
const val EXPAND_PANEL = "expand_panel"
|
const val EXPAND_PANEL = "expand_panel"
|
||||||
const val APP_UPDATE_REQUEST_CODE = 9002
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun createContentView(): View {
|
override fun createContentView(): View {
|
||||||
|
@ -82,20 +82,13 @@ class MainActivity : AbsSlidingMusicPanelActivity(), OnSharedPreferenceChangeLis
|
||||||
setLightNavigationBar(true)
|
setLightNavigationBar(true)
|
||||||
setTaskDescriptionColorAuto()
|
setTaskDescriptionColorAuto()
|
||||||
hideStatusBar()
|
hideStatusBar()
|
||||||
AppRater.appLaunched(this)
|
|
||||||
updateTabs()
|
updateTabs()
|
||||||
|
AppRater.appLaunched(this)
|
||||||
|
|
||||||
// NavigationUI.setupWithNavController(getBottomNavigationView(), findNavController(R.id.fragment_container))
|
|
||||||
setupNavigationController()
|
setupNavigationController()
|
||||||
if (!hasPermissions()) {
|
if (!hasPermissions()) {
|
||||||
findNavController(R.id.fragment_container).navigate(R.id.permissionFragment)
|
findNavController(R.id.fragment_container).navigate(R.id.permissionFragment)
|
||||||
}
|
}
|
||||||
|
|
||||||
showPromotionalDialog()
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun showPromotionalDialog() {
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setupNavigationController() {
|
private fun setupNavigationController() {
|
||||||
|
@ -117,27 +110,27 @@ class MainActivity : AbsSlidingMusicPanelActivity(), OnSharedPreferenceChangeLis
|
||||||
override fun onResume() {
|
override fun onResume() {
|
||||||
super.onResume()
|
super.onResume()
|
||||||
PreferenceUtil.registerOnSharedPreferenceChangedListener(this)
|
PreferenceUtil.registerOnSharedPreferenceChangedListener(this)
|
||||||
if (intent.hasExtra(EXPAND_PANEL) &&
|
val expand = extra<Boolean>(EXPAND_PANEL).value ?: false
|
||||||
intent.getBooleanExtra(EXPAND_PANEL, false) &&
|
if (expand && PreferenceUtil.isExpandPanel) {
|
||||||
PreferenceUtil.isExpandPanel
|
|
||||||
) {
|
|
||||||
expandPanel()
|
expandPanel()
|
||||||
intent.removeExtra(EXPAND_PANEL)
|
intent.removeExtra(EXPAND_PANEL)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onDestroy() {
|
||||||
|
super.onDestroy()
|
||||||
|
PreferenceUtil.unregisterOnSharedPreferenceChangedListener(this)
|
||||||
|
}
|
||||||
|
|
||||||
override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences?, key: String?) {
|
override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences?, key: String?) {
|
||||||
if (key == GENERAL_THEME || key == BLACK_THEME || key == ADAPTIVE_COLOR_APP || key == USER_NAME || key == TOGGLE_FULL_SCREEN || key == TOGGLE_VOLUME || key == ROUND_CORNERS || key == CAROUSEL_EFFECT || key == NOW_PLAYING_SCREEN_ID || key == TOGGLE_GENRE || key == BANNER_IMAGE_PATH || key == PROFILE_IMAGE_PATH || key == CIRCULAR_ALBUM_ART || key == KEEP_SCREEN_ON || key == TOGGLE_SEPARATE_LINE || key == TOGGLE_HOME_BANNER || key == TOGGLE_ADD_CONTROLS || key == ALBUM_COVER_STYLE || key == HOME_ARTIST_GRID_STYLE || key == ALBUM_COVER_TRANSFORM || key == DESATURATED_COLOR || key == EXTRA_SONG_INFO || key == TAB_TEXT_MODE || key == LANGUAGE_NAME || key == LIBRARY_CATEGORIES
|
if (key == GENERAL_THEME || key == BLACK_THEME || key == ADAPTIVE_COLOR_APP || key == USER_NAME || key == TOGGLE_FULL_SCREEN || key == TOGGLE_VOLUME || key == ROUND_CORNERS || key == CAROUSEL_EFFECT || key == NOW_PLAYING_SCREEN_ID || key == TOGGLE_GENRE || key == BANNER_IMAGE_PATH || key == PROFILE_IMAGE_PATH || key == CIRCULAR_ALBUM_ART || key == KEEP_SCREEN_ON || key == TOGGLE_SEPARATE_LINE || key == TOGGLE_HOME_BANNER || key == TOGGLE_ADD_CONTROLS || key == ALBUM_COVER_STYLE || key == HOME_ARTIST_GRID_STYLE || key == ALBUM_COVER_TRANSFORM || key == DESATURATED_COLOR || key == EXTRA_SONG_INFO || key == TAB_TEXT_MODE || key == LANGUAGE_NAME || key == LIBRARY_CATEGORIES) {
|
||||||
) {
|
|
||||||
postRecreate()
|
postRecreate()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onServiceConnected() {
|
override fun onServiceConnected() {
|
||||||
super.onServiceConnected()
|
super.onServiceConnected()
|
||||||
if (intent == null) {
|
intent ?: return
|
||||||
return
|
|
||||||
}
|
|
||||||
handlePlaybackIntent(intent)
|
handlePlaybackIntent(intent)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,9 +16,11 @@ package code.name.monkey.retromusic.fragments.player.full
|
||||||
|
|
||||||
import android.animation.ObjectAnimator
|
import android.animation.ObjectAnimator
|
||||||
import android.annotation.SuppressLint
|
import android.annotation.SuppressLint
|
||||||
|
import android.content.Intent
|
||||||
import android.content.res.ColorStateList
|
import android.content.res.ColorStateList
|
||||||
import android.graphics.Color
|
import android.graphics.Color
|
||||||
import android.graphics.PorterDuff
|
import android.graphics.PorterDuff
|
||||||
|
import android.graphics.drawable.Drawable
|
||||||
import android.os.AsyncTask
|
import android.os.AsyncTask
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
|
@ -27,12 +29,17 @@ import android.view.animation.DecelerateInterpolator
|
||||||
import android.view.animation.LinearInterpolator
|
import android.view.animation.LinearInterpolator
|
||||||
import android.widget.PopupMenu
|
import android.widget.PopupMenu
|
||||||
import android.widget.SeekBar
|
import android.widget.SeekBar
|
||||||
|
import androidx.lifecycle.lifecycleScope
|
||||||
import code.name.monkey.appthemehelper.util.ColorUtil
|
import code.name.monkey.appthemehelper.util.ColorUtil
|
||||||
import code.name.monkey.appthemehelper.util.TintHelper
|
import code.name.monkey.appthemehelper.util.TintHelper
|
||||||
import code.name.monkey.retromusic.R
|
import code.name.monkey.retromusic.R
|
||||||
|
import code.name.monkey.retromusic.db.PlaylistEntity
|
||||||
|
import code.name.monkey.retromusic.db.SongEntity
|
||||||
|
import code.name.monkey.retromusic.db.toSongEntity
|
||||||
import code.name.monkey.retromusic.extensions.applyColor
|
import code.name.monkey.retromusic.extensions.applyColor
|
||||||
import code.name.monkey.retromusic.extensions.hide
|
import code.name.monkey.retromusic.extensions.hide
|
||||||
import code.name.monkey.retromusic.extensions.show
|
import code.name.monkey.retromusic.extensions.show
|
||||||
|
import code.name.monkey.retromusic.fragments.LibraryViewModel
|
||||||
import code.name.monkey.retromusic.fragments.base.AbsPlayerControlsFragment
|
import code.name.monkey.retromusic.fragments.base.AbsPlayerControlsFragment
|
||||||
import code.name.monkey.retromusic.helper.MusicPlayerRemote
|
import code.name.monkey.retromusic.helper.MusicPlayerRemote
|
||||||
import code.name.monkey.retromusic.helper.MusicProgressViewUpdateHelper
|
import code.name.monkey.retromusic.helper.MusicProgressViewUpdateHelper
|
||||||
|
@ -42,8 +49,13 @@ import code.name.monkey.retromusic.model.Song
|
||||||
import code.name.monkey.retromusic.service.MusicService
|
import code.name.monkey.retromusic.service.MusicService
|
||||||
import code.name.monkey.retromusic.util.MusicUtil
|
import code.name.monkey.retromusic.util.MusicUtil
|
||||||
import code.name.monkey.retromusic.util.PreferenceUtil
|
import code.name.monkey.retromusic.util.PreferenceUtil
|
||||||
|
import code.name.monkey.retromusic.util.RetroUtil
|
||||||
import code.name.monkey.retromusic.util.color.MediaNotificationProcessor
|
import code.name.monkey.retromusic.util.color.MediaNotificationProcessor
|
||||||
import kotlinx.android.synthetic.main.fragment_full_player_controls.*
|
import kotlinx.android.synthetic.main.fragment_full_player_controls.*
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
|
import org.koin.androidx.viewmodel.ext.android.sharedViewModel
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by hemanths on 20/09/17.
|
* Created by hemanths on 20/09/17.
|
||||||
|
@ -56,6 +68,7 @@ class FullPlaybackControlsFragment :
|
||||||
private var lastPlaybackControlsColor: Int = 0
|
private var lastPlaybackControlsColor: Int = 0
|
||||||
private var lastDisabledPlaybackControlsColor: Int = 0
|
private var lastDisabledPlaybackControlsColor: Int = 0
|
||||||
private lateinit var progressViewUpdateHelper: MusicProgressViewUpdateHelper
|
private lateinit var progressViewUpdateHelper: MusicProgressViewUpdateHelper
|
||||||
|
private val libraryViewModel: LibraryViewModel by sharedViewModel()
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
|
@ -158,7 +171,6 @@ class FullPlaybackControlsFragment :
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setUpPlayPauseFab() {
|
private fun setUpPlayPauseFab() {
|
||||||
|
|
||||||
playPauseButton.setOnClickListener(PlayPauseButtonOnClickHandler())
|
playPauseButton.setOnClickListener(PlayPauseButtonOnClickHandler())
|
||||||
playPauseButton.post {
|
playPauseButton.post {
|
||||||
if (playPauseButton != null) {
|
if (playPauseButton != null) {
|
||||||
|
@ -283,44 +295,41 @@ class FullPlaybackControlsFragment :
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun toggleFavorite(song: Song) {
|
|
||||||
MusicUtil.toggleFavorite(requireContext(), song)
|
|
||||||
if (song.id == MusicPlayerRemote.currentSong.id) {
|
|
||||||
updateIsFavorite()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private var updateIsFavoriteTask: AsyncTask<*, *, *>? = null
|
|
||||||
|
|
||||||
@SuppressLint("StaticFieldLeak")
|
|
||||||
fun updateIsFavorite() {
|
fun updateIsFavorite() {
|
||||||
if (updateIsFavoriteTask != null) {
|
lifecycleScope.launch(Dispatchers.IO) {
|
||||||
updateIsFavoriteTask?.cancel(false)
|
val playlist: PlaylistEntity? = libraryViewModel.favoritePlaylist()
|
||||||
}
|
if (playlist != null) {
|
||||||
updateIsFavoriteTask = object : AsyncTask<Song, Void, Boolean>() {
|
val song: SongEntity =
|
||||||
override fun doInBackground(vararg params: Song): Boolean? {
|
MusicPlayerRemote.currentSong.toSongEntity(playlist.playListId)
|
||||||
val activity = activity
|
val isFavorite: Boolean = libraryViewModel.isFavoriteSong(song).isNotEmpty()
|
||||||
return if (activity != null) {
|
withContext(Dispatchers.Main) {
|
||||||
MusicUtil.isFavorite(requireActivity(), params[0])
|
val icon =
|
||||||
} else {
|
if (isFavorite) R.drawable.ic_favorite else R.drawable.ic_favorite_border
|
||||||
cancel(false)
|
val drawable = TintHelper.createTintedDrawable(activity, icon, Color.WHITE)
|
||||||
null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onPostExecute(isFavorite: Boolean?) {
|
|
||||||
val activity = activity
|
|
||||||
if (activity != null) {
|
|
||||||
val res = if (isFavorite!!)
|
|
||||||
R.drawable.ic_favorite
|
|
||||||
else
|
|
||||||
R.drawable.ic_favorite_border
|
|
||||||
|
|
||||||
val drawable = TintHelper.createTintedDrawable(activity, res, Color.WHITE)
|
|
||||||
songFavourite?.setImageDrawable(drawable)
|
songFavourite?.setImageDrawable(drawable)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}.execute(MusicPlayerRemote.currentSong)
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun toggleFavorite(song: Song) {
|
||||||
|
if (song.id == MusicPlayerRemote.currentSong.id) {
|
||||||
|
updateIsFavorite()
|
||||||
|
}
|
||||||
|
lifecycleScope.launch(Dispatchers.IO) {
|
||||||
|
val playlist: PlaylistEntity? = libraryViewModel.favoritePlaylist()
|
||||||
|
if (playlist != null) {
|
||||||
|
val songEntity = song.toSongEntity(playlist.playListId)
|
||||||
|
val isFavorite = libraryViewModel.isFavoriteSong(songEntity).isNotEmpty()
|
||||||
|
if (isFavorite) {
|
||||||
|
libraryViewModel.removeSongFromPlaylist(songEntity)
|
||||||
|
} else {
|
||||||
|
libraryViewModel.insertSongs(listOf(song.toSongEntity(playlist.playListId)))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
libraryViewModel.forceReload(ReloadType.Playlists)
|
||||||
|
requireContext().sendBroadcast(Intent(MusicService.FAVORITE_STATE_CHANGED))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onFavoriteToggled() {
|
fun onFavoriteToggled() {
|
||||||
|
|
Loading…
Reference in a new issue