|
@@ -1,31 +1,32 @@
|
|
package com.yyrh.core.impl.login.fragment;
|
|
package com.yyrh.core.impl.login.fragment;
|
|
|
|
|
|
|
|
+import android.graphics.Color;
|
|
import android.os.Bundle;
|
|
import android.os.Bundle;
|
|
import android.support.annotation.Nullable;
|
|
import android.support.annotation.Nullable;
|
|
import android.support.v4.app.Fragment;
|
|
import android.support.v4.app.Fragment;
|
|
import android.text.InputType;
|
|
import android.text.InputType;
|
|
import android.text.TextUtils;
|
|
import android.text.TextUtils;
|
|
|
|
+import android.view.Gravity;
|
|
import android.view.LayoutInflater;
|
|
import android.view.LayoutInflater;
|
|
import android.view.View;
|
|
import android.view.View;
|
|
import android.view.ViewGroup;
|
|
import android.view.ViewGroup;
|
|
import android.widget.Button;
|
|
import android.widget.Button;
|
|
import android.widget.ImageView;
|
|
import android.widget.ImageView;
|
|
|
|
+import android.widget.LinearLayout;
|
|
|
|
+import android.widget.RelativeLayout;
|
|
|
|
+import android.widget.ScrollView;
|
|
import android.widget.TextView;
|
|
import android.widget.TextView;
|
|
|
|
|
|
import com.yyrh.core.entity.ClickType;
|
|
import com.yyrh.core.entity.ClickType;
|
|
-import com.yyrh.core.entity.ResultInfo;
|
|
|
|
import com.yyrh.core.entity.Session;
|
|
import com.yyrh.core.entity.Session;
|
|
import com.yyrh.core.impl.login.LoginActivity;
|
|
import com.yyrh.core.impl.login.LoginActivity;
|
|
import com.yyrh.core.impl.login.LoginFragmentTag;
|
|
import com.yyrh.core.impl.login.LoginFragmentTag;
|
|
-import com.yyrh.core.internal.IRequestCallback;
|
|
|
|
-import com.yyrh.core.network.SdkRequest;
|
|
|
|
import com.yyrh.factory.SdkManager;
|
|
import com.yyrh.factory.SdkManager;
|
|
import com.yyrh.ui.dialog.TipsToast;
|
|
import com.yyrh.ui.dialog.TipsToast;
|
|
import com.yyrh.ui.widget.EventEditText;
|
|
import com.yyrh.ui.widget.EventEditText;
|
|
import com.yyrh.utils.SessionUtils;
|
|
import com.yyrh.utils.SessionUtils;
|
|
|
|
|
|
-import org.json.JSONException;
|
|
|
|
-import org.json.JSONObject;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
|
|
import cn.yyxx.support.ResUtils;
|
|
import cn.yyxx.support.ResUtils;
|
|
|
|
|
|
@@ -36,12 +37,17 @@ import cn.yyxx.support.ResUtils;
|
|
public class AccountLauncherFragment extends Fragment implements View.OnClickListener {
|
|
public class AccountLauncherFragment extends Fragment implements View.OnClickListener {
|
|
|
|
|
|
private View view;
|
|
private View view;
|
|
|
|
+ private LayoutInflater mInflater;
|
|
private LoginActivity loginImpl;
|
|
private LoginActivity loginImpl;
|
|
private EventEditText eetAccount, eetPwd;
|
|
private EventEditText eetAccount, eetPwd;
|
|
private Button btnLauncher, btnRegister;
|
|
private Button btnLauncher, btnRegister;
|
|
private ImageView ivCheck;
|
|
private ImageView ivCheck;
|
|
private TextView tvAgreement, tvPrivacy;
|
|
private TextView tvAgreement, tvPrivacy;
|
|
- private int imgCheck, imgUncheck, imgShow, imgHide;
|
|
|
|
|
|
+ private int imgCheck, imgUncheck, imgShow, imgHide, imgUp, imgDown;
|
|
|
|
+ private RelativeLayout rlAccountList;
|
|
|
|
+ private ScrollView svAccountList;
|
|
|
|
+ private LinearLayout llAccountList;
|
|
|
|
+ private ArrayList<Session> userList = new ArrayList<>();
|
|
private boolean check = false;
|
|
private boolean check = false;
|
|
private boolean showText = false;
|
|
private boolean showText = false;
|
|
|
|
|
|
@@ -50,6 +56,7 @@ public class AccountLauncherFragment extends Fragment implements View.OnClickLis
|
|
@Override
|
|
@Override
|
|
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
|
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
|
super.onCreateView(inflater, container, savedInstanceState);
|
|
super.onCreateView(inflater, container, savedInstanceState);
|
|
|
|
+ this.mInflater = inflater;
|
|
if (getActivity() instanceof LoginActivity) {
|
|
if (getActivity() instanceof LoginActivity) {
|
|
loginImpl = (LoginActivity) getActivity();
|
|
loginImpl = (LoginActivity) getActivity();
|
|
}
|
|
}
|
|
@@ -66,12 +73,22 @@ public class AccountLauncherFragment extends Fragment implements View.OnClickLis
|
|
imgUncheck = ResUtils.getResId(getActivity(), "hnyy_uncheck_img", "drawable");
|
|
imgUncheck = ResUtils.getResId(getActivity(), "hnyy_uncheck_img", "drawable");
|
|
imgShow = ResUtils.getResId(getActivity(), "hnyy_show_img", "drawable");
|
|
imgShow = ResUtils.getResId(getActivity(), "hnyy_show_img", "drawable");
|
|
imgHide = ResUtils.getResId(getActivity(), "hnyy_hide_img", "drawable");
|
|
imgHide = ResUtils.getResId(getActivity(), "hnyy_hide_img", "drawable");
|
|
|
|
+ imgUp = ResUtils.getResId(getActivity(), "hnyy_pick_up_img", "drawable");
|
|
|
|
+ imgDown = ResUtils.getResId(getActivity(), "hnyy_pick_down_img", "drawable");
|
|
|
|
+
|
|
|
|
|
|
eetAccount = view.findViewById(ResUtils.getResId(getActivity(), "hnyy_eet_account", "id"));
|
|
eetAccount = view.findViewById(ResUtils.getResId(getActivity(), "hnyy_eet_account", "id"));
|
|
eetAccount.getLeftImageView().setBackgroundResource(ResUtils.getResId(getActivity(), "hnyy_account_img", "drawable"));
|
|
eetAccount.getLeftImageView().setBackgroundResource(ResUtils.getResId(getActivity(), "hnyy_account_img", "drawable"));
|
|
eetAccount.getLeftImageView().setVisibility(View.VISIBLE);
|
|
eetAccount.getLeftImageView().setVisibility(View.VISIBLE);
|
|
eetAccount.getEditText().setHint("请输入账号");
|
|
eetAccount.getEditText().setHint("请输入账号");
|
|
eetAccount.getEditText().setText("test1231");
|
|
eetAccount.getEditText().setText("test1231");
|
|
|
|
+ eetAccount.getRightImageView().setBackgroundResource(imgDown);
|
|
|
|
+ eetAccount.getRightImageView().setOnClickListener(new View.OnClickListener() {
|
|
|
|
+ @Override
|
|
|
|
+ public void onClick(View v) {
|
|
|
|
+ changeAccountList();
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
|
|
eetPwd = view.findViewById(ResUtils.getResId(getActivity(), "hnyy_eet_pwd", "id"));
|
|
eetPwd = view.findViewById(ResUtils.getResId(getActivity(), "hnyy_eet_pwd", "id"));
|
|
eetPwd.getLeftImageView().setBackgroundResource(ResUtils.getResId(getActivity(), "hnyy_pwd_img", "drawable"));
|
|
eetPwd.getLeftImageView().setBackgroundResource(ResUtils.getResId(getActivity(), "hnyy_pwd_img", "drawable"));
|
|
@@ -117,8 +134,109 @@ public class AccountLauncherFragment extends Fragment implements View.OnClickLis
|
|
tvPrivacy.setOnClickListener(this);
|
|
tvPrivacy.setOnClickListener(this);
|
|
tvPrivacy.setTag(ClickType.ACTION_PRIVACY);
|
|
tvPrivacy.setTag(ClickType.ACTION_PRIVACY);
|
|
|
|
|
|
|
|
+ rlAccountList = view.findViewById(ResUtils.getResId(getActivity(), "hnyy_rl_account_list", "id"));
|
|
|
|
+ svAccountList = view.findViewById(ResUtils.getResId(getActivity(), "hnyy_sv_account_list", "id"));
|
|
|
|
+ llAccountList = view.findViewById(ResUtils.getResId(getActivity(), "hnyy_ll_account_list", "id"));
|
|
|
|
+ rlAccountList.setVisibility(View.GONE);
|
|
|
|
+
|
|
|
|
+ autoFillAccountInfo();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void autoFillAccountInfo() {
|
|
|
|
+ ArrayList<Session> temp = SessionUtils.getInstance().getLocalSessionLimit3();
|
|
|
|
+ if (temp == null || temp.size() == 0) {
|
|
|
|
+ eetAccount.getRightImageView().setVisibility(View.GONE);
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ for (Session session : temp) {
|
|
|
|
+ if (userList == null) {
|
|
|
|
+ userList = new ArrayList<>();
|
|
|
|
+ }
|
|
|
|
+ userList.add(session);
|
|
|
|
+ }
|
|
|
|
+ if (userList != null && userList.size() > 0) {
|
|
|
|
+ Session session = userList.get(0);
|
|
|
|
+ if (session != null) {
|
|
|
|
+ eetAccount.getEditText().setText(session.userName);
|
|
|
|
+ eetPwd.getEditText().setText(session.pwd);
|
|
|
|
+ }
|
|
|
|
+ if (userList.size() > 1) {
|
|
|
|
+ initAccountList();
|
|
|
|
+ eetAccount.getRightImageView().setVisibility(View.VISIBLE);
|
|
|
|
+ } else {
|
|
|
|
+ eetAccount.getRightImageView().setVisibility(View.GONE);
|
|
|
|
+ rlAccountList.setVisibility(View.GONE);
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ eetAccount.getRightImageView().setVisibility(View.GONE);
|
|
|
|
+ rlAccountList.setVisibility(View.GONE);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void initAccountList() {
|
|
|
|
+ llAccountList.removeAllViews();
|
|
|
|
+ // 单行高
|
|
|
|
+ int height = 100;
|
|
|
|
+ if (eetAccount.getLayoutParams().height != -1 || eetAccount.getLayoutParams().height != 0) {
|
|
|
|
+ height = eetAccount.getLayoutParams().height;
|
|
|
|
+ }
|
|
|
|
+ // ScrollView最大高度
|
|
|
|
+ int maxHeight = 0;
|
|
|
|
+ if (userList != null && userList.size() > 0) {
|
|
|
|
+ if (userList.size() < 3) {
|
|
|
|
+ maxHeight = userList.size() * height;
|
|
|
|
+ } else {
|
|
|
|
+ maxHeight = (userList.size() - 1) * height;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 循环添加列
|
|
|
|
+ for (int i = 0; i < userList.size(); i++) {
|
|
|
|
+ Session session = userList.get(i);
|
|
|
|
+ // 添加列线
|
|
|
|
+ LinearLayout.LayoutParams lineParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 2);
|
|
|
|
+ View line = new View(getActivity());
|
|
|
|
+ line.setLayoutParams(lineParams);
|
|
|
|
+ line.setBackgroundColor(Color.parseColor("#4D505050"));
|
|
|
|
+ if (llAccountList.getChildCount() > 0) {
|
|
|
|
+ llAccountList.addView(line);
|
|
|
|
+ }
|
|
|
|
+ // 添加账号
|
|
|
|
+ View view = mInflater.inflate(ResUtils.getResId(getActivity(), "hnyy_account_list_item", "layout"), null);
|
|
|
|
+ view.setOnClickListener(new AccountItemClick(session));
|
|
|
|
+
|
|
|
|
+ TextView tvAccountName = view.findViewById(ResUtils.getResId(getActivity(), "hnyy_tv_name", "id"));
|
|
|
|
+ tvAccountName.setGravity(Gravity.CENTER_VERTICAL);
|
|
|
|
+ tvAccountName.setPadding(15, 0, 0, 0);
|
|
|
|
+ tvAccountName.setText(session.userName);
|
|
|
|
+
|
|
|
|
+ ImageView ivDelete = view.findViewById(ResUtils.getResId(getActivity(), "hnyy_iv_delete", "id"));
|
|
|
|
+ ivDelete.setOnClickListener(new AccountItemDeleteClick(session));
|
|
|
|
+
|
|
|
|
+ view.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, height));
|
|
|
|
+ llAccountList.addView(view, llAccountList.getChildCount());
|
|
|
|
+ }
|
|
|
|
+ svAccountList.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, maxHeight));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void hideAccountList() {
|
|
|
|
+ if (userList != null && userList.size() > 0 && rlAccountList.getVisibility() == View.VISIBLE) {
|
|
|
|
+ eetAccount.getRightImageView().setBackgroundResource(imgDown);
|
|
|
|
+ rlAccountList.setVisibility(View.GONE);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void changeAccountList() {
|
|
|
|
+ if (rlAccountList.getVisibility() == View.GONE) {
|
|
|
|
+ eetAccount.getRightImageView().setBackgroundResource(imgUp);
|
|
|
|
+ rlAccountList.setVisibility(View.VISIBLE);
|
|
|
|
+ } else {
|
|
|
|
+ eetAccount.getRightImageView().setBackgroundResource(imgDown);
|
|
|
|
+ rlAccountList.setVisibility(View.GONE);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
private void changeCheck() {
|
|
private void changeCheck() {
|
|
if (check) {
|
|
if (check) {
|
|
check = false;
|
|
check = false;
|
|
@@ -144,33 +262,7 @@ public class AccountLauncherFragment extends Fragment implements View.OnClickLis
|
|
TipsToast.showErrorMsg(getActivity(), "请您先勾选同意下方协议");
|
|
TipsToast.showErrorMsg(getActivity(), "请您先勾选同意下方协议");
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
- SdkRequest.accountLauncher(getActivity(), userName, pwd, new IRequestCallback() {
|
|
|
|
- @Override
|
|
|
|
- public void onResponse(ResultInfo resultInfo) {
|
|
|
|
- if (resultInfo.code == 1) {
|
|
|
|
- try {
|
|
|
|
- JSONObject jsonObject = new JSONObject(resultInfo.data);
|
|
|
|
- Session session = new Session();
|
|
|
|
- session.userId = jsonObject.getString("channel_uid");
|
|
|
|
- session.userName = userName;
|
|
|
|
- session.pwd = pwd;
|
|
|
|
- SessionUtils.getInstance().saveSession(session);
|
|
|
|
- TipsToast.showSuccessMsg(getActivity(), resultInfo.msg);
|
|
|
|
- LoginActivity.implCallback.onResult(1, jsonObject.getString("token"));
|
|
|
|
- getActivity().finish();
|
|
|
|
- } catch (Exception e) {
|
|
|
|
- e.printStackTrace();
|
|
|
|
- }
|
|
|
|
- } else {
|
|
|
|
- String msg = resultInfo.msg;
|
|
|
|
- if (TextUtils.isEmpty(msg)) {
|
|
|
|
- msg = "登录发生异常,请重试";
|
|
|
|
- }
|
|
|
|
- TipsToast.showErrorMsg(getActivity(), msg);
|
|
|
|
- LoginActivity.implCallback.onResult(0, msg);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- });
|
|
|
|
|
|
+ loginImpl.viewModel.accountLauncher(getActivity(), userName, pwd);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -197,4 +289,37 @@ public class AccountLauncherFragment extends Fragment implements View.OnClickLis
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ private class AccountItemClick implements View.OnClickListener {
|
|
|
|
+
|
|
|
|
+ private Session session = null;
|
|
|
|
+
|
|
|
|
+ AccountItemClick(Session session) {
|
|
|
|
+ this.session = session;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void onClick(View v) {
|
|
|
|
+ eetAccount.getRightImageView().setBackgroundResource(imgUp);
|
|
|
|
+ hideAccountList();
|
|
|
|
+ eetAccount.getEditText().setText(session.userName);
|
|
|
|
+ eetPwd.getEditText().setText(session.pwd);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private class AccountItemDeleteClick implements View.OnClickListener {
|
|
|
|
+
|
|
|
|
+ private Session session = null;
|
|
|
|
+
|
|
|
|
+ AccountItemDeleteClick(Session session) {
|
|
|
|
+ this.session = session;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void onClick(View v) {
|
|
|
|
+ SessionUtils.getInstance().removeSession(session.userId);
|
|
|
|
+ userList.clear();
|
|
|
|
+ autoFillAccountInfo();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|