removing some more unwanted code
This commit is contained in:
parent
149f72d5b9
commit
119d014a2f
4 changed files with 6 additions and 178 deletions
|
@ -141,8 +141,6 @@
|
|||
<action android:name="com.simplemobiletools.musicplayer.action.SET_PROGRESS"/>
|
||||
<action android:name="com.simplemobiletools.musicplayer.action.SKIP_BACKWARD"/>
|
||||
<action android:name="com.simplemobiletools.musicplayer.action.SKIP_FORWARD"/>
|
||||
<action android:name="com.simplemobiletools.musicplayer.action.REMOVE_CURRENT_SONG"/>
|
||||
<action android:name="com.simplemobiletools.musicplayer.action.REMOVE_SONG_IDS"/>
|
||||
<action android:name="com.simplemobiletools.musicplayer.action.BROADCAST_STATUS"/>
|
||||
</intent-filter>
|
||||
</service>
|
||||
|
|
|
@ -4,29 +4,21 @@ import android.content.Intent
|
|||
import android.view.Menu
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import com.bumptech.glide.Glide
|
||||
import com.bumptech.glide.load.resource.bitmap.CenterCrop
|
||||
import com.bumptech.glide.load.resource.bitmap.RoundedCorners
|
||||
import com.bumptech.glide.request.RequestOptions
|
||||
import com.simplemobiletools.commons.adapters.MyRecyclerViewAdapter
|
||||
import com.simplemobiletools.commons.dialogs.ConfirmationDialog
|
||||
import com.simplemobiletools.commons.dialogs.PropertiesDialog
|
||||
import com.simplemobiletools.commons.extensions.*
|
||||
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
|
||||
import com.simplemobiletools.commons.models.FileDirItem
|
||||
import com.simplemobiletools.commons.extensions.sharePathsIntent
|
||||
import com.simplemobiletools.commons.views.FastScroller
|
||||
import com.simplemobiletools.commons.views.MyRecyclerView
|
||||
import com.simplemobiletools.musicplayer.BuildConfig
|
||||
import com.simplemobiletools.musicplayer.R
|
||||
import com.simplemobiletools.musicplayer.activities.SimpleActivity
|
||||
import com.simplemobiletools.musicplayer.dialogs.EditDialog
|
||||
import com.simplemobiletools.musicplayer.extensions.config
|
||||
import com.simplemobiletools.musicplayer.extensions.sendIntent
|
||||
import com.simplemobiletools.musicplayer.extensions.tracksDAO
|
||||
import com.simplemobiletools.musicplayer.helpers.*
|
||||
import com.simplemobiletools.musicplayer.helpers.EDIT
|
||||
import com.simplemobiletools.musicplayer.helpers.EDITED_TRACK
|
||||
import com.simplemobiletools.musicplayer.helpers.REFRESH_LIST
|
||||
import com.simplemobiletools.musicplayer.models.Track
|
||||
import com.simplemobiletools.musicplayer.services.MusicService
|
||||
import kotlinx.android.synthetic.main.item_old_song.view.*
|
||||
|
||||
class OldSongAdapter(activity: SimpleActivity, var songs: ArrayList<Track>, val transparentView: View,
|
||||
recyclerView: MyRecyclerView, fastScroller: FastScroller, itemClick: (Any) -> Unit) :
|
||||
|
@ -36,24 +28,10 @@ class OldSongAdapter(activity: SimpleActivity, var songs: ArrayList<Track>, val
|
|||
private val VIEW_TYPE_NAVIGATION = 1
|
||||
private val VIEW_TYPE_ITEM = 2
|
||||
|
||||
private val placeholder = resources.getColoredDrawableWithColor(R.drawable.ic_headset, textColor)
|
||||
|
||||
private var currentSongIndex = 0
|
||||
private var songsHashCode = songs.hashCode()
|
||||
private var currentSong: Track? = null
|
||||
private var textToHighlight = ""
|
||||
|
||||
private var transparentViewHolder: TransparentViewHolder? = null
|
||||
private var transparentViewHeight = 0
|
||||
|
||||
private var navigationView: ViewGroup? = null
|
||||
private var navigationViewHolder: NavigationViewHolder? = null
|
||||
private var navigationViewHeight = 0
|
||||
|
||||
init {
|
||||
setupDragListener(true)
|
||||
positionOffset = LIST_HEADERS_COUNT
|
||||
}
|
||||
|
||||
override fun getActionMenuId() = R.menu.cab
|
||||
|
||||
|
@ -73,19 +51,9 @@ class OldSongAdapter(activity: SimpleActivity, var songs: ArrayList<Track>, val
|
|||
}
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
||||
if (holder !is TransparentViewHolder && holder !is NavigationViewHolder) {
|
||||
val song = songs.getOrNull(position - LIST_HEADERS_COUNT) ?: return
|
||||
holder.bindView(song, true, true) { itemView, layoutPosition ->
|
||||
setupView(itemView, song, layoutPosition)
|
||||
}
|
||||
bindViewHolder(holder)
|
||||
} else {
|
||||
holder.itemView.tag = holder
|
||||
}
|
||||
}
|
||||
override fun onBindViewHolder(holder: ViewHolder, position: Int) {}
|
||||
|
||||
override fun getItemCount() = songs.size + LIST_HEADERS_COUNT
|
||||
override fun getItemCount() = songs.size
|
||||
|
||||
private fun getItemWithKey(key: Int): Track? = songs.firstOrNull { it.path.hashCode() == key }
|
||||
|
||||
|
@ -104,9 +72,6 @@ class OldSongAdapter(activity: SimpleActivity, var songs: ArrayList<Track>, val
|
|||
R.id.cab_properties -> showProperties()
|
||||
R.id.cab_rename -> displayEditDialog()
|
||||
R.id.cab_share -> shareItems()
|
||||
R.id.cab_select_all -> selectAll()
|
||||
R.id.cab_remove_from_playlist -> removeFromPlaylist()
|
||||
R.id.cab_delete -> askConfirmDelete()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -173,105 +138,6 @@ class OldSongAdapter(activity: SimpleActivity, var songs: ArrayList<Track>, val
|
|||
activity.sharePathsIntent(paths, BuildConfig.APPLICATION_ID)
|
||||
}
|
||||
|
||||
private fun askConfirmDelete() {
|
||||
ConfirmationDialog(activity) {
|
||||
ensureBackgroundThread {
|
||||
deleteSongs()
|
||||
activity.runOnUiThread {
|
||||
finishActMode()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun deleteSongs() {
|
||||
if (selectedKeys.isEmpty()) {
|
||||
return
|
||||
}
|
||||
|
||||
val SAFPath = getFirstSelectedItemPath()
|
||||
activity.handleSAFDialog(SAFPath) {
|
||||
val files = ArrayList<FileDirItem>(selectedKeys.size)
|
||||
val removeSongs = ArrayList<Track>(selectedKeys.size)
|
||||
val positions = ArrayList<Int>()
|
||||
|
||||
for (key in selectedKeys) {
|
||||
val song = getItemWithKey(key) ?: continue
|
||||
|
||||
val position = songs.indexOfFirst { it.path.hashCode() == key }
|
||||
if (position != -1) {
|
||||
positions.add(position + positionOffset)
|
||||
files.add(FileDirItem(song.path))
|
||||
removeSongs.add(song)
|
||||
activity.tracksDAO.removeSongPath(song.path)
|
||||
}
|
||||
}
|
||||
|
||||
positions.sortDescending()
|
||||
activity.runOnUiThread {
|
||||
removeSelectedItems(positions)
|
||||
}
|
||||
activity.deleteFiles(files)
|
||||
|
||||
val songIds = removeSongs.map { it.path.hashCode() } as ArrayList<Int>
|
||||
Intent(activity, MusicService::class.java).apply {
|
||||
putExtra(TRACK_IDS, songIds)
|
||||
action = REMOVE_TRACK_IDS
|
||||
activity.startService(this)
|
||||
}
|
||||
|
||||
songs.removeAll(removeSongs)
|
||||
}
|
||||
}
|
||||
|
||||
private fun removeFromPlaylist() {
|
||||
if (selectedKeys.isEmpty()) {
|
||||
return
|
||||
}
|
||||
|
||||
// remove the songs from playlist asap, so they dont get played at Next, if the currently playing song is removed from playlist
|
||||
val songIds = ArrayList<Int>(selectedKeys.size)
|
||||
for (key in selectedKeys) {
|
||||
val song = getItemWithKey(key) ?: continue
|
||||
songIds.add(song.path.hashCode())
|
||||
}
|
||||
|
||||
Intent(activity, MusicService::class.java).apply {
|
||||
putExtra(TRACK_IDS, songIds)
|
||||
action = REMOVE_TRACK_IDS
|
||||
activity.startService(this)
|
||||
}
|
||||
|
||||
val removeSongs = ArrayList<Track>(selectedKeys.size)
|
||||
val positions = ArrayList<Int>()
|
||||
|
||||
for (key in selectedKeys) {
|
||||
val song = getItemWithKey(key) ?: continue
|
||||
|
||||
val position = songs.indexOfFirst { it.path.hashCode() == key }
|
||||
if (position != -1) {
|
||||
positions.add(position + positionOffset)
|
||||
removeSongs.add(song)
|
||||
if (song == MusicService.mCurrTrack) {
|
||||
if (songs.size == removeSongs.size) {
|
||||
activity.sendIntent(REMOVE_CURRENT_TRACK)
|
||||
} else {
|
||||
activity.sendIntent(NEXT)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val removePaths = removeSongs.map { it.path } as ArrayList<String>
|
||||
activity.config.addIgnoredPaths(removePaths)
|
||||
songs.removeAll(removeSongs)
|
||||
positions.sortDescending()
|
||||
removeSelectedItems(positions)
|
||||
ensureBackgroundThread {
|
||||
activity.tracksDAO.removeSongsFromPlaylists(removeSongs)
|
||||
}
|
||||
}
|
||||
|
||||
private fun getFirstSelectedItemPath() = getSelectedSongs().firstOrNull()?.path ?: ""
|
||||
|
||||
private fun getSelectedSongs(): ArrayList<Track> {
|
||||
|
@ -287,29 +153,4 @@ class OldSongAdapter(activity: SimpleActivity, var songs: ArrayList<Track>, val
|
|||
inner class TransparentViewHolder(view: View) : ViewHolder(view)
|
||||
|
||||
inner class NavigationViewHolder(view: View) : ViewHolder(view)
|
||||
|
||||
private fun setupView(view: View, song: Track, layoutPosition: Int) {
|
||||
view.apply {
|
||||
song_frame?.isSelected = selectedKeys.contains(song.path.hashCode())
|
||||
song_title.text = if (textToHighlight.isEmpty()) song.title else song.title.highlightTextPart(textToHighlight, adjustedPrimaryColor)
|
||||
song_title.setTextColor(textColor)
|
||||
|
||||
song_artist.text = if (textToHighlight.isEmpty()) song.artist else song.artist.highlightTextPart(textToHighlight, adjustedPrimaryColor)
|
||||
song_artist.setTextColor(textColor)
|
||||
|
||||
song_note_image.beInvisibleIf(currentSongIndex != layoutPosition)
|
||||
if (currentSongIndex == layoutPosition) {
|
||||
song_note_image.applyColorFilter(textColor)
|
||||
}
|
||||
|
||||
val options = RequestOptions()
|
||||
.error(placeholder)
|
||||
.transform(CenterCrop(), RoundedCorners(8))
|
||||
|
||||
Glide.with(activity)
|
||||
.load(song.coverArt)
|
||||
.apply(options)
|
||||
.into(findViewById(R.id.song_image))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,8 +38,6 @@ const val SET_PROGRESS = PATH + "SET_PROGRESS"
|
|||
const val SET_EQUALIZER = PATH + "SET_EQUALIZER"
|
||||
const val SKIP_BACKWARD = PATH + "SKIP_BACKWARD"
|
||||
const val SKIP_FORWARD = PATH + "SKIP_FORWARD"
|
||||
const val REMOVE_CURRENT_TRACK = PATH + "REMOVE_CURRENT_TRACK"
|
||||
const val REMOVE_TRACK_IDS = PATH + "REMOVE_TRACK_IDS"
|
||||
const val BROADCAST_STATUS = PATH + "BROADCAST_STATUS"
|
||||
const val NOTIFICATION_DISMISSED = PATH + "NOTIFICATION_DISMISSED"
|
||||
|
||||
|
@ -60,7 +58,6 @@ const val SWAP_PREV_NEXT = "swap_prev_next"
|
|||
const val LAST_SLEEP_TIMER_SECONDS = "last_sleep_timer_seconds"
|
||||
const val SLEEP_IN_TS = "sleep_in_ts"
|
||||
|
||||
const val LIST_HEADERS_COUNT = 2
|
||||
const val LOWER_ALPHA = 0.5f
|
||||
|
||||
const val SHOW_FILENAME_NEVER = 1
|
||||
|
|
|
@ -156,8 +156,6 @@ class MusicService : Service(), MediaPlayer.OnPreparedListener, MediaPlayer.OnEr
|
|||
SET_EQUALIZER -> handleSetEqualizer(intent)
|
||||
SKIP_BACKWARD -> skip(false)
|
||||
SKIP_FORWARD -> skip(true)
|
||||
REMOVE_CURRENT_TRACK -> handleRemoveCurrentTrack()
|
||||
REMOVE_TRACK_IDS -> handleRemoveTrackIds(intent)
|
||||
START_SLEEP_TIMER -> startSleepTimer()
|
||||
STOP_SLEEP_TIMER -> stopSleepTimer()
|
||||
BROADCAST_STATUS -> broadcastPlayerStatus()
|
||||
|
@ -299,12 +297,6 @@ class MusicService : Service(), MediaPlayer.OnPreparedListener, MediaPlayer.OnEr
|
|||
}
|
||||
}
|
||||
|
||||
private fun handleRemoveCurrentTrack() {
|
||||
pauseTrack()
|
||||
mCurrTrack = null
|
||||
trackChanged()
|
||||
}
|
||||
|
||||
private fun handleRemoveTrackIds(intent: Intent) {
|
||||
val ids = intent.getIntegerArrayListExtra(TRACK_IDS)
|
||||
val tracksToRemove = ArrayList<Track>()
|
||||
|
|
Loading…
Reference in a new issue