Skip to content

Commit

Permalink
For mozilla-mobile#21043 - Integrate AC changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Mugurell authored and csadilek committed Sep 1, 2021
1 parent eb17c5c commit 232aca4
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 43 deletions.
20 changes: 0 additions & 20 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -368,26 +368,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())
}
}
}

0 comments on commit 232aca4

Please sign in to comment.