trackbook icon indicating copy to clipboard operation
trackbook copied to clipboard

TracklistFragment.toggleOnboardingLayout doesn't show the image after deleting a track

Open voussoir opened this issue 4 years ago • 1 comments

The function toggleOnboardingLayout shows a picture when your track list is blank.

Screenshot_20211018-010716_270x585

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

xxx

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:

  1. Record one track
  2. Delete it, onboarding image does not appear
  3. Pressing Tracks tab button again makes the onboarding image appear

Possible solutions:

  1. Make sure the tracklist is updated right away instead of waiting for the next UI cycle?
  2. Checking if the track count == 1 before deleting it?

voussoir avatar Oct 18 '21 09:10 voussoir

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.

voussoir avatar Apr 03 '22 17:04 voussoir