diff --git a/app/src/main/java/org/mozilla/fenix/exceptions/ExceptionsAdapter.kt b/app/src/main/java/org/mozilla/fenix/exceptions/ExceptionsAdapter.kt index 59e827a470..92053ba9e3 100644 --- a/app/src/main/java/org/mozilla/fenix/exceptions/ExceptionsAdapter.kt +++ b/app/src/main/java/org/mozilla/fenix/exceptions/ExceptionsAdapter.kt @@ -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) { + fun updateData(exceptions: List) { val adapterItems = mutableListOf() adapterItems.add(AdapterItem.Header) exceptions.mapTo(adapterItems) { AdapterItem.Item(it) } diff --git a/app/src/main/java/org/mozilla/fenix/exceptions/ExceptionsFragment.kt b/app/src/main/java/org/mozilla/fenix/exceptions/ExceptionsFragment.kt index 1ad3e0840b..3ee12b5c90 100644 --- a/app/src/main/java/org/mozilla/fenix/exceptions/ExceptionsFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/exceptions/ExceptionsFragment.kt @@ -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)) } } } diff --git a/app/src/main/java/org/mozilla/fenix/exceptions/ExceptionsFragmentStore.kt b/app/src/main/java/org/mozilla/fenix/exceptions/ExceptionsFragmentStore.kt index c61c308715..1ba13b0dd8 100644 --- a/app/src/main/java/org/mozilla/fenix/exceptions/ExceptionsFragmentStore.kt +++ b/app/src/main/java/org/mozilla/fenix/exceptions/ExceptionsFragmentStore.kt @@ -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) : ExceptionsFragmentAction() + data class Change(val list: List) : ExceptionsFragmentAction() } /** * The state for the Exceptions Screen * @property items List of exceptions to display */ -data class ExceptionsFragmentState(val items: List) : State +data class ExceptionsFragmentState(val items: List) : State /** * The ExceptionsState Reducer. diff --git a/app/src/main/java/org/mozilla/fenix/exceptions/ExceptionsInteractor.kt b/app/src/main/java/org/mozilla/fenix/exceptions/ExceptionsInteractor.kt index 1f02c3c5b6..9ec50c71f4 100644 --- a/app/src/main/java/org/mozilla/fenix/exceptions/ExceptionsInteractor.kt +++ b/app/src/main/java/org/mozilla/fenix/exceptions/ExceptionsInteractor.kt @@ -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) } } diff --git a/app/src/main/java/org/mozilla/fenix/exceptions/ExceptionsView.kt b/app/src/main/java/org/mozilla/fenix/exceptions/ExceptionsView.kt index e6c815ee31..c9cbe39c22 100644 --- a/app/src/main/java/org/mozilla/fenix/exceptions/ExceptionsView.kt +++ b/app/src/main/java/org/mozilla/fenix/exceptions/ExceptionsView.kt @@ -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) } /** diff --git a/app/src/main/java/org/mozilla/fenix/exceptions/viewholders/ExceptionsListItemViewHolder.kt b/app/src/main/java/org/mozilla/fenix/exceptions/viewholders/ExceptionsListItemViewHolder.kt index 03de65b7ea..f4f241a8cc 100644 --- a/app/src/main/java/org/mozilla/fenix/exceptions/viewholders/ExceptionsListItemViewHolder.kt +++ b/app/src/main/java/org/mozilla/fenix/exceptions/viewholders/ExceptionsListItemViewHolder.kt @@ -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) diff --git a/app/src/test/java/org/mozilla/fenix/exceptions/ExceptionsFragmentStoreTest.kt b/app/src/test/java/org/mozilla/fenix/exceptions/ExceptionsFragmentStoreTest.kt index 85e012b326..a6aec4f2f2 100644 --- a/app/src/test/java/org/mozilla/fenix/exceptions/ExceptionsFragmentStoreTest.kt +++ b/app/src/test/java/org/mozilla/fenix/exceptions/ExceptionsFragmentStoreTest.kt @@ -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) diff --git a/app/src/test/java/org/mozilla/fenix/exceptions/ExceptionsInteractorTest.kt b/app/src/test/java/org/mozilla/fenix/exceptions/ExceptionsInteractorTest.kt index b59bfcf6d1..3132101b26 100644 --- a/app/src/test/java/org/mozilla/fenix/exceptions/ExceptionsInteractorTest.kt +++ b/app/src/test/java/org/mozilla/fenix/exceptions/ExceptionsInteractorTest.kt @@ -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 },