-
Notifications
You must be signed in to change notification settings - Fork 539
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for multi deleting downloads and other major improvements/fixes #1177
Support for multi deleting downloads and other major improvements/fixes #1177
Conversation
This is probably a horrible way to do this, I just am not sure of the best way to go about this to be honest
I believe this is best done in the viewmodel as otherwise the views will recycle when scrolling or switching the episode ranges ect. |
I thought about that, but I figured this would work to do through the adapter, and I wasn't sure how best to actually implement something through the view model. But I agree that would be best also. The whole reason I actually passed scope to the delete method was to pass in a view model scope, which would be best. But then I couldn't figure out how to actually implement it through the view model. But I can definitely give another shot at it. Thanks! Also, one more note, the reason I even switched single deletes to use the new method passing one ID as a Also, just an FYI, I will do the actually multi-delete functionality in this PR and UI in another PR when I build it. I'd rather split it because that way, it's easier to review and less likely to be buggy, in my mind anyway. But if you'd rather me do it differently, I can try as well. |
Since I have a working UI that just needs more improvement I have decided to just do this all at once. |
@fire-light42 for the most part this works other than those TODOs however for the life of me I can not figure out that UI bug mentioned above and was wondering if you have any ideas/suggestions on that... EDIT: I FINALLY figured the UI bug out, turns out it is some sort of Android bug, but there is a workaround the seemed to work... |
If better ideas to fix this I would love to here them, I hate doing it like this
@fire-light42 other than deleting folders (which I am not sure what the best path for that is) I think this is ready for review. I do still plan to finish folders somehow, and you may want me to tweak UI which is fine if so as well, and I can do that. EDIT: I found a few more things that still need to be worked on. |
This does not fully fix the issue but does prevent a whole diffrent icon from showing first but the progress still has to re-populate
@fire-light42 I partially fixed the UI updates so it at least does not show a whole separate icon now but progress still has to repopulate. I think that might be good enough for now? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The previous issues has been resolved from my test, however deleting a movie does not remove it from the list. You have to manually switch tabs for it to register.
app/src/main/java/com/lagradost/cloudstream3/utils/SubtitleUtils.kt
Outdated
Show resolved
Hide resolved
Hmm, it removes it for me... odd... |
It won't remove it if it marks it as failed to delete, is there any indication in logs that it thinks the file failed to delete? |
@Luna712 After some debugging I found out that it is not a safefile/security issue this time, but a race condition. As deleteFile calls some events, those events can delete the file, resulting in toFile=null or delete=false. The fix for this is to also check for exists and moving the toFile to before the event. private fun deleteFile(context: Context, id: Int): Boolean {
val info =
context.getKey<DownloadedFileInfo>(KEY_DOWNLOAD_INFO, id.toString()) ?: return false
val file = info.toFile(context)
downloadEvent.invoke(id to DownloadActionType.Stop)
downloadProgressEvent.invoke(Triple(id, 0, 0))
downloadStatusEvent.invoke(id to DownloadType.IsStopped)
downloadDeleteEvent.invoke(id)
val isFileDeleted = file?.delete() == true || file?.exists() == false
if (isFileDeleted) deleteMatchingSubtitles(context, info)
return isFileDeleted
} |
Ah that makes sense, thanks... fixed! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was about to merge this, however I found one final bug in my final round of testing. 😔
Download an episode of a series, select that episode, then switch to home and back. Then you wont be able to select that episode on the first try. You need to release before holding again or it may also get unchecked even when it tells you 1 episode is selected. Please double check your viewmodel+adapter logic 👍
Whoops, sorry about that, should be fixed. |
…d but impossible to click Also fix sorting child list
I found and fixed one last bug caused by this. |
This will be merged after testing it for a final final time, if I do not find anything new. I will take a look tomorrow. 👍 |
I found another bug 😔 However it is sorta already in prerelease, so I dont think I can block this merge, but a fix would be appreciated. If you cancel a movie or episode from notification during the download, that item wont get removed from the list. This was already the case for movies in prerelease, however this PR also makes episodes have the same bug. |
This PR is already so large if it is another unrelated bug I would prefer to fix in a follow-up if it would be okay with you. If you really want I can try to fix it in this PR. |
Lets make the prerelease people stress test this. |
TODO:
setOnLongClickListener
toggle, so if it is already selected, another long click should deselectcontext.getNameFull()
heredownloadDeleteEvent
if we are multi-deleting so we don't end up running update on the lists for every single downloadContext.isNetworkAvailable()
Code-cleanup:
selectedChangedCallback
in adapter to the cleaner and more descriptiveonItemSelectionChanged
— also should rename other callbacks to this format as wellmultiDeleteStateCallback
(we can just useselectedChangedCallback
/onItemSelectionChanged
)notifyDataSetChanged()
requireContext()
updateList()
toupdateHeaderList()
to matchupdateChildList()
formatSet()
for ids since they should be uniqueisMatchingSubtitle
I have tested this with up to 30 random videos from invidious and two different series with 4 episodes each, all at once, and it does appear to delete them all properly, along in their subtitles, and in about the same amount of time as just deleting one with the pre release version takes for me.
Follow-up patches
Collapsed for cleaner description here since these don't necessarily have anything to do with this patch.