wangkai

添加详情页

Showing 54 changed files with 3816 additions and 22 deletions

Too many changes to show.

To preserve performance only 54 of 54+ files are displayed.

/build
\ No newline at end of file
... ...
configurations.maybeCreate("default")
artifacts.add("default", file('materialiconlib-1.1.5.aar'))
\ No newline at end of file
... ...
/build
\ No newline at end of file
... ...
configurations.maybeCreate("default")
artifacts.add("default", file('videocache-2.7.1.aar'))
\ No newline at end of file
... ...
/build
\ No newline at end of file
... ...
configurations.maybeCreate("default")
artifacts.add("default", file('doraemonlibrary_v1.5.0_release.aar'))
artifacts.add("default", file('main-2.2.1-release.aar'))
artifacts.add("default", file('logger-2.2.1-release.aar'))
\ No newline at end of file
... ...
/build
\ No newline at end of file
... ...
configurations.maybeCreate("default")
artifacts.add("default", file('auth_number_product-2.13.2.1-release.aar'))
\ No newline at end of file
... ...
/build
\ No newline at end of file
... ...
configurations.maybeCreate("default")
artifacts.add("default", file('etas-release_20240131.aar'))
\ No newline at end of file
... ...
/build
\ No newline at end of file
... ...
configurations.maybeCreate("default")
artifacts.add("default", file('nuisdk-release-V2.5.14-01B-20230807_Android.aar'))
\ No newline at end of file
... ...
/build
\ No newline at end of file
... ...
No preview for this file type
configurations.maybeCreate("default")
artifacts.add("default", file('ability-1.1.3.1.aar'))
\ No newline at end of file
... ...
/build
\ No newline at end of file
... ...
configurations.maybeCreate("default")
artifacts.add("default", file('framework-1.1.2.1.aar'))
\ No newline at end of file
... ...
... ... @@ -64,6 +64,8 @@ dependencies {
implementation project(path: ':module_home')
implementation project(path: ':module_videoplayer')
implementation project(path: ':module_personalcenter')
// annotationProcessor 'com.alibaba:arouter-compiler:1.5.2'
implementation project(path: ':lib_jsbridge')
implementation project(path: ':base_webview')
implementation project(path: ':base_comment')
}
\ No newline at end of file
... ...
... ... @@ -9,14 +9,16 @@
android:required="false" />
<application
android:name=".MyApplication"
android:allowBackup="true"
android:allowBackup="false"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_fastcode"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_fastcode"
android:supportsRtl="true"
android:theme="@style/Theme.MyApplication"
tools:targetApi="31">
android:theme="@style/AppTheme"
android:usesCleartextTraffic="true"
tools:ignore="Instantiatable"
tools:replace="android:allowBackup,android:name">
<activity
android:name=".MainActivity"
... ...
package com.wd.fastcoding.app;
import android.app.Application;
import com.wd.capability.network.RetrofitClient;
import com.wd.foundation.wdinterfaceimpl.interceptor.TokenInterceptor;
import com.wd.capability.router.ArouteInit;
import com.wd.foundation.wdkit.utils.CommonUtil;
import com.wd.common.base.BaseApplication;
import com.wd.fastcoding.app.start.StartTaskConfig;
import com.wd.foundation.wdkit.utils.CommonUtil;
import com.wd.foundation.wdkitcore.tools.AppContext;
import com.wd.foundation.wdkitcore.tools.StringUtils;
import okhttp3.Interceptor;
/**
* @author devel
* @time 2024/8/28 星期三 16:23
*/
public class MyApplication extends Application {
public class MyApplication extends BaseApplication {
@Override
public void onCreate() {
super.onCreate();
... ... @@ -52,4 +48,62 @@ public class MyApplication extends Application {
String name = getPackageName();
return StringUtils.isEmpty(curProcessName) || StringUtils.isEmpty(name) || name.equals(curProcessName);
}
@Override
public void countDownTimerChange(int i) {
super.countDownTimerChange(i);
// if (0 == i|| 1 == i) {
// // 更新倒计时文本
// PlayerManagerUtils.setTimer(0L);
// PlayerManager.getInstance().updateDownCount();
// if (mCountDownTimer != null) {
// // 取消倒计时
// mCountDownTimer.cancel();
// }
// return;
// }
// // 创建一个持续时间为 30 分钟的倒计时器,并设置倒计时间隔为 1 秒
// int time;
// switch (i) {
// case 3:
// time = 20;
// break;
// case 4:
// time = 30;
// break;
// case 5:
// time = 60;
// break;
// default:
// time = 10;
// break;
// }
// if (mCountDownTimer != null){
// mCountDownTimer.cancel();
// mCountDownTimer = null;
// }
// CustomCountDownTimer.OnCountDownListener listener = new CustomCountDownTimer.OnCountDownListener() {
// @Override
// public void onTick(long millisUntilFinished) {
// // 更新倒计时文本
// PlayerManagerUtils.setTimer(millisUntilFinished);
// PlayerManager.getInstance().updateDownCount();
// }
//
// @Override
// public void onFinish() {
// PlayerManagerUtils.pauseAudio();
// // 更新倒计时文本
// PlayerManagerUtils.setTimer(0L);
// PlayerManager.getInstance().updateDownCount();
// }
// };
//// if(i == 1){
//// mCountDownTimer = new CustomCountDownTimer(PlayerManager.getInstance().getResidueDuration(),1000,listener);
//// }else{
// mCountDownTimer = CustomCountDownTimer.create(time, listener);
//// }
// // 开始倒计时
// mCountDownTimer.start();
}
}
... ...
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="Theme.MyApplication" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<!-- Primary brand color. -->
<item name="colorPrimary">@color/purple_500</item>
<item name="colorPrimaryVariant">@color/purple_700</item>
<item name="colorOnPrimary">@color/white</item>
<!-- Secondary brand color. -->
<item name="colorSecondary">@color/teal_200</item>
<item name="colorSecondaryVariant">@color/teal_700</item>
<item name="colorOnSecondary">@color/black</item>
<!-- Status bar color. -->
<item name="android:statusBarColor">?attr/colorPrimaryVariant</item>
<style name="AppTheme" parent="Theme.AppCompat.DayNight.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/white</item>
<item name="colorPrimaryDark">@color/white</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:forceDarkAllowed" tools:targetApi="q">false</item>
</style>
</resources>
\ No newline at end of file
... ...
/build
\ No newline at end of file
... ...
plugins {
id 'com.android.library'
id 'kotlin-android'
}
android {
compileSdkVersion var.compileSdkVersion
buildToolsVersion var.buildToolsVersion
defaultConfig {
minSdkVersion var.minSdkVersion
targetSdkVersion var.targetSdkVersion
versionCode var.versionCode
versionName var.versionName
consumerProguardFiles "consumer-rules.pro"
javaCompileOptions {
annotationProcessorOptions {
arguments = [AROUTER_MODULE_NAME: project.getName()]
}
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
api rootProject.ext.dependencies["gson"]
// implementation project(path: ':base_umeng')
implementation project(path: ':base_speech')
api project(path: ':lib_base')
implementation project(':aar_repo:lib_speech')
implementation rootProject.ext.dependencies["eventbus"]
implementation rootProject.ext.support["legacy-support"]
annotationProcessor rootProject.ext.dependencies["arouter-compiler"]
// //图片选择
// implementation project(path: ':base_matisse')
// implementation project(path: ':lib_library')
}
\ No newline at end of file
... ...
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
\ No newline at end of file
... ...
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.people.comment">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<application></application>
</manifest>
\ No newline at end of file
... ...
package com.people.comment.adapter;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import com.people.comment.R;
import com.people.comment.view_holder.CommentChildViewHolder;
import com.people.comment.view_holder.CommentParentViewHolder;
import com.people.comment.view_holder.CommentTitleViewHolder;
import com.people.comment.view_holder.EmptyCommentViewHolder;
import com.people.comment.view_holder.MoreCommentViewHolder;
import com.people.comment.view_holder.NoMoreCommentViewHolder;
import com.wd.common.constant.PageNameConstants;
import com.wd.common.widget.DefaultView;
import com.wd.foundation.bean.custom.content.CommentItem;
import com.wd.foundation.wdkitcore.tools.ResUtils;
import java.util.ArrayList;
import java.util.List;
/**
* @Author LiuKun
* @date:2023/5/9
* @desc:评论适配器 详情页页面底部评论列表布局
*/
public class CommentListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
public static final int COMMENT_TYPE_ERROR = -1;
public static final int COMMENT_TYPE_PARENT = 1;
public static final int COMMENT_TYPE_CHILD = 2;
public static final int COMMENT_TYPE_MORE = 3;
public static final int COMMENT_TYPE_EMPTY = 4;
public static final int COMMENT_TYPE_FOOTER = 5;
public static final int COMMENT_TYPE_HIGHQUALITY = 6;
/**
* 标题
*/
public static final int COMMENT_TYPE_TITLE = 7;
private Context context;
private List<CommentItem> mData = new ArrayList<>();
private CommentAdapterListener mListener;
private DefaultView.RetryClickListener retryClickListener;
private String pageName;
private boolean isDarkMode = false;
public CommentListAdapter(Context context) {
mData.clear();
this.context = context;
}
public CommentListAdapter(Context context, boolean isDarkMode) {
mData.clear();
this.context = context;
this.isDarkMode = isDarkMode;
}
public CommentListAdapter(Context context, String fromPage) {
mData.clear();
this.context = context;
this.pageName = fromPage;
}
public void setData(List<CommentItem> data) {
mData.clear();
mData.addAll(data);
notifyDataSetChanged();
}
public List<CommentItem> getData() {
return mData;
}
/**
* 列表翻页添加数据
*/
public void addData(List<CommentItem> data, int startPosition) {
mData.addAll(data);
notifyItemRangeInserted(startPosition, data.size());
}
/**
* 删除单条数据
*/
public void removeSingleData(int position) {
mData.remove(position);
notifyItemRemoved(position);
notifyDataSetChanged();
}
/**
* 删除单条数据
*/
public void removeData(ArrayList<CommentItem> toRemove) {
for (int i = toRemove.size() - 1; i >= 0; i--) {
mData.remove(toRemove.get(i));
notifyItemRemoved(i);
}
notifyDataSetChanged();
}
/**
* 按指定位置添加某条数据
*/
public void addPositionData(int position, CommentItem itemBean) {
if (isAddEmptyOrErrorData()) {
mData.clear();
mData.add(itemBean);
notifyItemChanged(position);
} else {
mData.add(position, itemBean);
notifyItemRangeInserted(position, 1);
}
}
/**
* 插入二级数据
*/
public void insertData(int startPosition, List<CommentItem> data) {
mData.addAll(startPosition, data);
notifyItemRangeInserted(startPosition, data.size());
}
/**
* 收起二级数据
*/
public void rangeRemoveData(int startRangePosition, List<CommentItem> removeSecondList) {
mData.removeAll(removeSecondList);
notifyItemRangeRemoved(startRangePosition, removeSecondList.size());
}
/**
* 清除数据
*/
public void clearData() {
mData.clear();
notifyDataSetChanged();
}
/**
* 添加空数据
*/
public void addEmptyOrErrorData(CommentItem itemBean,int type) {
mData.clear();
if(type == 0){
CommentItem newTitleCommentObj = new CommentItem();
newTitleCommentObj.setCommentLevel(CommentListAdapter.COMMENT_TYPE_TITLE);
newTitleCommentObj.setItemType(-1);
newTitleCommentObj.setItemTitle("评论");
mData.add(newTitleCommentObj);
}
mData.add(itemBean);
notifyDataSetChanged();
}
/**
* 添加没有更多数据
*/
public void addNoMoreData(CommentItem itemBean) {
mData.add(itemBean);
notifyDataSetChanged();
}
/**
* 是否已显示空布局
*
* @return
*/
private boolean isAddEmptyOrErrorData() {
if (!isEmpty(mData) && mData.size() == 1) {
if (mData.get(0).getCommentLevel() == CommentListAdapter.COMMENT_TYPE_EMPTY
|| (mData.get(0).getCommentLevel() == CommentListAdapter.COMMENT_TYPE_ERROR)) {
return true;
}
}
return false;
}
/**
* 集合是否为空
*/
public static <D> boolean isEmpty(List<D> list) {
return list == null || list.isEmpty();
}
/**
* 重试按钮
* @param retryClickListener
*/
public void setRetryClickListener(DefaultView.RetryClickListener retryClickListener) {
this.retryClickListener = retryClickListener;
}
/**
* 加载数据
*/
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
//上层评论
if (viewType == COMMENT_TYPE_PARENT) {
View view = LayoutInflater.from(context).inflate(R.layout.item_comment_parent, parent, false);
return new CommentParentViewHolder(view, mListener, COMMENT_TYPE_PARENT);
}
//子评论
else if (viewType == COMMENT_TYPE_CHILD) {
View view = LayoutInflater.from(context).inflate(R.layout.item_comment_child, parent, false);
return new CommentChildViewHolder(view, mListener, COMMENT_TYPE_CHILD);
}
//更多评论
else if (viewType == COMMENT_TYPE_MORE) {
View view = LayoutInflater.from(context).inflate(R.layout.item_comment_more, parent, false);
return new MoreCommentViewHolder(view, mListener);
}
//没有更多评论
else if (viewType == COMMENT_TYPE_FOOTER) {
View view = LayoutInflater.from(context).inflate(R.layout.item_comment_no_more, parent, false);
return new NoMoreCommentViewHolder(view, mListener);
}
//评论标题
else if (viewType == COMMENT_TYPE_TITLE) {
View view = LayoutInflater.from(context).inflate(R.layout.item_comment_title, parent, false);
return new CommentTitleViewHolder(view);
}
//没有评论信息
else {
EmptyCommentViewHolder emptyCommentViewHolder;
View view = LayoutInflater.from(context).inflate(R.layout.item_comment_empty, parent, false);
if (PageNameConstants.DYNAMIC_DETAIL_PAGE.equals(pageName)||
PageNameConstants.ARTICLE_DETAIL_PAGE.equals(pageName)) {
//1、网络问题需要重试,2、默认无数据处理
if (viewType == COMMENT_TYPE_ERROR){
emptyCommentViewHolder = new EmptyCommentViewHolder(view,
(int) ResUtils.getDimension(R.dimen.rmrb_dp32),
(int) ResUtils.getDimension(R.dimen.rmrb_dp50), (int) ResUtils.getDimension(R.dimen.rmrb_dp258),-1, () -> {
if (retryClickListener != null){
retryClickListener.onRetryClick();
}
});
}else {
emptyCommentViewHolder = new EmptyCommentViewHolder(view,
(int) ResUtils.getDimension(R.dimen.rmrb_dp32),
(int) ResUtils.getDimension(R.dimen.rmrb_dp50), (int) ResUtils.getDimension(R.dimen.rmrb_dp258),0, null);
}
return emptyCommentViewHolder;
}else if(PageNameConstants.POLITICS_DETAIL_PAGE.equals(pageName)){
if (viewType == COMMENT_TYPE_ERROR){
//网络问题需要重试
emptyCommentViewHolder = new EmptyCommentViewHolder(view,
1, 1
, (int) ResUtils.getDimension(R.dimen.rmrb_dp258), -1, () -> {
if (retryClickListener != null){
retryClickListener.onRetryClick();
}
});
}else {
emptyCommentViewHolder = new EmptyCommentViewHolder(view,
1, 1
, (int) ResUtils.getDimension(R.dimen.rmrb_dp258),0,null);
}
return emptyCommentViewHolder;
}else {
if (viewType == COMMENT_TYPE_ERROR){
emptyCommentViewHolder = new EmptyCommentViewHolder(view,
1,
1, -1, () -> {
if (retryClickListener != null){
retryClickListener.onRetryClick();
}
});
}else {
emptyCommentViewHolder = new EmptyCommentViewHolder(view);
}
return emptyCommentViewHolder;
}
}
}
@Override
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
//父评论
if (holder instanceof CommentParentViewHolder) {
if(position == 0){
((CommentParentViewHolder) holder).getRoot().setPadding(0,-(int) ResUtils.getDimension(R.dimen.rmrb_dp2)
,0,(int) ResUtils.getDimension(R.dimen.rmrb_dp6));
}else{
((CommentParentViewHolder) holder).getRoot().setPadding(0,(int) ResUtils.getDimension(R.dimen.rmrb_dp8)
,0,(int) ResUtils.getDimension(R.dimen.rmrb_dp6));
}
((CommentParentViewHolder) holder).updateData(mData.get(position),COMMENT_TYPE_PARENT,isDarkMode);
}
//子评论
else if (holder instanceof CommentChildViewHolder) {
((CommentChildViewHolder) holder).updateData(mData.get(position), isDarkMode);
}
//二级评论分页查看更多回复
else if (holder instanceof MoreCommentViewHolder) {
CommentItem covertCommentBean = mData.get(position);
String realCommentContent = covertCommentBean.getRealCommentContent();
boolean showExpandChild = covertCommentBean.isShowExpandChild();
boolean showCloseChild = covertCommentBean.isShowCloseChild();
((MoreCommentViewHolder) holder)
.setMoreContent(realCommentContent)
.setExpandVisible(showExpandChild)
.setCloseTvVisible(showCloseChild);
}
//没有更多数据
else if (holder instanceof NoMoreCommentViewHolder) {
CommentItem covertCommentBean = mData.get(position);
((NoMoreCommentViewHolder) holder).setNoMoreContent(covertCommentBean.getRealCommentContent());
}
//标题
else if (holder instanceof CommentTitleViewHolder) {
CommentItem covertCommentBean = mData.get(position);
((CommentTitleViewHolder) holder).updateData(covertCommentBean);
}
}
/**
* 获取所有数据
*/
@Override
public int getItemCount() {
return mData.size();
}
/**
* 获取布局类型
*/
@Override
public int getItemViewType(int position) {
CommentItem entity = mData.get(position);
return entity.getCommentLevel();
}
/**
* 设置监听
*/
public void setCommentAdapterListener(CommentAdapterListener listener) {
mListener = listener;
}
/**
*加载更多
*/
/**
* 接口监听
*/
public interface CommentAdapterListener {
/**
* 回复
* @param position
*/
void replyComment(int position);
/**
* 二级回复
* @param position
*/
void loadSecondLevelComment(int position);
/**
* 关闭展开
* @param position
*/
void closeListComment(int position);
/**
* 点赞
* @param position
*/
void commentLike(int position);
/**
* 点击用户头像
* @param position
*/
void clickHead(int position);
/**
* 点击内容展开、收起
* @param position
* @param type
*/
void clickExpandOrShrink(int position, int type);
/**
* 长按弹窗海报
* @param position
*/
void commentLongClick(int position);
}
}
... ...
package com.people.comment.adapter;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import com.people.comment.R;
import com.people.comment.bean.EmojiEntity;
import java.util.List;
/**
* @author LiuKun
* @date 2023/5/2 18:48
* @Description:表情适配器
*/
public class ExpressionGridViewAdapter extends BaseAdapter {
private static final int ITEM_LAYOUT_TYPE_COUNT = 2;
private static final int TYPE_TEXT = 0;
private static final int TYPE_IMAGE = 1;
private LayoutInflater inflater;
private Context context;
private List<EmojiEntity> emojiList;
public ExpressionGridViewAdapter(Context context, List<EmojiEntity> emojiList) {
this.context = context;
this.emojiList = emojiList;
inflater = LayoutInflater.from(context);
}
@Override
public int getCount() {
return emojiList.size();
}
@Override
public EmojiEntity getItem(int position) {
return emojiList.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public int getViewTypeCount() {
return ITEM_LAYOUT_TYPE_COUNT;
}
@Override
public int getItemViewType(int position) {
if (position == 20) {
return TYPE_IMAGE;
} else {
return TYPE_TEXT;
}
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
int layoutType = getItemViewType(position);
if (TYPE_TEXT == layoutType) {
TextHolder viewHolder;
if (convertView == null) {
viewHolder = new TextHolder();
convertView = inflater.inflate(R.layout.adapter_row_expression, parent, false);
viewHolder.textView = (TextView) convertView.findViewById(R.id.tv_expression);
convertView.setTag(viewHolder);
} else {
viewHolder = (TextHolder) convertView.getTag();
}
viewHolder.textView.setText(getItem(position).code);
} else if (TYPE_IMAGE == layoutType) {
if (convertView == null) {
convertView = inflater.inflate(R.layout.adapter_row_expression_img, parent, false);
}
}
return convertView;
}
private class TextHolder {
TextView textView;
}
}
... ...
package com.people.comment.adapter;
import android.view.View;
import android.view.ViewGroup;
import androidx.viewpager.widget.PagerAdapter;
import java.util.List;
/**
* @author LiuKun
* @date 2023/5/2 18:52
* @Description:适配器
*/
public class ExpressionPagerAdapter extends PagerAdapter {
private List<View> views;
public ExpressionPagerAdapter(List<View> views) {
this.views = views;
}
@Override
public int getCount() {
return views.size();
}
@Override
public boolean isViewFromObject(View view, Object object) {
return view == object;
}
@Override
public Object instantiateItem(ViewGroup container, int position) {
container.addView(views.get(position));
return views.get(position);
}
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
container.removeView(views.get(position));
}
}
... ...
package com.people.comment.adapter;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.FrameLayout;
import android.widget.ImageView;
import com.people.comment.R;
import com.wd.common.imageglide.ImageUtils;
import com.wd.foundation.wdkit.utils.ScreenUtils;
import java.util.ArrayList;
import java.util.List;
/**
* @author qtiansheng
* @date 2024/2/6
* @Description 定制表情况图片适配器
* @doc
*/
public class ImageAdapter extends BaseAdapter {
private Context mContext;
/**
* 图片资源ID数组
*/
private List<String> mImageUrls;
private LayoutInflater inflater;
/**
* 构造函数
* @param context
* @param gifIcons
*/
public ImageAdapter(Context context, List<String> gifIcons) {
mContext = context;
mImageUrls = new ArrayList<String>();
if(gifIcons!= null && !gifIcons.isEmpty()) {
mImageUrls.addAll(gifIcons);
}
inflater = LayoutInflater.from(mContext);
}
@Override
public int getCount() {
if(mImageUrls != null && mImageUrls.size() > 0){
return mImageUrls.size();
}else{
return 0;
}
}
@Override
public Object getItem(int position) {
return position;
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ImageHolder viewHolder;
if (convertView == null) {
viewHolder = new ImageHolder();
convertView = inflater.inflate(R.layout.item_emoji_gif, parent, false);
viewHolder.imgLayout = (FrameLayout) convertView.findViewById(R.id.layout_gif);
viewHolder.imageView = (ImageView) convertView.findViewById(R.id.iv_gifview);
convertView.setTag(viewHolder);
} else {
viewHolder = (ImageHolder) convertView.getTag();
}
//最后一行设置下滑动间距
if(position == getCount() - 1){
ViewGroup.LayoutParams layoutParams = (ViewGroup.LayoutParams) viewHolder.imgLayout.getLayoutParams();
layoutParams.height = ScreenUtils.dpToPx(80);
viewHolder.imgLayout.setLayoutParams(layoutParams);
viewHolder.imgLayout.setPadding(0,0,0,ScreenUtils.dpToPx(20));
}
// 设置图片资源ID对应的图片资源到ImageView中
ImageUtils.getInstance().loadImageCanSameUrl(viewHolder.imageView,mImageUrls.get(position));
return convertView;
}
public void setDataList(List<String> listStr) {
mImageUrls.clear();
mImageUrls.addAll(listStr);
notifyDataSetChanged();
}
private class ImageHolder {
FrameLayout imgLayout;
ImageView imageView;
}
}
\ No newline at end of file
... ...
package com.people.comment.adapter;
import android.graphics.Typeface;
import android.text.Spannable;
import android.text.SpannableStringBuilder;
import android.text.TextPaint;
import android.text.TextUtils;
import android.text.method.LinkMovementMethod;
import android.text.style.ClickableSpan;
import android.text.style.StyleSpan;
import android.view.Gravity;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.core.content.ContextCompat;
import com.chad.library.adapter.base.BaseViewHolder;
import com.people.comment.R;
import com.wd.common.base.BaseSplitAdapter;
import com.wd.common.imageglide.ImageUtils;
import com.wd.common.viewclick.BaseClickListener;
import com.wd.common.widget.ExpandableTextView;
import com.wd.foundation.bean.custom.content.CommentItem;
import com.wd.foundation.bean.response.ParentCommentVoBean;
import com.wd.foundation.bean.utils.TimeUtil;
import com.wd.foundation.wdkit.perloader.DeviceHelper;
import com.wd.foundation.wdkit.utils.NumberStrUtils;
import com.wd.foundation.wdkit.view.AnimationView;
import com.wd.foundation.wdkit.view.RoundImageView;
import com.wd.foundation.wdkitcore.tools.AppContext;
import com.wd.foundation.wdkitcore.tools.StringUtils;
/**
* 查看自己/他人的评论列表适配器
* * @author ouyang
* * @version [V1.0.0, 2023/5/10]
*/
public class MyCommentListAdapter extends BaseSplitAdapter<CommentItem, BaseViewHolder> {
public OnAdapterClickListener mOnAdapterClickListener;
public OnMyLongClickListener mOnMyLongClickListener;
/**
* 加V
*/
private String authIcon;
/**
* 荣誉头像框
*/
private String honoraryIcon;
/**
* 等级头像框
*/
private String levelIcon;
public MyCommentListAdapter() {
super(R.layout.item_my_comment_list);
// addChildClickViewIds(R.id.tv_original_news_title,R.id.iv_like);
}
@Override
protected void convert(@NonNull BaseViewHolder baseViewHolder, CommentItem item) {
if (item==null) {
return;
}
ConstraintLayout cl_root = baseViewHolder.getView(R.id.cl_root);
ConstraintLayout cl_bottom = baseViewHolder.getView(R.id.cl_bottom);
RoundImageView iv_header_image = baseViewHolder.getView(R.id.iv_header_image);
//头像
if (item != null && StringUtils.isNotBlank(item.getFromUserType()) && !"1".equals(item.getFromUserType())){
ImageUtils.getInstance().
loadImageCircle(iv_header_image, item.getFromUserHeader(), R.mipmap.icon_default_head_mater);
}else {
ImageUtils.getInstance().
loadImageCircle(iv_header_image, item.getFromUserHeader(), R.mipmap.icon_default_head);
}
//加V
ImageView ivvip = baseViewHolder.getView(R.id.ivvip);
if(TextUtils.isEmpty(authIcon)){
ivvip.setVisibility(View.GONE);
}else{
ImageUtils.getInstance().loadImage(ivvip, authIcon);
ivvip.setVisibility(View.VISIBLE);
}
//头像框
ImageView ivAvatarFrame = baseViewHolder.getView(R.id.iv_avatar_frame);
setUserAvatarFrame(ivAvatarFrame, item);
TextView tv_name = baseViewHolder.getView(R.id.tv_name);
tv_name.setText(StringUtils.getStringValue(item.getFromUserName()));
tv_name.getPaint().setFakeBoldText(true);
TextView tv_date = baseViewHolder.getView(R.id.tv_date);
setTime(tv_date, TimeUtil.converTimeForm(item.getCreateTime()));
LinearLayout ll_like = baseViewHolder.getView(R.id.ll_like);
TextView tv_like_number = baseViewHolder.getView(R.id.tv_like_number);
tv_like_number.getPaint().setFakeBoldText(true);
AnimationView iv_like = baseViewHolder.getView(R.id.iv_like);
setLikeData(ll_like,tv_like_number,iv_like,item.getLikeNum(),item.getLikeStatus(),item.getCheckStatus());
ExpandableTextView tv_my_content = baseViewHolder.getView(R.id.tv_my_content);
setContent(tv_my_content,item);
//我的评论动画表情
ImageView ivMyComment = baseViewHolder.getView(R.id.iv_my_comment);
setContentPic(ivMyComment,item.getCommentPics());
ExpandableTextView tv_original_comment_content = baseViewHolder.getView(R.id.tv_original_comment_content);
View line_view = baseViewHolder.getView(R.id.line_view);
//评论所属内容的删除状态,0:有效;1:删除
TextView tv_original_news_title = baseViewHolder.getView(R.id.tv_original_news_title);
int targetStatus = item.getTargetStatus();
if (targetStatus==0) {
tv_original_news_title.setText(StringUtils.getStringValue(item.getTargetTitle()));
// tv_original_news_title.setTextColor(ContextCompat.getColor(getContext(),R.color.res_color_common_C1));
tv_original_news_title.setGravity(Gravity.LEFT);
}else{
tv_original_news_title.setText("抱歉,原内容已被删除");
tv_original_news_title.setGravity(Gravity.CENTER);
}
tv_original_news_title.setTextColor(ContextCompat.getColor(AppContext.getContext(),R.color.res_color_common_C2));
ParentCommentVoBean mParentCommentVoBean = item.getParentCommentVo();
if (mParentCommentVoBean==null) {
tv_original_comment_content.setVisibility(View.GONE);
line_view.setVisibility(View.GONE);
}else{
tv_original_comment_content.setVisibility(View.VISIBLE);
line_view.setVisibility(View.VISIBLE);
String user_name = mParentCommentVoBean.getFromUserName();
handleOriginalCommentContent(tv_original_comment_content,"@"+user_name+": "+mParentCommentVoBean.getCommentContent(),user_name.length()+2);
}
View bottomLine = baseViewHolder.getView(R.id.line_bottom);
int position = getItemPosition(item);
//设置分割线
int itemCount = getItemCount();
if(itemCount > 1 && position == itemCount - 2){
bottomLine.setVisibility(View.GONE);
}else {
bottomLine.setVisibility(View.VISIBLE);
}
MyOnLongClickListener mMyOnLongClickListener = new MyOnLongClickListener(position);
cl_root.setOnLongClickListener(mMyOnLongClickListener);
tv_my_content.setOnLongClickListener(mMyOnLongClickListener);
cl_bottom.setOnLongClickListener(mMyOnLongClickListener);
}
/**
* 设置评论图片
*/
public void setContentPic(ImageView ivMyComment, String picUrl) {
if (null == ivMyComment){
return;
}
if (!TextUtils.isEmpty(picUrl)) {
ivMyComment.setVisibility(View.VISIBLE);
if (picUrl.contains(",")) {
picUrl = picUrl.split(",")[0];
}
ImageUtils.getInstance().loadImageHighLev(ivMyComment, picUrl, R.drawable.rmrb_placeholder_compe_all);
} else {
ivMyComment.setVisibility(View.GONE);
}
}
public void setAuthIcon(String authIcon) {
this.authIcon = authIcon;
}
public void setHonoraryIcon(String honoraryIcon) {
this.honoraryIcon = honoraryIcon;
}
public void setLevelIcon(String levelIcon) {
this.levelIcon = levelIcon;
}
private void setUserAvatarFrame(ImageView ivAvatarFrame, CommentItem item){
ivAvatarFrame.setVisibility(View.GONE);
if ("1".equals(item.getFromUserType())){
// V>普通用户显示最佳评论员>等级头像框
if (StringUtils.isBlank(authIcon)){
if (StringUtils.isNotBlank(item.avatarFrame)){
ImageUtils.getInstance().loadImage(ivAvatarFrame,item.avatarFrame);
ivAvatarFrame.setVisibility(View.VISIBLE);
}else if (StringUtils.isNotBlank(levelIcon)){
ImageUtils.getInstance().loadImage(ivAvatarFrame,levelIcon);
ivAvatarFrame.setVisibility(View.VISIBLE);
}
}
}else {
// 号主显示荣誉头像,V>最佳评论员头像,不显示等级框
if (StringUtils.isNotBlank(honoraryIcon)){
ImageUtils.getInstance().loadImage(ivAvatarFrame,honoraryIcon);
ivAvatarFrame.setVisibility(View.VISIBLE);
}else {
//没有荣誉框且没有V才显示最佳评论员
if (StringUtils.isBlank(authIcon) && StringUtils.isNotBlank(item.avatarFrame)){
ImageUtils.getInstance().loadImage(ivAvatarFrame,item.avatarFrame);
ivAvatarFrame.setVisibility(View.VISIBLE);
}
}
}
}
/**
* 长按事件
*/
private class MyOnLongClickListener implements View.OnLongClickListener {
private int position;
public MyOnLongClickListener(int position){
this.position = position;
}
@Override
public boolean onLongClick(View v) {
if (mOnMyLongClickListener!=null) {
return mOnMyLongClickListener.OnMyLongClick(position);
}else{
return false;
}
}
}
/**
* 设置评论内容
*/
public void setContent(ExpandableTextView tv_my_content, CommentItem item) {
String content = item.getRealCommentContent();
int expandableStatus = item.getExpandableStatus();
if (!StringUtils.isBlank(content)) {
tv_my_content.setVisibility(View.VISIBLE);
tv_my_content.updateForRecyclerView(content, DeviceHelper.getRealWidth(AppContext.getContext()), expandableStatus);
//描述内容
tv_my_content.setExpandListener(new ExpandableTextView.OnExpandListener() {
int bindingAdapterPosition = getItemPosition(item);
@Override
public void onExpand(ExpandableTextView view) {
if(mOnAdapterClickListener !=null){
mOnAdapterClickListener.clickExpandOrShrink(bindingAdapterPosition, ExpandableTextView.STATE_EXPAND);
}
}
@Override
public void onShrink(ExpandableTextView view) {
if (mOnAdapterClickListener != null) {
mOnAdapterClickListener.clickExpandOrShrink(bindingAdapterPosition, ExpandableTextView.STATE_SHRINK);
}
}
});
} else {
tv_my_content.setVisibility(View.GONE);
}
}
public void setLikeData(LinearLayout ll_like,TextView tv_like_number,AnimationView iv_like,String likeNum, int likeStatus, int checkStatus) {
iv_like.setNeedLogin(true);
//checkStatus评论审核状态,0:未审核;1:审核中;2:通过;3:不通过 只有审核通过的才显示回复按钮
// if (checkStatus==2) {
ll_like.setVisibility(View.VISIBLE);
if (TextUtils.isEmpty(likeNum) || "0".equals(likeNum)) {
tv_like_number.setVisibility(View.GONE);
}else{
tv_like_number.setVisibility(View.VISIBLE);
tv_like_number.setText(NumberStrUtils.Companion.getINSTANCE().handlerNumber(String.valueOf(likeNum)));
}
if (likeStatus == 1) {
iv_like.setSelected(true);
tv_like_number.setTextColor(ContextCompat.getColor(AppContext.getContext(),R.color.res_color_common_C11));
}else{
iv_like.setSelected(false);
tv_like_number.setTextColor(ContextCompat.getColor(AppContext.getContext(),R.color.res_color_common_C2));
}
// }else{
// ll_like.setVisibility(View.GONE);
// }
}
/**
* 设置评论时间
*/
public void setTime(TextView tv_date,String adapterCommentDate) {
if (!TextUtils.isEmpty(adapterCommentDate)) {
tv_date.setVisibility(View.VISIBLE);
tv_date.setText(adapterCommentDate);
} else {
tv_date.setVisibility(View.GONE);
}
}
private void handleOriginalCommentContent(TextView tv_original_comment_content, String value, int handleLength) {
if (StringUtils.isBlank(value)) {
return;
}
if (value.length() < handleLength) {
return;
}
SpannableStringBuilder builder = new SpannableStringBuilder(value);
builder.setSpan(new StyleSpan(Typeface.BOLD), 0, handleLength, Spannable.SPAN_INCLUSIVE_INCLUSIVE);
//设置文本点击事件
builder.setSpan(new PrivacyPolicyDialogClickSpannable(new BaseClickListener() {
@Override
protected void onNoDoubleClick(View v) {
if(mOnAdapterClickListener !=null){
mOnAdapterClickListener.OnClickName();
}
}
}), 0, handleLength,Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
tv_original_comment_content.setMovementMethod(LinkMovementMethod.getInstance());
tv_original_comment_content.setText(builder);
}
private int getItemPosition(CommentItem item) {
return item != null && this.mData != null && !this.mData.isEmpty() ? this.mData.indexOf(item) : -1;
}
/**
* SpannableStringBuilder 点击事件
*/
public class PrivacyPolicyDialogClickSpannable extends ClickableSpan implements
View.OnClickListener {
private BaseClickListener onClickListener;
public PrivacyPolicyDialogClickSpannable(BaseClickListener onClickListener) {
this.onClickListener = onClickListener;
}
@Override
public void onClick(View widget) {
// onClickListener.onClick(widget);
}
@Override
public void updateDrawState(TextPaint ds) {
}
}
public void setOnAdapterClickListener(OnAdapterClickListener mOnClickNameListener){
this.mOnAdapterClickListener = mOnClickNameListener;
}
public void setOnMyLongClickListener(OnMyLongClickListener mOnMyLongClickListener){
this.mOnMyLongClickListener = mOnMyLongClickListener;
}
public interface OnAdapterClickListener{
void OnClickName();
/**
* 点击内容展开、收起
*/
void clickExpandOrShrink(int position, int type);
}
public interface OnMyLongClickListener{
boolean OnMyLongClick(int position);
}
}
... ...
package com.people.comment.adapter;
import android.graphics.Typeface;
import android.text.Spannable;
import android.text.SpannableStringBuilder;
import android.text.TextPaint;
import android.text.TextUtils;
import android.text.method.LinkMovementMethod;
import android.text.style.ClickableSpan;
import android.text.style.StyleSpan;
import android.view.Gravity;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.core.content.ContextCompat;
import com.chad.library.adapter.base.BaseViewHolder;
import com.people.comment.R;
import com.wd.common.base.BaseSplitAdapter;
import com.wd.common.imageglide.ImageUtils;
import com.wd.common.viewclick.BaseClickListener;
import com.wd.common.widget.ExpandableTextView;
import com.wd.foundation.bean.custom.content.CommentItem;
import com.wd.foundation.bean.music.bean.VoicePlayerBean;
import com.wd.foundation.bean.response.ParentCommentVoBean;
import com.wd.foundation.wdkit.perloader.DeviceHelper;
import com.wd.foundation.wdkitcore.tools.AppContext;
import com.wd.foundation.wdkitcore.tools.StringUtils;
/**
* 游客评论列表适配器
* @author baozhaoxin
* @version [V1.0.0, 2024/1/22]
* @since V1.0.0
*/
public class VisitorCommentListAdapter extends BaseSplitAdapter<CommentItem, BaseViewHolder> {
private OnAdapterClickListener mOnAdapterClickListener;
public OnMyLongClickListener mOnMyLongClickListener;
public VisitorCommentListAdapter() {
super(R.layout.item_visitor_comment_list);
// addChildClickViewIds(R.id.tv_original_news_title);
}
@Override
protected void convert(@NonNull BaseViewHolder baseViewHolder, CommentItem item) {
if (item == null) {
return;
}
ConstraintLayout cl_root = baseViewHolder.getView(R.id.cl_root);
ConstraintLayout cl_bottom = baseViewHolder.getView(R.id.cl_bottom);
ExpandableTextView tv_my_content = baseViewHolder.getView(R.id.tv_my_content);
setContent(tv_my_content,item);
//我的评论动画表情
ImageView ivMyComment = baseViewHolder.getView(R.id.iv_my_comment);
setContentPic(ivMyComment,item.getCommentPics());
ExpandableTextView tv_original_comment_content = baseViewHolder.getView(R.id.tv_original_comment_content);
View line_view = baseViewHolder.getView(R.id.line_view);
View bottomLine = baseViewHolder.getView(R.id.line_bottom);
//评论所属内容的删除状态,0:有效;1:删除
TextView tv_original_news_title = baseViewHolder.getView(R.id.tv_original_news_title);
int targetStatus = item.getTargetStatus();
if (targetStatus==0) {
tv_original_news_title.setText(StringUtils.getStringValue(item.getTargetTitle()));
// tv_original_news_title.setTextColor(ContextCompat.getColor(getContext(),R.color.res_color_common_C1));
tv_original_news_title.setGravity(Gravity.LEFT);
}else{
tv_original_news_title.setText("抱歉,原内容已被删除");
tv_original_news_title.setGravity(Gravity.CENTER);
}
tv_original_news_title.setTextColor(ContextCompat.getColor(AppContext.getContext(),R.color.res_color_common_C2));
ParentCommentVoBean mParentCommentVoBean = item.getParentCommentVo();
if (mParentCommentVoBean==null) {
tv_original_comment_content.setVisibility(View.GONE);
line_view.setVisibility(View.GONE);
}else{
tv_original_comment_content.setVisibility(View.VISIBLE);
line_view.setVisibility(View.VISIBLE);
String user_name = mParentCommentVoBean.getFromUserName();
handleOriginalCommentContent(tv_original_comment_content,"@"+user_name+": "+mParentCommentVoBean.getCommentContent(),user_name.length()+2);
}
int position = getItemPosition(item);
//设置分割线
int itemCount = getItemCount();
if(itemCount > 1 && position == itemCount - 2){
bottomLine.setVisibility(View.GONE);
}else {
bottomLine.setVisibility(View.VISIBLE);
}
MyOnLongClickListener mMyOnLongClickListener = new MyOnLongClickListener(position);
cl_root.setOnLongClickListener(mMyOnLongClickListener);
tv_my_content.setOnLongClickListener(mMyOnLongClickListener);
cl_bottom.setOnLongClickListener(mMyOnLongClickListener);
}
/**
* 设置评论图片
*/
public void setContentPic(ImageView ivMyComment, String picUrl) {
if (null == ivMyComment){
return;
}
if (!TextUtils.isEmpty(picUrl)) {
ivMyComment.setVisibility(View.VISIBLE);
if (picUrl.contains(",")) {
picUrl = picUrl.split(",")[0];
}
ImageUtils.getInstance().loadImageHighLev(ivMyComment, picUrl, R.drawable.rmrb_placeholder_compe_all);
} else {
ivMyComment.setVisibility(View.GONE);
}
}
/**
* 设置评论内容
*/
public void setContent(ExpandableTextView tv_my_content, CommentItem item) {
String content = item.getRealCommentContent();
int expandableStatus = item.getExpandableStatus();
if (!StringUtils.isBlank(content)) {
tv_my_content.setVisibility(View.VISIBLE);
tv_my_content.updateForRecyclerView(content, DeviceHelper.getRealWidth(AppContext.getContext()), expandableStatus);
//描述内容
tv_my_content.setExpandListener(new ExpandableTextView.OnExpandListener() {
int bindingAdapterPosition = getItemPosition(item);
@Override
public void onExpand(ExpandableTextView view) {
if(mOnAdapterClickListener !=null){
mOnAdapterClickListener.clickExpandOrShrink(bindingAdapterPosition, ExpandableTextView.STATE_EXPAND);
}
}
@Override
public void onShrink(ExpandableTextView view) {
if (mOnAdapterClickListener != null) {
mOnAdapterClickListener.clickExpandOrShrink(bindingAdapterPosition, ExpandableTextView.STATE_SHRINK);
}
}
});
} else {
tv_my_content.setVisibility(View.GONE);
}
}
private void handleOriginalCommentContent(TextView tv_original_comment_content, String value, int handleLength) {
if (StringUtils.isBlank(value)) {
return;
}
if (value.length() < handleLength) {
return;
}
SpannableStringBuilder builder = new SpannableStringBuilder(value);
builder.setSpan(new StyleSpan(Typeface.BOLD), 0, handleLength, Spannable.SPAN_INCLUSIVE_INCLUSIVE);
//设置文本点击事件
builder.setSpan(new PrivacyPolicyDialogClickSpannable(new BaseClickListener() {
@Override
protected void onNoDoubleClick(View v) {
if(mOnAdapterClickListener !=null){
mOnAdapterClickListener.OnClickName();
}
}
}), 0, handleLength,Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
tv_original_comment_content.setMovementMethod(LinkMovementMethod.getInstance());
tv_original_comment_content.setText(builder);
}
private int getItemPosition(CommentItem item) {
return item != null && this.mData != null && !this.mData.isEmpty() ? this.mData.indexOf(item) : -1;
}
/**
* SpannableStringBuilder 点击事件
*/
public class PrivacyPolicyDialogClickSpannable extends ClickableSpan implements
View.OnClickListener {
private BaseClickListener onClickListener;
public PrivacyPolicyDialogClickSpannable(BaseClickListener onClickListener) {
this.onClickListener = onClickListener;
}
@Override
public void onClick(View widget) {
// onClickListener.onClick(widget);
}
@Override
public void updateDrawState(TextPaint ds) {
}
}
/**
* 长按事件
*/
private class MyOnLongClickListener implements View.OnLongClickListener {
private int position;
public MyOnLongClickListener(int position){
this.position = position;
}
@Override
public boolean onLongClick(View v) {
if (mOnMyLongClickListener!=null) {
return mOnMyLongClickListener.OnMyLongClick(position);
}else{
return false;
}
}
}
public void setOnAdapterClickListener(OnAdapterClickListener mOnClickNameListener){
this.mOnAdapterClickListener = mOnClickNameListener;
}
public void setOnMyLongClickListener(OnMyLongClickListener mOnMyLongClickListener){
this.mOnMyLongClickListener = mOnMyLongClickListener;
}
public interface OnAdapterClickListener{
void OnClickName();
/**
* 点击内容展开、收起
*/
void clickExpandOrShrink(int position, int type);
}
public interface OnMyLongClickListener{
boolean OnMyLongClick(int position);
}
}
... ...
package com.people.comment.bean;
import androidx.annotation.IntDef;
/**
* @author LiuKun
* @date 2023/5/15 15:30
* @Description:弹出框
*/
@IntDef({CommentClickShowType.reply, CommentClickShowType.share, CommentClickShowType.copy, CommentClickShowType.delete, CommentClickShowType.report})
public @interface CommentClickShowType {
int reply = 0;
int share = 1;
int copy = 2;
int delete = 3;
int report = 4;
}
\ No newline at end of file
... ...
package com.people.comment.bean;
import java.util.ArrayList;
/**
* @Author LiuKun
* @date:2023/5/2
* @desc:消息透传实体类
*/
public class CommentEventBean {
public static class AudioPermissionApply {
public boolean result;
public AudioPermissionApply(boolean result) {
this.result = result;
}
}
public static class ImageUploadCallback {
public ArrayList<String> images;
public ImageUploadCallback(ArrayList<String> images) {
this.images = images;
}
}
}
... ...
package com.people.comment.bean;
/**
* @author LiuKun
* @date 2023/5/2 18:46
* @Description:表情
*/
public class EmojiEntity {
public String code;
public EmojiEntity(String code) {
this.code = code;
}
}
... ...
package com.people.comment.comment.listener;
import com.wd.foundation.bean.response.SpeechTokenBean;
import com.wd.foundation.wdkit.mvvm.vm.IVMCallback;
/**
* @author LiuKun
* @date 2023/5/5 14:39
* @Description:阿里监听
*/
public interface AliTokenListener extends IVMCallback {
/**
* @param SpeechTokenBean
*/
void onGetTokenSuccess(SpeechTokenBean SpeechTokenBean);
/**
* @param error 错误信息
*/
void onGetTokenFailed(String error);
}
... ...
package com.people.comment.comment.listener;
import com.wd.foundation.bean.comment.CommentListBean;
import com.wd.foundation.wdkit.mvvm.vm.IVMCallback;
/**
* 游客评论
* @author baozhaoxin
* @version [V1.0.0, 2024/1/22]
* @since V1.0.0
*/
public interface IVisitorCommentDataListener extends IVMCallback {
/**
* 获取评论列表成功
*
* @param commentList 列表
*/
void onGetCommentListSuccess(CommentListBean commentList);
/**
* 获取评论失列表败
*
* @param msg 消息
*/
void onGetCommentListFail(String msg);
}
... ...
package com.people.comment.comment.model;
import android.text.TextUtils;
import com.people.comment.adapter.CommentListAdapter;
import com.people.comment.listener.BatchMyCommentListLikeStatusListener;
import com.people.comment.listener.DeleteMyCommentListListener;
import com.people.comment.listener.MyCommentListDataListener;
import com.people.comment.listener.SubmitMyCommentListListener;
import com.wd.capability.network.BaseObserver;
import com.wd.capability.network.bean.MetaBean;
import com.wd.capability.network.constant.EventConstants;
import com.wd.capability.network.constant.ParameterConstant;
import com.wd.capability.network.fetcher.BaseDataFetcher;
import com.wd.capability.network.response.BaseResponse;
import com.wd.common.api.RequestApi;
import com.wd.common.incentive.constants.TaskOperateTypeConstants;
import com.wd.common.incentive.task.TaskManager;
import com.wd.common.interact.ICommentDataNewListener;
import com.wd.common.utils.CommonNetUtils;
import com.wd.common.utils.PDUtils;
import com.wd.foundation.bean.comment.CommentListBean;
import com.wd.foundation.bean.comment.CommentStatusBean;
import com.wd.foundation.bean.custom.content.CommentItem;
import com.wd.foundation.bean.incentive.LevelInfoBean;
import com.wd.foundation.bean.livedate.EventMessage;
import com.wd.foundation.bean.request.CommentLikeParameterBean;
import com.wd.foundation.bean.request.PublishCommentParameterBean;
import com.wd.foundation.bean.response.PersonalInfoBean;
import com.wd.foundation.bean.utils.TimeUtil;
import com.wd.foundation.wdkit.constant.IntentConstants;
import com.wd.foundation.wdkit.system.DeviceUtil;
import com.wd.foundation.wdkit.utils.CommonUtil;
import com.wd.foundation.wdkit.utils.SpUtils;
import com.wd.foundation.wdkitcore.livedata.LiveDataBus;
import com.wd.foundation.wdkitcore.tools.ArrayUtils;
import com.wd.foundation.wdkitcore.tools.StringUtils;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import io.reactivex.Observable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.functions.Action;
import io.reactivex.functions.Consumer;
import io.reactivex.schedulers.Schedulers;
/**
* @Author LiuKun
* @date:2023/5/9
* @desc:评论相关接口
*/
public class CommentDataFetcher extends BaseDataFetcher<RequestApi> {
/**
* 接口回调
*/
private ICommentDataNewListener mDataListener;
/**
* 数据请求
*/
public CommentDataFetcher(ICommentDataNewListener listener) {
mDataListener = listener;
}
public CommentDataFetcher() {
}
/**
* 获取评论列表
*/
public void getCommentList(String contentId, String contentType, int pageNum, int pageSize,
String hotComment,String hotIds) {
Map<String, Object> map = new HashMap<>();
//内容id 内容类型
map.put(ParameterConstant.CONTENTID, contentId);
map.put(ParameterConstant.CONTENT_TYPE, contentType);
map.put(ParameterConstant.PAGENUM, pageNum);
map.put(ParameterConstant.PAGESIZE, pageSize);
//用户信息 如果userType为2、3、4时,creatorId必填
map.put(ParameterConstant.USER_ID, SpUtils.getUserId());
map.put(ParameterConstant.USER_TYPE, SpUtils.getUserType());
map.put(ParameterConstant.CREATORID, SpUtils.getCreatorId());
//时间
map.put(ParameterConstant.TIME, TimeUtil.getDateToString(System.currentTimeMillis()));
//设备id
map.put(ParameterConstant.DEVICEID, DeviceUtil.getDeviceId());
//需要返回热门评论,默认为0不需要--兼容已发布客户端和官网
if(StringUtils.isEmpty(hotComment)){
map.put(ParameterConstant.HOT_COMMENT, "0");
}else {
map.put(ParameterConstant.HOT_COMMENT, hotComment);
}
//app评论列表第二页传值,热门评论ids,逗号分隔的字符串
if(StringUtils.isNotBlank(hotIds)){
map.put(ParameterConstant.HOT_IDS, hotIds);
}
//接口请求
Observable<BaseResponse<CommentListBean>> requestData = getRetrofit().getCommentList(map);
request(requestData, new BaseObserver<CommentListBean>() {
@Override
protected void dealSpecialCode(int code, String message) {
if (mDataListener != null) {
mDataListener.onGetCommentListFail(code, message);
}
}
@Override
public void onSuccess(CommentListBean videoItemBean) {
if (mDataListener != null) {
mDataListener.onGetCommentListSuccess(videoItemBean);
}
}
@Override
public void _onError(String e) {
if (mDataListener != null) {
mDataListener.onGetCommentListFail(-1, e);
}
}
});
}
/**
* 批查用户等级信息
*/
public void batchUserLevelInfor(List<CommentItem> data, int freshStartIndex, int listLevel) {
List<String> list = new ArrayList<>();
for (CommentItem bean : data) {
String fromUserId = bean.getFromUserId();
if (!TextUtils.isEmpty(fromUserId)) {
if (list.contains(fromUserId)) {
} else {
list.add(bean.getFromUserId());
}
}
}
//接口请求
Observable<BaseResponse<List<LevelInfoBean>>> requestData = getRetrofit().batchUser(getBody(list));
request(requestData, new BaseObserver<List<LevelInfoBean>>() {
@Override
protected void dealSpecialCode(int code, String message) {
mDataListener.onGetLevelInfoBeanListSuccess(data, freshStartIndex, listLevel);
}
@Override
public void onSuccess(List<LevelInfoBean> levelInfoBeans) {
if (mDataListener != null) {
if (levelInfoBeans != null) {
for (LevelInfoBean levelInfoBean : levelInfoBeans) {
String userId = levelInfoBean.getUserId();
for (CommentItem bean : data) {
String fromUserId = bean.getFromUserId();
if (!TextUtils.isEmpty(userId) && userId.equals(fromUserId)) {
bean.setLevelHead(levelInfoBean.getLevelHead());
bean.levelInfoBean = levelInfoBean;
}
}
}
mDataListener.onGetLevelInfoBeanListSuccess(data, freshStartIndex, listLevel);
}
}
}
@Override
public void _onError(String e) {
mDataListener.onGetLevelInfoBeanListSuccess(data, freshStartIndex, listLevel);
}
});
}
/**
* 单独查询用户等级头像
*/
private void batchUserLevelInfor(CommentItem data, int position, String msg) {
List<String> list = new ArrayList<>();
list.add(data.getFromUserId());
//接口请求
Observable<BaseResponse<List<LevelInfoBean>>> requestData = getRetrofit().batchUser(getBody(list));
request(requestData, new BaseObserver<List<LevelInfoBean>>() {
@Override
protected void dealSpecialCode(int code, String message) {
// mDataListener.onGetLevelInfoBeanSuccess(data, position);
if (mDataListener != null) {
mDataListener.onSubmitPushCommentSuccess(data, position, msg);
}
}
@Override
public void onSuccess(List<LevelInfoBean> levelInfoBeans) {
if (mDataListener != null) {
if (levelInfoBeans != null) {
for (LevelInfoBean levelInfoBean : levelInfoBeans) {
String userId = levelInfoBean.getUserId();
String fromUserId = data.getFromUserId();
if (!TextUtils.isEmpty(userId) && userId.equals(fromUserId)) {
data.setLevelHead(levelInfoBean.getLevelHead());
data.levelInfoBean = levelInfoBean;
}
}
}
mDataListener.onSubmitPushCommentSuccess(data, position, msg);
}
}
@Override
public void _onError(String e) {
if (mDataListener != null) {
mDataListener.onSubmitPushCommentSuccess(data, position, msg);
}
}
});
}
/**
* 单查用户号主信息
* @param creatorId
* @param data
* @param position
* @param msg
*/
private void getMastersAuthentication(String creatorId, CommentItem data, int position, String msg) {
Map<String, Object> map = new HashMap<>();
List<String> listMap = new ArrayList<>();
//creatorId 为空
if (StringUtils.isBlank(creatorId)){
if (mDataListener != null) {
mDataListener.onSubmitPushCommentSuccess(data, position, msg);
}
return;
}
listMap.add(creatorId);
map.put("creatorIdList", listMap);
Observable<BaseResponse<List<PersonalInfoBean>>> userInfo = getRetrofit().getMasterInfoListData(getBody(map));
request(userInfo, new BaseObserver<List<PersonalInfoBean>>() {
@Override
protected void dealSpecialCode(int code, String message) {
if (mDataListener != null) {
mDataListener.onSubmitPushCommentSuccess(data, position, msg);
}
}
@Override
public void onSuccess(List<PersonalInfoBean> masterInfoList) {
if (mDataListener != null) {
for (PersonalInfoBean masterInfoBean : masterInfoList) {
String targetId = masterInfoBean.getRmhId();
String fromCreatorId = StringUtils.getStringValue(data.getFromCreatorId());
if (fromCreatorId.equals(targetId)) {
data.setAuthIcon(masterInfoBean.getAuthIcon());
data.mainControl = masterInfoBean.getCnMainControl();
}
}
mDataListener.onSubmitPushCommentSuccess(data, position, msg);
}
}
@Override
public void _onError(String e) {
if (mDataListener != null) {
mDataListener.onSubmitPushCommentSuccess(data, position, msg);
}
}
});
}
/**
* 获取二级评论列表
*/
public void getSecondCommentList(int position, String commentId, String pageNum, String pageSize, String excludeIds, String contentId, String contentType) {
long currentTimeMillis = System.currentTimeMillis();
Map<String, Object> map = new HashMap<>();
//评论id
map.put(ParameterConstant.COMMENT_ID, commentId);
map.put(ParameterConstant.PAGENUM, pageNum);
map.put(ParameterConstant.PAGESIZE, pageSize);
//
map.put(ParameterConstant.EXCLUDE_IDS, excludeIds);
//用户信息
map.put(ParameterConstant.CREATORID, SpUtils.getCreatorId());
map.put(ParameterConstant.USER_ID, SpUtils.getUserId());
map.put(ParameterConstant.USER_TYPE, SpUtils.getUserType());
map.put(ParameterConstant.TIME, TimeUtil.getDateToString(currentTimeMillis));
//内容id、内容类型
map.put(ParameterConstant.CONTENTID, contentId);
map.put(ParameterConstant.CONTENT_TYPE, contentType);
//设备id
map.put(ParameterConstant.DEVICEID, DeviceUtil.getDeviceId());
Observable<BaseResponse<CommentListBean>> secondCommentList = getRetrofit().getSecondCommentList(map);
request(secondCommentList, new BaseObserver<CommentListBean>() {
@Override
protected void dealSpecialCode(int code, String message) {
if (mDataListener != null) {
mDataListener.onGetSecondCommentListFail();
}
}
@Override
public void onSuccess(CommentListBean videoItemBean) {
if (mDataListener != null) {
mDataListener.onGetSecondCommentListSuccess(position, videoItemBean);
}
}
@Override
public void _onError(String e) {
if (mDataListener != null) {
mDataListener.onGetSecondCommentListFail();
}
}
});
}
/**
* 提交评论
*/
public void submitPushComment(PublishCommentParameterBean parameterBean) {
int position = parameterBean.getPosition();
String rootCommentId = parameterBean.getRootCommentId();
Observable<BaseResponse<CommentItem>> submitRequestData = CommonNetUtils.getInstance().
createSubmitRequestData(parameterBean);
request(submitRequestData, new BaseObserver<CommentItem>() {
@Override
protected void dealSpecialCode(int code, String message) {
if (mDataListener != null) {
mDataListener.onSubmitPushCommentFail(code, message);
}
}
@Override
public void onSuccess(CommentItem pushCommentBean) {
}
@Override
protected void onSuccess(CommentItem pushCommentBean, MetaBean metaBean, String msg, int code) {
super.onSuccess(pushCommentBean, metaBean, msg, code);
if (StringUtils.isEqual("-1", rootCommentId)) {
//执行任务:评论
TaskManager.getInstance().executePointLevelOperate(TaskOperateTypeConstants.COMMENT);
} else {
//执行任务:回复
TaskManager.getInstance().executePointLevelOperate(TaskOperateTypeConstants.REPLY);
}
if(!PDUtils.isLogin()){
//未登录,游客评论
String touristFirstCommentTime = SpUtils.getTouristFirstCommentTime();
if(StringUtils.isEmpty(touristFirstCommentTime)){
//保存游客评论第一条的时间,格式:yyyy-MM-dd HH:mm:ss
try {
String currentDatetime = TimeUtil.currentDatetime();
SpUtils.saveTouristFirstCommentTime(currentDatetime);
} catch (Exception e) {
e.printStackTrace();
}
}
}
if (mDataListener != null && pushCommentBean != null) {
String creatorId = null;
int commentLevel = pushCommentBean.getCommentLevel();
if (commentLevel == CommentListAdapter.COMMENT_TYPE_PARENT || commentLevel == CommentListAdapter.COMMENT_TYPE_CHILD) {
//创作者
if (pushCommentBean.getCreatorFlag() == 1) {
creatorId = pushCommentBean.getFromCreatorId();
}
}
if (TextUtils.isEmpty(creatorId)) {
batchUserLevelInfor(pushCommentBean, position, msg);
} else {
getMastersAuthentication(creatorId, pushCommentBean, position, msg);
}
// mDataListener.onSubmitPushCommentSuccess(pushCommentBean, position, msg)
}else {
//有msg,也进行提示,处理评论预显示关闭,发布评论场景
if (mDataListener != null) {
mDataListener.onSubmitPushCommentSuccess(pushCommentBean, position, msg);
}
}
}
@Override
public void _onError(String e) {
if (mDataListener != null) {
mDataListener.onSubmitPushCommentFail(-1, e);
}
}
});
}
/**
* 批量获取创作者的认证信息
*
* @param targetId 内容id
* @param originalListData 一级评论原始数据
* @param freshStartIndex 刷新起始位置
* @param listLevel 数据类型 1 一级评论 2 二级评论
*/
public void getMastersAuthenticationList(String targetId,List<CommentItem> originalListData, int freshStartIndex, int listLevel) {
List<String> creatorIdList = new ArrayList<>();
// List<String> userIdList = new ArrayList<>();
int size = originalListData.size();
Observable.range(0, size)
.subscribeOn(Schedulers.io()) // 在 IO 线程执行循环操作
.observeOn(AndroidSchedulers.mainThread()) // 在主线程观察结果
.subscribe(new Consumer<Integer>() {
@Override
public void accept(Integer i) throws Exception {
// 循环体代码
int commentLevel = originalListData.get(i).getCommentLevel();
if (commentLevel == CommentListAdapter.COMMENT_TYPE_PARENT || commentLevel == CommentListAdapter.COMMENT_TYPE_CHILD) {
//不是创作者也有客态了
if (originalListData.get(i).getCreatorFlag() == 1) {
creatorIdList.add(originalListData.get(i).getFromCreatorId());
}
// if (!TextUtils.isEmpty(originalListData.get(i).getFromUserId() )){
// userIdList.add()
// }
}
}
}, new Consumer<Throwable>() {
@Override
public void accept(Throwable throwable) throws Exception {
// 处理错误
}
}, new Action() {
@Override
public void run() throws Exception {
// 循环完毕后执行下一步的代码
getMastersAuthenticationListRxjava(targetId,creatorIdList, originalListData, freshStartIndex, listLevel);
}
});
}
private void getMastersAuthenticationListRxjava(String targetId,List<String> creatorIdList, List<CommentItem> originalListData, int freshStartIndex, int listLevel) {
if (CommonUtil.isEmpty(creatorIdList)) {
//未登录不需查询点赞状态
if (!PDUtils.isLogin()) {
if (mDataListener != null) {
mDataListener.onGetMastersAuthenticationListSuccess(null, originalListData, freshStartIndex, listLevel);
}
return;
}
//没有创作者直接查询点赞状态
getCommentStatusList(targetId,null, originalListData, freshStartIndex, listLevel);
return;
}
Map<String, Object> map = new HashMap<>();
List<String> listMap = new ArrayList<>();
for (String tempCreatorId : creatorIdList) {
if (!listMap.contains(tempCreatorId)) {
//避免重复查询
listMap.add(tempCreatorId);
}
}
map.put("creatorIdList", listMap);
if (ArrayUtils.isEmpty(listMap)){
if (mDataListener != null) {
mDataListener.onGetMastersAuthenticationListFailure("creatorIdList 为空", listLevel);
}
return;
}
Observable<BaseResponse<List<PersonalInfoBean>>> userInfo = getRetrofit().getMasterInfoListData(getBody(map));
request(userInfo, new BaseObserver<List<PersonalInfoBean>>() {
@Override
protected void dealSpecialCode(int code, String message) {
if (mDataListener != null) {
mDataListener.onGetMastersAuthenticationListFailure(message, listLevel);
}
}
@Override
public void onSuccess(List<PersonalInfoBean> masterInfoList) {
//未登录只查询号主信息
if (!PDUtils.isLogin()) {
if (mDataListener != null) {
mDataListener.onGetMastersAuthenticationListSuccess(masterInfoList, originalListData, freshStartIndex, listLevel);
}
return;
}
//已登录 号主信息查完以后再查询点赞状态
getCommentStatusList(targetId,masterInfoList, originalListData, freshStartIndex, listLevel);
}
@Override
public void _onError(String e) {
if (mDataListener != null) {
mDataListener.onGetMastersAuthenticationListFailure(e, listLevel);
}
}
});
}
/**
* 批量查询当前登录人评论点赞状态
*
* @param targetId 内容id
* @param originalListData 一级评论原始数据
* @param freshStartIndex 刷新起始位置
* @param listLevel 数据类型 1 一级评论 2 二级评论
*/
public void getCommentStatusList(String targetId,List<PersonalInfoBean> masterInfoList, List<CommentItem> originalListData, int freshStartIndex, int listLevel) {
if(!PDUtils.isLogin()){
return;
}
List<Integer> commentIdList = new ArrayList<>();
List<String> uuidList = new ArrayList<>();
for (CommentItem mCovertCommentObj : originalListData) {
int tempId = mCovertCommentObj.getId();
//评论审核状态,0:未审核;1:审核中;2:通过;3:不通过 只有审核通过的才显示回复按钮
/*int checkStatus = mCovertCommentObj.getCheckStatus();
if (tempId != 0 || checkStatus == 2) {
commentIdList.add(tempId);
}*/
if(tempId != 0){
commentIdList.add(tempId);
}else if(StringUtils.isNotBlank(mCovertCommentObj.getUuid())){
uuidList.add(mCovertCommentObj.getUuid());
}
}
if (CommonUtil.isEmpty(commentIdList)) {
if (mDataListener != null) {
mDataListener.onGetAllDataSuccess(null, masterInfoList, originalListData, freshStartIndex, listLevel);
}
return;
}
Map<String, Object> map = new HashMap<>();
map.put("commentIdList", commentIdList);
map.put("targetId", targetId);
map.put("uuidList", uuidList);
Observable<BaseResponse<List<CommentStatusBean>>> userInfo = getRetrofit().batchCommentStatus(getBody(map));
request(userInfo, new BaseObserver<List<CommentStatusBean>>() {
@Override
protected void dealSpecialCode(int code, String message) {
if (mDataListener != null) {
mDataListener.onGetCommentStatusListFailure(message, listLevel);
}
}
@Override
public void onSuccess(List<CommentStatusBean> statusList) {
if (mDataListener != null) {
mDataListener.onGetAllDataSuccess(statusList, masterInfoList, originalListData, freshStartIndex, listLevel);
}
}
@Override
public void _onError(String e) {
//接口请求失败
if (mDataListener != null) {
mDataListener.onGetCommentStatusListFailure(e, listLevel);
}
}
});
}
/**
* 评论点赞
*/
public void commentLike(CommentLikeParameterBean commentLikeParameterBean) {
if(commentLikeParameterBean == null){
return;
}
String commentId = commentLikeParameterBean.getCommentId();
String targetId = commentLikeParameterBean.getTargetId();
int status = commentLikeParameterBean.getStatus();
Map<String, Object> map = new HashMap<>();
map.put("rootCommentId", commentLikeParameterBean.getRootCommentId());
map.put("uuid", commentLikeParameterBean.getUuid());
map.put("commentId", commentId);
map.put("targetId", targetId);
map.put("targetType", commentLikeParameterBean.getTargetType());
map.put("status", status);
map.put("userName", SpUtils.getUserName());
map.put("userHeaderUrl", SpUtils.getHeadPhotoUrl());
Observable<BaseResponse<Object>> requestData = getRetrofit().commentLike(getBody(map));
request(requestData, new BaseObserver<Object>() {
@Override
protected void dealSpecialCode(int code, String message) {
}
@Override
public void onSuccess(Object s) {
if(StringUtils.isEmpty(commentId)){
return;
}
EventMessage mEventMessage = new EventMessage(EventConstants.FRESH_ZAN_CREATOR_EVENT);
mEventMessage.putExtra(IntentConstants.CONTENT_ID, commentId);
mEventMessage.putExtra(IntentConstants.TARGET_ID, targetId);
mEventMessage.putExtra(IntentConstants.IS_ZAN, 0 == status);
//全局刷新创作者关注状态
LiveDataBus.getInstance().with(EventConstants.FRESH_ZAN_CREATOR_EVENT).postValue(mEventMessage);
}
@Override
public void _onError(String e) {
}
});
}
/**
* 评论点赞(不需要发通知事件)
*/
public void commentLike(String commentId, String targetId, String targetType, int status) {
Map<String, Object> map = new HashMap<>();
map.put("commentId", commentId);
map.put("targetId", targetId);
map.put("targetType", targetType);
map.put("status", status);
map.put("userName", SpUtils.getUserName());
map.put("userHeaderUrl", SpUtils.getHeadPhotoUrl());
Observable<BaseResponse<Object>> requestData = getRetrofit().commentLike(getBody(map));
request(requestData, new BaseObserver<Object>() {
@Override
protected void dealSpecialCode(int code, String message) {
}
@Override
public void onSuccess(Object s) {
}
@Override
public void _onError(String e) {
}
});
}
/**
* 获取发出去的单条评论数据的号主V
*
* @param creatorId 发送者的号主id
* @param freshPosition 后续需要刷新的item的下标
*/
public void getSingleMastersAuthenticationData(String creatorId, int freshPosition) {
Map<String, Object> map = new HashMap<>();
List<String> listMap = new ArrayList<>();
//避免重复查询
//creatorId 为空
if (StringUtils.isBlank(creatorId)){
return;
}
listMap.add(creatorId);
map.put("creatorIdList", listMap);
Observable<BaseResponse<List<PersonalInfoBean>>> userInfo = getRetrofit().getMasterInfoListData(getBody(map));
request(userInfo, new BaseObserver<List<PersonalInfoBean>>() {
@Override
protected void dealSpecialCode(int code, String message) {
}
@Override
public void onSuccess(List<PersonalInfoBean> masterInfoList) {
if (CommonUtil.isEmpty(masterInfoList)) {
return;
}
if (mDataListener != null) {
mDataListener.onGetSingleMastersAuthenticationDataSuccess(masterInfoList.get(0), freshPosition);
}
}
@Override
public void _onError(String e) {
}
});
}
/**
* 删除评论
*
* @param commentId 要删除的评论id
* @param targetId 删除评论所属内容id
*/
public void delComment(String commentId, String targetId, String uuid, int freshPosition) {
CommonNetUtils.getInstance().delComment(commentId,targetId,uuid,freshPosition,mDataListener);
}
/**
* 获取用户的评论列表数据
*/
public void getUserCommentList(String userId, String userType, String creatorId,
int pageNum, int pageSize, boolean isSelf,
MyCommentListDataListener mMyCommentListDataListener) {
long currentTimeMillis = System.currentTimeMillis();
HashMap<String, Object> queryMap = new HashMap<>();
queryMap.put(ParameterConstant.PAGENUM, pageNum);
queryMap.put(ParameterConstant.PAGESIZE, pageSize);
queryMap.put(ParameterConstant.TIME, TimeUtil.getDateToString(currentTimeMillis));
Observable<BaseResponse<CommentListBean>> register = null;
if (isSelf) {
register = getRetrofit().getMyCommentList(queryMap);
} else {
queryMap.put(ParameterConstant.CREATORID, creatorId);
queryMap.put(ParameterConstant.USER_ID, userId);
queryMap.put(ParameterConstant.USER_TYPE, userType);
register = getRetrofit().getOthersCommentList(queryMap);
}
if (register == null) {
return;
}
request(register, new BaseObserver<CommentListBean>() {
@Override
protected void dealSpecialCode(int code, String message) {
if (mMyCommentListDataListener != null) {
mMyCommentListDataListener.onGetDateFailed(message);
}
}
@Override
public void onSuccess(CommentListBean mData) {
if (mMyCommentListDataListener != null) {
mMyCommentListDataListener.onGetDateSuccess(mData);
}
}
@Override
public void _onError(String e) {
if (mMyCommentListDataListener != null) {
mMyCommentListDataListener.onGetDateFailed(e);
}
}
});
}
/**
* 批量查询我的评论列表评论点赞状态
*/
public void getMyCommentListStatusList(List<Integer> params, BatchMyCommentListLikeStatusListener mMyCommentListDataListener) {
if(!PDUtils.isLogin()){
return;
}
Map<String, Object> map = new HashMap<>();
map.put("commentIdList", params);
Observable<BaseResponse<List<CommentStatusBean>>> userInfo = getRetrofit().batchCommentStatus(getBody(map));
request(userInfo, new BaseObserver<List<CommentStatusBean>>() {
@Override
protected void dealSpecialCode(int code, String message) {
if (mMyCommentListDataListener != null) {
mMyCommentListDataListener.onGetCommentStatusListFailure(message);
}
}
@Override
public void onSuccess(List<CommentStatusBean> statusList) {
if (mMyCommentListDataListener != null) {
mMyCommentListDataListener.onGetCommentStatusListSuccess(statusList);
}
}
@Override
public void _onError(String e) {
if (mMyCommentListDataListener != null) {
mMyCommentListDataListener.onGetCommentStatusListFailure(e);
}
}
});
}
/**
* 删除评论(我的评论列表)
*
* @param commentId 要删除的评论id
* @param targetId 删除评论所属内容id
*/
public void delComment(String commentId, String targetId, String uuid, int freshPosition, DeleteMyCommentListListener mDeleteMyCommentListListener) {
Observable<BaseResponse<String>> userInfo = CommonNetUtils.getInstance().createDelRequestData(commentId, targetId, uuid);
request(userInfo, new BaseObserver<String>() {
@Override
protected void dealSpecialCode(int code, String message) {
if (mDeleteMyCommentListListener != null) {
mDeleteMyCommentListListener.onDeleteFailure(message);
}
}
@Override
public void onSuccess(String success) {
if (mDeleteMyCommentListListener != null) {
mDeleteMyCommentListListener.onDeleteSuccess(freshPosition);
}
}
@Override
public void _onError(String e) {
if (mDeleteMyCommentListListener != null) {
mDeleteMyCommentListListener.onDeleteFailure(e);
}
}
});
}
/**
* 提交评论(我的评论列表)
*/
public void submitPushComment(PublishCommentParameterBean parameterBean,
SubmitMyCommentListListener mSubmitMyCommentListListener) {
if(parameterBean == null){
return;
}
int position = parameterBean.getPosition();
String rootCommentId = parameterBean.getRootCommentId();
Observable<BaseResponse<CommentItem>> submitRequestData = CommonNetUtils.getInstance().createSubmitRequestData(parameterBean);
request(submitRequestData, new BaseObserver<CommentItem>() {
@Override
protected void dealSpecialCode(int code, String message) {
if (mSubmitMyCommentListListener != null) {
mSubmitMyCommentListListener.onSubmitFailure(code, message);
}
}
@Override
public void onSuccess(CommentItem pushCommentBean) {
}
@Override
protected void onSuccess(CommentItem listBean, MetaBean metaBean, String msg, int code) {
super.onSuccess(listBean, metaBean, msg, code);
if (StringUtils.isEqual("-1", rootCommentId)) {
//执行任务:评论
TaskManager.getInstance().executePointLevelOperate(TaskOperateTypeConstants.COMMENT);
} else {
//执行任务:回复
TaskManager.getInstance().executePointLevelOperate(TaskOperateTypeConstants.REPLY);
}
if(!PDUtils.isLogin()){
//未登录,游客评论
String touristFirstCommentTime = SpUtils.getTouristFirstCommentTime();
if(StringUtils.isEmpty(touristFirstCommentTime)){
//保存游客评论第一条的时间,格式:yyyy-MM-dd HH:mm:ss
try {
String currentDatetime = TimeUtil.currentDatetime();
SpUtils.saveTouristFirstCommentTime(currentDatetime);
} catch (Exception e) {
e.printStackTrace();
}
}
}
if (mSubmitMyCommentListListener != null) {
mSubmitMyCommentListListener.onSubmitSuccess(listBean, position, msg);
}
}
@Override
public void _onError(String e) {
if (mSubmitMyCommentListListener != null) {
mSubmitMyCommentListListener.onSubmitFailure(-1, e);
}
}
});
}
}
... ...
package com.people.comment.comment.model;
import com.people.comment.comment.listener.AliTokenListener;
import com.wd.capability.network.BaseObserver;
import com.wd.capability.network.fetcher.BaseDataFetcher;
import com.wd.capability.network.response.BaseResponse;
import com.wd.common.api.RequestApi;
import com.wd.foundation.bean.response.SpeechTokenBean;
import io.reactivex.Observable;
/**
* @Author LiuKun
* @date:2023/5/5
* @desc:获取阿里语音识别
*/
public class GetAliTokenFetcher extends BaseDataFetcher<RequestApi> {
/**
* 获取阿里云语音识别token
*/
public void getAliToken(AliTokenListener mListener) {
Observable<BaseResponse<SpeechTokenBean>> codeData = getRetrofit().getAliToken();
request(codeData, new BaseObserver<SpeechTokenBean>() {
@Override
protected void dealSpecialCode(int code, String message) {
}
@Override
protected void onSuccess(SpeechTokenBean speechTokenBean) {
if (mListener != null) {
mListener.onGetTokenSuccess(speechTokenBean);
}
}
@Override
public void _onError(String e) {
if (mListener != null) {
mListener.onGetTokenFailed(e);
}
}
});
}
}
... ...
package com.people.comment.comment.model;
import com.people.comment.comment.listener.IVisitorCommentDataListener;
import com.wd.capability.network.BaseObserver;
import com.wd.capability.network.constant.ParameterConstant;
import com.wd.capability.network.fetcher.BaseDataFetcher;
import com.wd.capability.network.response.BaseResponse;
import com.wd.common.api.RequestApi;
import com.wd.foundation.bean.comment.CommentListBean;
import com.wd.foundation.bean.utils.TimeUtil;
import com.wd.foundation.wdkit.system.DeviceUtil;
import com.wd.foundation.wdkit.utils.SpUtils;
import java.util.HashMap;
import java.util.Map;
import io.reactivex.Observable;
/**
* 游客评论
* @author baozhaoxin
* @version [V1.0.0, 2024/1/22]
* @since V1.0.0
*/
public class VisitorCommentDataFetcher extends BaseDataFetcher<RequestApi> {
private IVisitorCommentDataListener iVisitorCommentDataListener;
public VisitorCommentDataFetcher(IVisitorCommentDataListener iVisitorCommentDataListener) {
this.iVisitorCommentDataListener = iVisitorCommentDataListener;
}
/**
* 获取评论列表
*/
public void getCommentList(int pageNum, int pageSize) {
Map<String, Object> map = new HashMap<>();
map.put(ParameterConstant.PAGENUM, pageNum);
map.put(ParameterConstant.PAGESIZE, pageSize);
//时间
String currentDatetime = TimeUtil.currentDatetime();
map.put(ParameterConstant.TIME, currentDatetime);
String touristFirstCommentTime = SpUtils.getTouristFirstCommentTime();
String deviceId = DeviceUtil.getDeviceId();
map.put(ParameterConstant.VISITOR_FIRST_TIME, touristFirstCommentTime);
map.put(ParameterConstant.DEVICEID, deviceId);
Observable<BaseResponse<CommentListBean>> observable = getRetrofit().
getVisitorCommentList(map);
request(observable, new BaseObserver<CommentListBean>() {
@Override
protected void dealSpecialCode(int code, String message) {
if (iVisitorCommentDataListener != null) {
iVisitorCommentDataListener.onGetCommentListFail(message);
}
}
@Override
public void onSuccess(CommentListBean mData) {
if (iVisitorCommentDataListener != null) {
iVisitorCommentDataListener.onGetCommentListSuccess(mData);
}
}
@Override
public void _onError(String e) {
if (iVisitorCommentDataListener != null) {
iVisitorCommentDataListener.onGetCommentListFail(e);
}
}
});
}
}
... ...
package com.people.comment.comment.vm;
import androidx.lifecycle.LifecycleOwner;
import com.people.comment.comment.model.CommentDataFetcher;
import com.people.comment.listener.BatchMyCommentListLikeStatusListener;
import com.people.comment.listener.DeleteMyCommentListListener;
import com.people.comment.listener.MyCommentListDataListener;
import com.people.comment.listener.SubmitMyCommentListListener;
import com.wd.common.UIViewModel;
import com.wd.common.interact.ICommentDataNewListener;
import com.wd.common.interfaces.OnGetContentBeanSuccessListener;
import com.wd.common.utils.CommonNetUtils;
import com.wd.foundation.bean.custom.content.CommentItem;
import com.wd.foundation.bean.request.CommentLikeParameterBean;
import com.wd.foundation.bean.request.PublishCommentParameterBean;
import java.util.List;
/**
* @Author LiuKun
* @date:2023/5/9
* @desc:评论接口回调
*/
public class CommentViewModel extends UIViewModel {
/**
* 接口回调
*/
private ICommentDataNewListener mDataListener;
/**
* 数据请求
*/
private CommentDataFetcher mCommentFetcher;
public void observeCommentListener(LifecycleOwner lifecycleOwner, ICommentDataNewListener listener) {
if (mDataListener == null) {
mDataListener = observe(lifecycleOwner, listener, ICommentDataNewListener.class);
} else {
observeRepeat(lifecycleOwner, listener, mDataListener);
}
}
/**
* 获取评论列表
*
* @param contentId 内容id
* @param contentType 内容类型
*/
public void getCommentList(String contentId, String contentType, int pageNum, int pageSize,
String hotComment,String hotIds) {
if (mCommentFetcher == null) {
mCommentFetcher = new CommentDataFetcher(mDataListener);
}
mCommentFetcher.getCommentList(contentId, contentType, pageNum, pageSize,hotComment,hotIds);
}
/**
* 获取二级评论列表
*
* @param excludeIds 需要排除的id,多个用逗号隔开;【一级评论下面3条子评论的首次展开使用;pageId=1】
*/
public void getSecondCommentList(int position, String commentId, String pageNum, String pageSize, String excludeIds, String contentId, String contentType) {
if (mCommentFetcher == null) {
mCommentFetcher = new CommentDataFetcher(mDataListener);
}
mCommentFetcher.getSecondCommentList(position, commentId, pageNum, pageSize, excludeIds, contentId, contentType);
}
/**
* 发布评论
* @position 条目点击位置
*/
public void submitComment(PublishCommentParameterBean parameterBean) {
if (mCommentFetcher == null) {
mCommentFetcher = new CommentDataFetcher(mDataListener);
}
mCommentFetcher.submitPushComment(parameterBean);
}
/**
* 发布评论(我的评论列表)
*/
public void submitComment(PublishCommentParameterBean parameterBean,
SubmitMyCommentListListener mSubmitMyCommentListListener) {
if (mCommentFetcher == null) {
mCommentFetcher = new CommentDataFetcher(mDataListener);
}
mCommentFetcher.submitPushComment(parameterBean, mSubmitMyCommentListListener);
}
/**
* 批量获取创作者的认证信息
*
* @param targetId 内容id
* @param originalListData 一级评论原始数据
* @param freshStartIndex 刷新起始位置
* @param listLevel 数据类型 1 一级评论 2 二级评论
*/
public void getMastersAuthenticationList(String targetId, List<CommentItem> originalListData, int freshStartIndex, int listLevel) {
if (mCommentFetcher == null) {
mCommentFetcher = new CommentDataFetcher(mDataListener);
}
mCommentFetcher.getMastersAuthenticationList(targetId,originalListData, freshStartIndex, listLevel);
}
/**
* 评论点赞
*/
public void commentLike(CommentLikeParameterBean commentLikeParameterBean) {
if (mCommentFetcher == null) {
mCommentFetcher = new CommentDataFetcher(mDataListener);
}
mCommentFetcher.commentLike(commentLikeParameterBean);
}
/**
* 获取发出去的单条评论数据的号主V
*
* @param creatorId 发送者的号主id
* @param freshPosition 后续需要刷新的item的下标
*/
public void getSingleMastersAuthenticationData(String creatorId, int freshPosition) {
if (mCommentFetcher == null) {
mCommentFetcher = new CommentDataFetcher(mDataListener);
}
mCommentFetcher.getSingleMastersAuthenticationData(creatorId, freshPosition);
}
/**
* 用户删除评论
*
* @param commentId 要删除的评论id
* @param targetId 删除评论所属内容id
*/
public void delComment(String commentId, String targetId, String uuid,int freshPosition) {
if (mCommentFetcher == null) {
mCommentFetcher = new CommentDataFetcher(mDataListener);
}
mCommentFetcher.delComment(commentId, targetId,uuid, freshPosition);
}
/**
* 获取用户自己的评论列表数据
*
* @param userId
*/
public void getMyCommentList(String userId,String userType, String creatorId, int pageNum, int pageSize,boolean isSelf, MyCommentListDataListener mMyCommentListDataListener) {
if (mCommentFetcher == null) {
mCommentFetcher = new CommentDataFetcher();
}
mCommentFetcher.getUserCommentList(userId, userType,creatorId,pageNum,pageSize,isSelf,mMyCommentListDataListener);
}
/**
* 批量查询我的评论列表评论点赞状态
*/
public void getMyCommentListStatusList(List<Integer> params, BatchMyCommentListLikeStatusListener mMyCommentListDataListener) {
if (mCommentFetcher == null) {
mCommentFetcher = new CommentDataFetcher();
}
mCommentFetcher.getMyCommentListStatusList(params, mMyCommentListDataListener);
}
/**
* 用户删除评论(我的评论列表)
*
* @param commentId 要删除的评论id
* @param targetId 删除评论所属内容id
* @param uuid
*/
public void delComment(String commentId, String targetId,String uuid, int freshPosition, DeleteMyCommentListListener mDeleteMyCommentListListener) {
if (mCommentFetcher == null) {
mCommentFetcher = new CommentDataFetcher();
}
mCommentFetcher.delComment(commentId, targetId,uuid, freshPosition,mDeleteMyCommentListListener);
}
/**
* 获取评论关联的内容对象(通过contentId获取ContentBean)
* @param contentId
* @param mOnGetContentBeanSuccessListener
*/
public void getContentBeanByContentId(String contentId, String relId, String relType, OnGetContentBeanSuccessListener mOnGetContentBeanSuccessListener) {
if (mCommentFetcher == null) {
mCommentFetcher = new CommentDataFetcher();
}
CommonNetUtils.getInstance().getNewsDetail(contentId, relId,relType,mOnGetContentBeanSuccessListener);
}
/**
* 批查用户等级头像
* @param data
* @param freshStartIndex
* @param listLevel
*/
public void batchUserLevelInfor(List<CommentItem> data, int freshStartIndex, int listLevel) {
if (mCommentFetcher == null) {
mCommentFetcher = new CommentDataFetcher();
}
mCommentFetcher.batchUserLevelInfor(data,freshStartIndex, listLevel);
}
}
... ...
package com.people.comment.comment.vm;
import androidx.lifecycle.LifecycleOwner;
import com.people.comment.comment.listener.IVisitorCommentDataListener;
import com.people.comment.comment.model.VisitorCommentDataFetcher;
import com.wd.common.UIViewModel;
/**
* 游客评论vm
* @author baozhaoxin
* @version [V1.0.0, 2024/1/22]
* @since V1.0.0
*/
public class VisitorCommentViewModel extends UIViewModel {
/**
* 接口回调
*/
private IVisitorCommentDataListener mDataListener;
/**
* 数据请求
*/
private VisitorCommentDataFetcher mCommentFetcher;
public void observeCommentListener(LifecycleOwner lifecycleOwner, IVisitorCommentDataListener listener) {
if (mDataListener == null) {
mDataListener = observe(lifecycleOwner, listener, IVisitorCommentDataListener.class);
} else {
observeRepeat(lifecycleOwner, listener, mDataListener);
}
}
/**
* 获取评论列表
* @param pageNum
* @param pageSize
*/
public void getCommentList(int pageNum, int pageSize) {
if (mCommentFetcher == null) {
mCommentFetcher = new VisitorCommentDataFetcher(mDataListener);
}
mCommentFetcher.getCommentList(pageNum, pageSize);
}
}
... ...
package com.people.comment.dialog;
import android.app.Dialog;
import android.content.Context;
import android.graphics.Color;
import android.text.TextUtils;
import android.util.TypedValue;
import android.view.Display;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.view.WindowManager;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.ScrollView;
import android.widget.TextView;
import androidx.core.content.ContextCompat;
import com.people.comment.R;
import com.wd.foundation.wdkit.utils.UiUtils;
import java.util.ArrayList;
import java.util.List;
public class ActionSheetDialog {
private Context context;
private Dialog dialog;
private TextView txt_title;
private TextView txt_cancel;
private LinearLayout lLayout_content;
private ScrollView sLayout_content;
private boolean showTitle = false;
private List<SheetItem> sheetItemList;
private Display display;
public ActionSheetDialog(Context context) {
this.context = context;
WindowManager windowManager = (WindowManager) context
.getSystemService(Context.WINDOW_SERVICE);
display = windowManager.getDefaultDisplay();
}
public ActionSheetDialog builder() {
// 获取Dialog布局
View view = LayoutInflater.from(context).inflate(
R.layout.view_actionsheet, null);
// 设置Dialog最小宽度为屏幕宽度
view.setMinimumWidth(display.getWidth());
// 获取自定义Dialog布局中的控件
sLayout_content = (ScrollView) view.findViewById(R.id.sLayout_content);
lLayout_content = (LinearLayout) view
.findViewById(R.id.lLayout_content);
txt_title = (TextView) view.findViewById(R.id.txt_title);
txt_cancel = (TextView) view.findViewById(R.id.txt_cancel);
txt_cancel.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
}
});
// 定义Dialog布局和参数
dialog = new Dialog(context, R.style.ActionSheetDialogStyle);
dialog.setContentView(view);
Window dialogWindow = dialog.getWindow();
dialogWindow.setGravity(Gravity.CENTER | Gravity.BOTTOM);
WindowManager.LayoutParams lp = dialogWindow.getAttributes();
lp.x = 0;
lp.y = 0;
dialogWindow.setAttributes(lp);
return this;
}
public ActionSheetDialog setTitle(String title) {
showTitle = true;
txt_title.setVisibility(View.VISIBLE);
txt_title.setText(TextUtils.isEmpty(title)?"":title);
return this;
}
public ActionSheetDialog setCancelable(boolean cancel) {
dialog.setCancelable(cancel);
return this;
}
public ActionSheetDialog setCanceledOnTouchOutside(boolean cancel) {
dialog.setCanceledOnTouchOutside(cancel);
return this;
}
/**
*
* @param strItem
* 条目名称
* @param color
* 条目字体颜色,设置null则默认蓝色
* @param listener
* @return
*/
public ActionSheetDialog addSheetItem(String strItem, SheetItemColor color,
OnSheetItemClickListener listener) {
if (sheetItemList == null) {
sheetItemList = new ArrayList<SheetItem>();
}
sheetItemList.add(new SheetItem(strItem, color, listener));
return this;
}
/** 设置条目布局 */
private void setSheetItems() {
if (sheetItemList == null || sheetItemList.size() <= 0) {
return;
}
int size = sheetItemList.size();
// TODO 高度控制,非最佳解决办法
// 添加条目过多的时候控制高度
if (size >= 7) {
LayoutParams params = (LayoutParams) sLayout_content
.getLayoutParams();
params.height = display.getHeight() / 2;
sLayout_content.setLayoutParams(params);
}
// 循环添加条目
for (int i = 1; i <= size; i++) {
final int index = i;
SheetItem sheetItem = sheetItemList.get(i - 1);
String strItem = sheetItem.name;
SheetItemColor color = sheetItem.color;
final OnSheetItemClickListener listener = (OnSheetItemClickListener) sheetItem.itemClickListener;
TextView textView = new TextView(context);
textView.setText(TextUtils.isEmpty(strItem)?"":strItem);
textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
textView.setGravity(Gravity.CENTER);
// 背景图片
if (size == 1) {
if (showTitle) {
textView.setBackgroundResource(R.drawable.actionsheet_bottom_selector);
} else {
textView.setBackgroundResource(R.drawable.actionsheet_single_selector);
}
} else {
if (showTitle) {
if (i >= 1 && i < size) {
textView.setBackgroundResource(R.drawable.actionsheet_middle_selector);
} else {
textView.setBackgroundResource(R.drawable.actionsheet_bottom_selector);
}
} else {
if (i == 1) {
textView.setBackgroundResource(R.drawable.actionsheet_top_selector);
} else if (i < size) {
textView.setBackgroundResource(R.drawable.actionsheet_middle_selector);
} else {
textView.setBackgroundResource(R.drawable.actionsheet_bottom_selector);
}
}
}
// 字体颜色
if (color == null) {
textView.setTextColor(Color.parseColor(SheetItemColor.Blue
.getName()));
} else {
textView.setTextColor(Color.parseColor(color.getName()));
}
// 高度
float scale = context.getResources().getDisplayMetrics().density;
int height = (int) (50 * scale + 1);
textView.setLayoutParams(new LayoutParams(
LayoutParams.MATCH_PARENT, height));
// 点击事件
textView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
listener.onClick(index);
dialog.dismiss();
}
});
lLayout_content.addView(textView);
if (i!=size) {
View lineView = new View(context);
lineView.setLayoutParams(new LayoutParams(
LayoutParams.MATCH_PARENT, UiUtils.dp2px(0.5F)));
lineView.setBackgroundColor(ContextCompat.getColor(context,R.color.transparent));
lLayout_content.addView(lineView);
}
}
}
public void show() {
setSheetItems();
dialog.show();
}
public interface OnSheetItemClickListener {
void onClick(int which);
}
public class SheetItem {
String name;
OnSheetItemClickListener itemClickListener;
SheetItemColor color;
public SheetItem(String name, SheetItemColor color,
OnSheetItemClickListener itemClickListener) {
this.name = name;
this.color = color;
this.itemClickListener = itemClickListener;
}
}
public enum SheetItemColor {
Blue("#037BFF"), Red("#FD4A2E");
private String name;
private SheetItemColor(String name) {
this.name = name;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
}
... ...
package com.people.comment.dialog;
import android.app.Activity;
import android.content.pm.ActivityInfo;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.view.Gravity;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.core.content.ContextCompat;
import com.people.comment.R;
import com.people.comment.listener.CommitDialogListener;
import com.people.comment.manager.ExpressionManager;
import com.people.comment.utils.KeyboardHelper;
import com.wd.common.constant.PageNameConstants;
import com.wd.common.dialog.LayerDialog;
import com.wd.common.imageglide.ImageUtils;
import com.wd.common.permissions.IPmsCallBack;
import com.wd.common.permissions.PermissionsUtils;
import com.wd.common.widget.edittext.AutoAdaptTextSize;
import com.wd.foundation.bean.analytics.TraceBean;
import com.wd.foundation.bean.analytics.TrackContentBean;
import com.wd.foundation.bean.custom.video.VodDetailIntentBean;
import com.wd.foundation.wdkit.utils.SpUtils;
import com.wd.foundation.wdkit.utils.ToastNightUtil;
import com.wd.foundation.wdkitcore.constant.BaseConstants;
import com.wd.foundation.wdkitcore.storage.MemStoreUtils;
import com.wd.foundation.wdkitcore.tools.ResUtils;
import com.wd.foundation.wdkitcore.tools.StringUtils;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.List;
/**
* @Author LiuKun
* @date:2023/5/2
* @desc:评论弹出框
*/
public class CommentCommitDialog extends LayerDialog {
/**
* 上个页面传递过来的数据
*/
public VodDetailIntentBean intentBean;
private TrackContentBean mTrackContentBean;
/**
* 输入框
*/
private AutoAdaptTextSize inputEt;
/**
* 语音
*/
private ImageView voiceIv;
/**
* 表情
*/
private ImageView expressionIv,expressionIvGif;
/**
* 发送按钮
*/
private TextView publishBtn;
private View uploadImgView;
private View showImgView;
private ImageView showImageIv;
/**
* 删除图片
*/
private View delImageView;
private Activity activity;
private ExpressionManager expressionManager;
/**
* 发送文字、图片监听
*/
private CommitDialogListener commitDialogListener;
private String hintStr = "";
private int maxCountLength;
/**
* 选择的gif图
*/
private String gifUrl ;
/**
* 最近历史表情
*/
List<String> gifRecentListStr;
public CommentCommitDialog(Activity activity) {
this(activity, false);
}
public CommentCommitDialog(Activity activity, boolean isLive) {
super(activity, R.style.NoAnimBottom);
this.activity = activity;
this.maxCountLength = isLive?100:900;
}
/**
* 初始化
*/
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
this.setContentView(R.layout.dialog_commit_comment);
if (!EventBus.getDefault().isRegistered(this)) {
EventBus.getDefault().register(this);
}
initDialog();
initView();
}
/**
* 初始化弹出框
*/
private void initDialog() {
this.setCanceledOnTouchOutside(true);
WindowManager manager = this.getWindow().getWindowManager();
DisplayMetrics outMetrics = new DisplayMetrics();
manager.getDefaultDisplay().getMetrics(outMetrics);
int width = outMetrics.widthPixels;
WindowManager.LayoutParams lp = this.getWindow().getAttributes();
lp.width = width;
lp.gravity = Gravity.BOTTOM;
this.getWindow().setAttributes(lp);
}
/**
* 初始化布局控件
*/
private void initView() {
showImgView = findViewById(R.id.cd_fl_img);
showImageIv = findViewById(R.id.cd_iv_img);
delImageView = findViewById(R.id.cd_iv_del_img);
delImageView.setOnClickListener(v -> {
showImgView.setVisibility(View.GONE);
publishStatus();
ImageUtils.getInstance().loadImage(showImageIv, "");
});
uploadImgView = findViewById(R.id.cd_iv_img_btn);
//跳转到选择图片界面
uploadImgView.setOnClickListener(v -> {
if (null != expressionManager) {
expressionManager.voicePressUpLift();
}
//存入临时变量,只有横屏直播间用到,showWithAddBtn
//画中画模式时,修改选择选图片键盘弹框消失问题
MemStoreUtils.put("selectPic", "1");
goSelectPic();
});
inputEt = findViewById(R.id.cd_et_input);
inputEt.setHint(hintStr);
inputEt.setBackListener(textView -> dismiss());
//语音
voiceIv = findViewById(R.id.cd_iv_voice_btn);
//表情
expressionIv = findViewById(R.id.cd_iv_expression_btn);
//定制表情
expressionIvGif = findViewById(R.id.cd_iv_gif_btn);
//全部表情
List<String> gifListStr = new ArrayList<>();
try {
Object obj = MemStoreUtils.getObj("default_map_group","commentgif");
if (obj instanceof List<?>) {
gifListStr = (List<String>) obj;
}
}catch (Exception e){
e.printStackTrace();
}
//没有gif图数据隐藏定制表情
if (gifListStr == null || gifListStr.isEmpty()) {
expressionIvGif.setVisibility(View.GONE);
}
//定制最近表情数据
gifRecentListStr = new ArrayList<>();
try {
String str = SpUtils.getGifIcons();
if(!TextUtils.isEmpty(str)) {
String[] strList = str.split(";");
for (int i = 0; i < strList.length; i++) {
gifRecentListStr.add(strList[i]);
}
}
}catch (Exception e){
e.printStackTrace();
}
//发表按钮
publishBtn = findViewById(R.id.cd_tv_publish_btn);
publishBtn.setOnClickListener(v -> {
if (null != expressionManager) {
expressionManager.voicePressUpLift();
}
String text = getText();
if (commitDialogListener != null) {
if (showImgView.getVisibility() == View.VISIBLE || !TextUtils.isEmpty(text)) {
if(showImgView.getVisibility() == View.VISIBLE ){
commitDialogListener.publish(text,gifUrl);
}else{
commitDialogListener.publish(text,null);
}
// 清空内容
inputEt.setText("");
showImgView.setVisibility(View.GONE);
//清除动图
gifUrl = "";
//评论发布点击埋点
if(mTrackContentBean != null){
if (mTrackContentBean.getTraceBean() == null) {
TraceBean traceBean = new TraceBean();
mTrackContentBean.setTraceBean(traceBean);
}
// 浏览时长
TraceBean traceBean = mTrackContentBean.getTraceBean();
traceBean.duration = 0;
traceBean.shareChannel = "";
if (intentBean != null) {
traceBean.expIds = intentBean.getExpIds();
traceBean.itemId = intentBean.getItemId();
traceBean.traceId = intentBean.getTraceId();
// pageName
String pageName = intentBean.getPageName();
if (StringUtils.isBlank(pageName)) {
mTrackContentBean.setPage_name(PageNameConstants.VIDEO_DETAIL_PAGE);
}else {
mTrackContentBean.setPage_name(pageName);
}
// pageId
String pageId = intentBean.getPageId();
if (StringUtils.isBlank(pageId)) {
mTrackContentBean.setPage_id(PageNameConstants.VIDEO_DETAIL_PAGE);
}else {
mTrackContentBean.setPage_id(pageId);
}
}
mTrackContentBean.setDuration(0);
mTrackContentBean.commentAction();
// CommonTrack.getInstance().contentCommentTrack(mTrackContentBean);
}
}
}
});
//语音录入
View voiceLayout = findViewById(R.id.layout_voice);
//使用旧版表情包
View expressionLayout = findViewById(R.id.layout_expression);
//全部表情
View expressionGifLayout = findViewById(R.id.layout_expression_gif);
//最近使用表情
View expressionGifLayoutRecent = findViewById(R.id.layout_expression_gif_recent);
//表情管理类
expressionManager = new ExpressionManager(activity, voiceLayout, expressionLayout, expressionGifLayout,
expressionGifLayoutRecent, inputEt, voiceIv, expressionIv, expressionIvGif,gifListStr,gifRecentListStr);
if (maxCountLength > 0) {
expressionManager.setMaxCountLength(maxCountLength);
}
expressionManager.setInputTextListener(() -> {
publishStatus();
});
//更新输入框gif图
expressionManager.setGifInputTextListener(this::uploadImgGif);
//更新最近表情输入框gif图
expressionManager.setRecentGifInputTextListener(this::uploadImgGif);
}
public void setIntentBean(VodDetailIntentBean intentBean) {
this.intentBean = intentBean;
}
/**
* 去选择图片
*/
private void goSelectPic() {
PermissionsUtils.getCameraAndSdPermission(activity, new IPmsCallBack() {
@Override
public void granted() {
// Matisse.from(activity)
// .choose(EnumSet.of(MimeType.JPEG, MimeType.PNG, MimeType.GIF, MimeType.BMP), true)
// .countable(true)
// .maxSelectable(1)
// .restrictOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED)
// .thumbnailScale(0.85f)
// .imageEngine(new GlideEngine())
// //这两行要连用 是否在选择图片中展示照相 和适配安卓7.0 FileProvider
// .capture(true)
// .captureStrategy(new CaptureStrategy(true, BaseConstants.FILE_PROVIDER))
// //评论框跳转
// .setSkipType(0)
// //Glide加载方式
// .imageEngine(new GlideEngine())
// //Picasso加载方式
// // .imageEngine(new PicassoEngine())
// // 单个图片限制大小15M
// .addFilter(new PicSizeFilter(15* Filter.K*Filter.K))
// //请求码
// .forResult(10001);
}
@Override
public void notGranted() {
// ToastNightUtil.showShort("没有权限或拒绝权限");
}
});
}
/**
* 发送按钮状态
*/
private void publishStatus() {
String text = getText().trim();
if (showImgView.getVisibility() == View.VISIBLE || !TextUtils.isEmpty(text)) {
publishBtn.setBackgroundResource(R.drawable.shape_comment_input_publish);
publishBtn.setTextColor(ContextCompat.getColor(publishBtn.getContext(),
R.color.res_color_common_C8_keep));
} else {
publishBtn.setBackgroundResource(R.drawable.shape_comment_input_publish_default);
publishBtn.setTextColor(ContextCompat.getColor(publishBtn.getContext(),
R.color.res_color_general_FFFFFF_50_keep));
}
}
@Override
public void show() {
if ("1".equals(BaseConstants.cnCommentAllowed)){
ToastNightUtil.showShort(ResUtils.getString(R.string.res_unable_to_comment_temporarilyk));
return;
}
super.show();
}
/**
* 带有软键盘
*/
public void showWithSoftBoard() {
show();
showSoftBoard();
}
/**
* hint为回复userName:
*/
public void showUserName(String userName) {
setHint(activity.getResources().getString(R.string.str_reply_other_user, userName));
showWithSoftBoard();
}
/**
* hint为说两句
*/
public void showDefaultHint(int bestNoticer) {
if (1 == bestNoticer){
//开启最佳评论框
setHint(activity.getResources().getString(R.string.str_best_reviewer));
}else {
setHint(activity.getResources().getString(R.string.res_say_two_sentences));
}
showWithSoftBoard();
}
/**
* 显示图片选择
*/
public void showWithAddBtn() {
showWithSoftBoard();
uploadImgView.setVisibility(View.VISIBLE);
}
/**
* 隐藏gif定制表情入口
*/
public void hideWithGifBtn() {
showWithSoftBoard();
expressionIvGif.setVisibility(View.GONE);
}
/**
* 设置提示语
*/
public void setHint(String hint) {
this.hintStr = hint;
if (inputEt != null) {
inputEt.setHint(hint);
}
}
public String getText() {
return inputEt.getText().toString();
}
public void setCommitDialogListener(CommitDialogListener commitDialogListener) {
this.commitDialogListener = commitDialogListener;
}
public void closeDialog() {
dismiss();
clear();
}
/**
* 列表监听
*/
public void recycler() {
if (EventBus.getDefault().isRegistered(this)) {
EventBus.getDefault().unregister(this);
}
if (expressionManager != null) {
expressionManager.recycler();
}
}
/**
* 横屏直播上传选择图片
* @param selPaths
*/
@Subscribe(threadMode = ThreadMode.MAIN)
public void uploadImgCallback(ArrayList<String> selPaths) {
ArrayList<String> images = new ArrayList<>();
images.addAll(selPaths);
if (images.size() > 0) {
//接口上传图片
if (commitDialogListener != null) {
commitDialogListener.getUnloadImg(images);
}
if (images.size() > 0) {
showImgView.setVisibility(View.VISIBLE);
publishStatus();
ImageUtils.getInstance().loadImage(showImageIv, images.get(0), R.drawable.default_placeholder_img);
}
}
}
/**
* 选择gif图片到输入框
* @param url
*/
public void uploadImgGif(String url) {
if(!TextUtils.isEmpty(url)){
showImgView.setVisibility(View.VISIBLE);
publishStatus();
ImageUtils.getInstance().loadImage(showImageIv, url, R.drawable.default_placeholder_img);
gifUrl = url;
//最近表情存储
if(gifRecentListStr != null) {
if(gifRecentListStr.contains(gifUrl)){
gifRecentListStr.remove(gifUrl);
}else if (gifRecentListStr.size() > 4){
gifRecentListStr.remove(4);
}
gifRecentListStr.add(0, gifUrl);
}
if(gifRecentListStr != null && gifRecentListStr.size() >0 ){
StringBuilder stringBuilder = new StringBuilder();
for(int i=0; i<gifRecentListStr.size(); i++){
stringBuilder.append(gifRecentListStr.get(i));
if(i < gifRecentListStr.size()-1){
stringBuilder.append(";");
}
if(!TextUtils.isEmpty(stringBuilder)){
SpUtils.saveGifIcon(stringBuilder.toString());
}
}
}
}else{
gifUrl = "";
}
}
/**
* 消失
*/
@Override
public void dismiss() {
super.dismiss();
expressionManager.resetStatus();
// resetImageStatus();
}
/**
* 显示软键盘
*/
private void showSoftBoard() {
// HandlerHelper.main().postDelayed(() -> {
// if (activity == null || activity.isDestroyed()) {
// return;
// }
// if (inputEt != null) {
// KeyboardHelper.showSoftInput(inputEt);
// inputEt.requestFocus();
// }
// }, 200);
}
/**
* 清除所有输入
*/
public void clear() {
if (inputEt != null && inputEt.getEditableText() != null) {
inputEt.getEditableText().clear();
}
resetImageStatus();
}
/**
* 重置图片状态
*/
private void resetImageStatus() {
if (showImgView != null && showImgView.getVisibility() == View.VISIBLE) {
showImgView.setVisibility(View.GONE);
ImageUtils.getInstance().loadImage(showImageIv, "");
}
}
/**
* 清除输入框里的内容
*/
public void clearEditText() {
if (inputEt != null) {
inputEt.setText("");
}
resetImageStatus();
}
/**
*评论发布埋点数据
*/
public void setTrackContentBean(TrackContentBean trackContentBean){
this.mTrackContentBean = trackContentBean;
}
public TrackContentBean getmTrackContentBean(){
return mTrackContentBean;
}
}
... ...
package com.people.comment.dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;
import com.google.android.material.bottomsheet.BottomSheetDialog;
import com.people.comment.R;
import com.wd.foundation.bean.custom.content.CommentItem;
/**
* 个人主页-我的评论列表操作弹框
* * @author ouyang
* * @version [V1.0.0, 2023/5/10]
*/
public class CommentOperationsDialog extends BottomSheetDialog implements View.OnClickListener {
/**
* 回复
*/
public static final int OPERATION_TYPE_ANSWER = 1;
/**
* 删除
*/
public static final int OPERATION_TYPE_DELETE = 2;
/**
* 复制
*/
public static final int OPERATION_TYPE_COPY = 3;
/**
* 分享
*/
public static final int OPERATION_TYPE_SHARE = 4;
/**
* 举报
*/
public static final int OPERATION_TYPE_REPORT = 5;
/**
* 是否主态
*/
private boolean isSelf;
private OnButtonClickListener listener;
private TextView tv_share, tv_answer_delete, tv_copy;
private CommentItem currentEditObj;
private int currentEditPosition;
public CommentOperationsDialog(@NonNull Context context,boolean isSelf) {
super(context, R.style.BottomSheetDialog);
this.isSelf = isSelf;
}
public void setData(CommentItem currentEditFeedObj, int currentEditPosition) {
this.currentEditObj = currentEditFeedObj;
this.currentEditPosition = currentEditPosition;
initView();
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.comment_operations_dialog);
initOption();
TextView tv_cancel = findViewById(R.id.tv_cancel);
tv_answer_delete = findViewById(R.id.tv_answer_delete);
tv_copy = findViewById(R.id.tv_copy);
tv_share = findViewById(R.id.tv_share);
tv_cancel.setOnClickListener(this);
tv_answer_delete.setOnClickListener(this);
tv_copy.setOnClickListener(this);
tv_share.setOnClickListener(this);
initView();
}
public void initView() {
if (tv_share == null){
return;
}
if (isSelf) {
tv_answer_delete.setText("删除");
} else {
tv_answer_delete.setText("回复");
}
}
private void initOption() {
getDelegate().findViewById(com.google.android.material.R.id.design_bottom_sheet)
.setBackgroundColor(ContextCompat.getColor(getContext(),android.R.color.transparent));
getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
}
@Override
public void onClick(View v) {
if (v.getId() == R.id.tv_cancel) {
dismiss();
} else if (v.getId() == R.id.tv_answer_delete) {
if (listener != null) {
if (isSelf) {
// 删除
listener.onDialogItemClick(CommentOperationsDialog.OPERATION_TYPE_DELETE, currentEditObj,currentEditPosition);
}else{
// 回复
listener.onDialogItemClick(CommentOperationsDialog.OPERATION_TYPE_ANSWER, currentEditObj,currentEditPosition);
}
}
dismiss();
} else if (v.getId() == R.id.tv_copy) {
// 复制
if (listener != null) {
listener.onDialogItemClick(CommentOperationsDialog.OPERATION_TYPE_COPY, currentEditObj,currentEditPosition);
}
} else if (v.getId() == R.id.tv_share) {
// 分享
if (listener != null) {
listener.onDialogItemClick(CommentOperationsDialog.OPERATION_TYPE_SHARE, currentEditObj,currentEditPosition);
}
}
}
public interface OnButtonClickListener {
void onDialogItemClick(int types, CommentItem currentObj, int currentPosition);
}
public void setListener(OnButtonClickListener listener) {
this.listener = listener;
}
}
\ No newline at end of file
... ...