Closes #1320: Customize site info panel dialog for custom tabs. (#2304)

nightly-build-test
Arturo Mejia 5 years ago committed by Colin Lee
parent c2704c3fec
commit 583b954c5a

@ -43,6 +43,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- #1955 - Added a confirmation dialog for QR code and barcode searches
- #1874 - Added a "Turn on Sync" fragment for Firefox Accounts login and sign up
- #2308 - Update the deprecated BitmapDrawable constructor
- #1874 - Added TOP info panel dialog for custom tabs.
### Changed
- #1429 - Updated site permissions ui for MVP

@ -247,10 +247,20 @@ class BrowserFragment : Fragment(), BackHandler, CoroutineScope,
view = view
)
val accentHighContrastColor = DefaultThemeManager.resolveAttribute(R.attr.accentHighContrast, requireContext())
sitePermissionsFeature.set(
feature = SitePermissionsFeature(
anchorView = view.findInPageView,
sessionManager = sessionManager
context = requireContext(),
sessionManager = sessionManager,
fragmentManager = requireFragmentManager(),
promptsStyling = SitePermissionsFeature.PromptsStyling(
gravity = getAppropriateLayoutGravity(),
shouldWidthMatchParent = true,
positiveButtonBackgroundColor = accentHighContrastColor,
positiveButtonTextColor = R.color.photonWhite
),
sessionId = customTabSessionId
) { permissions ->
requestPermissions(permissions, REQUEST_CODE_APP_PERMISSIONS)
},
@ -658,7 +668,8 @@ class BrowserFragment : Fragment(), BackHandler, CoroutineScope,
url = session.url,
isSecured = session.securityInfo.secure,
isTrackingProtectionOn = Settings.getInstance(context!!).shouldUseTrackingProtection,
sitePermissions = sitePermissions
sitePermissions = sitePermissions,
gravity = getAppropriateLayoutGravity()
)
quickSettingsSheet.sitePermissions = sitePermissions
quickSettingsSheet.show(

@ -4,15 +4,21 @@
package org.mozilla.fenix.settings.quicksettings
import android.app.Dialog
import android.content.Context
import android.content.pm.PackageManager.PERMISSION_GRANTED
import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.os.Bundle
import android.view.Gravity.BOTTOM
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.LinearLayout
import androidx.appcompat.app.AppCompatDialogFragment
import androidx.appcompat.view.ContextThemeWrapper
import androidx.constraintlayout.widget.ConstraintLayout
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
import androidx.core.widget.NestedScrollView
import com.google.android.material.bottomsheet.BottomSheetDialog
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
@ -34,14 +40,16 @@ private const val KEY_URL = "KEY_URL"
private const val KEY_IS_SECURED = "KEY_IS_SECURED"
private const val KEY_SITE_PERMISSIONS = "KEY_SITE_PERMISSIONS"
private const val KEY_IS_TP_ON = "KEY_IS_TP_ON"
private const val KEY_DIALOG_GRAVITY = "KEY_DIALOG_GRAVITY"
private const val REQUEST_CODE_QUICK_SETTINGS_PERMISSIONS = 4
@SuppressWarnings("TooManyFunctions")
class QuickSettingsSheetDialogFragment : BottomSheetDialogFragment(), CoroutineScope {
class QuickSettingsSheetDialogFragment : AppCompatDialogFragment(), CoroutineScope {
private val safeArguments get() = requireNotNull(arguments)
private val url: String by lazy { safeArguments.getString(KEY_URL) }
private val isSecured: Boolean by lazy { safeArguments.getBoolean(KEY_IS_SECURED) }
private val isTrackingProtectionOn: Boolean by lazy { safeArguments.getBoolean(KEY_IS_TP_ON) }
private val promptGravity: Int by lazy { safeArguments.getInt(KEY_DIALOG_GRAVITY) }
private lateinit var quickSettingsComponent: QuickSettingsComponent
private lateinit var job: Job
@ -62,23 +70,53 @@ class QuickSettingsSheetDialogFragment : BottomSheetDialogFragment(), CoroutineS
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
): View {
return inflateRootView(container)
}
private fun inflateRootView(container: ViewGroup? = null): View {
val contextThemeWrapper = ContextThemeWrapper(
activity,
(activity as HomeActivity).themeManager.currentThemeResource
)
val localInflater = inflater.cloneInContext(contextThemeWrapper)
return localInflater.inflate(
return LayoutInflater.from(contextThemeWrapper).inflate(
R.layout.fragment_quick_settings_dialog_sheet,
container,
false
)
}
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
val customDialog = if (promptGravity == BOTTOM) {
return BottomSheetDialog(requireContext(), this.theme)
} else {
Dialog(requireContext())
}
return customDialog.applyCustomizationsForTopDialog(inflateRootView())
}
private fun Dialog.applyCustomizationsForTopDialog(rootView: View): Dialog {
addContentView(
rootView,
LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.MATCH_PARENT
)
)
window?.apply {
setGravity(promptGravity)
setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
// This must be called after addContentView, or it won't fully fill to the edge.
setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)
}
return this
}
override fun onViewCreated(rootView: View, savedInstanceState: Bundle?) {
super.onViewCreated(rootView, savedInstanceState)
quickSettingsComponent = QuickSettingsComponent(
rootView as ConstraintLayout, ActionBusFactory.get(this),
rootView as NestedScrollView, ActionBusFactory.get(this),
QuickSettingsState(
QuickSettingsState.Mode.Normal(
url,
@ -97,7 +135,8 @@ class QuickSettingsSheetDialogFragment : BottomSheetDialogFragment(), CoroutineS
url: String,
isSecured: Boolean,
isTrackingProtectionOn: Boolean,
sitePermissions: SitePermissions?
sitePermissions: SitePermissions?,
gravity: Int = BOTTOM
): QuickSettingsSheetDialogFragment {
val fragment = QuickSettingsSheetDialogFragment()
@ -108,6 +147,7 @@ class QuickSettingsSheetDialogFragment : BottomSheetDialogFragment(), CoroutineS
putBoolean(KEY_IS_SECURED, isSecured)
putBoolean(KEY_IS_TP_ON, isTrackingProtectionOn)
putParcelable(KEY_SITE_PERMISSIONS, sitePermissions)
putInt(KEY_DIALOG_GRAVITY, gravity)
}
fragment.arguments = arguments
return fragment

@ -3,9 +3,15 @@
- 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/. -->
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.core.widget.NestedScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/quick_action_sheet"
android:layout_width="match_parent"
android:layout_height="wrap_content"
@ -154,3 +160,4 @@
tools:text="Blocked"/>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.core.widget.NestedScrollView>
Loading…
Cancel
Save