Fixed Rumble comments and show error in CommentList whenever an error happens.

This commit is contained in:
Koen 2023-11-30 08:47:07 +01:00
parent a5dfa653ad
commit baad342aec
4 changed files with 43 additions and 10 deletions

View file

@ -1,10 +1,14 @@
package com.futo.platformplayer.views.segments
import android.content.Context
import android.graphics.Color
import android.util.AttributeSet
import android.view.Gravity
import android.view.KeyCharacterMap.UnavailableException
import android.view.LayoutInflater
import android.view.View
import android.widget.FrameLayout
import android.widget.TextView
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
@ -19,6 +23,7 @@ import com.futo.platformplayer.api.media.structures.IAsyncPager
import com.futo.platformplayer.api.media.structures.IPager
import com.futo.platformplayer.constructs.Event1
import com.futo.platformplayer.constructs.TaskHandler
import com.futo.platformplayer.engine.exceptions.ScriptUnavailableException
import com.futo.platformplayer.fullyBackfillServersAnnounceExceptions
import com.futo.platformplayer.states.StatePolycentric
import com.futo.platformplayer.views.adapters.CommentViewHolder
@ -29,15 +34,22 @@ import java.net.UnknownHostException
class CommentsList : ConstraintLayout {
private val _llmReplies: LinearLayoutManager;
private val _textMessage: TextView;
private val _taskLoadComments = if(!isInEditMode) TaskHandler<suspend () -> IPager<IPlatformComment>, IPager<IPlatformComment>>(StateApp.instance.scopeGetter, { it(); })
.success { pager -> onCommentsLoaded(pager); }
.exception<UnknownHostException> {
UIDialogs.toast("Failed to load comments");
setMessage("UnknownHostException: " + it.message);
Logger.e(TAG, "Failed to load comments.", it);
setLoading(false);
}
.exception<ScriptUnavailableException> {
setMessage(it.message);
Logger.e(TAG, "Failed to load comments.", it);
setLoading(false);
}
.exception<Throwable> {
setMessage("Throwable: " + it.message);
Logger.e(TAG, "Failed to load comments.", it);
UIDialogs.toast(context, context.getString(R.string.failed_to_load_comments) + "\n" + (it.message ?: ""));
//UIDialogs.showGeneralRetryErrorDialog(context, context.getString(R.string.failed_to_load_comments) + (it.message ?: ""), it, ::fetchComments);
setLoading(false);
} else TaskHandler(IPlatformVideoDetails::class.java, StateApp.instance.scopeGetter);
@ -75,15 +87,26 @@ class CommentsList : ConstraintLayout {
var onRepliesClick = Event1<IPlatformComment>();
var onCommentsLoaded = Event1<Int>();
constructor(context: Context, attrs: AttributeSet) : super(context, attrs) {
LayoutInflater.from(context).inflate(R.layout.view_comments_list, this, true);
_recyclerComments = findViewById(R.id.recycler_comments);
_textMessage = TextView(context).apply {
layoutParams = FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT).apply {
setMargins(0, 30, 0, 0)
}
textSize = 12.0f
setTextColor(Color.WHITE)
typeface = resources.getFont(R.font.inter_regular)
gravity = Gravity.CENTER_HORIZONTAL
}
_prependedView = FrameLayout(context);
_prependedView.layoutParams = FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT);
_adapterComments = InsertedViewAdapterWithLoader(context, arrayListOf(_prependedView), arrayListOf(),
_adapterComments = InsertedViewAdapterWithLoader(context, arrayListOf(_prependedView, _textMessage), arrayListOf(),
childCountGetter = { _comments.size },
childViewHolderBinder = { viewHolder, position -> viewHolder.bind(_comments[position], _readonly); },
childViewHolderFactory = { viewGroup, _ ->
@ -100,6 +123,16 @@ class CommentsList : ConstraintLayout {
_recyclerComments.addOnScrollListener(_scrollListener);
}
private fun setMessage(message: String?) {
Logger.i(TAG, "setMessage " + message)
if (message != null) {
_textMessage.visibility = View.VISIBLE
_textMessage.text = message
} else {
_textMessage.visibility = View.GONE
}
}
fun addComment(comment: IPlatformComment) {
_comments.add(0, comment);
_adapterComments.notifyItemRangeInserted(_adapterComments.childToParentPosition(0), 1);
@ -183,6 +216,7 @@ class CommentsList : ConstraintLayout {
fun load(readonly: Boolean, loader: suspend () -> IPager<IPlatformComment>) {
cancel();
setMessage(null);
_readonly = readonly;
setLoading(true);
@ -213,6 +247,7 @@ class CommentsList : ConstraintLayout {
_comments.clear();
_commentsPager = null;
_adapterComments.notifyDataSetChanged();
setMessage(null);
}
fun cancel() {

View file

@ -1,13 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
android:layout_height="match_parent">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_comments"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</FrameLayout>

@ -1 +1 @@
Subproject commit 60a7ee2ddf71b936d9c289a3343020cc20edfe56
Subproject commit b0e35a9b6631fb3279fb38619ecc3eba812e5ed6

@ -1 +1 @@
Subproject commit 60a7ee2ddf71b936d9c289a3343020cc20edfe56
Subproject commit b0e35a9b6631fb3279fb38619ecc3eba812e5ed6