Skip to content

Commit

Permalink
For mozilla-mobile#6313 - Set session ClearColor through Engine Defau…
Browse files Browse the repository at this point in the history
…ltSettings
  • Loading branch information
ekager committed Oct 22, 2020
1 parent c40b937 commit 10fe1c5
Show file tree
Hide file tree
Showing 10 changed files with 13 additions and 79 deletions.
5 changes: 0 additions & 5 deletions app/src/main/java/org/mozilla/fenix/FeatureFlags.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,6 @@ object FeatureFlags {
*/
val showGridViewInTabsSettings = Config.channel.isNightlyOrDebug

/**
* Enables wait til first contentful paint
*/
val waitUntilPaintToDraw = Config.channel.isNightlyOrDebug

/**
* Enables downloads with external download managers.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,9 +247,7 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, Session
fragment = WeakReference(this),
engineView = WeakReference(engineView),
swipeRefresh = WeakReference(swipeRefresh),
viewLifecycleScope = WeakReference(viewLifecycleOwner.lifecycleScope),
settings = context.components.settings,
firstContentfulHappened = ::didFirstContentfulHappen
viewLifecycleScope = WeakReference(viewLifecycleOwner.lifecycleScope)
).apply {
beginAnimateInIfNecessary()
}
Expand Down Expand Up @@ -659,28 +657,6 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, Session
.collect { tab -> pipModeChanged(tab) }
}

if (context.settings().waitToShowPageUntilFirstPaint) {
store.flowScoped(viewLifecycleOwner) { flow ->
flow.mapNotNull { state ->
state.findTabOrCustomTabOrSelectedTab(
customTabSessionId
)
}
.ifChanged { it.content.firstContentfulPaint }
.collect {
val showEngineView =
it.content.firstContentfulPaint || it.content.progress == LOADING_PROGRESS_COMPLETE

if (showEngineView) {
engineView?.asView()?.isVisible = true
swipeRefresh?.alpha = 1f
} else {
engineView?.asView()?.isVisible = false
}
}
}
}

view.swipeRefresh.isEnabled =
FeatureFlags.pullToRefreshEnabled && context.settings().isPullToRefreshEnabledInBrowser
if (view.swipeRefresh.isEnabled) {
Expand Down Expand Up @@ -1153,15 +1129,6 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, Session
}
}

private fun didFirstContentfulHappen() =
if (components.settings.waitToShowPageUntilFirstPaint) {
val tab =
components.core.store.state.findTabOrCustomTabOrSelectedTab(customTabSessionId)
tab?.content?.firstContentfulPaint ?: false
} else {
true
}

/*
* Dereference these views when the fragment view is destroyed to prevent memory leaks
*/
Expand Down
18 changes: 3 additions & 15 deletions app/src/main/java/org/mozilla/fenix/browser/BrowserAnimator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import mozilla.components.concept.engine.EngineView
import org.mozilla.fenix.R
import org.mozilla.fenix.components.toolbar.ToolbarPosition
import org.mozilla.fenix.ext.settings
import org.mozilla.fenix.utils.Settings
import java.lang.ref.WeakReference

/**
Expand All @@ -29,9 +28,7 @@ class BrowserAnimator(
private val fragment: WeakReference<Fragment>,
private val engineView: WeakReference<EngineView>,
private val swipeRefresh: WeakReference<View>,
private val viewLifecycleScope: WeakReference<LifecycleCoroutineScope>,
private val settings: Settings,
private val firstContentfulHappened: () -> Boolean
private val viewLifecycleScope: WeakReference<LifecycleCoroutineScope>
) {

private val unwrappedEngineView: EngineView?
Expand All @@ -41,17 +38,8 @@ class BrowserAnimator(
get() = swipeRefresh.get()

fun beginAnimateInIfNecessary() {
if (settings.waitToShowPageUntilFirstPaint) {
if (firstContentfulHappened()) {
viewLifecycleScope.get()?.launch {
delay(ANIMATION_DELAY)
unwrappedEngineView?.asView()?.visibility = View.VISIBLE
unwrappedSwipeRefresh?.background = null
unwrappedSwipeRefresh?.alpha = 1f
}
}
} else {
unwrappedSwipeRefresh?.alpha = 1f
viewLifecycleScope.get()?.launch {
delay(ANIMATION_DELAY)
unwrappedEngineView?.asView()?.visibility = View.VISIBLE
unwrappedSwipeRefresh?.background = null
}
Expand Down
12 changes: 9 additions & 3 deletions app/src/main/java/org/mozilla/fenix/components/Core.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import GeckoProvider
import android.content.Context
import android.content.res.Configuration
import android.os.StrictMode
import androidx.core.content.ContextCompat
import io.sentry.Sentry
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
Expand All @@ -21,8 +22,8 @@ import mozilla.components.browser.session.SessionManager
import mozilla.components.browser.session.engine.EngineMiddleware
import mozilla.components.browser.session.storage.SessionStorage
import mozilla.components.browser.session.undo.UndoMiddleware
import mozilla.components.browser.state.action.RestoreCompleteAction
import mozilla.components.browser.state.action.RecentlyClosedAction
import mozilla.components.browser.state.action.RestoreCompleteAction
import mozilla.components.browser.state.state.BrowserState
import mozilla.components.browser.state.store.BrowserStore
import mozilla.components.browser.storage.sync.PlacesBookmarksStorage
Expand Down Expand Up @@ -101,7 +102,11 @@ class Core(
fontInflationEnabled = context.settings().shouldUseAutoSize,
suspendMediaWhenInactive = false,
forceUserScalableContent = context.settings().forceEnableZoom,
loginAutofillEnabled = context.settings().shouldAutofillLogins
loginAutofillEnabled = context.settings().shouldAutofillLogins,
clearColor = ContextCompat.getColor(
context,
R.color.foundation_normal_theme
)
)

GeckoEngine(
Expand Down Expand Up @@ -230,7 +235,8 @@ class Core(
// Now that we have restored our previous state (if there's one) let's remove timed out tabs
if (!context.settings().manuallyCloseTabs) {
store.state.tabs.filter {
(System.currentTimeMillis() - it.lastAccess) > context.settings().getTabTimeout()
(System.currentTimeMillis() - it.lastAccess) > context.settings()
.getTabTimeout()
}.forEach {
val session = sessionManager.findSessionById(it.id)
if (session != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,6 @@ class SecretSettingsFragment : PreferenceFragmentCompat() {
onPreferenceChangeListener = SharedPreferenceUpdater()
}

requirePreference<SwitchPreference>(R.string.pref_key_wait_first_paint).apply {
isVisible = FeatureFlags.waitUntilPaintToDraw
isChecked = context.settings().waitToShowPageUntilFirstPaint
onPreferenceChangeListener = SharedPreferenceUpdater()
}

requirePreference<SwitchPreference>(R.string.pref_key_synced_tabs_tabs_tray).apply {
isVisible = FeatureFlags.syncedTabsInTabsTray
isChecked = context.settings().syncedTabsInTabsTray
Expand Down
6 changes: 0 additions & 6 deletions app/src/main/java/org/mozilla/fenix/utils/Settings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,6 @@ class Settings(private val appContext: Context) : PreferencesHolder {
featureFlag = FeatureFlags.showGridViewInTabsSettings
)

var waitToShowPageUntilFirstPaint by featureFlagPreference(
appContext.getPreferenceKey(R.string.pref_key_wait_first_paint),
default = false,
featureFlag = FeatureFlags.waitUntilPaintToDraw
)

var syncedTabsInTabsTray by featureFlagPreference(
appContext.getPreferenceKey(R.string.pref_key_synced_tabs_tabs_tray),
default = false,
Expand Down
1 change: 0 additions & 1 deletion app/src/main/res/layout/fragment_browser.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
android:id="@+id/swipeRefresh"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:alpha="0"
app:layout_behavior="@string/appbar_scrolling_view_behavior">

<mozilla.components.concept.engine.EngineView
Expand Down
2 changes: 0 additions & 2 deletions app/src/main/res/values/preference_keys.xml
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,6 @@
<string name="pref_key_migrating_from_fenix_tip" translatable="false">pref_key_migrating_from_fenix_tip</string>
<string name="pref_key_master_password_tip" translatable="false">pref_key_master_password_tip</string>

<string name="pref_key_wait_first_paint" translatable="false">pref_key_wait_first_paint</string>

<string name="pref_key_synced_tabs_tabs_tray" translatable="false">pref_key_synced_tabs_tabs_tray</string>

<string name="pref_key_debug_settings" translatable="false">pref_key_debug_settings</string>
Expand Down
2 changes: 0 additions & 2 deletions app/src/main/res/values/static_strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@
<string name="preferences_debug_settings">Secret Settings</string>
<!-- Label for the show grid view in tabs setting preference -->
<string name="preferences_debug_settings_show_grid_view_tabs_settings">Show Grid View in Tabs Settings</string>
<!-- Label for the wait until first paint preference -->
<string name="preferences_debug_settings_wait_first_paint">Wait Until First Paint To Show Page Content</string>
<!-- Label for showing Synced Tabs in the tabs tray -->
<string name="preferences_debug_synced_tabs_tabs_tray">Show Synced Tabs in the tabs tray</string>

Expand Down
5 changes: 0 additions & 5 deletions app/src/main/res/xml/secret_settings_preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@
android:key="@string/pref_key_show_grid_view_tabs_settings"
android:title="@string/preferences_debug_settings_show_grid_view_tabs_settings"
app:iconSpaceReserved="false" />
<SwitchPreference
android:defaultValue="false"
android:key="@string/pref_key_wait_first_paint"
android:title="@string/preferences_debug_settings_wait_first_paint"
app:iconSpaceReserved="false" />
<SwitchPreference
android:defaultValue="false"
android:key="@string/pref_key_synced_tabs_tabs_tray"
Expand Down

0 comments on commit 10fe1c5

Please sign in to comment.