Skip to content

Commit

Permalink
For mozilla-mobile#2681 - Adds ability to bypass cache when reloading
Browse files Browse the repository at this point in the history
  • Loading branch information
boek committed Jul 14, 2020
1 parent 88af736 commit 573b6a1
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import kotlinx.coroutines.launch
import mozilla.appservices.places.BookmarkRoot
import mozilla.components.browser.session.Session
import mozilla.components.browser.session.SessionManager
import mozilla.components.concept.engine.EngineSession.LoadUrlFlags
import mozilla.components.concept.engine.EngineView
import mozilla.components.concept.engine.prompt.ShareData
import mozilla.components.feature.session.SessionFeature
Expand Down Expand Up @@ -171,7 +172,15 @@ class DefaultBrowserToolbarController(
Do exhaustive when (item) {
ToolbarMenu.Item.Back -> sessionUseCases.goBack.invoke(currentSession)
ToolbarMenu.Item.Forward -> sessionUseCases.goForward.invoke(currentSession)
ToolbarMenu.Item.Reload -> sessionUseCases.reload.invoke(currentSession)
is ToolbarMenu.Item.Reload -> {
val flags = if (item.bypassCache) {
LoadUrlFlags.select(LoadUrlFlags.BYPASS_CACHE)
} else {
LoadUrlFlags.none()
}

sessionUseCases.reload.invoke(currentSession, flags = flags)
}
ToolbarMenu.Item.Stop -> sessionUseCases.stopLoading.invoke(currentSession)
ToolbarMenu.Item.Settings -> browserAnimator.captureEngineViewAndDrawStatically {
val directions = BrowserFragmentDirections.actionBrowserFragmentToSettingsFragment()
Expand Down Expand Up @@ -334,7 +343,7 @@ class DefaultBrowserToolbarController(
val eventItem = when (item) {
ToolbarMenu.Item.Back -> Event.BrowserMenuItemTapped.Item.BACK
ToolbarMenu.Item.Forward -> Event.BrowserMenuItemTapped.Item.FORWARD
ToolbarMenu.Item.Reload -> Event.BrowserMenuItemTapped.Item.RELOAD
is ToolbarMenu.Item.Reload -> Event.BrowserMenuItemTapped.Item.RELOAD
ToolbarMenu.Item.Stop -> Event.BrowserMenuItemTapped.Item.STOP
ToolbarMenu.Item.Settings -> Event.BrowserMenuItemTapped.Item.SETTINGS
is ToolbarMenu.Item.RequestDesktop ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package org.mozilla.fenix.components.toolbar
import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.view.Gravity
import android.view.HapticFeedbackConstants
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
Expand Down Expand Up @@ -209,6 +210,12 @@ class BrowserToolbarView(
customTabSession?.id,
shouldReverseItems = !shouldUseBottomToolbar,
onItemTapped = {
(it as? ToolbarMenu.Item.Reload)?.also { reload ->
if (reload.bypassCache) {
view.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS)
}
}

interactor.onBrowserToolbarMenuItemTapped(it)
}
)
Expand All @@ -217,7 +224,15 @@ class BrowserToolbarView(
context = this,
hasAccountProblem = components.backgroundServices.accountManager.accountNeedsReauth(),
shouldReverseItems = !shouldUseBottomToolbar,
onItemTapped = { interactor.onBrowserToolbarMenuItemTapped(it) },
onItemTapped = {
(it as? ToolbarMenu.Item.Reload)?.also { reload ->
if (reload.bypassCache) {
view.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS)
}
}

interactor.onBrowserToolbarMenuItemTapped(it)
},
lifecycleOwner = lifecycleOwner,
sessionManager = sessionManager,
store = components.core.store,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,13 @@ class DefaultToolbarMenu(
secondaryImageResource = mozilla.components.ui.icons.R.drawable.mozac_ic_stop,
secondaryContentDescription = context.getString(R.string.browser_menu_stop),
secondaryImageTintResource = primaryTextColor(),
disableInSecondaryState = false
disableInSecondaryState = false,
longClickListener = { onItemTapped.invoke(ToolbarMenu.Item.Reload(bypassCache = true)) }
) {
if (session?.loading == true) {
onItemTapped.invoke(ToolbarMenu.Item.Stop)
} else {
onItemTapped.invoke(ToolbarMenu.Item.Reload)
onItemTapped.invoke(ToolbarMenu.Item.Reload(bypassCache = false))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ interface ToolbarMenu {
object Share : Item()
object Back : Item()
object Forward : Item()
object Reload : Item()
data class Reload(val bypassCache: Boolean) : Item()
object Stop : Item()
object OpenInFenix : Item()
object SaveToCollection : Item()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,13 @@ class CustomTabToolbarMenu(
secondaryImageResource = mozilla.components.ui.icons.R.drawable.mozac_ic_stop,
secondaryContentDescription = context.getString(R.string.browser_menu_stop),
secondaryImageTintResource = primaryTextColor(),
disableInSecondaryState = false
disableInSecondaryState = false,
longClickListener = { onItemTapped.invoke(ToolbarMenu.Item.Reload(bypassCache = true)) }
) {
if (session?.loading == true) {
onItemTapped.invoke(ToolbarMenu.Item.Stop)
} else {
onItemTapped.invoke(ToolbarMenu.Item.Reload)
onItemTapped.invoke(ToolbarMenu.Item.Reload(bypassCache = false))
}
}

Expand Down
2 changes: 1 addition & 1 deletion buildSrc/src/main/java/AndroidComponents.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

object AndroidComponents {
const val VERSION = "50.0.20200712190143"
const val VERSION = "51.0.20200714190033"
}

0 comments on commit 573b6a1

Please sign in to comment.