|
|
@@ -0,0 +1,376 @@
|
|
|
+package com.sheep.gamegroup.view.dialog;
|
|
|
+
|
|
|
+import android.app.Activity;
|
|
|
+import android.content.DialogInterface;
|
|
|
+import android.os.Handler;
|
|
|
+import android.os.Message;
|
|
|
+import android.support.v7.app.AlertDialog;
|
|
|
+import android.text.Editable;
|
|
|
+import android.text.TextUtils;
|
|
|
+import android.text.TextWatcher;
|
|
|
+import android.view.LayoutInflater;
|
|
|
+import android.view.View;
|
|
|
+import android.view.ViewGroup;
|
|
|
+import android.widget.AdapterView;
|
|
|
+import android.widget.ArrayAdapter;
|
|
|
+import android.widget.BaseAdapter;
|
|
|
+import android.widget.CheckBox;
|
|
|
+import android.widget.EditText;
|
|
|
+import android.widget.LinearLayout;
|
|
|
+import android.widget.RadioButton;
|
|
|
+import android.widget.RadioGroup;
|
|
|
+import android.widget.Spinner;
|
|
|
+import android.widget.TextView;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.kfzs.duanduan.utils.dlg.ViewFindUtils;
|
|
|
+import com.sheep.gamegroup.model.entity.Agreement;
|
|
|
+import com.sheep.gamegroup.model.entity.BaseMessage;
|
|
|
+import com.sheep.gamegroup.model.entity.GameAccountEntity;
|
|
|
+import com.sheep.gamegroup.model.entity.GridViewEntity;
|
|
|
+import com.sheep.gamegroup.model.util.SheepSubscriber;
|
|
|
+import com.sheep.gamegroup.util.ListUtil;
|
|
|
+import com.sheep.gamegroup.util.MyListview;
|
|
|
+import com.sheep.gamegroup.util.ViewUtil;
|
|
|
+import com.sheep.jiuyan.samllsheep.R;
|
|
|
+import com.sheep.jiuyan.samllsheep.SheepApp;
|
|
|
+import com.sheep.jiuyan.samllsheep.utils.G;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+import rx.android.schedulers.AndroidSchedulers;
|
|
|
+import rx.schedulers.Schedulers;
|
|
|
+
|
|
|
+/**
|
|
|
+ * Created by ljy on 2018/7/10.
|
|
|
+ */
|
|
|
+
|
|
|
+public class DialogAddAccount {
|
|
|
+ private Activity activity;
|
|
|
+
|
|
|
+ private com.sheep.gamegroup.view.adapter.ArrayAdapter baseAdapter;
|
|
|
+ private com.sheep.gamegroup.view.adapter.ArrayAdapter accountAdapter;
|
|
|
+ private List<GameAccountEntity> gameAccountEntity = new ArrayList<>();
|
|
|
+ private ArrayList<Object> gamePlatorEntity = new ArrayList<>();
|
|
|
+ private ArrayList<Object> gameAccountListEntity = new ArrayList<>();
|
|
|
+
|
|
|
+ private int game_type;
|
|
|
+ private int task_id;
|
|
|
+ private String account;
|
|
|
+ private String password;
|
|
|
+ private int task_type;
|
|
|
+ Spinner game_account_game_list_spinner;
|
|
|
+
|
|
|
+ public DialogAddAccount(Activity activity) {
|
|
|
+ this.activity = activity;
|
|
|
+ }
|
|
|
+
|
|
|
+ Handler mHandler = new Handler(){
|
|
|
+ @Override
|
|
|
+ public void handleMessage(Message msg) {
|
|
|
+ super.handleMessage(msg);
|
|
|
+ try {
|
|
|
+ switch (msg.what){
|
|
|
+ case 0:
|
|
|
+ if(game_account_game_list_spinner == null)
|
|
|
+ return;
|
|
|
+
|
|
|
+ game_account_game_list_spinner.setVisibility((Integer) msg.obj);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }catch (Exception e){
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ public void showAddAccount(){
|
|
|
+ if(activity == null)
|
|
|
+ return;
|
|
|
+ platformData();
|
|
|
+ View dialog_parent = View.inflate(activity, R.layout.dialog_parent, null);
|
|
|
+ final AlertDialog dialog = new AlertDialog.Builder(activity, R.style.MyDialogActivityTheme)
|
|
|
+ .setView(dialog_parent)
|
|
|
+ .create();
|
|
|
+ TextView dialog_title = dialog_parent.findViewById(R.id.dialog_title);
|
|
|
+ final View dialog_close = dialog_parent.findViewById(R.id.dialog_close);
|
|
|
+ LinearLayout dialog_center_ll = dialog_parent.findViewById(R.id.dialog_center_ll);
|
|
|
+ View view = LayoutInflater.from(activity).inflate(R.layout.dialog_add_account, dialog_center_ll, true);
|
|
|
+ dialog_title.setText("添加账号");
|
|
|
+
|
|
|
+ TextView sureTv = view.findViewById(R.id.add_sure_tv);
|
|
|
+ final EditText game_account_et = view.findViewById(R.id.game_account_et);
|
|
|
+ final EditText game_pwd_et = view.findViewById(R.id.game_pwd_et);
|
|
|
+ final MyListview game_account_listview = view.findViewById(R.id.game_account_listview);
|
|
|
+
|
|
|
+ accountAdapter = new com.sheep.gamegroup.view.adapter.ArrayAdapter<Object>(activity, R.layout.dialog_item_game_list, gameAccountListEntity){
|
|
|
+ @Override
|
|
|
+ public boolean convert(int position, View convertView, ViewGroup parent, Object item) {
|
|
|
+ final GameAccountEntity gameAccountEntity = (GameAccountEntity) item;
|
|
|
+ final TextView name_tv = ViewFindUtils.find(convertView, R.id.name_tv);
|
|
|
+ name_tv.setText(gameAccountEntity.getTask_name()+"");
|
|
|
+ convertView.setOnClickListener(new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View v) {
|
|
|
+ game_account_et.setText(gameAccountEntity.getTask_name()+"");
|
|
|
+ game_account_listview.setVisibility(View.GONE);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ };
|
|
|
+ game_account_listview.setAdapter(accountAdapter);
|
|
|
+
|
|
|
+ game_account_et.addTextChangedListener(new TextWatcher() {
|
|
|
+ @Override
|
|
|
+ public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onTextChanged(CharSequence s, int start, int before, int count) {
|
|
|
+ if(!TextUtils.isEmpty(s) && s.length() > 4){
|
|
|
+ game_account_listview.setVisibility(View.VISIBLE);
|
|
|
+ intitDataAccountList(s.toString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void afterTextChanged(Editable s) {
|
|
|
+
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ Spinner game_account_plator_spinner = view.findViewById(R.id.game_account_plator_spinner);
|
|
|
+ game_account_game_list_spinner = view.findViewById(R.id.game_account_game_list_spinner);
|
|
|
+
|
|
|
+ final RadioButton conmon_id = view.findViewById(R.id.conmon_id);
|
|
|
+ final RadioButton fixation_id = view.findViewById(R.id.fixation_id);
|
|
|
+ RadioGroup radio_group= view.findViewById(R.id.radio_group);
|
|
|
+ radio_group.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
|
|
|
+ @Override
|
|
|
+ public void onCheckedChanged(RadioGroup group, int checkedId) {
|
|
|
+ // 获取选中的RadioButton的id
|
|
|
+ int id = group.getCheckedRadioButtonId();
|
|
|
+ // 通过id实例化选中的这个RadioButton
|
|
|
+ RadioButton choise = (RadioButton) activity.findViewById(id);
|
|
|
+
|
|
|
+ Message message = new Message();
|
|
|
+ message.what = 0;
|
|
|
+ if(id == R.id.conmon_id){
|
|
|
+ message.obj = View.GONE;
|
|
|
+ game_account_game_list_spinner.setVisibility(View.GONE);
|
|
|
+ }
|
|
|
+ if(id == R.id.fixation_id){
|
|
|
+ message.obj = View.VISIBLE;
|
|
|
+ game_account_game_list_spinner.setVisibility(View.VISIBLE);
|
|
|
+ }
|
|
|
+ mHandler.sendMessage(message);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ /**
|
|
|
+ * 平台列表
|
|
|
+ */
|
|
|
+ game_account_plator_spinner.setAdapter(new com.sheep.gamegroup.view.adapter.ArrayAdapter<Object>(activity, R.layout.dialog_item_game_list, gamePlatorEntity){
|
|
|
+ @Override
|
|
|
+ public boolean convert(int position, View convertView, ViewGroup parent, final Object item) {
|
|
|
+ final GridViewEntity gridViewEntity = (GridViewEntity) item;
|
|
|
+ final TextView name_tv = ViewFindUtils.find(convertView, R.id.name_tv);
|
|
|
+ name_tv.setText(gridViewEntity.getName()+"");
|
|
|
+ convertView.setOnClickListener(new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View view) {
|
|
|
+ task_type = Integer.parseInt(gridViewEntity.getTask_type());
|
|
|
+ }
|
|
|
+ });
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 游戏列表
|
|
|
+ */
|
|
|
+ baseAdapter = new com.sheep.gamegroup.view.adapter.ArrayAdapter<GameAccountEntity>(activity, R.layout.dialog_item_game_list, gameAccountEntity){
|
|
|
+ @Override
|
|
|
+ public boolean convert(int position, View convertView, ViewGroup parent, final GameAccountEntity item) {
|
|
|
+ final TextView name_tv = ViewFindUtils.find(convertView, R.id.name_tv);
|
|
|
+ name_tv.setText(item.getTask_name()+"");
|
|
|
+// convertView.setOnClickListener(new View.OnClickListener() {
|
|
|
+// @Override
|
|
|
+// public void onClick(View view) {
|
|
|
+// task_id = item.getTask_id();
|
|
|
+// task_type = item.getTask_type();
|
|
|
+// }
|
|
|
+// });
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ game_account_game_list_spinner.setAdapter(baseAdapter);
|
|
|
+ game_account_game_list_spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
|
|
+ @Override
|
|
|
+ public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
|
|
+
|
|
|
+ if(game_type < 1) {
|
|
|
+ G.showToast("请选择游戏平台!");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ intitDataGameList(game_type);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onNothingSelected(AdapterView<?> parent) {
|
|
|
+
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 添加账号提交
|
|
|
+ */
|
|
|
+ sureTv.setOnClickListener(new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View v) {
|
|
|
+
|
|
|
+ account = game_account_et.getText().toString().trim();
|
|
|
+ password = game_pwd_et.getText().toString().trim();
|
|
|
+ if(TextUtils.isEmpty(account)){
|
|
|
+ G.showToast("请选择或输入游戏账号");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if(task_type < 1){
|
|
|
+ G.showToast("请选择游戏平台");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
+ jsonObject.put("account",account);
|
|
|
+ jsonObject.put("password",password);
|
|
|
+ jsonObject.put("task_id",task_id);
|
|
|
+ jsonObject.put("task_type",task_type);
|
|
|
+
|
|
|
+ ViewUtil.newInstance().showProgress(activity);
|
|
|
+ SheepApp.getInstance()
|
|
|
+ .getNetComponent()
|
|
|
+ .getApiService()
|
|
|
+ .addGameAccount(jsonObject)
|
|
|
+ .subscribeOn(Schedulers.io())
|
|
|
+ .observeOn(AndroidSchedulers.mainThread())
|
|
|
+ .subscribe(new SheepSubscriber<BaseMessage>(SheepApp.mContext) {
|
|
|
+ @Override
|
|
|
+ public void onError(BaseMessage baseMessage) {
|
|
|
+
|
|
|
+ ViewUtil.newInstance().hideProgress(activity);
|
|
|
+ G.showToast(baseMessage.getMsg()+"");
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onNext(BaseMessage baseMessage) {
|
|
|
+ ViewUtil.newInstance().hideProgress(activity);
|
|
|
+ G.showToast(baseMessage.getMsg()+"");
|
|
|
+
|
|
|
+ dialog.dismiss();
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ dialog_close.setOnClickListener(new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View v) {
|
|
|
+ dialog.dismiss();
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ dialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
|
|
|
+ @Override
|
|
|
+ public void onDismiss(DialogInterface dialogInterface) {
|
|
|
+ }
|
|
|
+ });
|
|
|
+ try {
|
|
|
+ dialog.show();
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 平台数据
|
|
|
+ */
|
|
|
+ private void platformData(){
|
|
|
+ gamePlatorEntity.clear();
|
|
|
+ gamePlatorEntity.add(new GridViewEntity(false, "平台游戏", 1002+""));
|
|
|
+ gamePlatorEntity.add(new GridViewEntity(false, "小米游戏", 1004+""));
|
|
|
+ gamePlatorEntity.add(new GridViewEntity(false, "腾讯游戏", 1003+""));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 游戏任务列表
|
|
|
+ * @param game_type
|
|
|
+ */
|
|
|
+ private void intitDataGameList(int game_type){
|
|
|
+
|
|
|
+ ViewUtil.newInstance().showProgress(activity);
|
|
|
+ SheepApp.getInstance()
|
|
|
+ .getNetComponent()
|
|
|
+ .getApiService()
|
|
|
+ .getGameList(game_type)
|
|
|
+ .subscribeOn(Schedulers.io())
|
|
|
+ .observeOn(AndroidSchedulers.mainThread())
|
|
|
+ .subscribe(new SheepSubscriber<BaseMessage>(SheepApp.mContext) {
|
|
|
+ @Override
|
|
|
+ public void onError(BaseMessage baseMessage) {
|
|
|
+
|
|
|
+ ViewUtil.newInstance().hideProgress(activity);
|
|
|
+ G.showToast(baseMessage.getMsg()+"");
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onNext(BaseMessage baseMessage) {
|
|
|
+ ViewUtil.newInstance().hideProgress(activity);
|
|
|
+ List<GameAccountEntity> gameAccountEntitys = baseMessage.getDatas(GameAccountEntity.class);
|
|
|
+ if(!ListUtil.isEmpty(gameAccountEntitys)){
|
|
|
+ gameAccountEntity.clear();
|
|
|
+ gameAccountEntity.addAll(gameAccountEntitys);
|
|
|
+ if(baseAdapter != null)
|
|
|
+ baseAdapter.notifyDataSetChanged();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ private void intitDataAccountList(String account){
|
|
|
+
|
|
|
+ if(game_type < 1) {
|
|
|
+ G.showToast("请选择游戏平台!");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ ViewUtil.newInstance().showProgress(activity);
|
|
|
+ SheepApp.getInstance()
|
|
|
+ .getNetComponent()
|
|
|
+ .getApiService()
|
|
|
+ .getGameAccountList(game_type, account, task_id)
|
|
|
+ .subscribeOn(Schedulers.io())
|
|
|
+ .observeOn(AndroidSchedulers.mainThread())
|
|
|
+ .subscribe(new SheepSubscriber<BaseMessage>(SheepApp.mContext) {
|
|
|
+ @Override
|
|
|
+ public void onError(BaseMessage baseMessage) {
|
|
|
+
|
|
|
+ ViewUtil.newInstance().hideProgress(activity);
|
|
|
+ G.showToast(baseMessage.getMsg()+"");
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onNext(BaseMessage baseMessage) {
|
|
|
+ ViewUtil.newInstance().hideProgress(activity);
|
|
|
+ List<GameAccountEntity> gameAccountEntitys = baseMessage.getDatas(GameAccountEntity.class);
|
|
|
+ if(!ListUtil.isEmpty(gameAccountEntitys)){
|
|
|
+ gameAccountListEntity.clear();
|
|
|
+ gameAccountListEntity.addAll(gameAccountEntitys);
|
|
|
+ if(accountAdapter != null)
|
|
|
+ accountAdapter.notifyDataSetChanged();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+}
|