diff --git a/chat/kit/src/main/java/cn/wildfire/chat/kit/conversation/ConversationFragment.java b/chat/kit/src/main/java/cn/wildfire/chat/kit/conversation/ConversationFragment.java index 78a08bb20..c554b2bed 100644 --- a/chat/kit/src/main/java/cn/wildfire/chat/kit/conversation/ConversationFragment.java +++ b/chat/kit/src/main/java/cn/wildfire/chat/kit/conversation/ConversationFragment.java @@ -267,7 +267,7 @@ private void initView() { }); // message list - adapter = new ConversationMessageAdapter(getActivity()); + adapter = new ConversationMessageAdapter(this); adapter.setOnPortraitClickListener(this); adapter.setOnPortraitLongClickListener(this); adapter.setOnMessageCheckListener(this); diff --git a/chat/kit/src/main/java/cn/wildfire/chat/kit/conversation/ConversationMessageAdapter.java b/chat/kit/src/main/java/cn/wildfire/chat/kit/conversation/ConversationMessageAdapter.java index 7837a53e2..32a341078 100644 --- a/chat/kit/src/main/java/cn/wildfire/chat/kit/conversation/ConversationMessageAdapter.java +++ b/chat/kit/src/main/java/cn/wildfire/chat/kit/conversation/ConversationMessageAdapter.java @@ -1,6 +1,5 @@ package cn.wildfire.chat.kit.conversation; -import android.content.Context; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -10,7 +9,6 @@ import android.widget.Toast; import androidx.annotation.NonNull; -import androidx.fragment.app.FragmentActivity; import androidx.recyclerview.widget.RecyclerView; import com.afollestad.materialdialogs.DialogAction; @@ -42,7 +40,7 @@ import cn.wildfirechat.remote.ChatManager; public class ConversationMessageAdapter extends RecyclerView.Adapter { - private Context mContext; + private ConversationFragment fragment; public static int MODE_NORMAL = 0; public static int MODE_CHECKABLE = 1; @@ -54,9 +52,9 @@ public class ConversationMessageAdapter extends RecyclerView.Adapter 0 ? sendResId : R.layout.conversation_item_unknown_send); } else { - itemView = LayoutInflater.from(mContext).inflate(R.layout.conversation_item_message_container_receive, parent, false); + itemView = LayoutInflater.from(fragment.getContext()).inflate(R.layout.conversation_item_message_container_receive, parent, false); viewStub = itemView.findViewById(R.id.contentViewStub); viewStub.setLayoutResource(receiveResId > 0 ? receiveResId : R.layout.conversation_item_unknown_receive); } @@ -242,13 +240,13 @@ public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int } } catch (Exception e) { if (e.getMessage() != null && e.getMessage().contains("webview")) { - Toast.makeText(mContext, "请安装: Android System WebView", Toast.LENGTH_SHORT).show(); + Toast.makeText(fragment.getContext(), "请安装: Android System WebView", Toast.LENGTH_SHORT).show(); } } try { - Constructor constructor = viewHolderClazz.getConstructor(FragmentActivity.class, RecyclerView.Adapter.class, View.class); - MessageContentViewHolder viewHolder = (MessageContentViewHolder) constructor.newInstance(mContext, this, itemView); + Constructor constructor = viewHolderClazz.getConstructor(ConversationFragment.class, RecyclerView.Adapter.class, View.class); + MessageContentViewHolder viewHolder = (MessageContentViewHolder) constructor.newInstance(fragment, this, itemView); if (viewHolder instanceof SimpleNotificationMessageContentViewHolder) { return viewHolder; } @@ -388,12 +386,12 @@ public boolean onLongClick(View v) { List titles = new ArrayList<>(contextMenus.size()); for (ContextMenuItemWrapper itemWrapper : contextMenus) { if (itemWrapper.contextMenuItem.titleResId() != 0) { - titles.add(mContext.getString(itemWrapper.contextMenuItem.titleResId())); + titles.add(fragment.getString(itemWrapper.contextMenuItem.titleResId())); } else { titles.add(itemWrapper.contextMenuItem.title()); } } - new MaterialDialog.Builder(mContext).items(titles).itemsCallback(new MaterialDialog.ListCallback() { + new MaterialDialog.Builder(fragment.getContext()).items(titles).itemsCallback(new MaterialDialog.ListCallback() { @Override public void onSelection(MaterialDialog dialog, View v, int position, CharSequence text) { try { @@ -401,11 +399,11 @@ public void onSelection(MaterialDialog dialog, View v, int position, CharSequenc if (menuItem.contextMenuItem.confirm()) { String content; if (menuItem.contextMenuItem.confirmPromptResId() != 0) { - content = mContext.getString(menuItem.contextMenuItem.confirmPromptResId()); + content = fragment.getString(menuItem.contextMenuItem.confirmPromptResId()); } else { content = menuItem.contextMenuItem.confirmPrompt(); } - new MaterialDialog.Builder(mContext) + new MaterialDialog.Builder(fragment.getContext()) .content(content) .negativeText("取消") .positiveText("确认") diff --git a/chat/kit/src/main/java/cn/wildfire/chat/kit/conversation/message/viewholder/AudioMessageContentViewHolder.java b/chat/kit/src/main/java/cn/wildfire/chat/kit/conversation/message/viewholder/AudioMessageContentViewHolder.java index ac8c44960..4db6134a9 100644 --- a/chat/kit/src/main/java/cn/wildfire/chat/kit/conversation/message/viewholder/AudioMessageContentViewHolder.java +++ b/chat/kit/src/main/java/cn/wildfire/chat/kit/conversation/message/viewholder/AudioMessageContentViewHolder.java @@ -8,7 +8,6 @@ import android.widget.TextView; import androidx.annotation.Nullable; -import androidx.fragment.app.FragmentActivity; import androidx.recyclerview.widget.RecyclerView; import java.io.File; @@ -20,6 +19,7 @@ import cn.wildfire.chat.kit.annotation.MessageContentType; import cn.wildfire.chat.kit.annotation.ReceiveLayoutRes; import cn.wildfire.chat.kit.annotation.SendLayoutRes; +import cn.wildfire.chat.kit.conversation.ConversationFragment; import cn.wildfire.chat.kit.conversation.message.model.UiMessage; import cn.wildfire.chat.kit.third.utils.UIUtils; import cn.wildfirechat.chat.R; @@ -42,8 +42,8 @@ public class AudioMessageContentViewHolder extends MediaMessageContentViewHolder @BindView(R.id.playStatusIndicator) View playStatusIndicator; - public AudioMessageContentViewHolder(FragmentActivity context, RecyclerView.Adapter adapter, View itemView) { - super(context, adapter, itemView); + public AudioMessageContentViewHolder(ConversationFragment fragment, RecyclerView.Adapter adapter, View itemView) { + super(fragment, adapter, itemView); } @Override diff --git a/chat/kit/src/main/java/cn/wildfire/chat/kit/conversation/message/viewholder/ExampleRichNotificationMessageContentViewHolder.java b/chat/kit/src/main/java/cn/wildfire/chat/kit/conversation/message/viewholder/ExampleRichNotificationMessageContentViewHolder.java index 30896ca59..7bde85584 100644 --- a/chat/kit/src/main/java/cn/wildfire/chat/kit/conversation/message/viewholder/ExampleRichNotificationMessageContentViewHolder.java +++ b/chat/kit/src/main/java/cn/wildfire/chat/kit/conversation/message/viewholder/ExampleRichNotificationMessageContentViewHolder.java @@ -6,9 +6,9 @@ import android.widget.ImageView; import android.widget.Toast; -import androidx.fragment.app.FragmentActivity; import androidx.recyclerview.widget.RecyclerView; import androidx.swiperefreshlayout.widget.CircularProgressDrawable; + import butterknife.BindView; import butterknife.OnClick; import cn.wildfire.chat.kit.GlideApp; @@ -16,6 +16,7 @@ import cn.wildfire.chat.kit.annotation.LayoutRes; import cn.wildfire.chat.kit.annotation.MessageContentType; import cn.wildfire.chat.kit.annotation.MessageContextMenuItem; +import cn.wildfire.chat.kit.conversation.ConversationFragment; import cn.wildfire.chat.kit.conversation.forward.ForwardActivity; import cn.wildfire.chat.kit.conversation.message.model.UiMessage; import cn.wildfire.chat.kit.third.utils.UIUtils; @@ -30,8 +31,8 @@ public class ExampleRichNotificationMessageContentViewHolder extends Notificatio @BindView(R.id.stickerImageView) ImageView imageView; - public ExampleRichNotificationMessageContentViewHolder(FragmentActivity context, RecyclerView.Adapter adapter, View itemView) { - super(context, adapter, itemView); + public ExampleRichNotificationMessageContentViewHolder(ConversationFragment fragment, RecyclerView.Adapter adapter, View itemView) { + super(fragment, adapter, itemView); } @Override @@ -44,14 +45,14 @@ public void onBind(UiMessage message, int position) { if (stickerMessage.localPath.equals(path)) { return; } - GlideApp.with(context).load(stickerMessage.localPath) + GlideApp.with(fragment).load(stickerMessage.localPath) .into(imageView); path = stickerMessage.localPath; } else { - CircularProgressDrawable progressDrawable = new CircularProgressDrawable(context); + CircularProgressDrawable progressDrawable = new CircularProgressDrawable(fragment.getContext()); progressDrawable.setStyle(CircularProgressDrawable.DEFAULT); progressDrawable.start(); - GlideApp.with(context) + GlideApp.with(fragment) .load(stickerMessage.remoteUrl) .placeholder(progressDrawable) .into(imageView); @@ -60,7 +61,7 @@ public void onBind(UiMessage message, int position) { @OnClick(R.id.stickerImageView) public void onClick(View view) { - Toast.makeText(context, "TODO", Toast.LENGTH_SHORT).show(); + Toast.makeText(fragment.getContext(), "TODO", Toast.LENGTH_SHORT).show(); } @Override @@ -70,8 +71,8 @@ public boolean contextMenuItemFilter(UiMessage uiMessage, String itemTitle) { @MessageContextMenuItem(tag = MessageContextMenuItemTags.TAG_FORWARD, title = "转发", priority = 11) public void forwardMessage(View itemView, UiMessage message) { - Intent intent = new Intent(context, ForwardActivity.class); + Intent intent = new Intent(fragment.getContext(), ForwardActivity.class); intent.putExtra("message", message.message); - context.startActivity(intent); + fragment.startActivity(intent); } } diff --git a/chat/kit/src/main/java/cn/wildfire/chat/kit/conversation/message/viewholder/FileMessageContentViewHolder.java b/chat/kit/src/main/java/cn/wildfire/chat/kit/conversation/message/viewholder/FileMessageContentViewHolder.java index 75a79289e..c4fd7c896 100644 --- a/chat/kit/src/main/java/cn/wildfire/chat/kit/conversation/message/viewholder/FileMessageContentViewHolder.java +++ b/chat/kit/src/main/java/cn/wildfire/chat/kit/conversation/message/viewholder/FileMessageContentViewHolder.java @@ -5,7 +5,6 @@ import android.view.View; import android.widget.Toast; -import androidx.fragment.app.FragmentActivity; import androidx.recyclerview.widget.RecyclerView; import com.bumptech.glide.Glide; @@ -18,6 +17,7 @@ import cn.wildfire.chat.kit.annotation.EnableContextMenu; import cn.wildfire.chat.kit.annotation.LayoutRes; import cn.wildfire.chat.kit.annotation.MessageContentType; +import cn.wildfire.chat.kit.conversation.ConversationFragment; import cn.wildfire.chat.kit.conversation.message.model.UiMessage; import cn.wildfire.chat.kit.third.utils.UIUtils; import cn.wildfire.chat.kit.utils.FileUtils; @@ -35,8 +35,8 @@ public class FileMessageContentViewHolder extends MediaMessageContentViewHolder BubbleImageView imageView; private FileMessageContent fileMessageContent; - public FileMessageContentViewHolder(FragmentActivity context, RecyclerView.Adapter adapter, View itemView) { - super(context, adapter, itemView); + public FileMessageContentViewHolder(ConversationFragment fragment, RecyclerView.Adapter adapter, View itemView) { + super(fragment, adapter, itemView); } @Override @@ -51,7 +51,7 @@ public void onBind(UiMessage message) { imageView.setProgressVisible(false); imageView.showShadow(false); } - Glide.with(context).load(R.mipmap.ic_file) + Glide.with(fragment).load(R.mipmap.ic_file) .apply(new RequestOptions().override(UIUtils.dip2Px(150), UIUtils.dip2Px(150)).centerCrop()).into(imageView); } @@ -66,13 +66,13 @@ public void onClick(View view) { } if (file.exists()) { - Intent intent = FileUtils.getViewIntent(context, file); - ComponentName cn = intent.resolveActivity(context.getPackageManager()); + Intent intent = FileUtils.getViewIntent(fragment.getContext(), file); + ComponentName cn = intent.resolveActivity(fragment.getContext().getPackageManager()); if (cn == null) { - Toast.makeText(context, "找不到能打开此文件的应用", Toast.LENGTH_SHORT).show(); + Toast.makeText(fragment.getContext(), "找不到能打开此文件的应用", Toast.LENGTH_SHORT).show(); return; } - context.startActivity(intent); + fragment.startActivity(intent); } else { messageViewModel.downloadMedia(message, file); } diff --git a/chat/kit/src/main/java/cn/wildfire/chat/kit/conversation/message/viewholder/ImageMessageContentViewHolder.java b/chat/kit/src/main/java/cn/wildfire/chat/kit/conversation/message/viewholder/ImageMessageContentViewHolder.java index 76bbe618d..bb99c09de 100644 --- a/chat/kit/src/main/java/cn/wildfire/chat/kit/conversation/message/viewholder/ImageMessageContentViewHolder.java +++ b/chat/kit/src/main/java/cn/wildfire/chat/kit/conversation/message/viewholder/ImageMessageContentViewHolder.java @@ -6,7 +6,6 @@ import android.text.TextUtils; import android.view.View; -import androidx.fragment.app.FragmentActivity; import androidx.recyclerview.widget.RecyclerView; import butterknife.BindView; @@ -17,6 +16,7 @@ import cn.wildfire.chat.kit.annotation.MessageContentType; import cn.wildfire.chat.kit.annotation.ReceiveLayoutRes; import cn.wildfire.chat.kit.annotation.SendLayoutRes; +import cn.wildfire.chat.kit.conversation.ConversationFragment; import cn.wildfire.chat.kit.conversation.message.model.UiMessage; import cn.wildfire.chat.kit.third.utils.UIUtils; import cn.wildfire.chat.kit.widget.BubbleImageView; @@ -36,8 +36,8 @@ public class ImageMessageContentViewHolder extends MediaMessageContentViewHolder @BindView(R.id.imageView) BubbleImageView imageView; - public ImageMessageContentViewHolder(FragmentActivity context, RecyclerView.Adapter adapter, View itemView) { - super(context, adapter, itemView); + public ImageMessageContentViewHolder(ConversationFragment fragment, RecyclerView.Adapter adapter, View itemView) { + super(fragment, adapter, itemView); } @Override @@ -50,15 +50,15 @@ public void onBind(UiMessage message) { imageView.getLayoutParams().height = UIUtils.dip2Px(height > 200 ? 200 : height); if (!TextUtils.isEmpty(imageMessage.localPath)) { - GlideApp.with(context) + GlideApp.with(fragment) .load(imageMessage.localPath) .centerCrop() .into(imageView); } else { - GlideRequest request = GlideApp.with(context) + GlideRequest request = GlideApp.with(fragment) .load(imageMessage.remoteUrl); if (thumbnail != null) { - request = request.placeholder(new BitmapDrawable(context.getResources(), imageMessage.getThumbnail())); + request = request.placeholder(new BitmapDrawable(fragment.getResources(), imageMessage.getThumbnail())); } else { request = request.placeholder(R.mipmap.img_error); } diff --git a/chat/kit/src/main/java/cn/wildfire/chat/kit/conversation/message/viewholder/MediaMessageContentViewHolder.java b/chat/kit/src/main/java/cn/wildfire/chat/kit/conversation/message/viewholder/MediaMessageContentViewHolder.java index 4f08918a7..7fb437fe6 100644 --- a/chat/kit/src/main/java/cn/wildfire/chat/kit/conversation/message/viewholder/MediaMessageContentViewHolder.java +++ b/chat/kit/src/main/java/cn/wildfire/chat/kit/conversation/message/viewholder/MediaMessageContentViewHolder.java @@ -2,12 +2,12 @@ import android.view.View; -import androidx.fragment.app.FragmentActivity; import androidx.recyclerview.widget.RecyclerView; import java.util.ArrayList; import java.util.List; +import cn.wildfire.chat.kit.conversation.ConversationFragment; import cn.wildfire.chat.kit.conversation.ConversationMessageAdapter; import cn.wildfire.chat.kit.conversation.message.model.UiMessage; import cn.wildfire.chat.kit.mm.MMPreviewActivity; @@ -20,8 +20,8 @@ public class MediaMessageContentViewHolder extends NormalMessageContentViewHolder { - public MediaMessageContentViewHolder(FragmentActivity activity, RecyclerView.Adapter adapter, View itemView) { - super(activity, adapter, itemView); + public MediaMessageContentViewHolder(ConversationFragment fragment, RecyclerView.Adapter adapter, View itemView) { + super(fragment, adapter, itemView); } @Override @@ -71,6 +71,6 @@ protected void previewMM() { if (entries.isEmpty()) { return; } - MMPreviewActivity.startActivity(context, entries, current); + MMPreviewActivity.startActivity(fragment.getContext(), entries, current); } } diff --git a/chat/kit/src/main/java/cn/wildfire/chat/kit/conversation/message/viewholder/MessageContentViewHolder.java b/chat/kit/src/main/java/cn/wildfire/chat/kit/conversation/message/viewholder/MessageContentViewHolder.java index b9a6c81cb..78f2b1a60 100644 --- a/chat/kit/src/main/java/cn/wildfire/chat/kit/conversation/message/viewholder/MessageContentViewHolder.java +++ b/chat/kit/src/main/java/cn/wildfire/chat/kit/conversation/message/viewholder/MessageContentViewHolder.java @@ -3,12 +3,13 @@ import android.view.View; import android.widget.TextView; -import androidx.fragment.app.FragmentActivity; +import androidx.annotation.NonNull; import androidx.lifecycle.ViewModelProviders; import androidx.recyclerview.widget.RecyclerView; import butterknife.BindView; import butterknife.ButterKnife; +import cn.wildfire.chat.kit.conversation.ConversationFragment; import cn.wildfire.chat.kit.conversation.ConversationMessageAdapter; import cn.wildfire.chat.kit.conversation.message.model.UiMessage; import cn.wildfire.chat.kit.third.utils.TimeUtils; @@ -17,7 +18,8 @@ import cn.wildfirechat.message.Message; public abstract class MessageContentViewHolder extends RecyclerView.ViewHolder { - protected FragmentActivity context; + @NonNull + protected ConversationFragment fragment; protected View itemView; protected UiMessage message; protected int position; @@ -28,12 +30,12 @@ public abstract class MessageContentViewHolder extends RecyclerView.ViewHolder { TextView timeTextView; - public MessageContentViewHolder(FragmentActivity activity, RecyclerView.Adapter adapter, View itemView) { + public MessageContentViewHolder(@NonNull ConversationFragment fragment, RecyclerView.Adapter adapter, View itemView) { super(itemView); - this.context = activity; + this.fragment = fragment; this.itemView = itemView; this.adapter = adapter; - messageViewModel = ViewModelProviders.of(activity).get(MessageViewModel.class); + messageViewModel = ViewModelProviders.of(fragment).get(MessageViewModel.class); ButterKnife.bind(this, itemView); } diff --git a/chat/kit/src/main/java/cn/wildfire/chat/kit/conversation/message/viewholder/NormalMessageContentViewHolder.java b/chat/kit/src/main/java/cn/wildfire/chat/kit/conversation/message/viewholder/NormalMessageContentViewHolder.java index de115dc0b..046b6191a 100644 --- a/chat/kit/src/main/java/cn/wildfire/chat/kit/conversation/message/viewholder/NormalMessageContentViewHolder.java +++ b/chat/kit/src/main/java/cn/wildfire/chat/kit/conversation/message/viewholder/NormalMessageContentViewHolder.java @@ -12,7 +12,6 @@ import android.widget.TextView; import androidx.annotation.Nullable; -import androidx.fragment.app.FragmentActivity; import androidx.lifecycle.ViewModelProviders; import androidx.recyclerview.widget.RecyclerView; @@ -26,6 +25,7 @@ import cn.wildfire.chat.kit.GlideApp; import cn.wildfire.chat.kit.annotation.MessageContextMenuItem; import cn.wildfire.chat.kit.conversation.ConversationActivity; +import cn.wildfire.chat.kit.conversation.ConversationFragment; import cn.wildfire.chat.kit.conversation.forward.ForwardActivity; import cn.wildfire.chat.kit.conversation.message.model.UiMessage; import cn.wildfire.chat.kit.group.GroupViewModel; @@ -56,8 +56,8 @@ public abstract class NormalMessageContentViewHolder extends MessageContentViewH @BindView(R.id.checkbox) CheckBox checkBox; - public NormalMessageContentViewHolder(FragmentActivity activity, RecyclerView.Adapter adapter, View itemView) { - super(activity, adapter, itemView); + public NormalMessageContentViewHolder(ConversationFragment fragment, RecyclerView.Adapter adapter, View itemView) { + super(fragment, adapter, itemView); } @Override @@ -121,7 +121,7 @@ public boolean checkable(UiMessage message) { @Nullable @OnClick(R.id.errorLinearLayout) public void onRetryClick(View itemView) { - new MaterialDialog.Builder(context) + new MaterialDialog.Builder(fragment.getContext()) .content("重新发送?") .negativeText("取消") .positiveText("重发") @@ -143,20 +143,20 @@ public void removeMessage(View itemView, UiMessage message) { @MessageContextMenuItem(tag = MessageContextMenuItemTags.TAG_FORWARD, title = "转发", priority = 11) public void forwardMessage(View itemView, UiMessage message) { - Intent intent = new Intent(context, ForwardActivity.class); + Intent intent = new Intent(fragment.getContext(), ForwardActivity.class); intent.putExtra("message", message.message); - context.startActivity(intent); + fragment.startActivity(intent); } @MessageContextMenuItem(tag = MessageContextMenuItemTags.TAG_MULTI_CHECK, title = "多选", priority = 13) public void checkMessage(View itemView, UiMessage message) { - ((ConversationActivity) context).getConversationFragment().toggleMultiMessageMode(message); + fragment.toggleMultiMessageMode(message); } @MessageContextMenuItem(tag = MessageContextMenuItemTags.TAG_CHANEL_PRIVATE_CHAT, title = "私聊", priority = 12) public void startChanelPrivateChat(View itemView, UiMessage message) { - Intent intent = ConversationActivity.buildConversationIntent(context, Conversation.ConversationType.Channel, message.message.conversation.target, message.message.conversation.line, message.message.sender); - context.startActivity(intent); + Intent intent = ConversationActivity.buildConversationIntent(fragment.getContext(), Conversation.ConversationType.Channel, message.message.conversation.target, message.message.conversation.line, message.message.sender); + fragment.startActivity(intent); } @Override @@ -165,7 +165,7 @@ public boolean contextMenuItemFilter(UiMessage uiMessage, String tag) { if (MessageContextMenuItemTags.TAG_RECALL.equals(tag)) { String userId = ChatManager.Instance().getUserId(); if (message.conversation.type == Conversation.ConversationType.Group) { - GroupViewModel groupViewModel = ViewModelProviders.of(context).get(GroupViewModel.class); + GroupViewModel groupViewModel = ViewModelProviders.of(fragment).get(GroupViewModel.class); GroupInfo groupInfo = groupViewModel.getGroupInfo(message.conversation.target, false); if (groupInfo != null && userId.equals(groupInfo.owner)) { return false; @@ -204,7 +204,7 @@ private void setSenderAvatar(Message item) { UserInfo userInfo = ChatManagerHolder.gChatManager.getUserInfo(item.sender, false); if (portraitImageView != null) { GlideApp - .with(context) + .with(fragment) .load(userInfo.portrait) .transforms(new CenterCrop(), new RoundedCorners(10)) .error(R.mipmap.default_header) @@ -223,7 +223,7 @@ private void setSenderName(Message item) { } private void showGroupMemberAlias(Conversation conversation, String sender) { - UserViewModel userViewModel = ViewModelProviders.of(context).get(UserViewModel.class); + UserViewModel userViewModel = ViewModelProviders.of(fragment).get(UserViewModel.class); if (!"1".equals(userViewModel.getUserSetting(UserSettingScope.GroupHideNickname, conversation.target))) { nameTextView.setVisibility(View.GONE); return; @@ -233,7 +233,7 @@ private void showGroupMemberAlias(Conversation conversation, String sender) { // if (Conversation.equals(nameTextView.getTag(), sender)) { // return; // } - GroupViewModel groupViewModel = ViewModelProviders.of(context).get(GroupViewModel.class); + GroupViewModel groupViewModel = ViewModelProviders.of(fragment).get(GroupViewModel.class); nameTextView.setText(groupViewModel.getGroupMemberDisplayName(conversation.target, sender)); nameTextView.setTag(sender); diff --git a/chat/kit/src/main/java/cn/wildfire/chat/kit/conversation/message/viewholder/NotificationMessageContentViewHolder.java b/chat/kit/src/main/java/cn/wildfire/chat/kit/conversation/message/viewholder/NotificationMessageContentViewHolder.java index 347210f5a..659df87b4 100644 --- a/chat/kit/src/main/java/cn/wildfire/chat/kit/conversation/message/viewholder/NotificationMessageContentViewHolder.java +++ b/chat/kit/src/main/java/cn/wildfire/chat/kit/conversation/message/viewholder/NotificationMessageContentViewHolder.java @@ -2,11 +2,12 @@ import android.view.View; -import androidx.fragment.app.FragmentActivity; import androidx.recyclerview.widget.RecyclerView; +import cn.wildfire.chat.kit.conversation.ConversationFragment; + public abstract class NotificationMessageContentViewHolder extends MessageContentViewHolder { - public NotificationMessageContentViewHolder(FragmentActivity activity, RecyclerView.Adapter adapter, View itemView) { - super(activity, adapter, itemView); + public NotificationMessageContentViewHolder(ConversationFragment fragment, RecyclerView.Adapter adapter, View itemView) { + super(fragment, adapter, itemView); } } diff --git a/chat/kit/src/main/java/cn/wildfire/chat/kit/conversation/message/viewholder/RecallMessageContentViewHolderSimple.java b/chat/kit/src/main/java/cn/wildfire/chat/kit/conversation/message/viewholder/RecallMessageContentViewHolderSimple.java index acebab5c7..d46135afc 100644 --- a/chat/kit/src/main/java/cn/wildfire/chat/kit/conversation/message/viewholder/RecallMessageContentViewHolderSimple.java +++ b/chat/kit/src/main/java/cn/wildfire/chat/kit/conversation/message/viewholder/RecallMessageContentViewHolderSimple.java @@ -3,12 +3,12 @@ import android.view.View; import android.widget.TextView; -import androidx.fragment.app.FragmentActivity; import androidx.recyclerview.widget.RecyclerView; import butterknife.BindView; import cn.wildfire.chat.kit.annotation.LayoutRes; import cn.wildfire.chat.kit.annotation.MessageContentType; +import cn.wildfire.chat.kit.conversation.ConversationFragment; import cn.wildfire.chat.kit.conversation.message.model.UiMessage; import cn.wildfirechat.chat.R; import cn.wildfirechat.message.notification.RecallMessageContent; @@ -19,8 +19,8 @@ public class RecallMessageContentViewHolderSimple extends SimpleNotificationMess @BindView(R.id.notificationTextView) TextView notificationTextView; - public RecallMessageContentViewHolderSimple(FragmentActivity activity, RecyclerView.Adapter adapter, View itemView) { - super(activity, adapter, itemView); + public RecallMessageContentViewHolderSimple(ConversationFragment fragment, RecyclerView.Adapter adapter, View itemView) { + super(fragment, adapter, itemView); } @Override diff --git a/chat/kit/src/main/java/cn/wildfire/chat/kit/conversation/message/viewholder/SimpleNotificationMessageContentViewHolder.java b/chat/kit/src/main/java/cn/wildfire/chat/kit/conversation/message/viewholder/SimpleNotificationMessageContentViewHolder.java index 6726ebbbf..a53cbd6f1 100644 --- a/chat/kit/src/main/java/cn/wildfire/chat/kit/conversation/message/viewholder/SimpleNotificationMessageContentViewHolder.java +++ b/chat/kit/src/main/java/cn/wildfire/chat/kit/conversation/message/viewholder/SimpleNotificationMessageContentViewHolder.java @@ -3,12 +3,12 @@ import android.view.View; import android.widget.TextView; -import androidx.fragment.app.FragmentActivity; import androidx.recyclerview.widget.RecyclerView; import butterknife.BindView; import cn.wildfire.chat.kit.annotation.LayoutRes; import cn.wildfire.chat.kit.annotation.MessageContentType; +import cn.wildfire.chat.kit.conversation.ConversationFragment; import cn.wildfire.chat.kit.conversation.message.model.UiMessage; import cn.wildfirechat.chat.R; import cn.wildfirechat.message.notification.AddGroupMemberNotificationContent; @@ -58,8 +58,8 @@ public class SimpleNotificationMessageContentViewHolder extends MessageContentVi @BindView(R.id.notificationTextView) TextView notificationTextView; - public SimpleNotificationMessageContentViewHolder(FragmentActivity activity, RecyclerView.Adapter adapter, View itemView) { - super(activity, adapter, itemView); + public SimpleNotificationMessageContentViewHolder(ConversationFragment fragment, RecyclerView.Adapter adapter, View itemView) { + super(fragment, adapter, itemView); } @Override diff --git a/chat/kit/src/main/java/cn/wildfire/chat/kit/conversation/message/viewholder/StickerMessageContentViewHolder.java b/chat/kit/src/main/java/cn/wildfire/chat/kit/conversation/message/viewholder/StickerMessageContentViewHolder.java index 7bb31bb0c..5e324f86a 100644 --- a/chat/kit/src/main/java/cn/wildfire/chat/kit/conversation/message/viewholder/StickerMessageContentViewHolder.java +++ b/chat/kit/src/main/java/cn/wildfire/chat/kit/conversation/message/viewholder/StickerMessageContentViewHolder.java @@ -4,15 +4,16 @@ import android.view.View; import android.widget.ImageView; -import androidx.fragment.app.FragmentActivity; import androidx.recyclerview.widget.RecyclerView; import androidx.swiperefreshlayout.widget.CircularProgressDrawable; + import butterknife.BindView; import cn.wildfire.chat.kit.GlideApp; import cn.wildfire.chat.kit.annotation.EnableContextMenu; import cn.wildfire.chat.kit.annotation.MessageContentType; import cn.wildfire.chat.kit.annotation.ReceiveLayoutRes; import cn.wildfire.chat.kit.annotation.SendLayoutRes; +import cn.wildfire.chat.kit.conversation.ConversationFragment; import cn.wildfire.chat.kit.conversation.message.model.UiMessage; import cn.wildfire.chat.kit.third.utils.UIUtils; import cn.wildfirechat.chat.R; @@ -27,8 +28,8 @@ public class StickerMessageContentViewHolder extends NormalMessageContentViewHol @BindView(R.id.stickerImageView) ImageView imageView; - public StickerMessageContentViewHolder(FragmentActivity context, RecyclerView.Adapter adapter, View itemView) { - super(context, adapter, itemView); + public StickerMessageContentViewHolder(ConversationFragment fragment, RecyclerView.Adapter adapter, View itemView) { + super(fragment, adapter, itemView); } @Override @@ -41,14 +42,14 @@ public void onBind(UiMessage message) { if (stickerMessage.localPath.equals(path)) { return; } - GlideApp.with(context).load(stickerMessage.localPath) + GlideApp.with(fragment).load(stickerMessage.localPath) .into(imageView); path = stickerMessage.localPath; } else { - CircularProgressDrawable progressDrawable = new CircularProgressDrawable(context); + CircularProgressDrawable progressDrawable = new CircularProgressDrawable(fragment.getContext()); progressDrawable.setStyle(CircularProgressDrawable.DEFAULT); progressDrawable.start(); - GlideApp.with(context) + GlideApp.with(fragment) .load(stickerMessage.remoteUrl) .placeholder(progressDrawable) .into(imageView); diff --git a/chat/kit/src/main/java/cn/wildfire/chat/kit/conversation/message/viewholder/TextMessageContentViewHolder.java b/chat/kit/src/main/java/cn/wildfire/chat/kit/conversation/message/viewholder/TextMessageContentViewHolder.java index 2b3df9fe7..3a0a4bdcf 100644 --- a/chat/kit/src/main/java/cn/wildfire/chat/kit/conversation/message/viewholder/TextMessageContentViewHolder.java +++ b/chat/kit/src/main/java/cn/wildfire/chat/kit/conversation/message/viewholder/TextMessageContentViewHolder.java @@ -8,7 +8,6 @@ import android.widget.TextView; import android.widget.Toast; -import androidx.fragment.app.FragmentActivity; import androidx.recyclerview.widget.RecyclerView; import com.lqr.emoji.MoonUtils; @@ -21,6 +20,7 @@ import cn.wildfire.chat.kit.annotation.MessageContextMenuItem; import cn.wildfire.chat.kit.annotation.ReceiveLayoutRes; import cn.wildfire.chat.kit.annotation.SendLayoutRes; +import cn.wildfire.chat.kit.conversation.ConversationFragment; import cn.wildfire.chat.kit.conversation.message.model.UiMessage; import cn.wildfire.chat.kit.widget.LinkClickListener; import cn.wildfire.chat.kit.widget.LinkTextViewMovementMethod; @@ -35,17 +35,17 @@ public class TextMessageContentViewHolder extends NormalMessageContentViewHolder @BindView(R.id.contentTextView) TextView contentTextView; - public TextMessageContentViewHolder(FragmentActivity activity, RecyclerView.Adapter adapter, View itemView) { - super(activity, adapter, itemView); + public TextMessageContentViewHolder(ConversationFragment fragment, RecyclerView.Adapter adapter, View itemView) { + super(fragment, adapter, itemView); } @Override public void onBind(UiMessage message) { - MoonUtils.identifyFaceExpression(context, contentTextView, ((TextMessageContent) message.message.content).getContent(), ImageSpan.ALIGN_BOTTOM); + MoonUtils.identifyFaceExpression(fragment.getContext(), contentTextView, ((TextMessageContent) message.message.content).getContent(), ImageSpan.ALIGN_BOTTOM); contentTextView.setMovementMethod(new LinkTextViewMovementMethod(new LinkClickListener() { @Override public boolean onLinkClick(String link) { - WfcWebViewActivity.loadUrl(context, "", link); + WfcWebViewActivity.loadUrl(fragment.getContext(), "", link); return true; } })); @@ -53,13 +53,13 @@ public boolean onLinkClick(String link) { @OnClick(R.id.contentTextView) public void onClickTest(View view) { - Toast.makeText(context, "onTextMessage click: " + ((TextMessageContent) message.message.content).getContent(), Toast.LENGTH_SHORT).show(); + Toast.makeText(fragment.getContext(), "onTextMessage click: " + ((TextMessageContent) message.message.content).getContent(), Toast.LENGTH_SHORT).show(); } @MessageContextMenuItem(tag = MessageContextMenuItemTags.TAG_CLIP, title = "复制", confirm = false, priority = 12) public void clip(View itemView, UiMessage message) { - ClipboardManager clipboardManager = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); + ClipboardManager clipboardManager = (ClipboardManager) fragment.getContext().getSystemService(Context.CLIPBOARD_SERVICE); if (clipboardManager == null) { return; } diff --git a/chat/kit/src/main/java/cn/wildfire/chat/kit/conversation/message/viewholder/UnkownMessageContentViewHolder.java b/chat/kit/src/main/java/cn/wildfire/chat/kit/conversation/message/viewholder/UnkownMessageContentViewHolder.java index a1146bab9..02cbf6bc0 100644 --- a/chat/kit/src/main/java/cn/wildfire/chat/kit/conversation/message/viewholder/UnkownMessageContentViewHolder.java +++ b/chat/kit/src/main/java/cn/wildfire/chat/kit/conversation/message/viewholder/UnkownMessageContentViewHolder.java @@ -3,13 +3,14 @@ import android.view.View; import android.widget.TextView; -import androidx.fragment.app.FragmentActivity; import androidx.recyclerview.widget.RecyclerView; + import butterknife.BindView; import cn.wildfire.chat.kit.annotation.EnableContextMenu; import cn.wildfire.chat.kit.annotation.MessageContentType; import cn.wildfire.chat.kit.annotation.ReceiveLayoutRes; import cn.wildfire.chat.kit.annotation.SendLayoutRes; +import cn.wildfire.chat.kit.conversation.ConversationFragment; import cn.wildfire.chat.kit.conversation.message.model.UiMessage; import cn.wildfirechat.chat.R; import cn.wildfirechat.message.UnknownMessageContent; @@ -22,8 +23,8 @@ public class UnkownMessageContentViewHolder extends NormalMessageContentViewHold @BindView(R.id.contentTextView) TextView contentTextView; - public UnkownMessageContentViewHolder(FragmentActivity context, RecyclerView.Adapter adapter, View itemView) { - super(context, adapter, itemView); + public UnkownMessageContentViewHolder(ConversationFragment fragment, RecyclerView.Adapter adapter, View itemView) { + super(fragment, adapter, itemView); } @Override diff --git a/chat/kit/src/main/java/cn/wildfire/chat/kit/conversation/message/viewholder/VideoMessageContentViewHolder.java b/chat/kit/src/main/java/cn/wildfire/chat/kit/conversation/message/viewholder/VideoMessageContentViewHolder.java index d68e70aa7..d31a25cdc 100644 --- a/chat/kit/src/main/java/cn/wildfire/chat/kit/conversation/message/viewholder/VideoMessageContentViewHolder.java +++ b/chat/kit/src/main/java/cn/wildfire/chat/kit/conversation/message/viewholder/VideoMessageContentViewHolder.java @@ -11,10 +11,12 @@ import cn.wildfire.chat.kit.annotation.EnableContextMenu; import cn.wildfire.chat.kit.annotation.LayoutRes; import cn.wildfire.chat.kit.annotation.MessageContentType; +import cn.wildfire.chat.kit.conversation.ConversationFragment; import cn.wildfire.chat.kit.conversation.message.model.UiMessage; import cn.wildfire.chat.kit.widget.BubbleImageView; import cn.wildfirechat.chat.R; import cn.wildfirechat.message.VideoMessageContent; +import cn.wildfirechat.model.Conversation; @MessageContentType(VideoMessageContent.class) @LayoutRes(resId = R.layout.conversation_item_video_send) @@ -25,8 +27,8 @@ public class VideoMessageContentViewHolder extends MediaMessageContentViewHolder @BindView(R.id.playImageView) ImageView playImageView; - public VideoMessageContentViewHolder(FragmentActivity context, RecyclerView.Adapter adapter, View itemView) { - super(context, adapter, itemView); + public VideoMessageContentViewHolder(ConversationFragment fragment, RecyclerView.Adapter adapter, View itemView) { + super(fragment, adapter, itemView); } @Override diff --git a/chat/kit/src/main/java/cn/wildfire/chat/kit/conversation/message/viewholder/VoipMessageViewHolder.java b/chat/kit/src/main/java/cn/wildfire/chat/kit/conversation/message/viewholder/VoipMessageViewHolder.java index b1e8f7e69..3dbff214d 100644 --- a/chat/kit/src/main/java/cn/wildfire/chat/kit/conversation/message/viewholder/VoipMessageViewHolder.java +++ b/chat/kit/src/main/java/cn/wildfire/chat/kit/conversation/message/viewholder/VoipMessageViewHolder.java @@ -3,8 +3,8 @@ import android.view.View; import android.widget.TextView; -import androidx.fragment.app.FragmentActivity; import androidx.recyclerview.widget.RecyclerView; + import butterknife.BindView; import butterknife.ButterKnife; import butterknife.OnClick; @@ -13,6 +13,7 @@ import cn.wildfire.chat.kit.annotation.MessageContentType; import cn.wildfire.chat.kit.annotation.ReceiveLayoutRes; import cn.wildfire.chat.kit.annotation.SendLayoutRes; +import cn.wildfire.chat.kit.conversation.ConversationFragment; import cn.wildfire.chat.kit.conversation.message.model.UiMessage; import cn.wildfirechat.chat.R; import cn.wildfirechat.message.CallStartMessageContent; @@ -25,8 +26,8 @@ public class VoipMessageViewHolder extends NormalMessageContentViewHolder { @BindView(R.id.contentTextView) TextView textView; - public VoipMessageViewHolder(FragmentActivity activity, RecyclerView.Adapter adapter, View itemView) { - super(activity, adapter, itemView); + public VoipMessageViewHolder(ConversationFragment fragment, RecyclerView.Adapter adapter, View itemView) { + super(fragment, adapter, itemView); ButterKnife.bind(this, itemView); } @@ -58,6 +59,6 @@ public void call(View view) { if (((CallStartMessageContent) message.message.content).getStatus() == 1) { return; } - WfcUIKit.onCall(context, message.message.conversation.target, true, false); + WfcUIKit.onCall(fragment.getContext(), message.message.conversation.target, true, false); } } diff --git a/chat/src/main/java/cn/wildfire/chat/app/third/location/viewholder/LocationMessageContentViewHolder.java b/chat/src/main/java/cn/wildfire/chat/app/third/location/viewholder/LocationMessageContentViewHolder.java index 3a68a467c..cf97850bf 100644 --- a/chat/src/main/java/cn/wildfire/chat/app/third/location/viewholder/LocationMessageContentViewHolder.java +++ b/chat/src/main/java/cn/wildfire/chat/app/third/location/viewholder/LocationMessageContentViewHolder.java @@ -5,7 +5,6 @@ import android.widget.ImageView; import android.widget.TextView; -import androidx.fragment.app.FragmentActivity; import androidx.recyclerview.widget.RecyclerView; import com.bumptech.glide.Glide; @@ -17,6 +16,7 @@ import cn.wildfire.chat.kit.annotation.EnableContextMenu; import cn.wildfire.chat.kit.annotation.LayoutRes; import cn.wildfire.chat.kit.annotation.MessageContentType; +import cn.wildfire.chat.kit.conversation.ConversationFragment; import cn.wildfire.chat.kit.conversation.message.model.UiMessage; import cn.wildfire.chat.kit.conversation.message.viewholder.NormalMessageContentViewHolder; import cn.wildfire.chat.kit.third.utils.UIUtils; @@ -33,8 +33,8 @@ public class LocationMessageContentViewHolder extends NormalMessageContentViewHo @BindView(R.id.locationImageView) ImageView locationImageView; - public LocationMessageContentViewHolder(FragmentActivity context, RecyclerView.Adapter adapter, View itemView) { - super(context, adapter, itemView); + public LocationMessageContentViewHolder(ConversationFragment fragment, RecyclerView.Adapter adapter, View itemView) { + super(fragment, adapter, itemView); } @Override @@ -49,18 +49,18 @@ public void onBind(UiMessage message) { locationImageView.getLayoutParams().height = UIUtils.dip2Px(height > 200 ? 200 : height); locationImageView.setImageBitmap(locationMessage.getThumbnail()); } else { - Glide.with(context).load(R.mipmap.default_location) + Glide.with(fragment).load(R.mipmap.default_location) .apply(new RequestOptions().override(UIUtils.dip2Px(200), UIUtils.dip2Px(200)).centerCrop()).into(locationImageView); } } @OnClick(R.id.locationLinearLayout) public void onClick(View view) { - Intent intent = new Intent(context, ShowLocationActivity.class); + Intent intent = new Intent(fragment.getContext(), ShowLocationActivity.class); LocationMessageContent content = (LocationMessageContent) message.message.content; intent.putExtra("Lat", content.getLocation().getLatitude()); intent.putExtra("Long", content.getLocation().getLongitude()); intent.putExtra("title", content.getTitle()); - context.startActivity(intent); + fragment.startActivity(intent); } }