mirror of
https://github.com/fork-maintainers/iceraven-browser
synced 2024-11-03 23:15:31 +00:00
For #2302 - Listen to session to update QuickSettingsSheetDialogFragment
This commit is contained in:
parent
49ac62ab85
commit
e0e7ba5a43
@ -659,15 +659,17 @@ class BrowserFragment : Fragment(), BackHandler, CoroutineScope,
|
||||
|
||||
private fun showQuickSettingsDialog() {
|
||||
val session = requireNotNull(getSessionById())
|
||||
val host = requireNotNull(session.url.toUri()?.host)
|
||||
|
||||
launch {
|
||||
val storage = requireContext().components.storage
|
||||
val sitePermissions: SitePermissions? = storage.findSitePermissionsBy(host)
|
||||
val host = session.url.toUri()?.host
|
||||
val sitePermissions: SitePermissions? = host?.let {
|
||||
val storage = requireContext().components.storage
|
||||
storage.findSitePermissionsBy(it)
|
||||
}
|
||||
|
||||
launch(Main) {
|
||||
view?.let {
|
||||
val directions = BrowserFragmentDirections.actionBrowserFragmentToQuickSettingsSheetDialogFragment(
|
||||
sessionId = session.id,
|
||||
url = session.url,
|
||||
isSecured = session.securityInfo.secure,
|
||||
isTrackingProtectionOn = session.trackerBlockingEnabled,
|
||||
|
@ -23,7 +23,9 @@ import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.launch
|
||||
import mozilla.components.browser.session.Session
|
||||
import mozilla.components.feature.sitepermissions.SitePermissions
|
||||
import mozilla.components.support.ktx.kotlin.toUri
|
||||
import org.mozilla.fenix.HomeActivity
|
||||
import org.mozilla.fenix.R
|
||||
import org.mozilla.fenix.browser.BrowserFragment
|
||||
@ -43,6 +45,7 @@ private const val REQUEST_CODE_QUICK_SETTINGS_PERMISSIONS = 4
|
||||
@SuppressWarnings("TooManyFunctions")
|
||||
class QuickSettingsSheetDialogFragment : AppCompatDialogFragment(), CoroutineScope {
|
||||
private val safeArguments get() = requireNotNull(arguments)
|
||||
private val sessionId: String by lazy { QuickSettingsSheetDialogFragmentArgs.fromBundle(safeArguments).sessionId }
|
||||
private val url: String by lazy { QuickSettingsSheetDialogFragmentArgs.fromBundle(safeArguments).url }
|
||||
private val isSecured: Boolean by lazy { QuickSettingsSheetDialogFragmentArgs.fromBundle(safeArguments).isSecured }
|
||||
private val isTrackingProtectionOn: Boolean by lazy {
|
||||
@ -68,6 +71,7 @@ class QuickSettingsSheetDialogFragment : AppCompatDialogFragment(), CoroutineSco
|
||||
): View {
|
||||
sitePermissions = QuickSettingsSheetDialogFragmentArgs.fromBundle(safeArguments).sitePermissions
|
||||
val rootView = inflateRootView(container)
|
||||
requireComponents.core.sessionManager.findSessionById(sessionId)?.register(sessionObserver, view = rootView)
|
||||
quickSettingsComponent = QuickSettingsComponent(
|
||||
rootView as NestedScrollView, this, ActionBusFactory.get(this),
|
||||
QuickSettingsState(
|
||||
@ -218,4 +222,51 @@ class QuickSettingsSheetDialogFragment : AppCompatDialogFragment(), CoroutineSco
|
||||
.onNext(QuickSettingsChange.PromptRestarted(sitePermissions))
|
||||
}
|
||||
}
|
||||
|
||||
private val sessionObserver = object : Session.Observer {
|
||||
override fun onUrlChanged(session: Session, url: String) {
|
||||
super.onUrlChanged(session, url)
|
||||
launch {
|
||||
val host = session.url.toUri()?.host
|
||||
val sitePermissions: SitePermissions? = host?.let {
|
||||
val storage = requireContext().components.storage
|
||||
storage.findSitePermissionsBy(it)
|
||||
}
|
||||
launch(Dispatchers.Main) {
|
||||
getManagedEmitter<QuickSettingsChange>().onNext(
|
||||
QuickSettingsChange.Change(
|
||||
url,
|
||||
session.securityInfo.secure,
|
||||
session.trackerBlockingEnabled,
|
||||
sitePermissions
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onTrackerBlockingEnabledChanged(session: Session, blockingEnabled: Boolean) {
|
||||
super.onTrackerBlockingEnabledChanged(session, blockingEnabled)
|
||||
getManagedEmitter<QuickSettingsChange>().onNext(
|
||||
QuickSettingsChange.Change(
|
||||
session.url,
|
||||
session.securityInfo.secure,
|
||||
blockingEnabled,
|
||||
sitePermissions
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
override fun onSecurityChanged(session: Session, securityInfo: Session.SecurityInfo) {
|
||||
super.onSecurityChanged(session, securityInfo)
|
||||
getManagedEmitter<QuickSettingsChange>().onNext(
|
||||
QuickSettingsChange.Change(
|
||||
session.url,
|
||||
securityInfo.secure,
|
||||
session.trackerBlockingEnabled,
|
||||
sitePermissions
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -318,6 +318,9 @@
|
||||
android:id="@+id/quickSettingsSheetDialogFragment"
|
||||
android:name="org.mozilla.fenix.settings.quicksettings.QuickSettingsSheetDialogFragment"
|
||||
android:label="QuickSettingsSheetDialogFragment" >
|
||||
<argument
|
||||
android:name="sessionId"
|
||||
app:argType="string" />
|
||||
<argument
|
||||
android:name="url"
|
||||
app:argType="string" />
|
||||
|
Loading…
Reference in New Issue
Block a user