Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable the ratings feature #951

Merged
merged 3 commits into from
May 11, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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