TracklistFragment.toggleOnboardingLayout doesn't show the image after deleting a track
The function toggleOnboardingLayout shows a picture when your track list is blank.

But when you delete your last track, this image does not reappear until you reload the view by pressing the "Tracks" tab button again.

This line in onYesNoDialog and this line in onLayoutCompleted both try to display the onboarding, but the TracklistAdapter doesn't think the tracklist is empty yet so it doesn't work. I added a log statement to check tracklistAdapter.tracklist.tracklistElements.size and it was 1 even though I deleted the last track. When I pushed the Tracks button again, then the length was 0.
Note: I have already tried switching the order of the lines to make sure removeTrackAtPosition is called before toggleOnboardingLayout:
override fun onYesNoDialog(type: Int, dialogResult: Boolean, payload: Int, payloadString: String) {
when (type) {
Keys.DIALOG_DELETE_TRACK -> {
when (dialogResult) {
// user tapped remove track
true -> {
tracklistAdapter.removeTrackAtPosition(activity as Context, payload)
toggleOnboardingLayout()
}
// user tapped cancel
false -> {
tracklistAdapter.notifyItemChanged(payload)
}
}
}
}
}
But this still did not solve the problem! I'm guessing that when removeTrack calls notifyItemRemoved, it doesn't actually remove the item it until the next UI update, but toggleOnboardingLayout has already moved on.
To reproduce:
- Record one track
- Delete it, onboarding image does not appear
- Pressing Tracks tab button again makes the onboarding image appear
Possible solutions:
- Make sure the tracklist is updated right away instead of waiting for the next UI cycle?
- Checking if the track count == 1 before deleting it?
Edit: removed my code snippet because I broke the cancel button.
The new solution I came up with is to make TracklistAdapter.removeTrackAtPosition synchronous instead of asynchronous. If it's synchronous, then TracklistFragment.onYesNoDialog can call removeTrackAtPosition and then call toggleOnboardingLayout immediately, and it will be accurate.
I know that synchronous functions inside of a UI handler are usually avoided, but if deleting the track is fast then it shouldn't be a big problem. I haven't figured out an async solution yet since it gets a little tangled up.