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.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 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_delete; private ImageView iv_account_head,cancel; private RecyclerView listview; private LinearLayout add_accunt; 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: data.clear(); data.addAll( (List)msg.obj); childsAdapter.notifyDataSetChanged(); break; } } }; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_account_management); String userID = SaveParam.getInstance().getLoginParam(this,"userId"); try { long auserID = Long.parseLong(userID); HttpManager.getInstance().getchildAccountinfo(this,auserID,handler); } catch (NumberFormatException e) { e.printStackTrace(); } 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); tv_delete = (TextView) findViewById(R.id.tv_account_delete); iv_account_head = (ImageView) findViewById(R.id.tv_account_head); cancel = (ImageView) findViewById(R.id.cancel); add_accunt = (LinearLayout) findViewById(R.id.add_account); listview = (RecyclerView) findViewById(R.id.id_recyclerview_horizontal); } private void initData() { if (Content.changgeaccountflag ==1){ tv_delete.setText("使用中"); tv_delete.setEnabled(true); } 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); usernames.setText(cunt_username); tv_username.setText(tv_usernames); tv_grade.setText(tv_grades); tv_school.setText(tv_schools); tv_adress.setText(tv_adresss); 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); } private void initLister() { changbangding.setOnClickListener(this); changpassword.setOnClickListener(this); tv_delete.setOnClickListener(this); cancel.setOnClickListener(this); add_accunt.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.tv_account_delete: Content.changgeaccountflag =1; SaveParam.getInstance().saveLoginParam(this,SaveParam.ACCOUNT,"1"); break; case R.id.cancel: finish(); break; } } }