导航菜单

页面标题

页面副标题

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

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

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


package com.mu.gymtrain.Activity;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.blankj.utilcode.util.AdaptScreenUtils;
import com.blankj.utilcode.util.KeyboardUtils;
import com.blankj.utilcode.util.TimeUtils;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.githang.statusbar.StatusBarCompat;
import com.mu.gymtrain.Adapter.AiVideoMsgAdapter;
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.R;
import com.mu.gymtrain.Utils.UrlConfig;
import com.mu.gymtrain.viewmodel.VideoAiViewModel;

public class VideoAiActivity extends BaseActivity implements BaseQuickAdapter.OnItemChildClickListener {
    private AiVideoMsgAdapter adapter;
    private EditText etContent;
    private LinearLayoutManager linearLayoutManager;
    private View llProgress;
    private String name;
    private RecyclerView recyclerView;
    private String token;
    private int videoId;
    private VideoAiViewModel viewModel;

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

    public void initView() {
        this.videoId = getIntent().getIntExtra("videoId", -1);
        this.name = getIntent().getStringExtra("title");
        ((TextView) findViewById(R.id.tvTitle)).setText(this.name + "专项问答");
        this.viewModel = new VideoAiViewModel();
        StatusBarCompat.setStatusBarColor((Activity) this, getResources().getColor(R.color.orange), false);
        findViewById(R.id.tvSend).setOnClickListener(this);
        findViewById(R.id.imgBack).setOnClickListener(this);
        findViewById(R.id.tvRecord).setOnClickListener(this);
        this.etContent = (EditText) findViewById(R.id.etContent);
        this.llProgress = findViewById(R.id.llProgress);
        this.recyclerView = findViewById(2131297022);
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
        this.linearLayoutManager = linearLayoutManager;
        this.recyclerView.setLayoutManager(linearLayoutManager);
        AiVideoMsgAdapter aiVideoMsgAdapter = new AiVideoMsgAdapter(getStringFromSP(UrlConfig.Params.AVATAR));
        this.adapter = aiVideoMsgAdapter;
        this.recyclerView.setAdapter(aiVideoMsgAdapter);
        this.adapter.bindToRecyclerView(this.recyclerView);
        this.adapter.setOnItemChildClickListener(this);
    }

    public void initData() {
        this.token = getToken();
        this.llProgress.setVisibility(0);
        this.viewModel.getAiWelcomeByVideo(this.token, this.videoId, new VideoAiViewModel.OnAiCallBack<AiWelcomeBean>() {
            @Override
            public void onSuccess(AiWelcomeBean result) {
                VideoAiActivity.this.llProgress.setVisibility(8);
                MsgBean msgBean = new MsgBean();
                msgBean.setOwner(false);
                msgBean.setMsg(result.getData());
                VideoAiActivity.this.adapter.addData(msgBean);
            }

            @Override
            public void onFail(String msg) {
                VideoAiActivity.this.llProgress.setVisibility(8);
            }
        });
    }

    public void onClick(View v) {
        int id = v.getId();
        if (id == 2131296609) {
            finish();
            return;
        }
        if (id != 2131297395) {
            if (id != 2131297410) {
                return;
            }
            sendMsg(this.etContent.getText().toString());
        } else {
            Intent intent = new Intent((Context) this, (Class<?>) MineRequestionsActivity.class);
            intent.putExtra("videoId", this.videoId);
            intent.putExtra("title", this.name);
            startActivity(intent);
        }
    }

    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("");
        KeyboardUtils.hideSoftInput(this.etContent);
        this.linearLayoutManager.scrollToPositionWithOffset(this.adapter.getItemCount() - 1, 0);
        this.llProgress.setVisibility(0);
        this.viewModel.sendMsg(this.token, msg, this.videoId, "", new VideoAiViewModel.OnAiCallBack<SendMsgBean>() {
            @Override
            public void onSuccess(SendMsgBean result) {
                VideoAiActivity.this.llProgress.setVisibility(8);
                MsgBean msgBean2 = new MsgBean();
                msgBean2.setOwner(false);
                msgBean2.setTime(result.getData().getCreatedAt());
                msgBean2.setMsg(result.getData().getAnswer());
                msgBean2.setList(result.getData().getAttachments());
                msgBean2.setMessageId(result.getData().getMessageId());
                VideoAiActivity.this.adapter.addData(msgBean2);
                VideoAiActivity.this.scrollEnd();
            }

            @Override
            public void onFail(String msg2) {
                VideoAiActivity.this.llProgress.setVisibility(8);
            }
        });
    }

    public void scrollEnd() {
        this.recyclerView.postDelayed(new Runnable() {
            @Override
            public void run() {
                VideoAiActivity.this.runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        MsgBean msgBean = new MsgBean();
                        msgBean.setOwner(true);
                        msgBean.setTime(TimeUtils.getNowString());
                        msgBean.setMsg("#G#");
                        VideoAiActivity.this.adapter.addData(msgBean);
                        VideoAiActivity.this.linearLayoutManager.scrollToPositionWithOffset(VideoAiActivity.this.adapter.getItemCount() - 1, 0);
                    }
                });
            }
        }, 300L);
    }

    public void onItemChildClick(BaseQuickAdapter baseQuickAdapter, View view, int i) {
        MsgBean msgBean = (MsgBean) baseQuickAdapter.getItem(i);
        if (view.getId() == 2131296671) {
            if (msgBean.isZan()) {
                return;
            }
            msgBean.setCai(false);
            msgBean.setZan(true);
            this.viewModel.zan(this.token, msgBean.getMessageId());
        } else if (view.getId() == 2131296618) {
            if (msgBean.isCai()) {
                return;
            }
            msgBean.setZan(false);
            msgBean.setCai(true);
            this.viewModel.cai(this.token, msgBean.getMessageId());
        }
        baseQuickAdapter.notifyItemChanged(i);
    }

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