@@ -136,6 +136,8 @@ fun PostComposable(
136136
137137 val context = LocalContext .current
138138
139+ var postId by remember { mutableStateOf(post.id) }
140+
139141 val sheetState = rememberModalBottomSheetState()
140142 var showBottomSheet by remember {
141143 mutableIntStateOf(
@@ -147,14 +149,15 @@ fun PostComposable(
147149 )
148150 }
149151
150-
151-
152152 DisposableEffect (post.createdAt) {
153153 viewModel.convertTime(post.createdAt)
154154 onDispose {}
155155 }
156156
157157 LaunchedEffect (Unit ) {
158+ if (post.reblogId != null ) {
159+ postId = post.reblogId
160+ }
158161 if (viewModel.post == null ) {
159162 viewModel.updatePost(post)
160163 }
@@ -174,15 +177,10 @@ fun PostComposable(
174177
175178 LaunchedEffect (openReplies) {
176179 if (openReplies) {
177- if (viewModel.post!! .rebloggedBy != null ) {
178- viewModel.loadReplies(
179- viewModel.post?.reblogId ? : " "
180- )
181- } else {
182- viewModel.loadReplies(
183- viewModel.post!! .id
184- )
185- }
180+ viewModel.loadReplies(
181+ postId
182+ )
183+
186184 }
187185 }
188186
@@ -196,24 +194,21 @@ fun PostComposable(
196194 720f
197195 } else {
198196 0f
199- },
200- animationSpec = tween(durationMillis = 800 , easing = EaseInOut )
197+ }, animationSpec = tween(durationMillis = 800 , easing = EaseInOut )
201198 )
202199
203200
204201 var animateHeart by remember { mutableStateOf(false ) }
205- val heartScale by animateFloatAsState(
206- targetValue = if (animateHeart) 1.3f else 1f ,
202+ val heartScale by animateFloatAsState(targetValue = if (animateHeart) 1.3f else 1f ,
207203 animationSpec = tween(durationMillis = 200 , easing = LinearEasing ),
208204 finishedListener = {
209205 animateHeart = false
210- }
211- )
206+ })
212207
213208 if (viewModel.post != null ) {
214209 Column (modifier = modifier) {
215210
216- post.rebloggedBy?.let {reblogAccount ->
211+ post.rebloggedBy?.let { reblogAccount ->
217212 Row (
218213 verticalAlignment = Alignment .CenterVertically ,
219214 horizontalArrangement = Arrangement .spacedBy(8 .dp),
@@ -226,7 +221,12 @@ fun PostComposable(
226221 })
227222 ) {
228223 Icon (Icons .Outlined .Cached , contentDescription = " reblogged by" )
229- Text (stringResource(R .string.reblogged_by, reblogAccount.displayname ? : reblogAccount.username), fontSize = 12 .sp)
224+ Text (
225+ stringResource(
226+ R .string.reblogged_by,
227+ reblogAccount.displayname ? : reblogAccount.username
228+ ), fontSize = 12 .sp
229+ )
230230 }
231231 }
232232
@@ -355,13 +355,11 @@ fun PostComposable(
355355 .zIndex(10f )
356356 .padding(start = 12 .dp, end = 12 .dp)
357357 ) {
358- PostImage (
359- mediaAttachment = viewModel.post!! .mediaAttachments[page],
360- viewModel.post!! .id,
358+ PostImage (mediaAttachment = viewModel.post!! .mediaAttachments[page],
359+ postId,
361360 setZindex = { setZindex(it) },
362361 viewModel,
363- like = {animateHeart = true }
364- )
362+ like = { animateHeart = true })
365363 }
366364 }
367365
@@ -408,26 +406,26 @@ fun PostComposable(
408406 .zIndex(10f )
409407 .padding(start = 12 .dp, end = 12 .dp)
410408 ) {
411- PostImage (
412- mediaAttachment = viewModel.post!! .mediaAttachments[0 ],
413- viewModel.post!! .id,
409+ PostImage (mediaAttachment = viewModel.post!! .mediaAttachments[0 ],
410+ postId,
414411 setZindex = { setZindex(it) },
415412 viewModel,
416- like = {animateHeart = true }
417- )
413+ like = { animateHeart = true })
418414 }
419415 }
420416 }
421417 } else {
422418 if (viewModel.post!! .content.isNotBlank()) {
423419 Column (Modifier .padding(start = 16 .dp, top = 8 .dp, end = 16 .dp)) {
424420 HorizontalDivider ()
425- HashtagsMentionsTextView (text = viewModel.post!! .content,
421+ HashtagsMentionsTextView (
422+ text = viewModel.post!! .content,
426423 mentions = viewModel.post!! .mentions,
427424 navController = navController,
428425 textSize = 18 .sp,
429426 openUrl = { url -> viewModel.openUrl(context, url) },
430- modifier = Modifier .padding(top = 16 .dp, bottom = 16 .dp))
427+ modifier = Modifier .padding(top = 16 .dp, bottom = 16 .dp)
428+ )
431429 HorizontalDivider ()
432430 }
433431 }
@@ -442,24 +440,23 @@ fun PostComposable(
442440
443441 Row (verticalAlignment = Alignment .CenterVertically ) {
444442 if (viewModel.post!! .favourited) {
445- Icon (
446- imageVector = Icons .Filled .Favorite ,
443+ Icon (imageVector = Icons .Filled .Favorite ,
447444 modifier = Modifier
448445 .size(24 .dp)
449446 .clickable {
450- viewModel.unlikePost(viewModel.post!! .id)
451- }.scale(heartScale),
447+ viewModel.unlikePost(postId)
448+ }
449+ .scale(heartScale),
452450 contentDescription = " unlike post" ,
453- tint = Color (0xFFDD2E44 )
454- )
451+ tint = Color (0xFFDD2E44 ))
455452 } else {
456453 Icon (
457454 imageVector = Icons .Outlined .FavoriteBorder ,
458455 modifier = Modifier
459456 .size(24 .dp)
460457 .clickable {
461458 animateHeart = true
462- viewModel.likePost(viewModel.post !! .id )
459+ viewModel.likePost(postId )
463460 },
464461 contentDescription = " like post"
465462 )
@@ -481,15 +478,9 @@ fun PostComposable(
481478 modifier = Modifier
482479 .size(24 .dp)
483480 .clickable {
484- if (viewModel.post!! .rebloggedBy != null ) {
485- viewModel.loadReplies(
486- viewModel.post?.reblogId ? : " "
487- )
488- } else {
489- viewModel.loadReplies(
490- viewModel.post!! .id
491- )
492- }
481+ viewModel.loadReplies(
482+ postId
483+ )
493484 showBottomSheet = 1
494485 },
495486 contentDescription = " comments of post"
@@ -510,7 +501,7 @@ fun PostComposable(
510501
511502 if (viewModel.post!! .reblogged) {
512503 IconButton (onClick = {
513- viewModel.unreblogPost(viewModel.post !! .id )
504+ viewModel.unreblogPost(postId )
514505 }) {
515506 Icon (
516507 imageVector = Icons .Outlined .Cached ,
@@ -522,7 +513,7 @@ fun PostComposable(
522513 } else {
523514 IconButton (onClick = {
524515 animateBoost = true
525- viewModel.reblogPost(viewModel.post !! .id )
516+ viewModel.reblogPost(postId )
526517 }) {
527518 Icon (
528519 imageVector = Icons .Outlined .Cached ,
@@ -535,15 +526,16 @@ fun PostComposable(
535526
536527 if (viewModel.post!! .bookmarked) {
537528 IconButton (onClick = {
538- viewModel.unBookmarkPost(post.id )
529+ viewModel.unBookmarkPost(postId )
539530 }) {
540531 Icon (
541- imageVector = Icons .Filled .Bookmark , contentDescription = " unbookmark post"
532+ imageVector = Icons .Filled .Bookmark ,
533+ contentDescription = " unbookmark post"
542534 )
543535 }
544536 } else {
545537 IconButton (onClick = {
546- viewModel.bookmarkPost(post.id )
538+ viewModel.bookmarkPost(postId )
547539 }) {
548540 Icon (
549541 imageVector = Icons .Outlined .BookmarkBorder ,
@@ -576,7 +568,7 @@ fun PostComposable(
576568 fontWeight = FontWeight .Bold ,
577569 fontSize = 14 .sp,
578570 modifier = Modifier .clickable {
579- viewModel.loadLikedBy(post.id )
571+ viewModel.loadLikedBy(postId )
580572 showBottomSheet = 3
581573 })
582574 }
@@ -605,15 +597,9 @@ fun PostComposable(
605597 ),
606598 color = MaterialTheme .colorScheme.onSurfaceVariant,
607599 modifier = Modifier .clickable {
608- if (viewModel.post!! .rebloggedBy != null ) {
609- viewModel.loadReplies(
610- viewModel.post?.reblogId ? : " "
611- )
612- } else {
613- viewModel.loadReplies(
614- viewModel.post!! .id
615- )
616- }
600+ viewModel.loadReplies(
601+ postId
602+ )
617603 showBottomSheet = 1
618604 })
619605 }
0 commit comments