-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
402 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
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
85 changes: 85 additions & 0 deletions
85
app/src/main/java/io/github/a13e300/ro_tieba/api/json/UserPostResponse.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,85 @@ | ||
package io.github.a13e300.ro_tieba.api.json | ||
|
||
import com.google.gson.annotations.JsonAdapter | ||
import com.google.gson.annotations.SerializedName | ||
import io.github.a13e300.ro_tieba.api.adapters.IntBooleanAdapter | ||
import io.github.a13e300.ro_tieba.api.adapters.IntStringAdapter | ||
|
||
data class UserPostResponse( | ||
@JsonAdapter(IntBooleanAdapter::class) | ||
@SerializedName("hide_post") | ||
val hidePost: Boolean, | ||
@SerializedName("post_list") | ||
val postList: List<Post> // post for each forum | ||
) { | ||
data class Post( | ||
val content: List<Content>, | ||
@SerializedName("forum_id") | ||
@JsonAdapter(IntStringAdapter::class) | ||
val forumId: Long, | ||
@SerializedName("forum_name") | ||
val forumName: String, | ||
@JsonAdapter(IntStringAdapter::class) | ||
@SerializedName("freq_num") | ||
val freqNum: Int, | ||
@JsonAdapter(IntBooleanAdapter::class) | ||
@SerializedName("is_thread") | ||
val isThread: Boolean, | ||
@JsonAdapter(IntStringAdapter::class) | ||
@SerializedName("thread_id") | ||
val threadId: Long, | ||
@JsonAdapter(IntStringAdapter::class) | ||
@SerializedName("thread_type") | ||
val threadType: Int, | ||
val title: String, | ||
@JsonAdapter(IntStringAdapter::class) | ||
@SerializedName("reply_num") | ||
val replyNum: Int, | ||
@JsonAdapter(IntStringAdapter::class) | ||
@SerializedName("create_time") | ||
val createTime: Long, | ||
val quota: Quota? | ||
// user_id, user_name, user_portrait are useless | ||
) | ||
|
||
data class Content( | ||
@JsonAdapter(IntStringAdapter::class) | ||
@SerializedName("post_id") | ||
val postId: Long, | ||
@JsonAdapter(IntStringAdapter::class) | ||
@SerializedName("post_type") | ||
val postType: Int, // 0 -> floor, 1 -> floor in floor (has quota) | ||
@SerializedName("post_content") | ||
val postContent: List<PostContent> | ||
) | ||
|
||
data class PostContent( | ||
val type: String, | ||
val text: String, | ||
@JsonAdapter(IntStringAdapter::class) | ||
val uid: Long?, | ||
val bsize: String?, // w,h | ||
val src: String? | ||
) | ||
|
||
data class Quota( | ||
val content: String, | ||
@JsonAdapter(IntStringAdapter::class) | ||
@SerializedName("post_id") | ||
val postId: Long, | ||
@JsonAdapter(IntStringAdapter::class) | ||
@SerializedName("user_id") | ||
val userId: Long, | ||
@SerializedName("user_name") | ||
val userName: String | ||
) | ||
|
||
data class PrivSets( | ||
@JsonAdapter(IntStringAdapter::class) | ||
val like: Int?, | ||
@JsonAdapter(IntStringAdapter::class) | ||
val location: Int?, | ||
@JsonAdapter(IntStringAdapter::class) | ||
val post: Int? | ||
) | ||
} |
22 changes: 22 additions & 0 deletions
22
app/src/main/java/io/github/a13e300/ro_tieba/models/Reply.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,22 @@ | ||
package io.github.a13e300.ro_tieba.models | ||
|
||
import java.util.Date | ||
|
||
data class Reply( | ||
val content: List<Content>, | ||
val pid: Long, | ||
val comment: Boolean, | ||
val quota: QuotaInfo?, | ||
val threadId: Long, | ||
val threadTitle: String, | ||
val time: Date, | ||
val forumId: Long, | ||
val forumName: String | ||
) { | ||
data class QuotaInfo( | ||
val pid: Long, | ||
val uid: Long, | ||
val username: String, | ||
val content: String | ||
) | ||
} |
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
97 changes: 97 additions & 0 deletions
97
app/src/main/java/io/github/a13e300/ro_tieba/ui/profile/ProfileReplyFragment.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,97 @@ | ||
package io.github.a13e300.ro_tieba.ui.profile | ||
|
||
import android.os.Bundle | ||
import android.text.SpannableStringBuilder | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import androidx.core.view.isVisible | ||
import androidx.fragment.app.Fragment | ||
import androidx.fragment.app.viewModels | ||
import androidx.lifecycle.lifecycleScope | ||
import androidx.navigation.fragment.findNavController | ||
import androidx.paging.LoadState | ||
import androidx.paging.PagingDataAdapter | ||
import androidx.recyclerview.widget.DiffUtil | ||
import androidx.recyclerview.widget.LinearLayoutManager | ||
import androidx.recyclerview.widget.RecyclerView | ||
import io.github.a13e300.ro_tieba.MobileNavigationDirections | ||
import io.github.a13e300.ro_tieba.R | ||
import io.github.a13e300.ro_tieba.databinding.FragmentProfileReplyBinding | ||
import io.github.a13e300.ro_tieba.databinding.FragmentProfileReplyItemBinding | ||
import io.github.a13e300.ro_tieba.models.Reply | ||
import io.github.a13e300.ro_tieba.utils.appendSimpleContent | ||
import io.github.a13e300.ro_tieba.utils.toSimpleString | ||
import kotlinx.coroutines.launch | ||
|
||
class ProfileReplyFragment : Fragment() { | ||
private val viewModel: ProfileViewModel by viewModels({ requireParentFragment() }) | ||
private lateinit var binding: FragmentProfileReplyBinding | ||
|
||
override fun onCreateView( | ||
inflater: LayoutInflater, | ||
container: ViewGroup?, | ||
savedInstanceState: Bundle? | ||
): View { | ||
binding = FragmentProfileReplyBinding.inflate(inflater, container, false) | ||
val replyAdapter = ReplyAdapter(ReplyComparator) | ||
replyAdapter.addLoadStateListener { state -> | ||
binding.resultTips.isVisible = | ||
state.append is LoadState.NotLoading && state.append.endOfPaginationReached && replyAdapter.itemCount == 0 | ||
binding.resultTips.text = | ||
if (viewModel.postHidden) getString(R.string.user_replies_hidden) | ||
else getString(R.string.user_replies_empty) | ||
} | ||
binding.threadList.adapter = replyAdapter | ||
binding.threadList.layoutManager = LinearLayoutManager(requireContext()) | ||
lifecycleScope.launch { | ||
viewModel.repliesFlow.collect { | ||
replyAdapter.submitData(it) | ||
} | ||
} | ||
return binding.root | ||
} | ||
|
||
inner class ReplyAdapter( | ||
diffCallback: DiffUtil.ItemCallback<Reply> | ||
) : PagingDataAdapter<Reply, ReplyAdapter.ReplyViewHolder>(diffCallback) { | ||
inner class ReplyViewHolder(val binding: FragmentProfileReplyItemBinding) : | ||
RecyclerView.ViewHolder(binding.root) | ||
|
||
override fun onBindViewHolder(holder: ReplyViewHolder, position: Int) { | ||
val t = getItem(position) ?: return | ||
holder.binding.threadTitle.text = t.threadTitle | ||
holder.binding.threadInfo.text = "${t.time.toSimpleString()} ${t.forumName}吧" | ||
holder.binding.threadContent.text = | ||
SpannableStringBuilder().appendSimpleContent(t.content, requireContext()) | ||
holder.binding.root.setOnClickListener { | ||
val pid = if (t.comment) { | ||
t.quota?.pid ?: 0L | ||
} else t.pid | ||
findNavController().navigate( | ||
MobileNavigationDirections.goToThread(t.threadId).setPid(pid) | ||
) | ||
} | ||
} | ||
|
||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ReplyViewHolder { | ||
return ReplyViewHolder( | ||
FragmentProfileReplyItemBinding.inflate( | ||
LayoutInflater.from(parent.context), | ||
parent, | ||
false | ||
) | ||
) | ||
} | ||
} | ||
} | ||
|
||
object ReplyComparator : DiffUtil.ItemCallback<Reply>() { | ||
override fun areItemsTheSame(oldItem: Reply, newItem: Reply): Boolean { | ||
return oldItem.pid == newItem.pid | ||
} | ||
|
||
override fun areContentsTheSame(oldItem: Reply, newItem: Reply): Boolean { | ||
return oldItem == newItem | ||
} | ||
} |
Oops, something went wrong.