导航菜单

页面标题

页面副标题

自健身 v3.3.4 - AiCoachActivity.java 源代码

正在查看: 自健身 v3.3.4 应用的 AiCoachActivity.java JAVA 源代码文件

本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。


package com.mu.gymtrain.Activity;

import android.app.Activity;
import android.content.res.Resources;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.blankj.utilcode.util.AdaptScreenUtils;
import com.blankj.utilcode.util.TimeUtils;
import com.githang.statusbar.StatusBarCompat;
import com.hjq.http.EasyHttp;
import com.hjq.http.listener.OnHttpListener;
import com.hjq.http.request.PostRequest;
import com.mu.gymtrain.Adapter.AiMsgAdapter;
import com.mu.gymtrain.Base.BaseActivity;
import com.mu.gymtrain.Bean.AiWelcomeBean;
import com.mu.gymtrain.Bean.MsgBean;
import com.mu.gymtrain.Bean.SendMsgBean;
import com.mu.gymtrain.Http.api.AiWelcomeCoachAPI;
import com.mu.gymtrain.Http.api.SendCoachMsgAPI;
import com.mu.gymtrain.R;
import com.mu.gymtrain.Utils.UrlConfig;
import okhttp3.Call;

public class AiCoachActivity extends BaseActivity {
    private AiMsgAdapter adapter;
    private EditText etContent;
    private View llProgress;
    private RecyclerView recyclerView;
    private String token;

    public int getContentLayout() {
        return R.layout.activity_ai_layout;
    }

    public void initView() {
        StatusBarCompat.setStatusBarColor((Activity) this, getResources().getColor(R.color.orange), false);
        findViewById(R.id.tvSend).setOnClickListener(this);
        findViewById(R.id.tvClear).setOnClickListener(this);
        findViewById(R.id.imgBack).setOnClickListener(this);
        this.etContent = (EditText) findViewById(R.id.etContent);
        this.llProgress = findViewById(R.id.llProgress);
        RecyclerView findViewById = findViewById(2131297022);
        this.recyclerView = findViewById;
        findViewById.setLayoutManager(new LinearLayoutManager(this));
        AiMsgAdapter aiMsgAdapter = new AiMsgAdapter(getStringFromSP(UrlConfig.Params.AVATAR));
        this.adapter = aiMsgAdapter;
        this.recyclerView.setAdapter(aiMsgAdapter);
        this.adapter.bindToRecyclerView(this.recyclerView);
    }

    public void initData() {
        this.token = getToken();
        this.llProgress.setVisibility(0);
        ((PostRequest) EasyHttp.post(this).api(new AiWelcomeCoachAPI(this.token))).request(new OnHttpListener<AiWelcomeBean>() {
            @Override
            public void onEnd(Call call) {
                OnHttpListener.CC.$default$onEnd(this, call);
            }

            @Override
            public void onStart(Call call) {
                OnHttpListener.CC.$default$onStart(this, call);
            }

            @Override
            public void onSucceed(AiWelcomeBean aiWelcomeBean, boolean z) {
                onSucceed((AnonymousClass1) aiWelcomeBean);
            }

            @Override
            public void onSucceed(AiWelcomeBean result) {
                AiCoachActivity.this.llProgress.setVisibility(8);
                MsgBean msgBean = new MsgBean();
                msgBean.setOwner(false);
                msgBean.setMsg(result.getData());
                AiCoachActivity.this.adapter.addData(msgBean);
            }

            @Override
            public void onFail(Exception e) {
                AiCoachActivity.this.llProgress.setVisibility(8);
            }
        });
    }

    public void onClick(View v) {
        int id = v.getId();
        if (id == 2131296609) {
            finish();
        } else if (id == 2131297311) {
            this.adapter.setNewData(null);
        } else {
            if (id != 2131297410) {
                return;
            }
            sendMsg(this.etContent.getText().toString());
        }
    }

    public Resources getResources() {
        return AdaptScreenUtils.adaptWidth(super.getResources(), 750);
    }

    private void sendMsg(String msg) {
        if (TextUtils.isEmpty(msg)) {
            return;
        }
        MsgBean msgBean = new MsgBean();
        msgBean.setOwner(true);
        msgBean.setTime(TimeUtils.getNowString());
        msgBean.setMsg(msg);
        this.adapter.addData(msgBean);
        this.etContent.setText("");
        this.recyclerView.scrollToPosition(this.adapter.getItemCount() - 1);
        this.llProgress.setVisibility(0);
        ((PostRequest) EasyHttp.post(this).api(new SendCoachMsgAPI(msg, this.token))).request(new OnHttpListener<SendMsgBean>() {
            @Override
            public void onEnd(Call call) {
                OnHttpListener.CC.$default$onEnd(this, call);
            }

            @Override
            public void onStart(Call call) {
                OnHttpListener.CC.$default$onStart(this, call);
            }

            @Override
            public void onSucceed(SendMsgBean sendMsgBean, boolean z) {
                onSucceed((AnonymousClass2) sendMsgBean);
            }

            @Override
            public void onSucceed(SendMsgBean result) {
                AiCoachActivity.this.llProgress.setVisibility(8);
                MsgBean msgBean2 = new MsgBean();
                msgBean2.setOwner(false);
                msgBean2.setTime(result.getData().getCreatedAt());
                msgBean2.setMsg(result.getData().getAnswer());
                AiCoachActivity.this.adapter.addData(msgBean2);
                AiCoachActivity.this.recyclerView.scrollToPosition(AiCoachActivity.this.adapter.getItemCount() - 1);
            }

            @Override
            public void onFail(Exception e) {
                AiCoachActivity.this.llProgress.setVisibility(8);
            }
        });
    }
}