Skip to content
This repository has been archived by the owner on Feb 20, 2023. It is now read-only.

Update Android Components version #21109

Merged
merged 3 commits into from
Sep 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 0 additions & 20 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -367,26 +367,6 @@ android.applicationVariants.all { variant ->
println("--")
}

// -------------------------------------------------------------------------------------------------
// Pocket recommendations: Read token from local file if it exists (Only debug builds)
// -------------------------------------------------------------------------------------------------

print("Pocket recommendations token: ")

if (isDebug) {
if (gradle.hasProperty("localProperties.pocketConsumerKey")) {
def token = gradle.getProperty("localProperties.pocketConsumerKey")
buildConfigField 'String', 'POCKET_TOKEN', '"' + token + '"'
println "Added from local.properties file"
} else {
buildConfigField 'String', 'POCKET_TOKEN', '""'
println "Not found in local.properties file"
}
} else {
buildConfigField 'String', 'POCKET_TOKEN', '""'
println "Is to be only used in debug"
}

// -------------------------------------------------------------------------------------------------
// BuildConfig: Set flag for official builds; similar to MOZILLA_OFFICIAL in mozilla-central.
// -------------------------------------------------------------------------------------------------
Expand Down
4 changes: 1 addition & 3 deletions app/src/main/java/org/mozilla/fenix/components/Core.kt
Original file line number Diff line number Diff line change
Expand Up @@ -324,9 +324,7 @@ class Core(

@Suppress("MagicNumber")
val pocketStoriesConfig by lazyMonitored {
PocketStoriesConfig(
BuildConfig.POCKET_TOKEN, client, Frequency(4, TimeUnit.HOURS), 7
)
PocketStoriesConfig(client, Frequency(4, TimeUnit.HOURS))
}
val pocketStoriesService by lazyMonitored { PocketStoriesService(context, pocketStoriesConfig) }

Expand Down
3 changes: 1 addition & 2 deletions app/src/main/java/org/mozilla/fenix/home/HomeFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ import mozilla.components.feature.top.sites.TopSitesConfig
import mozilla.components.feature.top.sites.TopSitesFeature
import mozilla.components.lib.state.ext.consumeFlow
import mozilla.components.lib.state.ext.consumeFrom
import mozilla.components.service.pocket.stories.PocketStoriesUseCases
import mozilla.components.support.base.feature.ViewBoundFeatureWrapper
import mozilla.components.support.ktx.android.content.res.resolveAttribute
import mozilla.components.support.ktx.kotlinx.coroutines.flow.ifChanged
Expand Down Expand Up @@ -243,7 +242,7 @@ class HomeFragment : Fragment() {

if (requireContext().settings().pocketRecommendations) {
lifecycleScope.async(IO) {
val stories = PocketStoriesUseCases().GetPocketStories(requireContext()).invoke()
val stories = components.core.pocketStoriesService.getStories()
homeFragmentStore.dispatch(HomeFragmentAction.PocketArticlesChange(stories))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ fun PocketStory(
CompositionLocalProvider(LocalContentAlpha provides ContentAlpha.medium) {
Text(
modifier = Modifier.padding(bottom = 2.dp),
text = story.domain,
text = story.publisher,
style = MaterialTheme.typography.caption,
maxLines = 1,
overflow = TextOverflow.Ellipsis
Expand Down Expand Up @@ -170,13 +170,6 @@ fun PocketRecommendations(
) {
content()

// Don't yet have the bottom image from designs as a proper Android SVG.
Box(
Modifier
.background(Color.Red)
.size(64.dp, 27.dp)
.padding(top = 16.dp)
)
// Image(
// painterResource(R.drawable.ic_firefox_pocket),
// "Firefox and Pocket logos",
Expand Down Expand Up @@ -269,15 +262,12 @@ private fun getFakePocketStories(limit: Int = 1): List<PocketRecommendedStory> {

add(
PocketRecommendedStory(
id = randomNumber.toLong(),
url = "https://story$randomNumber.com",
title = "This is a ${"very ".repeat(randomNumber)} long title",
domain = "Website no #$randomNumber",
excerpt = "FOO",
dedupeUrl = "BAR",
imageSrc = "",
sortId = randomNumber,
publishedTimestamp = randomNumber.toString()
publisher = "Publisher",
url = "https://story$randomNumber.com",
imageUrl = "",
timeToRead = randomNumber,
category = "Category #$randomNumber"
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import mozilla.components.lib.state.ext.observeAsComposableState
import mozilla.components.service.pocket.PocketRecommendedStory
import org.mozilla.fenix.home.HomeFragmentStore

private const val STORIES_TO_SHOW_COUNT = 7

/**
* [RecyclerView.ViewHolder] that will display a list of [PocketRecommendedStory]es
* which is to be provided in the [bind] method.
Expand Down Expand Up @@ -41,11 +43,13 @@ class PocketStoriesViewHolder(

@Composable
fun PocketStories(store: HomeFragmentStore) {
val stories = store.observeAsComposableState { state -> state.pocketArticles }
val stories = store
.observeAsComposableState { state -> state.pocketArticles }.value
?.take(STORIES_TO_SHOW_COUNT)

ExpandableCard {
PocketRecommendations {
PocketStories(stories.value ?: emptyList())
PocketStories(stories ?: emptyList())
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import mozilla.components.browser.state.action.EngineAction
import mozilla.components.browser.state.action.TabListAction
import mozilla.components.browser.state.state.BrowserState
import mozilla.components.browser.state.state.createTab
import mozilla.components.browser.state.state.recover.RecoverableTab
import mozilla.components.browser.state.store.BrowserStore
import mozilla.components.service.glean.testing.GleanTestRule
import mozilla.components.support.base.android.Clock
Expand Down Expand Up @@ -168,11 +169,16 @@ class TelemetryMiddlewareTest {
fun `WHEN tabs are restored THEN the open tab count is updated`() {
assertEquals(0, settings.openTabsCount)
val tabsToRestore = listOf(
createTab("https://mozilla.org"),
createTab("https://firefox.com")
RecoverableTab(url = "https://mozilla.org", id = "1"),
RecoverableTab(url = "https://firefox.com", id = "2")
)

store.dispatch(TabListAction.RestoreAction(tabsToRestore)).joinBlocking()
store.dispatch(
TabListAction.RestoreAction(
tabs = tabsToRestore,
restoreLocation = TabListAction.RestoreAction.RestoreLocation.BEGINNING
)
).joinBlocking()
assertEquals(2, settings.openTabsCount)
verify(exactly = 1) { metrics.track(Event.HaveOpenTabs) }
}
Expand Down Expand Up @@ -204,11 +210,12 @@ class TelemetryMiddlewareTest {
store.dispatch(
TabListAction.RestoreAction(
listOf(
createTab("https://www.mozilla.org", id = "foreground"),
createTab("https://getpocket.com", id = "background_pocket"),
createTab("https://theverge.com", id = "background_verge")
RecoverableTab(url = "https://www.mozilla.org", id = "foreground"),
RecoverableTab(url = "https://getpocket.com", id = "background_pocket"),
RecoverableTab(url = "https://theverge.com", id = "background_verge")
),
selectedTabId = "foreground"
selectedTabId = "foreground",
restoreLocation = TabListAction.RestoreAction.RestoreLocation.BEGINNING
)
).joinBlocking()

Expand All @@ -227,11 +234,12 @@ class TelemetryMiddlewareTest {
store.dispatch(
TabListAction.RestoreAction(
listOf(
createTab("https://www.mozilla.org", id = "foreground"),
createTab("https://getpocket.com", id = "background_pocket"),
createTab("https://theverge.com", id = "background_verge")
RecoverableTab(url = "https://www.mozilla.org", id = "foreground"),
RecoverableTab(url = "https://getpocket.com", id = "background_pocket"),
RecoverableTab(url = "https://theverge.com", id = "background_verge")
),
selectedTabId = "foreground"
selectedTabId = "foreground",
restoreLocation = TabListAction.RestoreAction.RestoreLocation.BEGINNING
)
).joinBlocking()

Expand Down Expand Up @@ -260,11 +268,12 @@ class TelemetryMiddlewareTest {
store.dispatch(
TabListAction.RestoreAction(
listOf(
createTab("https://www.mozilla.org", id = "foreground"),
createTab("https://getpocket.com", id = "background_pocket"),
createTab("https://theverge.com", id = "background_verge")
RecoverableTab(url = "https://www.mozilla.org", id = "foreground"),
RecoverableTab(url = "https://getpocket.com", id = "background_pocket"),
RecoverableTab(url = "https://theverge.com", id = "background_verge")
),
selectedTabId = "foreground"
selectedTabId = "foreground",
restoreLocation = TabListAction.RestoreAction.RestoreLocation.BEGINNING
)
).joinBlocking()

Expand Down Expand Up @@ -296,11 +305,12 @@ class TelemetryMiddlewareTest {
store.dispatch(
TabListAction.RestoreAction(
listOf(
createTab("https://www.mozilla.org", id = "foreground"),
createTab("https://getpocket.com", id = "background_pocket"),
createTab("https://theverge.com", id = "background_verge")
RecoverableTab(url = "https://www.mozilla.org", id = "foreground"),
RecoverableTab(url = "https://getpocket.com", id = "background_pocket"),
RecoverableTab(url = "https://theverge.com", id = "background_verge")
),
selectedTabId = "foreground"
selectedTabId = "foreground",
restoreLocation = TabListAction.RestoreAction.RestoreLocation.BEGINNING
)
).joinBlocking()

Expand Down
2 changes: 1 addition & 1 deletion buildSrc/src/main/java/AndroidComponents.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

object AndroidComponents {
const val VERSION = "93.0.20210830220733"
const val VERSION = "93.0.20210901143120"
}