Skip to content

Commit

Permalink
progress
Browse files Browse the repository at this point in the history
  • Loading branch information
YohannesTz committed Nov 3, 2022
1 parent 8c38153 commit d8d8eeb
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 20 deletions.
5 changes: 3 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ dependencies {
kapt "androidx.hilt:hilt-compiler:1.0.0"

//firebase
implementation 'com.google.firebase:firebase-crashlytics:18.3.0'
implementation 'com.google.firebase:firebase-crashlytics:18.3.1'
implementation 'com.google.firebase:firebase-analytics:21.2.0'
implementation 'com.google.firebase:firebase-messaging-ktx:23.1.0'

Expand All @@ -102,8 +102,9 @@ dependencies {
//youtube library
implementation files('libs/YouTubeAndroidPlayerApi.jar')

//expandable textview
//expandable textview and time ago
implementation 'io.github.glailton.expandabletextview:expandabletextview:1.0.2'
implementation 'com.github.marlonlom:timeago:4.0.3'

testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.yohannes.dev.app.okami.adapters

import android.annotation.SuppressLint
import android.os.Build
import android.text.Html
import android.util.Log
Expand All @@ -9,8 +10,12 @@ import androidx.paging.PagingDataAdapter
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.RecyclerView
import coil.load
import com.github.marlonlom.utilities.timeago.TimeAgo
import com.github.yohannestz.kraw.models.PostData
import com.yohannes.dev.app.okami.databinding.PostListingItemBinding
import java.text.DateFormat
import java.text.SimpleDateFormat
import java.util.*

class PostPagedAdapter: PagingDataAdapter<PostData, PostPagedAdapter.PostViewHolder>(diffCallback) {

Expand All @@ -19,7 +24,7 @@ class PostPagedAdapter: PagingDataAdapter<PostData, PostPagedAdapter.PostViewHo
companion object {
val diffCallback = object : DiffUtil.ItemCallback<PostData>() {
override fun areItemsTheSame(oldItem: PostData, newItem: PostData): Boolean {
return oldItem == newItem
return oldItem.postId == newItem.postId
}

override fun areContentsTheSame(oldItem: PostData, newItem: PostData): Boolean {
Expand All @@ -28,20 +33,42 @@ class PostPagedAdapter: PagingDataAdapter<PostData, PostPagedAdapter.PostViewHo
}
}

@SuppressLint("SimpleDateFormat", "SetTextI18n")
override fun onBindViewHolder(holder: PostViewHolder, position: Int) {
val currentItem = getItem(position)
val post = currentItem?.post
val user = currentItem?.user
holder.binding.postContent.text = currentItem.toString()
Log.e("holder-binder", currentItem.toString())
holder.binding.postItemUserName.text = user?.name
holder.binding.postItemTimeStamp.text = post?.createdAt
holder.binding.postItemUserProfile.load(user?.coverImage?.tiny) {
crossfade(true)
crossfade(500)
}

holder.binding.postContent.text = post?.content
holder.binding.apply {
postItemUserName.text = user?.name

try {
val formatter: DateFormat = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'")
formatter.timeZone = TimeZone.getTimeZone("UTC");
val date: Date = post?.createdAt?.let { formatter.parse(it) } as Date
val output: Long = date.time / 1000L
val str = output.toString()
val timestamp = str.toLong() * 1000
postItemTimeStamp.text = TimeAgo.using(timestamp);
} catch (ex: Exception) {
ex.printStackTrace()
postItemTimeStamp.text = post?.createdAt.toString()
}

postLikesCount.text = "${post?.postLikesCount.toString()} Likes"
postCommentsCount.text = "${post?.commentsCount.toString()} Comments"

postContent.text = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
Html.fromHtml(post?.contentFormatted, Html.FROM_HTML_MODE_COMPACT)
} else {
Html.fromHtml(post?.contentFormatted)
}
postItemUserProfile.load(user?.coverImage?.tiny) {
crossfade(true)
crossfade(500)
}
}
}

override fun onCreateViewHolder(
Expand Down
39 changes: 34 additions & 5 deletions app/src/main/res/layout/post_listing_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
android:layout_height="wrap_content"
android:layout_margin="5dp"
app:cardCornerRadius="8dp"
card_view:cardElevation="5dp">
card_view:cardElevation="2dp">

<LinearLayout
android:layout_width="match_parent"
Expand Down Expand Up @@ -62,8 +62,6 @@
android:layout_marginTop="16dp"
android:textSize="16sp"
android:textColor="#546E7A"
tools:style=""
style="@style/Text.Clickable.Borderless"
expandableTextView:animDuration="500"
expandableTextView:collapsedLines="4"
expandableTextView:isExpanded="false"
Expand All @@ -72,13 +70,42 @@
expandableTextView:textMode="line"
tools:text="@string/long_text" />

<LinearLayout
android:paddingTop="8dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<TextView
android:id="@+id/postLikesCount"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Likes"
android:textSize="16sp"
android:textAllCaps="false"
app:iconTint="@color/black" />

<TextView
android:id="@+id/postCommentsCount"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Comments"
android:gravity="end"
android:textSize="16sp"
android:textAllCaps="false"
app:iconTint="@color/black" />

</LinearLayout>

<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="16dp"
android:layout_marginBottom="4dp"
android:background="#F5DCDCDC" />


<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
Expand All @@ -87,7 +114,8 @@
android:id="@+id/postItemLikeButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/Widget.AppCompat.Button.Borderless.Colored"
tools:style=""
style="@style/ClickableButton"
android:layout_weight="1"
android:text="Like"
android:textSize="16sp"
Expand All @@ -97,12 +125,13 @@

<TextView
android:id="@+id/postItemCommentButton"
style="@style/Widget.AppCompat.Button.Borderless.Colored"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Comment"
android:textSize="16sp"
tools:style=""
style="@style/ClickableButton"
android:textAllCaps="false"
app:iconTint="@color/black"
app:icon="@drawable/ic_baseline_favorite_border" />
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@
<item name="android:focusable">true</item>
</style>

<style name="ClickableButton" parent="Widget.AppCompat.Button.Borderless.Colored">
<item name="android:background">?attr/selectableItemBackgroundBorderless</item>
<item name="android:clickable">true</item>
<item name="android:focusable">true</item>
</style>

<!-- ImageView -->
<style name="Image.Clickable" parent="ThemeOverlay.AppCompat">
<item name="android:background">?attr/selectableItemBackground</item>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -408,15 +408,14 @@ open class KitsuClient {
@Provides
open suspend fun getPosts(offset: Int): List<PostData>? {
val response = kitsuApiService.getPostList(offset = offset, include = "user")
Log.e("postRes", response.body().toString())
val postDataList = mutableListOf<PostData>()
val body = response.body() as PostCollection
val includedList = body.included
val dataList = body.data

for (user in includedList) {
val post = dataList[includedList.indexOf(user)]
postDataList.add(PostData(post = post.post, user = user))
postDataList.add(PostData(post = post.attributes, user = user.attributes, postId = post.id, userId = user.id))
}

Log.e("postDataList", postDataList.toString())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.github.yohannestz.kraw.models
import com.squareup.moshi.Json
import java.io.Serializable

@Json(name = "attributes")
data class Post(
val createdAt: String?,
val updatedAt: String?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,19 @@ data class PostCollection(
@Json(name = "data")
val data: List<PostChild>,
@Json(name = "included")
val included: List<User>
val included: List<UserChild>
): Serializable

data class PostChild(
val id: String?,
val type: String?,
@Json(name = "attributes")
val post: Post
val attributes: Post?
): Serializable

data class UserChild(
val id: String?,
val type: String?,
@Json(name = "attributes")
val attributes: User?
)
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.github.yohannestz.kraw.models

data class PostData(
val postId: String?,
val post: Post?,
val userId: String?,
val user: User?
)

0 comments on commit d8d8eeb

Please sign in to comment.