PersonalDesActivity.java 3.09 KB
Newer Older
ydl committed
1 2 3 4 5 6 7 8 9
package com.yidianling.user.mine;

import android.annotation.SuppressLint;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.ydl.ydlcommon.base.BaseActivity;
10
import com.ydl.ydlcommon.bean.StatusBarOptions;
ydl committed
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
import com.ydl.ydlcommon.data.http.RxUtils;
import com.ydl.ydlcommon.data.http.ThrowableConsumer;
import com.ydl.ydlcommon.modular.ModularServiceManager;
import com.ydl.ydlcommon.utils.remind.ToastHelper;
import com.yidianling.common.tools.ToastUtil;
import com.yidianling.im.api.service.IImService;
import com.yidianling.user.R;
import com.yidianling.user.UserHelper;
import com.yidianling.user.http.UserHttp;
import com.yidianling.user.http.UserHttpImpl;
import com.yidianling.user.http.request.UserInfoParam;

import org.jetbrains.annotations.NotNull;

import io.reactivex.android.schedulers.AndroidSchedulers;


/**
 * 个人资料--个人简介
 * Created by hgw on 2017/3/24.
 */

public class PersonalDesActivity extends BaseActivity {

    ImageView imageBack;
    TextView tvCenterTitle;
    TextView textSave;
    RelativeLayout relaToolBar;
    EditText editDes;
40 41 42 43 44
    @NotNull
    @Override
    public StatusBarOptions getStatusViewOptions() {
        return new StatusBarOptions(true,true);
    }
ydl committed
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
    @Override
    protected int layoutResId() {
        return R.layout.user_mine_activity_personal_des;
    }

    @Override
    protected void initDataAndEvent() {
        imageBack = findViewById(R.id.image_back);
        tvCenterTitle = findViewById(R.id.tv_center_title);
        editDes = findViewById(R.id.edit_des);
        textSave = findViewById(R.id.text_save);
        imageBack.setOnClickListener(v -> {
            finish();
        });
        textSave.setOnClickListener(v -> {
            updateInfo("home_desc", editDes.getText().toString());
        });
        init();
    }


    private void init() {
        String desc = "";
        try {
            desc = ModularServiceManager.INSTANCE.provide(IImService.class).getUserInfoDescription();
        } catch (Exception e) {}
        editDes.setText(desc);
    }

    @SuppressLint("CheckResult")
    private void updateInfo(final String changType, final String value) {
        showProgressDialog("保存中");
        UserHttp userHttp = UserHttpImpl.Companion.getInstance();
        userHttp.setUserInfo(new UserInfoParam(changType, value))
                .filter(objectBaseResponse -> changType.equals("home_desc"))
                .compose(RxUtils.resultData())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(o -> {
                    dismissProgressDialog();
                    UserHelper.INSTANCE.getUserInfo().getUserInfo().setDescription(value);
                    ToastUtil.toastShort("保存成功");
                    finish();
                }, new ThrowableConsumer() {
                    @Override
                    public void accept(@NotNull String msg) {
                        dismissProgressDialog();
                        ToastHelper.Companion.show(msg);
                    }
                });
    }
}