removing some redundant old code
This commit is contained in:
parent
b3ed2557b8
commit
3d8235888c
4 changed files with 4 additions and 130 deletions
|
@ -4,7 +4,6 @@ import android.content.Intent
|
|||
import android.view.Menu
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.SeekBar
|
||||
import com.bumptech.glide.Glide
|
||||
import com.bumptech.glide.load.resource.bitmap.CenterCrop
|
||||
import com.bumptech.glide.load.resource.bitmap.RoundedCorners
|
||||
|
@ -43,8 +42,6 @@ class OldSongAdapter(activity: SimpleActivity, var songs: ArrayList<Track>, val
|
|||
private var currentSongIndex = 0
|
||||
private var songsHashCode = songs.hashCode()
|
||||
private var currentSong: Track? = null
|
||||
private var initialProgress = 0
|
||||
private var initialIsPlaying = false
|
||||
private var textToHighlight = ""
|
||||
|
||||
private var transparentViewHolder: TransparentViewHolder? = null
|
||||
|
@ -151,7 +148,6 @@ class OldSongAdapter(activity: SimpleActivity, var songs: ArrayList<Track>, val
|
|||
private fun getNavigationViewHolder(): NavigationViewHolder {
|
||||
if (navigationView == null) {
|
||||
navigationView = activity.layoutInflater.inflate(R.layout.item_navigation, null) as ViewGroup
|
||||
initNavigationView()
|
||||
}
|
||||
|
||||
if (navigationViewHolder == null) {
|
||||
|
@ -318,18 +314,6 @@ class OldSongAdapter(activity: SimpleActivity, var songs: ArrayList<Track>, val
|
|||
fastScroller?.measureRecyclerView()
|
||||
}
|
||||
|
||||
fun updateCurrentSongIndex(index: Int) {
|
||||
val correctIndex = index + LIST_HEADERS_COUNT
|
||||
val prevIndex = currentSongIndex
|
||||
currentSongIndex = -1
|
||||
notifyItemChanged(prevIndex)
|
||||
|
||||
currentSongIndex = correctIndex
|
||||
if (index >= 0) {
|
||||
notifyItemChanged(correctIndex)
|
||||
}
|
||||
}
|
||||
|
||||
fun updateSong(song: Track?) {
|
||||
currentSong = song
|
||||
navigationView?.apply {
|
||||
|
@ -340,98 +324,6 @@ class OldSongAdapter(activity: SimpleActivity, var songs: ArrayList<Track>, val
|
|||
}
|
||||
}
|
||||
|
||||
private fun initNavigationView() {
|
||||
navigationView?.apply {
|
||||
previous_btn.setOnClickListener { activity.sendIntent(PREVIOUS) }
|
||||
play_pause_btn.setOnClickListener { activity.sendIntent(PLAYPAUSE) }
|
||||
next_btn.setOnClickListener { activity.sendIntent(NEXT) }
|
||||
song_progress_current.setOnClickListener { activity.sendIntent(SKIP_BACKWARD) }
|
||||
song_progress_max.setOnClickListener { activity.sendIntent(SKIP_FORWARD) }
|
||||
|
||||
updateColors()
|
||||
|
||||
song_progressbar?.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener {
|
||||
override fun onProgressChanged(seekBar: SeekBar, progress: Int, fromUser: Boolean) {
|
||||
val duration = song_progressbar.max.getFormattedDuration()
|
||||
val formattedProgress = progress.getFormattedDuration()
|
||||
song_progress_current.text = formattedProgress
|
||||
song_progress_max.text = duration
|
||||
}
|
||||
|
||||
override fun onStartTrackingTouch(seekBar: SeekBar) {
|
||||
}
|
||||
|
||||
override fun onStopTrackingTouch(seekBar: SeekBar) {
|
||||
Intent(activity, MusicService::class.java).apply {
|
||||
putExtra(PROGRESS, seekBar.progress)
|
||||
action = SET_PROGRESS
|
||||
activity.startService(this)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
updateSong(currentSong)
|
||||
updateSongProgress(initialProgress)
|
||||
updateSongState(initialIsPlaying)
|
||||
}
|
||||
}
|
||||
|
||||
fun updateColors() {
|
||||
val config = activity.config
|
||||
textColor = config.textColor
|
||||
primaryColor = config.primaryColor
|
||||
backgroundColor = config.backgroundColor
|
||||
adjustedPrimaryColor = activity.getAdjustedPrimaryColor()
|
||||
navigationView?.apply {
|
||||
previous_btn.applyColorFilter(textColor)
|
||||
play_pause_btn.applyColorFilter(textColor)
|
||||
next_btn.applyColorFilter(textColor)
|
||||
repeat_btn.applyColorFilter(textColor)
|
||||
|
||||
shuffle_btn.applyColorFilter(if (config.isShuffleEnabled) adjustedPrimaryColor else textColor)
|
||||
shuffle_btn.alpha = if (config.isShuffleEnabled) 1f else LOWER_ALPHA
|
||||
|
||||
repeat_btn.applyColorFilter(if (config.repeatTrack) adjustedPrimaryColor else textColor)
|
||||
repeat_btn.alpha = if (config.repeatTrack) 1f else LOWER_ALPHA
|
||||
|
||||
song_info_title.setTextColor(textColor)
|
||||
song_info_artist.setTextColor(textColor)
|
||||
song_progress_current.setTextColor(textColor)
|
||||
song_progress_max.setTextColor(textColor)
|
||||
song_progressbar.setColors(textColor, adjustedPrimaryColor, backgroundColor)
|
||||
}
|
||||
}
|
||||
|
||||
fun updateSongState(isPlaying: Boolean) {
|
||||
if (navigationView == null) {
|
||||
initialIsPlaying = isPlaying
|
||||
}
|
||||
navigationView?.play_pause_btn?.setImageDrawable(resources.getDrawable(if (isPlaying) R.drawable.ic_pause_vector else R.drawable.ic_play_vector))
|
||||
}
|
||||
|
||||
fun updateSongProgress(progress: Int) {
|
||||
if (navigationView == null) {
|
||||
initialProgress = progress
|
||||
}
|
||||
navigationView?.song_progressbar?.progress = progress
|
||||
}
|
||||
|
||||
fun updateShuffle(enable: Boolean) {
|
||||
navigationView?.apply {
|
||||
shuffle_btn.applyColorFilter(if (enable) adjustedPrimaryColor else textColor)
|
||||
shuffle_btn.alpha = if (enable) 1f else LOWER_ALPHA
|
||||
shuffle_btn.contentDescription = resources.getString(if (enable) R.string.disable_shuffle else R.string.enable_shuffle)
|
||||
}
|
||||
}
|
||||
|
||||
fun updateRepeatSong(repeat: Boolean) {
|
||||
navigationView?.apply {
|
||||
repeat_btn.applyColorFilter(if (repeat) adjustedPrimaryColor else textColor)
|
||||
repeat_btn.alpha = if (repeat) 1f else LOWER_ALPHA
|
||||
repeat_btn.contentDescription = resources.getString(if (repeat) R.string.disable_song_repetition else R.string.enable_song_repetition)
|
||||
}
|
||||
}
|
||||
|
||||
inner class TransparentViewHolder(view: View) : ViewHolder(view)
|
||||
|
||||
inner class NavigationViewHolder(view: View) : ViewHolder(view)
|
||||
|
|
|
@ -5,7 +5,6 @@ import android.view.View
|
|||
import android.view.ViewGroup
|
||||
import com.simplemobiletools.commons.adapters.MyRecyclerViewAdapter
|
||||
import com.simplemobiletools.commons.extensions.deleteFiles
|
||||
import com.simplemobiletools.commons.extensions.getAdjustedPrimaryColor
|
||||
import com.simplemobiletools.commons.extensions.getFilenameFromPath
|
||||
import com.simplemobiletools.commons.extensions.highlightTextPart
|
||||
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
|
||||
|
@ -16,11 +15,8 @@ import com.simplemobiletools.musicplayer.R
|
|||
import com.simplemobiletools.musicplayer.activities.SimpleActivity
|
||||
import com.simplemobiletools.musicplayer.dialogs.NewPlaylistDialog
|
||||
import com.simplemobiletools.musicplayer.dialogs.RemovePlaylistDialog
|
||||
import com.simplemobiletools.musicplayer.extensions.config
|
||||
import com.simplemobiletools.musicplayer.extensions.deletePlaylists
|
||||
import com.simplemobiletools.musicplayer.extensions.getPlaylistTracks
|
||||
import com.simplemobiletools.musicplayer.extensions.playlistChanged
|
||||
import com.simplemobiletools.musicplayer.helpers.ALL_TRACKS_PLAYLIST_ID
|
||||
import com.simplemobiletools.musicplayer.models.Playlist
|
||||
import kotlinx.android.synthetic.main.item_playlist.view.*
|
||||
import java.util.*
|
||||
|
@ -79,11 +75,11 @@ class PlaylistsAdapter(activity: SimpleActivity, var playlists: ArrayList<Playli
|
|||
if (it) {
|
||||
ensureBackgroundThread {
|
||||
deletePlaylistSongs(ids) {
|
||||
removePlaylists(ids)
|
||||
removePlaylists()
|
||||
}
|
||||
}
|
||||
} else {
|
||||
removePlaylists(ids)
|
||||
removePlaylists()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -101,14 +97,7 @@ class PlaylistsAdapter(activity: SimpleActivity, var playlists: ArrayList<Playli
|
|||
}
|
||||
}
|
||||
|
||||
private fun removePlaylists(ids: ArrayList<Int>) {
|
||||
for (key in selectedKeys) {
|
||||
val playlist = getItemWithKey(key) ?: continue
|
||||
if (playlist.id == activity.config.currentPlaylist) {
|
||||
activity.playlistChanged(ALL_TRACKS_PLAYLIST_ID)
|
||||
}
|
||||
}
|
||||
|
||||
private fun removePlaylists() {
|
||||
val playlistsToDelete = ArrayList<Playlist>(selectedKeys.size)
|
||||
val positions = ArrayList<Int>()
|
||||
for (key in selectedKeys) {
|
||||
|
@ -123,14 +112,9 @@ class PlaylistsAdapter(activity: SimpleActivity, var playlists: ArrayList<Playli
|
|||
playlists.removeAll(playlistsToDelete)
|
||||
|
||||
ensureBackgroundThread {
|
||||
val isDeletingCurrentPlaylist = ids.contains(activity.config.currentPlaylist)
|
||||
activity.deletePlaylists(playlistsToDelete)
|
||||
activity.runOnUiThread {
|
||||
if (isDeletingCurrentPlaylist) {
|
||||
finishActMode()
|
||||
} else {
|
||||
removeSelectedItems(positions)
|
||||
}
|
||||
removeSelectedItems(positions)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,7 +37,6 @@ class OldSongsFragment(context: Context, attributeSet: AttributeSet) : MyViewPag
|
|||
private lateinit var activity: SimpleActivity
|
||||
|
||||
fun onResume() {
|
||||
getSongsAdapter()?.updateColors()
|
||||
songs_playlist_empty_placeholder_2.setTextColor(activity.getAdjustedPrimaryColor())
|
||||
songs_playlist_empty_placeholder_2.paintFlags = songs_playlist_empty_placeholder_2.paintFlags or Paint.UNDERLINE_TEXT_FLAG
|
||||
|
||||
|
|
|
@ -2,7 +2,6 @@ package com.simplemobiletools.musicplayer.helpers
|
|||
|
||||
import android.net.Uri
|
||||
|
||||
const val TRACK_POS = "track_position"
|
||||
const val PROGRESS = "progress"
|
||||
const val CALL_SETUP_AFTER = "call_setup_after"
|
||||
const val TRACK_IDS = "track_ids"
|
||||
|
|
Loading…
Reference in a new issue