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

Make datatypes Parcelable and Stable #1044

Merged
merged 6 commits into from
Jul 17, 2023
Merged

Conversation

MV-GH
Copy link
Collaborator

@MV-GH MV-GH commented Jul 15, 2023

I used v0.18.0 to generate the types it seems to added a few properties. Not sure if I did hot_rank correctly.

This pr makes all the datatypes Parceable and makes the one that weren't stable, stable due to them using List.
This fixes 33 datatypes that were previously unstable.

Example

unstable class MyUserInfo {
  stable val local_user_view: LocalUserView
  unstable val follows: List<CommunityFollowerView>
  unstable val moderates: List<CommunityModeratorView>
  unstable val community_blocks: List<CommunityBlockView>
  unstable val person_blocks: List<PersonBlockView>
  unstable val discussion_languages: List<Int{ com.jerboa.datatypes.types.LanguageId }>
  <runtime stability> = Unstable
}

unstable class PictrsImages {
  stable val msg: String
  unstable val files: List<PictrsImage>?
  <runtime stability> = Unstable
}

after

stable class MyUserInfo {
  stable val local_user_view: LocalUserView
  unstable val follows: List<CommunityFollowerView>
  unstable val moderates: List<CommunityModeratorView>
  unstable val community_blocks: List<CommunityBlockView>
  unstable val person_blocks: List<PersonBlockView>
  unstable val discussion_languages: List<Int{ com.jerboa.datatypes.types.LanguageId }>
}

stable class PictrsImages {
  stable val msg: String
  unstable val files: List<PictrsImage>?
}

Fixes #810

@nahwneeth not sure for what you needed them Parcelable though

@nahwneeth
Copy link
Contributor

https://github.com/dessalines/jerboa/blob/main/app/src/main/java/com/jerboa/ui/components/common/Navigation.kt#L54

If the object is parcelable, then here rememberSaveable can be used directly (no need to manually convert to json).

@MV-GH
Copy link
Collaborator Author

MV-GH commented Jul 17, 2023

@nahwneeth

I took a stab at replacing it but it does not work with nullable types.
How would I solve this

inline fun <reified D : Parcelable?> NavController.takeDepsFromRoot(): State<D> {
    val deps = rootChannel<D>().take()

    // This will survive process death
    val depsSaved = rememberSaveable { deps!! }

    // After process death, deps will be null
    return remember(depsSaved) {
        derivedStateOf {
            deps ?: depsSaved
        }
    }
}

@nahwneeth
Copy link
Contributor

I think a null check will solve this. If the deps is null, then it'll be null anyway after process death also.

@MV-GH
Copy link
Collaborator Author

MV-GH commented Jul 17, 2023

Yes but for a non nullable on process death, rootChannel<D>().take() will also return null in which case it has to return the savedDeps. How do I differentiate the two.

@nahwneeth
Copy link
Contributor

nahwneeth commented Jul 17, 2023

oh okay, I see. Can we make D non-nullable and return State<D?>

Edit: I think we can make D non-nullable and return State< D > itself. I don't see how the returned type would be nullable tbh.

@MV-GH
Copy link
Collaborator Author

MV-GH commented Jul 17, 2023

How would that work for nullable types? Currently we have one, createPost has Community? which returns the community if created from a CommunityActivity otherwise null.

@nahwneeth
Copy link
Contributor

I didn't expect nullability to be a problem tbh. Ig we need to create a wrapper for that which contains a Community? within it. Removing one hack is requiring another. smh.

@MV-GH
Copy link
Collaborator Author

MV-GH commented Jul 17, 2023

Alright, I ll make a separate issue for this and keep takeDepsFromRoot as is.

@twizmwazin twizmwazin enabled auto-merge (squash) July 17, 2023 20:14
@twizmwazin twizmwazin merged commit f1e4cab into LemmyNet:main Jul 17, 2023
@MV-GH MV-GH deleted the feat/parcelize branch July 17, 2023 20:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make autogen types extend Parcelable or Serializable
4 participants