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

Fix crash 0.37 due to missing SortTypes #918

Merged
merged 6 commits into from
Jul 1, 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
68 changes: 52 additions & 16 deletions app/src/main/java/com/jerboa/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -977,22 +977,58 @@ fun convertSpToPx(sp: TextUnit, ctx: Context): Int {
* Returns localized Strings for SortingType Enum
*/

fun getLocalizedSortingTypeName(ctx: Context, sortingType: SortType): String {
val returnString = when (sortingType) {
SortType.Active -> ctx.getString(R.string.sorttype_active)
SortType.Hot -> ctx.getString(R.string.sorttype_hot)
SortType.New -> ctx.getString(R.string.sorttype_new)
SortType.Old -> ctx.getString(R.string.sorttype_old)
SortType.TopDay -> ctx.getString(R.string.sorttype_topday)
SortType.TopWeek -> ctx.getString(R.string.sorttype_topweek)
SortType.TopMonth -> ctx.getString(R.string.sorttype_topmonth)
SortType.TopYear -> ctx.getString(R.string.sorttype_topyear)
SortType.TopAll -> ctx.getString(R.string.sorttype_topall)
SortType.MostComments -> ctx.getString(R.string.sorttype_mostcomments)
SortType.NewComments -> ctx.getString(R.string.sorttype_newcomments)
}
return returnString
}
fun getLocalizedSortingTypeShortName(ctx: Context, sortingType: SortType): String {
return ctx.getString(MAP_SORT_TYPE_SHORT_FORM[sortingType] ?: throw IllegalStateException("Someone forgot to update the MAP_SORT_TYPE_SHORT_FORM"))
}

// ORDER MUST BE THE SAME AS THE ENUM
val MAP_SORT_TYPE_SHORT_FORM = mapOf(
SortType.Active to R.string.sorttype_active,
SortType.Hot to R.string.sorttype_hot,
SortType.New to R.string.sorttype_new,
SortType.Old to R.string.sorttype_old,
SortType.TopDay to R.string.sorttype_topday,
SortType.TopWeek to R.string.sorttype_topweek,
SortType.TopMonth to R.string.sorttype_topmonth,
SortType.TopYear to R.string.sorttype_topyear,
SortType.TopAll to R.string.sorttype_topall,
SortType.MostComments to R.string.sorttype_mostcomments,
SortType.NewComments to R.string.sorttype_newcomments,
SortType.TopHour to R.string.sorttype_tophour,
SortType.TopSixHour to R.string.sorttype_topsixhour,
SortType.TopTwelveHour to R.string.sorttype_toptwelvehour,
SortType.TopThreeMonths to R.string.sorttype_topthreemonths,
SortType.TopSixMonths to R.string.sorttype_topsixmonths,
SortType.TopNineMonths to R.string.sorttype_topninemonths,
)

/**
* Returns localized Strings for SortingType Enum
*/

fun getLocalizedSortingTypeLongName(ctx: Context, sortingType: SortType): String {
return ctx.getString(MAP_SORT_TYPE_LONG_FORM[sortingType] ?: throw IllegalStateException("Someone forgot to update the MAP_SORT_TYPE_LONG_FORM"))
}

val MAP_SORT_TYPE_LONG_FORM = mapOf(
SortType.Active to R.string.sorttype_active,
SortType.Hot to R.string.sorttype_hot,
SortType.New to R.string.sorttype_new,
SortType.Old to R.string.sorttype_old,
SortType.TopDay to R.string.dialogs_top_day,
SortType.TopWeek to R.string.dialogs_top_week,
SortType.TopMonth to R.string.dialogs_top_month,
SortType.TopYear to R.string.dialogs_top_year,
SortType.TopAll to R.string.sorttype_topall,
SortType.MostComments to R.string.dialogs_most_comments,
SortType.NewComments to R.string.dialogs_new_comments,
SortType.TopHour to R.string.dialogs_top_hour,
SortType.TopSixHour to R.string.dialogs_top_six_hour,
SortType.TopTwelveHour to R.string.dialogs_top_twelve_hour,
SortType.TopThreeMonths to R.string.dialogs_top_three_month,
SortType.TopSixMonths to R.string.dialogs_top_six_month,
SortType.TopNineMonths to R.string.dialogs_top_nine_month,
)

/**
* Returns localized Strings for UserTab Enum
Expand Down
37 changes: 37 additions & 0 deletions app/src/main/java/com/jerboa/datatypes/types/Others.kt
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,44 @@ enum class SortType {
*/
@SerializedName("NewComments")
NewComments,

/**
* Posts sorted by the top hour.
*/
@SerializedName("TopHour")
TopHour,

/**
* Posts sorted by the top six hour.
*/
@SerializedName("TopSixHour")
TopSixHour,

/**
* Posts sorted by the top twelve hour.
*/
@SerializedName("TopTwelveHour")
TopTwelveHour,

/**
* Posts sorted by the top three months.
*/
@SerializedName("TopThreeMonths")
TopThreeMonths,

/**
* Posts sorted by the top six months.
*/
@SerializedName("TopSixMonths")
TopSixMonths,

/**
* Posts sorted by the top nine months.
*/
@SerializedName("TopNineMonths")
TopNineMonths,
}
// When updating this enum, don't forget to update MAP_SORT_TYPE_SHORT_FORM and MAP_SORT_TYPE_LONG_FORM

/**
* Different comment sort types used in lemmy.
Expand Down
43 changes: 11 additions & 32 deletions app/src/main/java/com/jerboa/ui/components/common/Dialogs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.semantics.semantics
Expand All @@ -44,6 +45,7 @@ import com.jerboa.datatypes.types.CommentSortType
import com.jerboa.datatypes.types.ListingType
import com.jerboa.datatypes.types.SortType
import com.jerboa.db.AppSettingsViewModel
import com.jerboa.getLocalizedSortingTypeLongName

val DONATION_MARKDOWN = """
### Support Jerboa
Expand All @@ -57,49 +59,26 @@ val DONATION_MARKDOWN = """

""".trimIndent()

val topSortTypes = listOf(
SortType.TopDay,
SortType.TopWeek,
SortType.TopMonth,
SortType.TopYear,
SortType.TopAll,
)
val topSortTypes = SortType.values().filter { it.name.startsWith("Top") }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I spose this is okay, although hard-coding them makes it much more clear.


@Composable
fun SortTopOptionsDialog(
onDismissRequest: () -> Unit,
onClickSortType: (SortType) -> Unit,
selectedSortType: SortType,
) {
val ctx = LocalContext.current
AlertDialog(
onDismissRequest = onDismissRequest,
text = {
Column {
IconAndTextDrawerItem(
text = stringResource(R.string.dialogs_top_day),
onClick = { onClickSortType(SortType.TopDay) },
highlight = (selectedSortType == SortType.TopDay),
)
IconAndTextDrawerItem(
text = stringResource(R.string.dialogs_top_week),
onClick = { onClickSortType(SortType.TopWeek) },
highlight = (selectedSortType == SortType.TopWeek),
)
IconAndTextDrawerItem(
text = stringResource(R.string.dialogs_top_month),
onClick = { onClickSortType(SortType.TopMonth) },
highlight = (selectedSortType == SortType.TopMonth),
)
IconAndTextDrawerItem(
text = stringResource(R.string.dialogs_top_year),
onClick = { onClickSortType(SortType.TopYear) },
highlight = (selectedSortType == SortType.TopYear),
)
IconAndTextDrawerItem(
text = stringResource(R.string.dialogs_top_all_time),
onClick = { onClickSortType(SortType.TopAll) },
highlight = (selectedSortType == SortType.TopAll),
)
topSortTypes.forEach {
IconAndTextDrawerItem(
text = getLocalizedSortingTypeLongName(ctx, it),
onClick = { onClickSortType(it) },
highlight = (selectedSortType == it),
)
}
}
},
confirmButton = {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import com.jerboa.datatypes.sampleCommunityView
import com.jerboa.datatypes.types.CommunityView
import com.jerboa.datatypes.types.SortType
import com.jerboa.datatypes.types.SubscribedType
import com.jerboa.getLocalizedSortingTypeName
import com.jerboa.getLocalizedSortingTypeShortName
import com.jerboa.ui.components.common.DefaultBackButton
import com.jerboa.ui.components.common.IconAndTextDrawerItem
import com.jerboa.ui.components.common.LargerCircularIcon
Expand Down Expand Up @@ -219,7 +219,7 @@ fun CommunityHeaderTitle(
style = MaterialTheme.typography.titleLarge,
)
Text(
text = getLocalizedSortingTypeName(ctx, selectedSortType),
text = getLocalizedSortingTypeShortName(ctx, selectedSortType),
style = MaterialTheme.typography.titleMedium,
)
}
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/com/jerboa/ui/components/home/Home.kt
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ import com.jerboa.datatypes.types.Tagline
import com.jerboa.db.Account
import com.jerboa.db.AccountViewModel
import com.jerboa.getLocalizedListingTypeName
import com.jerboa.getLocalizedSortingTypeName
import com.jerboa.getLocalizedSortingTypeShortName
import com.jerboa.ui.components.common.IconAndTextDrawerItem
import com.jerboa.ui.components.common.LargerCircularIcon
import com.jerboa.ui.components.common.ListingTypeOptionsDialog
Expand Down Expand Up @@ -465,7 +465,7 @@ fun HomeHeaderTitle(
style = MaterialTheme.typography.titleLarge,
)
Text(
text = getLocalizedSortingTypeName(ctx, selectedSortType),
text = getLocalizedSortingTypeShortName(ctx, selectedSortType),
style = MaterialTheme.typography.titleSmall,
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import com.jerboa.R
import com.jerboa.datatypes.samplePersonView
import com.jerboa.datatypes.types.PersonView
import com.jerboa.datatypes.types.SortType
import com.jerboa.getLocalizedSortingTypeName
import com.jerboa.getLocalizedSortingTypeShortName
import com.jerboa.personNameShown
import com.jerboa.ui.components.common.DefaultBackButton
import com.jerboa.ui.components.common.DotSpacer
Expand Down Expand Up @@ -250,7 +250,7 @@ fun PersonProfileHeaderTitle(
style = MaterialTheme.typography.titleLarge,
)
Text(
text = getLocalizedSortingTypeName(LocalContext.current, selectedSortType),
text = getLocalizedSortingTypeShortName(LocalContext.current, selectedSortType),
style = MaterialTheme.typography.titleMedium,
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import com.alorma.compose.settings.storage.base.rememberBooleanSettingState
import com.alorma.compose.settings.storage.base.rememberIntSettingState
import com.alorma.compose.settings.ui.SettingsCheckbox
import com.alorma.compose.settings.ui.SettingsListDropdown
import com.jerboa.MAP_SORT_TYPE_SHORT_FORM
import com.jerboa.R
import com.jerboa.api.ApiState
import com.jerboa.api.uploadPictrsImage
Expand Down Expand Up @@ -122,6 +123,9 @@ fun SettingsForm(
rememberBooleanSettingState(luv?.local_user?.show_new_post_notifs ?: false)
val sendNotificationsToEmail =
rememberBooleanSettingState(luv?.local_user?.send_notifications_to_email ?: false)
val sortTypeNames = remember {
MAP_SORT_TYPE_SHORT_FORM.values.map { ctx.getString(it) }
}
val form = SaveUserSettings(
display_name = displayName,
bio = bio.text,
Expand Down Expand Up @@ -236,19 +240,7 @@ fun SettingsForm(
SettingsListDropdown(
state = defaultSortType,
title = { Text(text = stringResource(R.string.account_settings_default_sort_type)) },
items = listOf(
stringResource(R.string.account_settings_active),
stringResource(R.string.account_settings_hot),
stringResource(R.string.account_settings_new),
stringResource(R.string.account_settings_old),
stringResource(R.string.account_settings_topday),
stringResource(R.string.account_settings_topweek),
stringResource(R.string.account_settings_topmonth),
stringResource(R.string.account_settings_topyear),
stringResource(R.string.account_settings_topall),
stringResource(R.string.account_settings_mostcomments),
stringResource(R.string.account_settings_newcomments),
),
items = sortTypeNames,
)

SettingsCheckbox(
Expand Down
19 changes: 0 additions & 19 deletions app/src/main/res/values-da/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@
<string name="pictrs_image_upload_image">Upload billede</string>
<string name="time_ago_ago">%1$s %2$s siden</string>
<string name="community_list_search">Søg...</string>
<string name="community_list_back">Tilbage</string>
<string name="community_users_month">%1$s brugere / måned</string>
<string name="community_joined">Blev medlem af</string>
<string name="community_subscribe">Bliv medlem af</string>
Expand All @@ -83,7 +82,6 @@
<string name="home_refresh">Opdater</string>
<string name="home_post_view_mode">Indlægvisningstilstand</string>
<string name="home_site_info">Sideinfo</string>
<string name="inbox_back">Tilbage</string>
<string name="inbox_inbox">Indbakke</string>
<string name="login_password">Adgangskode</string>
<string name="login_instance">Instans</string>
Expand All @@ -94,17 +92,14 @@
<string name="person_profile_joined">Blev medlem af</string>
<string name="person_profile_posts">%1$s indlæg</string>
<string name="person_profile_comments">%1$s kommentarer</string>
<string name="person_profile_back">Tilbage</string>
<string name="person_profile_block_person">Bloker bruger</string>
<string name="person_profile_report_person">Rapportér bruger</string>
<string name="person_profile_activity_moderates">Modererer</string>
<string name="create_post_create_post">Opret indlæg</string>
<string name="create_post_close">Luk</string>
<string name="create_post_copy_suggested_title">Kopier foreslået titel: %1$s</string>
<string name="create_post_community">Fællesskab</string>
<string name="create_post_a_title_here">En titel her....</string>
<string name="post_edit_edit_post">Rediger indlæg</string>
<string name="post_edit_close">Luk</string>
<string name="post_edit_body_placeholder">Hovedtekst</string>
<string name="post_activity_comments">Kommentarer</string>
<string name="post_listing_comments">%1$s kommentarer</string>
Expand Down Expand Up @@ -150,17 +145,6 @@
<string name="account_settings_local">Lokale</string>
<string name="account_settings_subscribed">Abonneret</string>
<string name="account_settings_default_listing_type">Foretrukket Listevisningstype</string>
<string name="account_settings_active">Aktive</string>
<string name="account_settings_hot">Populære</string>
<string name="account_settings_new">Nye</string>
<string name="account_settings_old">Gamle</string>
<string name="account_settings_topday">Populære i dag</string>
<string name="account_settings_topweek">Populære denne uge</string>
<string name="account_settings_topmonth">Populære denne måned</string>
<string name="account_settings_topyear">Populære i år</string>
<string name="account_settings_topall">Populære gennem tiderne</string>
<string name="account_settings_mostcomments">Flest kommentarer</string>
<string name="account_settings_newcomments">Nye kommentarer</string>
<string name="account_settings_default_sort_type">Foretrukken sorteringsmetode</string>
<string name="account_settings_show_nsfw">Vis eksplicit indhold (NSFW)</string>
<string name="account_settings_show_avatars">Vis profilbilleder</string>
Expand Down Expand Up @@ -191,9 +175,7 @@
<string name="settings_activity_look_and_feel">Udseende og fornemmelse</string>
<string name="settings_activity_account_settings">%1$s indstillinger</string>
<string name="settings_activity_about">Om</string>
<string name="community_blocked">%1$s Blokeret</string>
<string name="comment_mention_node_permalink_copied">Permanent link kopieret</string>
<string name="person_routines_blocked">%1$s Blokeret</string>
<string name="utils_login_first">Log ind først</string>
<string name="login_view_model_incorrect_login">Forkert login</string>
<string name="login_view_model_is_not_a_lemmy_instance">%1$s er ikke en Lemmy-instans</string>
Expand All @@ -219,7 +201,6 @@
<string name="removeBookmark">Fjern bogmærke</string>
<string name="commentFooter_reply">Svar på denne kommentar</string>
<string name="dialog_moreOptions">Vis flere muligheder</string>
<string name="pickImage_imagePreview">Forhåndsvisning af uploadet billede</string>
<string name="commentEdit_save">Gem redigeret kommentar</string>
<string name="commentReply_send">Send svar</string>
<string name="community_sortBy">Sorter efter</string>
Expand Down
Loading