/
Others.kt
201 lines (180 loc) · 7.08 KB
/
Others.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
package com.jerboa.datatypes
import android.content.Context
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.Scale
import androidx.compose.material.icons.outlined.ThumbsUpDown
import androidx.compose.ui.graphics.vector.ImageVector
import com.jerboa.R
import com.jerboa.UnreadOrAll
import com.jerboa.ui.components.person.UserTab
import it.vercruysse.lemmyapi.dto.CommentSortType
import it.vercruysse.lemmyapi.dto.ListingType
import it.vercruysse.lemmyapi.dto.PostFeatureType
import it.vercruysse.lemmyapi.dto.SortType
import it.vercruysse.lemmyapi.v0x19.datatypes.Community
import it.vercruysse.lemmyapi.v0x19.datatypes.Person
import it.vercruysse.lemmyapi.v0x19.datatypes.Post
import kotlinx.serialization.Serializable
data class CommentSortData(
@StringRes val text: Int,
val icon: ImageVector,
)
val CommentSortType.data: CommentSortData
get() = when (this) {
CommentSortType.Hot -> CommentSortData(R.string.dialogs_hot, Icons.Outlined.LocalFireDepartment)
CommentSortType.New -> CommentSortData(R.string.dialogs_new, Icons.Outlined.BrightnessLow)
CommentSortType.Old -> CommentSortData(R.string.dialogs_old, Icons.Outlined.History)
CommentSortType.Top -> CommentSortData(R.string.dialogs_top, Icons.Outlined.BarChart)
CommentSortType.Controversial -> CommentSortData(R.string.sorttype_controversial, Icons.Outlined.ThumbsUpDown)
}
data class SortData(
@StringRes val shortForm: Int,
@StringRes val longForm: Int,
val icon: ImageVector,
)
val SortType.data: SortData
get() = when (this) {
SortType.Active -> SortData(R.string.sorttype_active, R.string.sorttype_active, Icons.Outlined.Moving)
SortType.Hot -> SortData(R.string.sorttype_hot, R.string.sorttype_hot, Icons.Outlined.LocalFireDepartment)
SortType.New -> SortData(R.string.sorttype_new, R.string.sorttype_new, Icons.Outlined.BrightnessLow)
SortType.Old -> SortData(R.string.sorttype_old, R.string.sorttype_old, Icons.Outlined.History)
SortType.Controversial -> SortData(
R.string.sorttype_controversial,
R.string.sorttype_controversial,
Icons.Outlined.ThumbsUpDown,
)
SortType.TopDay -> SortData(R.string.sorttype_topday, R.string.dialogs_top_day, Icons.Outlined.BarChart)
SortType.TopWeek -> SortData(R.string.sorttype_topweek, R.string.dialogs_top_week, Icons.Outlined.BarChart)
SortType.TopMonth -> SortData(R.string.sorttype_topmonth, R.string.dialogs_top_month, Icons.Outlined.BarChart)
SortType.TopYear -> SortData(R.string.sorttype_topyear, R.string.dialogs_top_year, Icons.Outlined.BarChart)
SortType.TopAll -> SortData(R.string.sorttype_topall, R.string.dialogs_top_all, Icons.Outlined.BarChart)
SortType.MostComments -> SortData(
R.string.sorttype_mostcomments,
R.string.sorttype_mostcomments_long,
Icons.Outlined.FormatListNumbered,
)
SortType.NewComments -> SortData(
R.string.sorttype_newcomments,
R.string.sorttype_newcomments_long,
Icons.Outlined.NewReleases,
)
SortType.TopHour -> SortData(R.string.sorttype_tophour, R.string.dialogs_top_hour, Icons.Outlined.BarChart)
SortType.TopSixHour -> SortData(
R.string.sorttype_topsixhour,
R.string.dialogs_top_six_hour,
Icons.Outlined.BarChart,
)
SortType.TopTwelveHour -> SortData(
R.string.sorttype_toptwelvehour,
R.string.dialogs_top_twelve_hour,
Icons.Outlined.BarChart,
)
SortType.TopThreeMonths -> SortData(
R.string.sorttype_topthreemonths,
R.string.dialogs_top_three_month,
Icons.Outlined.BarChart,
)
SortType.TopSixMonths -> SortData(
R.string.sorttype_topsixmonths,
R.string.dialogs_top_six_month,
Icons.Outlined.BarChart,
)
SortType.TopNineMonths -> SortData(
R.string.sorttype_topninemonths,
R.string.dialogs_top_nine_month,
Icons.Outlined.BarChart,
)
SortType.Scaled -> SortData(R.string.sorttype_scaled, R.string.sorttype_scaled, Icons.Outlined.Scale)
}
/**
* Returns localized Strings for UserTab Enum
*/
fun getLocalizedStringForUserTab(
ctx: Context,
tab: UserTab,
): String =
when (tab) {
UserTab.About -> ctx.getString(R.string.person_profile_activity_about)
UserTab.Posts -> ctx.getString(R.string.person_profile_activity_posts)
UserTab.Comments -> ctx.getString(R.string.person_profile_activity_comments)
}
/**
* Returns localized Strings for ListingType Enum
*/
fun getLocalizedListingTypeName(
ctx: Context,
listingType: ListingType,
): String =
when (listingType) {
ListingType.All -> ctx.getString(R.string.home_all)
ListingType.Local -> ctx.getString(R.string.home_local)
ListingType.Subscribed -> ctx.getString(R.string.home_subscribed)
ListingType.ModeratorView -> ctx.getString(R.string.home_moderator_view)
}
/**
* Returns localized Strings for CommentSortType Enum
*/
fun getLocalizedCommentSortTypeName(
ctx: Context,
commentSortType: CommentSortType,
): String =
when (commentSortType) {
CommentSortType.Hot -> ctx.getString(R.string.sorttype_hot)
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)
}
/**
* Returns localized Strings for UnreadOrAll Enum
*/
fun getLocalizedUnreadOrAllName(
ctx: Context,
unreadOrAll: UnreadOrAll,
): String =
when (unreadOrAll) {
UnreadOrAll.Unread -> ctx.getString(R.string.dialogs_unread)
UnreadOrAll.All -> ctx.getString(R.string.dialogs_all)
}
/**
* A container to store extra community ban info
*/
@Serializable
data class BanFromCommunityData(
val person: Person,
val community: Community,
val banned: Boolean,
)
/**
* A container to store extra post feature info
*/
data class PostFeatureData(
val post: Post,
val type: PostFeatureType,
val featured: Boolean,
)
// TODO this should be got rid of after https://github.com/LemmyNet/lemmy/issues/4449
enum class VoteDisplayMode {
Full,
ScoreAndDownvote,
ScoreAndUpvotePercentage,
UpvotePercentage,
Score,
HideAll,
}
/**
* Says which type of users can view which bottom app bar tabs.
*/
enum class UserViewType {
Normal,
AdminOnly,
AdminOrMod,
}