Skip to content

Commit

Permalink
Merge pull request #951 from Automattic/task/enable-ratings
Browse files Browse the repository at this point in the history
Enable the ratings feature
  • Loading branch information
ashiagr authored May 11, 2023
2 parents 40af8ca + b456557 commit f45f1ad
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 26 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
7.39
-----
* New Features:
* Added the ability to see ratings for podcasts
([#951](https://github.com/Automattic/pocket-casts-android/pull/951)).

7.38
-----
Expand Down
1 change: 0 additions & 1 deletion base.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ android {

// Feature Flags
buildConfigField "boolean", "END_OF_YEAR_ENABLED", "false"
buildConfigField "boolean", "SHOW_RATINGS", "false"
buildConfigField "boolean", "ADD_PATRON_ENABLED", "false"

testInstrumentationRunner project.testInstrumentationRunner
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.tooling.preview.PreviewParameter
import androidx.compose.ui.unit.dp
import au.com.shiftyjelly.pocketcasts.compose.AppThemeWithBackground
import au.com.shiftyjelly.pocketcasts.compose.components.TextP50
import au.com.shiftyjelly.pocketcasts.compose.components.TextP40
import au.com.shiftyjelly.pocketcasts.compose.preview.ThemePreviewParameterProvider
import au.com.shiftyjelly.pocketcasts.compose.theme
import au.com.shiftyjelly.pocketcasts.podcasts.viewmodel.PodcastRatingsViewModel
Expand Down Expand Up @@ -66,7 +66,12 @@ private fun Content(
stars = state.stars,
color = MaterialTheme.theme.colors.filter03
)
state.total?.let { TextP50(text = it.abbreviated) }
state.total?.let {
TextP40(
text = it.abbreviated,
modifier = Modifier.padding(start = 6.dp)
)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import au.com.shiftyjelly.pocketcasts.models.entity.Podcast
import au.com.shiftyjelly.pocketcasts.models.entity.PodcastEpisode
import au.com.shiftyjelly.pocketcasts.models.to.PodcastGrouping
import au.com.shiftyjelly.pocketcasts.models.type.EpisodesSortType
import au.com.shiftyjelly.pocketcasts.podcasts.BuildConfig
import au.com.shiftyjelly.pocketcasts.podcasts.R
import au.com.shiftyjelly.pocketcasts.podcasts.databinding.AdapterEpisodeBinding
import au.com.shiftyjelly.pocketcasts.podcasts.databinding.AdapterEpisodeHeaderBinding
Expand Down Expand Up @@ -276,10 +275,8 @@ class PodcastAdapter(
// expand the podcast description and details if the user hasn't subscribed
if (this.podcast.uuid != podcast.uuid) {
headerExpanded = !podcast.isSubscribed
if (BuildConfig.SHOW_RATINGS) {
ratingsViewModel.loadRatings(podcast.uuid)
ratingsViewModel.refreshPodcastRatings(podcast.uuid)
}
ratingsViewModel.loadRatings(podcast.uuid)
ratingsViewModel.refreshPodcastRatings(podcast.uuid)
onHeaderSummaryToggled(headerExpanded, false)
}
this.podcast = podcast
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import au.com.shiftyjelly.pocketcasts.analytics.AnalyticsEvent
import au.com.shiftyjelly.pocketcasts.analytics.AnalyticsTrackerWrapper
import au.com.shiftyjelly.pocketcasts.podcasts.BuildConfig
import au.com.shiftyjelly.pocketcasts.repositories.ratings.RatingsManager
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.CoroutineScope
Expand Down Expand Up @@ -34,24 +33,22 @@ class PodcastRatingsViewModel
val stateFlow: StateFlow<RatingState> = _stateFlow

fun loadRatings(podcastUuid: String) {
if (BuildConfig.SHOW_RATINGS) {
viewModelScope.launch {
try {
ratingsManager.podcastRatings(podcastUuid)
.stateIn(viewModelScope)
.collect { ratings ->
_stateFlow.update {
RatingState.Loaded(
podcastUuid = ratings.podcastUuid,
stars = getStars(ratings.average),
total = ratings.total
)
}
viewModelScope.launch {
try {
ratingsManager.podcastRatings(podcastUuid)
.stateIn(viewModelScope)
.collect { ratings ->
_stateFlow.update {
RatingState.Loaded(
podcastUuid = ratings.podcastUuid,
stars = getStars(ratings.average),
total = ratings.total
)
}
} catch (e: IOException) {
Timber.e(e, "Failed to load podcast ratings")
_stateFlow.update { RatingState.Error }
}
}
} catch (e: IOException) {
Timber.e(e, "Failed to load podcast ratings")
_stateFlow.update { RatingState.Error }
}
}
}
Expand Down

0 comments on commit f45f1ad

Please sign in to comment.