导航菜单

页面标题

页面副标题

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

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

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


package com.mu.gymtrain.Activity;

import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import butterknife.BindView;
import butterknife.OnClick;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.github.mikephil.charting.utils.Utils;
import com.mu.gymtrain.Activity.PersonPackage.PersonalInfoActivity;
import com.mu.gymtrain.Adapter.AddFriendsListAdapter;
import com.mu.gymtrain.Base.BaseActivity;
import com.mu.gymtrain.Bean.FriendsEntity;
import com.mu.gymtrain.Bean.UserInfoBean;
import com.mu.gymtrain.Dialog.DialogUtils;
import com.mu.gymtrain.Http.CreatMap;
import com.mu.gymtrain.Http.HttpHelper;
import com.mu.gymtrain.Http.ResponseFunc;
import com.mu.gymtrain.R;
import com.mu.gymtrain.Utils.FinalTools;
import com.mu.gymtrain.Utils.ToastUtil;
import com.mu.gymtrain.Utils.ToastUtils;
import com.mu.gymtrain.Utils.ViewUtils;
import rx.Observer;
import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

public class AddFriendsActivity extends BaseActivity implements BaseQuickAdapter.OnItemClickListener {
    private AddFriendsListAdapter adapter;

    @BindView(R.id.etSearch)
    EditText mEtSearch;
    private Dialog mNoInfoDialog;

    @BindView(2131297022)
    RecyclerView mRecyclerView;

    @BindView(R.id.title_left)
    ImageView mTitleLeft;

    @BindView(R.id.title_middle)
    TextView mTitleMiddle;

    @BindView(R.id.tvSearch)
    TextView mTvSearch;
    private String searchValue;

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

    public void initData() {
    }

    public void initView() {
        this.mTitleMiddle.setText("添加好友");
        this.mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
        AddFriendsListAdapter addFriendsListAdapter = new AddFriendsListAdapter();
        this.adapter = addFriendsListAdapter;
        this.mRecyclerView.setAdapter(addFriendsListAdapter);
        this.adapter.setOnItemClickListener(this);
    }

    @OnClick({R.id.title_left, R.id.tvSearch})
    public void onViewClicked(View view) {
        int id = view.getId();
        if (id == 2131297253) {
            finish();
            return;
        }
        if (id != 2131297407) {
            return;
        }
        InputMethodManager inputMethodManager = (InputMethodManager) getSystemService("input_method");
        if (inputMethodManager != null) {
            inputMethodManager.hideSoftInputFromWindow(this.mEtSearch.getWindowToken(), 0);
        }
        String obj = this.mEtSearch.getText().toString();
        this.searchValue = obj;
        if (TextUtils.isEmpty(obj)) {
            return;
        }
        request();
    }

    public void onClick(View v) {
        super.onClick(v);
        if (v.getId() != 2131297339) {
            return;
        }
        this.mNoInfoDialog.dismiss();
        startActivity(new Intent((Context) this, (Class<?>) PersonalInfoActivity.class));
    }

    private void request() {
        ViewUtils.showLoading(this, "搜索中...");
        HttpHelper.getInstance().getRetrofitService(this).searchFriend(getToken(), this.searchValue).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Observer<FriendsEntity>() {
            public void onCompleted() {
            }

            public void onError(Throwable e) {
                ViewUtils.hideLoading();
                ToastUtils.show(AddFriendsActivity.this, e.getMessage());
            }

            public void onNext(FriendsEntity friendsEntity) {
                ViewUtils.hideLoading();
                AddFriendsActivity.this.adapter.setNewData(friendsEntity.data);
            }
        });
    }

    public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
        getUserInfo(((FriendsEntity.UserInfo) adapter.getData().get(position)).user_id);
    }

    private void getUserInfo(final String userId) {
        ViewUtils.showLoading(this, "加载中...");
        HttpHelper.getInstance().getRetrofitService(this).getUserInfo(new CreatMap.Builder().build().getParam()).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).map(new ResponseFunc()).subscribe(new Subscriber<UserInfoBean>() {
            public void onCompleted() {
            }

            public void onError(Throwable e) {
                ViewUtils.hideLoading();
                ToastUtil.showShort((Context) AddFriendsActivity.this, (CharSequence) "获取个人信息失败!");
            }

            public void onNext(UserInfoBean userInfoBean) {
                ViewUtils.hideLoading();
                if (userInfoBean.getHeight() == Utils.DOUBLE_EPSILON || userInfoBean.getAge() == 0 || TextUtils.isEmpty(userInfoBean.getUser_name())) {
                    AddFriendsActivity.this.noInfoDialog();
                    return;
                }
                Intent intent = new Intent((Context) AddFriendsActivity.this, (Class<?>) FriendInfoActivity.class);
                intent.putExtra(FinalTools.USER_ID, userId);
                AddFriendsActivity.this.startActivity(intent);
            }
        });
    }

    public void noInfoDialog() {
        View inflate = View.inflate(this, R.layout.dialog_weight_no_info_layout, null);
        ((TextView) inflate.findViewById(2131297190)).setText("请您完善个人资料再添加好友。");
        this.mNoInfoDialog = DialogUtils.createDialog(this, inflate);
        inflate.findViewById(R.id.tvInput).setOnClickListener(this);
        this.mNoInfoDialog.setCanceledOnTouchOutside(true);
        this.mNoInfoDialog.show();
    }
}