[fenix] Rename BrowserStore/State/Action to BrowserFragmentStore/State/Action.

pull/600/head
Sebastian Kaspari 5 years ago committed by Jeff Boek
parent c0b76b338f
commit 52d15c5be7

@ -58,8 +58,8 @@ import org.mozilla.fenix.collections.CreateCollectionViewModel
import org.mozilla.fenix.components.FenixSnackbar import org.mozilla.fenix.components.FenixSnackbar
import org.mozilla.fenix.components.FindInPageIntegration import org.mozilla.fenix.components.FindInPageIntegration
import org.mozilla.fenix.components.StoreProvider import org.mozilla.fenix.components.StoreProvider
import org.mozilla.fenix.components.toolbar.BrowserState import org.mozilla.fenix.components.toolbar.BrowserFragmentState
import org.mozilla.fenix.components.toolbar.BrowserStore import org.mozilla.fenix.components.toolbar.BrowserFragmentStore
import org.mozilla.fenix.components.toolbar.BrowserToolbarController import org.mozilla.fenix.components.toolbar.BrowserToolbarController
import org.mozilla.fenix.components.toolbar.BrowserToolbarView import org.mozilla.fenix.components.toolbar.BrowserToolbarView
import org.mozilla.fenix.components.toolbar.BrowserToolbarViewInteractor import org.mozilla.fenix.components.toolbar.BrowserToolbarViewInteractor
@ -81,7 +81,7 @@ import org.mozilla.fenix.utils.Settings
*/ */
@Suppress("TooManyFunctions", "LargeClass") @Suppress("TooManyFunctions", "LargeClass")
abstract class BaseBrowserFragment : Fragment(), BackHandler, SessionManager.Observer { abstract class BaseBrowserFragment : Fragment(), BackHandler, SessionManager.Observer {
protected lateinit var browserStore: BrowserStore protected lateinit var browserStore: BrowserFragmentStore
protected lateinit var browserInteractor: BrowserToolbarViewInteractor protected lateinit var browserInteractor: BrowserToolbarViewInteractor
protected lateinit var browserToolbarView: BrowserToolbarView protected lateinit var browserToolbarView: BrowserToolbarView
@ -122,8 +122,8 @@ abstract class BaseBrowserFragment : Fragment(), BackHandler, SessionManager.Obs
val appLink = requireComponents.useCases.appLinksUseCases.appLinkRedirect val appLink = requireComponents.useCases.appLinksUseCases.appLinkRedirect
browserStore = StoreProvider.get(this) { browserStore = StoreProvider.get(this) {
BrowserStore( BrowserFragmentStore(
BrowserState( BrowserFragmentState(
quickActionSheetState = QuickActionSheetState( quickActionSheetState = QuickActionSheetState(
readable = getSessionById()?.readerable ?: false, readable = getSessionById()?.readerable ?: false,
bookmarked = false, bookmarked = false,

@ -8,14 +8,14 @@ import mozilla.components.lib.state.Action
import mozilla.components.lib.state.State import mozilla.components.lib.state.State
import mozilla.components.lib.state.Store import mozilla.components.lib.state.Store
class BrowserStore(initialState: BrowserState) : class BrowserFragmentStore(initialState: BrowserFragmentState) :
Store<BrowserState, BrowserAction>(initialState, ::browserStateReducer) Store<BrowserFragmentState, BrowserFragmentAction>(initialState, ::browserStateReducer)
/** /**
* The state for the Browser Screen * The state for the Browser Screen
* @property quickActionSheetState: state of the quick action sheet * @property quickActionSheetState: state of the quick action sheet
*/ */
data class BrowserState( data class BrowserFragmentState(
val quickActionSheetState: QuickActionSheetState val quickActionSheetState: QuickActionSheetState
) : State ) : State
@ -34,12 +34,12 @@ data class QuickActionSheetState(
val isAppLink: Boolean val isAppLink: Boolean
) : State ) : State
sealed class BrowserAction : Action sealed class BrowserFragmentAction : Action
/** /**
* Actions to dispatch through the [QuickActionSheetStore] to modify [QuickActionSheetState] through the reducer. * Actions to dispatch through the [QuickActionSheetStore] to modify [QuickActionSheetState] through the reducer.
*/ */
sealed class QuickActionSheetAction : BrowserAction() { sealed class QuickActionSheetAction : BrowserFragmentAction() {
data class BookmarkedStateChange(val bookmarked: Boolean) : QuickActionSheetAction() data class BookmarkedStateChange(val bookmarked: Boolean) : QuickActionSheetAction()
data class ReadableStateChange(val readable: Boolean) : QuickActionSheetAction() data class ReadableStateChange(val readable: Boolean) : QuickActionSheetAction()
data class ReaderActiveStateChange(val active: Boolean) : QuickActionSheetAction() data class ReaderActiveStateChange(val active: Boolean) : QuickActionSheetAction()
@ -48,15 +48,15 @@ sealed class QuickActionSheetAction : BrowserAction() {
} }
/** /**
* Reducers for [BrowserStore]. * Reducers for [BrowserFragmentStore].
* *
* A top level reducer that receives the current [BrowserState] and an [Action] and then delegates to the proper child * A top level reducer that receives the current [BrowserFragmentState] and an [Action] and then delegates to the proper child
* *
*/ */
fun browserStateReducer( fun browserStateReducer(
state: BrowserState, state: BrowserFragmentState,
action: BrowserAction action: BrowserFragmentAction
): BrowserState { ): BrowserFragmentState {
return when (action) { return when (action) {
is QuickActionSheetAction -> { is QuickActionSheetAction -> {
QuickActionSheetStateReducer.reduce(state, action) QuickActionSheetStateReducer.reduce(state, action)
@ -65,10 +65,10 @@ fun browserStateReducer(
} }
/** /**
* Reduces [QuickActionSheetAction]s to update [BrowserState]. * Reduces [QuickActionSheetAction]s to update [BrowserFragmentState].
*/ */
internal object QuickActionSheetStateReducer { internal object QuickActionSheetStateReducer {
fun reduce(state: BrowserState, action: QuickActionSheetAction): BrowserState { fun reduce(state: BrowserFragmentState, action: QuickActionSheetAction): BrowserFragmentState {
return when (action) { return when (action) {
is QuickActionSheetAction.BookmarkedStateChange -> is QuickActionSheetAction.BookmarkedStateChange ->
state.copy(quickActionSheetState = state.quickActionSheetState.copy(bookmarked = action.bookmarked)) state.copy(quickActionSheetState = state.quickActionSheetState.copy(bookmarked = action.bookmarked))

@ -28,7 +28,7 @@ open class BrowserToolbarInteractor(
class BrowserInteractor( class BrowserInteractor(
private val context: Context, private val context: Context,
private val store: BrowserStore, private val store: BrowserFragmentStore,
browserToolbarController: BrowserToolbarController, browserToolbarController: BrowserToolbarController,
private val quickActionSheetController: QuickActionSheetController, private val quickActionSheetController: QuickActionSheetController,
private val readerModeController: ReaderModeController, private val readerModeController: ReaderModeController,

@ -111,7 +111,7 @@ class BrowserToolbarView(
} }
@Suppress("UNUSED_PARAMETER") @Suppress("UNUSED_PARAMETER")
fun update(state: BrowserState) { fun update(state: BrowserFragmentState) {
// Intentionally leaving this as a stub for now since we don't actually want to update currently // Intentionally leaving this as a stub for now since we don't actually want to update currently
} }

@ -17,7 +17,7 @@ import kotlinx.android.synthetic.main.layout_quick_action_sheet.*
import kotlinx.android.synthetic.main.layout_quick_action_sheet.view.* import kotlinx.android.synthetic.main.layout_quick_action_sheet.view.*
import mozilla.components.support.ktx.android.view.putCompoundDrawablesRelativeWithIntrinsicBounds import mozilla.components.support.ktx.android.view.putCompoundDrawablesRelativeWithIntrinsicBounds
import org.mozilla.fenix.R import org.mozilla.fenix.R
import org.mozilla.fenix.components.toolbar.BrowserState import org.mozilla.fenix.components.toolbar.BrowserFragmentState
import org.mozilla.fenix.utils.Settings import org.mozilla.fenix.utils.Settings
interface QuickActionSheetViewInteractor { interface QuickActionSheetViewInteractor {
@ -110,7 +110,7 @@ class QuickActionSheetView(
} }
} }
fun update(state: BrowserState) { fun update(state: BrowserFragmentState) {
val quickActionSheetState = state.quickActionSheetState val quickActionSheetState = state.quickActionSheetState
view.quick_action_read.isVisible = quickActionSheetState.readable view.quick_action_read.isVisible = quickActionSheetState.readable
view.quick_action_read.isSelected = quickActionSheetState.readerActive view.quick_action_read.isSelected = quickActionSheetState.readerActive

@ -9,12 +9,12 @@ import org.junit.Assert.assertEquals
import org.junit.Assert.assertNotSame import org.junit.Assert.assertNotSame
import org.junit.Test import org.junit.Test
class BrowserStoreTest { class BrowserFragmentStoreTest {
@Test @Test
fun bookmarkStateChange() = runBlocking { fun bookmarkStateChange() = runBlocking {
val initialState = defaultBrowserState() val initialState = defaultBrowserState()
val store = BrowserStore(initialState) val store = BrowserFragmentStore(initialState)
store.dispatch(QuickActionSheetAction.BookmarkedStateChange(true)).join() store.dispatch(QuickActionSheetAction.BookmarkedStateChange(true)).join()
assertNotSame(initialState, store.state) assertNotSame(initialState, store.state)
@ -24,7 +24,7 @@ class BrowserStoreTest {
@Test @Test
fun readableStateChange() = runBlocking { fun readableStateChange() = runBlocking {
val initialState = defaultBrowserState() val initialState = defaultBrowserState()
val store = BrowserStore(initialState) val store = BrowserFragmentStore(initialState)
store.dispatch(QuickActionSheetAction.ReadableStateChange(true)).join() store.dispatch(QuickActionSheetAction.ReadableStateChange(true)).join()
assertNotSame(initialState, store.state) assertNotSame(initialState, store.state)
@ -34,7 +34,7 @@ class BrowserStoreTest {
@Test @Test
fun readerActiveStateChange() = runBlocking { fun readerActiveStateChange() = runBlocking {
val initialState = defaultBrowserState() val initialState = defaultBrowserState()
val store = BrowserStore(initialState) val store = BrowserFragmentStore(initialState)
store.dispatch(QuickActionSheetAction.ReaderActiveStateChange(true)).join() store.dispatch(QuickActionSheetAction.ReaderActiveStateChange(true)).join()
assertNotSame(initialState, store.state) assertNotSame(initialState, store.state)
@ -44,7 +44,7 @@ class BrowserStoreTest {
@Test @Test
fun bounceNeededChange() = runBlocking { fun bounceNeededChange() = runBlocking {
val initialState = defaultBrowserState() val initialState = defaultBrowserState()
val store = BrowserStore(initialState) val store = BrowserFragmentStore(initialState)
store.dispatch(QuickActionSheetAction.BounceNeededChange).join() store.dispatch(QuickActionSheetAction.BounceNeededChange).join()
assertNotSame(initialState, store.state) assertNotSame(initialState, store.state)
@ -54,14 +54,14 @@ class BrowserStoreTest {
@Test @Test
fun appLinkStateChange() = runBlocking { fun appLinkStateChange() = runBlocking {
val initialState = defaultBrowserState() val initialState = defaultBrowserState()
val store = BrowserStore(initialState) val store = BrowserFragmentStore(initialState)
store.dispatch(QuickActionSheetAction.AppLinkStateChange(true)).join() store.dispatch(QuickActionSheetAction.AppLinkStateChange(true)).join()
assertNotSame(initialState, store.state) assertNotSame(initialState, store.state)
assertEquals(store.state.quickActionSheetState.isAppLink, true) assertEquals(store.state.quickActionSheetState.isAppLink, true)
} }
private fun defaultBrowserState(): BrowserState = BrowserState( private fun defaultBrowserState(): BrowserFragmentState = BrowserFragmentState(
quickActionSheetState = defaultQuickActionSheetState() quickActionSheetState = defaultQuickActionSheetState()
) )

@ -168,7 +168,7 @@ class BrowserInteractorTest {
val metrics: MetricController = mockk() val metrics: MetricController = mockk()
val session: Session = mockk() val session: Session = mockk()
val readerModeController: ReaderModeController = mockk(relaxed = true) val readerModeController: ReaderModeController = mockk(relaxed = true)
val browserStore: BrowserStore = mockk(relaxed = true) val browserStore: BrowserFragmentStore = mockk(relaxed = true)
val interactor = BrowserInteractor( val interactor = BrowserInteractor(
context, context,
browserStore, browserStore,
@ -195,7 +195,7 @@ class BrowserInteractorTest {
val metrics: MetricController = mockk() val metrics: MetricController = mockk()
val session: Session = mockk() val session: Session = mockk()
val readerModeController: ReaderModeController = mockk(relaxed = true) val readerModeController: ReaderModeController = mockk(relaxed = true)
val browserStore: BrowserStore = mockk(relaxed = true) val browserStore: BrowserFragmentStore = mockk(relaxed = true)
val interactor = BrowserInteractor( val interactor = BrowserInteractor(
context, context,

@ -18,7 +18,7 @@ import mozilla.components.feature.app.links.AppLinksUseCases
import org.junit.Before import org.junit.Before
import org.junit.Test import org.junit.Test
import org.mozilla.fenix.components.Components import org.mozilla.fenix.components.Components
import org.mozilla.fenix.components.toolbar.BrowserStore import org.mozilla.fenix.components.toolbar.BrowserFragmentStore
import org.mozilla.fenix.components.toolbar.QuickActionSheetAction import org.mozilla.fenix.components.toolbar.QuickActionSheetAction
@ExperimentalCoroutinesApi @ExperimentalCoroutinesApi
@ -27,7 +27,7 @@ class QuickActionSheetSessionObserverTest {
private lateinit var components: Components private lateinit var components: Components
private lateinit var appLinkRedirect: AppLinksUseCases.GetAppLinkRedirect private lateinit var appLinkRedirect: AppLinksUseCases.GetAppLinkRedirect
private lateinit var store: BrowserStore private lateinit var store: BrowserFragmentStore
private lateinit var dispatch: (QuickActionSheetAction) -> Unit private lateinit var dispatch: (QuickActionSheetAction) -> Unit
@Before @Before

Loading…
Cancel
Save