导航菜单

页面标题

页面副标题

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

正在查看: 自健身 v3.3.4 应用的 FamilyAccountMainActivity.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.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.EditText;
import android.widget.TextView;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import butterknife.BindView;
import butterknife.OnClick;
import com.blankj.utilcode.util.LogUtils;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.mu.gymtrain.Adapter.FamilyAccountMainAdapter;
import com.mu.gymtrain.Base.BaseActivity;
import com.mu.gymtrain.Bean.FriendsEntity;
import com.mu.gymtrain.Bean.SucessBean;
import com.mu.gymtrain.Http.HttpHelper;
import com.mu.gymtrain.R;
import com.mu.gymtrain.Utils.FinalTools;
import com.mu.gymtrain.Utils.JsonUtil;
import com.mu.gymtrain.Utils.PreferenceUtils;
import com.mu.gymtrain.Utils.ToastUtils;
import com.mu.gymtrain.Utils.ViewUtils;
import com.mu.gymtrain.Utils.WindowUtils;
import java.io.IOException;
import okhttp3.ResponseBody;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import rx.Observer;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

public class FamilyAccountMainActivity extends BaseActivity implements BaseQuickAdapter.OnItemClickListener {
    private FamilyAccountMainAdapter adapter;
    private Dialog dialog;
    private int dialogFlag;

    @BindView(R.id.etSearch)
    EditText mEtSearch;

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

    @BindView(R.id.tvRight)
    TextView mTvRight;

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

    @BindView(2131297022)
    RecyclerView recyclerView;

    @BindView(R.id.tVBalance)
    TextView tVBalance;
    private TextView tvAccount;
    private TextView tvCancelDialog;
    private TextView tvDialogContent;
    private TextView tvNickname;
    private String userId;
    private String userName;
    private final int DISBAND_ACCOUNT_FLAG = 1;
    private final int INVITE_JOIN = 2;
    private final int ADD_FRIEND = 3;

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

    public void initView() {
        String string = PreferenceUtils.getInstance().getString("userName", "");
        this.mTitle.setText(string + "的家庭账户");
        this.recyclerView.setLayoutManager(new LinearLayoutManager(this));
        FamilyAccountMainAdapter familyAccountMainAdapter = new FamilyAccountMainAdapter();
        this.adapter = familyAccountMainAdapter;
        this.recyclerView.setAdapter(familyAccountMainAdapter);
        this.adapter.setOnItemClickListener(this);
        initDialog();
    }

    private void initDialog() {
        View inflate = LayoutInflater.from(this).inflate(R.layout.dialog_add_family_member_layout, (ViewGroup) null, false);
        Dialog dialog = new Dialog(this, R.style.progress_dialog);
        this.dialog = dialog;
        dialog.setContentView(inflate);
        Window window = this.dialog.getWindow();
        WindowManager.LayoutParams attributes = window.getAttributes();
        double wIndowWidth = WindowUtils.getWIndowWidth(this);
        Double.isNaN(wIndowWidth);
        attributes.width = (int) (wIndowWidth * 0.7d);
        attributes.height = -2;
        window.setGravity(17);
        TextView textView = (TextView) inflate.findViewById(R.id.tvSure);
        this.tvAccount = (TextView) inflate.findViewById(R.id.tvAccount);
        this.tvNickname = (TextView) inflate.findViewById(R.id.tvNickname);
        this.tvDialogContent = (TextView) inflate.findViewById(2131297190);
        this.tvCancelDialog = (TextView) inflate.findViewById(R.id.tvCancel);
        textView.setOnClickListener(this);
        this.tvCancelDialog.setOnClickListener(this);
        this.dialog.setCanceledOnTouchOutside(false);
    }

    public void initData() {
        String string = PreferenceUtils.getInstance().getString("money", "");
        this.tVBalance.setText("总余额:" + string);
        initRightBtn();
    }

    public void initRightBtn() {
        this.mTvRight.setBackgroundResource(R.drawable.shape_btn_family_organe);
        this.mTvRight.setClickable(true);
    }

    public void onClick(View v) {
        int id = v.getId();
        if (id == 2131297300) {
            this.dialog.dismiss();
            return;
        }
        if (id != 2131297421) {
            return;
        }
        this.dialog.dismiss();
        int i = this.dialogFlag;
        if (i == 1) {
            disbandAccount();
        } else {
            if (i != 2) {
                return;
            }
            join();
        }
    }

