Closes #1004: Integrating ThumbnailsFeature.
parent
9d18bbad12
commit
2fa25a86f0
|
@ -4,6 +4,7 @@
|
|||
|
||||
package org.mozilla.fenix.browser
|
||||
|
||||
import android.content.ComponentCallbacks2
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
|
@ -30,6 +31,7 @@ import mozilla.components.feature.prompts.PromptFeature
|
|||
import mozilla.components.feature.session.FullScreenFeature
|
||||
import mozilla.components.feature.session.SessionFeature
|
||||
import mozilla.components.feature.session.SessionUseCases
|
||||
import mozilla.components.feature.session.ThumbnailsFeature
|
||||
import mozilla.components.feature.sitepermissions.SitePermissionsFeature
|
||||
import mozilla.components.support.base.feature.BackHandler
|
||||
import mozilla.components.support.base.feature.ViewBoundFeatureWrapper
|
||||
|
@ -53,7 +55,7 @@ import org.mozilla.fenix.ext.share
|
|||
import org.mozilla.fenix.mvi.ActionBusFactory
|
||||
import org.mozilla.fenix.mvi.getAutoDisposeObservable
|
||||
|
||||
class BrowserFragment : Fragment(), BackHandler {
|
||||
class BrowserFragment : Fragment(), BackHandler, ComponentCallbacks2 {
|
||||
private lateinit var toolbarComponent: ToolbarComponent
|
||||
|
||||
private val sessionFeature = ViewBoundFeatureWrapper<SessionFeature>()
|
||||
|
@ -65,6 +67,7 @@ class BrowserFragment : Fragment(), BackHandler {
|
|||
private val toolbarIntegration = ViewBoundFeatureWrapper<ToolbarIntegration>()
|
||||
private val sitePermissionsFeature = ViewBoundFeatureWrapper<SitePermissionsFeature>()
|
||||
private val fullScreenFeature = ViewBoundFeatureWrapper<FullScreenFeature>()
|
||||
private val thumbnailsFeature = ViewBoundFeatureWrapper<ThumbnailsFeature>()
|
||||
var sessionId: String? = null
|
||||
|
||||
override fun onCreateView(
|
||||
|
@ -207,6 +210,12 @@ class BrowserFragment : Fragment(), BackHandler {
|
|||
owner = this,
|
||||
view = view
|
||||
)
|
||||
|
||||
thumbnailsFeature.set(
|
||||
feature = ThumbnailsFeature(requireContext(), view.engineView, requireComponents.core.sessionManager),
|
||||
owner = this,
|
||||
view = view
|
||||
)
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
|
@ -256,6 +265,10 @@ class BrowserFragment : Fragment(), BackHandler {
|
|||
promptsFeature.withFeature { it.onActivityResult(requestCode, resultCode, data) }
|
||||
}
|
||||
|
||||
override fun onTrimMemory(level: Int) {
|
||||
requireComponents.core.sessionManager.onLowMemory()
|
||||
}
|
||||
|
||||
// This method triggers the complexity warning. However it's actually not that hard to understand.
|
||||
@SuppressWarnings("ComplexMethod")
|
||||
private fun handleToolbarItemInteraction(action: SearchAction.ToolbarMenuItemTapped) {
|
||||
|
|
|
@ -124,8 +124,12 @@ class TabsAdapter(private val actionEmitter: Observer<TabsAction>) :
|
|||
}
|
||||
|
||||
fun updateTabBackground(id: Int) {
|
||||
val background = availableBackgrounds[id % availableBackgrounds.size]
|
||||
tab_background.image = ContextCompat.getDrawable(view.context, background)
|
||||
if (session?.thumbnail != null) {
|
||||
tab_background.setImageBitmap(session?.thumbnail)
|
||||
} else {
|
||||
val background = availableBackgrounds[id % availableBackgrounds.size]
|
||||
tab_background.image = ContextCompat.getDrawable(view.context, background)
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
package org.mozilla.fenix.home.tabs
|
||||
|
||||
import android.graphics.Bitmap
|
||||
import android.view.ViewGroup
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import kotlinx.android.synthetic.main.component_tabs.view.*
|
||||
|
@ -41,10 +42,10 @@ class TabsComponent(
|
|||
}
|
||||
|
||||
data class TabsState(val sessions: List<SessionViewState>) : ViewState
|
||||
data class SessionViewState(val id: String, val url: String, val selected: Boolean)
|
||||
data class SessionViewState(val id: String, val url: String, val selected: Boolean, val thumbnail: Bitmap? = null)
|
||||
|
||||
fun Session.toSessionViewState(selected: Boolean): SessionViewState {
|
||||
return SessionViewState(this.id, this.url, selected)
|
||||
return SessionViewState(this.id, this.url, selected, this.thumbnail)
|
||||
}
|
||||
|
||||
sealed class TabsAction : Action {
|
||||
|
|
Loading…
Reference in New Issue