首页设备列表
This commit is contained in:
@@ -13,7 +13,6 @@ import androidx.annotation.Nullable;
|
||||
|
||||
import com.ckkj.water.base.entity.MineUserInfoBean;
|
||||
import com.google.gson.Gson;
|
||||
import com.ckkj.water.fate.util.LunarDateLoader;
|
||||
import com.ckkj.water.login.entity.LoginEntity;
|
||||
import com.ckkj.water.network.NetWorkManager;
|
||||
import com.ckkj.water.utils.dataUtil.SharePreUtil;
|
||||
@@ -67,8 +66,6 @@ public class MyApplication extends Application {
|
||||
super.onCreate();
|
||||
instance = this;
|
||||
context = getApplicationContext();
|
||||
// 异步预加载农历数据缓存
|
||||
LunarDateLoader.preloadLunarJson(this);
|
||||
|
||||
boolean isUserAgreed = SharePreUtil.getBoolean(ConstantUtil.SHARE_PRE_NAME,context,ConstantUtil.PRIVACY_POLICY_AGREED);
|
||||
if(isUserAgreed){
|
||||
|
||||
@@ -1,900 +0,0 @@
|
||||
package com.ckkj.water.chat;
|
||||
|
||||
import static android.app.Activity.RESULT_OK;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Color;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.text.Editable;
|
||||
import android.text.TextUtils;
|
||||
import android.text.TextWatcher;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.core.widget.NestedScrollView;
|
||||
import androidx.recyclerview.widget.GridLayoutManager;
|
||||
|
||||
import com.chad.library.adapter.base.BaseQuickAdapter;
|
||||
import com.ckkj.water.AppConfig;
|
||||
import com.ckkj.water.EventMessage;
|
||||
import com.ckkj.water.R;
|
||||
import com.ckkj.water.base.BaseFragment;
|
||||
import com.ckkj.water.chat.adapter.ChatQuestionDetailAdapter;
|
||||
import com.ckkj.water.chat.adapter.ChatZixunAdapter;
|
||||
import com.ckkj.water.chat.entity.ChatQuestionEntity;
|
||||
import com.ckkj.water.custom.GridSpacingItemDecoration;
|
||||
import com.ckkj.water.databinding.IndexLayoutBinding;
|
||||
import com.ckkj.water.chat.adapter.IndexChatAdapter;
|
||||
import com.ckkj.water.chat.adapter.IndexOptionAdapter;
|
||||
import com.ckkj.water.chat.adapter.IndexEnterHintAdapter;
|
||||
import com.ckkj.water.chat.adapter.IndexQuickAskAdapter;
|
||||
import com.ckkj.water.chat.entity.CharHistoryEntity;
|
||||
import com.ckkj.water.chat.entity.ChatAiMsgEntity;
|
||||
import com.ckkj.water.chat.entity.ChatMultiItem;
|
||||
import com.ckkj.water.chat.entity.IndexTemplateEntity;
|
||||
import com.ckkj.water.chat.mvp.IndexContract;
|
||||
import com.ckkj.water.chat.mvp.IndexImpl;
|
||||
import com.ckkj.water.chat.mvp.IndexPresenter;
|
||||
import com.ckkj.water.dialog.ContentReportDialog;
|
||||
import com.ckkj.water.login.LoginActivity;
|
||||
import com.ckkj.water.network.BaseBean;
|
||||
import com.ckkj.water.plate.entity.BaziResultBean;
|
||||
import com.ckkj.water.plate.entity.PaipanCache;
|
||||
import com.ckkj.water.utils.click.ClickUtil;
|
||||
import com.ckkj.water.utils.manager.ColorManage;
|
||||
import com.ckkj.water.utils.show.ToastUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import de.greenrobot.event.Subscribe;
|
||||
import de.greenrobot.event.ThreadMode;
|
||||
import android.content.ClipData;
|
||||
import android.content.ClipboardManager;
|
||||
|
||||
/**
|
||||
* @author fengxiaoyang
|
||||
* @date 2025/7/7
|
||||
* @description TODO: 描述该类的作用
|
||||
*/
|
||||
|
||||
public class ChatFragment extends BaseFragment<IndexLayoutBinding, IndexPresenter> implements IndexContract.IndexView {
|
||||
|
||||
//顶部 adapter
|
||||
private IndexOptionAdapter mOptionAdapter;
|
||||
private ChatZixunAdapter mZixunQuestAdapter;
|
||||
private ChatQuestionDetailAdapter mQuesDetailAdapter;
|
||||
//快速提问 adapter
|
||||
private IndexQuickAskAdapter mQuickAskAdapter;
|
||||
private List<IndexTemplateEntity> mQuickAskList = new ArrayList<>();
|
||||
|
||||
private List<ChatMultiItem> mChatMsgList = new ArrayList<>();
|
||||
//聊天 adapter
|
||||
private IndexChatAdapter mChatAdapter;
|
||||
//欢迎语 adapter
|
||||
private IndexEnterHintAdapter mHintAdapter;
|
||||
//输入的内容
|
||||
private String mCurrentInputContent = "";
|
||||
//当前options 的 pos
|
||||
private int mCurrentStreamPos = 0;
|
||||
//模板数据 list
|
||||
private List<IndexTemplateEntity> mIndexTemList = new ArrayList<>();
|
||||
//输出是否完成
|
||||
private boolean mIsStreamStop = true;
|
||||
//当前选中 option 的 typeID
|
||||
private String mSelectTypeID = "1";
|
||||
//会话 ID
|
||||
private String mSessionId = "";
|
||||
|
||||
// 添加流式数据累积变量
|
||||
private StringBuilder mStreamContentBuilder = new StringBuilder();
|
||||
private ChatAiMsgEntity mCurrentStreamEntity = null;
|
||||
|
||||
// 智能滚动管理
|
||||
private boolean mIsUserScrolling = false;
|
||||
|
||||
// 优化防抖机制
|
||||
private Handler mUpdateHandler = new Handler();
|
||||
private Runnable mUpdateRunnable;
|
||||
|
||||
private List<ChatQuestionEntity> mQuesTypeList = new ArrayList<>();
|
||||
private boolean mIsShowQuestions = true;
|
||||
|
||||
@Override
|
||||
public void initData(Bundle state) {
|
||||
|
||||
mOptionAdapter = new IndexOptionAdapter(mContext, R.layout.index_device_list_item, mIndexTemList);
|
||||
viewBinding.rvOptions.setAdapter(mOptionAdapter);
|
||||
mQuickAskAdapter = new IndexQuickAskAdapter(mContext, R.layout.index_home_quick_ask_item, mQuickAskList);
|
||||
viewBinding.rvQuickAsk.setAdapter(mQuickAskAdapter);
|
||||
mChatAdapter = new IndexChatAdapter(mContext, mChatMsgList, viewBinding.rvChat);
|
||||
viewBinding.rvChat.setAdapter(mChatAdapter);
|
||||
//提问类型
|
||||
GridLayoutManager manager = new GridLayoutManager(mContext, 2);
|
||||
viewBinding.rvChatQuick.setLayoutManager(manager);
|
||||
List<ChatQuestionEntity.SubheadingsDTO> subList = new ArrayList<>();
|
||||
mQuesDetailAdapter = new ChatQuestionDetailAdapter(R.layout.chat_quest_detail_item, subList);
|
||||
viewBinding.rvChatQuick.setAdapter(mQuesDetailAdapter);
|
||||
viewBinding.rvChatQuick.addItemDecoration(new GridSpacingItemDecoration(2, 10, true));
|
||||
mZixunQuestAdapter = new ChatZixunAdapter(mContext, R.layout.chat_zixun_type_item, mQuesTypeList);
|
||||
viewBinding.rvChatType.setAdapter(mZixunQuestAdapter);
|
||||
|
||||
// 设置聊天RecyclerView的LayoutManager(禁用滚动)
|
||||
androidx.recyclerview.widget.LinearLayoutManager chatLayoutManager =
|
||||
new androidx.recyclerview.widget.LinearLayoutManager(mContext);
|
||||
chatLayoutManager.setStackFromEnd(false);
|
||||
viewBinding.rvChat.setLayoutManager(chatLayoutManager);
|
||||
|
||||
// 禁用RecyclerView的滚动,让NestedScrollView处理滚动
|
||||
viewBinding.rvChat.setNestedScrollingEnabled(false);
|
||||
|
||||
mHintAdapter = new IndexEnterHintAdapter(mContext, R.layout.index_enter_hint_item, new ArrayList<>());
|
||||
viewBinding.rvEnterHint.setAdapter(mHintAdapter);
|
||||
|
||||
setAdapterClick();
|
||||
|
||||
// 添加EditText的焦点监听器
|
||||
viewBinding.editInput.setOnFocusChangeListener(new View.OnFocusChangeListener() {
|
||||
@Override
|
||||
public void onFocusChange(View v, boolean hasFocus) {
|
||||
if (hasFocus) {
|
||||
// EditText获取焦点时,延迟滚动到底部,确保键盘弹出后再滚动
|
||||
new Handler().postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
scrollNestedScrollViewToBottom();
|
||||
}
|
||||
}, 300); // 延迟300ms,等待键盘弹出
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
viewBinding.editInput.addTextChangedListener(new TextWatcher() {
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {
|
||||
if (s != null) {
|
||||
mCurrentInputContent = s.toString().trim();
|
||||
if (TextUtils.isEmpty(s.toString().trim())) {
|
||||
viewBinding.imgSend.setImageDrawable(ContextCompat.getDrawable(mContext, R.mipmap.icon_index_send));
|
||||
viewBinding.editInput.setHint("请输入您的问题");
|
||||
} else {
|
||||
viewBinding.imgSend.setImageDrawable(ContextCompat.getDrawable(mContext, R.mipmap.icon_index_send_b));
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
//请求页面模板数据
|
||||
mPresenter.getIndexTemplateDatas();
|
||||
mPresenter.getChatTemplateDatas();
|
||||
//组件增加点击区域
|
||||
ClickUtil.addClickPart(viewBinding.imgCloseQuick, 30);
|
||||
ClickUtil.addClickPart(viewBinding.imgRefresh, 30);
|
||||
ClickUtil.addClickPart(viewBinding.imgHistory, 30);
|
||||
|
||||
// 设置智能滚动监听
|
||||
setupSmartScrollListener();
|
||||
// 设置页面点击监听,用于隐藏键盘
|
||||
setupPageClickListener();
|
||||
// 检查是否有传递过来的参数
|
||||
checkAndHandleBundle();
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查并处理传递过来的Bundle参数
|
||||
*/
|
||||
private void checkAndHandleBundle() {
|
||||
Bundle args = getArguments();
|
||||
if (args != null) {
|
||||
handleBirthInfoBundle(args);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理出生信息Bundle参数
|
||||
*
|
||||
* @param bundle 包含出生信息的Bundle
|
||||
*/
|
||||
public void handleBirthInfoBundle(Bundle bundle) {
|
||||
if (bundle != null) {
|
||||
BaziResultBean baseEntity = PaipanCache.get();
|
||||
// 获取出生信息
|
||||
BaziResultBean.BaseInfoDTO birthInfo = baseEntity.getBaseInfo();
|
||||
BaziResultBean.DetailInfoDTO.SizhuInfoDTO sizhuInfoDTO = baseEntity.getDetailInfo().getSizhuInfo();
|
||||
BaziResultBean.DetailInfoDTO.DayunInfoDTO defaulLiunian = (BaziResultBean.DetailInfoDTO.DayunInfoDTO) bundle.getSerializable("defaul_liunian");
|
||||
if (birthInfo != null) {
|
||||
viewBinding.editInput.setText("我叫" + birthInfo.getName() + "," +
|
||||
((birthInfo.getSex().equals("乾造") ? "男" : "女") + "," +
|
||||
"生于公历" + birthInfo.getGongli() + "," + "当前大运为" + defaulLiunian.getDayunStartYear() + "--" +
|
||||
defaulLiunian.getDayunEndYear() + "," + defaulLiunian.getDayunStartGanzhi() + "大运,四柱为"
|
||||
+ sizhuInfoDTO.getYear().getTg() + sizhuInfoDTO.getYear().getDz() + "、" +
|
||||
sizhuInfoDTO.getMonth().getTg() + sizhuInfoDTO.getMonth().getDz() + "、" +
|
||||
sizhuInfoDTO.getDay().getTg() + sizhuInfoDTO.getDay().getDz() + "、" +
|
||||
sizhuInfoDTO.getHour().getTg() + sizhuInfoDTO.getHour().getDz() + "," +
|
||||
"现在需要你根据我的八字,给我具体分析一下我的事业、感情、健康、财富、格局、喜用神"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 当Fragment参数更新时调用(用于处理onNewIntent的情况)
|
||||
*/
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
|
||||
// 检查是否有新的参数需要处理
|
||||
Bundle args = getArguments();
|
||||
if (args != null && args.getBoolean("goto_index_fragment", false)) {
|
||||
// 处理参数
|
||||
handleBirthInfoBundle(args);
|
||||
|
||||
// 清除标记,避免重复处理
|
||||
args.remove("goto_index_fragment");
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe(threadMode = ThreadMode.MainThread)
|
||||
public void onGetMessage(EventMessage message) {
|
||||
//用户添加地址成功
|
||||
if (message.getEventStrKey().equals(EventMessage.HISTORY_SESSIONID_DELETE_SUCCESS)) {
|
||||
if (message.getMsg().equals(mSessionId)) {
|
||||
// viewBinding.linearOptionHint.setVisibility(View.VISIBLE);
|
||||
mChatMsgList.clear();
|
||||
mChatAdapter.setNewData(mChatMsgList);
|
||||
mSessionId = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 设置页面点击监听器
|
||||
*/
|
||||
private void setupPageClickListener() {
|
||||
viewBinding.rvChat.setOnTouchListener(new View.OnTouchListener() {
|
||||
@Override
|
||||
public boolean onTouch(View v, MotionEvent event) {
|
||||
// 当用户触摸NestedScrollView时,隐藏键盘并清除焦点
|
||||
if (event.getAction() == MotionEvent.ACTION_DOWN) {
|
||||
hideKeyboardAndClearFocus();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 隐藏键盘并清除EditText焦点
|
||||
*/
|
||||
private void hideKeyboardAndClearFocus() {
|
||||
// 清除EditText焦点
|
||||
viewBinding.editInput.clearFocus();
|
||||
|
||||
// 隐藏键盘
|
||||
InputMethodManager imm = (InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
if (imm != null) {
|
||||
imm.hideSoftInputFromWindow(viewBinding.editInput.getWindowToken(), 0);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 滚动NestedScrollView到底部
|
||||
*/
|
||||
private void scrollNestedScrollViewToBottom() {
|
||||
if (viewBinding.nestedScrollChat != null) {
|
||||
// 获取NestedScrollView的子视图(RecyclerView)
|
||||
View childView = viewBinding.nestedScrollChat.getChildAt(0);
|
||||
if (childView != null) {
|
||||
// 滚动到底部
|
||||
viewBinding.nestedScrollChat.smoothScrollTo(0, childView.getHeight());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置智能滚动监听器(修改为监听NestedScrollView)
|
||||
*/
|
||||
private void setupSmartScrollListener() {
|
||||
// 监听NestedScrollView的滚动
|
||||
viewBinding.nestedScrollChat.setOnScrollChangeListener(new NestedScrollView.OnScrollChangeListener() {
|
||||
@Override
|
||||
public void onScrollChange(NestedScrollView v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
|
||||
// 检测用户是否向上滑动
|
||||
if (scrollY < oldScrollY) {
|
||||
// 用户向上滑动
|
||||
mIsUserScrolling = true;
|
||||
} else if (scrollY > oldScrollY) {
|
||||
// 用户向下滑动
|
||||
mIsUserScrolling = true;
|
||||
}
|
||||
|
||||
// 检查是否滚动到底部
|
||||
if (scrollY >= (v.getChildAt(0).getHeight() - v.getHeight())) {
|
||||
// 滚动到底部,恢复自动滚动
|
||||
mIsUserScrolling = false;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
private void setAdapterClick() {
|
||||
//顶部的选项 adapter 点击事件
|
||||
mOptionAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
|
||||
@Override
|
||||
public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
|
||||
if (mCurrentStreamPos != position) {
|
||||
if (mIsStreamStop) {
|
||||
viewBinding.rlQuickAsk.setVisibility(View.GONE);
|
||||
mOptionAdapter.setSelectPos(position);
|
||||
setOptionSelStyle(position);
|
||||
mCurrentStreamPos = position;
|
||||
mSessionId = "";
|
||||
mSelectTypeID = mIndexTemList.get(position).getId();
|
||||
} else {
|
||||
ToastUtil.showShort(mContext, "Ai解答中,请稍后操作");
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
//咨询类型 adapter
|
||||
mZixunQuestAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
|
||||
@Override
|
||||
public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
|
||||
if (mIsStreamStop) {
|
||||
mZixunQuestAdapter.setSelectPos(position);
|
||||
mQuesDetailAdapter.setNewData(mQuesTypeList.get(position).getSubheadings());
|
||||
} else {
|
||||
ToastUtil.showShort(mContext, "Ai解答中,请稍后操作");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
//快速提问
|
||||
mQuesDetailAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
|
||||
@Override
|
||||
public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
|
||||
if (!AppConfig.USER_LOGIN) {
|
||||
goTo(mContext, LoginActivity.class, null);
|
||||
return;
|
||||
}
|
||||
if (!mIsStreamStop) {
|
||||
ToastUtil.showShort(mContext, "Ai解答中,请稍后操作");
|
||||
return;
|
||||
}
|
||||
String quickAskContent = mQuesTypeList.get(mZixunQuestAdapter.getmSelPos()).
|
||||
getSubheadings().get(position).getContent();
|
||||
sendMsgToAi(quickAskContent);
|
||||
}
|
||||
});
|
||||
|
||||
//流式输出,是否完成
|
||||
mChatAdapter.setOnStreamCompleteListener(new IndexChatAdapter.OnStreamCompleteListener() {
|
||||
@Override
|
||||
//此时已经流式输出完成
|
||||
public void onStreamComplete(int position) {
|
||||
mCurrentStreamPos = position;
|
||||
viewBinding.imgSend.setVisibility(View.VISIBLE);
|
||||
viewBinding.imgStop.setVisibility(View.GONE);
|
||||
mIsStreamStop = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStreamStop() {
|
||||
viewBinding.imgSend.setVisibility(View.VISIBLE);
|
||||
viewBinding.imgStop.setVisibility(View.GONE);
|
||||
mIsStreamStop = true;
|
||||
}
|
||||
});
|
||||
mChatAdapter.setOnItemChildClickListener(new BaseQuickAdapter.OnItemChildClickListener() {
|
||||
@Override
|
||||
public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) {
|
||||
switch (view.getId()) {
|
||||
case R.id.img_jb:
|
||||
ContentReportDialog cancelDialog = new ContentReportDialog(mContext, R.layout.dialog_report_reason, "");
|
||||
cancelDialog.show();
|
||||
cancelDialog.setOnDialogListener(new ContentReportDialog.DialogListener() {
|
||||
@Override
|
||||
public void callBackDatas(String reason) {
|
||||
showLoadingDialog();
|
||||
//举报
|
||||
mPresenter.commitReport(reason);
|
||||
}
|
||||
});
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// 设置长按菜单监听器
|
||||
mChatAdapter.setOnItemLongClickMenuListener(new IndexChatAdapter.OnItemLongClickMenuListener() {
|
||||
@Override
|
||||
public void onCopyClick(ChatMultiItem item, int position) {
|
||||
// 处理复制操作
|
||||
String content = item.getMessage().getContent();
|
||||
if (!TextUtils.isEmpty(content)) {
|
||||
ClipboardManager clipboard = (ClipboardManager) mContext.getSystemService(Context.CLIPBOARD_SERVICE);
|
||||
ClipData clip = ClipData.newPlainText("chat_content", content);
|
||||
clipboard.setPrimaryClip(clip);
|
||||
ToastUtil.showShort(mContext, "内容已复制");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReportClick(ChatMultiItem item, int position) {
|
||||
// 处理举报操作
|
||||
ContentReportDialog cancelDialog = new ContentReportDialog(mContext, R.layout.dialog_report_reason, "");
|
||||
cancelDialog.show();
|
||||
cancelDialog.setOnDialogListener(new ContentReportDialog.DialogListener() {
|
||||
@Override
|
||||
public void callBackDatas(String reason) {
|
||||
showLoadingDialog();
|
||||
//举报
|
||||
mPresenter.commitReport(reason);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// 添加长按监听器
|
||||
// mChatAdapter.setOnItemChildLongClickListener(new BaseQuickAdapter.OnItemChildLongClickListener() {
|
||||
// @Override
|
||||
// public boolean onItemChildLongClick(BaseQuickAdapter adapter, View view, int position) {
|
||||
// switch (view.getId()) {
|
||||
// case R.id.tv_text: // 文本内容的view id
|
||||
// XPopup.fixLongClick(view); // 能保证弹窗弹出后,下层的View无法滑动
|
||||
//
|
||||
// // 获取当前消息内容
|
||||
// ChatMultiItem item = mChatMsgList.get(position);
|
||||
// String content = item.getMessage().getContent();
|
||||
//
|
||||
// // 使用链式调用,确保atView在asAttachList之前
|
||||
// new XPopup.Builder(getContext())
|
||||
// .hasShadowBg(false)
|
||||
// .atView(view) // 使用atView而不是watchView
|
||||
// .asAttachList(new String[]{"复制", "举报"},
|
||||
// null,
|
||||
// new OnSelectListener() {
|
||||
// @Override
|
||||
// public void onSelect(int selectPosition, String text) {
|
||||
// switch (selectPosition) {
|
||||
// case 0: // 复制
|
||||
// if (!TextUtils.isEmpty(content)) {
|
||||
// ClipboardManager clipboard = (ClipboardManager) mContext.getSystemService(Context.CLIPBOARD_SERVICE);
|
||||
// ClipData clip = ClipData.newPlainText("chat_content", content);
|
||||
// clipboard.setPrimaryClip(clip);
|
||||
// ToastUtil.showShort(mContext, "内容已复制");
|
||||
// }
|
||||
// break;
|
||||
// case 1: // 举报
|
||||
// ContentReportDialog cancelDialog = new ContentReportDialog(mContext, R.layout.dialog_report_reason, "");
|
||||
// cancelDialog.show();
|
||||
// cancelDialog.setOnDialogListener(new ContentReportDialog.DialogListener() {
|
||||
// @Override
|
||||
// public void callBackDatas(String reason) {
|
||||
// showLoadingDialog();
|
||||
// //举报
|
||||
// mPresenter.commitReport(reason);
|
||||
// }
|
||||
// });
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// })
|
||||
// .show();
|
||||
// return true;
|
||||
// }
|
||||
// return false;
|
||||
// }
|
||||
// });
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 停止输出
|
||||
*/
|
||||
private void stopSteamOutput() {
|
||||
// 停止当前网络请求
|
||||
mPresenter.stopCurrentRequest();
|
||||
|
||||
// 获取当前正在流式输出的位置
|
||||
int currentPosition = mChatMsgList.size() - 1;
|
||||
|
||||
// 标记当前消息为被停止状态
|
||||
mChatAdapter.markAsStopped(currentPosition);
|
||||
|
||||
// 停止适配器中的流式输出
|
||||
mChatAdapter.setStreamerStop(currentPosition);
|
||||
|
||||
// 清除当前流式输出位置
|
||||
mChatAdapter.setCurrentStreamingPosition(-1);
|
||||
|
||||
// 强制更新当前item以显示停止标识
|
||||
mChatAdapter.notifyItemChanged(currentPosition);
|
||||
|
||||
// 恢复UI状态
|
||||
viewBinding.imgSend.setVisibility(View.VISIBLE);
|
||||
viewBinding.imgStop.setVisibility(View.GONE);
|
||||
mIsStreamStop = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
if (data != null) {
|
||||
if (resultCode == RESULT_OK) {
|
||||
switch (requestCode) {
|
||||
case REQUEST_EVENT_CODE_10001:
|
||||
String sessionId = data.getStringExtra("session_id");
|
||||
String numerologyType = data.getStringExtra("numerology_type");
|
||||
int showSelPos = -1;
|
||||
for (int i = 0; i < mIndexTemList.size(); i++) {
|
||||
if (numerologyType.equals(mIndexTemList.get(i).getId())) {
|
||||
showSelPos = i;
|
||||
}
|
||||
}
|
||||
if (mCurrentStreamPos != showSelPos) {
|
||||
|
||||
}
|
||||
if (mIsStreamStop) {
|
||||
viewBinding.rlQuickAsk.setVisibility(View.GONE);
|
||||
mOptionAdapter.setSelectPos(showSelPos);
|
||||
setOptionSelStyle(showSelPos);
|
||||
mCurrentStreamPos = showSelPos;
|
||||
mSelectTypeID = mIndexTemList.get(showSelPos).getId();
|
||||
if (!TextUtils.isEmpty(sessionId)) {
|
||||
mPresenter.getChatDetailByID(sessionId);
|
||||
}
|
||||
} else {
|
||||
ToastUtil.showShort(mContext, "Ai解答中,请稍后操作");
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送消息给 AI
|
||||
*/
|
||||
private void sendMsgToAi(String senMsg) {
|
||||
if (!AppConfig.USER_LOGIN) {
|
||||
goTo(mContext, LoginActivity.class, null);
|
||||
return;
|
||||
}
|
||||
viewBinding.cardQuestion.setVisibility(View.GONE);
|
||||
viewBinding.imgClose.setImageDrawable(ContextCompat.getDrawable(mContext, R.mipmap.icon_chat_down));
|
||||
mIsShowQuestions = false;
|
||||
viewBinding.linearOptionHint.setVisibility(View.GONE);
|
||||
// 重置滚动状态
|
||||
mIsUserScrolling = false;
|
||||
// 清理适配器缓存
|
||||
mChatAdapter.clearCache();
|
||||
|
||||
// 创建用户消息
|
||||
ChatAiMsgEntity chatMsgEntity = new ChatAiMsgEntity();
|
||||
chatMsgEntity.setSessionId(mSessionId);
|
||||
chatMsgEntity.setType(mSelectTypeID);
|
||||
chatMsgEntity.setContent(senMsg);
|
||||
ChatMultiItem userEntity = new ChatMultiItem(ChatMultiItem.TYPE_TEXT_RIGHT, chatMsgEntity);
|
||||
mChatMsgList.add(userEntity);
|
||||
mChatAdapter.notifyItemInserted(mChatMsgList.size() - 1);
|
||||
|
||||
// 创建AI回复消息(初始为空)
|
||||
mCurrentStreamEntity = new ChatAiMsgEntity();
|
||||
mCurrentStreamEntity.setSessionId(mSessionId);
|
||||
mCurrentStreamEntity.setType(mSelectTypeID);
|
||||
mCurrentStreamEntity.setContent(""); // 初始为空
|
||||
ChatMultiItem aiEntity = new ChatMultiItem(ChatMultiItem.TYPE_TEXT_LEFT, mCurrentStreamEntity);
|
||||
mChatMsgList.add(aiEntity);
|
||||
|
||||
// 设置当前流式输出位置
|
||||
int aiMessagePosition = mChatMsgList.size() - 1;
|
||||
mChatAdapter.setCurrentStreamingPosition(aiMessagePosition);
|
||||
mChatAdapter.notifyItemInserted(aiMessagePosition);
|
||||
|
||||
// 重置流式数据累积器
|
||||
mStreamContentBuilder.setLength(0);
|
||||
|
||||
// 清空输入框
|
||||
viewBinding.editInput.setText("");
|
||||
|
||||
// 设置UI状态
|
||||
viewBinding.imgSend.setVisibility(View.GONE);
|
||||
viewBinding.imgStop.setVisibility(View.VISIBLE);
|
||||
|
||||
// 发送消息后自动滚动到底部
|
||||
scrollToBottomAfterSend();
|
||||
|
||||
// 发起流式请求
|
||||
mPresenter.talkToAi(senMsg, mSelectTypeID, mSessionId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IndexPresenter createPresenter() {
|
||||
return new IndexPresenter(new IndexImpl());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getTalkResultSuccess(ChatAiMsgEntity bean) {
|
||||
hideDialogLoading();
|
||||
}
|
||||
|
||||
/**
|
||||
* 首页数据获取成功
|
||||
*
|
||||
* @param list
|
||||
*/
|
||||
@Override
|
||||
public void getIndexTemplateSuccess(List<IndexTemplateEntity> list) {
|
||||
if (list != null && list.size() != 0) {
|
||||
mIndexTemList = list;
|
||||
mOptionAdapter.setNewData(mIndexTemList);
|
||||
setAdapterClick();
|
||||
setOptionSelStyle(0);
|
||||
mSelectTypeID = mIndexTemList.get(0).getId();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 切换设置显示内容
|
||||
*
|
||||
* @param pos
|
||||
*/
|
||||
private void setOptionSelStyle(int pos) {
|
||||
try {
|
||||
mChatMsgList.clear();
|
||||
mChatAdapter.setNewData(mChatMsgList);
|
||||
// 清理缓存
|
||||
mChatAdapter.clearCache();
|
||||
// viewBinding.linearOptionHint.setVisibility(View.VISIBLE);
|
||||
IndexTemplateEntity defaulEntity = mIndexTemList.get(pos);
|
||||
viewBinding.tvTitleExpert.setText(defaulEntity.getTitle() + "专家");
|
||||
viewBinding.tvSelectOptionLable.setText(defaulEntity.getTitle() + "专家");
|
||||
viewBinding.tvSelectOptionSlogan.setText(defaulEntity.getSubheading());
|
||||
if (ColorManage.getInstance().isParsableColor(defaulEntity.getColor())) {
|
||||
viewBinding.tvSelectOptionSlogan.setTextColor(Color.parseColor(defaulEntity.getColor()));
|
||||
} else {
|
||||
viewBinding.tvSelectOptionSlogan.setTextColor(ContextCompat.getColor(mContext, R.color.color_zhu));
|
||||
}
|
||||
//提示语
|
||||
List<String> hintMsgList = new ArrayList<>();
|
||||
hintMsgList = Arrays.asList(defaulEntity.getIntermediateContent().split("#"));
|
||||
mHintAdapter.setNewData(hintMsgList);
|
||||
//快速提问
|
||||
mQuickAskList.clear();
|
||||
List<String> quickAskList = new ArrayList<>();
|
||||
quickAskList = Arrays.asList(defaulEntity.getQuickQuestions().split("#"));
|
||||
for (String content : quickAskList) {
|
||||
IndexTemplateEntity entity = new IndexTemplateEntity();
|
||||
entity.setColor(defaulEntity.getColor());
|
||||
entity.setBlackcolor(defaulEntity.getBlackcolor());
|
||||
entity.setSpliteItemContent(content);
|
||||
mQuickAskList.add(entity);
|
||||
}
|
||||
mQuickAskAdapter.setNewData(mQuickAskList);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNetChange(int netModel) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showError(String message) {
|
||||
hideDialogLoading();
|
||||
ToastUtil.showShort(mContext, message);
|
||||
// 流式传输完成,恢复UI状态
|
||||
viewBinding.imgSend.setVisibility(View.VISIBLE);
|
||||
viewBinding.imgStop.setVisibility(View.GONE);
|
||||
mIsStreamStop = true;
|
||||
|
||||
// 可以在这里处理会话ID等
|
||||
if (mCurrentStreamEntity != null && !TextUtils.isEmpty(mCurrentStreamEntity.getSessionId())) {
|
||||
mSessionId = mCurrentStreamEntity.getSessionId();
|
||||
}
|
||||
|
||||
// 清理当前流式实体
|
||||
mCurrentStreamEntity = null;
|
||||
mStreamContentBuilder.setLength(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void logOut(BaseBean bean) {
|
||||
|
||||
}
|
||||
|
||||
// 实现流式消息接收回调
|
||||
@Override
|
||||
public void onStreamMessageReceived(String messageChunk) {
|
||||
mIsStreamStop = false;
|
||||
if (mCurrentStreamEntity != null) {
|
||||
// 更新当前AI消息的内容
|
||||
mCurrentStreamEntity.setContent(messageChunk);
|
||||
|
||||
// 取消之前的更新任务
|
||||
if (mUpdateRunnable != null) {
|
||||
mUpdateHandler.removeCallbacks(mUpdateRunnable);
|
||||
}
|
||||
|
||||
mUpdateRunnable = () -> {
|
||||
// 只更新最后一个item
|
||||
int lastPosition = mChatMsgList.size() - 1;
|
||||
if (lastPosition >= 0) {
|
||||
// 使用更轻量的更新方式,避免重新布局
|
||||
mChatAdapter.notifyItemChanged(lastPosition, "content_only");
|
||||
|
||||
// 流式输出时,如果用户没有手动滑动,则自动滚动NestedScrollView
|
||||
if (!mIsUserScrolling) {
|
||||
smoothScrollNestedScrollView();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// 增加延迟时间,减少更新频率
|
||||
mUpdateHandler.postDelayed(mUpdateRunnable, 100);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 实现流式完成回调
|
||||
@Override
|
||||
public void onStreamComplete(String complateMsg) {
|
||||
// 流式传输完成,恢复UI状态
|
||||
viewBinding.imgSend.setVisibility(View.VISIBLE);
|
||||
viewBinding.imgStop.setVisibility(View.GONE);
|
||||
mIsStreamStop = true;
|
||||
|
||||
// 清除当前流式输出位置
|
||||
mChatAdapter.setCurrentStreamingPosition(-1);
|
||||
|
||||
// 注意:这里不标记为停止状态,因为这是正常完成
|
||||
|
||||
// 可以在这里处理会话ID等
|
||||
if (mCurrentStreamEntity != null && !TextUtils.isEmpty(mCurrentStreamEntity.getSessionId())) {
|
||||
mSessionId = mCurrentStreamEntity.getSessionId();
|
||||
}
|
||||
|
||||
// 清理当前流式实体
|
||||
mCurrentStreamEntity = null;
|
||||
mStreamContentBuilder.setLength(0);
|
||||
// 假设你最后一个消息是流式的 placeholder,现在替换它
|
||||
ChatMultiItem lastMessage = mChatMsgList.get(mChatMsgList.size() - 1);
|
||||
lastMessage.getMessage().setContent(complateMsg); // 你可以解析 Markdown 变 PlainText,或保留 Markdown 渲染
|
||||
// mChatAdapter.notifyItemChanged(mChatMsgList.size() - 1); // 更新 UI
|
||||
int lastPos = mChatAdapter.getItemCount() - 1;
|
||||
mChatAdapter.updateTipsVisibility(lastPos);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 根据会话 id 查询对话详情
|
||||
*
|
||||
* @param list
|
||||
*/
|
||||
@Override
|
||||
public void getChatDetailSuccess(List<ChatAiMsgEntity> list) {
|
||||
mChatMsgList.clear();
|
||||
if (list != null && list.size() != 0) {
|
||||
mSessionId = list.get(0).getSessionId();
|
||||
}
|
||||
for (ChatAiMsgEntity entity : list) {
|
||||
ChatMultiItem item;
|
||||
if (entity.getRole().equals("user")) {
|
||||
item = new ChatMultiItem(ChatMultiItem.TYPE_TEXT_RIGHT, entity);
|
||||
} else {
|
||||
item = new ChatMultiItem(ChatMultiItem.TYPE_TEXT_LEFT, entity);
|
||||
}
|
||||
mChatMsgList.add(item);
|
||||
}
|
||||
mChatAdapter.setNewData(mChatMsgList);
|
||||
viewBinding.linearOptionHint.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loginLost() {
|
||||
if (isFragmentVisible()) {
|
||||
handleLoginLost();
|
||||
}
|
||||
stopSteamOutput();
|
||||
if (mChatAdapter != null) {
|
||||
mChatAdapter.remove(mChatMsgList.size() - 1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取咨询模板成功
|
||||
*
|
||||
* @param list
|
||||
*/
|
||||
@Override
|
||||
public void getChatZixunSuccess(List<ChatQuestionEntity> list) {
|
||||
this.mQuesTypeList = list;
|
||||
if (list != null) {
|
||||
mZixunQuestAdapter.setNewData(list);
|
||||
mQuesDetailAdapter.setNewData(list.get(0).getSubheadings());
|
||||
setAdapterClick();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 举报成功
|
||||
* @param bean
|
||||
*/
|
||||
@Override
|
||||
public void commitReportSuccess(BaseBean bean) {
|
||||
ToastUtil.showShort(mContext, "星语明灯感谢您的反馈");
|
||||
hideDialogLoading();
|
||||
}
|
||||
|
||||
// 实现sessionId接收回调
|
||||
@Override
|
||||
public void onSessionReceived(String sessionId) {
|
||||
// 保存sessionId
|
||||
mSessionId = sessionId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getHistoryDataSuccess(CharHistoryEntity entity) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteHistorySuccess(BaseBean bean, int delPos) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 平滑滚动NestedScrollView到底部
|
||||
*/
|
||||
private void smoothScrollNestedScrollView() {
|
||||
if (mChatAdapter != null && mChatAdapter.getItemCount() > 0) {
|
||||
// 直接滚动NestedScrollView到底部
|
||||
viewBinding.nestedScrollChat.post(() -> {
|
||||
viewBinding.nestedScrollChat.fullScroll(View.FOCUS_DOWN);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 发送消息后滚动到底部
|
||||
*/
|
||||
private void scrollToBottomAfterSend() {
|
||||
new Handler().postDelayed(() -> {
|
||||
if (isFragmentVisible()) {
|
||||
viewBinding.nestedScrollChat.fullScroll(View.FOCUS_DOWN);
|
||||
}
|
||||
}, 100);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPermissionsGranted(int requestCode, @NonNull List<String> perms) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPermissionsDenied(int requestCode, @NonNull List<String> perms) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,225 +0,0 @@
|
||||
package com.ckkj.water.chat;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
|
||||
import com.chad.library.adapter.base.BaseQuickAdapter;
|
||||
import com.gyf.immersionbar.ImmersionBar;
|
||||
import com.ckkj.water.chat.entity.ChatQuestionEntity;
|
||||
import com.scwang.smart.refresh.footer.ClassicsFooter;
|
||||
import com.scwang.smart.refresh.layout.api.RefreshHeader;
|
||||
import com.ckkj.water.R;
|
||||
import com.ckkj.water.base.BaseActivity;
|
||||
import com.ckkj.water.custom.view.CustomRefreshHeader;
|
||||
import com.ckkj.water.databinding.IndexHistoryLayoutBinding;
|
||||
import com.ckkj.water.chat.adapter.ChatHistoryAdapter;
|
||||
import com.ckkj.water.chat.entity.CharHistoryEntity;
|
||||
import com.ckkj.water.chat.entity.ChatAiMsgEntity;
|
||||
import com.ckkj.water.chat.entity.IndexTemplateEntity;
|
||||
import com.ckkj.water.chat.mvp.IndexContract;
|
||||
import com.ckkj.water.chat.mvp.IndexImpl;
|
||||
import com.ckkj.water.chat.mvp.IndexPresenter;
|
||||
import com.ckkj.water.network.BaseBean;
|
||||
import com.ckkj.water.utils.show.ToastUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author fengxiaoyang
|
||||
* @date 2025/7/11
|
||||
* @description 历史记录
|
||||
*/
|
||||
|
||||
public class ChatHistoryActivity extends BaseActivity<IndexHistoryLayoutBinding, IndexPresenter>
|
||||
implements IndexContract.IndexView {
|
||||
private int mCurrentPage = 1;
|
||||
private ChatHistoryAdapter mAdapter;
|
||||
//历史记录
|
||||
private List<CharHistoryEntity.Sessions> mChatList = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
public IndexPresenter createPresenter() {
|
||||
return new IndexPresenter(new IndexImpl());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLayoutResId(Bundle savedInstanceState) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initData(Bundle savedInstanceState) {
|
||||
super.initData(savedInstanceState);
|
||||
ImmersionBar.with(this)
|
||||
.statusBarColor(R.color.white)
|
||||
.statusBarDarkFont(true)
|
||||
.titleBar(viewBinding.rlTitle) // 替换为你的标题栏View
|
||||
.keyboardEnable(true)
|
||||
.navigationBarDarkIcon(true)
|
||||
.init();
|
||||
viewBinding.includedTitle.tvTitle.setText("历史记录");
|
||||
viewBinding.includedTitle.imgBack.setOnClickListener(c ->finish());
|
||||
mAdapter = new ChatHistoryAdapter(mContext, R.layout.history_item_layout, mChatList);
|
||||
viewBinding.rvData.setAdapter(mAdapter);
|
||||
setAdapterClick();
|
||||
// 设置自定义刷新头
|
||||
RefreshHeader header = new CustomRefreshHeader(mContext);
|
||||
viewBinding.refresh.setRefreshHeader(header);
|
||||
viewBinding.refresh.setRefreshFooter(new ClassicsFooter(mContext));
|
||||
viewBinding.refresh.setOnRefreshListener(layout -> {
|
||||
mCurrentPage = 1;
|
||||
getHistoryDatas();
|
||||
});
|
||||
viewBinding.refresh.setOnLoadMoreListener(layout -> {
|
||||
mCurrentPage++;
|
||||
getHistoryDatas();
|
||||
});
|
||||
showLoadingDialog();
|
||||
getHistoryDatas();
|
||||
}
|
||||
|
||||
private void setAdapterClick() {
|
||||
mAdapter.setOnItemChildClickListener(new BaseQuickAdapter.OnItemChildClickListener() {
|
||||
@Override
|
||||
public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) {
|
||||
switch (view.getId()){
|
||||
case R.id.img_delete:
|
||||
showLoadingDialog();
|
||||
mPresenter.deleteHistoryBySessionID(mChatList.get(position).getSessionId(),position);
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
mAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
|
||||
@Override
|
||||
public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
|
||||
Intent intent = new Intent();
|
||||
intent.putExtra("session_id",mChatList.get(position).getSessionId());
|
||||
intent.putExtra("numerology_type",mChatList.get(position).getNumerologyType());
|
||||
setResult(RESULT_OK,intent);
|
||||
finish();
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
private void getHistoryDatas() {
|
||||
mPresenter.getHistoryDatas(mCurrentPage);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询历史数据成功 g
|
||||
*
|
||||
* @param entity
|
||||
*/
|
||||
@Override
|
||||
public void getHistoryDataSuccess(CharHistoryEntity entity) {
|
||||
hideDialogLoading();
|
||||
int totalPage = entity.getPages();
|
||||
viewBinding.refresh.finishRefresh(300);
|
||||
viewBinding.refresh.finishLoadMore(300);
|
||||
List<CharHistoryEntity.Sessions> list = entity.getSessions();
|
||||
if (mCurrentPage == 1) {
|
||||
mChatList.clear(); // 只在刷新时清除
|
||||
mChatList = list;
|
||||
} else {
|
||||
mChatList.addAll(list);
|
||||
}
|
||||
mAdapter.setNewData(mChatList);
|
||||
// 4. 判断是否还有更多数据
|
||||
if (totalPage == mCurrentPage || list == null || list.size() == 0) {
|
||||
// ✅ 告诉 SmartRefreshLayout 没有更多数据了
|
||||
viewBinding.refresh.setNoMoreData(true);
|
||||
viewBinding.relNoMore.setVisibility(View.VISIBLE); // 自定义底部提示“暂无更多数据”
|
||||
} else {
|
||||
viewBinding.refresh.setNoMoreData(false); // 重置状态
|
||||
viewBinding.relNoMore.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
// 5. 控制空布局和内容显示
|
||||
if (mAdapter.getItemCount() != 0) {
|
||||
viewBinding.refresh.setVisibility(View.VISIBLE);
|
||||
viewBinding.relNoresult.setVisibility(View.GONE);
|
||||
} else {
|
||||
viewBinding.refresh.setVisibility(View.GONE);
|
||||
viewBinding.relNoresult.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除历史会话记录成功
|
||||
* @param bean
|
||||
*/
|
||||
@Override
|
||||
public void deleteHistorySuccess(BaseBean bean, int delPos) {
|
||||
hideDialogLoading();
|
||||
mAdapter.remove(delPos);
|
||||
if(mAdapter.getItemCount() == 0){
|
||||
viewBinding.refresh.setVisibility(View.GONE);
|
||||
viewBinding.relNoresult.setVisibility(View.VISIBLE);
|
||||
viewBinding.relNoMore.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getChatDetailSuccess(List<ChatAiMsgEntity> list) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loginLost() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getChatZixunSuccess(List<ChatQuestionEntity> list) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void commitReportSuccess(BaseBean bean) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getTalkResultSuccess(ChatAiMsgEntity bean) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getIndexTemplateSuccess(List<IndexTemplateEntity> list) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStreamMessageReceived(String messageChunk) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStreamComplete(String complateMsg) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSessionReceived(String sessionId) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void showError(String message) {
|
||||
viewBinding.refresh.finishRefresh(500);
|
||||
viewBinding.refresh.finishLoadMore(200);
|
||||
ToastUtil.showShort(mContext, message);
|
||||
hideDialogLoading();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void logOut(BaseBean bean) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,75 +0,0 @@
|
||||
package com.ckkj.water.chat.adapter;
|
||||
|
||||
import android.content.Context;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.core.content.ContextCompat;
|
||||
|
||||
import com.chad.library.adapter.base.BaseQuickAdapter;
|
||||
import com.chad.library.adapter.base.BaseViewHolder;
|
||||
import com.ckkj.water.R;
|
||||
import com.ckkj.water.chat.entity.CharHistoryEntity;
|
||||
import com.ckkj.water.utils.time.ZYTimeUtils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author fengxiaoyang
|
||||
* @date 2025/7/11
|
||||
* @description TODO: 描述该类的作用
|
||||
*/
|
||||
|
||||
public class ChatHistoryAdapter extends BaseQuickAdapter<CharHistoryEntity.Sessions, BaseViewHolder> {
|
||||
private Context mContext;
|
||||
|
||||
public ChatHistoryAdapter(Context context,int layoutResId, @Nullable List<CharHistoryEntity.Sessions> data) {
|
||||
super(layoutResId, data);
|
||||
this.mContext = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void convert(BaseViewHolder helper, CharHistoryEntity.Sessions item) {
|
||||
ImageView imgType = helper.getView(R.id.img_logo);
|
||||
switch (item.getNumerologyType()){
|
||||
case "1"://八字命理
|
||||
imgType.setImageDrawable(ContextCompat.getDrawable(mContext,R.mipmap.icon_index_bzml));
|
||||
helper.setBackgroundRes(R.id.tv_type_name,R.drawable.shape_history_type_bzml_bg);
|
||||
helper.setTextColor(R.id.tv_type_name,ContextCompat.getColor(mContext,R.color.color_319EF4));
|
||||
break;
|
||||
case "2"://紫微斗数
|
||||
imgType.setImageDrawable(ContextCompat.getDrawable(mContext,R.mipmap. icon_index_zwds));
|
||||
helper.setBackgroundRes(R.id.tv_type_name,R.drawable.shape_history_type_zwds_bg);
|
||||
helper.setTextColor(R.id.tv_type_name,ContextCompat.getColor(mContext,R.color.color_B85CE6));
|
||||
break;
|
||||
case "3"://风水堪舆
|
||||
imgType.setImageDrawable(ContextCompat.getDrawable(mContext,R.mipmap.icon_index_fsky));
|
||||
helper.setBackgroundRes(R.id.tv_type_name,R.drawable.shape_history_type_fsky_bg);
|
||||
helper.setTextColor(R.id.tv_type_name,ContextCompat.getColor(mContext,R.color.color_24B326));
|
||||
break;
|
||||
case "6"://奇门遁甲
|
||||
imgType.setImageDrawable(ContextCompat.getDrawable(mContext,R.mipmap.icon_index_qmdj));
|
||||
helper.setBackgroundRes(R.id.tv_type_name,R.drawable.shape_history_type_qmdj_bg);
|
||||
helper.setTextColor(R.id.tv_type_name,ContextCompat.getColor(mContext,R.color.color_2A5CAA));
|
||||
break;
|
||||
case "10"://五行起名
|
||||
imgType.setImageDrawable(ContextCompat.getDrawable(mContext,R.mipmap. icon_index_wxqm));
|
||||
helper.setBackgroundRes(R.id.tv_type_name,R.drawable.shape_history_type_wxqm_bg);
|
||||
helper.setTextColor(R.id.tv_type_name,ContextCompat.getColor(mContext,R.color.color_E69900));
|
||||
break;
|
||||
default:
|
||||
imgType.setImageDrawable(ContextCompat.getDrawable(mContext,R.mipmap.icon_index_bzml));
|
||||
helper.setBackgroundRes(R.id.tv_type_name,R.drawable.shape_history_type_bzml_bg);
|
||||
helper.setTextColor(R.id.tv_type_name,ContextCompat.getColor(mContext,R.color.color_319EF4));
|
||||
break;
|
||||
}
|
||||
helper.setText(R.id.tv_type_content,item.getFirstUserMessage());
|
||||
helper.setText(R.id.tv_type_name,item.getSessionName());
|
||||
String chatTime = ZYTimeUtils.formatDateOrOneYearAgo(item.getCreateTime());
|
||||
helper.setText(R.id.tv_time,chatTime);
|
||||
helper.addOnClickListener(R.id.img_delete);
|
||||
// helper.addOnClickListener(R.id.rl_title);
|
||||
// helper.addOnClickListener(R.id.tv_type_content);
|
||||
// helper.addOnClickListener(R.id.img_logo);
|
||||
}
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
package com.ckkj.water.chat.adapter;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.chad.library.adapter.base.BaseQuickAdapter;
|
||||
import com.chad.library.adapter.base.BaseViewHolder;
|
||||
import com.ckkj.water.R;
|
||||
import com.ckkj.water.chat.entity.ChatQuestionEntity;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author fengxiaoyang
|
||||
* @date 2025/8/19
|
||||
* @description TODO: 描述该类的作用
|
||||
*/
|
||||
|
||||
public class ChatQuestionDetailAdapter extends BaseQuickAdapter<ChatQuestionEntity.SubheadingsDTO, BaseViewHolder> {
|
||||
|
||||
public ChatQuestionDetailAdapter(int layoutResId, @Nullable List<ChatQuestionEntity.SubheadingsDTO> data) {
|
||||
super(layoutResId, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void convert(BaseViewHolder helper, ChatQuestionEntity.SubheadingsDTO item) {
|
||||
helper.setText(R.id.tv_title,item.getTitle());
|
||||
helper.setText(R.id.tv_content,item.getContent());
|
||||
}
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
package com.ckkj.water.chat.adapter;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.chad.library.adapter.base.BaseQuickAdapter;
|
||||
import com.chad.library.adapter.base.BaseViewHolder;
|
||||
import com.ckkj.water.R;
|
||||
import com.ckkj.water.chat.entity.ChatQuestionEntity;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author fengxiaoyang
|
||||
* @date 2025/7/7
|
||||
* @description TODO: 描述该类的作用
|
||||
*/
|
||||
|
||||
public class ChatZixunAdapter extends BaseQuickAdapter<ChatQuestionEntity, BaseViewHolder> {
|
||||
private Context mContext;
|
||||
private int mSelPos = 0;
|
||||
|
||||
public ChatZixunAdapter(Context context, int layoutResId, @Nullable List<ChatQuestionEntity> data) {
|
||||
super(layoutResId, data);
|
||||
this.mContext = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void convert(BaseViewHolder helper, ChatQuestionEntity item) {
|
||||
helper.setText(R.id.tv_content,item.getTeb());
|
||||
if(helper.getLayoutPosition() == mSelPos){
|
||||
helper.setTextColor(R.id.tv_content,mContext.getColor(R.color.color_zhu));
|
||||
helper.setBackgroundRes(R.id.tv_content, R.drawable.shape_chat_zixun_type);
|
||||
}else{
|
||||
helper.setTextColor(R.id.tv_content,mContext.getColor(R.color.color_7A8699));
|
||||
helper.setBackgroundRes(R.id.tv_content, R.drawable.shape_trans_touming);
|
||||
}
|
||||
}
|
||||
|
||||
public void setSelectPos(int position) {
|
||||
this.mSelPos = position;
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
public int getmSelPos() {
|
||||
return mSelPos;
|
||||
}
|
||||
}
|
||||
@@ -1,244 +0,0 @@
|
||||
package com.ckkj.water.chat.adapter;
|
||||
|
||||
import android.content.Context;
|
||||
import android.text.Spanned;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
|
||||
import com.chad.library.adapter.base.BaseViewHolder;
|
||||
import com.ckkj.water.R;
|
||||
import com.ckkj.water.chat.entity.ChatAiMsgEntity;
|
||||
import com.ckkj.water.chat.entity.ChatMultiItem;
|
||||
import com.ckkj.water.utils.show.ToastUtil;
|
||||
import com.ckkj.water.utils.stream.MarkdownStreamer;
|
||||
import com.lxj.xpopup.XPopup;
|
||||
import com.lxj.xpopup.interfaces.OnSelectListener;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import io.noties.markwon.Markwon;
|
||||
|
||||
/**
|
||||
* @author fengxiaoyang
|
||||
* @date 2025/7/7
|
||||
* @description TODO: 描述该类的作用
|
||||
*/
|
||||
|
||||
public class IndexChatAdapter extends BaseMultiItemQuickAdapter<ChatMultiItem, BaseViewHolder> {
|
||||
private Context mContext;
|
||||
private RecyclerView recyclerView;
|
||||
private OnStreamCompleteListener streamCompleteListener;
|
||||
//convert() 中每次绑定 item 时缓存 MarkdownStreamer 实例
|
||||
private final Map<Integer, MarkdownStreamer> streamerMap = new HashMap<>();
|
||||
|
||||
// 新增:Markdown 解析器
|
||||
private Markwon markwon;
|
||||
|
||||
// 新增:当前正在流式输出的位置
|
||||
private int mCurrentStreamingPosition = -1;
|
||||
// 用于标记哪个 position 需要显示 llTips
|
||||
// 在 IndexChatAdapter 类中新增字段
|
||||
private Integer pendingTipsCheckPos = null;
|
||||
// 新增:记录被停止的位置
|
||||
private final Map<Integer, Boolean> stoppedPositions = new HashMap<>();
|
||||
|
||||
public IndexChatAdapter(Context context, List<ChatMultiItem> data, RecyclerView recyclerView) {
|
||||
super(data);
|
||||
this.mContext = context;
|
||||
this.recyclerView = recyclerView;
|
||||
this.markwon = Markwon.create(context);
|
||||
addItemType(ChatMultiItem.TYPE_TEXT_LEFT, R.layout.item_text_left);
|
||||
addItemType(ChatMultiItem.TYPE_TEXT_RIGHT, R.layout.item_text_right);
|
||||
}
|
||||
|
||||
public void setStreamerStop(int position) {
|
||||
MarkdownStreamer streamer = streamerMap.get(position);
|
||||
if (streamer != null) {
|
||||
streamer.stopStreaming();
|
||||
streamerMap.remove(position);
|
||||
}
|
||||
if (mCurrentStreamingPosition == position) {
|
||||
mCurrentStreamingPosition = -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 标记某个位置为被停止的状态
|
||||
*/
|
||||
public void markAsStopped(int position) {
|
||||
stoppedPositions.put(position, true);
|
||||
// 通知该位置更新显示
|
||||
notifyItemChanged(position);
|
||||
}
|
||||
|
||||
public interface OnStreamCompleteListener {
|
||||
void onStreamComplete(int position);
|
||||
void onStreamStop();
|
||||
}
|
||||
|
||||
public void setOnStreamCompleteListener(OnStreamCompleteListener listener) {
|
||||
this.streamCompleteListener = listener;
|
||||
}
|
||||
|
||||
// 新增:长按菜单项点击回调接口
|
||||
public interface OnItemLongClickMenuListener {
|
||||
void onCopyClick(ChatMultiItem item, int position);
|
||||
void onReportClick(ChatMultiItem item, int position);
|
||||
}
|
||||
|
||||
private OnItemLongClickMenuListener mLongClickMenuListener;
|
||||
|
||||
public void setOnItemLongClickMenuListener(OnItemLongClickMenuListener listener) {
|
||||
this.mLongClickMenuListener = listener;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置当前正在流式输出的位置
|
||||
*/
|
||||
public void setCurrentStreamingPosition(int position) {
|
||||
mCurrentStreamingPosition = position;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 对外暴露的方法:检查某个 position 是否为最后一条,并据此显示/隐藏 llTips。
|
||||
* 仅记录“待检查的位置”并触发该 position 的刷新;实际显示逻辑在 convert() 末尾统一处理。
|
||||
*/
|
||||
public void updateTipsVisibility(int position) {
|
||||
if (position < 0 || position >= getItemCount()) return;
|
||||
pendingTipsCheckPos = position;
|
||||
// notifyItemChanged(position);
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
public void setPendingTipsCheckPos(Integer pendingTipsCheckPos) {
|
||||
this.pendingTipsCheckPos = pendingTipsCheckPos;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void convert(BaseViewHolder helper, ChatMultiItem item) {
|
||||
ChatAiMsgEntity msgEntity = item.getMessage();
|
||||
TextView tvContent = helper.getView(R.id.tv_text);
|
||||
LinearLayout llThinking = helper.getView(R.id.linear_thinking);
|
||||
LinearLayout llStop = helper.getView(R.id.linear_stop);
|
||||
LinearLayout llTips = helper.getView(R.id.linear_tips);
|
||||
int position = helper.getBindingAdapterPosition();
|
||||
helper.addOnClickListener(R.id.img_jb);
|
||||
// helper.addOnLongClickListener(R.id.tv_text);
|
||||
|
||||
if (item.getItemType() == ChatMultiItem.TYPE_TEXT_LEFT) {
|
||||
String content = msgEntity.getContent();
|
||||
if(TextUtils.isEmpty(content)){
|
||||
llThinking.setVisibility(View.VISIBLE);
|
||||
tvContent.setText("");
|
||||
llStop.setVisibility(View.GONE);
|
||||
} else {
|
||||
llThinking.setVisibility(View.GONE);
|
||||
|
||||
// 优化流式输出更新逻辑
|
||||
if (position == mCurrentStreamingPosition) {
|
||||
// 当前正在流式输出的位置
|
||||
try {
|
||||
Spanned spanned = markwon.toMarkdown(content);
|
||||
tvContent.setText(spanned);
|
||||
} catch (Exception e) {
|
||||
tvContent.setText(content);
|
||||
}
|
||||
|
||||
// 显示停止标识(如果被停止)
|
||||
if (stoppedPositions.containsKey(position) && stoppedPositions.get(position)) {
|
||||
llStop.setVisibility(View.VISIBLE);
|
||||
llTips.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
llStop.setVisibility(View.GONE);
|
||||
}
|
||||
} else {
|
||||
// 历史消息,直接显示完整内容
|
||||
try {
|
||||
Spanned spanned = markwon.toMarkdown(content);
|
||||
tvContent.setText(spanned);
|
||||
} catch (Exception e) {
|
||||
tvContent.setText(content);
|
||||
}
|
||||
|
||||
// 历史消息也检查是否被停止
|
||||
if (stoppedPositions.containsKey(position) && stoppedPositions.get(position)) {
|
||||
llStop.setVisibility(View.VISIBLE);
|
||||
llTips.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
llStop.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
}
|
||||
Log.i("mingdenglog","XXXXX---position======" + pendingTipsCheckPos);
|
||||
if (pendingTipsCheckPos != null && position == pendingTipsCheckPos) {
|
||||
Log.i("mingdenglog","position======" + position);
|
||||
Log.i("mingdenglog","getItemCount() - 1 ------" + (getItemCount() - 1) );
|
||||
// 仅当是最后一条才显示 llTips,否则隐藏
|
||||
llTips.setVisibility(position == getItemCount() - 1 ? View.VISIBLE : View.GONE);
|
||||
// 用一次即清
|
||||
// pendingTipsCheckPos = null;
|
||||
}else{
|
||||
llTips.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
switch (item.getItemType()) {
|
||||
case ChatMultiItem.TYPE_TEXT_RIGHT:
|
||||
tvContent.setText(msgEntity.getContent());
|
||||
break;
|
||||
}
|
||||
|
||||
// //必须要在事件发生之前就watch
|
||||
final XPopup.Builder builder = new XPopup.Builder(mContext)
|
||||
.hasShadowBg(false).watchView(tvContent);
|
||||
tvContent.setOnLongClickListener(new View.OnLongClickListener() {
|
||||
@Override
|
||||
public boolean onLongClick(View v) {
|
||||
// 如果正在流式输出,则拦截长按事件,不执行任何操作
|
||||
if (mCurrentStreamingPosition != -1) {
|
||||
// 可以选择性地提示用户
|
||||
ToastUtil.showShort(mContext, "Ai解答中,请稍后操作");
|
||||
return true; // 拦截事件
|
||||
}
|
||||
|
||||
builder.asAttachList(new String[]{"复制", "举报"}, null, new OnSelectListener() {
|
||||
@Override
|
||||
public void onSelect(int menuPosition, String text) {
|
||||
// 通过接口回调处理菜单项点击事件
|
||||
if (mLongClickMenuListener != null) {
|
||||
switch (menuPosition){
|
||||
case 0: // 复制
|
||||
mLongClickMenuListener.onCopyClick(item, position);
|
||||
break;
|
||||
case 1: // 举报
|
||||
mLongClickMenuListener.onReportClick(item, position);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}).show();
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 清理缓存
|
||||
*/
|
||||
public void clearCache() {
|
||||
streamerMap.clear();
|
||||
stoppedPositions.clear();
|
||||
mCurrentStreamingPosition = -1;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
package com.ckkj.water.chat.adapter;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.chad.library.adapter.base.BaseQuickAdapter;
|
||||
import com.chad.library.adapter.base.BaseViewHolder;
|
||||
import com.ckkj.water.R;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author fengxiaoyang
|
||||
* @date 2025/7/7
|
||||
* @description TODO: 描述该类的作用
|
||||
*/
|
||||
|
||||
public class IndexEnterHintAdapter extends BaseQuickAdapter<String, BaseViewHolder> {
|
||||
private Context mContext;
|
||||
private int mSelPos = 0;
|
||||
private String textColor;
|
||||
private String bgColor;
|
||||
|
||||
public void setColor(String textColor,String bgColor){
|
||||
this.textColor = textColor;
|
||||
this.bgColor = bgColor;
|
||||
}
|
||||
public IndexEnterHintAdapter(Context context, int layoutResId, @Nullable List<String> data) {
|
||||
super(layoutResId, data);
|
||||
this.mContext = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void convert(BaseViewHolder helper, String item) {
|
||||
helper.setText(R.id.tv_quick_ask_name,item);
|
||||
}
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
package com.ckkj.water.chat.adapter;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.chad.library.adapter.base.BaseQuickAdapter;
|
||||
import com.chad.library.adapter.base.BaseViewHolder;
|
||||
import com.ckkj.water.R;
|
||||
import com.ckkj.water.chat.entity.IndexTemplateEntity;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author fengxiaoyang
|
||||
* @date 2025/7/7
|
||||
* @description TODO: 描述该类的作用
|
||||
*/
|
||||
|
||||
public class IndexOptionAdapter extends BaseQuickAdapter<IndexTemplateEntity, BaseViewHolder> {
|
||||
private Context mContext;
|
||||
private int mSelPos = 0;
|
||||
|
||||
public IndexOptionAdapter(Context context,int layoutResId, @Nullable List<IndexTemplateEntity> data) {
|
||||
super(layoutResId, data);
|
||||
this.mContext = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void convert(BaseViewHolder helper, IndexTemplateEntity item) {
|
||||
// helper.setText(R.id.tv_option_name,item.getTitle());
|
||||
// if(helper.getLayoutPosition() == mSelPos){
|
||||
// helper.setTextColor(R.id.tv_option_name,mContext.getColor(R.color.white));
|
||||
// helper.setBackgroundRes(R.id.tv_option_name, R.drawable.shape_index_option_selected);
|
||||
// }else{
|
||||
// helper.setTextColor(R.id.tv_option_name,mContext.getColor(R.color.color_zhu));
|
||||
// helper.setBackgroundRes(R.id.tv_option_name, R.drawable.shape_index_option_un_selected);
|
||||
// }
|
||||
}
|
||||
|
||||
public void setSelectPos(int position) {
|
||||
this.mSelPos = position;
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
@@ -1,58 +0,0 @@
|
||||
package com.ckkj.water.chat.adapter;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.drawable.GradientDrawable;
|
||||
import android.util.TypedValue;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.core.content.ContextCompat;
|
||||
|
||||
import com.chad.library.adapter.base.BaseQuickAdapter;
|
||||
import com.chad.library.adapter.base.BaseViewHolder;
|
||||
import com.ckkj.water.R;
|
||||
import com.ckkj.water.chat.entity.IndexTemplateEntity;
|
||||
import com.ckkj.water.utils.manager.ColorManage;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author fengxiaoyang
|
||||
* @date 2025/7/8
|
||||
* @description TODO: 描述该类的作用
|
||||
*/
|
||||
|
||||
public class IndexQuickAskAdapter extends BaseQuickAdapter<IndexTemplateEntity, BaseViewHolder> {
|
||||
private Context context;
|
||||
public IndexQuickAskAdapter(Context context,int layoutResId, @Nullable List<IndexTemplateEntity> data) {
|
||||
super(layoutResId, data);
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void convert(BaseViewHolder helper, IndexTemplateEntity item) {
|
||||
helper.setText(R.id.tv_quick_ask_name,item.getSpliteItemContent());
|
||||
if(ColorManage.getInstance().isParsableColor(item.getColor())){
|
||||
helper.setTextColor(R.id.tv_quick_ask_name, Color.parseColor(item.getColor()));
|
||||
}else{
|
||||
helper.setTextColor(R.id.tv_quick_ask_name, ContextCompat.getColor(mContext,R.color.color_zhu));
|
||||
}
|
||||
if(ColorManage.getInstance().isParsableColor(item.getBlackcolor())){
|
||||
setRoundedBackground(helper.getView(R.id.tv_quick_ask_name),Color.parseColor(item.getBlackcolor()),30);
|
||||
}else{
|
||||
setRoundedBackground(helper.getView(R.id.tv_quick_ask_name),ContextCompat.getColor(mContext,R.color.color_E5F2FB),30);
|
||||
}
|
||||
}
|
||||
|
||||
private void setRoundedBackground(View view, int fillColor, float cornerRadiusDp) {
|
||||
GradientDrawable drawable = new GradientDrawable();
|
||||
drawable.setShape(GradientDrawable.RECTANGLE);
|
||||
drawable.setColor(fillColor); // 设置填充色
|
||||
float radiusPx = TypedValue.applyDimension(
|
||||
TypedValue.COMPLEX_UNIT_DIP, cornerRadiusDp, view.getResources().getDisplayMetrics()
|
||||
);
|
||||
drawable.setCornerRadius(radiusPx); // 设置圆角半径(单位:px)
|
||||
view.setBackground(drawable); // 应用背景
|
||||
}
|
||||
}
|
||||
@@ -1,122 +0,0 @@
|
||||
package com.ckkj.water.chat.entity;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author fengxiaoyang
|
||||
* @date 2025/7/11
|
||||
* @description TODO: 描述该类的作用
|
||||
*/
|
||||
|
||||
public class CharHistoryEntity implements Serializable {
|
||||
private int total;
|
||||
private List<Sessions> sessions;
|
||||
private int pages;
|
||||
private int pageSize;
|
||||
private long userId;
|
||||
private int pageNum;
|
||||
public void setTotal(int total) {
|
||||
this.total = total;
|
||||
}
|
||||
public int getTotal() {
|
||||
return total;
|
||||
}
|
||||
|
||||
public void setSessions(List<Sessions> sessions) {
|
||||
this.sessions = sessions;
|
||||
}
|
||||
public List<Sessions> getSessions() {
|
||||
return sessions;
|
||||
}
|
||||
|
||||
public void setPages(int pages) {
|
||||
this.pages = pages;
|
||||
}
|
||||
public int getPages() {
|
||||
return pages;
|
||||
}
|
||||
|
||||
public void setPageSize(int pageSize) {
|
||||
this.pageSize = pageSize;
|
||||
}
|
||||
public int getPageSize() {
|
||||
return pageSize;
|
||||
}
|
||||
|
||||
public void setUserId(long userId) {
|
||||
this.userId = userId;
|
||||
}
|
||||
public long getUserId() {
|
||||
return userId;
|
||||
}
|
||||
|
||||
public void setPageNum(int pageNum) {
|
||||
this.pageNum = pageNum;
|
||||
}
|
||||
public int getPageNum() {
|
||||
return pageNum;
|
||||
}
|
||||
|
||||
|
||||
public static class Sessions implements Serializable{
|
||||
|
||||
private String sessionId;
|
||||
private long userId;
|
||||
private String sessionName;
|
||||
private String numerologyType;
|
||||
private String firstUserMessage;
|
||||
private Date createTime;
|
||||
private Date updateTime;
|
||||
public void setSessionId(String sessionId) {
|
||||
this.sessionId = sessionId;
|
||||
}
|
||||
public String getSessionId() {
|
||||
return sessionId;
|
||||
}
|
||||
|
||||
public void setUserId(long userId) {
|
||||
this.userId = userId;
|
||||
}
|
||||
public long getUserId() {
|
||||
return userId;
|
||||
}
|
||||
|
||||
public void setSessionName(String sessionName) {
|
||||
this.sessionName = sessionName;
|
||||
}
|
||||
public String getSessionName() {
|
||||
return sessionName;
|
||||
}
|
||||
|
||||
public void setNumerologyType(String numerologyType) {
|
||||
this.numerologyType = numerologyType;
|
||||
}
|
||||
public String getNumerologyType() {
|
||||
return numerologyType;
|
||||
}
|
||||
|
||||
public void setFirstUserMessage(String firstUserMessage) {
|
||||
this.firstUserMessage = firstUserMessage;
|
||||
}
|
||||
public String getFirstUserMessage() {
|
||||
return firstUserMessage;
|
||||
}
|
||||
|
||||
public void setCreateTime(Date createTime) {
|
||||
this.createTime = createTime;
|
||||
}
|
||||
public Date getCreateTime() {
|
||||
return createTime;
|
||||
}
|
||||
|
||||
public void setUpdateTime(Date updateTime) {
|
||||
this.updateTime = updateTime;
|
||||
}
|
||||
public Date getUpdateTime() {
|
||||
return updateTime;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,75 +0,0 @@
|
||||
package com.ckkj.water.chat.entity;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author fengxiaoyang
|
||||
* @date 2025/7/7
|
||||
* @description TODO: 描述该类的作用
|
||||
*/
|
||||
|
||||
public class ChatAiMsgEntity implements Serializable {
|
||||
private int id;
|
||||
private String sessionId;
|
||||
private String type;
|
||||
private String content;
|
||||
private String role;
|
||||
private String messageOrder;
|
||||
private String createTime;
|
||||
|
||||
public String getSessionId() {
|
||||
return sessionId;
|
||||
}
|
||||
|
||||
public void setSessionId(String sessionId) {
|
||||
this.sessionId = sessionId;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getContent() {
|
||||
return content;
|
||||
}
|
||||
|
||||
public void setContent(String content) {
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getRole() {
|
||||
return role;
|
||||
}
|
||||
|
||||
public void setRole(String role) {
|
||||
this.role = role;
|
||||
}
|
||||
|
||||
public String getMessageOrder() {
|
||||
return messageOrder;
|
||||
}
|
||||
|
||||
public void setMessageOrder(String messageOrder) {
|
||||
this.messageOrder = messageOrder;
|
||||
}
|
||||
|
||||
public String getCreateTime() {
|
||||
return createTime;
|
||||
}
|
||||
|
||||
public void setCreateTime(String createTime) {
|
||||
this.createTime = createTime;
|
||||
}
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
package com.ckkj.water.chat.entity;
|
||||
|
||||
import com.chad.library.adapter.base.entity.MultiItemEntity;
|
||||
|
||||
/**
|
||||
* @author fengxiaoyang
|
||||
* @date 2025/7/7
|
||||
* @description TODO: 描述该类的作用
|
||||
*/
|
||||
|
||||
public class ChatMultiItem implements MultiItemEntity {
|
||||
public static final int TYPE_TEXT_LEFT = 1;
|
||||
public static final int TYPE_TEXT_RIGHT = 2;
|
||||
public static final int TYPE_IMAGE_LEFT = 3;
|
||||
public static final int TYPE_IMAGE_RIGHT = 4;
|
||||
public static final int TYPE_VOICE_LEFT = 5;
|
||||
public static final int TYPE_VOICE_RIGHT = 6;
|
||||
public static final int TYPE_TIME = 7; // 新增时间类型
|
||||
|
||||
private int itemType;
|
||||
private ChatAiMsgEntity message;
|
||||
|
||||
public ChatMultiItem(int itemType, ChatAiMsgEntity message) {
|
||||
this.itemType = itemType;
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemType() {
|
||||
return itemType;
|
||||
}
|
||||
|
||||
public void setItemType(int itemType) {
|
||||
this.itemType = itemType;
|
||||
}
|
||||
|
||||
public ChatAiMsgEntity getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public void setMessage(ChatAiMsgEntity message) {
|
||||
this.message = message;
|
||||
}
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
package com.ckkj.water.chat.entity;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* @author fengxiaoyang
|
||||
* @date 2025/8/19
|
||||
* @description TODO: 描述该类的作用
|
||||
*/
|
||||
|
||||
@NoArgsConstructor
|
||||
@Data
|
||||
public class ChatQuestionEntity implements Serializable {
|
||||
|
||||
@SerializedName("teb")
|
||||
private String teb;
|
||||
@SerializedName("subheadings")
|
||||
private List<SubheadingsDTO> subheadings;
|
||||
@SerializedName("id")
|
||||
private String id;
|
||||
|
||||
@NoArgsConstructor
|
||||
@Data
|
||||
public static class SubheadingsDTO {
|
||||
@SerializedName("title")
|
||||
private String title;
|
||||
@SerializedName("content")
|
||||
private String content;
|
||||
}
|
||||
}
|
||||
@@ -1,111 +0,0 @@
|
||||
package com.ckkj.water.chat.entity;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author fengxiaoyang
|
||||
* @date 2025/7/8
|
||||
* @description TODO: 描述该类的作用
|
||||
*/
|
||||
|
||||
public class IndexTemplateEntity implements Serializable {
|
||||
private String id;
|
||||
private String title;
|
||||
private String titletp;
|
||||
private String color;
|
||||
private String blackcolor;
|
||||
private String subheading;
|
||||
private String intermediateContent;
|
||||
private String quickQuestions;
|
||||
private String hide;
|
||||
private String type;
|
||||
private String spliteItemContent;
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public String getTitletp() {
|
||||
return titletp;
|
||||
}
|
||||
|
||||
public void setTitletp(String titletp) {
|
||||
this.titletp = titletp;
|
||||
}
|
||||
|
||||
public String getColor() {
|
||||
return color;
|
||||
}
|
||||
|
||||
public void setColor(String color) {
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
public String getBlackcolor() {
|
||||
return blackcolor;
|
||||
}
|
||||
|
||||
public void setBlackcolor(String blackcolor) {
|
||||
this.blackcolor = blackcolor;
|
||||
}
|
||||
|
||||
public String getSubheading() {
|
||||
return subheading;
|
||||
}
|
||||
|
||||
public void setSubheading(String subheading) {
|
||||
this.subheading = subheading;
|
||||
}
|
||||
|
||||
public String getIntermediateContent() {
|
||||
return intermediateContent;
|
||||
}
|
||||
|
||||
public void setIntermediateContent(String intermediateContent) {
|
||||
this.intermediateContent = intermediateContent;
|
||||
}
|
||||
|
||||
public String getQuickQuestions() {
|
||||
return quickQuestions;
|
||||
}
|
||||
|
||||
public void setQuickQuestions(String quickQuestions) {
|
||||
this.quickQuestions = quickQuestions;
|
||||
}
|
||||
|
||||
public String getHide() {
|
||||
return hide;
|
||||
}
|
||||
|
||||
public void setHide(String hide) {
|
||||
this.hide = hide;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getSpliteItemContent() {
|
||||
return spliteItemContent;
|
||||
}
|
||||
|
||||
public void setSpliteItemContent(String spliteItemContent) {
|
||||
this.spliteItemContent = spliteItemContent;
|
||||
}
|
||||
}
|
||||
@@ -1,78 +0,0 @@
|
||||
package com.ckkj.water.chat.mvp;
|
||||
|
||||
import com.ckkj.water.base.IView;
|
||||
import com.ckkj.water.chat.entity.CharHistoryEntity;
|
||||
import com.ckkj.water.chat.entity.ChatAiMsgEntity;
|
||||
import com.ckkj.water.chat.entity.ChatQuestionEntity;
|
||||
import com.ckkj.water.chat.entity.IndexTemplateEntity;
|
||||
import com.ckkj.water.network.BaseBean;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author fengxiaoyang
|
||||
* @date 2025/7/7
|
||||
* @description TODO: 描述该类的作用
|
||||
*/
|
||||
|
||||
public class IndexContract {
|
||||
public interface DataModel{
|
||||
//发送消息给 AI
|
||||
void sendMsgToAi(Map<String,Object> map, CallBack callBack);
|
||||
//发送消息给 AI
|
||||
void sendMsgToAi(Map<String,Object> map, AiStreamCallback callBack);
|
||||
//停止当前请求
|
||||
void stopCurrentRequest();
|
||||
//获取首页数据
|
||||
void getIndexTemplateDatas(CallBack callBack);
|
||||
//获取会话历史
|
||||
void getHistoryChatDatas(Map<String,Object> map, CallBack callBack);
|
||||
//删除会话
|
||||
void deleteHistoryBySessionID(Map<String,Object> map, CallBack callBack);
|
||||
//根据会话 id,查询记录详情
|
||||
void getChatDetailById(Map<String,Object> map, CallBack callBack);
|
||||
//首页咨询模板
|
||||
void getChatemplateDatas(CallBack callBack);
|
||||
//举报好友
|
||||
void commitReport(Map<String,Object> map,CallBack callBack);
|
||||
}
|
||||
|
||||
public interface CallBack<T> {
|
||||
void success(T msg);
|
||||
void fail(String msg);
|
||||
}
|
||||
|
||||
public interface AiStreamCallback {
|
||||
void onMessage(String messageChunk); // 每次返回一段内容
|
||||
void onError(String error);
|
||||
void onComplete(String complateContent); // 结束
|
||||
void onSessionReceived(String sessionId); // 新增:接收sessionId
|
||||
void loginLost();
|
||||
}
|
||||
|
||||
public interface IndexView extends IView {
|
||||
//发送消息给 AI,获取结果
|
||||
void getTalkResultSuccess(ChatAiMsgEntity bean);
|
||||
//获取首页数据成功
|
||||
void getIndexTemplateSuccess(List<IndexTemplateEntity> list);
|
||||
// 新增流式回调方法
|
||||
void onStreamMessageReceived(String messageChunk);
|
||||
//完成
|
||||
void onStreamComplete(String complateMsg);
|
||||
//接收sessionId
|
||||
void onSessionReceived(String sessionId);
|
||||
//查询历史记录成功 g
|
||||
void getHistoryDataSuccess(CharHistoryEntity entity);
|
||||
//删除会话成功
|
||||
void deleteHistorySuccess(BaseBean bean,int delPos);
|
||||
//根据 id 查询会话详情
|
||||
void getChatDetailSuccess(List<ChatAiMsgEntity> list);
|
||||
//登录失效
|
||||
void loginLost();
|
||||
//获取首页聊天模板
|
||||
void getChatZixunSuccess(List<ChatQuestionEntity> list);
|
||||
//提交举报反馈成功
|
||||
void commitReportSuccess(BaseBean bean);
|
||||
}
|
||||
}
|
||||
@@ -1,575 +0,0 @@
|
||||
package com.ckkj.water.chat.mvp;
|
||||
|
||||
import static android.content.ContentValues.TAG;
|
||||
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.util.Log;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import com.ckkj.water.AppConfig;
|
||||
import com.ckkj.water.chat.entity.CharHistoryEntity;
|
||||
import com.ckkj.water.chat.entity.ChatAiMsgEntity;
|
||||
import com.ckkj.water.chat.entity.ChatQuestionEntity;
|
||||
import com.ckkj.water.chat.entity.IndexTemplateEntity;
|
||||
import com.ckkj.water.network.BaseBean;
|
||||
import com.ckkj.water.network.NetWorkManager;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.net.SocketTimeoutException;
|
||||
|
||||
import io.reactivex.Observer;
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.annotations.NonNull;
|
||||
import io.reactivex.disposables.Disposable;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
import okhttp3.Call;
|
||||
import okhttp3.Callback;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
|
||||
/**
|
||||
* @author fengxiaoyang
|
||||
* @date 2025/7/7
|
||||
* @description TODO: 描述该类的作用
|
||||
*/
|
||||
|
||||
public class IndexImpl implements IndexContract.DataModel{
|
||||
|
||||
@Override
|
||||
public void sendMsgToAi(Map<String, Object> map, IndexContract.CallBack callBack) {
|
||||
try {
|
||||
NetWorkManager.getRequest().indexTalkToAi(NetWorkManager.getToken(),map)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.unsubscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Observer<BaseBean<ChatAiMsgEntity>>() {
|
||||
@Override
|
||||
public void onSubscribe(@NonNull Disposable d) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(@NonNull BaseBean<ChatAiMsgEntity> bean) {
|
||||
if(bean.getCode() == 200){
|
||||
callBack.success(bean.getData());
|
||||
}else{
|
||||
callBack.fail(bean.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(@NonNull Throwable e) {
|
||||
callBack.fail(e.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送消息给 AI - 流式版本
|
||||
* @param map
|
||||
* @param callBack
|
||||
*/
|
||||
private final OkHttpClient client = new OkHttpClient.Builder()
|
||||
.connectTimeout(60, TimeUnit.SECONDS) // 连接超时60秒
|
||||
.readTimeout(60, TimeUnit.SECONDS) // 读取超时60秒
|
||||
.writeTimeout(60, TimeUnit.SECONDS) // 写入超时60秒
|
||||
.callTimeout(60, TimeUnit.SECONDS) // 整个调用超时60秒
|
||||
.build();
|
||||
|
||||
private Call currentCall = null; // 新增:保存当前请求的Call对象
|
||||
private volatile boolean isRequestStopped = false; // 新增:标记是否已停止请求
|
||||
|
||||
@Override
|
||||
public void sendMsgToAi(Map<String, Object> map, IndexContract.AiStreamCallback callBack) {
|
||||
try {
|
||||
String finalUrl = AppConfig.BASE_URL + "mobile/context?" + buildQueryParams(map);
|
||||
Log.d(TAG, "Request URL: " + finalUrl);
|
||||
|
||||
Request request = new Request.Builder()
|
||||
.addHeader("Authorization", "Bearer " + AppConfig.USER_TOKEN)
|
||||
.url(finalUrl)
|
||||
.get()
|
||||
.build();
|
||||
currentCall = client.newCall(request);
|
||||
isRequestStopped = false;
|
||||
|
||||
currentCall.enqueue(new Callback() {
|
||||
@Override
|
||||
public void onFailure(Call call, IOException e) {
|
||||
if (isRequestStopped) return; // 如果已停止,不处理失败回调
|
||||
|
||||
// 检查是否是超时异常
|
||||
String errorMessage = e.getMessage();
|
||||
if (e instanceof SocketTimeoutException ||
|
||||
(errorMessage != null && errorMessage.contains("timeout"))) {
|
||||
errorMessage = "请求超时,请稍后重试";
|
||||
}
|
||||
|
||||
String finalErrorMessage = errorMessage;
|
||||
new Handler(Looper.getMainLooper()).post(() -> {
|
||||
if (callBack != null) callBack.onError(finalErrorMessage);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResponse(Call call, Response response) {
|
||||
if (isRequestStopped) return;
|
||||
|
||||
if (!response.isSuccessful()) {
|
||||
new Handler(Looper.getMainLooper()).post(() -> {
|
||||
if (callBack != null) callBack.onError("请求失败: " + response.code());
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
InputStream inputStream = response.body().byteStream();
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
|
||||
|
||||
try {
|
||||
reader.mark(1024); // 标记流的当前位置
|
||||
String peekLine = reader.readLine();
|
||||
reader.reset(); // 回到标记位置
|
||||
|
||||
// 判断是否是标准 JSON(非流式错误返回)
|
||||
if (peekLine != null && peekLine.trim().startsWith("{")) {
|
||||
StringBuilder jsonBuilder = new StringBuilder();
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
jsonBuilder.append(line);
|
||||
}
|
||||
String responseJson = jsonBuilder.toString();
|
||||
|
||||
JSONObject json = new JSONObject(responseJson);
|
||||
int code = json.optInt("code", 0);
|
||||
String msg = json.optString("msg", "");
|
||||
if (code == 401) {
|
||||
new Handler(Looper.getMainLooper()).post(() -> {
|
||||
if (callBack != null) callBack.loginLost();
|
||||
});
|
||||
} else {
|
||||
new Handler(Looper.getMainLooper()).post(() -> {
|
||||
if (callBack != null) callBack.onError("未知错误: " + msg);
|
||||
});
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// 否则处理为 SSE 流式数据
|
||||
handleSSEStream(reader, callBack);
|
||||
|
||||
} catch (Exception e) {
|
||||
new Handler(Looper.getMainLooper()).post(() -> {
|
||||
// if (callBack != null) callBack.onError("响应异常: " + e.getMessage());
|
||||
});
|
||||
} finally {
|
||||
try {
|
||||
reader.close();
|
||||
response.close();
|
||||
} catch (IOException ignored) {}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
} catch (Exception e) {
|
||||
new Handler(Looper.getMainLooper()).post(() -> {
|
||||
if (callBack != null) callBack.onError("请求异常: " + e.getMessage());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void handleSSEStream(BufferedReader reader, IndexContract.AiStreamCallback callBack) throws IOException {
|
||||
String line;
|
||||
StringBuilder accumulatedContent = new StringBuilder();
|
||||
StringBuilder lastLineBuffer = new StringBuilder();
|
||||
String currentEvent = null;
|
||||
String currentData = null;
|
||||
String sessionId = "";
|
||||
|
||||
while ((line = reader.readLine()) != null) {
|
||||
if (isRequestStopped) break;
|
||||
|
||||
if (line.startsWith("event:")) {
|
||||
currentEvent = line.substring(6).trim();
|
||||
} else if (line.startsWith("data:")) {
|
||||
currentData = line.substring(5).trim();
|
||||
|
||||
if ("session".equals(currentEvent)) {
|
||||
try {
|
||||
JsonObject sessionData = JsonParser.parseString(currentData).getAsJsonObject();
|
||||
sessionId = sessionData.get("sessionId").getAsString();
|
||||
if (callBack != null && !isRequestStopped) {
|
||||
callBack.onSessionReceived(sessionId);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "解析session数据失败", e);
|
||||
}
|
||||
} else if ("chunk".equals(currentEvent)) {
|
||||
try {
|
||||
JsonObject chunkData = JsonParser.parseString(currentData).getAsJsonObject();
|
||||
String content = chunkData.get("content").getAsString();
|
||||
boolean hasNewline = chunkData.get("hasNewline").getAsBoolean();
|
||||
|
||||
if (isTableLineFragment(lastLineBuffer.toString(), content)) {
|
||||
lastLineBuffer.append(content);
|
||||
if (hasNewline) {
|
||||
accumulatedContent.append(lastLineBuffer).append("\n");
|
||||
lastLineBuffer.setLength(0);
|
||||
}
|
||||
} else {
|
||||
if (lastLineBuffer.length() > 0) {
|
||||
accumulatedContent.append(lastLineBuffer);
|
||||
lastLineBuffer.setLength(0);
|
||||
}
|
||||
lastLineBuffer.append(content);
|
||||
if (hasNewline) {
|
||||
accumulatedContent.append(lastLineBuffer).append("\n");
|
||||
lastLineBuffer.setLength(0);
|
||||
}
|
||||
}
|
||||
|
||||
final String currentContent = accumulatedContent.toString();
|
||||
new Handler(Looper.getMainLooper()).post(() -> {
|
||||
if (callBack != null && !isRequestStopped) {
|
||||
callBack.onMessage(currentContent);
|
||||
}
|
||||
});
|
||||
|
||||
} catch (Exception e) {
|
||||
accumulatedContent.append(currentData);
|
||||
final String currentContent = accumulatedContent.toString();
|
||||
new Handler(Looper.getMainLooper()).post(() -> {
|
||||
if (callBack != null && !isRequestStopped) {
|
||||
callBack.onMessage(currentContent);
|
||||
}
|
||||
});
|
||||
}
|
||||
} else if ("complete".equals(currentEvent)) {
|
||||
// 先处理剩余的 lastLineBuffer 内容,但不通过 onMessage 回调
|
||||
if (lastLineBuffer.length() > 0) {
|
||||
accumulatedContent.append(lastLineBuffer);
|
||||
// 注意:这里不调用 callBack.onMessage(),避免触发 onStreamMessageReceived
|
||||
}
|
||||
|
||||
String complateContent = "";
|
||||
try {
|
||||
JsonObject completeData = JsonParser.parseString(currentData).getAsJsonObject();
|
||||
complateContent = completeData.get("fullResponse").getAsString();
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "解析complete数据失败", e);
|
||||
}
|
||||
|
||||
final String finalComplateContent = complateContent;
|
||||
new Handler(Looper.getMainLooper()).post(() -> {
|
||||
if (callBack != null && !isRequestStopped) {
|
||||
callBack.onComplete(finalComplateContent); // 只调用 onComplete
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 处理结束前残留内容
|
||||
// if (lastLineBuffer.length() > 0 && !isRequestStopped) {
|
||||
// accumulatedContent.append(lastLineBuffer);
|
||||
// final String finalContent = accumulatedContent.toString();
|
||||
// new Handler(Looper.getMainLooper()).post(() -> {
|
||||
// if (callBack != null && !isRequestStopped) {
|
||||
// callBack.onMessage(finalContent);
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
}
|
||||
|
||||
/**
|
||||
* 停止当前请求
|
||||
*/
|
||||
public void stopCurrentRequest() {
|
||||
isRequestStopped = true;
|
||||
if (currentCall != null && !currentCall.isCanceled()) {
|
||||
currentCall.cancel();
|
||||
currentCall = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否是表格分隔线片段
|
||||
*/
|
||||
private boolean isTableLineFragment(String last, String curr) {
|
||||
return (last.contains("|") && last.contains("-")) || (curr.contains("|") && curr.contains("-"));
|
||||
}
|
||||
|
||||
// 构造 GET 参数
|
||||
private String buildQueryParams(Map<String, Object> map) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (Map.Entry<String, Object> entry : map.entrySet()) {
|
||||
try {
|
||||
if (sb.length() > 0) sb.append("&");
|
||||
sb.append(URLEncoder.encode(entry.getKey(), "UTF-8"));
|
||||
sb.append("=");
|
||||
sb.append(URLEncoder.encode(String.valueOf(entry.getValue()), "UTF-8"));
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "Encoding error", e);
|
||||
}
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取首页数据
|
||||
*/
|
||||
@Override
|
||||
public void getIndexTemplateDatas(IndexContract.CallBack callBack) {
|
||||
try {
|
||||
NetWorkManager.getRequest().getIndexTemplateDatas()
|
||||
.subscribeOn(Schedulers.io())
|
||||
.unsubscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Observer<BaseBean<List<IndexTemplateEntity>>>() {
|
||||
@Override
|
||||
public void onSubscribe(@NonNull Disposable d) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(@NonNull BaseBean<List<IndexTemplateEntity>> bean) {
|
||||
if(bean.getCode() == 200){
|
||||
callBack.success(bean.getData());
|
||||
}else{
|
||||
callBack.fail(bean.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(@NonNull Throwable e) {
|
||||
callBack.fail(e.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取会话历史记录
|
||||
* @param map
|
||||
* @param callBack
|
||||
*/
|
||||
@Override
|
||||
public void getHistoryChatDatas(Map<String, Object> map, IndexContract.CallBack callBack) {
|
||||
try {
|
||||
NetWorkManager.getRequest().getHistoryList(NetWorkManager.getToken(),map)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.unsubscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Observer<BaseBean<CharHistoryEntity>>() {
|
||||
@Override
|
||||
public void onSubscribe(@NonNull Disposable d) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(@NonNull BaseBean<CharHistoryEntity> bean) {
|
||||
if(bean.getCode() == 200){
|
||||
callBack.success(bean.getData());
|
||||
}else{
|
||||
callBack.fail(bean.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(@NonNull Throwable e) {
|
||||
callBack.fail(e.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除历史会话
|
||||
* @param map
|
||||
* @param callBack
|
||||
*/
|
||||
@Override
|
||||
public void deleteHistoryBySessionID(Map<String, Object> map, IndexContract.CallBack callBack) {
|
||||
try {
|
||||
NetWorkManager.getRequest().deleteHistoryBySessionID(NetWorkManager.getToken(),map)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.unsubscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Observer<BaseBean>() {
|
||||
@Override
|
||||
public void onSubscribe(@NonNull Disposable d) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(@NonNull BaseBean bean) {
|
||||
if(bean.getCode() == 200){
|
||||
callBack.success(bean);
|
||||
}else{
|
||||
callBack.fail(bean.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(@NonNull Throwable e) {
|
||||
callBack.fail(e.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 根据会话 id 查询详情
|
||||
* @param map
|
||||
* @param callBack
|
||||
*/
|
||||
@Override
|
||||
public void getChatDetailById(Map<String, Object> map, IndexContract.CallBack callBack) {
|
||||
try {
|
||||
NetWorkManager.getRequest().getChatDetailById(NetWorkManager.getToken(),map)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.unsubscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Observer<BaseBean<List<ChatAiMsgEntity>>>() {
|
||||
@Override
|
||||
public void onSubscribe(@NonNull Disposable d) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(@NonNull BaseBean<List<ChatAiMsgEntity>> bean) {
|
||||
if(bean.getCode() == 200){
|
||||
callBack.success(bean.getData());
|
||||
}else{
|
||||
callBack.fail(bean.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(@NonNull Throwable e) {
|
||||
callBack.fail(e.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 对话页,咨询模板获取
|
||||
* @param callBack
|
||||
*/
|
||||
@Override
|
||||
public void getChatemplateDatas(IndexContract.CallBack callBack) {
|
||||
try {
|
||||
NetWorkManager.getRequest().aitebcontent()
|
||||
.subscribeOn(Schedulers.io())
|
||||
.unsubscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Observer<BaseBean<List<ChatQuestionEntity>>>() {
|
||||
@Override
|
||||
public void onSubscribe(@NonNull Disposable d) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(@NonNull BaseBean<List<ChatQuestionEntity>> bean) {
|
||||
if(bean.getCode() == 200){
|
||||
callBack.success(bean.getData());
|
||||
}else{
|
||||
callBack.fail(bean.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(@NonNull Throwable e) {
|
||||
callBack.fail(e.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 举报反馈
|
||||
* @param map
|
||||
* @param callBack
|
||||
*/
|
||||
@Override
|
||||
public void commitReport(Map<String, Object> map, IndexContract.CallBack callBack) {
|
||||
try {
|
||||
NetWorkManager.getRequest().commitReporting(NetWorkManager.getToken(),map)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.unsubscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Observer<BaseBean>() {
|
||||
@Override
|
||||
public void onSubscribe(@NonNull Disposable d) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(@NonNull BaseBean bean) {
|
||||
if(bean.getCode() == 200){
|
||||
callBack.success(bean.getData());
|
||||
}else{
|
||||
callBack.fail(bean.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(@NonNull Throwable e) {
|
||||
callBack.fail(e.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,249 +0,0 @@
|
||||
package com.ckkj.water.chat.mvp;
|
||||
|
||||
import com.ckkj.water.EventMessage;
|
||||
import com.ckkj.water.base.BasePresenter;
|
||||
import com.ckkj.water.chat.entity.CharHistoryEntity;
|
||||
import com.ckkj.water.chat.entity.ChatAiMsgEntity;
|
||||
import com.ckkj.water.chat.entity.ChatQuestionEntity;
|
||||
import com.ckkj.water.chat.entity.IndexTemplateEntity;
|
||||
import com.ckkj.water.network.BaseBean;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import de.greenrobot.event.EventBus;
|
||||
|
||||
/**
|
||||
* @author fengxiaoyang
|
||||
* @date 2025/7/7
|
||||
* @description TODO: 描述该类的作用
|
||||
*/
|
||||
|
||||
public class IndexPresenter extends BasePresenter<IndexContract.IndexView> {
|
||||
private IndexImpl impl;
|
||||
|
||||
public IndexPresenter(IndexImpl impl) {
|
||||
this.impl = impl;
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送消息给 AI
|
||||
*
|
||||
* @param content
|
||||
*/
|
||||
// public void talkToAi(String content,String type) {
|
||||
// Map<String,Object> map = new HashMap<>();
|
||||
// map.put("content",content);
|
||||
// map.put("type",type);
|
||||
// map.put("sessionId","");
|
||||
// impl.sendMsgToAi(map, new IndexContract.CallBack<ChatAiMsgEntity>() {
|
||||
// @Override
|
||||
// public void success(ChatAiMsgEntity bean) {
|
||||
// if( IndexPresenter.this.getView() != null){
|
||||
// IndexPresenter.this.getView().getTalkResultSuccess(bean);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void fail(String msg) {
|
||||
// if( IndexPresenter.this.getView() != null){
|
||||
// IndexPresenter.this.getView().showError(msg);
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
public void talkToAi(String content, String type, String sessionID) {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("content", content);
|
||||
map.put("type", type);
|
||||
map.put("sessionId", sessionID);
|
||||
|
||||
impl.sendMsgToAi(map, new IndexContract.AiStreamCallback() {
|
||||
@Override
|
||||
public void onMessage(String messageChunk) {
|
||||
// 流式数据到达时,通知View更新UI
|
||||
if (IndexPresenter.this.getView() != null) {
|
||||
IndexPresenter.this.getView().onStreamMessageReceived(messageChunk);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(String msg) {
|
||||
if (IndexPresenter.this.getView() != null) {
|
||||
IndexPresenter.this.getView().showError(msg);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete(String complateMsg) {
|
||||
// 流式传输完成
|
||||
if (IndexPresenter.this.getView() != null) {
|
||||
IndexPresenter.this.getView().onStreamComplete(complateMsg);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSessionReceived(String sessionId) {
|
||||
// 接收到sessionId时,通知View
|
||||
if (IndexPresenter.this.getView() != null) {
|
||||
IndexPresenter.this.getView().onSessionReceived(sessionId);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loginLost() {
|
||||
if (IndexPresenter.this.getView() != null) {
|
||||
IndexPresenter.this.getView().loginLost();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 停止当前流式请求
|
||||
*/
|
||||
public void stopCurrentRequest() {
|
||||
impl.stopCurrentRequest();
|
||||
}
|
||||
|
||||
/**
|
||||
* 首页模板消息数据获取
|
||||
*/
|
||||
public void getIndexTemplateDatas() {
|
||||
impl.getIndexTemplateDatas(new IndexContract.CallBack<List<IndexTemplateEntity>>() {
|
||||
@Override
|
||||
public void success(List<IndexTemplateEntity> list) {
|
||||
if (IndexPresenter.this.getView() != null) {
|
||||
IndexPresenter.this.getView().getIndexTemplateSuccess(list);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fail(String msg) {
|
||||
if (IndexPresenter.this.getView() != null) {
|
||||
IndexPresenter.this.getView().showError(msg);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取历史记录
|
||||
* @param mCurrentPage
|
||||
*/
|
||||
public void getHistoryDatas(int mCurrentPage) {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("pageNum", mCurrentPage);
|
||||
map.put("pageSize", 10);
|
||||
impl.getHistoryChatDatas(map, new IndexContract.CallBack<CharHistoryEntity>() {
|
||||
@Override
|
||||
public void success(CharHistoryEntity entity) {
|
||||
if (IndexPresenter.this.getView() != null) {
|
||||
IndexPresenter.this.getView().getHistoryDataSuccess(entity);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fail(String msg) {
|
||||
if (IndexPresenter.this.getView() != null) {
|
||||
IndexPresenter.this.getView().showError(msg);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 删除历史记录
|
||||
* @param sessionID
|
||||
*/
|
||||
public void deleteHistoryBySessionID(String sessionID,int delPos) {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("sessionId", sessionID);
|
||||
impl.deleteHistoryBySessionID(map, new IndexContract.CallBack<BaseBean>() {
|
||||
@Override
|
||||
public void success(BaseBean entity) {
|
||||
EventBus.getDefault().post(new EventMessage(EventMessage.HISTORY_SESSIONID_DELETE_SUCCESS,sessionID));
|
||||
if (IndexPresenter.this.getView() != null) {
|
||||
IndexPresenter.this.getView().deleteHistorySuccess(entity,delPos);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fail(String msg) {
|
||||
if (IndexPresenter.this.getView() != null) {
|
||||
IndexPresenter.this.getView().showError(msg);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
/**
|
||||
* 根据sessionID 查询消息记录
|
||||
* @param sessionId
|
||||
*/
|
||||
public void getChatDetailByID(String sessionId) {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("sessionId", sessionId);
|
||||
impl.getChatDetailById(map, new IndexContract.CallBack<List<ChatAiMsgEntity>>() {
|
||||
@Override
|
||||
public void success(List<ChatAiMsgEntity> list) {
|
||||
if (IndexPresenter.this.getView() != null) {
|
||||
IndexPresenter.this.getView().getChatDetailSuccess(list);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fail(String msg) {
|
||||
if (IndexPresenter.this.getView() != null) {
|
||||
IndexPresenter.this.getView().showError(msg);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取首页咨询会话模板
|
||||
*/
|
||||
public void getChatTemplateDatas() {
|
||||
impl.getChatemplateDatas(new IndexContract.CallBack<List<ChatQuestionEntity>>() {
|
||||
@Override
|
||||
public void success(List<ChatQuestionEntity> list) {
|
||||
if (IndexPresenter.this.getView() != null) {
|
||||
IndexPresenter.this.getView().getChatZixunSuccess(list);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fail(String msg) {
|
||||
if (IndexPresenter.this.getView() != null) {
|
||||
IndexPresenter.this.getView().showError(msg);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 举报
|
||||
* @param reason
|
||||
*/
|
||||
public void commitReport(String reason) {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("content", reason);
|
||||
impl.commitReport(map, new IndexContract.CallBack<BaseBean>() {
|
||||
@Override
|
||||
public void success(BaseBean bean) {
|
||||
if (IndexPresenter.this.getView() != null) {
|
||||
IndexPresenter.this.getView().commitReportSuccess(bean);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fail(String msg) {
|
||||
if (IndexPresenter.this.getView() != null) {
|
||||
IndexPresenter.this.getView().showError(msg);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -16,7 +16,6 @@ import androidx.annotation.NonNull;
|
||||
import com.ckkj.water.ConstantUtil;
|
||||
import com.ckkj.water.R;
|
||||
import com.ckkj.water.base.BaseActivity;
|
||||
import com.ckkj.water.chat.mvp.IndexPresenter;
|
||||
import com.ckkj.water.databinding.AddDeviceLayoutBinding;
|
||||
import com.ckkj.water.device.mvp.DeviceContract;
|
||||
import com.ckkj.water.device.mvp.DeviceImpl;
|
||||
|
||||
@@ -123,15 +123,14 @@ public class SelectWifiActivity extends BaseActivity<DeviceResetWifiBinding, Dev
|
||||
|
||||
case R.id.tv_select_wifi:
|
||||
String[] permission = {
|
||||
Manifest.permission.BLUETOOTH_SCAN,
|
||||
Manifest.permission.ACCESS_FINE_LOCATION
|
||||
};
|
||||
boolean hasPermission = hasRecordPermission(permission);
|
||||
if(!hasPermission){
|
||||
goTo(mContext, PermissionActivity.class,null);
|
||||
}else{
|
||||
scanWifi();
|
||||
}
|
||||
scanWifi();
|
||||
break;
|
||||
|
||||
case R.id.tv_next:
|
||||
|
||||
@@ -1,52 +0,0 @@
|
||||
package com.ckkj.water.fate.adapter;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.chad.library.adapter.base.BaseQuickAdapter;
|
||||
import com.chad.library.adapter.base.BaseViewHolder;
|
||||
import com.ckkj.water.R;
|
||||
import com.ckkj.water.fate.entity.FateHistoryEntity;
|
||||
import com.ckkj.water.utils.color.FateDataUtil;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author fengxiaoyang
|
||||
* @date 2025/7/24
|
||||
* @description TODO: 描述该类的作用
|
||||
*/
|
||||
|
||||
public class FateHistoryAdapter extends BaseQuickAdapter<FateHistoryEntity.HistoryList, BaseViewHolder> {
|
||||
private Context mContext;
|
||||
public FateHistoryAdapter(Context context,int layoutResId, @Nullable List<FateHistoryEntity.HistoryList> data) {
|
||||
super(layoutResId, data);
|
||||
this.mContext = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void convert(BaseViewHolder holder, FateHistoryEntity.HistoryList item) {
|
||||
holder.setText(R.id.tv_date,item.getRecordDate());
|
||||
holder.setText(R.id.tv_week,item.getDayOfWeek());
|
||||
if(item.isToday()){
|
||||
holder.setVisible(R.id.tv_today,true);
|
||||
}else{
|
||||
holder.setVisible(R.id.tv_today,false);
|
||||
}
|
||||
holder.setText(R.id.tv_name,item.getName());
|
||||
holder.setText(R.id.tv_location,item.getCurrentPlace());
|
||||
holder.setText(R.id.tv_weather,item.getWeatherCondition());
|
||||
holder.setText(R.id.tv_star,item.getConstellation());
|
||||
holder.setText(R.id.tv_score,item.getOverallScore() + "");
|
||||
holder.setText(R.id.tv_syy_score,item.getCareerScore() + "");
|
||||
holder.setText(R.id.tv_gqy_score,item.getLoveScore() + "");
|
||||
holder.setText(R.id.tv_jky_score,item.getHealthScore() + "");
|
||||
holder.setText(R.id.tv_cfy_score,item.getWealthScore() + "");
|
||||
holder.setTextColor(R.id.tv_score, FateDataUtil.getScoreColor(item.getOverallScore()));
|
||||
holder.setTextColor(R.id.tv_syy_score, FateDataUtil.getScoreColor(item.getCareerScore()));
|
||||
holder.setTextColor(R.id.tv_gqy_score, FateDataUtil.getScoreColor(item.getLoveScore()));
|
||||
holder.setTextColor(R.id.tv_jky_score, FateDataUtil.getScoreColor(item.getHealthScore()));
|
||||
holder.setTextColor(R.id.tv_cfy_score, FateDataUtil.getScoreColor(item.getWealthScore()));
|
||||
}
|
||||
}
|
||||
@@ -1,50 +0,0 @@
|
||||
package com.ckkj.water.fate.adapter;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.chad.library.adapter.base.BaseQuickAdapter;
|
||||
import com.chad.library.adapter.base.BaseViewHolder;
|
||||
import com.ckkj.water.R;
|
||||
import com.ckkj.water.fate.entity.CityDataEntity;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author fengxiaoyang
|
||||
* @date 2025/7/18
|
||||
* @description TODO: 描述该类的作用
|
||||
*/
|
||||
|
||||
public class SelectCityAdapter extends BaseQuickAdapter<CityDataEntity, BaseViewHolder> {
|
||||
private Context mContext;
|
||||
private int mSelPos = -1;
|
||||
public SelectCityAdapter(Context context,int layoutResId, @Nullable List<CityDataEntity> data) {
|
||||
super(layoutResId, data);
|
||||
this.mContext = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void convert(BaseViewHolder helper, CityDataEntity item) {
|
||||
helper.setText(R.id.tv_city_name,item.getCityName());
|
||||
if(mSelPos == helper.getLayoutPosition()){
|
||||
helper.setVisible(R.id.img_select,true);
|
||||
}else{
|
||||
helper.setVisible(R.id.img_select,false);
|
||||
}
|
||||
}
|
||||
|
||||
public void setSelPos(int pos){
|
||||
this.mSelPos = pos;
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
public int getmSelPos() {
|
||||
return mSelPos;
|
||||
}
|
||||
|
||||
public void setmSelPos(int mSelPos) {
|
||||
this.mSelPos = mSelPos;
|
||||
}
|
||||
}
|
||||
@@ -1,203 +0,0 @@
|
||||
package com.ckkj.water.fate.entity;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author fengxiaoyang
|
||||
* @date 2025/7/18
|
||||
* @description TODO: 描述该类的作用
|
||||
*/
|
||||
|
||||
public class CityDataEntity implements Serializable {
|
||||
private int id;
|
||||
private String cityCode;
|
||||
private String cityName;
|
||||
private String cityNameEn;
|
||||
private String provinceCode;
|
||||
private String provinceName;
|
||||
private int cityLevel;
|
||||
private String cityType;
|
||||
private double longitude;
|
||||
private double latitude;
|
||||
private String population;
|
||||
private String area;
|
||||
private String gdp;
|
||||
private String zipCode;
|
||||
private String phoneCode;
|
||||
private int isCapital;
|
||||
private int isActive;
|
||||
private int sortOrder;
|
||||
private String remark;
|
||||
private String createdTime;
|
||||
private String updatedTime;
|
||||
private String capitalCity;
|
||||
|
||||
public String getCapitalCity() {
|
||||
return capitalCity;
|
||||
}
|
||||
|
||||
public void setCapitalCity(String capitalCity) {
|
||||
this.capitalCity = capitalCity;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getCityCode() {
|
||||
return cityCode;
|
||||
}
|
||||
|
||||
public void setCityCode(String cityCode) {
|
||||
this.cityCode = cityCode;
|
||||
}
|
||||
|
||||
public String getCityName() {
|
||||
return cityName;
|
||||
}
|
||||
|
||||
public void setCityName(String cityName) {
|
||||
this.cityName = cityName;
|
||||
}
|
||||
|
||||
public String getCityNameEn() {
|
||||
return cityNameEn;
|
||||
}
|
||||
|
||||
public void setCityNameEn(String cityNameEn) {
|
||||
this.cityNameEn = cityNameEn;
|
||||
}
|
||||
|
||||
public String getProvinceCode() {
|
||||
return provinceCode;
|
||||
}
|
||||
|
||||
public void setProvinceCode(String provinceCode) {
|
||||
this.provinceCode = provinceCode;
|
||||
}
|
||||
|
||||
public String getProvinceName() {
|
||||
return provinceName;
|
||||
}
|
||||
|
||||
public void setProvinceName(String provinceName) {
|
||||
this.provinceName = provinceName;
|
||||
}
|
||||
|
||||
public int getCityLevel() {
|
||||
return cityLevel;
|
||||
}
|
||||
|
||||
public void setCityLevel(int cityLevel) {
|
||||
this.cityLevel = cityLevel;
|
||||
}
|
||||
|
||||
public String getCityType() {
|
||||
return cityType;
|
||||
}
|
||||
|
||||
public void setCityType(String cityType) {
|
||||
this.cityType = cityType;
|
||||
}
|
||||
|
||||
public double getLongitude() {
|
||||
return longitude;
|
||||
}
|
||||
|
||||
public void setLongitude(double longitude) {
|
||||
this.longitude = longitude;
|
||||
}
|
||||
|
||||
public double getLatitude() {
|
||||
return latitude;
|
||||
}
|
||||
|
||||
public void setLatitude(double latitude) {
|
||||
this.latitude = latitude;
|
||||
}
|
||||
|
||||
public String getPopulation() {
|
||||
return population;
|
||||
}
|
||||
|
||||
public void setPopulation(String population) {
|
||||
this.population = population;
|
||||
}
|
||||
|
||||
public String getArea() {
|
||||
return area;
|
||||
}
|
||||
|
||||
public void setArea(String area) {
|
||||
this.area = area;
|
||||
}
|
||||
|
||||
public String getGdp() {
|
||||
return gdp;
|
||||
}
|
||||
|
||||
public void setGdp(String gdp) {
|
||||
this.gdp = gdp;
|
||||
}
|
||||
|
||||
public String getZipCode() {
|
||||
return zipCode;
|
||||
}
|
||||
|
||||
public void setZipCode(String zipCode) {
|
||||
this.zipCode = zipCode;
|
||||
}
|
||||
|
||||
public String getPhoneCode() {
|
||||
return phoneCode;
|
||||
}
|
||||
|
||||
public void setPhoneCode(String phoneCode) {
|
||||
this.phoneCode = phoneCode;
|
||||
}
|
||||
|
||||
public int getIsCapital() {
|
||||
return isCapital;
|
||||
}
|
||||
|
||||
public void setIsCapital(int isCapital) {
|
||||
this.isCapital = isCapital;
|
||||
}
|
||||
|
||||
public int getIsActive() {
|
||||
return isActive;
|
||||
}
|
||||
|
||||
public void setIsActive(int isActive) {
|
||||
this.isActive = isActive;
|
||||
}
|
||||
|
||||
public int getSortOrder() {
|
||||
return sortOrder;
|
||||
}
|
||||
|
||||
public void setSortOrder(int sortOrder) {
|
||||
this.sortOrder = sortOrder;
|
||||
}
|
||||
|
||||
public String getRemark() {
|
||||
return remark;
|
||||
}
|
||||
|
||||
public void setRemark(String remark) {
|
||||
this.remark = remark;
|
||||
}
|
||||
|
||||
public void setCreatedTime(String createdTime) {
|
||||
this.createdTime = createdTime;
|
||||
}
|
||||
|
||||
public void setUpdatedTime(String updatedTime) {
|
||||
this.updatedTime = updatedTime;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,139 +0,0 @@
|
||||
package com.ckkj.water.fate.entity;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author fengxiaoyang
|
||||
* @date 2025/7/25
|
||||
* @description TODO: 描述该类的作用
|
||||
*/
|
||||
|
||||
public class FateHistoryEntity {
|
||||
private List<HistoryList> list;
|
||||
private int total;
|
||||
public void setList(List<HistoryList> list) {
|
||||
this.list = list;
|
||||
}
|
||||
public List<HistoryList> getList() {
|
||||
return list;
|
||||
}
|
||||
|
||||
public void setTotal(int total) {
|
||||
this.total = total;
|
||||
}
|
||||
public int getTotal() {
|
||||
return total;
|
||||
}
|
||||
|
||||
public static class HistoryList implements Serializable{
|
||||
private String recordDate;
|
||||
private String dayOfWeek;
|
||||
private String name;
|
||||
private String currentPlace;
|
||||
private String weatherCondition;
|
||||
private String constellation;
|
||||
private int overallScore;
|
||||
private int careerScore;
|
||||
private int loveScore;
|
||||
private int healthScore;
|
||||
private int wealthScore;
|
||||
private boolean isToday;
|
||||
|
||||
public String getRecordDate() {
|
||||
return recordDate;
|
||||
}
|
||||
|
||||
public void setRecordDate(String recordDate) {
|
||||
this.recordDate = recordDate;
|
||||
}
|
||||
|
||||
public String getDayOfWeek() {
|
||||
return dayOfWeek;
|
||||
}
|
||||
|
||||
public void setDayOfWeek(String dayOfWeek) {
|
||||
this.dayOfWeek = dayOfWeek;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getCurrentPlace() {
|
||||
return currentPlace;
|
||||
}
|
||||
|
||||
public void setCurrentPlace(String currentPlace) {
|
||||
this.currentPlace = currentPlace;
|
||||
}
|
||||
|
||||
public String getWeatherCondition() {
|
||||
return weatherCondition;
|
||||
}
|
||||
|
||||
public void setWeatherCondition(String weatherCondition) {
|
||||
this.weatherCondition = weatherCondition;
|
||||
}
|
||||
|
||||
public String getConstellation() {
|
||||
return constellation;
|
||||
}
|
||||
|
||||
public void setConstellation(String constellation) {
|
||||
this.constellation = constellation;
|
||||
}
|
||||
|
||||
public int getOverallScore() {
|
||||
return overallScore;
|
||||
}
|
||||
|
||||
public void setOverallScore(int overallScore) {
|
||||
this.overallScore = overallScore;
|
||||
}
|
||||
|
||||
public int getCareerScore() {
|
||||
return careerScore;
|
||||
}
|
||||
|
||||
public void setCareerScore(int careerScore) {
|
||||
this.careerScore = careerScore;
|
||||
}
|
||||
|
||||
public int getLoveScore() {
|
||||
return loveScore;
|
||||
}
|
||||
|
||||
public void setLoveScore(int loveScore) {
|
||||
this.loveScore = loveScore;
|
||||
}
|
||||
|
||||
public int getHealthScore() {
|
||||
return healthScore;
|
||||
}
|
||||
|
||||
public void setHealthScore(int healthScore) {
|
||||
this.healthScore = healthScore;
|
||||
}
|
||||
|
||||
public int getWealthScore() {
|
||||
return wealthScore;
|
||||
}
|
||||
|
||||
public void setWealthScore(int wealthScore) {
|
||||
this.wealthScore = wealthScore;
|
||||
}
|
||||
|
||||
public boolean isToday() {
|
||||
return isToday;
|
||||
}
|
||||
|
||||
public void setToday(boolean today) {
|
||||
isToday = today;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,66 +0,0 @@
|
||||
package com.ckkj.water.fate.entity;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author fengxiaoyang
|
||||
* @date 2025/7/16
|
||||
* @description TODO: 描述该类的作用
|
||||
*/
|
||||
|
||||
public class LunarYearEntity implements Serializable {
|
||||
public String year; // 年份
|
||||
public List<LunarMonth> month; // 月份列表
|
||||
// Gson需要无参构造
|
||||
public LunarYearEntity() {}
|
||||
|
||||
public String getYear() {
|
||||
return year;
|
||||
}
|
||||
|
||||
public void setYear(String year) {
|
||||
this.year = year;
|
||||
}
|
||||
|
||||
public List<LunarMonth> getMonth() {
|
||||
return month;
|
||||
}
|
||||
|
||||
public void setMonth(List<LunarMonth> month) {
|
||||
this.month = month;
|
||||
}
|
||||
|
||||
public static class LunarMonth implements Serializable{
|
||||
public String name; // 月份数字(字符串形式)
|
||||
public int isRun; // 是否闰月(0=否,1=是)
|
||||
public int isAllDay; // 是否包含三十(0=29天,1=30天)
|
||||
|
||||
// Gson需要无参构造
|
||||
public LunarMonth() {}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public int getIsRun() {
|
||||
return isRun;
|
||||
}
|
||||
|
||||
public void setIsRun(int isRun) {
|
||||
this.isRun = isRun;
|
||||
}
|
||||
|
||||
public int getIsAllDay() {
|
||||
return isAllDay;
|
||||
}
|
||||
|
||||
public void setIsAllDay(int isAllDay) {
|
||||
this.isAllDay = isAllDay;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,526 +0,0 @@
|
||||
package com.ckkj.water.fate.entity;
|
||||
|
||||
import com.ckkj.water.base.entity.UserInfoEntity;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author fengxiaoyang
|
||||
* @date 2025/7/21
|
||||
* @description TODO: 描述该类的作用
|
||||
*/
|
||||
|
||||
public class TodayFateEntity implements Serializable {
|
||||
private FortuneAnalysis fortuneAnalysis;
|
||||
private UserInfoEntity userInfo;
|
||||
private TodayInfo todayInfo;
|
||||
private String weatherCondition;
|
||||
private String weatherTemperature;
|
||||
private int todayVisitCount;
|
||||
private int totalVisitDays;
|
||||
public void setFortuneAnalysis(FortuneAnalysis fortuneAnalysis) {
|
||||
this.fortuneAnalysis = fortuneAnalysis;
|
||||
}
|
||||
public FortuneAnalysis getFortuneAnalysis() {
|
||||
return fortuneAnalysis;
|
||||
}
|
||||
|
||||
public void setUserInfo(UserInfoEntity userInfo) {
|
||||
this.userInfo = userInfo;
|
||||
}
|
||||
public UserInfoEntity getUserInfo() {
|
||||
return userInfo;
|
||||
}
|
||||
|
||||
public void setTodayInfo(TodayInfo todayInfo) {
|
||||
this.todayInfo = todayInfo;
|
||||
}
|
||||
public TodayInfo getTodayInfo() {
|
||||
return todayInfo;
|
||||
}
|
||||
|
||||
public void setWeatherCondition(String weatherCondition) {
|
||||
this.weatherCondition = weatherCondition;
|
||||
}
|
||||
public String getWeatherCondition() {
|
||||
return weatherCondition;
|
||||
}
|
||||
|
||||
public void setWeatherTemperature(String weatherTemperature) {
|
||||
this.weatherTemperature = weatherTemperature;
|
||||
}
|
||||
public String getWeatherTemperature() {
|
||||
return weatherTemperature;
|
||||
}
|
||||
|
||||
public void setTodayVisitCount(int todayVisitCount) {
|
||||
this.todayVisitCount = todayVisitCount;
|
||||
}
|
||||
public int getTodayVisitCount() {
|
||||
return todayVisitCount;
|
||||
}
|
||||
|
||||
public void setTotalVisitDays(int totalVisitDays) {
|
||||
this.totalVisitDays = totalVisitDays;
|
||||
}
|
||||
public int getTotalVisitDays() {
|
||||
return totalVisitDays;
|
||||
}
|
||||
|
||||
/**
|
||||
* Copyright 2025 bejson.com
|
||||
*/
|
||||
/**
|
||||
* Auto-generated: 2025-07-21 17:23:17
|
||||
*
|
||||
* @author bejson.com (i@bejson.com)
|
||||
* @website http://www.bejson.com/java2pojo/
|
||||
*/
|
||||
public static class TodayInfo implements Serializable{
|
||||
|
||||
private Date date;
|
||||
private String weekDay;
|
||||
private int year;
|
||||
private int month;
|
||||
private int day;
|
||||
public void setDate(Date date) {
|
||||
this.date = date;
|
||||
}
|
||||
public Date getDate() {
|
||||
return date;
|
||||
}
|
||||
|
||||
public void setWeekDay(String weekDay) {
|
||||
this.weekDay = weekDay;
|
||||
}
|
||||
public String getWeekDay() {
|
||||
return weekDay;
|
||||
}
|
||||
|
||||
public void setYear(int year) {
|
||||
this.year = year;
|
||||
}
|
||||
public int getYear() {
|
||||
return year;
|
||||
}
|
||||
|
||||
public void setMonth(int month) {
|
||||
this.month = month;
|
||||
}
|
||||
public int getMonth() {
|
||||
return month;
|
||||
}
|
||||
|
||||
public void setDay(int day) {
|
||||
this.day = day;
|
||||
}
|
||||
public int getDay() {
|
||||
return day;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Copyright 2025 bejson.com
|
||||
*/
|
||||
/**
|
||||
* Auto-generated: 2025-07-21 17:23:17
|
||||
*
|
||||
* @author bejson.com (i@bejson.com)
|
||||
* @website http://www.bejson.com/java2pojo/
|
||||
*/
|
||||
public static class FortuneAnalysis implements Serializable{
|
||||
|
||||
private int overallScore;
|
||||
private String overallDescription;
|
||||
private String destiny;
|
||||
private String todayGanzhi;
|
||||
private BaziAnalysis baziAnalysis;
|
||||
private Weather weather;
|
||||
private AstrologyInfluence astrologyInfluence;
|
||||
private LuckyInfo luckyInfo;
|
||||
private int careerScore;
|
||||
private String careerDescription;
|
||||
private int loveScore;
|
||||
private String loveDescription;
|
||||
private int healthScore;
|
||||
private String healthDescription;
|
||||
private int wealthScore;
|
||||
private String wealthDescription;
|
||||
private Suggestions suggestions;
|
||||
private String fiveElementsAnalysis;
|
||||
public void setOverallScore(int overallScore) {
|
||||
this.overallScore = overallScore;
|
||||
}
|
||||
public int getOverallScore() {
|
||||
return overallScore;
|
||||
}
|
||||
|
||||
public void setOverallDescription(String overallDescription) {
|
||||
this.overallDescription = overallDescription;
|
||||
}
|
||||
public String getOverallDescription() {
|
||||
return overallDescription;
|
||||
}
|
||||
|
||||
public void setDestiny(String destiny) {
|
||||
this.destiny = destiny;
|
||||
}
|
||||
public String getDestiny() {
|
||||
return destiny;
|
||||
}
|
||||
|
||||
public void setTodayGanzhi(String todayGanzhi) {
|
||||
this.todayGanzhi = todayGanzhi;
|
||||
}
|
||||
public String getTodayGanzhi() {
|
||||
return todayGanzhi;
|
||||
}
|
||||
|
||||
public void setBaziAnalysis(BaziAnalysis baziAnalysis) {
|
||||
this.baziAnalysis = baziAnalysis;
|
||||
}
|
||||
public BaziAnalysis getBaziAnalysis() {
|
||||
return baziAnalysis;
|
||||
}
|
||||
|
||||
public void setWeather(Weather weather) {
|
||||
this.weather = weather;
|
||||
}
|
||||
public Weather getWeather() {
|
||||
return weather;
|
||||
}
|
||||
|
||||
public void setAstrologyInfluence(AstrologyInfluence astrologyInfluence) {
|
||||
this.astrologyInfluence = astrologyInfluence;
|
||||
}
|
||||
public AstrologyInfluence getAstrologyInfluence() {
|
||||
return astrologyInfluence;
|
||||
}
|
||||
|
||||
public void setLuckyInfo(LuckyInfo luckyInfo) {
|
||||
this.luckyInfo = luckyInfo;
|
||||
}
|
||||
public LuckyInfo getLuckyInfo() {
|
||||
return luckyInfo;
|
||||
}
|
||||
|
||||
public void setCareerScore(int careerScore) {
|
||||
this.careerScore = careerScore;
|
||||
}
|
||||
public int getCareerScore() {
|
||||
return careerScore;
|
||||
}
|
||||
|
||||
public void setCareerDescription(String careerDescription) {
|
||||
this.careerDescription = careerDescription;
|
||||
}
|
||||
public String getCareerDescription() {
|
||||
return careerDescription;
|
||||
}
|
||||
|
||||
public void setLoveScore(int loveScore) {
|
||||
this.loveScore = loveScore;
|
||||
}
|
||||
public int getLoveScore() {
|
||||
return loveScore;
|
||||
}
|
||||
|
||||
public void setLoveDescription(String loveDescription) {
|
||||
this.loveDescription = loveDescription;
|
||||
}
|
||||
public String getLoveDescription() {
|
||||
return loveDescription;
|
||||
}
|
||||
|
||||
public void setHealthScore(int healthScore) {
|
||||
this.healthScore = healthScore;
|
||||
}
|
||||
public int getHealthScore() {
|
||||
return healthScore;
|
||||
}
|
||||
|
||||
public void setHealthDescription(String healthDescription) {
|
||||
this.healthDescription = healthDescription;
|
||||
}
|
||||
public String getHealthDescription() {
|
||||
return healthDescription;
|
||||
}
|
||||
|
||||
public void setWealthScore(int wealthScore) {
|
||||
this.wealthScore = wealthScore;
|
||||
}
|
||||
public int getWealthScore() {
|
||||
return wealthScore;
|
||||
}
|
||||
|
||||
public void setWealthDescription(String wealthDescription) {
|
||||
this.wealthDescription = wealthDescription;
|
||||
}
|
||||
public String getWealthDescription() {
|
||||
return wealthDescription;
|
||||
}
|
||||
|
||||
public void setSuggestions(Suggestions suggestions) {
|
||||
this.suggestions = suggestions;
|
||||
}
|
||||
public Suggestions getSuggestions() {
|
||||
return suggestions;
|
||||
}
|
||||
|
||||
public void setFiveElementsAnalysis(String fiveElementsAnalysis) {
|
||||
this.fiveElementsAnalysis = fiveElementsAnalysis;
|
||||
}
|
||||
public String getFiveElementsAnalysis() {
|
||||
return fiveElementsAnalysis;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Copyright 2025 bejson.com
|
||||
*/
|
||||
/**
|
||||
* Auto-generated: 2025-07-21 17:23:17
|
||||
*
|
||||
* @author bejson.com (i@bejson.com)
|
||||
* @website http://www.bejson.com/java2pojo/
|
||||
*/
|
||||
public static class Suggestions implements Serializable{
|
||||
|
||||
private String positive;
|
||||
private String negative;
|
||||
public void setPositive(String positive) {
|
||||
this.positive = positive;
|
||||
}
|
||||
public String getPositive() {
|
||||
return positive;
|
||||
}
|
||||
|
||||
public void setNegative(String negative) {
|
||||
this.negative = negative;
|
||||
}
|
||||
public String getNegative() {
|
||||
return negative;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Copyright 2025 bejson.com
|
||||
*/
|
||||
/**
|
||||
* Auto-generated: 2025-07-21 17:23:17
|
||||
*
|
||||
* @author bejson.com (i@bejson.com)
|
||||
* @website http://www.bejson.com/java2pojo/
|
||||
*/
|
||||
public static class LuckyInfo implements Serializable{
|
||||
|
||||
private String[] numbers;
|
||||
private String color;
|
||||
private String direction;
|
||||
private List<LuckyTimes> luckyTimes;
|
||||
private String flower;
|
||||
private String food;
|
||||
|
||||
public String[] getNumbers() {
|
||||
return numbers;
|
||||
}
|
||||
|
||||
public void setNumbers(String[] numbers) {
|
||||
this.numbers = numbers;
|
||||
}
|
||||
|
||||
public void setColor(String color) {
|
||||
this.color = color;
|
||||
}
|
||||
public String getColor() {
|
||||
return color;
|
||||
}
|
||||
|
||||
public void setDirection(String direction) {
|
||||
this.direction = direction;
|
||||
}
|
||||
public String getDirection() {
|
||||
return direction;
|
||||
}
|
||||
|
||||
public void setLuckyTimes(List<LuckyTimes> luckyTimes) {
|
||||
this.luckyTimes = luckyTimes;
|
||||
}
|
||||
public List<LuckyTimes> getLuckyTimes() {
|
||||
return luckyTimes;
|
||||
}
|
||||
|
||||
public void setFlower(String flower) {
|
||||
this.flower = flower;
|
||||
}
|
||||
public String getFlower() {
|
||||
return flower;
|
||||
}
|
||||
|
||||
public void setFood(String food) {
|
||||
this.food = food;
|
||||
}
|
||||
public String getFood() {
|
||||
return food;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Copyright 2025 bejson.com
|
||||
*/
|
||||
/**
|
||||
* Auto-generated: 2025-07-21 17:23:17
|
||||
*
|
||||
* @author bejson.com (i@bejson.com)
|
||||
* @website http://www.bejson.com/java2pojo/
|
||||
*/
|
||||
public static class LuckyTimes implements Serializable{
|
||||
|
||||
private String time;
|
||||
private String description;
|
||||
public void setTime(String time) {
|
||||
this.time = time;
|
||||
}
|
||||
public String getTime() {
|
||||
return time;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Copyright 2025 bejson.com
|
||||
*/
|
||||
/**
|
||||
* Auto-generated: 2025-07-21 17:23:17
|
||||
*
|
||||
* @author bejson.com (i@bejson.com)
|
||||
* @website http://www.bejson.com/java2pojo/
|
||||
*/
|
||||
public static class AstrologyInfluence implements Serializable{
|
||||
|
||||
private String constellation;
|
||||
private String value;
|
||||
private String description;
|
||||
public void setConstellation(String constellation) {
|
||||
this.constellation = constellation;
|
||||
}
|
||||
public String getConstellation() {
|
||||
return constellation;
|
||||
}
|
||||
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Copyright 2025 bejson.com
|
||||
*/
|
||||
/**
|
||||
* Auto-generated: 2025-07-21 17:23:17
|
||||
*
|
||||
* @author bejson.com (i@bejson.com)
|
||||
* @website http://www.bejson.com/java2pojo/
|
||||
*/
|
||||
public static class Weather implements Serializable{
|
||||
|
||||
private String condition;
|
||||
private String temperature;
|
||||
public void setCondition(String condition) {
|
||||
this.condition = condition;
|
||||
}
|
||||
public String getCondition() {
|
||||
return condition;
|
||||
}
|
||||
|
||||
public void setTemperature(String temperature) {
|
||||
this.temperature = temperature;
|
||||
}
|
||||
public String getTemperature() {
|
||||
return temperature;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Copyright 2025 bejson.com
|
||||
*/
|
||||
/**
|
||||
* Auto-generated: 2025-07-21 17:23:17
|
||||
*
|
||||
* @author bejson.com (i@bejson.com)
|
||||
* @website http://www.bejson.com/java2pojo/
|
||||
*/
|
||||
public static class BaziAnalysis implements Serializable{
|
||||
|
||||
private String nianzhu;
|
||||
private String yuezhu;
|
||||
private String rizhu;
|
||||
private String shizhu;
|
||||
private String todayInfluence;
|
||||
public void setNianzhu(String nianzhu) {
|
||||
this.nianzhu = nianzhu;
|
||||
}
|
||||
public String getNianzhu() {
|
||||
return nianzhu;
|
||||
}
|
||||
|
||||
public void setYuezhu(String yuezhu) {
|
||||
this.yuezhu = yuezhu;
|
||||
}
|
||||
public String getYuezhu() {
|
||||
return yuezhu;
|
||||
}
|
||||
|
||||
public void setRizhu(String rizhu) {
|
||||
this.rizhu = rizhu;
|
||||
}
|
||||
public String getRizhu() {
|
||||
return rizhu;
|
||||
}
|
||||
|
||||
public void setShizhu(String shizhu) {
|
||||
this.shizhu = shizhu;
|
||||
}
|
||||
public String getShizhu() {
|
||||
return shizhu;
|
||||
}
|
||||
|
||||
public void setTodayInfluence(String todayInfluence) {
|
||||
this.todayInfluence = todayInfluence;
|
||||
}
|
||||
public String getTodayInfluence() {
|
||||
return todayInfluence;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,56 +0,0 @@
|
||||
package com.ckkj.water.fate.mvp;
|
||||
|
||||
import com.ckkj.water.base.IView;
|
||||
import com.ckkj.water.base.entity.MineUserInfoBean;
|
||||
import com.ckkj.water.fate.entity.CityDataEntity;
|
||||
import com.ckkj.water.fate.entity.FateHistoryEntity;
|
||||
import com.ckkj.water.fate.entity.TodayFateEntity;
|
||||
import com.ckkj.water.network.BaseBean;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author fengxiaoyang
|
||||
* @date 2025/7/15
|
||||
* @description TODO: 描述该类的作用
|
||||
*/
|
||||
|
||||
public class FateContract {
|
||||
|
||||
public interface CallBack<T> {
|
||||
void success(T msg);
|
||||
void fail(String msg);
|
||||
}
|
||||
|
||||
public interface DataModel{
|
||||
//查询所有城市
|
||||
void getAllCityDatas(Map<String,Object> map, CallBack callBack);
|
||||
//保存用户生日信息
|
||||
void saveUserBirthInfo(JSONObject json, CallBack callBack);
|
||||
//用户修改生日信息
|
||||
void saveUserEditBirthInfo(JSONObject json, CallBack callBack);
|
||||
//查询用户今日运势
|
||||
void getUserTodayFateDatas(Map<String,Object> map, CallBack callBack);
|
||||
//查询历史运势
|
||||
void getUserFateHistory(Map<String,Object> map, CallBack callBack);
|
||||
}
|
||||
|
||||
|
||||
public interface FateView extends IView{
|
||||
//查询所有城市成功
|
||||
void getAllCitySuccess(List<CityDataEntity> list);
|
||||
//获取今日运势成功
|
||||
void getUserTodayFateDataSuccess(TodayFateEntity entity);
|
||||
//获取历史运势成功
|
||||
void getFateHistorySuccess(FateHistoryEntity entity);
|
||||
//用户保存生辰八字成功
|
||||
void userSaveBirthInfoSuccess(TodayFateEntity bean);
|
||||
//用户信息
|
||||
void getUserInfoSuccess(MineUserInfoBean bean);
|
||||
//提交举报反馈成功
|
||||
void commitReportSuccess(BaseBean bean);
|
||||
}
|
||||
}
|
||||
@@ -1,232 +0,0 @@
|
||||
package com.ckkj.water.fate.mvp;
|
||||
|
||||
import com.ckkj.water.fate.entity.CityDataEntity;
|
||||
import com.ckkj.water.fate.entity.FateHistoryEntity;
|
||||
import com.ckkj.water.fate.entity.TodayFateEntity;
|
||||
import com.ckkj.water.network.BaseBean;
|
||||
import com.ckkj.water.network.NetWorkManager;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import io.reactivex.Observer;
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.annotations.NonNull;
|
||||
import io.reactivex.disposables.Disposable;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
|
||||
/**
|
||||
* @author fengxiaoyang
|
||||
* @date 2025/7/15
|
||||
* @description TODO: 描述该类的作用
|
||||
*/
|
||||
|
||||
public class FateImpl implements FateContract.DataModel{
|
||||
|
||||
/**
|
||||
* 所有城市
|
||||
* @param map
|
||||
* @param callBack
|
||||
*/
|
||||
@Override
|
||||
public void getAllCityDatas(Map<String, Object> map, FateContract.CallBack callBack) {
|
||||
try {
|
||||
NetWorkManager.getRequest().getCityDatas(NetWorkManager.getToken(),map)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.unsubscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Observer<BaseBean<List<CityDataEntity>>>() {
|
||||
@Override
|
||||
public void onSubscribe(@NonNull Disposable d) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(@NonNull BaseBean<List<CityDataEntity>> bean) {
|
||||
if(bean.getCode() == 200){
|
||||
callBack.success(bean.getData());
|
||||
}else{
|
||||
callBack.fail(bean.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(@NonNull Throwable e) {
|
||||
callBack.fail(e.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存用户生辰信息
|
||||
* @param json
|
||||
* @param callBack
|
||||
*/
|
||||
@Override
|
||||
public void saveUserBirthInfo(JSONObject json, FateContract.CallBack callBack) {
|
||||
try {
|
||||
NetWorkManager.getRequest().saveUserBirthInfo(NetWorkManager.getToken(),NetWorkManager.toRequestBody(json))
|
||||
.subscribeOn(Schedulers.io())
|
||||
.unsubscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Observer<BaseBean>() {
|
||||
@Override
|
||||
public void onSubscribe(@NonNull Disposable d) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(@NonNull BaseBean bean) {
|
||||
if(bean.getCode() == 200){
|
||||
callBack.success(bean);
|
||||
}else{
|
||||
callBack.fail(bean.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(@NonNull Throwable e) {
|
||||
callBack.fail(e.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户修改生辰八字
|
||||
* @param json
|
||||
* @param callBack
|
||||
*/
|
||||
@Override
|
||||
public void saveUserEditBirthInfo(JSONObject json, FateContract.CallBack callBack) {
|
||||
try {
|
||||
NetWorkManager.getRequest().saveUserEditBirthInfo(NetWorkManager.getToken(),NetWorkManager.toRequestBody(json))
|
||||
.subscribeOn(Schedulers.io())
|
||||
.unsubscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Observer<BaseBean<TodayFateEntity>>() {
|
||||
@Override
|
||||
public void onSubscribe(@NonNull Disposable d) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(@NonNull BaseBean<TodayFateEntity> bean) {
|
||||
if(bean.getCode() == 200){
|
||||
callBack.success(bean.getData());
|
||||
}else{
|
||||
callBack.fail(bean.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(@NonNull Throwable e) {
|
||||
callBack.fail(e.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取今日运势
|
||||
* @param map
|
||||
* @param callBack
|
||||
*/
|
||||
@Override
|
||||
public void getUserTodayFateDatas(Map<String, Object> map, FateContract.CallBack callBack) {
|
||||
try {
|
||||
NetWorkManager.getRequest().getUserTodayFateDatas(NetWorkManager.getToken())
|
||||
.subscribeOn(Schedulers.io())
|
||||
.unsubscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Observer<BaseBean<TodayFateEntity>>() {
|
||||
@Override
|
||||
public void onSubscribe(@NonNull Disposable d) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(@NonNull BaseBean<TodayFateEntity> bean) {
|
||||
if(bean.getCode() == 200){
|
||||
callBack.success(bean.getData());
|
||||
}else{
|
||||
callBack.fail(bean.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(@NonNull Throwable e) {
|
||||
callBack.fail(e.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取历史数据
|
||||
* @param map
|
||||
* @param callBack
|
||||
*/
|
||||
@Override
|
||||
public void getUserFateHistory(Map<String, Object> map, FateContract.CallBack callBack) {
|
||||
try {
|
||||
NetWorkManager.getRequest().getUserFateHistory(NetWorkManager.getToken())
|
||||
.subscribeOn(Schedulers.io())
|
||||
.unsubscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Observer<BaseBean<FateHistoryEntity>>() {
|
||||
@Override
|
||||
public void onSubscribe(@NonNull Disposable d) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(@NonNull BaseBean<FateHistoryEntity> bean) {
|
||||
if(bean.getCode() == 200){
|
||||
callBack.success(bean.getData());
|
||||
}else{
|
||||
callBack.fail(bean.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(@NonNull Throwable e) {
|
||||
callBack.fail(e.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,191 +0,0 @@
|
||||
package com.ckkj.water.fate.mvp;
|
||||
|
||||
import com.ckkj.water.base.BasePresenter;
|
||||
import com.ckkj.water.base.entity.MineUserInfoBean;
|
||||
import com.ckkj.water.chat.mvp.IndexContract;
|
||||
import com.ckkj.water.chat.mvp.IndexImpl;
|
||||
import com.ckkj.water.fate.entity.CityDataEntity;
|
||||
import com.ckkj.water.fate.entity.FateHistoryEntity;
|
||||
import com.ckkj.water.fate.entity.TodayFateEntity;
|
||||
import com.ckkj.water.login.mvp.LoginContract;
|
||||
import com.ckkj.water.mine.mvp.MineImpl;
|
||||
import com.ckkj.water.network.BaseBean;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author fengxiaoyang
|
||||
* @date 2025/7/15
|
||||
* @description TODO: 描述该类的作用
|
||||
*/
|
||||
|
||||
public class FatePresenter extends BasePresenter<FateContract.FateView> {
|
||||
private FateImpl impl;
|
||||
|
||||
public FatePresenter(FateImpl impl) {
|
||||
this.impl = impl;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取城市列表
|
||||
*/
|
||||
public void getCityDatas() {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
impl.getAllCityDatas(map, new FateContract.CallBack<List<CityDataEntity>>() {
|
||||
@Override
|
||||
public void success(List<CityDataEntity> list) {
|
||||
if(FatePresenter.this.getView() != null){
|
||||
FatePresenter.this.getView().getAllCitySuccess(list);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fail(String msg) {
|
||||
if(FatePresenter.this.getView() != null){
|
||||
FatePresenter.this.getView().showError(msg);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存用户生辰
|
||||
* @param json
|
||||
*/
|
||||
public void saveUserBirthInfo(JSONObject json) {
|
||||
impl.saveUserBirthInfo(json, new FateContract.CallBack<BaseBean>() {
|
||||
@Override
|
||||
public void success(BaseBean bean) {
|
||||
if(FatePresenter.this.getView() != null){
|
||||
FatePresenter.this.getView().userSaveBirthInfoSuccess(null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fail(String msg) {
|
||||
if(FatePresenter.this.getView() != null){
|
||||
FatePresenter.this.getView().showError(msg);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取今日运势
|
||||
*/
|
||||
public void getTodayFateDatas() {
|
||||
impl.getUserTodayFateDatas(new HashMap<>(), new FateContract.CallBack<TodayFateEntity>() {
|
||||
@Override
|
||||
public void success(TodayFateEntity bean) {
|
||||
if(FatePresenter.this.getView() != null){
|
||||
FatePresenter.this.getView().getUserTodayFateDataSuccess(bean);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fail(String msg) {
|
||||
if(FatePresenter.this.getView() != null){
|
||||
FatePresenter.this.getView().showError(msg);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取历史运势
|
||||
* @param page
|
||||
*/
|
||||
public void getHistoryDatas(int page) {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("pageNum", page);
|
||||
map.put("pageSize", 10);
|
||||
impl.getUserFateHistory(map, new FateContract.CallBack<FateHistoryEntity>() {
|
||||
|
||||
@Override
|
||||
public void success(FateHistoryEntity entity) {
|
||||
if(FatePresenter.this.getView() != null){
|
||||
FatePresenter.this.getView().getFateHistorySuccess(entity);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fail(String msg) {
|
||||
if(FatePresenter.this.getView() != null){
|
||||
FatePresenter.this.getView().showError(msg);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户修改的生辰八字保存
|
||||
* @param json
|
||||
*/
|
||||
public void saveEditBirthInfo(JSONObject json) {
|
||||
impl.saveUserEditBirthInfo(json, new FateContract.CallBack<TodayFateEntity>() {
|
||||
@Override
|
||||
public void success(TodayFateEntity bean) {
|
||||
if(FatePresenter.this.getView() != null){
|
||||
FatePresenter.this.getView().userSaveBirthInfoSuccess(bean);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fail(String msg) {
|
||||
if(FatePresenter.this.getView() != null){
|
||||
FatePresenter.this.getView().showError(msg);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取个人信息
|
||||
*/
|
||||
public void getUserInfo() {
|
||||
Map<String,Object> map = new HashMap<>();
|
||||
// new MineImpl().getUserInfo(map, new LoginContract.CallBack<MineUserInfoBean>() {
|
||||
// @Override
|
||||
// public void success(MineUserInfoBean bean) {
|
||||
// if( FatePresenter.this.getView() != null){
|
||||
// FatePresenter.this.getView().getUserInfoSuccess(bean);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void fail(String msg) {
|
||||
// if( FatePresenter.this.getView() != null){
|
||||
// FatePresenter.this.getView().showError(msg);
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
}
|
||||
|
||||
/**
|
||||
* 举报
|
||||
* @param reason
|
||||
*/
|
||||
public void commitReport(String reason) {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("content", reason);
|
||||
new IndexImpl().commitReport(map, new IndexContract.CallBack<BaseBean>() {
|
||||
@Override
|
||||
public void success(BaseBean bean) {
|
||||
if (FatePresenter.this.getView() != null) {
|
||||
FatePresenter.this.getView().commitReportSuccess(bean);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fail(String msg) {
|
||||
if (FatePresenter.this.getView() != null) {
|
||||
FatePresenter.this.getView().showError(msg);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,75 +0,0 @@
|
||||
package com.ckkj.water.fate.util;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import org.json.JSONArray;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.InputStream;
|
||||
|
||||
public class LunarDateLoader {
|
||||
|
||||
// 缓存静态变量
|
||||
private static JSONArray cachedLunarJsonArray = null;
|
||||
|
||||
/**
|
||||
* 初始化缓存(异步调用,建议在 Application 中调用)
|
||||
*/
|
||||
public static void preloadLunarJson(final Context context) {
|
||||
if (cachedLunarJsonArray != null) return; // 已加载过则跳过
|
||||
|
||||
new Thread(() -> {
|
||||
try {
|
||||
InputStream inputStream = context.getAssets().open("lunar_1899_2099.json");
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
byte[] buffer = new byte[1024];
|
||||
int len;
|
||||
|
||||
while ((len = inputStream.read(buffer)) != -1) {
|
||||
outputStream.write(buffer, 0, len);
|
||||
}
|
||||
|
||||
inputStream.close();
|
||||
String jsonStr = outputStream.toString("UTF-8");
|
||||
cachedLunarJsonArray = new JSONArray(jsonStr);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取缓存的农历 JSON 数据(同步获取)
|
||||
* 可在页面中直接调用
|
||||
*/
|
||||
@Nullable
|
||||
public static JSONArray getCachedLunarJson() {
|
||||
return cachedLunarJsonArray;
|
||||
}
|
||||
|
||||
/**
|
||||
* 同步加载(兜底)
|
||||
*/
|
||||
@Nullable
|
||||
public static JSONArray loadJsonFromAssets(Context context, String fileName) {
|
||||
try {
|
||||
InputStream inputStream = context.getAssets().open(fileName);
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
byte[] buffer = new byte[1024];
|
||||
int len;
|
||||
|
||||
while ((len = inputStream.read(buffer)) != -1) {
|
||||
outputStream.write(buffer, 0, len);
|
||||
}
|
||||
|
||||
inputStream.close();
|
||||
String jsonStr = outputStream.toString("UTF-8");
|
||||
return new JSONArray(jsonStr);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,96 +0,0 @@
|
||||
package com.ckkj.water.fate.util;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.ckkj.water.fate.entity.LunarYearEntity;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class LunarDatePicker {
|
||||
private List<LunarYearEntity> lunarYears; // 所有年份数据
|
||||
private List<LunarYearEntity.LunarMonth> currentYearMonths; // 当前选中年的月份数据
|
||||
|
||||
// 月份名称映射(数字->中文)
|
||||
private static final String[] MONTH_NAMES = {
|
||||
"正月", "二月", "三月", "四月", "五月", "六月",
|
||||
"七月", "八月", "九月", "十月", "冬月", "腊月"
|
||||
};
|
||||
|
||||
// 日期名称列表(初一到三十)
|
||||
private static final String[] DAY_NAMES = {
|
||||
"初一", "初二", "初三", "初四", "初五", "初六", "初七", "初八", "初九", "初十",
|
||||
"十一", "十二", "十三", "十四", "十五", "十六", "十七", "十八", "十九", "二十",
|
||||
"廿一", "廿二", "廿三", "廿四", "廿五", "廿六", "廿七", "廿八", "廿九", "三十"
|
||||
};
|
||||
|
||||
public LunarDatePicker(String jsonData) {
|
||||
// 解析JSON数据
|
||||
parseLunarData(jsonData);
|
||||
}
|
||||
|
||||
// 解析JSON数据
|
||||
private void parseLunarData(String jsonData) {
|
||||
Gson gson = new Gson();
|
||||
Type type = new TypeToken<List<LunarYearEntity>>(){}.getType();
|
||||
lunarYears = gson.fromJson(jsonData, type);
|
||||
}
|
||||
|
||||
// 获取年份列表(用于年的WheelView)
|
||||
public List<String> getYearList() {
|
||||
List<String> years = new ArrayList<>();
|
||||
for (LunarYearEntity year : lunarYears) {
|
||||
years.add(year.getYear());
|
||||
}
|
||||
return years;
|
||||
}
|
||||
|
||||
// 根据选中的年份索引获取月份列表(用于月的WheelView)
|
||||
public List<String> getMonthList(int yearIndex) {
|
||||
if (yearIndex < 0 || yearIndex >= lunarYears.size()) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
LunarYearEntity selectedYear = lunarYears.get(yearIndex);
|
||||
currentYearMonths = selectedYear.getMonth(); // 保存当前年的月份数据
|
||||
|
||||
List<String> monthList = new ArrayList<>();
|
||||
for (LunarYearEntity.LunarMonth month : selectedYear.month) {
|
||||
int monthNum = Integer.parseInt(month.name);
|
||||
String monthName = MONTH_NAMES[monthNum - 1]; // 数组索引从0开始
|
||||
|
||||
// 处理闰月
|
||||
if (month.isRun == 1) {
|
||||
monthName = "闰" + monthName;
|
||||
}
|
||||
|
||||
monthList.add(monthName);
|
||||
}
|
||||
return monthList;
|
||||
}
|
||||
|
||||
// 根据选中的月份索引获取日期列表(用于日的WheelView)
|
||||
public List<String> getDayList(int monthIndex) {
|
||||
if (currentYearMonths == null || monthIndex < 0 || monthIndex >= currentYearMonths.size()) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
LunarYearEntity.LunarMonth selectedMonth = currentYearMonths.get(monthIndex);
|
||||
int days = selectedMonth.isAllDay == 1 ? 30 : 29; // 确定天数
|
||||
|
||||
List<String> dayList = new ArrayList<>();
|
||||
for (int i = 0; i < days; i++) {
|
||||
dayList.add(DAY_NAMES[i]);
|
||||
}
|
||||
return dayList;
|
||||
}
|
||||
|
||||
// 获取选中的完整日期(年、月、日索引)
|
||||
public String getSelectedDate(int yearIndex, int monthIndex, int dayIndex) {
|
||||
String year = lunarYears.get(yearIndex).year + "年";
|
||||
String month = getMonthList(yearIndex).get(monthIndex);
|
||||
String day = getDayList(monthIndex).get(dayIndex);
|
||||
return year + month + day;
|
||||
}
|
||||
}
|
||||
@@ -1,744 +0,0 @@
|
||||
package com.ckkj.water.fate.view;
|
||||
|
||||
import static android.app.Activity.RESULT_OK;
|
||||
import static com.qweather.sdk.QWeather.instance;
|
||||
|
||||
import android.animation.Animator;
|
||||
import android.animation.AnimatorListenerAdapter;
|
||||
import android.animation.AnimatorSet;
|
||||
import android.animation.ObjectAnimator;
|
||||
import android.animation.ValueAnimator;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Rect;
|
||||
import android.os.Bundle;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.view.animation.AccelerateDecelerateInterpolator;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.amap.api.services.core.AMapException;
|
||||
import com.amap.api.services.core.LatLonPoint;
|
||||
import com.amap.api.services.geocoder.GeocodeAddress;
|
||||
import com.amap.api.services.geocoder.GeocodeQuery;
|
||||
import com.amap.api.services.geocoder.GeocodeResult;
|
||||
import com.amap.api.services.geocoder.GeocodeSearch;
|
||||
import com.google.android.material.progressindicator.CircularProgressIndicator;
|
||||
import com.google.android.material.progressindicator.LinearProgressIndicator;
|
||||
import com.ckkj.water.AppConfig;
|
||||
import com.ckkj.water.ConstantUtil;
|
||||
import com.ckkj.water.EventMessage;
|
||||
import com.ckkj.water.R;
|
||||
import com.ckkj.water.base.BaseFragment;
|
||||
import com.ckkj.water.base.entity.MineUserInfoBean;
|
||||
import com.ckkj.water.custom.view.CustomRefreshHeader;
|
||||
import com.ckkj.water.databinding.FateLayoutBinding;
|
||||
import com.ckkj.water.fate.entity.CityDataEntity;
|
||||
import com.ckkj.water.fate.entity.FateHistoryEntity;
|
||||
import com.ckkj.water.fate.entity.TodayFateEntity;
|
||||
import com.ckkj.water.fate.mvp.FateContract;
|
||||
import com.ckkj.water.fate.mvp.FateImpl;
|
||||
import com.ckkj.water.fate.mvp.FatePresenter;
|
||||
import com.ckkj.water.network.BaseBean;
|
||||
import com.ckkj.water.utils.WeatherIconUtil;
|
||||
import com.ckkj.water.utils.click.ClickUtil;
|
||||
import com.ckkj.water.utils.color.FateDataUtil;
|
||||
import com.ckkj.water.utils.dataUtil.SharePreUtil;
|
||||
import com.ckkj.water.utils.manager.WaterUserInfoManager;
|
||||
import com.ckkj.water.utils.number.NumberDecimalFilter;
|
||||
import com.ckkj.water.utils.show.ToastUtil;
|
||||
import com.ckkj.water.utils.time.ZYTimeUtils;
|
||||
import com.qweather.sdk.Callback;
|
||||
import com.qweather.sdk.JWTGenerator;
|
||||
import com.qweather.sdk.QWeather;
|
||||
import com.qweather.sdk.basic.Lang;
|
||||
import com.qweather.sdk.basic.Unit;
|
||||
import com.qweather.sdk.parameter.weather.WeatherParameter;
|
||||
import com.qweather.sdk.response.error.ErrorResponse;
|
||||
import com.qweather.sdk.response.geo.GeoPoiResponse;
|
||||
import com.qweather.sdk.response.weather.WeatherNowResponse;
|
||||
import com.scwang.smart.refresh.layout.api.RefreshHeader;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Calendar;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
|
||||
import de.greenrobot.event.Subscribe;
|
||||
import de.greenrobot.event.ThreadMode;
|
||||
import pub.devrel.easypermissions.EasyPermissions;
|
||||
|
||||
/**
|
||||
* @author fengxiaoyang
|
||||
* @date 2025/7/7
|
||||
* @description TODO: 描述该类的作用
|
||||
*/
|
||||
|
||||
public class FateFragment extends BaseFragment<FateLayoutBinding, FatePresenter>
|
||||
implements FateContract.FateView , EasyPermissions.PermissionCallbacks{
|
||||
|
||||
private TodayFateEntity mTodayEntity;
|
||||
// 添加动画执行标志位
|
||||
private boolean isCareerAnimPlayed = false;
|
||||
private boolean isLoveAnimPlayed = false;
|
||||
private boolean isHealthAnimPlayed = false;
|
||||
private boolean isWealthAnimPlayed = false;
|
||||
private boolean isOverallAnimPlayed = false;
|
||||
//是否已经加载过
|
||||
private boolean hasLoaded = false;
|
||||
|
||||
// 添加Toast相关的成员变量
|
||||
private Handler toastHandler = new Handler(Looper.getMainLooper());
|
||||
private Runnable toastRunnable;
|
||||
private boolean isToastTaskRunning = false;
|
||||
private int currentToastIndex = 0;
|
||||
private String[] toastMessages = {
|
||||
"正在查看您的今日能量值",
|
||||
"让我帮你看看今天的星座运势",
|
||||
"正在生成您的幸运元素",
|
||||
"别着急,让我来想想今天的事宜"
|
||||
};
|
||||
|
||||
|
||||
@Override
|
||||
public void setUserVisibleHint(boolean isVisibleToUser) {
|
||||
super.setUserVisibleHint(isVisibleToUser);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onResumeInitData() {
|
||||
super.onResumeInitData();
|
||||
// 确保在Fragment可见时检查动画
|
||||
viewBinding.getRoot().postDelayed(() -> {
|
||||
checkAndAnimateProgressBars();
|
||||
}, 300);
|
||||
if(AppConfig.USER_LOGIN){
|
||||
mPresenter.getUserInfo();
|
||||
}else{
|
||||
viewBinding.llInput.setVisibility(View.VISIBLE);
|
||||
}
|
||||
if (getUserVisibleHint() && !hasLoaded) {
|
||||
if(AppConfig.USER_LOGIN){
|
||||
showLoadingDialog();
|
||||
// 调用接口并启动延迟Toast任务
|
||||
startFateDataRequest();
|
||||
hasLoaded = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void initData(Bundle state) {
|
||||
//请求定位权限
|
||||
// String permission = Manifest.permission.ACCESS_FINE_LOCATION;
|
||||
// if(!hasRecordPermission(permission)){
|
||||
// getPermissionRequst(permission,"定位权限申请","叮叮车需要您的授权,获取您当前所在的城市",REQUEST_EVENT_CODE_10002);
|
||||
// }else{
|
||||
// AMapLocationClient.updatePrivacyAgree(mContext, true);
|
||||
// initLocationInfo();
|
||||
// }
|
||||
|
||||
// 设置当前日期和星期几
|
||||
setCurrentDate();
|
||||
|
||||
//和风天气 init
|
||||
try {
|
||||
JWTGenerator jwt = new JWTGenerator(
|
||||
"-----BEGIN PRIVATE KEY-----\n" +
|
||||
"MC4CAQAwBQYDK2VwBCIEIFH+qB/0rER1mEpgAIwpBiAShW9pnSAj8OipGY/eFLRb\n" +
|
||||
"-----END PRIVATE KEY-----",//密钥
|
||||
"2A89MF5WVU",//项目 ID
|
||||
"K5PU3M4P2A");//凭据 ID
|
||||
|
||||
instance = QWeather.getInstance(mContext, "mr3597qqpv.re.qweatherapi.com")
|
||||
.setTokenGenerator(jwt)
|
||||
.setLogEnable(true);
|
||||
Log.d(TAG,"和风天气初始化成功");
|
||||
} catch (Throwable e) {
|
||||
Log.d(TAG,"和风天气初始化异常");
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
// 添加视图可见性监听
|
||||
setupProgressAnimations();
|
||||
ClickUtil.addClickPart(viewBinding.imgHistory,60);
|
||||
// 设置自定义刷新头
|
||||
RefreshHeader header = new CustomRefreshHeader(mContext);
|
||||
viewBinding.refresh.setRefreshHeader(header);
|
||||
// viewBinding.refresh.setRefreshFooter(new ClassicsFooter(mContext));
|
||||
viewBinding.refresh.setOnRefreshListener(layout -> {
|
||||
if(AppConfig.USER_LOGIN){
|
||||
showLoadingDialog();
|
||||
// 调用接口并启动延迟Toast任务
|
||||
startFateDataRequest();
|
||||
hasLoaded = true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置当前日期和星期几
|
||||
*/
|
||||
private void setCurrentDate() {
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
int month = calendar.get(Calendar.MONTH) + 1; // Calendar.MONTH 从0开始,所以要+1
|
||||
int day = calendar.get(Calendar.DAY_OF_MONTH);
|
||||
int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK);
|
||||
|
||||
// 将数字星期转换为中文
|
||||
String[] weekDays = {"星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"};
|
||||
String weekDayStr = weekDays[dayOfWeek - 1]; // Calendar.DAY_OF_WEEK 从1开始(星期日=1)
|
||||
|
||||
// 格式化日期字符串:例如 "9 月 9 日 星期三"
|
||||
String dateStr = month + " 月 " + day + " 日 " + weekDayStr;
|
||||
|
||||
// 设置到TextView
|
||||
viewBinding.tvDate.setText(dateStr);
|
||||
}
|
||||
|
||||
private void setupProgressAnimations() {
|
||||
// 监听父滚动视图(假设外层是NestedScrollView)
|
||||
View scrollView = viewBinding.getRoot().findViewById(R.id.nesd_scrollview); // 替换为你的NestedScrollView id
|
||||
|
||||
if (scrollView != null) {
|
||||
scrollView.getViewTreeObserver().addOnScrollChangedListener(() -> {
|
||||
checkAndAnimateProgressBars();
|
||||
});
|
||||
}
|
||||
|
||||
// 初始检查(如果视图已经可见)
|
||||
viewBinding.getRoot().postDelayed(() -> {
|
||||
checkAndAnimateProgressBars();
|
||||
}, 300); // 延迟300ms确保布局完成
|
||||
}
|
||||
|
||||
private void checkAndAnimateProgressBars() {
|
||||
if(mTodayEntity == null){
|
||||
return;
|
||||
}
|
||||
// 圆形进度条(运势分数)
|
||||
if (isViewVisible(viewBinding.includedTodayFateDatas.progressIndicator) && !isOverallAnimPlayed) {
|
||||
animateCircularProgress(
|
||||
viewBinding.includedTodayFateDatas.progressIndicator,
|
||||
mTodayEntity.getFortuneAnalysis().getOverallScore()
|
||||
);
|
||||
isOverallAnimPlayed = true;
|
||||
}
|
||||
// 检查每个进度条是否需要执行动画
|
||||
if (isViewVisible(viewBinding.includedSyy.proSyy) && !isCareerAnimPlayed) {
|
||||
animateProgress(viewBinding.includedSyy.proSyy,
|
||||
mTodayEntity.getFortuneAnalysis().getCareerScore());
|
||||
isCareerAnimPlayed = true;
|
||||
}
|
||||
|
||||
if (isViewVisible(viewBinding.includedSyy.proGqy) && !isLoveAnimPlayed) {
|
||||
animateProgress(viewBinding.includedSyy.proGqy,
|
||||
mTodayEntity.getFortuneAnalysis().getLoveScore());
|
||||
isLoveAnimPlayed = true;
|
||||
}
|
||||
|
||||
if (isViewVisible(viewBinding.includedSyy.proJky) && !isHealthAnimPlayed) {
|
||||
animateProgress(viewBinding.includedSyy.proJky,
|
||||
mTodayEntity.getFortuneAnalysis().getHealthScore());
|
||||
isHealthAnimPlayed = true;
|
||||
}
|
||||
|
||||
if (isViewVisible(viewBinding.includedSyy.proCfy) && !isWealthAnimPlayed) {
|
||||
animateProgress(viewBinding.includedSyy.proCfy,
|
||||
mTodayEntity.getFortuneAnalysis().getWealthScore());
|
||||
isWealthAnimPlayed = true;
|
||||
}
|
||||
}
|
||||
|
||||
// 判断视图是否可见
|
||||
private boolean isViewVisible(View view) {
|
||||
if (view == null) return false;
|
||||
|
||||
Rect scrollBounds = new Rect();
|
||||
View scrollView = viewBinding.getRoot().findViewById(R.id.nesd_scrollview);
|
||||
|
||||
if (scrollView != null) {
|
||||
scrollView.getHitRect(scrollBounds);
|
||||
return view.getLocalVisibleRect(scrollBounds);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// 执行进度条动画
|
||||
private void animateProgress(LinearProgressIndicator progressBar, int targetProgress) {
|
||||
// 保存原始进度值
|
||||
final int originalProgress = progressBar.getProgress();
|
||||
|
||||
// 先重置为0
|
||||
progressBar.setProgress(0);
|
||||
|
||||
// 创建动画
|
||||
ObjectAnimator animator = ObjectAnimator.ofInt(progressBar, "progress", 0, targetProgress);
|
||||
animator.setDuration(800); // 动画时长800ms
|
||||
animator.setInterpolator(new AccelerateDecelerateInterpolator());
|
||||
|
||||
// 添加脉冲效果
|
||||
animator.addUpdateListener(animation -> {
|
||||
float fraction = animation.getAnimatedFraction();
|
||||
float scale = 1 + 0.2f * (float) Math.sin(fraction * Math.PI);
|
||||
progressBar.setScaleX(scale);
|
||||
progressBar.setScaleY(scale);
|
||||
});
|
||||
|
||||
animator.addListener(new AnimatorListenerAdapter() {
|
||||
@Override
|
||||
public void onAnimationEnd(Animator animation) {
|
||||
// 恢复原始大小
|
||||
progressBar.animate()
|
||||
.scaleX(1f)
|
||||
.scaleY(1f)
|
||||
.setDuration(200)
|
||||
.start();
|
||||
}
|
||||
});
|
||||
animator.start();
|
||||
}
|
||||
|
||||
|
||||
// 执行圆形进度条动画(带旋转效果)
|
||||
private void animateCircularProgress(CircularProgressIndicator progressBar, int targetProgress) {
|
||||
// 保存原始进度值
|
||||
final int originalProgress = progressBar.getProgress();
|
||||
|
||||
// 先重置为0
|
||||
progressBar.setProgress(0);
|
||||
|
||||
// 创建进度动画
|
||||
ValueAnimator progressAnimator = ValueAnimator.ofInt(0, targetProgress);
|
||||
progressAnimator.setDuration(1000); // 动画时长1000ms
|
||||
progressAnimator.setInterpolator(new AccelerateDecelerateInterpolator());
|
||||
|
||||
// 创建旋转动画
|
||||
ObjectAnimator rotationAnimator = ObjectAnimator.ofFloat(progressBar, "rotation", 0f, 360f);
|
||||
rotationAnimator.setDuration(800);
|
||||
rotationAnimator.setInterpolator(new AccelerateDecelerateInterpolator());
|
||||
|
||||
// 组合动画
|
||||
AnimatorSet animatorSet = new AnimatorSet();
|
||||
animatorSet.playTogether(progressAnimator, rotationAnimator);
|
||||
|
||||
// 添加脉冲缩放效果
|
||||
progressAnimator.addUpdateListener(animation -> {
|
||||
int progress = (int) animation.getAnimatedValue();
|
||||
progressBar.setProgress(progress);
|
||||
|
||||
// 脉冲效果:在动画过程中轻微缩放
|
||||
float fraction = animation.getAnimatedFraction();
|
||||
float scale = 1 + 0.12f * (float) Math.sin(fraction * Math.PI);
|
||||
progressBar.setScaleX(scale);
|
||||
progressBar.setScaleY(scale);
|
||||
});
|
||||
|
||||
animatorSet.addListener(new AnimatorListenerAdapter() {
|
||||
@Override
|
||||
public void onAnimationEnd(Animator animation) {
|
||||
// 恢复原始大小
|
||||
progressBar.animate()
|
||||
.scaleX(1f)
|
||||
.scaleY(1f)
|
||||
.setDuration(200)
|
||||
.start();
|
||||
}
|
||||
});
|
||||
|
||||
animatorSet.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public FatePresenter createPresenter() {
|
||||
return new FatePresenter(new FateImpl());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
if(data != null){
|
||||
if(resultCode == RESULT_OK){
|
||||
switch (requestCode){
|
||||
case REQUEST_EVENT_CODE_10002:
|
||||
break;
|
||||
|
||||
case REQUEST_EVENT_CODE_10001:
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe(threadMode = ThreadMode.MainThread)
|
||||
public void onGetMessage(EventMessage message) {
|
||||
switch (message.msg){
|
||||
case EventMessage.DATA_REFRESH_EVENT:
|
||||
showLoadingDialog();
|
||||
startFateDataRequest();
|
||||
break;
|
||||
|
||||
case EventMessage.USER_LOGIN_SUCCESS:
|
||||
startFateDataRequest();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 启动今日运势数据请求并开始延迟Toast任务
|
||||
*/
|
||||
private void startFateDataRequest() {
|
||||
// 停止之前的Toast任务(如果有的话)
|
||||
stopToastTask();
|
||||
|
||||
// 调用接口
|
||||
mPresenter.getTodayFateDatas();
|
||||
|
||||
// 启动延迟Toast任务
|
||||
startDelayedToastTask();
|
||||
}
|
||||
|
||||
/**
|
||||
* 启动延迟Toast任务
|
||||
*/
|
||||
private void startDelayedToastTask() {
|
||||
// 5秒后开始显示Toast
|
||||
toastHandler.postDelayed(() -> {
|
||||
if (!isToastTaskRunning) {
|
||||
isToastTaskRunning = true;
|
||||
currentToastIndex = 0;
|
||||
startToastLoop();
|
||||
}
|
||||
}, 5000);
|
||||
}
|
||||
|
||||
/**
|
||||
* 开始Toast循环显示
|
||||
*/
|
||||
private void startToastLoop() {
|
||||
if (!isToastTaskRunning) {
|
||||
return;
|
||||
}
|
||||
|
||||
toastRunnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (isToastTaskRunning && currentToastIndex < toastMessages.length) {
|
||||
// 显示当前Toast
|
||||
ToastUtil.showLong(mContext, toastMessages[currentToastIndex]);
|
||||
currentToastIndex++;
|
||||
|
||||
// 如果还有下一条消息,5秒后显示
|
||||
if (currentToastIndex < toastMessages.length && isToastTaskRunning) {
|
||||
toastHandler.postDelayed(this, 5000);
|
||||
} else {
|
||||
// 所有消息显示完毕,重新开始循环
|
||||
if (isToastTaskRunning) {
|
||||
currentToastIndex = 0;
|
||||
toastHandler.postDelayed(this, 5000);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// 立即执行第一次
|
||||
toastRunnable.run();
|
||||
}
|
||||
|
||||
/**
|
||||
* 停止Toast任务
|
||||
*/
|
||||
private void stopToastTask() {
|
||||
isToastTaskRunning = false;
|
||||
if (toastRunnable != null) {
|
||||
toastHandler.removeCallbacks(toastRunnable);
|
||||
}
|
||||
// 移除所有待执行的任务
|
||||
toastHandler.removeCallbacksAndMessages(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 今日运势请求成功
|
||||
* @param entity
|
||||
*/
|
||||
@Override
|
||||
public void getUserTodayFateDataSuccess(TodayFateEntity entity) {
|
||||
// 立即停止Toast任务
|
||||
stopToastTask();
|
||||
|
||||
hideDialogLoading();
|
||||
mTodayEntity = entity;
|
||||
getLatLngByCityName(entity.getUserInfo().getCurrentPlace());
|
||||
setDataShow();
|
||||
viewBinding.refresh.finishRefresh(300);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getFateHistorySuccess(FateHistoryEntity entity) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void userSaveBirthInfoSuccess(TodayFateEntity bean) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getUserInfoSuccess(MineUserInfoBean bean) {
|
||||
}
|
||||
|
||||
/**
|
||||
* 提交举报成功
|
||||
* @param bean
|
||||
*/
|
||||
@Override
|
||||
public void commitReportSuccess(BaseBean bean) {
|
||||
ToastUtil.showShort(mContext, "星语明灯感谢您的反馈");
|
||||
hideDialogLoading();
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置显示内容
|
||||
*/
|
||||
private void setDataShow() {
|
||||
//出生日期
|
||||
String birthDay = mTodayEntity.getUserInfo().getBirthTime();
|
||||
viewBinding.includedBirthInfo.tvBirthdayTime.setText(ZYTimeUtils.formatDateString(birthDay));
|
||||
//真太阳时
|
||||
String realSunTime = mTodayEntity.getUserInfo().getTrueSolarTime();
|
||||
viewBinding.includedBirthInfo.tvZhentaiyangValue.setText(TextUtils.isEmpty(realSunTime) ?
|
||||
"未知":ZYTimeUtils.formatToChineseDate(realSunTime));
|
||||
//命格
|
||||
viewBinding.includedBirthInfo.tvMingge.setText(TextUtils.isEmpty(mTodayEntity.getFortuneAnalysis().getDestiny()) ?
|
||||
"未知": mTodayEntity.getFortuneAnalysis().getDestiny());
|
||||
//经纬度
|
||||
String lng = NumberDecimalFilter.truncateToTwoDecimal(Double.parseDouble(mTodayEntity.getUserInfo().getLongitude()));
|
||||
String lat = NumberDecimalFilter.truncateToTwoDecimal(Double.parseDouble(mTodayEntity.getUserInfo().getLatitude()));
|
||||
viewBinding.includedBirthInfo.tvLonglat.setText(lng + "," + lat);
|
||||
//出生地
|
||||
viewBinding.includedBirthInfo.tvBirthAddress.setText(mTodayEntity.getUserInfo().getBirthPlace());
|
||||
//星座
|
||||
viewBinding.includedBirthInfo.tvXingzuo.setText(mTodayEntity.getUserInfo().getConstellation());
|
||||
//运势分数
|
||||
int todayScore = mTodayEntity.getFortuneAnalysis().getOverallScore();
|
||||
int color = FateDataUtil.getScoreColor(todayScore);
|
||||
viewBinding.includedTodayFateDatas.progressIndicator.setIndicatorColor(color);
|
||||
// viewBinding.includedTodayFateDatas.progressIndicator.setProgress(todayScore,true);
|
||||
viewBinding.includedTodayFateDatas.tvFeenValue.setText(String.valueOf(todayScore));
|
||||
viewBinding.includedTodayFateDatas.tvFeenValue.setTextColor(color);
|
||||
//运势内容
|
||||
viewBinding.includedTodayFateDatas.tvYunshiContent.setText(TextUtils.isEmpty(mTodayEntity.getFortuneAnalysis().getOverallDescription())?
|
||||
"暂无内容" : mTodayEntity.getFortuneAnalysis().getOverallDescription());
|
||||
//今日吉时
|
||||
viewBinding.includedTodayFateDatas.tvTimeZc.setText(mTodayEntity.getFortuneAnalysis().getLuckyInfo().getLuckyTimes().get(0).getTime());
|
||||
viewBinding.includedTodayFateDatas.tvThingZc.setText(mTodayEntity.getFortuneAnalysis().getLuckyInfo().getLuckyTimes().get(0).getDescription());
|
||||
viewBinding.includedTodayFateDatas.tvTimeZw.setText(mTodayEntity.getFortuneAnalysis().getLuckyInfo().getLuckyTimes().get(1).getTime());
|
||||
viewBinding.includedTodayFateDatas.tvThingZw.setText(mTodayEntity.getFortuneAnalysis().getLuckyInfo().getLuckyTimes().get(1).getDescription());
|
||||
viewBinding.includedTodayFateDatas.tvTimeXw.setText(mTodayEntity.getFortuneAnalysis().getLuckyInfo().getLuckyTimes().get(2).getTime());
|
||||
viewBinding.includedTodayFateDatas.tvThingXw.setText(mTodayEntity.getFortuneAnalysis().getLuckyInfo().getLuckyTimes().get(2).getDescription());
|
||||
//天象星座
|
||||
viewBinding.includedXingzuo.tvXingzuo.setText(mTodayEntity.getUserInfo().getConstellation());
|
||||
viewBinding.includedXingzuo.tvWendu.setText(mTodayEntity.getWeatherTemperature());
|
||||
viewBinding.includedXingzuo.tvTianqi.setText(mTodayEntity.getWeatherCondition());
|
||||
viewBinding.includedXingzuo.tvXzType.setText(FateDataUtil.getConstellationType(mTodayEntity.getUserInfo().getConstellation()));
|
||||
viewBinding.includedXingzuo.tvXingzuoYingxiang.setText(mTodayEntity.getFortuneAnalysis().getAstrologyInfluence().getDescription());
|
||||
//事业运
|
||||
viewBinding.includedSyy.tvSyyScore.setText(String.valueOf(mTodayEntity.getFortuneAnalysis().getCareerScore()));
|
||||
// viewBinding.includedSyy.proSyy.setProgress(mTodayEntity.getFortuneAnalysis().getCareerScore());
|
||||
viewBinding.includedSyy.tvSyyContent.setText(mTodayEntity.getFortuneAnalysis().getCareerDescription());
|
||||
//事业运
|
||||
viewBinding.includedSyy.tvGqyScore.setText(String.valueOf(mTodayEntity.getFortuneAnalysis().getLoveScore()));
|
||||
// viewBinding.includedSyy.proGqy.setProgress(mTodayEntity.getFortuneAnalysis().getLoveScore());
|
||||
viewBinding.includedSyy.tvGqyContent.setText(mTodayEntity.getFortuneAnalysis().getLoveDescription());
|
||||
//事业运
|
||||
viewBinding.includedSyy.tvJkyScore.setText(String.valueOf(mTodayEntity.getFortuneAnalysis().getHealthScore()));
|
||||
// viewBinding.includedSyy.proJky.setProgress(mTodayEntity.getFortuneAnalysis().getHealthScore());
|
||||
viewBinding.includedSyy.tvJkyContent.setText(mTodayEntity.getFortuneAnalysis().getHealthDescription());
|
||||
//事业运
|
||||
viewBinding.includedSyy.tvCfyScore.setText(String.valueOf(mTodayEntity.getFortuneAnalysis().getWealthScore()));
|
||||
// viewBinding.includedSyy.proCfy.setProgress(mTodayEntity.getFortuneAnalysis().getWealthScore());
|
||||
viewBinding.includedSyy.tvCfyContent.setText(mTodayEntity.getFortuneAnalysis().getWealthDescription());
|
||||
//幸运数字
|
||||
String [] numbers = mTodayEntity.getFortuneAnalysis().getLuckyInfo().getNumbers();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < numbers.length; i++) {
|
||||
sb.append(numbers[i]);
|
||||
if (i < numbers.length - 1) {
|
||||
sb.append("、");
|
||||
}
|
||||
}
|
||||
viewBinding.includeXingyun.tvLuckNum.setText(sb.toString());
|
||||
//幸运颜色
|
||||
viewBinding.includeXingyun.tvLuckColor.setText(mTodayEntity.getFortuneAnalysis().getLuckyInfo().getColor());
|
||||
//幸运方位
|
||||
viewBinding.includeXingyun.tvLuckFw.setText(mTodayEntity.getFortuneAnalysis().getLuckyInfo().getDirection());
|
||||
//幸运时间
|
||||
viewBinding.includeXingyun. tvLuckTime.setText(mTodayEntity.getFortuneAnalysis().getLuckyInfo().getLuckyTimes().get(0).getTime());
|
||||
//幸运花卉
|
||||
viewBinding.includeXingyun.tvLuckFlower.setText(mTodayEntity.getFortuneAnalysis().getLuckyInfo().getFlower());
|
||||
//幸运方位
|
||||
viewBinding.includeXingyun.tvLuckFood.setText(mTodayEntity.getFortuneAnalysis().getLuckyInfo().getFood());
|
||||
//宜 忌
|
||||
String positive = mTodayEntity.getFortuneAnalysis().getSuggestions().getPositive();
|
||||
String negative = mTodayEntity.getFortuneAnalysis().getSuggestions().getNegative();
|
||||
viewBinding.includeYsjy.tvPositive.setText(positive);
|
||||
viewBinding.includeYsjy.tvNegative.setText(negative);
|
||||
//五行分析
|
||||
viewBinding.includeYsjy.tvFive.setText(mTodayEntity.getFortuneAnalysis().getFiveElementsAnalysis());
|
||||
// 重置动画标志位
|
||||
resetAnimationFlags();
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过城市逆地理编码,获取经纬度
|
||||
* @param cityName
|
||||
*/
|
||||
private void getLatLngByCityName(String cityName) {
|
||||
try {
|
||||
GeocodeSearch geocodeSearch = new GeocodeSearch(mContext);
|
||||
geocodeSearch.setOnGeocodeSearchListener(new GeocodeSearch.OnGeocodeSearchListener() {
|
||||
@Override
|
||||
public void onRegeocodeSearched(com.amap.api.services.geocoder.RegeocodeResult regeocodeResult, int i) {
|
||||
// Not used here
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGeocodeSearched(GeocodeResult geocodeResult, int rCode) {
|
||||
if (rCode == AMapException.CODE_AMAP_SUCCESS) {
|
||||
List<GeocodeAddress> addressList = geocodeResult.getGeocodeAddressList();
|
||||
if (addressList != null && !addressList.isEmpty()) {
|
||||
GeocodeAddress address = addressList.get(0);
|
||||
LatLonPoint latLonPoint = address.getLatLonPoint();
|
||||
String lat = String.valueOf(NumberDecimalFilter.roundToTwoDecimalPlaces(latLonPoint.getLatitude()));
|
||||
String lng = String.valueOf(NumberDecimalFilter.roundToTwoDecimalPlaces(latLonPoint.getLongitude()));
|
||||
WeatherParameter parameter = new WeatherParameter(lng + "," + lat)
|
||||
.lang(Lang.ZH_HANS)
|
||||
.unit(Unit.METRIC);
|
||||
instance.weatherNow(parameter, new Callback<WeatherNowResponse>() {
|
||||
@Override
|
||||
public void onSuccess(WeatherNowResponse response) {
|
||||
mContext.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
WeatherIconUtil.loadWeatherIcon(mContext,viewBinding.includedBirthInfo.imgWeather,response.getNow().getIcon());
|
||||
viewBinding.includedBirthInfo.tvTianqi.setText(response.getNow().getText() + " " +response.getNow().getTemp() + "℃");
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(ErrorResponse errorResponse) {
|
||||
Log.d(TAG,"调用和风 API--onFailure" + errorResponse.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onException(Throwable e) {
|
||||
Log.d(TAG,"调用和风 API--onException" + e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
Log.d("GeoUtil", "未找到城市: " + cityName);
|
||||
}
|
||||
} else {
|
||||
Log.e("GeoUtil", "查询失败,错误码: " + rCode);
|
||||
}
|
||||
}
|
||||
});
|
||||
// 创建 GeocodeQuery,第一个参数是城市名,第二个参数可指定省份(可选)
|
||||
GeocodeQuery query = new GeocodeQuery(cityName, null);
|
||||
geocodeSearch.getFromLocationNameAsyn(query); // 异步查询
|
||||
} catch (AMapException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
// 重置动画标志位
|
||||
private void resetAnimationFlags() {
|
||||
isOverallAnimPlayed = false;
|
||||
isCareerAnimPlayed = false;
|
||||
isLoveAnimPlayed = false;
|
||||
isHealthAnimPlayed = false;
|
||||
isWealthAnimPlayed = false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
// 停止Toast任务
|
||||
stopToastTask();
|
||||
// 重置标志位以便下次可见时重新动画
|
||||
resetAnimationFlags();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
// 清理资源
|
||||
stopToastTask();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNetChange(int netModel) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showError(String message) {
|
||||
// 停止Toast任务
|
||||
stopToastTask();
|
||||
|
||||
hideDialogLoading();
|
||||
ToastUtil.showShort(mContext,message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void logOut(BaseBean bean) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getAllCitySuccess(List<CityDataEntity> list) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private void getCurrentCityWeather(GeoPoiResponse response) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPermissionsGranted(int requestCode, @NonNull List<String> perms) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPermissionsDenied(int requestCode, @NonNull List<String> perms) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
|
||||
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
||||
EasyPermissions.onRequestPermissionsResult(requestCode, permissions, grantResults, this);
|
||||
hidePermissionDialog();
|
||||
if(requestCode == REQUEST_EVENT_CODE_10002){
|
||||
if(grantResults[0] == 0){
|
||||
ToastUtil.showShort(mContext,"定位获取成功");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -19,6 +19,7 @@ import com.ckkj.water.index.mvp.IndexContract;
|
||||
import com.ckkj.water.index.mvp.IndexImpl;
|
||||
import com.ckkj.water.index.mvp.IndexPresenter;
|
||||
import com.ckkj.water.network.BaseBean;
|
||||
import com.ckkj.water.permission.PermissionActivity;
|
||||
import com.ckkj.water.utils.show.ToastUtil;
|
||||
import com.maning.mlkitscanner.scan.MNScanManager;
|
||||
import com.maning.mlkitscanner.scan.callback.act.MNScanCallback;
|
||||
@@ -33,6 +34,7 @@ public class IndexFragment extends BaseFragment<IndexFragmentLayoutBinding, Inde
|
||||
|
||||
private DeviceAdapter deviceAdapter;
|
||||
private List<IndexDeviceEntity> devList = new ArrayList<>();
|
||||
private int mCurrentPage = 1;
|
||||
|
||||
@Override
|
||||
protected void initArgs(Bundle bundle) {
|
||||
@@ -48,6 +50,8 @@ public class IndexFragment extends BaseFragment<IndexFragmentLayoutBinding, Inde
|
||||
devList.add(entity2);
|
||||
devList.add(entity3);
|
||||
devList.add(entity4);
|
||||
showLoadingDialog();
|
||||
mPresenter.getDevicesList();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -86,7 +90,13 @@ public class IndexFragment extends BaseFragment<IndexFragmentLayoutBinding, Inde
|
||||
break;
|
||||
|
||||
case R.id.img_add:
|
||||
String permission = Manifest.permission.ACCESS_FINE_LOCATION;
|
||||
boolean hasPermission = hasRecordPermission(permission);
|
||||
if(!hasPermission){
|
||||
goTo(mContext, PermissionActivity.class,null);
|
||||
}else{
|
||||
goTo(mContext, AddDeviceActivity.class,null);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -122,6 +132,15 @@ public class IndexFragment extends BaseFragment<IndexFragmentLayoutBinding, Inde
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取设备列表成功
|
||||
*/
|
||||
@Override
|
||||
public void getDeviceListSuccess() {
|
||||
hideDialogLoading();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
super.onDestroyView();
|
||||
@@ -133,6 +152,8 @@ public class IndexFragment extends BaseFragment<IndexFragmentLayoutBinding, Inde
|
||||
|
||||
@Override
|
||||
public void showError(String message) {
|
||||
hideDialogLoading();
|
||||
ToastUtil.showShort(mContext,message);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -148,4 +169,6 @@ public class IndexFragment extends BaseFragment<IndexFragmentLayoutBinding, Inde
|
||||
scanQrcode();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -6,6 +6,8 @@ import com.ckkj.water.network.BaseBean;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author fengxiaoyang
|
||||
* @date 2025/7/26
|
||||
@@ -18,8 +20,26 @@ public class IndexContract {
|
||||
void fail(String msg);
|
||||
}
|
||||
public interface DataModel{
|
||||
|
||||
//获取设备列表
|
||||
void getDeviceList(Map<String,String> map,CallBack callBack);
|
||||
|
||||
//查询设备信息
|
||||
void getDeviceInfomation(Map<String,String> map,CallBack callBack);
|
||||
//添加设备
|
||||
void addDevice(JSONObject json,CallBack callBack);
|
||||
|
||||
//修改设备信息
|
||||
void editDeviceInfo(JSONObject json,CallBack callBack);
|
||||
|
||||
//修改设备信息
|
||||
void deleteDevice(JSONObject json,CallBack callBack);
|
||||
|
||||
//手动开启关闭设备
|
||||
void turnOnOffDevice(JSONObject json,CallBack callBack);
|
||||
}
|
||||
|
||||
public interface IndexView extends IView{
|
||||
void getDeviceListSuccess();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,76 @@
|
||||
package com.ckkj.water.index.mvp;
|
||||
|
||||
import com.ckkj.water.network.BaseBean;
|
||||
import com.ckkj.water.network.NetWorkManager;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import io.reactivex.Observer;
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.annotations.NonNull;
|
||||
import io.reactivex.disposables.Disposable;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
|
||||
public class IndexImpl implements IndexContract.DataModel{
|
||||
|
||||
/**
|
||||
* 设备列表
|
||||
* @param map
|
||||
* @param callBack
|
||||
*/
|
||||
@Override
|
||||
public void getDeviceList(Map<String, String> map, IndexContract.CallBack callBack) {
|
||||
NetWorkManager.getRequest().getIndexDeviceList(NetWorkManager.getToken())
|
||||
.subscribeOn(Schedulers.io())
|
||||
.unsubscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Observer<BaseBean>() {
|
||||
@Override
|
||||
public void onSubscribe(@NonNull Disposable d) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(@NonNull BaseBean bean) {
|
||||
if (bean.getCode() == 200) {
|
||||
callBack.success(bean.getData());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(@NonNull Throwable e) {
|
||||
callBack.fail(e.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getDeviceInfomation(Map<String, String> map, IndexContract.CallBack callBack) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addDevice(JSONObject json, IndexContract.CallBack callBack) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void editDeviceInfo(JSONObject json, IndexContract.CallBack callBack) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteDevice(JSONObject json, IndexContract.CallBack callBack) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void turnOnOffDevice(JSONObject json, IndexContract.CallBack callBack) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,8 @@ import com.ckkj.water.base.BasePresenter;
|
||||
import com.ckkj.water.login.mvp.LoginImpl;
|
||||
import com.ckkj.water.network.BaseBean;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class IndexPresenter extends BasePresenter<IndexContract.IndexView>{
|
||||
|
||||
private IndexImpl mImpl;
|
||||
@@ -12,4 +14,24 @@ public class IndexPresenter extends BasePresenter<IndexContract.IndexView>{
|
||||
this.mImpl = mImpl;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询设备列表
|
||||
*/
|
||||
public void getDevicesList() {
|
||||
mImpl.getDeviceList(new HashMap<>(), new IndexContract.CallBack<BaseBean>() {
|
||||
@Override
|
||||
public void success(BaseBean bean) {
|
||||
if(IndexPresenter.this.getView() != null){
|
||||
IndexPresenter.this.getView().getDeviceListSuccess();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fail(String msg) {
|
||||
if(IndexPresenter.this.getView() != null){
|
||||
IndexPresenter.this.getView().showError(msg);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,6 @@ import com.ckkj.water.R;
|
||||
import com.ckkj.water.adapter.ViewPageAdapter;
|
||||
import com.ckkj.water.base.BaseActivity;
|
||||
import com.ckkj.water.base.entity.MineUserInfoBean;
|
||||
import com.ckkj.water.chat.ChatFragment;
|
||||
import com.ckkj.water.databinding.MainActivityLayoutBinding;
|
||||
import com.ckkj.water.dialog.DialogAppUpdate;
|
||||
import com.ckkj.water.main.MainContract;
|
||||
@@ -230,8 +229,6 @@ public class MainActivity extends BaseActivity<MainActivityLayoutBinding, MainPr
|
||||
// 设置底部导航栏选中状态
|
||||
viewBinding.navView.setSelectedItemId(R.id.navigation_index);
|
||||
|
||||
// 将参数传递给IndexFragment
|
||||
passBundleToIndexFragment(extras);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -250,28 +247,10 @@ public class MainActivity extends BaseActivity<MainActivityLayoutBinding, MainPr
|
||||
// 设置底部导航栏选中状态
|
||||
viewBinding.navView.setSelectedItemId(R.id.navigation_index);
|
||||
|
||||
// 将参数传递给IndexFragment
|
||||
passBundleToIndexFragment(extras);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 将Bundle参数传递给IndexFragment
|
||||
*/
|
||||
private void passBundleToIndexFragment(Bundle bundle) {
|
||||
// 获取IndexFragment实例
|
||||
Fragment indexFragment = mFragmentList.get(1);
|
||||
if (indexFragment instanceof ChatFragment) {
|
||||
// 设置参数到Fragment
|
||||
indexFragment.setArguments(bundle);
|
||||
|
||||
// 如果Fragment已经创建,可以调用其方法来处理参数
|
||||
if (indexFragment.isAdded()) {
|
||||
((ChatFragment) indexFragment).handleBirthInfoBundle(bundle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
|
||||
@@ -3,19 +3,8 @@ package com.ckkj.water.network;
|
||||
|
||||
|
||||
import com.ckkj.water.base.entity.MineUserInfoBean;
|
||||
import com.ckkj.water.chat.entity.ChatQuestionEntity;
|
||||
import com.ckkj.water.fate.entity.CityDataEntity;
|
||||
import com.ckkj.water.fate.entity.FateHistoryEntity;
|
||||
import com.ckkj.water.fate.entity.TodayFateEntity;
|
||||
import com.ckkj.water.chat.entity.CharHistoryEntity;
|
||||
import com.ckkj.water.chat.entity.ChatAiMsgEntity;
|
||||
import com.ckkj.water.chat.entity.IndexTemplateEntity;
|
||||
import com.ckkj.water.login.entity.LoginEntity;
|
||||
import com.ckkj.water.main.entity.CheckVersionEntity;
|
||||
import com.ckkj.water.mine.entity.InviteeRecordEntity;
|
||||
import com.ckkj.water.mine.entity.MemberComboEntity;
|
||||
import com.ckkj.water.mine.entity.RecommendDataEntity;
|
||||
import com.ckkj.water.mine.entity.RewardRecordEntity;
|
||||
import com.ckkj.water.plate.entity.BaziResultBean;
|
||||
import com.ckkj.water.plate.entity.BaziSaveSuccessEntity;
|
||||
import com.ckkj.water.plate.entity.PaipanHistoryEntity;
|
||||
@@ -36,66 +25,35 @@ import retrofit2.http.QueryMap;
|
||||
*/
|
||||
|
||||
public interface Request {
|
||||
//注册
|
||||
@POST("auth/register")
|
||||
Observable<BaseBean> register(@Body RequestBody requestBody);
|
||||
//获取验证码
|
||||
@POST("user/api/phone")
|
||||
Observable<BaseBean> getSmsCode(@QueryMap Map<String, Object> map);
|
||||
//版本检测更新
|
||||
@POST("mobile/version?end=android")
|
||||
Observable<BaseBean<CheckVersionEntity>> checkVersionCode(@HeaderMap Map<String, String> headMap, @Body RequestBody requestBody);
|
||||
//输入激活码,临时会员
|
||||
@POST("user/api/useActivationCode")
|
||||
Observable<BaseBean> activationVip(@HeaderMap Map<String, String> headMap, @QueryMap Map<String, Object> map);
|
||||
//版本检测更新
|
||||
@POST("mine/api/versionNum")
|
||||
Observable<BaseBean<CheckVersionEntity>> getVersionCheck(@HeaderMap Map<String, String> headMap, @QueryMap Map<String, Object> map);
|
||||
//版本检测更新
|
||||
@POST("mobile/context")
|
||||
Observable<BaseBean<ChatAiMsgEntity>> indexTalkToAi(@HeaderMap Map<String, String> headMap, @QueryMap Map<String, Object> map);
|
||||
//首页模板消息数据获取
|
||||
@POST("mobile/homeInfo")
|
||||
Observable<BaseBean<List<IndexTemplateEntity>>> getIndexTemplateDatas();
|
||||
//会话底部模板数据获取
|
||||
@POST("mobile/aitebcontent")
|
||||
Observable<BaseBean<List<ChatQuestionEntity>>> aitebcontent();
|
||||
//对话历史记录
|
||||
@POST("mobile/mySessions")
|
||||
Observable<BaseBean<CharHistoryEntity>> getHistoryList(@HeaderMap Map<String, String> headMap, @QueryMap Map<String, Object> map);
|
||||
//删除历史记录
|
||||
@POST("mobile/deleteSession")
|
||||
Observable<BaseBean> deleteHistoryBySessionID(@HeaderMap Map<String, String> headMap, @QueryMap Map<String, Object> map);
|
||||
//根据 id 查询会话详情
|
||||
@POST("mobile/sessionMessages")
|
||||
Observable<BaseBean<List<ChatAiMsgEntity>>> getChatDetailById(@HeaderMap Map<String, String> headMap, @QueryMap Map<String, Object> map);
|
||||
//获取城市列表
|
||||
@GET("mobile/chinaCites")
|
||||
Observable<BaseBean<List<CityDataEntity>>> getCityDatas(@HeaderMap Map<String, String> headMap, @QueryMap Map<String, Object> map);
|
||||
//保存用户的生辰八字
|
||||
@POST("mobile/yourhoroscope")
|
||||
Observable<BaseBean> saveUserBirthInfo(@HeaderMap Map<String, String> headMap,@Body RequestBody requestBody);
|
||||
//修改用户的生辰八字
|
||||
@POST("mobile/yourhoroscope/modify")
|
||||
Observable<BaseBean<TodayFateEntity>> saveUserEditBirthInfo(@HeaderMap Map<String, String> headMap,@Body RequestBody requestBody);
|
||||
|
||||
//发送验证码
|
||||
@GET("resource/code")
|
||||
Observable<BaseBean> sendPhoneCode(@HeaderMap Map<String, String> headMap,@QueryMap Map<String, Object> map);
|
||||
|
||||
|
||||
//注册
|
||||
@POST("auth/register")
|
||||
Observable<BaseBean> register(@Body RequestBody requestBody);
|
||||
//登录
|
||||
@POST("auth/login")
|
||||
Observable<BaseBean<LoginEntity>> loginBySmsCode(@HeaderMap Map<String, String> headMap, @Body RequestBody requestBody);
|
||||
//获取个人信息
|
||||
@GET("app/v1/getUserInfo")
|
||||
Observable<BaseBean<MineUserInfoBean>> getMineUserInfo(@HeaderMap Map<String, String> headMap, @QueryMap Map<String, Object> map);
|
||||
//更新用户头像
|
||||
//获取今日运势
|
||||
@POST("mobile/yourhoroscope/today")
|
||||
Observable<BaseBean<TodayFateEntity>> getUserTodayFateDatas(@HeaderMap Map<String, String> headMap);
|
||||
//获取运势历史列表
|
||||
@GET("mobile/yourhoroscope/history")
|
||||
Observable<BaseBean<FateHistoryEntity>> getUserFateHistory(@HeaderMap Map<String, String> headMap);
|
||||
|
||||
//首页设备列表
|
||||
@GET("app/v1/deviceList")
|
||||
Observable<BaseBean> getIndexDeviceList(@HeaderMap Map<String, String> headMap);
|
||||
|
||||
|
||||
|
||||
@POST("mobile/version?end=android")
|
||||
Observable<BaseBean<CheckVersionEntity>> checkVersionCode(@HeaderMap Map<String, String> headMap, @Body RequestBody requestBody);
|
||||
//版本检测更新
|
||||
@POST("mine/api/versionNum")
|
||||
Observable<BaseBean<CheckVersionEntity>> getVersionCheck(@HeaderMap Map<String, String> headMap, @QueryMap Map<String, Object> map);
|
||||
|
||||
|
||||
|
||||
|
||||
//保存排盘结果
|
||||
@POST("mobile/paiPan")
|
||||
Observable<BaseBean<BaziSaveSuccessEntity>> startPaipan(@HeaderMap Map<String, String> headMap, @Body RequestBody requestBody);
|
||||
@@ -111,9 +69,6 @@ public interface Request {
|
||||
//删除历史记录
|
||||
@POST("mobile/paiPan/record")
|
||||
Observable<BaseBean> deletePaipanRecordById(@HeaderMap Map<String, String> headMap, @QueryMap Map<String, Object> map);
|
||||
//修改手机号
|
||||
@POST("mobile/reporting")
|
||||
Observable<BaseBean> commitReporting(@HeaderMap Map<String, String> headMap,@QueryMap Map<String, Object> map);
|
||||
//邀请数据
|
||||
//奖励记录
|
||||
/***************************钱包********************************/
|
||||
|
||||
@@ -72,12 +72,11 @@ public class PermissionActivity extends BaseActivity<PermissionLayoutBinding, Ma
|
||||
|
||||
case R.id.tv_commit:
|
||||
String[] permission = {
|
||||
Manifest.permission.BLUETOOTH_SCAN,
|
||||
Manifest.permission.ACCESS_FINE_LOCATION
|
||||
};
|
||||
boolean hasPermission = hasRecordPermission(permission);
|
||||
if(!hasPermission){
|
||||
getMorePermissionRequst(permission,"权限申请","智溉管家需要您的授权获取蓝牙和位置权限,用于添加设备",REQUEST_EVENT_CODE_10001);
|
||||
getMorePermissionRequst(permission,"权限申请","智溉管家需要您的授权获取位置权限,用于添加设备",REQUEST_EVENT_CODE_10001);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -128,7 +127,7 @@ public class PermissionActivity extends BaseActivity<PermissionLayoutBinding, Ma
|
||||
public void onPermissionsGranted(int requestCode, @NonNull List<String> perms) {
|
||||
if (requestCode == REQUEST_EVENT_CODE_10001) {
|
||||
ToastUtil.showShort(mContext,"权限获取成功");
|
||||
hidePermissionDialog();
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,114 +1,114 @@
|
||||
package com.ckkj.water.plate;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
import com.ckkj.water.AppConfig;
|
||||
import com.ckkj.water.R;
|
||||
import com.ckkj.water.base.BaseFragment;
|
||||
import com.ckkj.water.databinding.PlateFragmentBinding;
|
||||
import com.ckkj.water.login.LoginActivity;
|
||||
import com.ckkj.water.network.BaseBean;
|
||||
import com.ckkj.water.plate.adapter.ViewPagerAdapter;
|
||||
import com.ckkj.water.plate.entity.BaziResultBean;
|
||||
import com.ckkj.water.plate.entity.BaziSaveSuccessEntity;
|
||||
import com.ckkj.water.plate.entity.PaipanHistoryEntity;
|
||||
import com.ckkj.water.plate.mvp.PlateContract;
|
||||
import com.ckkj.water.plate.mvp.PlateImpl;
|
||||
import com.ckkj.water.plate.mvp.PlatePresenter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* @author fengxiaoyang
|
||||
* @date 2025/7/30
|
||||
* @description TODO: 排盘页面
|
||||
*/
|
||||
|
||||
public class PlateFragment extends BaseFragment<PlateFragmentBinding, PlatePresenter>
|
||||
implements PlateContract.PlateView {
|
||||
private List<Fragment> mFragmentList = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
public PlatePresenter createPresenter() {
|
||||
return new PlatePresenter(new PlateImpl());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initData(Bundle state) {
|
||||
viewBinding.includedTitle.imgBack.setVisibility(View.GONE);
|
||||
viewBinding.includedTitle.tvTitle.setText("信息录入");
|
||||
ViewPagerAdapter adapter = new ViewPagerAdapter(this, mFragmentList);
|
||||
viewBinding.viewpage.setAdapter(adapter);
|
||||
viewBinding.tvPaipan.setSelected(true);
|
||||
viewBinding.viewpage.setCurrentItem(0);
|
||||
//viewpage2 特有的 api,禁止滑动
|
||||
viewBinding.viewpage.setUserInputEnabled(false);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onNetChange(int netModel) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showError(String message) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void logOut(BaseBean bean) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getPaipanResult(BaziResultBean bean) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveBaziResultSuccess(BaziSaveSuccessEntity bean) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getHistorySuccess(PaipanHistoryEntity entity) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deletePaipanHistorySuccess(int pos) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStreamMessageReceived(String messageChunk) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStreamComplete(String complateMsg) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void commitReportSuccess(BaseBean bean) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPermissionsGranted(int requestCode, @NonNull List<String> perms) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPermissionsDenied(int requestCode, @NonNull List<String> perms) {
|
||||
|
||||
}
|
||||
}
|
||||
//package com.ckkj.water.plate;
|
||||
//
|
||||
//import android.os.Bundle;
|
||||
//import android.view.View;
|
||||
//
|
||||
//import androidx.annotation.NonNull;
|
||||
//import androidx.fragment.app.Fragment;
|
||||
//
|
||||
//import com.ckkj.water.AppConfig;
|
||||
//import com.ckkj.water.R;
|
||||
//import com.ckkj.water.base.BaseFragment;
|
||||
//import com.ckkj.water.databinding.PlateFragmentBinding;
|
||||
//import com.ckkj.water.login.LoginActivity;
|
||||
//import com.ckkj.water.network.BaseBean;
|
||||
//import com.ckkj.water.plate.adapter.ViewPagerAdapter;
|
||||
//import com.ckkj.water.plate.entity.BaziResultBean;
|
||||
//import com.ckkj.water.plate.entity.BaziSaveSuccessEntity;
|
||||
//import com.ckkj.water.plate.entity.PaipanHistoryEntity;
|
||||
//import com.ckkj.water.plate.mvp.PlateContract;
|
||||
//import com.ckkj.water.plate.mvp.PlateImpl;
|
||||
//import com.ckkj.water.plate.mvp.PlatePresenter;
|
||||
//
|
||||
//import java.util.ArrayList;
|
||||
//import java.util.List;
|
||||
//
|
||||
//
|
||||
///**
|
||||
// * @author fengxiaoyang
|
||||
// * @date 2025/7/30
|
||||
// * @description TODO: 排盘页面
|
||||
// */
|
||||
//
|
||||
//public class PlateFragment extends BaseFragment<PlateFragmentBinding, PlatePresenter>
|
||||
// implements PlateContract.PlateView {
|
||||
// private List<Fragment> mFragmentList = new ArrayList<>();
|
||||
//
|
||||
// @Override
|
||||
// public PlatePresenter createPresenter() {
|
||||
// return new PlatePresenter(new PlateImpl());
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void initData(Bundle state) {
|
||||
// viewBinding.includedTitle.imgBack.setVisibility(View.GONE);
|
||||
// viewBinding.includedTitle.tvTitle.setText("信息录入");
|
||||
// ViewPagerAdapter adapter = new ViewPagerAdapter(this, mFragmentList);
|
||||
// viewBinding.viewpage.setAdapter(adapter);
|
||||
// viewBinding.tvPaipan.setSelected(true);
|
||||
// viewBinding.viewpage.setCurrentItem(0);
|
||||
// //viewpage2 特有的 api,禁止滑动
|
||||
// viewBinding.viewpage.setUserInputEnabled(false);
|
||||
// }
|
||||
//
|
||||
//
|
||||
// @Override
|
||||
// public void onNetChange(int netModel) {
|
||||
//
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void showError(String message) {
|
||||
//
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void logOut(BaseBean bean) {
|
||||
//
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void getPaipanResult(BaziResultBean bean) {
|
||||
//
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void saveBaziResultSuccess(BaziSaveSuccessEntity bean) {
|
||||
//
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void getHistorySuccess(PaipanHistoryEntity entity) {
|
||||
//
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void deletePaipanHistorySuccess(int pos) {
|
||||
//
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onStreamMessageReceived(String messageChunk) {
|
||||
//
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onStreamComplete(String complateMsg) {
|
||||
//
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void commitReportSuccess(BaseBean bean) {
|
||||
//
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onPermissionsGranted(int requestCode, @NonNull List<String> perms) {
|
||||
//
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onPermissionsDenied(int requestCode, @NonNull List<String> perms) {
|
||||
//
|
||||
// }
|
||||
//}
|
||||
|
||||
@@ -1,228 +1,225 @@
|
||||
package com.ckkj.water.plate.mvp;
|
||||
|
||||
import com.ckkj.water.base.BasePresenter;
|
||||
import com.ckkj.water.chat.mvp.IndexContract;
|
||||
import com.ckkj.water.chat.mvp.IndexImpl;
|
||||
import com.ckkj.water.fate.entity.CityDataEntity;
|
||||
import com.ckkj.water.network.BaseBean;
|
||||
import com.ckkj.water.plate.entity.BaziResultBean;
|
||||
import com.ckkj.water.plate.entity.BaziSaveSuccessEntity;
|
||||
import com.ckkj.water.plate.entity.PaipanHistoryEntity;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author fengxiaoyang
|
||||
* @date 2025/7/30
|
||||
* @description TODO: 描述该类的作用
|
||||
*/
|
||||
|
||||
public class PlatePresenter extends BasePresenter<PlateContract.PlateView> {
|
||||
private PlateImpl impl;
|
||||
|
||||
public PlatePresenter(PlateImpl impl) {
|
||||
this.impl = impl;
|
||||
}
|
||||
|
||||
/**
|
||||
* 排盘,直接调用缘份居 Api
|
||||
* @param map
|
||||
*/
|
||||
public void startPaiPan(Map<String, Object> map) {
|
||||
impl.startPaiPanByYfjApi(map, new PlateContract.CallBack<BaziResultBean>() {
|
||||
@Override
|
||||
public void success(BaziResultBean entity) {
|
||||
if(PlatePresenter.this.getView() != null){
|
||||
if(PlatePresenter.this.getView() != null){
|
||||
PlatePresenter.this.getView().getPaipanResult(entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fail(String msg) {
|
||||
if(PlatePresenter.this.getView() != null){
|
||||
PlatePresenter.this.getView().showError(msg);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传八字结果
|
||||
*
|
||||
* @param result
|
||||
* @param cityData
|
||||
* @param timeType
|
||||
*/
|
||||
public void uploadBaziResult(BaziResultBean result, CityDataEntity cityData, int timeType) {
|
||||
try {
|
||||
BaziResultBean.BaseInfoDTO baseInfoDTO = result.getBaseInfo();
|
||||
BaziResultBean.DetailInfoDTO.SizhuInfoDTO sizhuInfoDTO = result.getDetailInfo().getSizhuInfo();
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("name",baseInfoDTO.getName());
|
||||
json.put("gender",baseInfoDTO.getSex().equals("乾造")? "0" : "1");
|
||||
json.put("birthType",timeType == 2001 ? "1":"0");
|
||||
json.put("yangLiBirthTime",baseInfoDTO.getGongli());
|
||||
json.put("yinLiBirthTime",baseInfoDTO.getNongli());
|
||||
json.put("birthPlace",cityData == null ? "北京市": cityData.getCityName());
|
||||
json.put("province",cityData == null ? "北京市": cityData.getProvinceName());
|
||||
json.put("city",cityData == null ? "北京": cityData.getCityName());
|
||||
json.put("openSolarTime","2");
|
||||
json.put("nianZhu",sizhuInfoDTO.getYear().getTg() + "," + sizhuInfoDTO.getYear().getDz());
|
||||
json.put("yueZhu",sizhuInfoDTO.getMonth().getTg() + "," + sizhuInfoDTO.getMonth().getDz());
|
||||
json.put("riZhu",sizhuInfoDTO.getDay().getTg() + "," + sizhuInfoDTO.getDay().getDz());
|
||||
json.put("shiZhu",sizhuInfoDTO.getHour().getTg() + "," + sizhuInfoDTO.getHour().getDz());
|
||||
impl.saveUserBirthInfo(json, new PlateContract.CallBack<BaziSaveSuccessEntity>() {
|
||||
@Override
|
||||
public void success(BaziSaveSuccessEntity bean) {
|
||||
if(PlatePresenter.this.getView() != null){
|
||||
if(PlatePresenter.this.getView() != null){
|
||||
PlatePresenter.this.getView().saveBaziResultSuccess(bean);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fail(String msg) {
|
||||
if(PlatePresenter.this.getView() != null){
|
||||
if(PlatePresenter.this.getView() != null){
|
||||
PlatePresenter.this.getView().showError(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
} catch (JSONException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取历史运势
|
||||
* @param page
|
||||
*/
|
||||
public void getHistoryDatas(int page) {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("pageNum", page);
|
||||
map.put("pageSize", 10);
|
||||
impl.getPaipanHistoryList(map, new PlateContract.CallBack<PaipanHistoryEntity>() {
|
||||
|
||||
@Override
|
||||
public void success(PaipanHistoryEntity entity) {
|
||||
if(PlatePresenter.this.getView() != null){
|
||||
PlatePresenter.this.getView().getHistorySuccess(entity);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fail(String msg) {
|
||||
if(PlatePresenter.this.getView() != null){
|
||||
PlatePresenter.this.getView().showError(msg);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除记录
|
||||
* @param id
|
||||
*/
|
||||
public void deleteRecordByID(String id,int pos) {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("recordId", id);
|
||||
impl.deleteRecordByID(map, new PlateContract.CallBack<BaseBean>() {
|
||||
@Override
|
||||
public void success(BaseBean bean) {
|
||||
if(PlatePresenter.this.getView() != null){
|
||||
PlatePresenter.this.getView().deletePaipanHistorySuccess(pos);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fail(String msg) {
|
||||
if(PlatePresenter.this.getView() != null){
|
||||
PlatePresenter.this.getView().showError(msg);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* ai 分析八字
|
||||
* @param mSaveEntity
|
||||
*/
|
||||
public void AiParseBaziResult(BaziSaveSuccessEntity mSaveEntity) {
|
||||
try {
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("resultId", mSaveEntity.getRecordId());
|
||||
impl.sendMsgToAi(json, new PlateContract.AiStreamCallback() {
|
||||
@Override
|
||||
public void onMessage(String messageChunk) {
|
||||
if (PlatePresenter.this.getView() != null) {
|
||||
PlatePresenter.this.getView().onStreamMessageReceived(messageChunk);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(String error) {
|
||||
if (PlatePresenter.this.getView() != null) {
|
||||
PlatePresenter.this.getView().showError(error);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete(String complateContent) {
|
||||
if (PlatePresenter.this.getView() != null) {
|
||||
PlatePresenter.this.getView().onStreamComplete(complateContent);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSessionReceived(String sessionId) {
|
||||
// 这个回调在当前场景下可能不需要,但保留接口一致性
|
||||
// Log.d("PlatePresenter", "Session received: " + sessionId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loginLost() {
|
||||
if (PlatePresenter.this.getView() != null) {
|
||||
// 处理登录失效的情况
|
||||
// 这里可以根据需要跳转到登录页面
|
||||
// Log.w("PlatePresenter", "Login lost");
|
||||
}
|
||||
}
|
||||
});
|
||||
} catch (JSONException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 举报
|
||||
* @param reason
|
||||
*/
|
||||
public void commitReport(String reason) {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("content", reason);
|
||||
new IndexImpl().commitReport(map, new IndexContract.CallBack<BaseBean>() {
|
||||
@Override
|
||||
public void success(BaseBean bean) {
|
||||
if (PlatePresenter.this.getView() != null) {
|
||||
PlatePresenter.this.getView().commitReportSuccess(bean);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fail(String msg) {
|
||||
if (PlatePresenter.this.getView() != null) {
|
||||
PlatePresenter.this.getView().showError(msg);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
//package com.ckkj.water.plate.mvp;
|
||||
//
|
||||
//import com.ckkj.water.base.BasePresenter;
|
||||
//import com.ckkj.water.network.BaseBean;
|
||||
//import com.ckkj.water.plate.entity.BaziResultBean;
|
||||
//import com.ckkj.water.plate.entity.BaziSaveSuccessEntity;
|
||||
//import com.ckkj.water.plate.entity.PaipanHistoryEntity;
|
||||
//
|
||||
//import org.json.JSONException;
|
||||
//import org.json.JSONObject;
|
||||
//
|
||||
//import java.util.HashMap;
|
||||
//import java.util.Map;
|
||||
//
|
||||
///**
|
||||
// * @author fengxiaoyang
|
||||
// * @date 2025/7/30
|
||||
// * @description TODO: 描述该类的作用
|
||||
// */
|
||||
//
|
||||
//public class PlatePresenter extends BasePresenter<PlateContract.PlateView> {
|
||||
// private PlateImpl impl;
|
||||
//
|
||||
// public PlatePresenter(PlateImpl impl) {
|
||||
// this.impl = impl;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 排盘,直接调用缘份居 Api
|
||||
// * @param map
|
||||
// */
|
||||
// public void startPaiPan(Map<String, Object> map) {
|
||||
// impl.startPaiPanByYfjApi(map, new PlateContract.CallBack<BaziResultBean>() {
|
||||
// @Override
|
||||
// public void success(BaziResultBean entity) {
|
||||
// if(PlatePresenter.this.getView() != null){
|
||||
// if(PlatePresenter.this.getView() != null){
|
||||
// PlatePresenter.this.getView().getPaipanResult(entity);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void fail(String msg) {
|
||||
// if(PlatePresenter.this.getView() != null){
|
||||
// PlatePresenter.this.getView().showError(msg);
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 上传八字结果
|
||||
// *
|
||||
// * @param result
|
||||
// * @param cityData
|
||||
// * @param timeType
|
||||
// */
|
||||
// public void uploadBaziResult(BaziResultBean result, CityDataEntity cityData, int timeType) {
|
||||
// try {
|
||||
// BaziResultBean.BaseInfoDTO baseInfoDTO = result.getBaseInfo();
|
||||
// BaziResultBean.DetailInfoDTO.SizhuInfoDTO sizhuInfoDTO = result.getDetailInfo().getSizhuInfo();
|
||||
// JSONObject json = new JSONObject();
|
||||
// json.put("name",baseInfoDTO.getName());
|
||||
// json.put("gender",baseInfoDTO.getSex().equals("乾造")? "0" : "1");
|
||||
// json.put("birthType",timeType == 2001 ? "1":"0");
|
||||
// json.put("yangLiBirthTime",baseInfoDTO.getGongli());
|
||||
// json.put("yinLiBirthTime",baseInfoDTO.getNongli());
|
||||
// json.put("birthPlace",cityData == null ? "北京市": cityData.getCityName());
|
||||
// json.put("province",cityData == null ? "北京市": cityData.getProvinceName());
|
||||
// json.put("city",cityData == null ? "北京": cityData.getCityName());
|
||||
// json.put("openSolarTime","2");
|
||||
// json.put("nianZhu",sizhuInfoDTO.getYear().getTg() + "," + sizhuInfoDTO.getYear().getDz());
|
||||
// json.put("yueZhu",sizhuInfoDTO.getMonth().getTg() + "," + sizhuInfoDTO.getMonth().getDz());
|
||||
// json.put("riZhu",sizhuInfoDTO.getDay().getTg() + "," + sizhuInfoDTO.getDay().getDz());
|
||||
// json.put("shiZhu",sizhuInfoDTO.getHour().getTg() + "," + sizhuInfoDTO.getHour().getDz());
|
||||
// impl.saveUserBirthInfo(json, new PlateContract.CallBack<BaziSaveSuccessEntity>() {
|
||||
// @Override
|
||||
// public void success(BaziSaveSuccessEntity bean) {
|
||||
// if(PlatePresenter.this.getView() != null){
|
||||
// if(PlatePresenter.this.getView() != null){
|
||||
// PlatePresenter.this.getView().saveBaziResultSuccess(bean);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void fail(String msg) {
|
||||
// if(PlatePresenter.this.getView() != null){
|
||||
// if(PlatePresenter.this.getView() != null){
|
||||
// PlatePresenter.this.getView().showError(msg);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
// } catch (JSONException e) {
|
||||
// throw new RuntimeException(e);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 获取历史运势
|
||||
// * @param page
|
||||
// */
|
||||
// public void getHistoryDatas(int page) {
|
||||
// Map<String, Object> map = new HashMap<>();
|
||||
// map.put("pageNum", page);
|
||||
// map.put("pageSize", 10);
|
||||
// impl.getPaipanHistoryList(map, new PlateContract.CallBack<PaipanHistoryEntity>() {
|
||||
//
|
||||
// @Override
|
||||
// public void success(PaipanHistoryEntity entity) {
|
||||
// if(PlatePresenter.this.getView() != null){
|
||||
// PlatePresenter.this.getView().getHistorySuccess(entity);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void fail(String msg) {
|
||||
// if(PlatePresenter.this.getView() != null){
|
||||
// PlatePresenter.this.getView().showError(msg);
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 删除记录
|
||||
// * @param id
|
||||
// */
|
||||
// public void deleteRecordByID(String id,int pos) {
|
||||
// Map<String, Object> map = new HashMap<>();
|
||||
// map.put("recordId", id);
|
||||
// impl.deleteRecordByID(map, new PlateContract.CallBack<BaseBean>() {
|
||||
// @Override
|
||||
// public void success(BaseBean bean) {
|
||||
// if(PlatePresenter.this.getView() != null){
|
||||
// PlatePresenter.this.getView().deletePaipanHistorySuccess(pos);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void fail(String msg) {
|
||||
// if(PlatePresenter.this.getView() != null){
|
||||
// PlatePresenter.this.getView().showError(msg);
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * ai 分析八字
|
||||
// * @param mSaveEntity
|
||||
// */
|
||||
// public void AiParseBaziResult(BaziSaveSuccessEntity mSaveEntity) {
|
||||
// try {
|
||||
// JSONObject json = new JSONObject();
|
||||
// json.put("resultId", mSaveEntity.getRecordId());
|
||||
// impl.sendMsgToAi(json, new PlateContract.AiStreamCallback() {
|
||||
// @Override
|
||||
// public void onMessage(String messageChunk) {
|
||||
// if (PlatePresenter.this.getView() != null) {
|
||||
// PlatePresenter.this.getView().onStreamMessageReceived(messageChunk);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onError(String error) {
|
||||
// if (PlatePresenter.this.getView() != null) {
|
||||
// PlatePresenter.this.getView().showError(error);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onComplete(String complateContent) {
|
||||
// if (PlatePresenter.this.getView() != null) {
|
||||
// PlatePresenter.this.getView().onStreamComplete(complateContent);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onSessionReceived(String sessionId) {
|
||||
// // 这个回调在当前场景下可能不需要,但保留接口一致性
|
||||
// // Log.d("PlatePresenter", "Session received: " + sessionId);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void loginLost() {
|
||||
// if (PlatePresenter.this.getView() != null) {
|
||||
// // 处理登录失效的情况
|
||||
// // 这里可以根据需要跳转到登录页面
|
||||
// // Log.w("PlatePresenter", "Login lost");
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
// } catch (JSONException e) {
|
||||
// throw new RuntimeException(e);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * 举报
|
||||
// * @param reason
|
||||
// */
|
||||
// public void commitReport(String reason) {
|
||||
// Map<String, Object> map = new HashMap<>();
|
||||
// map.put("content", reason);
|
||||
// new IndexImpl().commitReport(map, new IndexContract.CallBack<BaseBean>() {
|
||||
// @Override
|
||||
// public void success(BaseBean bean) {
|
||||
// if (PlatePresenter.this.getView() != null) {
|
||||
// PlatePresenter.this.getView().commitReportSuccess(bean);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void fail(String msg) {
|
||||
// if (PlatePresenter.this.getView() != null) {
|
||||
// PlatePresenter.this.getView().showError(msg);
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
//}
|
||||
|
||||
@@ -1,171 +1,170 @@
|
||||
package com.ckkj.water.utils;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
|
||||
import com.ckkj.water.fate.entity.CityDataEntity;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author fengxiaoyang
|
||||
* @date 2025/8/11
|
||||
* @description 城市信息JSON处理工具类
|
||||
*/
|
||||
|
||||
public class YfjJsonHadnlerUtil {
|
||||
|
||||
private static final String TAG = "YfjJsonHadnlerUtil";
|
||||
private static final String CITY_INFO_FILE = "yfj_city_info.json";
|
||||
|
||||
private static JSONObject cityInfoJson = null;
|
||||
|
||||
/**
|
||||
* 初始化城市信息数据
|
||||
* @param context 上下文
|
||||
*/
|
||||
public static void initCityInfo(Context context) {
|
||||
if (cityInfoJson == null) {
|
||||
cityInfoJson = loadCityInfoFromAssets(context);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 从assets文件夹加载城市信息JSON文件
|
||||
* @param context 上下文
|
||||
* @return JSONObject 城市信息数据
|
||||
*/
|
||||
private static JSONObject loadCityInfoFromAssets(Context context) {
|
||||
try {
|
||||
InputStream inputStream = context.getAssets().open(CITY_INFO_FILE);
|
||||
int size = inputStream.available();
|
||||
byte[] buffer = new byte[size];
|
||||
inputStream.read(buffer);
|
||||
inputStream.close();
|
||||
|
||||
String jsonString = new String(buffer, StandardCharsets.UTF_8);
|
||||
return new JSONObject(jsonString);
|
||||
} catch (IOException | JSONException e) {
|
||||
Log.e(TAG, "加载城市信息文件失败: " + e.getMessage());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据城市名称查找匹配的城市信息
|
||||
* @param cityEntity 城市名称,如"济宁市"、"北京市"、"XX地区"
|
||||
* @return 匹配的城市名称,如果找不到则返回空字符串
|
||||
*/
|
||||
public static String findCityByName(CityDataEntity cityEntity) {
|
||||
String cityResult = "";
|
||||
if (cityInfoJson == null) {
|
||||
Log.e(TAG, "城市信息未初始化,请先调用initCityInfo方法");
|
||||
return "";
|
||||
}
|
||||
|
||||
if (cityEntity == null || cityEntity.getCityName().trim().isEmpty()) {
|
||||
return "";
|
||||
}
|
||||
|
||||
try {
|
||||
// 遍历所有省份/直辖市
|
||||
JSONArray provinceNames = cityInfoJson.names();
|
||||
if (provinceNames != null) {
|
||||
for (int i = 0; i < provinceNames.length(); i++) {
|
||||
String provinceName = provinceNames.getString(i);
|
||||
|
||||
// 检查省份名称是否包含城市名称
|
||||
if (cityEntity.getCityName().contains(provinceName) || provinceName.contains(cityEntity.getCityName())) {
|
||||
String proName = provinceName.replace("市","");
|
||||
return proName;
|
||||
}else if(cityEntity.getCityType().equals("特别行政区")){
|
||||
|
||||
}
|
||||
if(cityEntity.getProvinceName().equals(provinceName)){
|
||||
// 获取该省份下的城市列表
|
||||
JSONArray cityList = cityInfoJson.getJSONArray(provinceName);
|
||||
if (cityList != null) {
|
||||
for (int j = 0; j < cityList.length(); j++) {
|
||||
String city = cityList.getString(j);
|
||||
|
||||
// 检查城市名称是否包含城市名称参数,或者城市名称参数是否包含城市名称
|
||||
if ((cityEntity.getCityName().contains(city) || city.contains(cityEntity.getCityName()))
|
||||
&& cityEntity.getProvinceName().equals(provinceName)) {
|
||||
cityResult = city;
|
||||
return cityResult;
|
||||
}else{
|
||||
cityResult = cityEntity.getCapitalCity();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
Log.e(TAG, "解析城市信息失败: " + e.getMessage());
|
||||
}
|
||||
|
||||
return cityResult;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有省份名称
|
||||
* @return 省份名称列表
|
||||
*/
|
||||
public static List<String> getAllProvinces() {
|
||||
List<String> provinces = new ArrayList<>();
|
||||
|
||||
if (cityInfoJson == null) {
|
||||
return provinces;
|
||||
}
|
||||
|
||||
try {
|
||||
JSONArray provinceNames = cityInfoJson.names();
|
||||
if (provinceNames != null) {
|
||||
for (int i = 0; i < provinceNames.length(); i++) {
|
||||
provinces.add(provinceNames.getString(i));
|
||||
}
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
Log.e(TAG, "获取省份列表失败: " + e.getMessage());
|
||||
}
|
||||
|
||||
return provinces;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据省份名称获取该省份下的城市列表
|
||||
* @param provinceName 省份名称
|
||||
* @return 城市列表
|
||||
*/
|
||||
public static List<String> getCitiesByProvince(String provinceName) {
|
||||
List<String> cities = new ArrayList<>();
|
||||
|
||||
if (cityInfoJson == null || provinceName == null || provinceName.trim().isEmpty()) {
|
||||
return cities;
|
||||
}
|
||||
|
||||
try {
|
||||
if (cityInfoJson.has(provinceName)) {
|
||||
JSONArray cityList = cityInfoJson.getJSONArray(provinceName);
|
||||
if (cityList != null) {
|
||||
for (int i = 0; i < cityList.length(); i++) {
|
||||
cities.add(cityList.getString(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
Log.e(TAG, "获取城市列表失败: " + e.getMessage());
|
||||
}
|
||||
|
||||
return cities;
|
||||
}
|
||||
}
|
||||
//package com.ckkj.water.utils;
|
||||
//
|
||||
//import android.content.Context;
|
||||
//import android.util.Log;
|
||||
//
|
||||
//
|
||||
//import org.json.JSONArray;
|
||||
//import org.json.JSONException;
|
||||
//import org.json.JSONObject;
|
||||
//
|
||||
//import java.io.IOException;
|
||||
//import java.io.InputStream;
|
||||
//import java.nio.charset.StandardCharsets;
|
||||
//import java.util.ArrayList;
|
||||
//import java.util.List;
|
||||
//
|
||||
///**
|
||||
// * @author fengxiaoyang
|
||||
// * @date 2025/8/11
|
||||
// * @description 城市信息JSON处理工具类
|
||||
// */
|
||||
//
|
||||
//public class YfjJsonHadnlerUtil {
|
||||
//
|
||||
// private static final String TAG = "YfjJsonHadnlerUtil";
|
||||
// private static final String CITY_INFO_FILE = "yfj_city_info.json";
|
||||
//
|
||||
// private static JSONObject cityInfoJson = null;
|
||||
//
|
||||
// /**
|
||||
// * 初始化城市信息数据
|
||||
// * @param context 上下文
|
||||
// */
|
||||
// public static void initCityInfo(Context context) {
|
||||
// if (cityInfoJson == null) {
|
||||
// cityInfoJson = loadCityInfoFromAssets(context);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 从assets文件夹加载城市信息JSON文件
|
||||
// * @param context 上下文
|
||||
// * @return JSONObject 城市信息数据
|
||||
// */
|
||||
// private static JSONObject loadCityInfoFromAssets(Context context) {
|
||||
// try {
|
||||
// InputStream inputStream = context.getAssets().open(CITY_INFO_FILE);
|
||||
// int size = inputStream.available();
|
||||
// byte[] buffer = new byte[size];
|
||||
// inputStream.read(buffer);
|
||||
// inputStream.close();
|
||||
//
|
||||
// String jsonString = new String(buffer, StandardCharsets.UTF_8);
|
||||
// return new JSONObject(jsonString);
|
||||
// } catch (IOException | JSONException e) {
|
||||
// Log.e(TAG, "加载城市信息文件失败: " + e.getMessage());
|
||||
// return null;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 根据城市名称查找匹配的城市信息
|
||||
// * @param cityEntity 城市名称,如"济宁市"、"北京市"、"XX地区"
|
||||
// * @return 匹配的城市名称,如果找不到则返回空字符串
|
||||
// */
|
||||
// public static String findCityByName(CityDataEntity cityEntity) {
|
||||
// String cityResult = "";
|
||||
// if (cityInfoJson == null) {
|
||||
// Log.e(TAG, "城市信息未初始化,请先调用initCityInfo方法");
|
||||
// return "";
|
||||
// }
|
||||
//
|
||||
// if (cityEntity == null || cityEntity.getCityName().trim().isEmpty()) {
|
||||
// return "";
|
||||
// }
|
||||
//
|
||||
// try {
|
||||
// // 遍历所有省份/直辖市
|
||||
// JSONArray provinceNames = cityInfoJson.names();
|
||||
// if (provinceNames != null) {
|
||||
// for (int i = 0; i < provinceNames.length(); i++) {
|
||||
// String provinceName = provinceNames.getString(i);
|
||||
//
|
||||
// // 检查省份名称是否包含城市名称
|
||||
// if (cityEntity.getCityName().contains(provinceName) || provinceName.contains(cityEntity.getCityName())) {
|
||||
// String proName = provinceName.replace("市","");
|
||||
// return proName;
|
||||
// }else if(cityEntity.getCityType().equals("特别行政区")){
|
||||
//
|
||||
// }
|
||||
// if(cityEntity.getProvinceName().equals(provinceName)){
|
||||
// // 获取该省份下的城市列表
|
||||
// JSONArray cityList = cityInfoJson.getJSONArray(provinceName);
|
||||
// if (cityList != null) {
|
||||
// for (int j = 0; j < cityList.length(); j++) {
|
||||
// String city = cityList.getString(j);
|
||||
//
|
||||
// // 检查城市名称是否包含城市名称参数,或者城市名称参数是否包含城市名称
|
||||
// if ((cityEntity.getCityName().contains(city) || city.contains(cityEntity.getCityName()))
|
||||
// && cityEntity.getProvinceName().equals(provinceName)) {
|
||||
// cityResult = city;
|
||||
// return cityResult;
|
||||
// }else{
|
||||
// cityResult = cityEntity.getCapitalCity();
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// } catch (JSONException e) {
|
||||
// Log.e(TAG, "解析城市信息失败: " + e.getMessage());
|
||||
// }
|
||||
//
|
||||
// return cityResult;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 获取所有省份名称
|
||||
// * @return 省份名称列表
|
||||
// */
|
||||
// public static List<String> getAllProvinces() {
|
||||
// List<String> provinces = new ArrayList<>();
|
||||
//
|
||||
// if (cityInfoJson == null) {
|
||||
// return provinces;
|
||||
// }
|
||||
//
|
||||
// try {
|
||||
// JSONArray provinceNames = cityInfoJson.names();
|
||||
// if (provinceNames != null) {
|
||||
// for (int i = 0; i < provinceNames.length(); i++) {
|
||||
// provinces.add(provinceNames.getString(i));
|
||||
// }
|
||||
// }
|
||||
// } catch (JSONException e) {
|
||||
// Log.e(TAG, "获取省份列表失败: " + e.getMessage());
|
||||
// }
|
||||
//
|
||||
// return provinces;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 根据省份名称获取该省份下的城市列表
|
||||
// * @param provinceName 省份名称
|
||||
// * @return 城市列表
|
||||
// */
|
||||
// public static List<String> getCitiesByProvince(String provinceName) {
|
||||
// List<String> cities = new ArrayList<>();
|
||||
//
|
||||
// if (cityInfoJson == null || provinceName == null || provinceName.trim().isEmpty()) {
|
||||
// return cities;
|
||||
// }
|
||||
//
|
||||
// try {
|
||||
// if (cityInfoJson.has(provinceName)) {
|
||||
// JSONArray cityList = cityInfoJson.getJSONArray(provinceName);
|
||||
// if (cityList != null) {
|
||||
// for (int i = 0; i < cityList.length(); i++) {
|
||||
// cities.add(cityList.getString(i));
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// } catch (JSONException e) {
|
||||
// Log.e(TAG, "获取城市列表失败: " + e.getMessage());
|
||||
// }
|
||||
//
|
||||
// return cities;
|
||||
// }
|
||||
//}
|
||||
|
||||
Reference in New Issue
Block a user