deselect all list items if the current tab changes

This commit is contained in:
tibbi 2020-10-17 17:46:59 +02:00
parent 6fbae01f9f
commit a28908e4ce
7 changed files with 31 additions and 2 deletions

View file

@ -35,6 +35,8 @@ import com.simplemobiletools.musicplayer.models.Events
import com.simplemobiletools.musicplayer.models.Playlist
import com.simplemobiletools.musicplayer.services.MusicService
import kotlinx.android.synthetic.main.activity_main.*
import kotlinx.android.synthetic.main.fragment_artists.*
import kotlinx.android.synthetic.main.fragment_playlists.*
import kotlinx.android.synthetic.main.fragment_songs.*
import kotlinx.android.synthetic.main.view_current_track_bar.*
import org.greenrobot.eventbus.EventBus
@ -221,6 +223,10 @@ class MainActivity : SimpleActivity(), MainActivityInterface {
override fun onPageSelected(position: Int) {
main_tabs_holder.getTabAt(position)?.select()
getAllFragments().forEach {
it?.finishActMode()
}
invalidateOptionsMenu()
}
})
@ -478,6 +484,8 @@ class MainActivity : SimpleActivity(), MainActivityInterface {
}
}
private fun getAllFragments() = arrayListOf(artists_fragment_holder, playlists_fragment_holder)
@Subscribe(threadMode = ThreadMode.MAIN)
fun trackChangedEvent(event: Events.TrackChanged) {
if (wasInitialPlaylistSet) {

View file

@ -60,8 +60,8 @@ abstract class SongsDatabase : RoomDatabase() {
}
private fun addInitialPlaylist(context: Context) {
val allSongs = context.resources.getString(R.string.all_songs)
val playlist = Playlist(ALL_TRACKS_PLAYLIST_ID, allSongs)
val allTracks = context.resources.getString(R.string.all_tracks)
val playlist = Playlist(ALL_TRACKS_PLAYLIST_ID, allTracks)
context.playlistDAO.insert(playlist)
}

View file

@ -6,6 +6,7 @@ import android.content.Intent
import android.provider.MediaStore.Audio
import android.util.AttributeSet
import com.google.gson.Gson
import com.simplemobiletools.commons.adapters.MyRecyclerViewAdapter
import com.simplemobiletools.commons.extensions.getIntValue
import com.simplemobiletools.commons.extensions.getLongValue
import com.simplemobiletools.commons.extensions.getStringValue
@ -35,6 +36,10 @@ class ArtistsFragment(context: Context, attributeSet: AttributeSet) : MyViewPage
}
}
override fun finishActMode() {
(artists_list.adapter as? MyRecyclerViewAdapter)?.finishActMode()
}
private fun getArtists(activity: Activity, callback: (artists: ArrayList<Artist>) -> Unit) {
ensureBackgroundThread {
val artists = ArrayList<Artist>()

View file

@ -7,4 +7,6 @@ import com.simplemobiletools.musicplayer.activities.SimpleActivity
abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet) : RelativeLayout(context, attributeSet) {
abstract fun setupFragment(activity: SimpleActivity)
abstract fun finishActMode()
}

View file

@ -2,6 +2,7 @@ package com.simplemobiletools.musicplayer.fragments
import android.content.Context
import android.util.AttributeSet
import com.simplemobiletools.commons.adapters.MyRecyclerViewAdapter
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
import com.simplemobiletools.musicplayer.activities.SimpleActivity
import com.simplemobiletools.musicplayer.adapters.PlaylistsAdapter
@ -28,4 +29,8 @@ class PlaylistsFragment(context: Context, attributeSet: AttributeSet) : MyViewPa
}
}
}
override fun finishActMode() {
(playlists_list.adapter as? MyRecyclerViewAdapter)?.finishActMode()
}
}

View file

@ -10,6 +10,7 @@ import android.os.Environment
import android.util.AttributeSet
import android.view.ViewGroup
import android.widget.SeekBar
import com.simplemobiletools.commons.adapters.MyRecyclerViewAdapter
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.interfaces.RecyclerScrollCallback
import com.simplemobiletools.commons.views.MyLinearLayoutManager
@ -26,6 +27,7 @@ import com.simplemobiletools.musicplayer.interfaces.SongListListener
import com.simplemobiletools.musicplayer.models.Track
import com.simplemobiletools.musicplayer.services.MusicService
import com.squareup.picasso.Picasso
import kotlinx.android.synthetic.main.fragment_artists.view.*
import kotlinx.android.synthetic.main.fragment_songs.view.*
import kotlinx.android.synthetic.main.item_navigation.view.*
import java.util.*
@ -80,6 +82,10 @@ class SongsFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerF
storeStateVariables()
}
override fun finishActMode() {
(songs_list.adapter as? MyRecyclerViewAdapter)?.finishActMode()
}
private fun storeStateVariables() {
config.apply {
storedTextColor = textColor

View file

@ -45,6 +45,8 @@
<string name="show_filename">Show filename as song title</string>
<string name="title_is_not_available">If title is not available</string>
<string name="show_album_cover">Show album cover on the main screen</string>
<string name="all_tracks">All tracks</string>
<string name="add_to_playlist">Add to playlist</string>
<!-- Artists -->
<string name="artists">Artists</string>
@ -61,6 +63,7 @@
<!-- Queue -->
<string name="next_track">Next:</string>
<string name="track_queue">Track queue</string>
<string name="add_to_queue">Add to queue</string>
<!-- Settings -->
<string name="equalizer">Equalizer</string>