MineFragment.java
6.9 KB
1
2
3
4
5
6
7
8
9
10
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
40
41
42
43
44
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
package com.hh.xuetubao.fragment;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.FragmentTransaction;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.bumptech.glide.Glide;
import com.hh.xuetubao.R;
import com.hh.xuetubao.Utils.SharedPrefrenceUtils;
import com.hh.xuetubao.activity.login.LoginActivity;
import com.hh.xuetubao.activity.personal.DeliveryActivity;
import com.hh.xuetubao.activity.personal.InfromationActivity;
import com.hh.xuetubao.activity.personal.MessageActivity;
import com.hh.xuetubao.activity.personal.MoneyActivity;
import com.hh.xuetubao.activity.personal.ResumeActivity;
import com.hh.xuetubao.activity.study.StudyNoteActivity;
import com.hh.xuetubao.bean.UserBean;
import com.hh.xuetubao.model.PersonalModel;
import com.hh.xuetubao.mvp.BaseMvpFragment;
import com.hh.xuetubao.mvp.CommonPresenter;
import com.hh.xuetubao.mvp.ICommonView;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;
/**
* 我的Fragment
*/
public class MineFragment extends BaseMvpFragment<CommonPresenter, PersonalModel> implements ICommonView, View.OnClickListener {
@BindView(R.id.rl_xinxi)
RelativeLayout rlXinxi;
@BindView(R.id.rl_jianli)
RelativeLayout rlJianli;
@BindView(R.id.rl_message)
RelativeLayout rlMessage;
@BindView(R.id.rl_money)
RelativeLayout rlMoney;
@BindView(R.id.rl_study)
RelativeLayout rlStudy;
@BindView(R.id.rl_toudi)
RelativeLayout rlToudi;
Unbinder unbinder;
@BindView(R.id.message_num)
TextView messageNum;
@BindView(R.id.img_user)
ImageView imgUser;
@BindView(R.id.tv_user)
TextView tvUser;
@BindView(R.id.rl_cuoti)
RelativeLayout rlCuoti;
@BindView(R.id.rl_end)
RelativeLayout rlEnd;
private Intent intent;
private FragmentTransaction transaction;
private PraticeWrongFragment wrongFragment;
private String accountOid;
@Override
public int getLayoutId() {
return R.layout.fragment_mine;
}
@Override
public void initView(@Nullable Bundle savedInstanceState) {
accountOid = SharedPrefrenceUtils.getString(getActivity(), "AccountOid");
rlXinxi.setOnClickListener(this);
rlJianli.setOnClickListener(this);
rlMessage.setOnClickListener(this);
rlMoney.setOnClickListener(this);
rlToudi.setOnClickListener(this);
rlStudy.setOnClickListener(this);
rlCuoti.setOnClickListener(this);
rlEnd.setOnClickListener(this);
}
@Override
public void initData() {
PersonalModel model = new PersonalModel();
model.getModel(this, 1, 1, "HeadPic");
model.getModel(this, 1, 2, "CoverPic");
model.getModel(this, 1, 3, accountOid);
model.getModel(this, 2, 1, accountOid);
}
@Override
public CommonPresenter getPresenter() {
return new CommonPresenter();
}
@Override
public PersonalModel getModel() {
return new PersonalModel();
}
@Override
public void getData(Object o, int api, int intent) {
if (api == 1 && intent == 1) {
UserBean bean = (UserBean) o;
String imgUrl = bean.getImgUrl();
SharedPrefrenceUtils.saveString(getActivity(), "HeadPic", imgUrl);
}
if (api == 1 && intent == 2) {
UserBean bean = (UserBean) o;
String imgUrl = bean.getImgUrl();
SharedPrefrenceUtils.saveString(getActivity(), "CoverPic", imgUrl);
}
if (api == 1 && intent == 3) {
UserBean bean = (UserBean) o;
int count = bean.getUnReadCount();
messageNum.setText(String.valueOf(count));
}
if (api == 2 && intent == 1) {
UserBean bean = (UserBean) o;
if (bean.getUserName() != null)
SharedPrefrenceUtils.saveString(getActivity(), "UserName", bean.getUserName());
tvUser.setText(bean.getUserName());
if (bean.getLoginName() != null)
SharedPrefrenceUtils.saveString(getActivity(), "LoginName", bean.getLoginName());
if (bean.getHeadPic() != null && bean.getHeadPic() != "") {
SharedPrefrenceUtils.saveString(getActivity(), "ReallHeader", bean.getHeadPic());
Glide.with(getActivity()).load(bean.getHeadPic()).into(imgUser);
} else {
String headPic = SharedPrefrenceUtils.getString(getActivity(), "HeadPic");
Glide.with(getActivity()).load(headPic).into(imgUser);
}
}
}
@Override
public void onComplete(int api) {
}
@Override
public void onError(Throwable e, int api) {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// TODO: inflate a fragment view
View rootView = super.onCreateView(inflater, container, savedInstanceState);
unbinder = ButterKnife.bind(this, rootView);
return rootView;
}
@Override
public void onDestroyView() {
super.onDestroyView();
unbinder.unbind();
}
@Override
public void onClick(View v) {
transaction = getActivity().getSupportFragmentManager().beginTransaction();
wrongFragment = new PraticeWrongFragment();
switch (v.getId()) {
case R.id.rl_xinxi:
intent = new Intent(getActivity(), InfromationActivity.class);
startActivity(intent);
break;
case R.id.rl_jianli:
intent = new Intent(getActivity(), ResumeActivity.class);
startActivity(intent);
break;
case R.id.rl_message:
intent = new Intent(getActivity(), MessageActivity.class);
startActivity(intent);
break;
case R.id.rl_money:
intent = new Intent(getActivity(), MoneyActivity.class);
startActivity(intent);
break;
case R.id.rl_toudi:
intent = new Intent(getActivity(), DeliveryActivity.class);
startActivity(intent);
break;
case R.id.rl_study:
intent = new Intent(getActivity(), StudyNoteActivity.class);
startActivity(intent);
break;
case R.id.rl_cuoti:
transaction.replace(R.id.frame, wrongFragment);
transaction.commit();
break;
case R.id.rl_end:
SharedPrefrenceUtils.saveString(getActivity(),"AccountOid",null);
startActivity(new Intent(getActivity(), LoginActivity.class));
getActivity().finish();
break;
}
}
}