This repository has been archived by the owner on Aug 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Aayush Gupta <[email protected]>
- Loading branch information
1 parent
744652d
commit 6e18225
Showing
17 changed files
with
502 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
app/src/main/java/io/aayush/relabs/network/data/post/Attachment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package io.aayush.relabs.network.data.post | ||
|
||
data class Attachment( | ||
val attach_date: Int = 0, | ||
val attachment_id: Int = 0, | ||
val content_id: Int = 0, | ||
val content_type: String = String(), | ||
val direct_url: String = String(), | ||
val file_size: Int = 0, | ||
val filename: String = String(), | ||
val height: Int = 0, | ||
val is_audio: Boolean = false, | ||
val is_video: Boolean = false, | ||
val thumbnail_url: String = String(), | ||
val view_count: Int = 0, | ||
val width: Int = 0 | ||
) |
31 changes: 31 additions & 0 deletions
31
app/src/main/java/io/aayush/relabs/network/data/post/Post.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package io.aayush.relabs.network.data.post | ||
|
||
import io.aayush.relabs.network.data.user.User | ||
|
||
data class Post( | ||
val Attachments: List<Attachment> = emptyList(), | ||
val User: User = User(), | ||
val attach_count: Int = 0, | ||
val can_edit: Boolean = false, | ||
val can_hard_delete: Boolean = false, | ||
val can_react: Boolean = false, | ||
val can_soft_delete: Boolean = false, | ||
val can_view_attachments: Boolean = false, | ||
val is_first_post: Boolean = false, | ||
val is_last_post: Boolean = false, | ||
val is_reacted_to: Boolean = false, | ||
val is_unread: Boolean = false, | ||
val last_edit_date: Int = 0, | ||
val message: String = String(), | ||
val message_parsed: String = String(), | ||
val message_state: String = String(), | ||
val position: Int = 0, | ||
val post_date: Int = 0, | ||
val post_id: Int = 0, | ||
val reaction_score: Int = 0, | ||
val thread_id: Int = 0, | ||
val user_id: Int = 0, | ||
val username: String = String(), | ||
val view_url: String = String(), | ||
val warning_message: String = String() | ||
) |
10 changes: 10 additions & 0 deletions
10
app/src/main/java/io/aayush/relabs/network/data/thread/ThreadInfo.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package io.aayush.relabs.network.data.thread | ||
|
||
import io.aayush.relabs.network.data.common.Pagination | ||
import io.aayush.relabs.network.data.post.Post | ||
|
||
data class ThreadInfo( | ||
val pagination: Pagination = Pagination(), | ||
val posts: List<Post> = emptyList(), | ||
val thread: Thread = Thread() | ||
) |
143 changes: 143 additions & 0 deletions
143
app/src/main/java/io/aayush/relabs/ui/components/PostItem.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
package io.aayush.relabs.ui.components | ||
|
||
import android.os.Build | ||
import android.text.format.DateUtils | ||
import android.text.util.Linkify | ||
import androidx.compose.foundation.background | ||
import androidx.compose.foundation.isSystemInDarkTheme | ||
import androidx.compose.foundation.layout.Arrangement | ||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.Row | ||
import androidx.compose.foundation.layout.Spacer | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.foundation.layout.requiredSize | ||
import androidx.compose.foundation.layout.width | ||
import androidx.compose.foundation.shape.CircleShape | ||
import androidx.compose.foundation.shape.RoundedCornerShape | ||
import androidx.compose.material3.MaterialTheme | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.draw.clip | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.graphics.toArgb | ||
import androidx.compose.ui.layout.ContentScale | ||
import androidx.compose.ui.platform.LocalContext | ||
import androidx.compose.ui.text.font.FontWeight | ||
import androidx.compose.ui.unit.dp | ||
import androidx.compose.ui.unit.sp | ||
import androidx.compose.ui.viewinterop.AndroidView | ||
import androidx.core.text.HtmlCompat | ||
import coil.ImageLoader | ||
import coil.compose.SubcomposeAsyncImage | ||
import coil.decode.GifDecoder | ||
import coil.decode.ImageDecoderDecoder | ||
import coil.request.ImageRequest | ||
import com.google.android.material.textview.MaterialTextView | ||
import io.aayush.relabs.R | ||
import io.aayush.relabs.network.data.post.Post | ||
import io.aayush.relabs.utils.DesignQuoteSpan | ||
import io.aayush.relabs.utils.LinkTransformationMethod | ||
import io.aayush.relabs.utils.formatBlockQuotes | ||
import java.util.Date | ||
|
||
@Composable | ||
fun PostItem( | ||
modifier: Modifier, | ||
post: Post, | ||
linkTransformationMethod: LinkTransformationMethod, | ||
designQuoteSpan: DesignQuoteSpan, | ||
onClicked: () -> Unit = {} | ||
) { | ||
Box( | ||
modifier = modifier | ||
.fillMaxWidth() | ||
.clip(RoundedCornerShape(10.dp)) | ||
.background( | ||
color = if (isSystemInDarkTheme()) { | ||
MaterialTheme.colorScheme.onSecondary | ||
} else { | ||
MaterialTheme.colorScheme.secondary | ||
} | ||
) | ||
) { | ||
Column( | ||
modifier = Modifier.padding(10.dp), | ||
verticalArrangement = Arrangement.spacedBy(10.dp, Alignment.Top), | ||
horizontalAlignment = Alignment.Start | ||
) { | ||
Row( | ||
verticalAlignment = Alignment.CenterVertically, | ||
horizontalArrangement = Arrangement.Start | ||
) { | ||
SubcomposeAsyncImage( | ||
model = ImageRequest.Builder(LocalContext.current) | ||
.data(post.User.avatar_urls.values.first() ?: R.drawable.ic_account) | ||
.placeholder(R.drawable.ic_account) | ||
.crossfade(true) | ||
.build(), | ||
imageLoader = ImageLoader.Builder(LocalContext.current) | ||
.components { | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { | ||
add(ImageDecoderDecoder.Factory()) | ||
} else { | ||
add(GifDecoder.Factory()) | ||
} | ||
}.build(), | ||
contentDescription = "", | ||
contentScale = ContentScale.Crop, | ||
modifier = Modifier | ||
.requiredSize(64.dp) | ||
.clip(CircleShape) | ||
) | ||
Spacer(modifier = Modifier.width(10.dp)) | ||
Column( | ||
verticalArrangement = Arrangement.Top, | ||
horizontalAlignment = Alignment.Start | ||
) { | ||
Text( | ||
text = post.User.username, | ||
fontSize = 15.sp, | ||
fontWeight = FontWeight.Bold, | ||
color = Color.White | ||
) | ||
Text(text = post.User.user_title, fontSize = 13.sp, color = Color.White) | ||
Text( | ||
text = DateUtils.getRelativeTimeSpanString( | ||
post.post_date.toLong() * 1000L, | ||
Date().time, | ||
DateUtils.MINUTE_IN_MILLIS | ||
).toString(), | ||
fontSize = 12.sp, | ||
fontWeight = FontWeight.Light, | ||
color = Color.White | ||
) | ||
} | ||
} | ||
AndroidView( | ||
modifier = modifier, | ||
factory = { | ||
MaterialTextView(it).apply { | ||
autoLinkMask = Linkify.WEB_URLS | ||
linksClickable = true | ||
transformationMethod = linkTransformationMethod | ||
setLinkTextColor(Color.White.toArgb()) | ||
} | ||
}, | ||
update = { | ||
it.setTextColor(Color.White.toArgb()) | ||
it.text = HtmlCompat.fromHtml( | ||
post.message_parsed | ||
// XenForo doesn't applies line break after quote while vbulletin did | ||
.replace("</blockquote>", "</blockquote><br />") | ||
.replace("</blockquote><br /><br />", "</blockquote><br />"), | ||
HtmlCompat.FROM_HTML_MODE_COMPACT | ||
).formatBlockQuotes(designQuoteSpan) | ||
} | ||
) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.