comments: add loading message

This commit is contained in:
Yuriy Liskov
2023-01-06 19:13:11 +02:00
parent 831a4713dc
commit 644018cd6d
10 changed files with 89 additions and 22 deletions

View File

@ -14,7 +14,6 @@ import android.widget.TextView;
import androidx.annotation.LayoutRes;
import androidx.annotation.NonNull;
import androidx.core.text.util.LinkifyCompat;
import androidx.core.view.ViewCompat;
import com.stfalcon.chatkit.R;
@ -37,10 +36,12 @@ import java.util.List;
public class MessageHolders {
private static final short VIEW_TYPE_DATE_HEADER = 130;
private static final short VIEW_TYPE_STRING_HEADER = 133;
private static final short VIEW_TYPE_TEXT_MESSAGE = 131;
private static final short VIEW_TYPE_IMAGE_MESSAGE = 132;
private Class<? extends ViewHolder<Date>> dateHeaderHolder;
private Class<? extends ViewHolder<String>> stringHeaderHolder;
private int dateHeaderLayout;
private HolderConfig<IMessage> incomingTextConfig;
@ -55,6 +56,8 @@ public class MessageHolders {
this.dateHeaderHolder = DefaultDateHeaderViewHolder.class;
this.dateHeaderLayout = R.layout.item_date_header;
this.stringHeaderHolder = DefaultStringHeaderViewHolder.class;
this.incomingTextConfig = new HolderConfig<>(DefaultIncomingTextMessageViewHolder.class, R.layout.item_incoming_text_message);
this.outcomingTextConfig = new HolderConfig<>(DefaultOutcomingTextMessageViewHolder.class, R.layout.item_outcoming_text_message);
this.incomingImageConfig = new HolderConfig<>(DefaultIncomingImageMessageViewHolder.class, R.layout.item_incoming_image_message);
@ -544,6 +547,8 @@ public class MessageHolders {
switch (viewType) {
case VIEW_TYPE_DATE_HEADER:
return getHolder(parent, dateHeaderLayout, dateHeaderHolder, messagesListStyle, null);
case VIEW_TYPE_STRING_HEADER:
return getHolder(parent, dateHeaderLayout, stringHeaderHolder, messagesListStyle, null);
case VIEW_TYPE_TEXT_MESSAGE:
return getHolder(parent, incomingTextConfig, messagesListStyle);
case -VIEW_TYPE_TEXT_MESSAGE:
@ -603,6 +608,8 @@ public class MessageHolders {
isOutcoming = message.getUser().getId().contentEquals(senderId);
viewType = getContentViewType(message);
} else if (item instanceof String) {
viewType = VIEW_TYPE_STRING_HEADER;
} else viewType = VIEW_TYPE_DATE_HEADER;
return isOutcoming ? viewType * -1 : viewType;
@ -1065,6 +1072,35 @@ public class MessageHolders {
}
}
public static class DefaultStringHeaderViewHolder extends ViewHolder<String>
implements DefaultMessageViewHolder {
protected TextView text;
public DefaultStringHeaderViewHolder(View itemView) {
super(itemView);
text = itemView.findViewById(R.id.messageText);
}
@Override
public void onBind(String message) {
if (text != null) {
text.setText(message);
}
}
@Override
public void applyStyle(MessagesListStyle style) {
if (text != null) {
text.setTextColor(style.getDateHeaderTextColor());
text.setTextSize(TypedValue.COMPLEX_UNIT_PX, style.getDateHeaderTextSize());
text.setTypeface(text.getTypeface(), style.getDateHeaderTextStyle());
text.setPadding(style.getDateHeaderPadding(), style.getDateHeaderPadding(),
style.getDateHeaderPadding(), style.getDateHeaderPadding());
}
}
}
/**
* Base view holder for incoming message
*/

View File

@ -28,6 +28,7 @@ import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import androidx.annotation.LayoutRes;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.stfalcon.chatkit.R;
import com.stfalcon.chatkit.commons.ImageLoader;
@ -154,6 +155,8 @@ public class MessagesListAdapter<MESSAGE extends IMessage>
return;
}
removeLoadingMessageIfNeeded();
boolean isNewMessageToday = isTopDateEnabled && !isPreviousSameDate(0, message.getCreatedAt());
if (isNewMessageToday) {
items.add(0, new Wrapper<>(message.getCreatedAt()));
@ -397,6 +400,25 @@ public class MessagesListAdapter<MESSAGE extends IMessage>
isTopDateEnabled = enable;
}
public void setLoadingMessage(String message, boolean alignBottom) {
if (message == null || !items.isEmpty()) {
return;
}
((LinearLayoutManager) layoutManager).setReverseLayout(alignBottom);
items.add(new Wrapper<>(message));
notifyItemInserted(0);
}
private void removeLoadingMessageIfNeeded() {
if (items.size() == 1 && items.get(0).item instanceof String) {
// Reset to defaults (see MessagesList.setAdapter)
((LinearLayoutManager) layoutManager).setReverseLayout(true);
items.remove(0);
notifyItemRemoved(0);
}
}
/**
* Returns the list of selected messages.
*

View File

@ -5,21 +5,17 @@ import com.liskovsoft.mediaserviceinterfaces.data.MediaItemMetadata;
import com.liskovsoft.sharedutils.helpers.Helpers;
import com.liskovsoft.sharedutils.mylogger.Log;
import com.liskovsoft.sharedutils.rx.RxUtils;
import com.liskovsoft.smartyoutubetv2.common.R;
import com.liskovsoft.smartyoutubetv2.common.app.models.playback.PlayerEventListenerHelper;
import com.liskovsoft.smartyoutubetv2.common.app.models.playback.controller.PlaybackUIController;
import com.liskovsoft.smartyoutubetv2.common.app.models.playback.managers.SuggestionsLoaderManager.MetadataListener;
import com.liskovsoft.smartyoutubetv2.common.app.models.playback.ui.CommentsReceiver;
import com.liskovsoft.smartyoutubetv2.common.app.models.playback.ui.CommentsReceiverImpl;
import com.liskovsoft.smartyoutubetv2.common.app.models.playback.ui.OptionItem;
import com.liskovsoft.smartyoutubetv2.common.app.models.playback.ui.UiOptionItem;
import com.liskovsoft.smartyoutubetv2.common.app.presenters.AppDialogPresenter;
import com.liskovsoft.smartyoutubetv2.common.app.presenters.dialogs.menu.VideoMenuPresenter;
import com.liskovsoft.youtubeapi.service.YouTubeMediaService;
import io.reactivex.disposables.Disposable;
import java.util.ArrayList;
import java.util.List;
public class CommentsManager extends PlayerEventListenerHelper implements MetadataListener {
private static final String TAG = CommentsManager.class.getSimpleName();
private CommentsService mCommentsService;
@ -73,6 +69,11 @@ public class CommentsManager extends PlayerEventListenerHelper implements Metada
loadComments(nestedReceiver, nestedCommentsKey);
}
@Override
public String getLoadingMessage() {
return getActivity().getString(R.string.loading);
}
};
showDialog(commentsReceiver);

View File

@ -10,4 +10,5 @@ public interface CommentsReceiver {
void setCallback(Callback callback);
void onLoadMore(String nextCommentsKey);
void onCommentClicked(String nestedCommentsKey);
String getLoadingMessage();
}

View File

@ -26,4 +26,9 @@ public class CommentsReceiverImpl implements CommentsReceiver {
public void onCommentClicked(String nestedCommentsKey) {
}
@Override
public String getLoadingMessage() {
return null;
}
}

View File

@ -485,4 +485,5 @@
<string name="chapters">Эпизоды</string>
<string name="card_multiline_subtitle">Несколько строк в подзаголовках</string>
<string name="auto_frame_rate_modes">Поддерживаемые режимы</string>
<string name="loading">Загрузка...</string>
</resources>

View File

@ -485,4 +485,5 @@
<string name="chapters">Розділи</string>
<string name="card_multiline_subtitle">Декілька рядків у підзаголовках</string>
<string name="auto_frame_rate_modes">Підтримувані режими</string>
<string name="loading">Завантаження...</string>
</resources>

View File

@ -493,4 +493,5 @@
<string name="chapters">Chapters</string>
<string name="card_multiline_subtitle">Multiline subtitles</string>
<string name="auto_frame_rate_modes">Supported modes</string>
<string name="loading">Loading…</string>
</resources>

View File

@ -125,11 +125,11 @@ android {
versionCode 11000 + defaultConfig.versionCode
applicationId "com.redboxtv.smartyoutubetv"
}
stsibsetru {
// matchingFallbacks = ['lite']
versionCode 11000 + defaultConfig.versionCode
applicationId "com.sibsetru.smartyoutubetv"
}
// stsibsetru {
// // matchingFallbacks = ['lite']
// versionCode 11000 + defaultConfig.versionCode
// applicationId "com.sibsetru.smartyoutubetv"
// }
}
// naming example: SmartYouTubeTV_Xwalk_v6.8.12_r.apk

View File

@ -69,18 +69,17 @@ public class CommentsPreferenceDialogFragment extends LeanbackPreferenceDialogFr
adapter.setLoadMoreListener((page, totalItemsCount) -> mCommentsReceiver.onLoadMore(mNextCommentsKey));
adapter.setOnMessageClickListener(message -> mCommentsReceiver.onCommentClicked(message.getNestedCommentsKey()));
messagesList.setAdapter(adapter);
adapter.setLoadingMessage(mCommentsReceiver.getLoadingMessage(), false);
if (mCommentsReceiver != null) {
mCommentsReceiver.setCallback(commentGroup -> {
for (CommentItem commentItem : commentGroup.getComments()) {
adapter.addToStart(ChatItemMessage.from(commentItem), false);
}
if (mNextCommentsKey == null) {
adapter.scrollToTop();
}
mNextCommentsKey = commentGroup.getNextCommentsKey();
});
}
mCommentsReceiver.setCallback(commentGroup -> {
for (CommentItem commentItem : commentGroup.getComments()) {
adapter.addToStart(ChatItemMessage.from(commentItem), false);
}
if (mNextCommentsKey == null) {
adapter.scrollToTop();
}
mNextCommentsKey = commentGroup.getNextCommentsKey();
});
if (mIsTransparent) {
ViewUtil.enableTransparentDialog(getActivity(), view);