Skip to content

Commit

Permalink
added rating
Browse files Browse the repository at this point in the history
  • Loading branch information
DatL4g committed Apr 4, 2024
1 parent 7503003 commit b427b55
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@ class MediumStateMachine(
currentState = it
}
onEnter { state ->
Cache.getMedium(state.snapshot.query)?.let {
return@onEnter state.override { State.Success(query, it) }
}

val response = CatchResult.result {
client.query(state.snapshot.query).execute().dataOrThrow()
}.mapSuccess<State> {
Expand All @@ -40,14 +36,20 @@ class MediumStateMachine(
}
}

val cached = Cache.getMedium(state.snapshot.query)

state.override {
response.asSuccess {
crashlytics?.log(it)

if (retry <= 3) {
State.Loading(query, retry + 1)
if (cached != null) {
State.Success(query, cached)
} else {
State.Error(query)
if (retry <= 3) {
State.Loading(query, retry + 1)
} else {
State.Error(query)
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,8 @@ open class Medium(
val isYoutube: Boolean = site.contains("youtu.be", ignoreCase = true)
|| site.contains("youtube", ignoreCase = true)

val isDailymotion: Boolean = site.contains("dailymotion", ignoreCase = true)

private val youtubeVideoId: String? = run {
val afterVi = thumbnail.substringAfter(
delimiter = "vi/",
Expand All @@ -395,9 +397,19 @@ open class Medium(
afterVi.substringBefore('/', missingDelimiterValue = "").ifBlank { null }
}

val youtubeVideo = (id ?: youtubeVideoId)?.let {
private val youtubeVideo = (id ?: youtubeVideoId)?.let {
"https://youtube.com/watch?v=$it"
}

private val dailymotionVideo = id?.let {
"https://dailymotion.com/video/$it"
}

val videoUrl = when {
isYoutube -> youtubeVideo
isDailymotion -> dailymotionVideo
else -> null
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ fun EditFAB(
)
) {
LabelFAB(
label = "Rating",
label = "Progress",
onClick = {
showOtherFABs = false
onRate()
onProgress()
}
) {
Icon(
imageVector = Icons.Default.Star,
imageVector = Icons.Default.Visibility,
contentDescription = null
)
}
Expand All @@ -74,14 +74,14 @@ fun EditFAB(
)
) {
LabelFAB(
label = "Progress",
label = "Rating",
onClick = {
showOtherFABs = false
onProgress()
onRate()
}
) {
Icon(
imageVector = Icons.Default.Visibility,
imageVector = Icons.Default.Star,
contentDescription = null
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ fun MediumScreen(component: MediumComponent) {
bodyText = ""
),
config = RatingConfig(
ratingOptionsCount = 5
ratingOptionsCount = 5,
ratingOptionsSelected = userRating.takeIf { it > 0 },
ratingZeroValid = true
)
)

Expand Down Expand Up @@ -488,8 +490,7 @@ fun MediumScreen(component: MediumComponent) {
Card(
modifier = Modifier.fillParentMaxWidth().height(200.dp).padding(16.dp),
onClick = {
Napier.e(t.id ?: t.website)
uriHandler.openUri(t.youtubeVideo ?: t.website)
uriHandler.openUri(t.videoUrl ?: t.website)
}
) {
Box(
Expand Down

0 comments on commit b427b55

Please sign in to comment.