mirror of
https://github.com/fork-maintainers/iceraven-browser
synced 2024-11-03 23:15:31 +00:00
[fenix] Rename HistoryStore/State/Action to HistoryFragmentStore/State/Action.
This commit is contained in:
parent
a682a16b25
commit
ec29bdbc78
@ -31,7 +31,7 @@ class HistoryAdapter(
|
||||
private val historyInteractor: HistoryInteractor
|
||||
) : PagedListAdapter<HistoryItem, HistoryListItemViewHolder>(historyDiffCallback), SelectionHolder<HistoryItem> {
|
||||
|
||||
private var mode: HistoryState.Mode = HistoryState.Mode.Normal
|
||||
private var mode: HistoryFragmentState.Mode = HistoryFragmentState.Mode.Normal
|
||||
override val selectedItems get() = mode.selectedItems
|
||||
|
||||
override fun getItemViewType(position: Int): Int = HistoryListItemViewHolder.LAYOUT_ID
|
||||
@ -41,7 +41,7 @@ class HistoryAdapter(
|
||||
return HistoryListItemViewHolder(view, historyInteractor, this)
|
||||
}
|
||||
|
||||
fun updateMode(mode: HistoryState.Mode) {
|
||||
fun updateMode(mode: HistoryFragmentState.Mode) {
|
||||
this.mode = mode
|
||||
// Update the delete button alpha that the first item holds
|
||||
if (itemCount > 0) notifyItemChanged(0)
|
||||
|
@ -17,7 +17,7 @@ interface HistoryController {
|
||||
}
|
||||
|
||||
class DefaultHistoryController(
|
||||
private val store: HistoryStore,
|
||||
private val store: HistoryFragmentStore,
|
||||
private val openToBrowser: (item: HistoryItem) -> Unit,
|
||||
private val displayDeleteAll: () -> Unit,
|
||||
private val invalidateOptionsMenu: () -> Unit,
|
||||
@ -28,16 +28,16 @@ class DefaultHistoryController(
|
||||
}
|
||||
|
||||
override fun handleSelect(item: HistoryItem) {
|
||||
store.dispatch(HistoryAction.AddItemForRemoval(item))
|
||||
store.dispatch(HistoryFragmentAction.AddItemForRemoval(item))
|
||||
}
|
||||
|
||||
override fun handleDeselect(item: HistoryItem) {
|
||||
store.dispatch(HistoryAction.RemoveItemForRemoval(item))
|
||||
store.dispatch(HistoryFragmentAction.RemoveItemForRemoval(item))
|
||||
}
|
||||
|
||||
override fun handleBackPressed(): Boolean {
|
||||
return if (store.state.mode is HistoryState.Mode.Editing) {
|
||||
store.dispatch(HistoryAction.ExitEditMode)
|
||||
return if (store.state.mode is HistoryFragmentState.Mode.Editing) {
|
||||
store.dispatch(HistoryFragmentAction.ExitEditMode)
|
||||
true
|
||||
} else {
|
||||
false
|
||||
|
@ -42,7 +42,7 @@ import org.mozilla.fenix.share.ShareTab
|
||||
|
||||
@SuppressWarnings("TooManyFunctions", "LargeClass")
|
||||
class HistoryFragment : LibraryPageFragment<HistoryItem>(), BackHandler {
|
||||
private lateinit var historyStore: HistoryStore
|
||||
private lateinit var historyStore: HistoryFragmentStore
|
||||
private lateinit var historyView: HistoryView
|
||||
private lateinit var historyInteractor: HistoryInteractor
|
||||
private lateinit var viewModel: HistoryViewModel
|
||||
@ -54,9 +54,9 @@ class HistoryFragment : LibraryPageFragment<HistoryItem>(), BackHandler {
|
||||
): View? {
|
||||
val view = inflater.inflate(R.layout.fragment_history, container, false)
|
||||
historyStore = StoreProvider.get(this) {
|
||||
HistoryStore(
|
||||
HistoryState(
|
||||
items = listOf(), mode = HistoryState.Mode.Normal
|
||||
HistoryFragmentStore(
|
||||
HistoryFragmentState(
|
||||
items = listOf(), mode = HistoryFragmentState.Mode.Normal
|
||||
)
|
||||
)
|
||||
}
|
||||
@ -106,7 +106,7 @@ class HistoryFragment : LibraryPageFragment<HistoryItem>(), BackHandler {
|
||||
}
|
||||
}
|
||||
viewModel.invalidate()
|
||||
historyStore.dispatch(HistoryAction.ExitDeletionMode)
|
||||
historyStore.dispatch(HistoryFragmentAction.ExitDeletionMode)
|
||||
}
|
||||
}
|
||||
|
||||
@ -135,12 +135,12 @@ class HistoryFragment : LibraryPageFragment<HistoryItem>(), BackHandler {
|
||||
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
|
||||
val mode = historyStore.state.mode
|
||||
when (mode) {
|
||||
HistoryState.Mode.Normal -> R.menu.library_menu
|
||||
is HistoryState.Mode.Editing -> R.menu.history_select_multi
|
||||
HistoryFragmentState.Mode.Normal -> R.menu.library_menu
|
||||
is HistoryFragmentState.Mode.Editing -> R.menu.history_select_multi
|
||||
else -> null
|
||||
}?.let { inflater.inflate(it, menu) }
|
||||
|
||||
if (mode is HistoryState.Mode.Editing) {
|
||||
if (mode is HistoryFragmentState.Mode.Editing) {
|
||||
menu.findItem(R.id.share_history_multi_select)?.run {
|
||||
isVisible = true
|
||||
icon.colorFilter = PorterDuffColorFilter(
|
||||
@ -174,7 +174,7 @@ class HistoryFragment : LibraryPageFragment<HistoryItem>(), BackHandler {
|
||||
lifecycleScope.launch(Main) {
|
||||
deleteSelectedHistory(historyStore.state.mode.selectedItems, components)
|
||||
viewModel.invalidate()
|
||||
historyStore.dispatch(HistoryAction.ExitDeletionMode)
|
||||
historyStore.dispatch(HistoryFragmentAction.ExitDeletionMode)
|
||||
}
|
||||
true
|
||||
}
|
||||
@ -228,13 +228,13 @@ class HistoryFragment : LibraryPageFragment<HistoryItem>(), BackHandler {
|
||||
dialog.cancel()
|
||||
}
|
||||
setPositiveButton(R.string.delete_browsing_data_prompt_allow) { dialog: DialogInterface, _ ->
|
||||
historyStore.dispatch(HistoryAction.EnterDeletionMode)
|
||||
historyStore.dispatch(HistoryFragmentAction.EnterDeletionMode)
|
||||
lifecycleScope.launch {
|
||||
requireComponents.analytics.metrics.track(Event.HistoryAllItemsRemoved)
|
||||
requireComponents.core.historyStorage.deleteEverything()
|
||||
launch(Main) {
|
||||
viewModel.invalidate()
|
||||
historyStore.dispatch(HistoryAction.ExitDeletionMode)
|
||||
historyStore.dispatch(HistoryFragmentAction.ExitDeletionMode)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -18,20 +18,20 @@ import mozilla.components.lib.state.Store
|
||||
data class HistoryItem(val id: Int, val title: String, val url: String, val visitedAt: Long)
|
||||
|
||||
/**
|
||||
* The [Store] for holding the [HistoryState] and applying [HistoryAction]s.
|
||||
* The [Store] for holding the [HistoryFragmentState] and applying [HistoryFragmentAction]s.
|
||||
*/
|
||||
class HistoryStore(initialState: HistoryState) :
|
||||
Store<HistoryState, HistoryAction>(initialState, ::historyStateReducer)
|
||||
class HistoryFragmentStore(initialState: HistoryFragmentState) :
|
||||
Store<HistoryFragmentState, HistoryFragmentAction>(initialState, ::historyStateReducer)
|
||||
|
||||
/**
|
||||
* Actions to dispatch through the `HistoryStore` to modify `HistoryState` through the reducer.
|
||||
*/
|
||||
sealed class HistoryAction : Action {
|
||||
object ExitEditMode : HistoryAction()
|
||||
data class AddItemForRemoval(val item: HistoryItem) : HistoryAction()
|
||||
data class RemoveItemForRemoval(val item: HistoryItem) : HistoryAction()
|
||||
object EnterDeletionMode : HistoryAction()
|
||||
object ExitDeletionMode : HistoryAction()
|
||||
sealed class HistoryFragmentAction : Action {
|
||||
object ExitEditMode : HistoryFragmentAction()
|
||||
data class AddItemForRemoval(val item: HistoryItem) : HistoryFragmentAction()
|
||||
data class RemoveItemForRemoval(val item: HistoryItem) : HistoryFragmentAction()
|
||||
object EnterDeletionMode : HistoryFragmentAction()
|
||||
object ExitDeletionMode : HistoryFragmentAction()
|
||||
}
|
||||
|
||||
/**
|
||||
@ -39,7 +39,7 @@ sealed class HistoryAction : Action {
|
||||
* @property items List of HistoryItem to display
|
||||
* @property mode Current Mode of History
|
||||
*/
|
||||
data class HistoryState(val items: List<HistoryItem>, val mode: Mode) : State {
|
||||
data class HistoryFragmentState(val items: List<HistoryItem>, val mode: Mode) : State {
|
||||
sealed class Mode {
|
||||
open val selectedItems = emptySet<HistoryItem>()
|
||||
|
||||
@ -52,18 +52,18 @@ data class HistoryState(val items: List<HistoryItem>, val mode: Mode) : State {
|
||||
/**
|
||||
* The HistoryState Reducer.
|
||||
*/
|
||||
fun historyStateReducer(state: HistoryState, action: HistoryAction): HistoryState {
|
||||
private fun historyStateReducer(state: HistoryFragmentState, action: HistoryFragmentAction): HistoryFragmentState {
|
||||
return when (action) {
|
||||
is HistoryAction.AddItemForRemoval ->
|
||||
state.copy(mode = HistoryState.Mode.Editing(state.mode.selectedItems + action.item))
|
||||
is HistoryAction.RemoveItemForRemoval -> {
|
||||
is HistoryFragmentAction.AddItemForRemoval ->
|
||||
state.copy(mode = HistoryFragmentState.Mode.Editing(state.mode.selectedItems + action.item))
|
||||
is HistoryFragmentAction.RemoveItemForRemoval -> {
|
||||
val selected = state.mode.selectedItems - action.item
|
||||
state.copy(
|
||||
mode = if (selected.isEmpty()) HistoryState.Mode.Normal else HistoryState.Mode.Editing(selected)
|
||||
mode = if (selected.isEmpty()) HistoryFragmentState.Mode.Normal else HistoryFragmentState.Mode.Editing(selected)
|
||||
)
|
||||
}
|
||||
is HistoryAction.ExitEditMode -> state.copy(mode = HistoryState.Mode.Normal)
|
||||
is HistoryAction.EnterDeletionMode -> state.copy(mode = HistoryState.Mode.Deleting)
|
||||
is HistoryAction.ExitDeletionMode -> state.copy(mode = HistoryState.Mode.Normal)
|
||||
is HistoryFragmentAction.ExitEditMode -> state.copy(mode = HistoryFragmentState.Mode.Normal)
|
||||
is HistoryFragmentAction.EnterDeletionMode -> state.copy(mode = HistoryFragmentState.Mode.Deleting)
|
||||
is HistoryFragmentAction.ExitDeletionMode -> state.copy(mode = HistoryFragmentState.Mode.Normal)
|
||||
}
|
||||
}
|
@ -57,7 +57,7 @@ class HistoryView(
|
||||
.inflate(R.layout.component_history, container, true)
|
||||
|
||||
private var items: List<HistoryItem> = listOf()
|
||||
var mode: HistoryState.Mode = HistoryState.Mode.Normal
|
||||
var mode: HistoryFragmentState.Mode = HistoryFragmentState.Mode.Normal
|
||||
private set
|
||||
|
||||
val historyAdapter = HistoryAdapter(interactor)
|
||||
@ -71,10 +71,10 @@ class HistoryView(
|
||||
}
|
||||
}
|
||||
|
||||
fun update(state: HistoryState) {
|
||||
fun update(state: HistoryFragmentState) {
|
||||
val oldMode = mode
|
||||
|
||||
view.progress_bar.isVisible = state.mode === HistoryState.Mode.Deleting
|
||||
view.progress_bar.isVisible = state.mode === HistoryFragmentState.Mode.Deleting
|
||||
items = state.items
|
||||
mode = state.mode
|
||||
|
||||
@ -88,7 +88,7 @@ class HistoryView(
|
||||
}
|
||||
}
|
||||
|
||||
if (state.mode is HistoryState.Mode.Editing) {
|
||||
if (state.mode is HistoryFragmentState.Mode.Editing) {
|
||||
val unselectedItems = oldMode.selectedItems - state.mode.selectedItems
|
||||
|
||||
state.mode.selectedItems.union(unselectedItems).forEach { item ->
|
||||
@ -97,9 +97,9 @@ class HistoryView(
|
||||
}
|
||||
|
||||
when (val mode = state.mode) {
|
||||
is HistoryState.Mode.Normal ->
|
||||
is HistoryFragmentState.Mode.Normal ->
|
||||
setUiForNormalMode(context.getString(R.string.library_history))
|
||||
is HistoryState.Mode.Editing ->
|
||||
is HistoryFragmentState.Mode.Editing ->
|
||||
setUiForSelectingMode(context.getString(R.string.history_multi_select_title, mode.selectedItems.size))
|
||||
}
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ import org.mozilla.fenix.library.history.HistoryInteractor
|
||||
import org.mozilla.fenix.library.history.HistoryItem
|
||||
import org.mozilla.fenix.library.history.HistoryItemMenu
|
||||
import org.mozilla.fenix.library.history.HistoryItemTimeGroup
|
||||
import org.mozilla.fenix.library.history.HistoryState
|
||||
import org.mozilla.fenix.library.history.HistoryFragmentState
|
||||
|
||||
class HistoryListItemViewHolder(
|
||||
view: View,
|
||||
@ -40,14 +40,14 @@ class HistoryListItemViewHolder(
|
||||
item: HistoryItem,
|
||||
timeGroup: HistoryItemTimeGroup?,
|
||||
showDeleteButton: Boolean,
|
||||
mode: HistoryState.Mode
|
||||
mode: HistoryFragmentState.Mode
|
||||
) {
|
||||
this.item = item
|
||||
|
||||
itemView.history_layout.titleView.text = item.title
|
||||
itemView.history_layout.urlView.text = item.url
|
||||
|
||||
toggleDeleteButton(showDeleteButton, mode === HistoryState.Mode.Normal)
|
||||
toggleDeleteButton(showDeleteButton, mode === HistoryFragmentState.Mode.Normal)
|
||||
|
||||
val headerText = timeGroup?.humanReadable(itemView.context)
|
||||
toggleHeader(headerText)
|
||||
|
@ -16,8 +16,8 @@ import org.junit.Test
|
||||
class HistoryControllerTest {
|
||||
|
||||
private val historyItem = HistoryItem(0, "title", "url", 0.toLong())
|
||||
private val store: HistoryStore = mockk(relaxed = true)
|
||||
private val state: HistoryState = mockk(relaxed = true)
|
||||
private val store: HistoryFragmentStore = mockk(relaxed = true)
|
||||
private val state: HistoryFragmentState = mockk(relaxed = true)
|
||||
|
||||
@Before
|
||||
fun setUp() {
|
||||
@ -28,7 +28,7 @@ class HistoryControllerTest {
|
||||
fun onPressHistoryItemInNormalMode() {
|
||||
var historyItemReceived: HistoryItem? = null
|
||||
|
||||
every { state.mode } returns HistoryState.Mode.Normal
|
||||
every { state.mode } returns HistoryFragmentState.Mode.Normal
|
||||
|
||||
val controller = DefaultHistoryController(
|
||||
store,
|
||||
@ -44,7 +44,7 @@ class HistoryControllerTest {
|
||||
|
||||
@Test
|
||||
fun onPressHistoryItemInEditMode() {
|
||||
every { state.mode } returns HistoryState.Mode.Editing(setOf())
|
||||
every { state.mode } returns HistoryFragmentState.Mode.Editing(setOf())
|
||||
|
||||
val controller = DefaultHistoryController(
|
||||
store,
|
||||
@ -57,13 +57,13 @@ class HistoryControllerTest {
|
||||
controller.handleSelect(historyItem)
|
||||
|
||||
verify {
|
||||
store.dispatch(HistoryAction.AddItemForRemoval(historyItem))
|
||||
store.dispatch(HistoryFragmentAction.AddItemForRemoval(historyItem))
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun onPressSelectedHistoryItemInEditMode() {
|
||||
every { state.mode } returns HistoryState.Mode.Editing(setOf(historyItem))
|
||||
every { state.mode } returns HistoryFragmentState.Mode.Editing(setOf(historyItem))
|
||||
|
||||
val controller = DefaultHistoryController(
|
||||
store,
|
||||
@ -76,13 +76,13 @@ class HistoryControllerTest {
|
||||
controller.handleDeselect(historyItem)
|
||||
|
||||
verify {
|
||||
store.dispatch(HistoryAction.RemoveItemForRemoval(historyItem))
|
||||
store.dispatch(HistoryFragmentAction.RemoveItemForRemoval(historyItem))
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun onBackPressedInNormalMode() {
|
||||
every { state.mode } returns HistoryState.Mode.Normal
|
||||
every { state.mode } returns HistoryFragmentState.Mode.Normal
|
||||
|
||||
val controller = DefaultHistoryController(store, mockk(), mockk(), mockk(), mockk())
|
||||
assertFalse(controller.handleBackPressed())
|
||||
@ -90,13 +90,13 @@ class HistoryControllerTest {
|
||||
|
||||
@Test
|
||||
fun onBackPressedInEditMode() {
|
||||
every { state.mode } returns HistoryState.Mode.Editing(setOf())
|
||||
every { state.mode } returns HistoryFragmentState.Mode.Editing(setOf())
|
||||
|
||||
val controller = DefaultHistoryController(store, mockk(), mockk(), mockk(), mockk())
|
||||
assertTrue(controller.handleBackPressed())
|
||||
|
||||
verify {
|
||||
store.dispatch(HistoryAction.ExitEditMode)
|
||||
store.dispatch(HistoryFragmentAction.ExitEditMode)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -9,55 +9,55 @@ import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertNotSame
|
||||
import org.junit.Test
|
||||
|
||||
class HistoryStoreTest {
|
||||
class HistoryFragmentStoreTest {
|
||||
private val historyItem = HistoryItem(0, "title", "url", 0.toLong())
|
||||
private val newHistoryItem = HistoryItem(1, "title", "url", 0.toLong())
|
||||
|
||||
@Test
|
||||
fun exitEditMode() = runBlocking {
|
||||
val initialState = oneItemEditState()
|
||||
val store = HistoryStore(initialState)
|
||||
val store = HistoryFragmentStore(initialState)
|
||||
|
||||
store.dispatch(HistoryAction.ExitEditMode).join()
|
||||
store.dispatch(HistoryFragmentAction.ExitEditMode).join()
|
||||
assertNotSame(initialState, store.state)
|
||||
assertEquals(store.state.mode, HistoryState.Mode.Normal)
|
||||
assertEquals(store.state.mode, HistoryFragmentState.Mode.Normal)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun itemAddedForRemoval() = runBlocking {
|
||||
val initialState = emptyDefaultState()
|
||||
val store = HistoryStore(initialState)
|
||||
val store = HistoryFragmentStore(initialState)
|
||||
|
||||
store.dispatch(HistoryAction.AddItemForRemoval(newHistoryItem)).join()
|
||||
store.dispatch(HistoryFragmentAction.AddItemForRemoval(newHistoryItem)).join()
|
||||
assertNotSame(initialState, store.state)
|
||||
assertEquals(
|
||||
store.state.mode,
|
||||
HistoryState.Mode.Editing(setOf(newHistoryItem))
|
||||
HistoryFragmentState.Mode.Editing(setOf(newHistoryItem))
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun removeItemForRemoval() = runBlocking {
|
||||
val initialState = twoItemEditState()
|
||||
val store = HistoryStore(initialState)
|
||||
val store = HistoryFragmentStore(initialState)
|
||||
|
||||
store.dispatch(HistoryAction.RemoveItemForRemoval(newHistoryItem)).join()
|
||||
store.dispatch(HistoryFragmentAction.RemoveItemForRemoval(newHistoryItem)).join()
|
||||
assertNotSame(initialState, store.state)
|
||||
assertEquals(store.state.mode, HistoryState.Mode.Editing(setOf(historyItem)))
|
||||
assertEquals(store.state.mode, HistoryFragmentState.Mode.Editing(setOf(historyItem)))
|
||||
}
|
||||
|
||||
private fun emptyDefaultState(): HistoryState = HistoryState(
|
||||
private fun emptyDefaultState(): HistoryFragmentState = HistoryFragmentState(
|
||||
items = listOf(),
|
||||
mode = HistoryState.Mode.Normal
|
||||
mode = HistoryFragmentState.Mode.Normal
|
||||
)
|
||||
|
||||
private fun oneItemEditState(): HistoryState = HistoryState(
|
||||
private fun oneItemEditState(): HistoryFragmentState = HistoryFragmentState(
|
||||
items = listOf(),
|
||||
mode = HistoryState.Mode.Editing(setOf(historyItem))
|
||||
mode = HistoryFragmentState.Mode.Editing(setOf(historyItem))
|
||||
)
|
||||
|
||||
private fun twoItemEditState(): HistoryState = HistoryState(
|
||||
private fun twoItemEditState(): HistoryFragmentState = HistoryFragmentState(
|
||||
items = listOf(),
|
||||
mode = HistoryState.Mode.Editing(setOf(historyItem, newHistoryItem))
|
||||
mode = HistoryFragmentState.Mode.Editing(setOf(historyItem, newHistoryItem))
|
||||
)
|
||||
}
|
Loading…
Reference in New Issue
Block a user