我的界面 布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:id="@+id/my_head"
android:layout_width="match_parent"
android:layout_height="170dp"
android:background="@drawable/loginbefore">
<com.facebook.drawee.view.SimpleDraweeView
android:id="@+id/my_icon"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:layout_marginStart="21dp"
app:placeholderImage="@drawable/loginbefore"
app:roundAsCircle="true" />
<TextView
android:id="@+id/my_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:layout_marginStart="104dp"
android:text="登录/注册>"
android:textColor="@color/white" />
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="@+id/my_order"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="我的订单" />
</LinearLayout>
</LinearLayout>
我的界面 代码
public class MyFragment extends Fragment {
@BindView(R.id.my_icon)
SimpleDraweeView myIcon;
@BindView(R.id.my_name)
TextView myName;
@BindView(R.id.my_head)
RelativeLayout myHead;
Unbinder unbinder;
@BindView(R.id.my_order)
Button myOrder;
private SharedPreferences preferences;
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = View.inflate(getActivity(), R.layout.my_fg, null);
unbinder = ButterKnife.bind(this, view);
return view;
}
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
}
private int getIsLogin() {
// SharedPreferences preferences = getActivity().getSharedPreferences("user", 0);
return preferences.getInt("islogin", 0);
}
@Override
public void onDestroyView() {
super.onDestroyView();
unbinder.unbind();
}
@Override
public void onResume() {
super.onResume();
preferences = getActivity().getSharedPreferences("user", 0);
if (getIsLogin() == 1) {
String icon = preferences.getString("icon", "null");
String nickname = preferences.getString("nickname", "null");
myHead.setBackground(getResources().getDrawable(R.drawable.loginafter));
myIcon.setImageURI(Uri.parse(icon));
myName.setText(nickname);
//*****************************************
myHead.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(getActivity(), UserSetActivity.class));
}
});
} else {
myHead.setBackground(getResources().getDrawable(R.drawable.loginbefore));
//设置本地图片
myIcon.setActualImageResource(R.drawable.user);
myName.setText("登录/注册>");
myHead.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(getActivity(), LoginActivity.class));
}
});
}
}
@OnClick(R.id.my_order)
public void onViewClicked() {
startActivity(new Intent(getActivity(), MyOrderActivity.class));
}
}
mvp-moedl-RegisterModel
public class RegisterModel {
public Observable<Register> Register(String name, String pwd) {
return RetrofitUtil.getDefault().create(MyRetrofit.class).getRegister(name, pwd);
}
}
mvp-model-LoginModel
public class LoginModel {
public Observable<Login> login(String name, String pwd) {
return RetrofitUtil.getDefault().create(MyRetrofit.class).getLogin(name, pwd);
}
}
mvp-presenter-RegisterPresenter
public class RegisterPresenter extends BasePresenter<RegisterView> {
private RegisterModel registerModel;
public RegisterPresenter(RegisterView view) {
super(view);
}
@Override
public void initModel() {
registerModel = new RegisterModel();
}
public void register(String name, String pwd){
registerModel.Register(name,pwd)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Observer<Register>() {
@Override
public void onSubscribe(Disposable d) {
compositeDisposable.add(d);
}
@Override
public void onNext(Register register) {
view.onRegisterSuccess(register);
}
@Override
public void onError(Throwable e) {
}
@Override
public void onComplete() {
}
});
}
}
mvp-model-LoginPresenter
public class LoginPresenter extends BasePresenter<LoginView> {
private LoginModel loginModel;
public LoginPresenter(LoginView view) {
super(view);
}
@Override
public void initModel() {
loginModel &#