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

Remove ImmutableList and add stability config file #1342

Merged
merged 1 commit into from
Feb 5, 2024
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
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ You can run it by doing
You can generate the compose compiler metrics by executing the following gradle task.

```shell
./gradlew assembleRelease --rerun-tasks -P com.jerboa.enableComposeCompilerReports=true
./gradlew assembleRelease --rerun-tasks -P enableComposeCompilerReports=true
```

Then you will find the metrics in `app/build/compose_metrics` directory.
Expand Down
2 changes: 0 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,6 @@ dependencies {
implementation("androidx.profileinstaller:profileinstaller:1.3.1")
baselineProfile(project(":benchmarks"))

implementation("org.jetbrains.kotlinx:kotlinx-collections-immutable:0.3.7")

implementation("it.vercruysse.lemmyapi:lemmy-api:0.2.8-SNAPSHOT")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.2")
// Ktor uses SLF4J
Expand Down
10 changes: 4 additions & 6 deletions app/src/main/java/com/jerboa/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ import com.jerboa.db.entity.AppSettings
import com.jerboa.ui.components.common.Route
import com.jerboa.ui.theme.SMALL_PADDING
import it.vercruysse.lemmyapi.v0x19.datatypes.*
import kotlinx.collections.immutable.ImmutableList
import kotlinx.collections.immutable.toImmutableList
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.launch
import okhttp3.Request
Expand Down Expand Up @@ -126,8 +124,8 @@ class MissingCommentNode(
override fun getPath() = missingCommentView.path
}

fun commentsToFlatNodes(comments: List<CommentView>): ImmutableList<CommentNode> {
return comments.map { c -> CommentNode(c, depth = 0) }.toImmutableList()
fun commentsToFlatNodes(comments: List<CommentView>): List<CommentNode> {
return comments.map { c -> CommentNode(c, depth = 0) }
}

/**
Expand All @@ -141,7 +139,7 @@ fun buildCommentsTree(
comments: List<CommentView>,
// If it's in CommentView, then we need to know the root comment id
rootCommentId: CommentId?,
): ImmutableList<CommentNodeData> {
): List<CommentNodeData> {
val isCommentView = rootCommentId != null

val map = LinkedHashMap<Number, CommentNodeData>()
Expand Down Expand Up @@ -169,7 +167,7 @@ fun buildCommentsTree(
}
}

return tree.toImmutableList()
return tree
}

/**
Expand Down
9 changes: 4 additions & 5 deletions app/src/main/java/com/jerboa/feat/ModActions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package com.jerboa.feat
import it.vercruysse.lemmyapi.v0x19.datatypes.CommunityModeratorView
import it.vercruysse.lemmyapi.v0x19.datatypes.PersonId
import it.vercruysse.lemmyapi.v0x19.datatypes.PersonView
import kotlinx.collections.immutable.ImmutableList
import java.time.Instant
import java.time.temporal.ChronoUnit

Expand All @@ -12,8 +11,8 @@ import java.time.temporal.ChronoUnit
*/
fun canMod(
creatorId: PersonId,
admins: ImmutableList<PersonView>?,
moderators: ImmutableList<CommunityModeratorView>?,
admins: List<PersonView>?,
moderators: List<CommunityModeratorView>?,
myId: PersonId?,
onSelf: Boolean = false,
): Boolean {
Expand Down Expand Up @@ -46,14 +45,14 @@ fun futureDaysToUnixTime(days: Long?): Long? {
}

fun amMod(
moderators: ImmutableList<CommunityModeratorView>?,
moderators: List<CommunityModeratorView>?,
myId: PersonId?,
): Boolean {
return moderators?.map { it.moderator.id }?.contains(myId) ?: false
}

fun amAdmin(
admins: ImmutableList<PersonView>?,
admins: List<PersonView>?,
myId: PersonId?,
): Boolean {
return admins?.map { it.person.id }?.contains(myId) ?: false
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/java/com/jerboa/model/AppSettingsViewModel.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.jerboa.model

import androidx.compose.runtime.Stable
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import androidx.lifecycle.viewmodel.initializer
Expand All @@ -9,6 +10,7 @@ import com.jerboa.db.repository.AppSettingsRepository
import com.jerboa.jerboaApplication
import kotlinx.coroutines.launch

@Stable
class AppSettingsViewModel(private val repository: AppSettingsRepository) : ViewModel() {
val appSettings = repository.appSettings
val changelog = repository.changelog
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@ import it.vercruysse.lemmyapi.v0x19.datatypes.CommunityFollowerView
import it.vercruysse.lemmyapi.v0x19.datatypes.CommunityView
import it.vercruysse.lemmyapi.v0x19.datatypes.Search
import it.vercruysse.lemmyapi.v0x19.datatypes.SearchResponse
import kotlinx.collections.immutable.ImmutableList
import kotlinx.coroutines.launch

class CommunityListViewModel(communities: ImmutableList<CommunityFollowerView>) : ViewModel() {
class CommunityListViewModel(communities: List<CommunityFollowerView>) : ViewModel() {
var searchRes: ApiState<SearchResponse> by mutableStateOf(ApiState.Empty)
private set

Expand All @@ -35,7 +34,7 @@ class CommunityListViewModel(communities: ImmutableList<CommunityFollowerView>)
setCommunityListFromFollowed(communities)
}

private fun setCommunityListFromFollowed(myFollows: ImmutableList<CommunityFollowerView>) {
private fun setCommunityListFromFollowed(myFollows: List<CommunityFollowerView>) {
// A hack to convert communityFollowerView into CommunityView
val followsIntoCommunityViews =
myFollows.map { cfv ->
Expand Down Expand Up @@ -72,7 +71,7 @@ class CommunityListViewModel(communities: ImmutableList<CommunityFollowerView>)

companion object {
class Factory(
private val followedCommunities: ImmutableList<CommunityFollowerView>,
private val followedCommunities: List<CommunityFollowerView>,
) : ViewModelProvider.Factory {
@Suppress("UNCHECKED_CAST")
override fun <T : ViewModel> create(
Expand Down
15 changes: 6 additions & 9 deletions app/src/main/java/com/jerboa/model/SiteViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ import it.vercruysse.lemmyapi.v0x19.datatypes.GetSiteResponse
import it.vercruysse.lemmyapi.v0x19.datatypes.GetUnreadCountResponse
import it.vercruysse.lemmyapi.v0x19.datatypes.PersonView
import it.vercruysse.lemmyapi.v0x19.datatypes.SaveUserSettings
import kotlinx.collections.immutable.ImmutableList
import kotlinx.collections.immutable.persistentListOf
import kotlinx.collections.immutable.toImmutableList
import kotlinx.coroutines.Job
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.launch
Expand Down Expand Up @@ -159,17 +156,17 @@ class SiteViewModel(private val accountRepository: AccountRepository) : ViewMode
}
}

fun getFollowList(): ImmutableList<CommunityFollowerView> {
fun getFollowList(): List<CommunityFollowerView> {
return when (val res = siteRes) {
is ApiState.Success -> res.data.my_user?.follows?.toImmutableList() ?: persistentListOf()
else -> persistentListOf()
is ApiState.Success -> res.data.my_user?.follows ?: emptyList()
else -> emptyList()
}
}

fun admins(): ImmutableList<PersonView> {
fun admins(): List<PersonView> {
return when (val res = siteRes) {
is ApiState.Success -> res.data.admins.toImmutableList()
else -> persistentListOf()
is ApiState.Success -> res.data.admins
else -> emptyList()
}
}

Expand Down
23 changes: 10 additions & 13 deletions app/src/main/java/com/jerboa/ui/components/comment/CommentNode.kt
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,6 @@ import com.jerboa.ui.theme.XXL_PADDING
import com.jerboa.ui.theme.colorList
import com.jerboa.ui.theme.muted
import it.vercruysse.lemmyapi.v0x19.datatypes.*
import kotlinx.collections.immutable.ImmutableList
import kotlinx.collections.immutable.persistentListOf
import kotlinx.collections.immutable.toImmutableList

@Composable
fun CommentNodeHeader(
Expand Down Expand Up @@ -174,8 +171,8 @@ fun CommentBodyPreview() {

fun LazyListScope.commentNodeItem(
node: CommentNode,
admins: ImmutableList<PersonView>,
moderators: ImmutableList<CommunityModeratorView>?,
admins: List<PersonView>,
moderators: List<CommunityModeratorView>?,
increaseLazyListIndexTracker: () -> Unit,
addToParentIndexes: () -> Unit,
isFlat: Boolean,
Expand Down Expand Up @@ -386,7 +383,7 @@ fun LazyListScope.commentNodeItem(
}

commentNodeItems(
nodes = node.children.toImmutableList(),
nodes = node.children.toList(),
increaseLazyListIndexTracker = increaseLazyListIndexTracker,
addToParentIndexes = addToParentIndexes,
isFlat = isFlat,
Expand Down Expand Up @@ -429,8 +426,8 @@ fun LazyListScope.commentNodeItem(

fun LazyListScope.missingCommentNodeItem(
node: MissingCommentNode,
admins: ImmutableList<PersonView>,
moderators: ImmutableList<CommunityModeratorView>?,
admins: List<PersonView>,
moderators: List<CommunityModeratorView>?,
increaseLazyListIndexTracker: () -> Unit,
addToParentIndexes: () -> Unit,
isFlat: Boolean,
Expand Down Expand Up @@ -532,7 +529,7 @@ fun LazyListScope.missingCommentNodeItem(
increaseLazyListIndexTracker()

commentNodeItems(
nodes = node.children.toImmutableList(),
nodes = node.children.toList(),
admins = admins,
moderators = moderators,
increaseLazyListIndexTracker = increaseLazyListIndexTracker,
Expand Down Expand Up @@ -669,8 +666,8 @@ fun PostAndCommunityContextHeaderPreview() {
@Composable
fun CommentFooterLine(
commentView: CommentView,
admins: ImmutableList<PersonView>,
moderators: ImmutableList<CommunityModeratorView>?,
admins: List<PersonView>,
moderators: List<CommunityModeratorView>?,
enableDownVotes: Boolean,
instantScores: InstantScores,
onUpvoteClick: () -> Unit,
Expand Down Expand Up @@ -811,8 +808,8 @@ fun CommentNodesPreview() {
val tree = buildCommentsTree(comments, null)
CommentNodes(
nodes = tree,
admins = persistentListOf(),
moderators = persistentListOf(),
admins = emptyList(),
moderators = emptyList(),
increaseLazyListIndexTracker = {},
addToParentIndexes = {},
isFlat = false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,12 @@ import it.vercruysse.lemmyapi.v0x19.datatypes.Person
import it.vercruysse.lemmyapi.v0x19.datatypes.PersonId
import it.vercruysse.lemmyapi.v0x19.datatypes.PersonView
import it.vercruysse.lemmyapi.v0x19.datatypes.PostId
import kotlinx.collections.immutable.ImmutableList

@Composable
fun CommentNodes(
nodes: ImmutableList<CommentNodeData>,
admins: ImmutableList<PersonView>,
moderators: ImmutableList<CommunityModeratorView>?,
nodes: List<CommentNodeData>,
admins: List<PersonView>,
moderators: List<CommunityModeratorView>?,
increaseLazyListIndexTracker: () -> Unit,
addToParentIndexes: () -> Unit,
isFlat: Boolean,
Expand Down Expand Up @@ -113,9 +112,9 @@ fun CommentNodes(
}

fun LazyListScope.commentNodeItems(
nodes: ImmutableList<CommentNodeData>,
admins: ImmutableList<PersonView>,
moderators: ImmutableList<CommunityModeratorView>?,
nodes: List<CommentNodeData>,
admins: List<PersonView>,
moderators: List<CommunityModeratorView>?,
increaseLazyListIndexTracker: () -> Unit,
addToParentIndexes: () -> Unit,
isFlat: Boolean,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ import it.vercruysse.lemmyapi.v0x19.datatypes.PersonId
import it.vercruysse.lemmyapi.v0x19.datatypes.PersonMentionView
import it.vercruysse.lemmyapi.v0x19.datatypes.PersonView
import it.vercruysse.lemmyapi.v0x19.datatypes.PostId
import kotlinx.collections.immutable.ImmutableList

@Composable
fun CommentMentionNodeHeader(
Expand Down Expand Up @@ -97,8 +96,8 @@ fun CommentMentionNodeHeaderPreview() {
@Composable
fun CommentMentionNodeFooterLine(
personMentionView: PersonMentionView,
admins: ImmutableList<PersonView>,
moderators: ImmutableList<CommunityModeratorView>?,
admins: List<PersonView>,
moderators: List<CommunityModeratorView>?,
onUpvoteClick: () -> Unit,
onDownvoteClick: () -> Unit,
onReplyClick: (personMentionView: PersonMentionView) -> Unit,
Expand Down Expand Up @@ -247,8 +246,8 @@ fun CommentMentionNodeFooterLine(
@Composable
fun CommentMentionNode(
personMentionView: PersonMentionView,
admins: ImmutableList<PersonView>,
moderators: ImmutableList<CommunityModeratorView>?,
admins: List<PersonView>,
moderators: List<CommunityModeratorView>?,
onUpvoteClick: (personMentionView: PersonMentionView) -> Unit,
onDownvoteClick: (personMentionView: PersonMentionView) -> Unit,
onReplyClick: (personMentionView: PersonMentionView) -> Unit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import androidx.compose.ui.focus.onFocusChanged
import androidx.compose.ui.layout.boundsInWindow
import androidx.compose.ui.layout.onGloballyPositioned
import androidx.compose.ui.unit.dp
import kotlinx.collections.immutable.ImmutableList

inline fun Modifier.ifDo(
predicate: Boolean,
Expand Down Expand Up @@ -42,7 +41,7 @@ fun Modifier.getBlurredOrRounded(
fun Modifier.onAutofill(
tree: AutofillTree,
autofill: Autofill?,
autofillTypes: ImmutableList<AutofillType>,
autofillTypes: List<AutofillType>,
onFill: (String) -> Unit,
): Modifier {
val autofillNode =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ import it.vercruysse.lemmyapi.v0x19.datatypes.MarkPostAsRead
import it.vercruysse.lemmyapi.v0x19.datatypes.PersonView
import it.vercruysse.lemmyapi.v0x19.datatypes.PostView
import it.vercruysse.lemmyapi.v0x19.datatypes.SavePost
import kotlinx.collections.immutable.toImmutableList

@OptIn(ExperimentalMaterial3Api::class, ExperimentalMaterialApi::class)
@Composable
Expand Down Expand Up @@ -212,15 +211,15 @@ fun CommunityActivity(
val moderators =
remember(communityRes) {
when (communityRes) {
is ApiState.Success -> communityRes.data.moderators.toImmutableList()
is ApiState.Success -> communityRes.data.moderators
else -> {
null
}
}
}

PostListings(
posts = postsRes.data.posts.toImmutableList(),
posts = postsRes.data.posts,
admins = siteViewModel.admins(),
moderators = moderators,
contentAboveListings = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import it.vercruysse.lemmyapi.dto.SearchType
import it.vercruysse.lemmyapi.dto.SortType
import it.vercruysse.lemmyapi.v0x19.datatypes.CommunityFollowerView
import it.vercruysse.lemmyapi.v0x19.datatypes.Search
import kotlinx.collections.immutable.ImmutableList
import kotlinx.coroutines.Job
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
Expand All @@ -41,7 +40,7 @@ object CommunityListReturn {
fun CommunityListActivity(
appState: JerboaAppState,
selectMode: Boolean = false,
followList: ImmutableList<CommunityFollowerView>,
followList: List<CommunityFollowerView>,
blurNSFW: Int,
drawerState: DrawerState,
) {
Expand Down
Loading