mirror of
https://github.com/yuliskov/SmartTube.git
synced 2025-05-17 19:35:54 +08:00
comments: add loading message
This commit is contained in:
@ -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
|
||||
*/
|
||||
|
@ -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.
|
||||
*
|
||||
|
Reference in New Issue
Block a user