Skip to content

Commit

Permalink
Issue mozilla-mobile#7313: Update sample browser to use thumbnail loader
Browse files Browse the repository at this point in the history
  • Loading branch information
jonalmeida committed Jun 12, 2020
1 parent 68d5518 commit d5d8745
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
1 change: 1 addition & 0 deletions samples/browser/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ dependencies {

implementation project(':support-utils')
implementation project(':feature-downloads')
implementation project(':support-images')
implementation project(':support-ktx')
implementation project(':support-webextensions')
implementation project(':support-rustlog')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,16 @@ import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.util.AttributeSet
import android.view.LayoutInflater
import android.view.View
import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.Fragment
import mozilla.components.browser.state.state.WebExtensionState
import mozilla.components.browser.tabstray.BrowserTabsTray
import mozilla.components.browser.tabstray.DefaultTabViewHolder
import mozilla.components.browser.tabstray.TabsAdapter
import mozilla.components.browser.tabstray.ViewHolderProvider
import mozilla.components.browser.thumbnails.loader.ThumbnailLoader
import mozilla.components.concept.engine.EngineView
import mozilla.components.concept.tabstray.TabsTray
import mozilla.components.feature.intent.ext.getSessionId
Expand Down Expand Up @@ -81,7 +86,7 @@ open class BrowserActivity : AppCompatActivity(), ComponentCallbacks2 {
share(it)
}
}.asView()
TabsTray::class.java.name -> BrowserTabsTray(context, attrs)
TabsTray::class.java.name -> createTabsTray(context, attrs)
else -> super.onCreateView(parent, name, context, attrs)
}

Expand All @@ -92,4 +97,23 @@ open class BrowserActivity : AppCompatActivity(), ComponentCallbacks2 {
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
startActivity(intent)
}

private fun createTabsTray(context: Context, attrs: AttributeSet): BrowserTabsTray {
val thumbnailLoader = ThumbnailLoader(components.thumbnailStorage)
val viewHolderProvider: ViewHolderProvider = { viewGroup, tabsTray ->
DefaultTabViewHolder(
LayoutInflater.from(viewGroup.context).inflate(
R.layout.mozac_browser_tabstray_item,
viewGroup,
false
),
tabsTray,
thumbnailLoader
)
}

val adapter = TabsAdapter(thumbnailLoader, viewHolderProvider)

return BrowserTabsTray(context, attrs, 0, adapter)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ open class DefaultComponents(private val applicationContext: Context) {

private val sessionStorage by lazy { SessionStorage(applicationContext, engine) }

private val thumbnailStorage by lazy { ThumbnailStorage(applicationContext) }
val thumbnailStorage by lazy { ThumbnailStorage(applicationContext) }

val store by lazy {
BrowserStore(middleware = listOf(
Expand Down

0 comments on commit d5d8745

Please sign in to comment.