Skip to content

Commit

Permalink
feat(Activity): localize list activity text (#217)
Browse files Browse the repository at this point in the history
  • Loading branch information
axiel7 committed Oct 26, 2024
1 parent cd22518 commit 30a2d41
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.axiel7.anihyou.data.model.activity
import androidx.compose.runtime.Immutable
import com.axiel7.anihyou.ActivityDetailsQuery
import com.axiel7.anihyou.fragment.ActivityReplyFragment
import com.axiel7.anihyou.fragment.ListActivityFragment
import com.axiel7.anihyou.type.ActivityType

@Immutable
Expand All @@ -20,6 +21,7 @@ data class GenericActivity(
val mediaId: Int? = null,
val mediaCoverUrl: String? = null,
val replies: List<ActivityReplyFragment>?,
val listActivityFragment: ListActivityFragment? = null,
) {
fun updateLikeStatus(isLiked: Boolean) = copy(
isLiked = isLiked,
Expand All @@ -45,7 +47,7 @@ fun ActivityDetailsQuery.OnListActivity.toGenericActivity() = GenericActivity(
id = listActivityFragment.id,
type = ActivityType.MEDIA_LIST,
createdAt = listActivityFragment.createdAt,
text = listActivityFragment.text(),
text = null,
isLiked = listActivityFragment.isLiked,
likeCount = listActivityFragment.likeCount,
replyCount = listActivityFragment.replyCount,
Expand All @@ -54,7 +56,8 @@ fun ActivityDetailsQuery.OnListActivity.toGenericActivity() = GenericActivity(
avatarUrl = user?.avatar?.medium,
mediaId = listActivityFragment.media?.id,
mediaCoverUrl = listActivityFragment.media?.coverImage?.medium,
replies = replies?.filterNotNull()?.map { it.activityReplyFragment }
replies = replies?.filterNotNull()?.map { it.activityReplyFragment },
listActivityFragment = listActivityFragment,
)

fun ActivityDetailsQuery.OnMessageActivity.toGenericActivity() = GenericActivity(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,43 @@
package com.axiel7.anihyou.data.model.activity

import androidx.compose.runtime.Composable
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.capitalize
import androidx.compose.ui.text.intl.Locale
import com.axiel7.anihyou.R
import com.axiel7.anihyou.fragment.ListActivityFragment

private const val watchedStatus = "watched episode"
private const val rewatchedStatus = "rewatched episode"
private const val plansToWatchStatus = "plans to watch"
private const val readStatus = "read chapter"
private const val rereadStatus = "reread chapter"
private const val plansToReadStatus = "plans to read"
private const val completedStatus = "completed"
private const val droppedStatus = "dropped"
private const val pausedStatus = "paused"

@Composable
fun ListActivityFragment.text(): String {
return if (progress != null) "${status?.capitalize(Locale.current)} $progress of ${media?.title?.userPreferred}"
else "${status?.capitalize(Locale.current)} ${media?.title?.userPreferred}"
val mediaTitle = media?.title?.userPreferred.orEmpty()
return if (progress != null) {
when (status) {
watchedStatus -> stringResource(R.string.watched_episode_of, progress, mediaTitle)
rewatchedStatus -> stringResource(R.string.rewatched_episode_of, progress, mediaTitle)
readStatus -> stringResource(R.string.read_chapter_of, progress, mediaTitle)
rereadStatus -> stringResource(R.string.reread_chapter_of, progress, mediaTitle)
else -> "${status?.capitalize(Locale.current)} $progress of $mediaTitle"
}
} else {
when (status) {
plansToWatchStatus -> stringResource(R.string.plans_to_watch_anime, mediaTitle)
plansToReadStatus -> stringResource(R.string.plans_to_read_manga, mediaTitle)
completedStatus -> stringResource(R.string.completed_media, mediaTitle)
droppedStatus -> stringResource(R.string.dropped_media, mediaTitle)
pausedStatus -> stringResource(R.string.paused_media, mediaTitle)
else -> "${status?.capitalize(Locale.current)} $mediaTitle"
}
}
}

fun ListActivityFragment.updateLikeStatus(isLiked: Boolean) = copy(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.compose.LifecycleResumeEffect
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.axiel7.anihyou.R
import com.axiel7.anihyou.data.model.activity.text
import com.axiel7.anihyou.ui.common.navigation.NavActionManager
import com.axiel7.anihyou.ui.composables.DefaultScaffoldWithSmallTopAppBar
import com.axiel7.anihyou.ui.composables.common.BackIconButton
Expand Down Expand Up @@ -125,7 +126,8 @@ private fun ActivityDetailsContent(
if (uiState.details != null) {
ActivityTextView(
modifier = Modifier.padding(16.dp),
text = uiState.details.text.orEmpty(),
text = uiState.details.text
?: uiState.details.listActivityFragment?.text().orEmpty(),
username = uiState.details.username,
avatarUrl = uiState.details.avatarUrl,
mediaCoverUrl = uiState.details.mediaCoverUrl,
Expand Down
9 changes: 9 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,15 @@
<string name="male">Male</string>
<string name="female">Female</string>
<string name="non_binary">Non-binary</string>
<string name="watched_episode_of">Watched episode %1$s of %2$s</string>
<string name="rewatched_episode_of">Rewatched episode %1$s of %2$s</string>
<string name="read_chapter_of">Read chapter %1$s of %2$s</string>
<string name="reread_chapter_of">Reread chapter %1$s of %2$s</string>
<string name="plans_to_watch_anime">Plans to watch %s</string>
<string name="plans_to_read_manga">Plans to read %s</string>
<string name="completed_media">Completed %s</string>
<string name="dropped_media">Dropped %s</string>
<string name="paused_media">Paused %s</string>
<plurals name="hour_abbreviation">
<item quantity="one">%d h</item>
<item quantity="other">%d h</item>
Expand Down

0 comments on commit 30a2d41

Please sign in to comment.