diff --git a/app/src/main/java/code/name/monkey/retromusic/adapter/SongFileAdapter.kt b/app/src/main/java/code/name/monkey/retromusic/adapter/SongFileAdapter.kt index f76c5d28..cc169e2d 100644 --- a/app/src/main/java/code/name/monkey/retromusic/adapter/SongFileAdapter.kt +++ b/app/src/main/java/code/name/monkey/retromusic/adapter/SongFileAdapter.kt @@ -55,12 +55,8 @@ class SongFileAdapter( override fun onBindViewHolder(holder: ViewHolder, index: Int) { val file = dataSet!![index] - holder.itemView.isActivated = isChecked(file) - - if (holder.title != null) { - holder.title!!.text = getFileTitle(file) - } + holder.title?.text = getFileTitle(file) if (holder.text != null) { if (holder.itemViewType == FILE) { holder.text!!.text = getFileText(file) diff --git a/app/src/main/java/code/name/monkey/retromusic/adapter/album/AlbumAdapter.kt b/app/src/main/java/code/name/monkey/retromusic/adapter/album/AlbumAdapter.kt index 40b79f5a..0ffe9a5f 100644 --- a/app/src/main/java/code/name/monkey/retromusic/adapter/album/AlbumAdapter.kt +++ b/app/src/main/java/code/name/monkey/retromusic/adapter/album/AlbumAdapter.kt @@ -80,19 +80,11 @@ open class AlbumAdapter(protected val activity: AppCompatActivity, override fun onBindViewHolder(holder: ViewHolder, position: Int) { val album = dataSet[position] - val isChecked = isChecked(album) holder.itemView.isActivated = isChecked - - if (holder.title != null) { - holder.title!!.text = getAlbumTitle(album) - } - if (holder.text != null) { - holder.text!!.text = getAlbumText(album) - } - if (holder.playSongs != null) { - holder.playSongs!!.setOnClickListener { MusicPlayerRemote.openQueue(album.songs!!, 0, true) } - } + holder.title?.text = getAlbumTitle(album) + holder.text?.text = getAlbumText(album) + holder.playSongs?.setOnClickListener { album.songs?.let { songs -> MusicPlayerRemote.openQueue(songs, 0, true) } } loadAlbumCover(album, holder) } diff --git a/app/src/main/java/code/name/monkey/retromusic/adapter/album/AlbumFullWidthAdapter.kt b/app/src/main/java/code/name/monkey/retromusic/adapter/album/AlbumFullWidthAdapter.kt index 5cf7c8fe..84d30fac 100644 --- a/app/src/main/java/code/name/monkey/retromusic/adapter/album/AlbumFullWidthAdapter.kt +++ b/app/src/main/java/code/name/monkey/retromusic/adapter/album/AlbumFullWidthAdapter.kt @@ -40,18 +40,10 @@ class AlbumFullWidthAdapter(private val activity: Activity, private val dataSet: override fun onBindViewHolder(holder: FullMetalViewHolder, position: Int) { // don't forget about calling supper.onBindViewHolder! super.onBindViewHolder(holder, position) - val album = dataSet[position] - - if (holder.title != null) { - holder.title!!.text = getAlbumTitle(album) - } - if (holder.text != null) { - holder.text!!.text = getAlbumText(album) - } - if (holder.playSongs != null) { - holder.playSongs!!.setOnClickListener { MusicPlayerRemote.openQueue(album.songs!!, 0, true) } - } + holder.title?.text = getAlbumTitle(album) + holder.text?.text = getAlbumText(album) + holder.playSongs?.setOnClickListener { album.songs?.let { songs -> MusicPlayerRemote.openQueue(songs, 0, true) } } loadAlbumCover(album, holder) } diff --git a/app/src/main/java/code/name/monkey/retromusic/adapter/playlist/AddToPlaylist.kt b/app/src/main/java/code/name/monkey/retromusic/adapter/playlist/AddToPlaylist.kt deleted file mode 100644 index 684270ba..00000000 --- a/app/src/main/java/code/name/monkey/retromusic/adapter/playlist/AddToPlaylist.kt +++ /dev/null @@ -1,44 +0,0 @@ -package code.name.monkey.retromusic.adapter.playlist - -import android.app.Activity -import android.app.Dialog -import android.view.LayoutInflater -import android.view.View -import android.view.ViewGroup - -import java.util.ArrayList -import androidx.recyclerview.widget.RecyclerView -import code.name.monkey.retromusic.model.Playlist -import code.name.monkey.retromusic.model.Song -import code.name.monkey.retromusic.adapter.base.MediaEntryViewHolder -import code.name.monkey.retromusic.adapter.playlist.AddToPlaylist.ViewHolder -import code.name.monkey.retromusic.util.PlaylistsUtil - -class AddToPlaylist(private val activity: Activity, - private val playlists: ArrayList, private val itemLayoutRes: Int, - private val songs: ArrayList, private val dialog: Dialog) : RecyclerView.Adapter() { - - override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { - return ViewHolder(LayoutInflater.from(activity).inflate(itemLayoutRes, parent, false)) - } - - override fun onBindViewHolder(holder: ViewHolder, position: Int) { - val playlist = playlists[position] - if (holder.title != null) { - holder.title!!.text = playlist.name - } - } - - override fun getItemCount(): Int { - return playlists.size - } - - inner class ViewHolder(itemView: View) : MediaEntryViewHolder(itemView) { - - override fun onClick(v: View?) { - super.onClick(v) - PlaylistsUtil.addToPlaylist(activity, songs, playlists[adapterPosition].id, true) - dialog.dismiss() - } - } -} diff --git a/app/src/main/java/code/name/monkey/retromusic/adapter/playlist/PlaylistAdapter.kt b/app/src/main/java/code/name/monkey/retromusic/adapter/playlist/PlaylistAdapter.kt index 17d4f738..8d040588 100755 --- a/app/src/main/java/code/name/monkey/retromusic/adapter/playlist/PlaylistAdapter.kt +++ b/app/src/main/java/code/name/monkey/retromusic/adapter/playlist/PlaylistAdapter.kt @@ -5,7 +5,6 @@ import android.view.LayoutInflater import android.view.MenuItem import android.view.View import android.view.ViewGroup -import androidx.annotation.LayoutRes import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.widget.PopupMenu import code.name.monkey.appthemehelper.ThemeStore @@ -30,15 +29,15 @@ import code.name.monkey.retromusic.util.NavigationUtil import java.util.* -class PlaylistAdapter(protected val activity: AppCompatActivity, dataSet: ArrayList, - @param:LayoutRes protected var itemLayoutRes: Int, cabHolder: CabHolder?) : AbsMultiSelectAdapter(activity, cabHolder, R.menu.menu_playlists_selection) { - var dataSet: ArrayList - protected set +class PlaylistAdapter(private val activity: AppCompatActivity, + var dataSet: ArrayList, + private var itemLayoutRes: Int, + cabHolder: CabHolder?) : AbsMultiSelectAdapter(activity, cabHolder, R.menu.menu_playlists_selection) { + var songs = ArrayList() init { - this.dataSet = dataSet setHasStableIds(true) } @@ -70,20 +69,11 @@ class PlaylistAdapter(protected val activity: AppCompatActivity, dataSet: ArrayL } override fun onBindViewHolder(holder: ViewHolder, position: Int) { - val playlist = dataSet[position] - val songs = getSongs(playlist) holder.itemView.isActivated = isChecked(playlist) - - if (holder.title != null) { - holder.title!!.text = getPlaylistTitle(playlist) - } - if (holder.text != null) { - holder.text!!.text = getPlaylistText(playlist) - } - if (holder.image != null) { - holder.image!!.setImageDrawable(getIconRes(playlist)) - } + holder.title?.text = getPlaylistTitle(playlist) + holder.text?.text = getPlaylistText(playlist) + holder.image?.setImageDrawable(getIconRes(playlist)) } private fun getIconRes(playlist: Playlist): Drawable { diff --git a/app/src/main/java/code/name/monkey/retromusic/adapter/song/OrderablePlaylistSongAdapter.kt b/app/src/main/java/code/name/monkey/retromusic/adapter/song/OrderablePlaylistSongAdapter.kt index 88f78b8b..2753c13c 100644 --- a/app/src/main/java/code/name/monkey/retromusic/adapter/song/OrderablePlaylistSongAdapter.kt +++ b/app/src/main/java/code/name/monkey/retromusic/adapter/song/OrderablePlaylistSongAdapter.kt @@ -100,9 +100,9 @@ class OrderablePlaylistSongAdapter(activity: AppCompatActivity, init { if (dragView != null) { if (onMoveItemListener != null) { - dragView!!.visibility = View.VISIBLE + dragView?.visibility = View.VISIBLE } else { - dragView!!.visibility = View.GONE + dragView?.visibility = View.GONE } } } diff --git a/app/src/main/java/code/name/monkey/retromusic/adapter/song/PlayingQueueAdapter.kt b/app/src/main/java/code/name/monkey/retromusic/adapter/song/PlayingQueueAdapter.kt index eaaf686e..1f388554 100644 --- a/app/src/main/java/code/name/monkey/retromusic/adapter/song/PlayingQueueAdapter.kt +++ b/app/src/main/java/code/name/monkey/retromusic/adapter/song/PlayingQueueAdapter.kt @@ -5,8 +5,6 @@ import android.graphics.PorterDuff import android.view.MenuItem import android.view.View import android.widget.ImageView -import androidx.annotation.ColorInt -import androidx.annotation.LayoutRes import androidx.appcompat.app.AppCompatActivity import code.name.monkey.retromusic.R import code.name.monkey.retromusic.helper.MusicPlayerRemote @@ -20,36 +18,27 @@ import com.h6ah4i.android.widget.advrecyclerview.draggable.annotation.DraggableI import java.util.* -class PlayingQueueAdapter : SongAdapter, DraggableItemAdapter { +class PlayingQueueAdapter(activity: AppCompatActivity, + dataSet: ArrayList, + private var current: Int, + itemLayoutRes: Int) : SongAdapter( + activity, + dataSet, + itemLayoutRes, + false, + null +), DraggableItemAdapter { - private var current: Int = 0 private var color = -1 - constructor(activity: AppCompatActivity, dataSet: ArrayList, current: Int, - @LayoutRes itemLayoutRes: Int) : super(activity, dataSet, itemLayoutRes, false, null) { - this.current = current - } - - constructor(activity: AppCompatActivity, - dataSet: ArrayList, current: Int, - @LayoutRes itemLayoutRes: Int, - @ColorInt color: Int) : super(activity, dataSet, itemLayoutRes, false, null) { - this.current = current - this.color = color - } - override fun createViewHolder(view: View): SongAdapter.ViewHolder { return ViewHolder(view) } override fun onBindViewHolder(holder: SongAdapter.ViewHolder, position: Int) { super.onBindViewHolder(holder, position) - if (holder.imageText != null) { - holder.imageText!!.text = (position - current).toString() - } - if (holder.time != null) { - holder.time!!.text = MusicUtil.getReadableDurationString(dataSet[position].duration) - } + holder.imageText?.text = (position - current).toString() + holder.time?.text = MusicUtil.getReadableDurationString(dataSet[position].duration) if (holder.itemViewType == HISTORY || holder.itemViewType == CURRENT) { setAlpha(holder, 0.5f) } @@ -66,15 +55,10 @@ class PlayingQueueAdapter : SongAdapter, DraggableItemAdapter