[fenix] Fix breaking changes from new TrackingProtectionException

pull/600/head
Chenxia Liu 5 years ago committed by Sawyer Blatz
parent 9006f7f610
commit b7a62205ec

@ -9,6 +9,7 @@ import android.view.ViewGroup
import androidx.recyclerview.widget.DiffUtil import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.ListAdapter import androidx.recyclerview.widget.ListAdapter
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import mozilla.components.concept.engine.content.blocking.TrackingProtectionException
import org.mozilla.fenix.exceptions.viewholders.ExceptionsDeleteButtonViewHolder import org.mozilla.fenix.exceptions.viewholders.ExceptionsDeleteButtonViewHolder
import org.mozilla.fenix.exceptions.viewholders.ExceptionsHeaderViewHolder import org.mozilla.fenix.exceptions.viewholders.ExceptionsHeaderViewHolder
import org.mozilla.fenix.exceptions.viewholders.ExceptionsListItemViewHolder import org.mozilla.fenix.exceptions.viewholders.ExceptionsListItemViewHolder
@ -16,7 +17,7 @@ import org.mozilla.fenix.exceptions.viewholders.ExceptionsListItemViewHolder
sealed class AdapterItem { sealed class AdapterItem {
object DeleteButton : AdapterItem() object DeleteButton : AdapterItem()
object Header : AdapterItem() object Header : AdapterItem()
data class Item(val item: ExceptionsItem) : AdapterItem() data class Item(val item: TrackingProtectionException) : AdapterItem()
} }
/** /**
@ -31,7 +32,7 @@ class ExceptionsAdapter(
* Change the list of items that are displayed. * Change the list of items that are displayed.
* Header and footer items are added to the list as well. * Header and footer items are added to the list as well.
*/ */
fun updateData(exceptions: List<ExceptionsItem>) { fun updateData(exceptions: List<TrackingProtectionException>) {
val adapterItems = mutableListOf<AdapterItem>() val adapterItems = mutableListOf<AdapterItem>()
adapterItems.add(AdapterItem.Header) adapterItems.add(AdapterItem.Header)
exceptions.mapTo(adapterItems) { AdapterItem.Item(it) } exceptions.mapTo(adapterItems) { AdapterItem.Item(it) }

@ -12,6 +12,7 @@ import android.view.ViewGroup
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import kotlinx.android.synthetic.main.fragment_exceptions.view.* import kotlinx.android.synthetic.main.fragment_exceptions.view.*
import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.ExperimentalCoroutinesApi
import mozilla.components.concept.engine.content.blocking.TrackingProtectionException
import mozilla.components.feature.session.TrackingProtectionUseCases import mozilla.components.feature.session.TrackingProtectionUseCases
import mozilla.components.lib.state.ext.consumeFrom import mozilla.components.lib.state.ext.consumeFrom
import org.mozilla.fenix.BrowserDirection import org.mozilla.fenix.BrowserDirection
@ -74,7 +75,7 @@ class ExceptionsFragment : Fragment() {
reloadExceptions() reloadExceptions()
} }
private fun deleteOneItem(item: ExceptionsItem) { private fun deleteOneItem(item: TrackingProtectionException) {
// We can't currently delete one item in this Exceptions list with a URL with the GV API // We can't currently delete one item in this Exceptions list with a URL with the GV API
// See https://github.com/mozilla-mobile/android-components/issues/4699 // See https://github.com/mozilla-mobile/android-components/issues/4699
Log.e("Remove one exception", "$item") Log.e("Remove one exception", "$item")
@ -92,8 +93,7 @@ class ExceptionsFragment : Fragment() {
private fun reloadExceptions() { private fun reloadExceptions() {
trackingProtectionUseCases.fetchExceptions { resultList -> trackingProtectionUseCases.fetchExceptions { resultList ->
val exceptionsList = resultList.map { ExceptionsItem(it) } exceptionsStore.dispatch(ExceptionsFragmentAction.Change(resultList))
exceptionsStore.dispatch(ExceptionsFragmentAction.Change(exceptionsList))
} }
} }
} }

@ -4,6 +4,7 @@
package org.mozilla.fenix.exceptions package org.mozilla.fenix.exceptions
import mozilla.components.concept.engine.content.blocking.TrackingProtectionException
import mozilla.components.lib.state.Action 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
@ -12,7 +13,7 @@ import mozilla.components.lib.state.Store
* Class representing an exception item * Class representing an exception item
* @property url Host of the exception * @property url Host of the exception
*/ */
data class ExceptionsItem(val url: String) data class ExceptionItem(override val url: String) : TrackingProtectionException
/** /**
* The [Store] for holding the [ExceptionsFragmentState] and applying [ExceptionsFragmentAction]s. * The [Store] for holding the [ExceptionsFragmentState] and applying [ExceptionsFragmentAction]s.
@ -24,14 +25,14 @@ class ExceptionsFragmentStore(initialState: ExceptionsFragmentState) :
* Actions to dispatch through the `ExceptionsStore` to modify `ExceptionsState` through the reducer. * Actions to dispatch through the `ExceptionsStore` to modify `ExceptionsState` through the reducer.
*/ */
sealed class ExceptionsFragmentAction : Action { sealed class ExceptionsFragmentAction : Action {
data class Change(val list: List<ExceptionsItem>) : ExceptionsFragmentAction() data class Change(val list: List<TrackingProtectionException>) : ExceptionsFragmentAction()
} }
/** /**
* The state for the Exceptions Screen * The state for the Exceptions Screen
* @property items List of exceptions to display * @property items List of exceptions to display
*/ */
data class ExceptionsFragmentState(val items: List<ExceptionsItem>) : State data class ExceptionsFragmentState(val items: List<TrackingProtectionException>) : State
/** /**
* The ExceptionsState Reducer. * The ExceptionsState Reducer.

@ -4,13 +4,15 @@
package org.mozilla.fenix.exceptions package org.mozilla.fenix.exceptions
import mozilla.components.concept.engine.content.blocking.TrackingProtectionException
/** /**
* Interactor for the exceptions screen * Interactor for the exceptions screen
* Provides implementations for the ExceptionsViewInteractor * Provides implementations for the ExceptionsViewInteractor
*/ */
class ExceptionsInteractor( class ExceptionsInteractor(
private val learnMore: () -> Unit, private val learnMore: () -> Unit,
private val deleteOne: (ExceptionsItem) -> Unit, private val deleteOne: (TrackingProtectionException) -> Unit,
private val deleteAll: () -> Unit private val deleteAll: () -> Unit
) : ExceptionsViewInteractor { ) : ExceptionsViewInteractor {
override fun onLearnMore() { override fun onLearnMore() {
@ -21,7 +23,7 @@ class ExceptionsInteractor(
deleteAll.invoke() deleteAll.invoke()
} }
override fun onDeleteOne(item: ExceptionsItem) { override fun onDeleteOne(item: TrackingProtectionException) {
deleteOne.invoke(item) deleteOne.invoke(item)
} }
} }

@ -14,6 +14,7 @@ import androidx.core.view.isVisible
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import kotlinx.android.extensions.LayoutContainer import kotlinx.android.extensions.LayoutContainer
import kotlinx.android.synthetic.main.component_exceptions.view.* import kotlinx.android.synthetic.main.component_exceptions.view.*
import mozilla.components.concept.engine.content.blocking.TrackingProtectionException
import org.mozilla.fenix.R import org.mozilla.fenix.R
/** /**
@ -34,7 +35,7 @@ interface ExceptionsViewInteractor {
/** /**
* Called whenever one exception item is deleted * Called whenever one exception item is deleted
*/ */
fun onDeleteOne(item: ExceptionsItem) fun onDeleteOne(item: TrackingProtectionException)
} }
/** /**

@ -7,9 +7,9 @@ package org.mozilla.fenix.exceptions.viewholders
import android.view.View import android.view.View
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import kotlinx.android.synthetic.main.exception_item.view.* import kotlinx.android.synthetic.main.exception_item.view.*
import mozilla.components.concept.engine.content.blocking.TrackingProtectionException
import org.mozilla.fenix.R import org.mozilla.fenix.R
import org.mozilla.fenix.exceptions.ExceptionsInteractor import org.mozilla.fenix.exceptions.ExceptionsInteractor
import org.mozilla.fenix.exceptions.ExceptionsItem
import org.mozilla.fenix.ext.components import org.mozilla.fenix.ext.components
import org.mozilla.fenix.ext.loadIntoView import org.mozilla.fenix.ext.loadIntoView
@ -25,7 +25,7 @@ class ExceptionsListItemViewHolder(
private val url = view.domainView private val url = view.domainView
private val deleteButton = view.delete_exception private val deleteButton = view.delete_exception
private var item: ExceptionsItem? = null private var item: TrackingProtectionException? = null
init { init {
deleteButton.setOnClickListener { deleteButton.setOnClickListener {
@ -35,7 +35,7 @@ class ExceptionsListItemViewHolder(
} }
} }
fun bind(item: ExceptionsItem) { fun bind(item: TrackingProtectionException) {
this.item = item this.item = item
url.text = item.url url.text = item.url
updateFavIcon(item.url) updateFavIcon(item.url)

@ -14,7 +14,7 @@ class ExceptionsFragmentStoreTest {
fun onChange() = runBlocking { fun onChange() = runBlocking {
val initialState = emptyDefaultState() val initialState = emptyDefaultState()
val store = ExceptionsFragmentStore(initialState) val store = ExceptionsFragmentStore(initialState)
val newExceptionsItem = ExceptionsItem("URL") val newExceptionsItem = ExceptionItem("URL")
store.dispatch(ExceptionsFragmentAction.Change(listOf(newExceptionsItem))).join() store.dispatch(ExceptionsFragmentAction.Change(listOf(newExceptionsItem))).join()
assertNotSame(initialState, store.state) assertNotSame(initialState, store.state)

@ -5,6 +5,7 @@
package org.mozilla.fenix.exceptions package org.mozilla.fenix.exceptions
import io.mockk.mockk import io.mockk.mockk
import mozilla.components.concept.engine.content.blocking.TrackingProtectionException
import org.junit.Assert.assertEquals import org.junit.Assert.assertEquals
import org.junit.Test import org.junit.Test
@ -36,8 +37,8 @@ class ExceptionsInteractorTest {
@Test @Test
fun onDeleteOne() { fun onDeleteOne() {
var exceptionsItemReceived: ExceptionsItem? = null var exceptionsItemReceived: TrackingProtectionException? = null
val exceptionsItem = ExceptionsItem("url") val exceptionsItem = ExceptionItem("url")
val interactor = ExceptionsInteractor( val interactor = ExceptionsInteractor(
mockk(), mockk(),
{ exceptionsItemReceived = exceptionsItem }, { exceptionsItemReceived = exceptionsItem },

Loading…
Cancel
Save