[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.ListAdapter
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.ExceptionsHeaderViewHolder
import org.mozilla.fenix.exceptions.viewholders.ExceptionsListItemViewHolder
@ -16,7 +17,7 @@ import org.mozilla.fenix.exceptions.viewholders.ExceptionsListItemViewHolder
sealed class AdapterItem {
object DeleteButton : 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.
* 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>()
adapterItems.add(AdapterItem.Header)
exceptions.mapTo(adapterItems) { AdapterItem.Item(it) }

@ -12,6 +12,7 @@ import android.view.ViewGroup
import androidx.fragment.app.Fragment
import kotlinx.android.synthetic.main.fragment_exceptions.view.*
import kotlinx.coroutines.ExperimentalCoroutinesApi
import mozilla.components.concept.engine.content.blocking.TrackingProtectionException
import mozilla.components.feature.session.TrackingProtectionUseCases
import mozilla.components.lib.state.ext.consumeFrom
import org.mozilla.fenix.BrowserDirection
@ -74,7 +75,7 @@ class ExceptionsFragment : Fragment() {
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
// See https://github.com/mozilla-mobile/android-components/issues/4699
Log.e("Remove one exception", "$item")
@ -92,8 +93,7 @@ class ExceptionsFragment : Fragment() {
private fun reloadExceptions() {
trackingProtectionUseCases.fetchExceptions { resultList ->
val exceptionsList = resultList.map { ExceptionsItem(it) }
exceptionsStore.dispatch(ExceptionsFragmentAction.Change(exceptionsList))
exceptionsStore.dispatch(ExceptionsFragmentAction.Change(resultList))
}
}
}

@ -4,6 +4,7 @@
package org.mozilla.fenix.exceptions
import mozilla.components.concept.engine.content.blocking.TrackingProtectionException
import mozilla.components.lib.state.Action
import mozilla.components.lib.state.State
import mozilla.components.lib.state.Store
@ -12,7 +13,7 @@ import mozilla.components.lib.state.Store
* Class representing an exception item
* @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.
@ -24,14 +25,14 @@ class ExceptionsFragmentStore(initialState: ExceptionsFragmentState) :
* Actions to dispatch through the `ExceptionsStore` to modify `ExceptionsState` through the reducer.
*/
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
* @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.

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

@ -14,6 +14,7 @@ import androidx.core.view.isVisible
import androidx.recyclerview.widget.LinearLayoutManager
import kotlinx.android.extensions.LayoutContainer
import kotlinx.android.synthetic.main.component_exceptions.view.*
import mozilla.components.concept.engine.content.blocking.TrackingProtectionException
import org.mozilla.fenix.R
/**
@ -34,7 +35,7 @@ interface ExceptionsViewInteractor {
/**
* 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 androidx.recyclerview.widget.RecyclerView
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.exceptions.ExceptionsInteractor
import org.mozilla.fenix.exceptions.ExceptionsItem
import org.mozilla.fenix.ext.components
import org.mozilla.fenix.ext.loadIntoView
@ -25,7 +25,7 @@ class ExceptionsListItemViewHolder(
private val url = view.domainView
private val deleteButton = view.delete_exception
private var item: ExceptionsItem? = null
private var item: TrackingProtectionException? = null
init {
deleteButton.setOnClickListener {
@ -35,7 +35,7 @@ class ExceptionsListItemViewHolder(
}
}
fun bind(item: ExceptionsItem) {
fun bind(item: TrackingProtectionException) {
this.item = item
url.text = item.url
updateFavIcon(item.url)

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

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

Loading…
Cancel
Save