Hey all, I want to show the title, author, and background image. Display it on a card. I can log out the data but do not know how to display it on the screen. Can I get some help please. Also using compose
internal class BlogPostRepositoryImpl(
private val remoteBlogPostDataSource: BlogPostDataSource
) : BlogPostRepository {
override suspend fun getFeaturedPost(): NetworkResult<PostItemFragment> {
return try {
val response = remoteBlogPostDataSource.getFeaturedPost()
if (response != null) {
NetworkResult.Success(response.postItemFragment)
} else {
NetworkResult.Failure(NetworkError(type = NetworkErrorType.NOT_FOUND))
}
} catch (ex: Exception) {
NetworkResult.handleException(ex)
}
}
}
class BlogPostUseCases(
private val blogPostRepository: BlogPostRepository
) {
suspend fun getFeaturedPost(): NetworkResult<PostItemFragment> {
return blogPostRepository.getFeaturedPost()
}
// TODO: Implement Paging and caching for retrieved posts.
suspend fun getAllPosts(blogPostPaging: BlogPostPaging): NetworkResult<List<GetBlogPostsQuery.Item?>?> {
return blogPostRepository.getAllPosts(blogPostPaging)
}
suspend fun getPostById(id: String): NetworkResult<PostItemFragment> {
return blogPostRepository.getPostById(id)
}
}
class HomeViewModel() : ViewModel(), KoinComponent {
private val userUseCases: UserUseCases by inject()
private val blogPostUseCases: BlogPostUseCases by inject()
val user = userUseCases.loggedInUserName
fun getFeaturedArticle() {
viewModelScope.launch {
blogPostUseCases.getFeaturedPost()
Log.i("debug", "featured: ${blogPostUseCases.getFeaturedPost()}")
}
}
}
public data class PostItemFragment(
public val color: String?,
public val featured: Boolean?,
public val name: String?,
public val postBody: String?,
public val postSummary: String?,
public val title: String?,
public val thumbnailImage: ThumbnailImage?,
public val mainImage: MainImage?,
public val createdOn: Any?,
public val createdBy: String?,
public val publishedOn: Any?,
public val publishedBy: String?,
public val author: Author?
) : Fragment.Data {
public data class ThumbnailImage(
public val fileId: String?,
public val url: String?
)
public data class MainImage(
public val fileId: String?,
public val url: String?
)
public data class Author(
public val avatar: String?,
public val name: String?,
public val id: String?
)
}
query GetFeaturedBlogPost {
getFeaturedBlogPost {
...postItemFragment
}
}