refresh all fragments if a folder gets excluded
This commit is contained in:
parent
8a1f0d4feb
commit
bb67649e88
6 changed files with 16 additions and 33 deletions
|
@ -109,13 +109,7 @@ class MainActivity : SimpleActivity() {
|
|||
}
|
||||
|
||||
if (storedExcludedFolders != config.excludedFolders.hashCode()) {
|
||||
updateAllDatabases {
|
||||
runOnUiThread {
|
||||
getAllFragments().forEach {
|
||||
it?.setupFragment(this)
|
||||
}
|
||||
}
|
||||
}
|
||||
refreshAllFragments()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -230,6 +224,10 @@ class MainActivity : SimpleActivity() {
|
|||
}
|
||||
}
|
||||
|
||||
refreshAllFragments()
|
||||
}
|
||||
|
||||
private fun refreshAllFragments() {
|
||||
updateAllDatabases {
|
||||
runOnUiThread {
|
||||
getAllFragments().forEach {
|
||||
|
@ -568,12 +566,8 @@ class MainActivity : SimpleActivity() {
|
|||
}
|
||||
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
fun trackDeleted(event: Events.TrackDeleted) {
|
||||
updateAllDatabases {
|
||||
getAllFragments().forEach {
|
||||
it?.setupFragment(this)
|
||||
}
|
||||
}
|
||||
fun shouldRefreshFragments(event: Events.RefreshFragments) {
|
||||
refreshAllFragments()
|
||||
}
|
||||
|
||||
private fun closeSearch() {
|
||||
|
|
|
@ -10,12 +10,13 @@ import com.simplemobiletools.commons.extensions.highlightTextPart
|
|||
import com.simplemobiletools.commons.views.MyRecyclerView
|
||||
import com.simplemobiletools.musicplayer.R
|
||||
import com.simplemobiletools.musicplayer.extensions.config
|
||||
import com.simplemobiletools.musicplayer.interfaces.RefreshFragmentListener
|
||||
import com.simplemobiletools.musicplayer.models.Events
|
||||
import com.simplemobiletools.musicplayer.models.Folder
|
||||
import kotlinx.android.synthetic.main.item_folder.view.*
|
||||
import org.greenrobot.eventbus.EventBus
|
||||
|
||||
class FoldersAdapter(
|
||||
activity: BaseSimpleActivity, var folders: ArrayList<Folder>, recyclerView: MyRecyclerView, val listener: RefreshFragmentListener, itemClick: (Any) -> Unit
|
||||
activity: BaseSimpleActivity, var folders: ArrayList<Folder>, recyclerView: MyRecyclerView, itemClick: (Any) -> Unit
|
||||
) : MyRecyclerViewAdapter(activity, recyclerView, itemClick), RecyclerViewFastScroller.OnPopupTextUpdate {
|
||||
|
||||
private var textToHighlight = ""
|
||||
|
@ -64,7 +65,7 @@ class FoldersAdapter(
|
|||
}
|
||||
|
||||
finishActMode()
|
||||
listener.refreshItems(this.activity)
|
||||
EventBus.getDefault().post(Events.RefreshFragments())
|
||||
}
|
||||
|
||||
private fun getSelectedFolders(): List<Folder> = folders.filter { selectedKeys.contains(it.hashCode()) }.toList()
|
||||
|
|
|
@ -66,7 +66,7 @@ fun BaseSimpleActivity.deleteTracks(tracks: List<Track>, callback: () -> Unit) {
|
|||
deleteSDK30Uris(uris) { success ->
|
||||
if (success) {
|
||||
removeQueueItems(tracks) {}
|
||||
EventBus.getDefault().post(Events.TrackDeleted())
|
||||
EventBus.getDefault().post(Events.RefreshFragments())
|
||||
callback()
|
||||
} else {
|
||||
toast(R.string.unknown_error_occurred)
|
||||
|
@ -86,7 +86,7 @@ fun BaseSimpleActivity.deleteTracks(tracks: List<Track>, callback: () -> Unit) {
|
|||
}
|
||||
|
||||
removeQueueItems(tracks) {}
|
||||
EventBus.getDefault().post(Events.TrackDeleted())
|
||||
EventBus.getDefault().post(Events.RefreshFragments())
|
||||
callback()
|
||||
}
|
||||
|
||||
|
|
|
@ -19,13 +19,12 @@ import com.simplemobiletools.musicplayer.extensions.config
|
|||
import com.simplemobiletools.musicplayer.extensions.tracksDAO
|
||||
import com.simplemobiletools.musicplayer.helpers.FOLDER
|
||||
import com.simplemobiletools.musicplayer.helpers.TAB_FOLDERS
|
||||
import com.simplemobiletools.musicplayer.interfaces.RefreshFragmentListener
|
||||
import com.simplemobiletools.musicplayer.models.Album
|
||||
import com.simplemobiletools.musicplayer.models.Folder
|
||||
import com.simplemobiletools.musicplayer.models.Track
|
||||
import kotlinx.android.synthetic.main.fragment_folders.view.*
|
||||
|
||||
class FoldersFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerFragment(context, attributeSet), RefreshFragmentListener {
|
||||
class FoldersFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerFragment(context, attributeSet) {
|
||||
private var foldersIgnoringSearch = ArrayList<Folder>()
|
||||
|
||||
override fun setupFragment(activity: BaseSimpleActivity) {
|
||||
|
@ -84,7 +83,7 @@ class FoldersFragment(context: Context, attributeSet: AttributeSet) : MyViewPage
|
|||
|
||||
val adapter = folders_list.adapter
|
||||
if (adapter == null) {
|
||||
FoldersAdapter(activity, folders, folders_list, this) {
|
||||
FoldersAdapter(activity, folders, folders_list) {
|
||||
activity.hideKeyboard()
|
||||
Intent(activity, TracksActivity::class.java).apply {
|
||||
putExtra(FOLDER, (it as Folder).title)
|
||||
|
@ -138,8 +137,4 @@ class FoldersFragment(context: Context, attributeSet: AttributeSet) : MyViewPage
|
|||
folders_fastscroller.updateColors(adjustedPrimaryColor)
|
||||
folders_placeholder_2.setTextColor(adjustedPrimaryColor)
|
||||
}
|
||||
|
||||
override fun refreshItems(activity: BaseSimpleActivity) {
|
||||
setupFragment(activity)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +0,0 @@
|
|||
package com.simplemobiletools.musicplayer.interfaces
|
||||
|
||||
import com.simplemobiletools.commons.activities.BaseSimpleActivity
|
||||
|
||||
interface RefreshFragmentListener {
|
||||
fun refreshItems(activity: BaseSimpleActivity)
|
||||
}
|
|
@ -10,7 +10,7 @@ class Events {
|
|||
class ProgressUpdated(val progress: Int)
|
||||
class SleepTimerChanged(val seconds: Int)
|
||||
class PlaylistsUpdated
|
||||
class TrackDeleted
|
||||
class RefreshFragments
|
||||
class NoStoragePermission
|
||||
class RefreshTracks
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue