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

Controversial posts and comments #1106

Merged
merged 19 commits into from
Aug 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
9665061
Added Controversial sort options for posts and comments
iByteABit256 Jul 27, 2023
6fb6fd4
Added Controversial sort options for posts and comments
iByteABit256 Jul 27, 2023
23a3fde
Merge branch 'main' into controversial-posts-and-comments
iByteABit256 Jul 27, 2023
0467b17
Merge branch 'main' into controversial-posts-and-comments
iByteABit256 Jul 29, 2023
94f0cfe
Added supported versions for sort types, siteVersion() in SiteViewMod…
iByteABit256 Jul 31, 2023
d32f12d
Fixed lint errors
iByteABit256 Jul 31, 2023
3ae3a02
Added short form and long form to SortType enum, removed getLocalized…
iByteABit256 Aug 1, 2023
3bb0f3b
Merge branch 'main' into controversial-posts-and-comments
iByteABit256 Aug 1, 2023
7bfaddb
Lint errors
iByteABit256 Aug 1, 2023
dcf0e65
Removed dialog string for Controversial and made everything use the s…
iByteABit256 Aug 2, 2023
c431b74
Merge branch 'main' into controversial-posts-and-comments
iByteABit256 Aug 2, 2023
dde6e65
Merge branch 'main' into controversial-posts-and-comments
iByteABit256 Aug 2, 2023
e6f2f46
lint
iByteABit256 Aug 2, 2023
21e26ef
Fixed SortType and supported sort type indexes not lining up
iByteABit256 Aug 3, 2023
b4c9c25
Merge branch 'main' into controversial-posts-and-comments
iByteABit256 Aug 3, 2023
63df4cb
Merge branch 'main' of github.com:iByteABit256/jerboa into controvers…
iByteABit256 Aug 8, 2023
99ba843
unused imports
iByteABit256 Aug 8, 2023
e8d41cc
Merge branch 'main' into controversial-posts-and-comments
dessalines Aug 24, 2023
53ac0a8
Fixing lints.
dessalines Aug 24, 2023
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
64 changes: 1 addition & 63 deletions app/src/main/java/com/jerboa/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -1041,69 +1041,6 @@ fun convertSpToPx(sp: TextUnit, ctx: Context): Int {
return (sp.value * ctx.resources.displayMetrics.scaledDensity).toInt()
}

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

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.dialogs_top_all,
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 Expand Up @@ -1137,6 +1074,7 @@ fun getLocalizedCommentSortTypeName(ctx: Context, commentSortType: CommentSortTy
CommentSortType.New -> ctx.getString(R.string.sorttype_new)
CommentSortType.Old -> ctx.getString(R.string.sorttype_old)
CommentSortType.Top -> ctx.getString(R.string.dialogs_top)
CommentSortType.Controversial -> ctx.getString(R.string.sorttype_controversial)
}
return returnString
}
Expand Down
167 changes: 143 additions & 24 deletions app/src/main/java/com/jerboa/datatypes/types/Others.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,27 @@
package com.jerboa.datatypes.types

import android.os.Parcelable
import androidx.annotation.StringRes
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.outlined.BarChart
import androidx.compose.material.icons.outlined.BrightnessLow
import androidx.compose.material.icons.outlined.FormatListNumbered
import androidx.compose.material.icons.outlined.History
import androidx.compose.material.icons.outlined.LocalFireDepartment
import androidx.compose.material.icons.outlined.Moving
import androidx.compose.material.icons.outlined.NewReleases
import androidx.compose.material.icons.outlined.ThumbsUpDown
import androidx.compose.runtime.Immutable
import androidx.compose.ui.graphics.vector.ImageVector
import com.google.gson.annotations.SerializedName
import com.jerboa.R
import com.jerboa.api.MINIMUM_API_VERSION
import com.jerboa.compareVersions
import kotlinx.parcelize.Parcelize

const val MINIMUM_CONTROVERSIAL_SORT_API_VERSION: String = "0.19"
const val MINIMUM_TOP_X_MONTHLY_SORT_API_VERSION: String = "0.18.1"

enum class RegistrationMode {
@SerializedName("Closed")
Closed,
Expand All @@ -19,135 +36,237 @@ enum class RegistrationMode {
/**
* Different sort types used in lemmy.
*/
enum class SortType {
enum class SortType(
@StringRes val shortForm: Int,
@StringRes val longForm: Int,
val icon: ImageVector? = null,
val version: String = MINIMUM_API_VERSION,
MV-GH marked this conversation as resolved.
Show resolved Hide resolved
) {
/**
* Posts sorted by the most recent comment.
*/
@SerializedName("Active")
Active,
Active(
R.string.sorttype_active,
R.string.sorttype_active,
Icons.Outlined.Moving,
),

/**
* Posts sorted by the published time.
*/
@SerializedName("Hot")
Hot,
Hot(
R.string.sorttype_hot,
R.string.sorttype_hot,
Icons.Outlined.LocalFireDepartment,
),

@SerializedName("New")
New,
New(
R.string.sorttype_new,
R.string.sorttype_new,
Icons.Outlined.BrightnessLow,
),

/**
* Posts sorted by the published time ascending
*/
@SerializedName("Old")
Old,
Old(
R.string.sorttype_old,
R.string.sorttype_old,
Icons.Outlined.History,
),

/**
* Posts sorted by controversy rank.
*/
@SerializedName("Controversial")
Controversial(
R.string.sorttype_controversial,
R.string.sorttype_controversial,
Icons.Outlined.ThumbsUpDown,
MINIMUM_CONTROVERSIAL_SORT_API_VERSION,
),

/**
* The top posts for this last day.
*/
@SerializedName("TopDay")
TopDay,
TopDay(
R.string.sorttype_topday,
R.string.dialogs_top_day,
Icons.Outlined.BarChart,
),

/**
* The top posts for this last week.
*/
@SerializedName("TopWeek")
TopWeek,
TopWeek(
R.string.sorttype_topweek,
R.string.dialogs_top_week,
Icons.Outlined.BarChart,
),

/**
* The top posts for this last month.
*/
@SerializedName("TopMonth")
TopMonth,
TopMonth(
R.string.sorttype_topmonth,
R.string.dialogs_top_month,
Icons.Outlined.BarChart,
),

/**
* The top posts for this last year.
*/
@SerializedName("TopYear")
TopYear,
TopYear(
R.string.sorttype_topyear,
R.string.dialogs_top_year,
Icons.Outlined.BarChart,
),

/**
* The top posts of all time.
*/
@SerializedName("TopAll")
TopAll,
TopAll(
R.string.sorttype_topall,
R.string.dialogs_top_all,
Icons.Outlined.BarChart,
),

/**
* Posts sorted by the most comments.
*/
@SerializedName("MostComments")
MostComments,
MostComments(
R.string.sorttype_mostcomments,
R.string.sorttype_mostcomments,
Icons.Outlined.FormatListNumbered,
),

/**
* Posts sorted by the newest comments, with no necrobumping. IE a forum sort.
*/
@SerializedName("NewComments")
NewComments,
NewComments(
R.string.sorttype_newcomments,
R.string.sorttype_newcomments,
Icons.Outlined.NewReleases,
),

/**
* Posts sorted by the top hour.
*/
@SerializedName("TopHour")
TopHour,
TopHour(
R.string.sorttype_tophour,
R.string.dialogs_top_hour,
Icons.Outlined.BarChart,
),

/**
* Posts sorted by the top six hour.
*/
@SerializedName("TopSixHour")
TopSixHour,
TopSixHour(
R.string.sorttype_topsixhour,
R.string.dialogs_top_six_hour,
Icons.Outlined.BarChart,
),

/**
* Posts sorted by the top twelve hour.
*/
@SerializedName("TopTwelveHour")
TopTwelveHour,
TopTwelveHour(
R.string.sorttype_toptwelvehour,
R.string.dialogs_top_twelve_hour,
Icons.Outlined.BarChart,
),

/**
* Posts sorted by the top three months.
*/
@SerializedName("TopThreeMonths")
TopThreeMonths,
TopThreeMonths(
R.string.sorttype_topthreemonths,
R.string.dialogs_top_three_month,
Icons.Outlined.BarChart,
MINIMUM_TOP_X_MONTHLY_SORT_API_VERSION,
),

/**
* Posts sorted by the top six months.
*/
@SerializedName("TopSixMonths")
TopSixMonths,
TopSixMonths(
R.string.sorttype_topsixmonths,
R.string.dialogs_top_six_month,
Icons.Outlined.BarChart,
MINIMUM_TOP_X_MONTHLY_SORT_API_VERSION,
),

/**
* Posts sorted by the top nine months.
*/
@SerializedName("TopNineMonths")
TopNineMonths,
TopNineMonths(
R.string.sorttype_topninemonths,
R.string.dialogs_top_nine_month,
Icons.Outlined.BarChart,
MINIMUM_TOP_X_MONTHLY_SORT_API_VERSION,
),
;

companion object {
val getSupportedSortTypes = { siteVersion: String -> values().filter { compareVersions(siteVersion, it.version) >= 0 } }
}
}
// 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.
*/
enum class CommentSortType {
enum class CommentSortType(val text: Int, val icon: ImageVector? = null, val version: String = MINIMUM_API_VERSION) {
/**
* Comments sorted by a decaying rank.
*/
@SerializedName("Hot")
Hot,
Hot(R.string.dialogs_hot, Icons.Outlined.LocalFireDepartment),

/**
* Comments sorted by top score.
*/
@SerializedName("Top")
Top,
Top(R.string.dialogs_top, Icons.Outlined.BarChart),

/**
* Comments sorted by new.
*/
@SerializedName("New")
New,
New(R.string.dialogs_new, Icons.Outlined.BrightnessLow),

/**
* Comments sorted by old.
*/
@SerializedName("Old")
Old,
Old(R.string.dialogs_old, Icons.Outlined.History),

/**
* Posts sorted by controversy rank.
*/
@SerializedName("Controversial")
Controversial(R.string.sorttype_controversial, Icons.Outlined.ThumbsUpDown, MINIMUM_CONTROVERSIAL_SORT_API_VERSION),
;

companion object {
val getSupportedSortTypes = { siteVersion: String -> values().filter { compareVersions(siteVersion, it.version) >= 0 } }
}
}

/**
Expand Down
8 changes: 8 additions & 0 deletions app/src/main/java/com/jerboa/model/SiteViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import androidx.lifecycle.viewmodel.viewModelFactory
import com.jerboa.api.API
import com.jerboa.api.ApiState
import com.jerboa.api.DEFAULT_INSTANCE
import com.jerboa.api.MINIMUM_API_VERSION
import com.jerboa.api.apiWrapper
import com.jerboa.datatypes.types.GetSite
import com.jerboa.datatypes.types.GetSiteResponse
Expand Down Expand Up @@ -150,6 +151,13 @@ class SiteViewModel(private val accountRepository: AccountRepository) : ViewMode
}
}

fun siteVersion(): String {
return when (val res = siteRes) {
is ApiState.Success -> res.data.version
else -> MINIMUM_API_VERSION
}
}

companion object {
val Factory = viewModelFactory {
initializer {
Expand Down
Loading