2019-05-07 22:28:38 +02:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
2019-07-12 20:38:15 +02:00
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2019-05-07 22:28:38 +02:00
|
|
|
|
2020-07-02 04:37:03 +02:00
|
|
|
package org.mozilla.fenix.trackingprotectionexceptions
|
2019-05-07 22:28:38 +02:00
|
|
|
|
2019-07-19 00:15:24 +02:00
|
|
|
import android.text.method.LinkMovementMethod
|
2019-05-07 22:28:38 +02:00
|
|
|
import android.view.LayoutInflater
|
|
|
|
import android.view.ViewGroup
|
2019-07-19 00:15:24 +02:00
|
|
|
import android.widget.FrameLayout
|
2019-11-22 16:38:13 +01:00
|
|
|
import androidx.core.view.isVisible
|
2019-05-07 22:28:38 +02:00
|
|
|
import androidx.recyclerview.widget.LinearLayoutManager
|
2019-07-19 01:07:48 +02:00
|
|
|
import kotlinx.android.extensions.LayoutContainer
|
2020-07-08 21:07:59 +02:00
|
|
|
import kotlinx.android.synthetic.main.component_exceptions.*
|
2020-01-22 04:07:50 +01:00
|
|
|
import mozilla.components.concept.engine.content.blocking.TrackingProtectionException
|
2019-05-07 22:28:38 +02:00
|
|
|
import org.mozilla.fenix.R
|
2020-07-16 07:38:46 +02:00
|
|
|
import org.mozilla.fenix.ext.addUnderline
|
2019-05-07 22:28:38 +02:00
|
|
|
|
2019-07-19 01:07:48 +02:00
|
|
|
/**
|
|
|
|
* Interface for the ExceptionsViewInteractor. This interface is implemented by objects that want
|
|
|
|
* to respond to user interaction on the ExceptionsView
|
|
|
|
*/
|
|
|
|
interface ExceptionsViewInteractor {
|
|
|
|
/**
|
|
|
|
* Called whenever learn more about tracking protection is tapped
|
|
|
|
*/
|
|
|
|
fun onLearnMore()
|
2019-05-07 22:28:38 +02:00
|
|
|
|
2019-07-19 01:07:48 +02:00
|
|
|
/**
|
|
|
|
* Called whenever all exception items are deleted
|
|
|
|
*/
|
|
|
|
fun onDeleteAll()
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called whenever one exception item is deleted
|
|
|
|
*/
|
2020-01-22 04:07:50 +01:00
|
|
|
fun onDeleteOne(item: TrackingProtectionException)
|
2019-07-19 01:07:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* View that contains and configures the Exceptions List
|
|
|
|
*/
|
|
|
|
class ExceptionsView(
|
2020-07-08 21:07:59 +02:00
|
|
|
container: ViewGroup,
|
|
|
|
interactor: ExceptionsInteractor
|
2019-07-19 01:07:48 +02:00
|
|
|
) : LayoutContainer {
|
|
|
|
|
2020-07-08 21:07:59 +02:00
|
|
|
override val containerView: FrameLayout = LayoutInflater.from(container.context)
|
|
|
|
.inflate(R.layout.component_exceptions, container, true)
|
2019-07-19 00:15:24 +02:00
|
|
|
.findViewById(R.id.exceptions_wrapper)
|
2019-05-07 22:28:38 +02:00
|
|
|
|
2020-07-02 04:37:03 +02:00
|
|
|
private val exceptionsAdapter =
|
|
|
|
ExceptionsAdapter(
|
|
|
|
interactor
|
|
|
|
)
|
2019-07-19 01:07:48 +02:00
|
|
|
|
2019-05-07 22:28:38 +02:00
|
|
|
init {
|
2020-07-08 21:07:59 +02:00
|
|
|
exceptions_list.apply {
|
2019-11-22 16:38:13 +01:00
|
|
|
adapter = exceptionsAdapter
|
2020-07-08 21:07:59 +02:00
|
|
|
layoutManager = LinearLayoutManager(container.context)
|
2019-05-07 22:28:38 +02:00
|
|
|
}
|
2020-07-08 21:07:59 +02:00
|
|
|
|
|
|
|
with(exceptions_learn_more) {
|
2020-07-16 07:38:46 +02:00
|
|
|
addUnderline()
|
2020-07-08 21:07:59 +02:00
|
|
|
|
2019-09-16 14:48:42 +02:00
|
|
|
movementMethod = LinkMovementMethod.getInstance()
|
|
|
|
setOnClickListener { interactor.onLearnMore() }
|
2019-07-19 00:15:24 +02:00
|
|
|
}
|
2019-05-07 22:28:38 +02:00
|
|
|
}
|
|
|
|
|
2019-08-30 15:14:00 +02:00
|
|
|
fun update(state: ExceptionsFragmentState) {
|
2020-07-08 21:07:59 +02:00
|
|
|
exceptions_empty_view.isVisible = state.items.isEmpty()
|
|
|
|
exceptions_list.isVisible = state.items.isNotEmpty()
|
2019-11-22 16:38:13 +01:00
|
|
|
exceptionsAdapter.updateData(state.items)
|
2019-05-07 22:28:38 +02:00
|
|
|
}
|
|
|
|
}
|