package com.hjx.personalcenter.activity; import android.content.Intent; import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.view.View; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TextView; import com.facebook.drawee.view.SimpleDraweeView; import com.hjx.personalcenter.R; import com.hjx.personalcenter.adapter.AccountChildsAdapter; import com.hjx.personalcenter.customdialog.RecyclerViewSpaceItem; import com.hjx.personalcenter.db.Content; import com.hjx.personalcenter.db.SaveParam; import com.hjx.personalcenter.http.HttpCode; import com.hjx.personalcenter.http.HttpManager; import com.hjx.personalcenter.model.ChildsInfo; import com.hjx.personalcenter.util.AlertUtils; import com.hjx.personalcenter.util.GetDevicesUtil; import java.util.ArrayList; import java.util.List; /**账户管理 熊巍 * Created by h on 2017/8/12. */ public class AccountManagementActivity extends AppCompatActivity implements View.OnClickListener { private TextView changbangding,changpassword,usernames, tv_username,tv_grade,tv_school,tv_adress,tv_changzhu; private ImageView iv_useing,cancel; private SimpleDraweeView mSimpleDraweeView; private RecyclerView listview; private LinearLayout add_accunt,ll_zhu_backgrangd; private AccountChildsAdapter childsAdapter; private ArrayList data = new ArrayList<>(); Handler handler = new Handler(){ @Override public void handleMessage(Message msg) { super.handleMessage(msg); switch (msg.what){ case HttpCode.CHILDS_SUCESS: String name = null; String grade = null; String school = null; String addr = null; String phote = null; List childList = new ArrayList<>() ; List list = (List)msg.obj ; for (int i = 0; i < list.size(); i++) { int type = list.get(i).getType(); if(type == 1){ name = list.get(i).getName(); grade = list.get(i).getGrade(); school = list.get(i).getSchool(); addr = list.get(i).getRegion(); phote = list.get(i).getImage(); }else if (type == 2){ childList.add(list.get(i)); } } tv_username.setText(name); tv_grade.setText(grade); tv_school.setText(school); tv_adress.setText(addr); data.clear(); data.addAll(childList); childsAdapter.notifyDataSetChanged(); break; } } }; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_account_management); initView(); initData(); initLister(); } private void initView() { changbangding = (TextView) findViewById(R.id.changBangding); changpassword = (TextView) findViewById(R.id.changpassword); usernames = (TextView) findViewById(R.id.cunt_username); tv_username = (TextView) findViewById(R.id.tv_account_name); tv_grade = (TextView) findViewById(R.id.tv_account_grade); tv_school = (TextView) findViewById(R.id.tv_account_school); tv_adress = (TextView) findViewById(R.id.tv_account_adress); mSimpleDraweeView = (SimpleDraweeView) findViewById(R.id.tv_account_head); iv_useing = (ImageView) findViewById(R.id.iv_shiyongzhong); cancel = (ImageView) findViewById(R.id.cancel); add_accunt = (LinearLayout) findViewById(R.id.add_account); ll_zhu_backgrangd = (LinearLayout) findViewById(R.id.ll_zhu_backgrangd); tv_changzhu = (TextView) findViewById(R.id.change_zhu_account); listview = (RecyclerView) findViewById(R.id.id_recyclerview_horizontal); } private void initData() { String cunt_username = SaveParam.getInstance().getLoginParam(this,"username"); String tv_usernames = SaveParam.getInstance().getLoginParam(this,SaveParam.USERNAME); String tv_grades = SaveParam.getInstance().getLoginParam(this,SaveParam.GRADES); String tv_schools = SaveParam.getInstance().getLoginParam(this,SaveParam.SCHOOL); String tv_adresss = SaveParam.getInstance().getLoginParam(this,SaveParam.ADRESS); String account = SaveParam.getInstance().getLoginParam(this,SaveParam.ACCOUNT); usernames.setText(cunt_username); if (account.equals("1")){ tv_changzhu.setText("使用中"); tv_changzhu.setEnabled(false); iv_useing.setVisibility(View.VISIBLE); ll_zhu_backgrangd.setBackgroundResource(R.drawable.corcle_blue_bg); }else { tv_changzhu.setText("切换主账户"); tv_changzhu.setEnabled(true); iv_useing.setVisibility(View.GONE); ll_zhu_backgrangd.setBackgroundResource(R.drawable.corcle_black_bg); } LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this); linearLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL); listview.setLayoutManager(linearLayoutManager); childsAdapter = new AccountChildsAdapter(data,this); listview.addItemDecoration(new RecyclerViewSpaceItem(10)); listview.setAdapter(childsAdapter); childsAdapter.setOnItemClickListener(new AccountChildsAdapter.OnItemClickListener() { @Override public void onItemClick(View view, int position) { AlertUtils.showToast(AccountManagementActivity.this,"你点击了"+data.get(position)); } }); } private void initLister() { changbangding.setOnClickListener(this); changpassword.setOnClickListener(this); cancel.setOnClickListener(this); add_accunt.setOnClickListener(this); tv_changzhu.setOnClickListener(this); } @Override public void onClick(View v) { switch (v.getId()){ case R.id.changBangding: Intent changebangding = new Intent(); changebangding.setClass(AccountManagementActivity.this,ChangeBangDingActivity.class); startActivity(changebangding); overridePendingTransition(R.anim.rightin, R.anim.rightout); break; case R.id.changpassword: Content.authcodeflag = 1; Intent changpwd = new Intent(); changpwd.setClass(AccountManagementActivity.this,ChangePasswordActivity.class); startActivity(changpwd); overridePendingTransition(R.anim.rightin, R.anim.rightout); break; case R.id.add_account: Content.accountflag = 2; Intent account = new Intent(); account.setClass(AccountManagementActivity.this,RegisterInfoActivity.class); startActivity(account); overridePendingTransition(R.anim.rightin, R.anim.rightout); break; case R.id.change_zhu_account: Content.changgeaccountflag =1; String userID = SaveParam.getInstance().getLoginParam(this,"userId"); SaveParam.getInstance().saveLoginParam(this,SaveParam.ACCOUNT,"1"); String devicenumber = GetDevicesUtil.getDevicesInfo(this).getDeviceNumber(); try { long auserID = Long.parseLong(userID); HttpManager.getInstance().Accountinfo(AccountManagementActivity.this,auserID, devicenumber,1); } catch (NumberFormatException e) { e.printStackTrace(); } break; case R.id.cancel: finish(); break; } } @Override protected void onResume() { super.onResume(); String userID = SaveParam.getInstance().getLoginParam(this,"userId"); String devicenumber = GetDevicesUtil.getDevicesInfo(this).getDeviceNumber(); try { long auserID = Long.parseLong(userID); HttpManager.getInstance().getchildAccountinfo(this,auserID,devicenumber,handler); } catch (NumberFormatException e) { e.printStackTrace(); } } }