1
0
Fork 0

For #11371 - Fix for Dynamic Download Dialog

master
codrut.topliceanu 2020-06-12 17:39:12 +03:00 committed by Emily Kager
parent ed41c97be0
commit 0eb2f328dc
1 changed files with 34 additions and 16 deletions

View File

@ -357,9 +357,13 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, Session
downloadJobStatus == AbstractFetchDownloadService.DownloadJobStatus.FAILED downloadJobStatus == AbstractFetchDownloadService.DownloadJobStatus.FAILED
) { ) {
saveDownloadDialogState(session, downloadState, downloadJobStatus) saveDownloadDialogState(
downloadState.sessionId,
downloadState,
downloadJobStatus
)
DynamicDownloadDialog( val dynamicDownloadDialog = DynamicDownloadDialog(
container = view.browserLayout, container = view.browserLayout,
downloadState = downloadState, downloadState = downloadState,
didFail = downloadJobStatus == AbstractFetchDownloadService.DownloadJobStatus.FAILED, didFail = downloadJobStatus == AbstractFetchDownloadService.DownloadJobStatus.FAILED,
@ -375,20 +379,26 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, Session
}, },
view = view.viewDynamicDownloadDialog, view = view.viewDynamicDownloadDialog,
toolbarHeight = toolbarHeight, toolbarHeight = toolbarHeight,
onDismiss = { sharedViewModel.downloadDialogState.remove(session.id) } onDismiss = { sharedViewModel.downloadDialogState.remove(downloadState.sessionId) }
).show() )
browserToolbarView.expand()
// Don't show the dialog if we aren't in the tab that started the download
if (downloadState.sessionId == sessionManager.selectedSession?.id) {
dynamicDownloadDialog.show()
browserToolbarView.expand()
}
} }
} }
resumeDownloadDialogState(sessionManager.selectedSession?.id,
store, view, context, toolbarHeight)
downloadsFeature.set( downloadsFeature.set(
downloadFeature, downloadFeature,
owner = this, owner = this,
view = view view = view
) )
resumeDownloadDialogState(session, store, view, context, toolbarHeight)
pipFeature = PictureInPictureFeature( pipFeature = PictureInPictureFeature(
store = store, store = store,
activity = requireActivity(), activity = requireActivity(),
@ -531,6 +541,7 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, Session
override fun onSessionSelected(session: Session) { override fun onSessionSelected(session: Session) {
fullScreenChanged(false) fullScreenChanged(false)
browserToolbarView.expand() browserToolbarView.expand()
resumeDownloadDialogState(session.id, store, view, context, toolbarHeight)
} }
}, owner = viewLifecycleOwner) }, owner = viewLifecycleOwner)
@ -583,14 +594,16 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, Session
* other fragments navigation. * other fragments navigation.
* */ * */
private fun saveDownloadDialogState( private fun saveDownloadDialogState(
session: Session, sessionId: String?,
downloadState: DownloadState, downloadState: DownloadState,
downloadJobStatus: AbstractFetchDownloadService.DownloadJobStatus downloadJobStatus: AbstractFetchDownloadService.DownloadJobStatus
) { ) {
sharedViewModel.downloadDialogState[session.id] = Pair( sessionId?.let { id ->
downloadState, sharedViewModel.downloadDialogState[id] = Pair(
downloadJobStatus == AbstractFetchDownloadService.DownloadJobStatus.FAILED downloadState,
) downloadJobStatus == AbstractFetchDownloadService.DownloadJobStatus.FAILED
)
}
} }
/** /**
@ -600,20 +613,25 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, Session
* download, because [DownloadsFeature] clears any queued downloads onStop. * download, because [DownloadsFeature] clears any queued downloads onStop.
* */ * */
private fun resumeDownloadDialogState( private fun resumeDownloadDialogState(
session: Session, sessionId: String?,
store: BrowserStore, store: BrowserStore,
view: View, view: View,
context: Context, context: Context,
toolbarHeight: Int toolbarHeight: Int
) { ) {
val savedDownloadState = val savedDownloadState =
sharedViewModel.downloadDialogState[session.id] ?: return sharedViewModel.downloadDialogState[sessionId]
if (savedDownloadState == null || sessionId == null) {
view.viewDynamicDownloadDialog.visibility = View.GONE
return
}
val onTryAgain: (Long) -> Unit = { val onTryAgain: (Long) -> Unit = {
savedDownloadState.first?.let { dlState -> savedDownloadState.first?.let { dlState ->
store.dispatch( store.dispatch(
ContentAction.UpdateDownloadAction( ContentAction.UpdateDownloadAction(
session.id, dlState.copy(skipConfirmation = true) sessionId, dlState.copy(skipConfirmation = true)
) )
) )
} }
@ -630,7 +648,7 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, Session
} }
val onDismiss: () -> Unit = val onDismiss: () -> Unit =
{ sharedViewModel.downloadDialogState.remove(session.id) } { sharedViewModel.downloadDialogState.remove(sessionId) }
DynamicDownloadDialog( DynamicDownloadDialog(
container = view.browserLayout, container = view.browserLayout,