    private void join() {
        ViewUtils.showLoading(this, "加载中...");
        HttpHelper.getInstance().getRetrofitService(this).joinFamily(getToken(), this.userId).enqueue(new Callback<ResponseBody>() {
            @Override
            public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
                ViewUtils.hideLoading();
                ResponseBody responseBody = (ResponseBody) response.body();
                if (responseBody != null) {
                    try {
                        String string = responseBody.string();
                        LogUtils.i(new Object[]{string});
                        SucessBean sucessBean = (SucessBean) JsonUtil.json2Bean(string, SucessBean.class);
                        int i = sucessBean.code;
                        if (i == 10000) {
                            ToastUtils.show(FamilyAccountMainActivity.this, "邀请成功,等待对付确认");
                        } else {
                            if (i != 20000 && i != 30000 && i != 30010) {
                                switch (i) {
                                    case 30021:
                                        FamilyAccountMainActivity.this.dialogFlag = -1;
                                        FamilyAccountMainActivity.this.tvAccount.setVisibility(0);
                                        FamilyAccountMainActivity.this.tvNickname.setVisibility(0);
                                        FamilyAccountMainActivity.this.tvCancelDialog.setVisibility(8);
                                        FamilyAccountMainActivity.this.tvAccount.setText("账号: " + FamilyAccountMainActivity.this.phoneNumber);
                                        FamilyAccountMainActivity.this.tvNickname.setText("昵称: " + FamilyAccountMainActivity.this.userName);
                                        FamilyAccountMainActivity.this.tvDialogContent.setText(FamilyAccountMainActivity.this.userName + "已经有家庭账户了");
                                        FamilyAccountMainActivity.this.dialog.show();
                                        break;
                                    case 30025:
                                        FamilyAccountMainActivity.this.showAddFriendDialog();
                                        break;
                                }
                            }
                            ToastUtils.show(FamilyAccountMainActivity.this, sucessBean.message);
                        }
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }

            @Override
            public void onFailure(Call<ResponseBody> call, Throwable t) {
                ViewUtils.hideLoading();
                LogUtils.i(new Object[]{t.getMessage()});
                ToastUtils.show(FamilyAccountMainActivity.this, t.getMessage());
            }
        });
    }

    public void showAddFriendDialog() {
        this.dialogFlag = 3;
        this.tvAccount.setVisibility(0);
        this.tvNickname.setVisibility(0);
        this.tvAccount.setText("账号: " + this.phoneNumber);
        this.tvNickname.setText("昵称: " + this.userName);
        this.tvDialogContent.setText("他不是您的好友\n请先添加好友后操作");
        this.tvCancelDialog.setVisibility(8);
        this.dialog.show();
    }

    @OnClick({R.id.title_left, R.id.tvRight, R.id.tvSearch})
    public void onViewClicked(View view) {
        int id = view.getId();
        if (id == 2131297253) {
            finish();
            return;
        }
        if (id == 2131297402) {
            showDisbandDialog();
            return;
        }
        if (id != 2131297407) {
            return;
        }
        String obj = this.mEtSearch.getText().toString();
        this.phoneNumber = obj;
        if (TextUtils.isEmpty(obj) || this.phoneNumber.length() != 11) {
            ToastUtils.show(this, "请输入正确的手机号");
        } else if (PreferenceUtils.getInstance().getString(FinalTools.PHONE, "").equals(this.phoneNumber)) {
            ToastUtils.show(this, "不能添加自己");
        } else {
            queryAccount();
        }
    }

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

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

            public void onNext(FriendsEntity friendsEntity) {
                ViewUtils.hideLoading();
                if (friendsEntity.data != null && friendsEntity.data.size() > 0) {
                    FriendsEntity.UserInfo userInfo = friendsEntity.data.get(0);
                    FamilyAccountMainActivity.this.userName = userInfo.user_name;
                    FamilyAccountMainActivity.this.userId = userInfo.user_id;
                    FamilyAccountMainActivity.this.showDialog();
                    return;
                }
                ToastUtils.show(FamilyAccountMainActivity.this, "没有查询到该账号");
            }
        });
    }

    private void showDisbandDialog() {
        this.dialogFlag = 1;
        this.tvAccount.setVisibility(8);
        this.tvNickname.setVisibility(8);
        this.tvCancelDialog.setVisibility(0);
        this.tvDialogContent.setText("是否解散家庭账户\n解散后余额将退回您的账号");
        this.dialog.show();
    }

    private void disbandAccount() {
        ViewUtils.showLoading(this, "加载中...");
        HttpHelper.getInstance().getRetrofitService(this).disbandAccount(getToken()).enqueue(new Callback<ResponseBody>() {
            @Override
            public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
                ViewUtils.hideLoading();
                ResponseBody responseBody = (ResponseBody) response.body();
                if (responseBody != null) {
                    try {
                        SucessBean sucessBean = (SucessBean) JsonUtil.json2Bean(responseBody.string(), SucessBean.class);
                        if (sucessBean.code == 10000) {
                            ToastUtils.show(FamilyAccountMainActivity.this, "解散成功");
                            FamilyAccountMainActivity.this.finish();
                        } else {
                            ToastUtils.show(FamilyAccountMainActivity.this, sucessBean.message);
                        }
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }

            @Override
            public void onFailure(Call<ResponseBody> call, Throwable t) {
                ViewUtils.hideLoading();
                LogUtils.i(new Object[]{t.getMessage()});
                ToastUtils.show(FamilyAccountMainActivity.this, t.getMessage());
            }
        });
    }

    public void showDialog() {
        this.dialogFlag = 2;
        this.tvAccount.setVisibility(0);
        this.tvNickname.setVisibility(0);
        this.tvCancelDialog.setVisibility(0);
        this.tvAccount.setText("账号: " + this.phoneNumber);
        this.tvNickname.setText("昵称: " + this.userName);
        this.tvDialogContent.setText("是否添加为家庭成员\n他将使用您的账号消费");
        this.dialog.show();
    }

    public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
        Intent intent = new Intent((Context) this, (Class<?>) FamilyMemberActivity.class);
        intent.putExtra(FinalTools.USER_ID, "");
        intent.putExtra("from", "main");
        startActivity(intent);
    }
}