fixed chat preview
This commit is contained in:
@@ -0,0 +1,96 @@
|
||||
package ru.vtosters.lite.ui.adapters;
|
||||
|
||||
import static ru.vtosters.lite.utils.Themes.getTextAttr;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.TypedValue;
|
||||
import android.view.Gravity;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.vk.core.widget.BubbleFluidLayout;
|
||||
import com.vk.im.ui.views.msg.bubble.MsgBubbleView;
|
||||
import com.vtosters.lite.R;
|
||||
|
||||
import ru.vtosters.lite.utils.Globals;
|
||||
|
||||
public class MessagesPreviewAdapter extends RecyclerView.Adapter<MessagesPreviewAdapter.MessagePreviewViewHolder> {
|
||||
|
||||
private static final int ME = 0x0;
|
||||
private static final int ANONYMOUS = -0x1;
|
||||
|
||||
private final String[] mMessages = {
|
||||
"Доброе время", "Доброе утро, день, вечер. ночь", "Как живёшь?", "Не мёртвый, и то хорошо"
|
||||
};
|
||||
|
||||
@Override
|
||||
public int getItemViewType(int i) {
|
||||
return i % 2 == 0 ? ANONYMOUS : ME;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public MessagePreviewViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int viewType) {
|
||||
Context context = viewGroup.getContext();
|
||||
|
||||
var bubbleFluidLayout = (BubbleFluidLayout) LayoutInflater.from(context).inflate(R.layout.vkim_msg_list_item_msg_from_user, viewGroup, false);
|
||||
|
||||
bubbleFluidLayout.findViewById(R.id.avatar).setVisibility(View.GONE);
|
||||
bubbleFluidLayout.findViewById(R.id.avatar_space).setVisibility(View.GONE);
|
||||
bubbleFluidLayout.findViewById(R.id.vkim_channel_share).setVisibility(View.GONE);
|
||||
bubbleFluidLayout.findViewById(R.id.status).setVisibility(View.GONE);
|
||||
bubbleFluidLayout.findViewById(R.id.status_space).setVisibility(View.GONE);
|
||||
|
||||
var messageBubbleView = (MsgBubbleView) bubbleFluidLayout.findViewById(R.id.bubble);
|
||||
messageBubbleView.setContentPaddingLeft(Globals.convertDpToPixel(5));
|
||||
messageBubbleView.setContentPaddingTop(Globals.convertDpToPixel(5));
|
||||
messageBubbleView.setContentPaddingRight(Globals.convertDpToPixel(5));
|
||||
messageBubbleView.setContentPaddingBottom(Globals.convertDpToPixel(5));
|
||||
bubbleFluidLayout.setGravity(viewType == ME ? Gravity.RIGHT : Gravity.LEFT);
|
||||
|
||||
var message = new TextView(context);
|
||||
message.setTag("message");
|
||||
message.setGravity(Gravity.LEFT);
|
||||
message.setTextColor(getTextAttr());
|
||||
|
||||
messageBubbleView.setContentView(message);
|
||||
|
||||
return new MessagePreviewViewHolder(bubbleFluidLayout);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull MessagePreviewViewHolder viewHolder, int pos) {
|
||||
viewHolder.bind(mMessages[pos]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return mMessages.length;
|
||||
}
|
||||
|
||||
private static int getColorFromAttribute(Context context, int attrId) {
|
||||
TypedValue typedValue = new TypedValue();
|
||||
context.getTheme().resolveAttribute(attrId, typedValue, true);
|
||||
return typedValue.data;
|
||||
}
|
||||
|
||||
protected static class MessagePreviewViewHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
private final TextView mMessage;
|
||||
|
||||
public MessagePreviewViewHolder(@NonNull View view) {
|
||||
super(view);
|
||||
|
||||
mMessage = view.findViewWithTag("message");
|
||||
}
|
||||
|
||||
public void bind(String text) {
|
||||
mMessage.setText(text);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -28,13 +28,13 @@ public class SuperAppEditorManager {
|
||||
}
|
||||
|
||||
private void init() {
|
||||
var tmp = getPreferences().getString("superapp_items", "promo,miniapps,vkpay_slim,greeting,holiday,weather,sport,games,informer,food,event,music,vk_run");
|
||||
var tmp = getPreferences().getString("superapp_items", "menu,promo,miniapps,vkpay_slim,greeting,holiday,weather,sport,games,informer,food,event,music,vk_run");
|
||||
var selectedTags = !tmp.isEmpty() ? tmp.split(",") : new String[0];
|
||||
parseSelectedItems(selectedTags);
|
||||
}
|
||||
|
||||
private void parseSelectedItems(String[] selectedTabsTags) {
|
||||
List<String> allTags = new ArrayList<>(Arrays.asList( "promo", "miniapps", "vkpay_slim", "greeting", "holiday",
|
||||
List<String> allTags = new ArrayList<>(Arrays.asList( "menu", "promo", "miniapps", "vkpay_slim", "greeting", "holiday",
|
||||
"weather", "sport", "games", "informer", "food", "event", "music", "vk_run" ));
|
||||
for (String tag : selectedTabsTags) {
|
||||
mSelectedItems.add(getItemByTag(tag));
|
||||
|
||||
@@ -20,8 +20,6 @@ public class InterfaceFragment extends MaterialPreferenceToolbarFragment{
|
||||
prefs();
|
||||
}
|
||||
|
||||
//dockbar_tab_titles
|
||||
|
||||
private void prefs(){
|
||||
findPreference("stories").setOnPreferenceClickListener(new restart());
|
||||
findPreference("swipe").setOnPreferenceClickListener(new restart());
|
||||
|
||||
@@ -1,167 +1,71 @@
|
||||
package ru.vtosters.lite.ui.wallpapers;
|
||||
|
||||
import static ru.vtosters.lite.ui.wallpapers.WallpapersHooks.getWallpaper;
|
||||
import static ru.vtosters.lite.ui.wallpapers.WallpapersHooks.getWallpaperFile;
|
||||
import static ru.vtosters.lite.utils.Globals.convertDpToPixel;
|
||||
import static ru.vtosters.lite.utils.Globals.getIdentifier;
|
||||
import static ru.vtosters.lite.utils.Themes.getSTextAttr;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.ColorStateList;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Handler;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.TypedValue;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceViewHolder;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.Executors;
|
||||
import ru.vtosters.lite.ui.adapters.MessagesPreviewAdapter;
|
||||
|
||||
import ru.vtosters.lite.utils.Themes;
|
||||
public class WallpaperPreferences extends Preference {
|
||||
|
||||
public class WallpaperPreferences extends Preference{
|
||||
private final Executor mExecutor = Executors.newSingleThreadExecutor();
|
||||
RecyclerView preview;
|
||||
ImageView bg;
|
||||
private Handler mUIHandler;
|
||||
private MessagesPreviewAdapter mAdapter;
|
||||
RecyclerView mRecyclerView;
|
||||
ImageView mChatBackground;
|
||||
|
||||
public WallpaperPreferences(Context context){
|
||||
public WallpaperPreferences(Context context) {
|
||||
this(context, null, -1, -1);
|
||||
}
|
||||
|
||||
public WallpaperPreferences(Context context, AttributeSet attributeSet){
|
||||
public WallpaperPreferences(Context context, AttributeSet attributeSet) {
|
||||
this(context, attributeSet, -1, -1);
|
||||
}
|
||||
|
||||
public WallpaperPreferences(Context context, AttributeSet attributeSet, int defStyleAttr){
|
||||
public WallpaperPreferences(Context context, AttributeSet attributeSet, int defStyleAttr) {
|
||||
this(context, attributeSet, defStyleAttr, -1);
|
||||
}
|
||||
|
||||
public WallpaperPreferences(Context context, AttributeSet attributeSet, int defStyleAttr, int i1){
|
||||
public WallpaperPreferences(Context context, AttributeSet attributeSet, int defStyleAttr, int i1) {
|
||||
super(context, attributeSet, defStyleAttr, i1);
|
||||
setLayoutResource(getIdentifier("wppreview", "layout"));
|
||||
}
|
||||
|
||||
public static int getMsgInColor(Context ctx){
|
||||
TypedValue typedValue = new TypedValue();
|
||||
ctx.getTheme().resolveAttribute(com.vtosters.lite.R.attr.im_bubble_incoming, typedValue, true);
|
||||
return typedValue.data;
|
||||
}
|
||||
|
||||
public static int getMsgOutColor(Context ctx){
|
||||
TypedValue typedValue = new TypedValue();
|
||||
ctx.getTheme().resolveAttribute(com.vtosters.lite.R.attr.im_bubble_outgoing, typedValue, true);
|
||||
return typedValue.data;
|
||||
}
|
||||
|
||||
public static int getSTextColor(Context ctx){
|
||||
TypedValue typedValue = new TypedValue();
|
||||
ctx.getTheme().resolveAttribute(getSTextAttr(), typedValue, true);
|
||||
return typedValue.data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(PreferenceViewHolder preferenceViewHolder){
|
||||
public void onBindViewHolder(PreferenceViewHolder preferenceViewHolder) {
|
||||
super.onBindViewHolder(preferenceViewHolder);
|
||||
|
||||
preview = (RecyclerView) preferenceViewHolder.findViewById(getIdentifier("install_btn_container", "id"));
|
||||
preview.setPadding(0, convertDpToPixel(8), 0, 0);
|
||||
preview.setLayoutManager(new LinearLayoutManager(getContext()));
|
||||
preview.setAdapter(new PreviewAdapter());
|
||||
preview.setClickable(false);
|
||||
preview.setFocusable(false);
|
||||
mRecyclerView = (RecyclerView) preferenceViewHolder.findViewById(getIdentifier("install_btn_container", "id"));
|
||||
mRecyclerView.setPadding(0, convertDpToPixel(8), 0, 0);
|
||||
mRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
|
||||
mRecyclerView.setAdapter((mAdapter = new MessagesPreviewAdapter()));
|
||||
mRecyclerView.setClickable(false);
|
||||
mRecyclerView.setFocusable(false);
|
||||
|
||||
mUIHandler = new Handler();
|
||||
|
||||
bg = (ImageView) preferenceViewHolder.findViewById(getIdentifier("author", "id"));
|
||||
mChatBackground = (ImageView) preferenceViewHolder.findViewById(getIdentifier("author", "id"));
|
||||
requestBg();
|
||||
}
|
||||
|
||||
private void requestBg(){
|
||||
mExecutor.execute(() -> {
|
||||
final Drawable drawable = getWallpaper();
|
||||
private void requestBg() {
|
||||
final Drawable drawable = getWallpaper();
|
||||
|
||||
mUIHandler.post(() -> {
|
||||
if (drawable != null && getWallpaperFile().exists())
|
||||
bg.setImageDrawable(drawable);
|
||||
else
|
||||
bg.setImageDrawable(null);
|
||||
});
|
||||
});
|
||||
if (drawable != null && getWallpaperFile().exists())
|
||||
mChatBackground.setImageDrawable(drawable);
|
||||
else
|
||||
mChatBackground.setImageDrawable(null);
|
||||
}
|
||||
|
||||
void redraw(){
|
||||
preview.getAdapter().notifyDataSetChanged();
|
||||
void redraw() {
|
||||
mAdapter.notifyDataSetChanged();
|
||||
requestBg();
|
||||
}
|
||||
|
||||
private static class PreviewAdapter extends RecyclerView.Adapter<PreviewAdapter.PreviewVH>{
|
||||
private final CharSequence[] previews = new CharSequence[] {
|
||||
" Привет ", " Привет ", " Ты кто? "
|
||||
};
|
||||
|
||||
private final boolean[] isOut = new boolean[] {
|
||||
false, true, false
|
||||
};
|
||||
|
||||
@Override
|
||||
public int getItemCount(){
|
||||
return previews.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull PreviewAdapter.PreviewVH previewVH, int i){
|
||||
TextView bubble = previewVH.itemView.findViewById(getIdentifier("author", "id"));
|
||||
|
||||
bubble.setText(previews[previewVH.getAdapterPosition()]);
|
||||
|
||||
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
|
||||
if (isOut[previewVH.getAdapterPosition()]) {
|
||||
params.addRule(RelativeLayout.ALIGN_PARENT_END);
|
||||
bubble.setPadding(convertDpToPixel(16), convertDpToPixel(16), convertDpToPixel(24), 0);
|
||||
bubble.setBackgroundResource(com.vtosters.lite.R.drawable.vkim_msg_new_out_light_full);
|
||||
bubble.setBackgroundTintList(ColorStateList.valueOf(getMsgOutColor(previewVH.itemView.getContext())));
|
||||
} else {
|
||||
params.addRule(RelativeLayout.ALIGN_PARENT_START);
|
||||
bubble.setPadding(convertDpToPixel(24), convertDpToPixel(16), convertDpToPixel(16), 0);
|
||||
bubble.setBackgroundResource(com.vtosters.lite.R.drawable.vkim_msg_new_in_light_full);
|
||||
bubble.setBackgroundTintList(ColorStateList.valueOf(getMsgInColor(previewVH.itemView.getContext())));
|
||||
}
|
||||
|
||||
bubble.setTextColor(Themes.getTextAttr());
|
||||
bubble.setLayoutParams(params);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public PreviewAdapter.PreviewVH onCreateViewHolder(@NonNull ViewGroup viewGroup, int i){
|
||||
Context ctx = viewGroup.getContext();
|
||||
|
||||
RelativeLayout root = new RelativeLayout(ctx);
|
||||
root.setLayoutParams(new RelativeLayout.LayoutParams(
|
||||
RelativeLayout.LayoutParams.MATCH_PARENT,
|
||||
RelativeLayout.LayoutParams.MATCH_PARENT));
|
||||
|
||||
TextView bubble = new TextView(ctx);
|
||||
bubble.setId(getIdentifier("author", "id"));
|
||||
root.addView(bubble);
|
||||
|
||||
return new PreviewVH(root);
|
||||
}
|
||||
|
||||
private static class PreviewVH extends RecyclerView.ViewHolder{
|
||||
public PreviewVH(@NonNull View view){
|
||||
super(view);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user