2018-04-10

Android开发实习——蓄电池防盗

主要任务:搭建登录页面和修改密码页面(修改密码功能实现基于ygq的帮忙)。

UI图


屏幕快照 2018-04-10 16.04.41.png

xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">



    

    







屏幕快照 2018-04-10 16.05.36.png


xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="cc.makepower.tt.monitor.ui.setting.PasswordActivity">



    







修改密码功能用到MVP框架附上文章一篇转载自:


屏幕快照 2018-04-10 16.22.48.png

https://www.jianshu.com/p/1f91cfd68d48

PasswordActivity.Java
package cc.makepower.accumulator.ui.setting;

import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import butterknife.BindView;
import cc.makepower.accumulator.R;
import cc.makepower.accumulator.contract.PasswordContract;
import cc.makepower.accumulator.presenter.PasswordPresenter;
import cc.makepower.software.android.Base.APresenter;
import cc.makepower.software.android.Base.BaseActivity;

/**

  • Created by CY on 2018/1/6 0006.
    */

public class PasswordActivity extends BaseActivity implements PasswordContract.View{
@BindView(R.id.toolbar)
Toolbar toolbar;
@BindView(R.id.edit_text_1)
EditText edit_text_1;
@BindView(R.id.edit_text_2)
EditText edit_text_2;
// @BindView(R.id.et_check_password)
// EditText check_password;
@BindView(R.id.btn_put)
Button button;

private PasswordPresenter passwordPresenter;
@Override
protected int getLayoutId() {
    return R.layout.alert_password;
}

@Override
protected void afterInCreate(Bundle savedInstanceState) {
    toolbar.setNavigationOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            finish();
        }
    });
    button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

// finish();

            if (TextUtils.isEmpty(edit_text_1.getText().toString())){
                showToast("密码不能为空");
                return;
            }
            if (TextUtils.isEmpty(edit_text_2.getText().toString())){
                showToast("密码不能为空");
                return;
            }

            click();
        }
    });
}

@Override
protected APresenter injectPresenter() {
    passwordPresenter=new PasswordPresenter(PasswordActivity.this);
    return passwordPresenter;
}

void click(){
passwordPresenter.changePwd(edit_text_1.getText().toString(),edit_text_2.getText().toString());
}

@Override
public void changePwdResult(boolean resu) {

    if (resu){
        finish();
    }else
    showToast("密码修改失败");
}

}

PasswordPresenter.Java
package cc.makepower.accumulator.presenter;

import android.content.Context;

import cc.makepower.accumulator.R;
import cc.makepower.accumulator.contract.PasswordContract;
import cc.makepower.software.android.Base.APresenter;
import cc.makepower.software.android.Beans.PostResult;
import cc.makepower.software.android.Beans.ResultBean;
import cc.makepower.software.android.remote.RestDataSource;
import rx.Observer;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

public class PasswordPresenter extends APresenter{

private RestDataSource restDataSource;
public PasswordPresenter(Context context){

    restDataSource=RestDataSource.getInstance(context);
}


public void changePwd(String oldPwd,String newPwd){
    unSubscribe();
    getView().showProgress(R.string.please_wait);
    subscription=restDataSource.changePwd(newPwd,newPwd)
            .subscribeOn(Schedulers.newThread())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(new Observer() {
                @Override
                public void onCompleted() {
                    getView().hideProgress();
                }
                @Override
                public void onError(Throwable e) {
                    getView().hideProgress();
                    getView().showToast(showError(e));
                    getView().changePwdResult(false);
                }

                @Override
                public void onNext(PostResult postResult) {
                    getView().hideProgress();
                    getView().changePwdResult(postResult.getStatus()==PostResult.status.SUCCESS);
                }
            });
}

}

PasswordContract.Java(接口类文件)
package cc.makepower.accumulator.contract;

import cc.makepower.software.android.Base.BaseView;

public interface PasswordContract {

interface View  extends BaseView{
    void changePwdResult(boolean resu);

}

}

你可能感兴趣的:(2018-04-10)