|
|
@@ -0,0 +1,490 @@
|
|
|
+package com.yingtang.devicemanager.ui;
|
|
|
+
|
|
|
+import android.app.AlertDialog;
|
|
|
+import android.content.DialogInterface;
|
|
|
+import android.content.Intent;
|
|
|
+import android.graphics.drawable.BitmapDrawable;
|
|
|
+import android.os.Bundle;
|
|
|
+import android.support.v4.app.Fragment;
|
|
|
+import android.text.TextUtils;
|
|
|
+import android.view.Gravity;
|
|
|
+import android.view.LayoutInflater;
|
|
|
+import android.view.View;
|
|
|
+import android.widget.AdapterView;
|
|
|
+import android.widget.ArrayAdapter;
|
|
|
+import android.widget.Button;
|
|
|
+import android.widget.LinearLayout;
|
|
|
+import android.widget.ListView;
|
|
|
+import android.widget.PopupWindow;
|
|
|
+import android.widget.TextView;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.android.volley.RequestQueue;
|
|
|
+import com.android.volley.toolbox.JsonRequest;
|
|
|
+import com.common.data.JSONUtil;
|
|
|
+import com.core.base.BaseActivity;
|
|
|
+import com.core.utils.CommonUtil;
|
|
|
+import com.core.widget.view.Activity.CommonWebviewActivity;
|
|
|
+import com.me.network.app.base.HttpCallback;
|
|
|
+import com.me.network.app.base.HttpParams;
|
|
|
+import com.me.network.app.http.HttpRequest;
|
|
|
+import com.me.network.app.http.Method;
|
|
|
+import com.yingtang.devicemanager.Constant;
|
|
|
+import com.yingtang.devicemanager.R;
|
|
|
+import com.yingtang.devicemanager.adapter.IpAddressAdapter;
|
|
|
+import com.yingtang.devicemanager.bean.IPPORT;
|
|
|
+import com.yingtang.devicemanager.bean.LoginDataBean;
|
|
|
+import com.yingtang.devicemanager.bean.Master;
|
|
|
+import com.yingtang.devicemanager.utils.CookieUtil;
|
|
|
+import com.yingtang.devicemanager.utils.DataSourceManager;
|
|
|
+import com.yingtang.devicemanager.utils.JsonTools;
|
|
|
+
|
|
|
+import org.json.JSONArray;
|
|
|
+import org.json.JSONException;
|
|
|
+import org.json.JSONObject;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+/**
|
|
|
+ * Created by jsxiaoshui on 2021/7/15
|
|
|
+ */
|
|
|
+public class SettingActivity extends BaseActivity implements View.OnClickListener {
|
|
|
+ private static final Object TAG = "IndexSettingFragment";
|
|
|
+ public static final String KEY_URI = "key_uri";
|
|
|
+ private TextView userNameTv, mIpAddressTv, mAccountBookTv, mVersionTextView;
|
|
|
+ private LinearLayout settingCompanyNameLl;
|
|
|
+ private LinearLayout settingCheckUpdateLl;
|
|
|
+ private LinearLayout settingAboutUsLl;
|
|
|
+ private LinearLayout settingExitCurrentAccountLl;
|
|
|
+
|
|
|
+ private String mUserCache;
|
|
|
+ private String mUserName;
|
|
|
+ private String mPassword;
|
|
|
+ private String mAccountName;
|
|
|
+
|
|
|
+ private PopupWindow mAccountBookPop, mIpAddressPop;
|
|
|
+ private Fragment mFragment;
|
|
|
+ private ArrayAdapter<String> otherAccountAdapter;
|
|
|
+ private IpAddressAdapter mIpAddressAdapter;
|
|
|
+ private List<String> allFunname, allName;
|
|
|
+ private List<LoginDataBean> mLoginDataBeans;
|
|
|
+
|
|
|
+ private RequestQueue mRequestQueue;
|
|
|
+ private JsonRequest mJsonRequest;
|
|
|
+
|
|
|
+ private String cacheUri;
|
|
|
+ private String mIp, mPort;
|
|
|
+ private int mLoginPosition;
|
|
|
+ private boolean isSwitchComplete = true;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void onCreate(Bundle savedInstanceState) {
|
|
|
+ super.onCreate(savedInstanceState);
|
|
|
+ setContentView(R.layout.activity_new_setting);
|
|
|
+ setTitle(R.string.setting);
|
|
|
+ getUserName();
|
|
|
+ mAccountName = CommonUtil.getSharedPreferencesString(SettingActivity.this, Constant.ERP_MASTER_ZH, null);
|
|
|
+ userNameTv = (TextView) findViewById(R.id.user_name_tv);
|
|
|
+ settingCheckUpdateLl = (LinearLayout) findViewById(R.id.setting_check_update_ll);
|
|
|
+ settingAboutUsLl = (LinearLayout) findViewById(R.id.setting_about_us_ll);
|
|
|
+ settingExitCurrentAccountLl = (LinearLayout) findViewById(R.id.setting_exit_current_account_ll);
|
|
|
+ mIpAddressTv = (TextView) findViewById(R.id.setting_ip_address_name_tv);
|
|
|
+ mAccountBookTv = findViewById(R.id.setting_account_name_tv);
|
|
|
+ mVersionTextView = findViewById(R.id.setting_current_version);
|
|
|
+
|
|
|
+ //init data
|
|
|
+ userNameTv.setText(mUserName);
|
|
|
+ mAccountBookTv.setText(mAccountName);
|
|
|
+ mIpAddressTv.setText(mAccountName + "(" + mIp + ")");
|
|
|
+ mVersionTextView.setText("V"+CommonUtil.ApkVersionCode(this));
|
|
|
+ //切换账套,地址
|
|
|
+ findViewById(R.id.setting_account_book_rl).setOnClickListener(this);
|
|
|
+ findViewById(R.id.setting_ip_address_rl).setOnClickListener(this);
|
|
|
+ //当前版本,关于我们,退出账号
|
|
|
+ settingCheckUpdateLl.setOnClickListener(this);
|
|
|
+ settingAboutUsLl.setOnClickListener(this);
|
|
|
+ settingExitCurrentAccountLl.setOnClickListener(this);
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onClick(View v) {
|
|
|
+ switch (v.getId()) {
|
|
|
+ case R.id.setting_account_book_rl:
|
|
|
+ changeAccountBook();
|
|
|
+ break;
|
|
|
+ case R.id.setting_ip_address_rl:
|
|
|
+ changeIpAddress();
|
|
|
+ break;
|
|
|
+ case R.id.setting_check_update_ll:
|
|
|
+ showToast("当前版本:V"+CommonUtil.ApkVersionCode(this));
|
|
|
+ break;
|
|
|
+ case R.id.setting_about_us_ll:
|
|
|
+ Intent intent=new Intent(this, CommonWebviewActivity.class);
|
|
|
+ intent.putExtra("scan_url","https://www.ubtob.net/about");
|
|
|
+ intent.putExtra("title","关于我们");
|
|
|
+ startActivity(intent);
|
|
|
+ break;
|
|
|
+ case R.id.setting_exit_current_account_ll:
|
|
|
+ new AlertDialog.Builder(this).setTitle("提示").setMessage("确定要退出当前账号吗?")
|
|
|
+ .setPositiveButton(getString(R.string.confirm), new DialogInterface.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(DialogInterface dialog, int which) {
|
|
|
+ progressDialog.show();
|
|
|
+ //VolleyUtil.setVolleyHandler(mHandler);
|
|
|
+ //VolleyUtil.getVolleyUtil().requestConnectServer(getActivity(), GloableParams.ADDRESS_LOGOUT_APPLY, VolleyUtil.METHOD_GET, VolleyUtil.FRAGMENT_LOGOUT);
|
|
|
+ showToast("正在退出中...");
|
|
|
+ Map<String ,String> headMap= CookieUtil.getHeadersMap(SettingActivity.this);
|
|
|
+ HttpRequest.getInstance().sendRequest(CommonUtil.getAppBaseUrl(SettingActivity.this),
|
|
|
+ new HttpParams.Builder()
|
|
|
+ .url("api/pda/logout.action")
|
|
|
+ .connectTimeOut(5)
|
|
|
+ .readTimeOut(5)
|
|
|
+ .method(Method.GET)
|
|
|
+ .addHeader(Constant.HEAD_MASTER,headMap.get(Constant.HEAD_MASTER))
|
|
|
+ .addHeader(Constant.HEAD_USER_NAME,headMap.get(Constant.HEAD_USER_NAME))
|
|
|
+ .addHeader(Constant.HEAD_PWD,headMap.get(Constant.HEAD_PWD))
|
|
|
+ .addHeader(Constant.HEAD_COOKIE,headMap.get(Constant.HEAD_COOKIE))
|
|
|
+ .addHeader(Constant.HEAD_VERSION_CODE,headMap.get(Constant.HEAD_VERSION_CODE))
|
|
|
+ .build(), new HttpCallback() {
|
|
|
+ @Override
|
|
|
+ public void onSuccess(int flag, Object o) throws Exception {
|
|
|
+ progressDialog.dismiss();
|
|
|
+ com.alibaba.fastjson.JSONObject resultObject=JSON.parseObject(o.toString());
|
|
|
+ boolean success=JSONUtil.getBoolean(resultObject,"success");
|
|
|
+ if(success){
|
|
|
+ DataSourceManager.getDataSourceManager().setMasterList(o.toString());
|
|
|
+ Intent intent = new Intent();
|
|
|
+ intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
|
+ intent.setClass(SettingActivity.this, LoginActivity.class);
|
|
|
+ intent.putExtra(Constant.KEY_URI_LOGIN_INFO,getIpAndPort());
|
|
|
+ startActivity(intent);
|
|
|
+ }else{
|
|
|
+ showToast("退出登录失败,请稍后重试!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onFail(int flag, String failStr) throws Exception {
|
|
|
+ progressDialog.dismiss();
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ }).setNegativeButton(getString(R.string.cancel), null).create().show();
|
|
|
+
|
|
|
+ break;
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 更换常用地址
|
|
|
+ */
|
|
|
+ private void changeIpAddress() {
|
|
|
+ View accountBookView = LayoutInflater.from(this).inflate(R.layout.popupwindow_ip_address_change, null);
|
|
|
+ ListView accountBookLv = (ListView) accountBookView.findViewById(R.id.ip_address_change_lv);
|
|
|
+ Button closeBtn = (Button) accountBookView.findViewById(R.id.ip_address_change_close_btn);
|
|
|
+ final String currentFunname = CommonUtil.getSharedPreferencesString(this, Constant.ERP_MASTER_ZH, null);
|
|
|
+ List<LoginDataBean> loginListCache = DataSourceManager.getLoginListCache(this);
|
|
|
+ mLoginDataBeans = new ArrayList<>();
|
|
|
+ if (loginListCache != null && mUserName != null) {
|
|
|
+ for (LoginDataBean loginDataBean : loginListCache) {
|
|
|
+ mLoginDataBeans.add(loginDataBean);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ mIpAddressAdapter = new IpAddressAdapter(this, mLoginDataBeans);
|
|
|
+ mIpAddressAdapter.setCurrent(currentFunname, mIp);
|
|
|
+ accountBookLv.setAdapter(mIpAddressAdapter);
|
|
|
+ closeBtn.setOnClickListener(new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View v) {
|
|
|
+ closeIpAddressPop();
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ accountBookLv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
|
|
+ LoginDataBean loginDataBean = mLoginDataBeans.get(position);
|
|
|
+ if (currentFunname != null && currentFunname.equals(loginDataBean.getMasterName())
|
|
|
+ && mIp != null && mIp.equals(loginDataBean.getIp())) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (isSwitchComplete) {
|
|
|
+ isSwitchComplete = false;
|
|
|
+ mLoginPosition = position;
|
|
|
+ switchLoginAccount(loginDataBean);
|
|
|
+ } else {
|
|
|
+ showToast("地址正在切换中,请勿操作!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ if (mLoginDataBeans.size() == 0) {
|
|
|
+ showToast("您没有其他常用地址");
|
|
|
+ } else {
|
|
|
+ mIpAddressPop = new PopupWindow(accountBookView, LinearLayout.LayoutParams.WRAP_CONTENT,
|
|
|
+ LinearLayout.LayoutParams.WRAP_CONTENT, true);
|
|
|
+ mIpAddressPop.setAnimationStyle(R.style.MenuAnimationFade);
|
|
|
+ mIpAddressPop.setBackgroundDrawable(new BitmapDrawable());
|
|
|
+ mIpAddressPop.showAtLocation(mIpAddressTv, Gravity.CENTER, 0, 0);
|
|
|
+ CommonUtil.setBackgroundAlpha(this, 0.5f);
|
|
|
+
|
|
|
+ mIpAddressPop.setOnDismissListener(new PopupWindow.OnDismissListener() {
|
|
|
+ @Override
|
|
|
+ public void onDismiss() {
|
|
|
+ closeIpAddressPop();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ private void closeIpAddressPop() {
|
|
|
+ if (mIpAddressPop != null) {
|
|
|
+ mIpAddressPop.dismiss();
|
|
|
+ mIpAddressPop = null;
|
|
|
+ CommonUtil.setBackgroundAlpha(this, 1f);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 切换登录账号
|
|
|
+ *
|
|
|
+ */
|
|
|
+ private void switchLoginAccount(LoginDataBean loginDataBean) {
|
|
|
+ progressDialog.show();
|
|
|
+ String httpUrl = loginDataBean.getHttp()+"://"+loginDataBean.getIp()+":"+loginDataBean.getPort()+"/"+loginDataBean.getSite()+"/";
|
|
|
+ Map<String ,String> headMap= CookieUtil.getHeadersMap(SettingActivity.this);
|
|
|
+ HttpRequest.getInstance().sendRequest(httpUrl,
|
|
|
+ new HttpParams.Builder()
|
|
|
+ .url("api/pda/loginGetMasters.action")
|
|
|
+ .connectTimeOut(5)
|
|
|
+ .readTimeOut(5)
|
|
|
+ .method(Method.POST)
|
|
|
+ .addParam(Constant.HEAD_MASTER,loginDataBean.getMaster())
|
|
|
+ .addParam(Constant.HEAD_USER_NAME,mUserName)
|
|
|
+ .addParam(Constant.HEAD_PWD,mPassword)
|
|
|
+ .addParam(Constant.HEAD_VERSION_CODE,headMap.get(Constant.HEAD_VERSION_CODE))
|
|
|
+ .build(), new HttpCallback() {
|
|
|
+ @Override
|
|
|
+ public void onSuccess(int flag, Object o) throws Exception {
|
|
|
+ isSwitchComplete = true;
|
|
|
+ String result = o.toString();
|
|
|
+ com.alibaba.fastjson.JSONObject resultObject = JSON.parseObject(result);
|
|
|
+ boolean success=JSONUtil.getBoolean(resultObject,"success");
|
|
|
+ if(success){
|
|
|
+ showToast("地址切换成功");
|
|
|
+ LoginDataBean loginDataBean = mLoginDataBeans.get(mLoginPosition);
|
|
|
+ mAccountBookTv.setText(loginDataBean.getMasterName());
|
|
|
+ mIpAddressTv.setText(loginDataBean.getMasterName() + "(" + loginDataBean.getIp() + ")");
|
|
|
+ mIp = loginDataBean.getIp();
|
|
|
+ mPort = loginDataBean.getPort();
|
|
|
+ String cacheUri = DataSourceManager.getDataSourceManager().addUriItem(loginDataBean.getIp(), loginDataBean.getPort());
|
|
|
+ CommonUtil.setSharedPreferences(SettingActivity.this,Constant.ERP_MASTER,loginDataBean.getMaster());
|
|
|
+ CommonUtil.setSharedPreferences(SettingActivity.this,Constant.ERP_MASTER_ZH,loginDataBean.getMasterName());
|
|
|
+ CommonUtil.setSharedPreferences(SettingActivity.this,Constant.HTTP_CACHE,loginDataBean.getHttp());
|
|
|
+ CommonUtil.setSharedPreferences(SettingActivity.this,Constant.SYSTEM_CACHE,loginDataBean.getSite());
|
|
|
+ CommonUtil.setSharedPreferences(SettingActivity.this,Constant.KEY_URI,cacheUri);
|
|
|
+ //保存当前切换的地址
|
|
|
+ CommonUtil.setSharedPreferences(SettingActivity.this,Constant.ERP_BASEURL,httpUrl);
|
|
|
+
|
|
|
+ }else{
|
|
|
+ String reason=JSONUtil.getText(resultObject,"reason");
|
|
|
+ if(TextUtils.isEmpty(reason)){
|
|
|
+ showToast("切换登录失败");
|
|
|
+ }else{
|
|
|
+ showToast("切换登录失败:"+reason);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ closeIpAddressPop();
|
|
|
+ progressDialog.dismiss();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onFail(int flag, String failStr) throws Exception {
|
|
|
+ isSwitchComplete = true;
|
|
|
+ showToast("切换登录失败");
|
|
|
+ closeIpAddressPop();
|
|
|
+ progressDialog.dismiss();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 更换账套
|
|
|
+ */
|
|
|
+ private void changeAccountBook() {
|
|
|
+ View accountBookView = LayoutInflater.from(this).inflate(R.layout.popupwindow_account_book_change, null);
|
|
|
+ ListView accountBookLv = (ListView) accountBookView.findViewById(R.id.account_book_change_lv);
|
|
|
+ Button closeBtn = (Button) accountBookView.findViewById(R.id.account_book_change_close_btn);
|
|
|
+ String currentFunname = CommonUtil.getSharedPreferencesString(this, Constant.ERP_MASTER_ZH, null);
|
|
|
+ String currentName = CommonUtil.getSharedPreferencesString(this, Constant.ERP_MASTER, null);
|
|
|
+
|
|
|
+ List<String> masterFuncList = DataSourceManager.getDataSourceManager().getMasterFuncList();
|
|
|
+ allFunname = new ArrayList<>();
|
|
|
+ if (masterFuncList != null) {
|
|
|
+ for (int i = 0; i < masterFuncList.size(); i++) {
|
|
|
+ allFunname.add(masterFuncList.get(i));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ allName = new ArrayList<>();
|
|
|
+ List<Master> masterList = DataSourceManager.getDataSourceManager().getMasterList();
|
|
|
+ if (masterList != null) {
|
|
|
+ for (int i = 0; i < masterList.size(); i++) {
|
|
|
+ allName.add(masterList.get(i).getMaName());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //移除当前账套
|
|
|
+ allFunname.remove(currentFunname);
|
|
|
+ allName.remove(currentName);
|
|
|
+
|
|
|
+ otherAccountAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, allFunname);
|
|
|
+ accountBookLv.setAdapter(otherAccountAdapter);
|
|
|
+
|
|
|
+ closeBtn.setOnClickListener(new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View v) {
|
|
|
+ closeAccountBookPop();
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ accountBookLv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
|
|
+ changeMasterItemClick(position);
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ if (allFunname.size() == 0) {
|
|
|
+ showToast("您没有其他账套");
|
|
|
+ } else {
|
|
|
+ mAccountBookPop = new PopupWindow(accountBookView, LinearLayout.LayoutParams.WRAP_CONTENT,
|
|
|
+ LinearLayout.LayoutParams.WRAP_CONTENT, true);
|
|
|
+ mAccountBookPop.setAnimationStyle(R.style.MenuAnimationFade);
|
|
|
+ mAccountBookPop.setBackgroundDrawable(new BitmapDrawable());
|
|
|
+ mAccountBookPop.showAtLocation(mAccountBookTv, Gravity.CENTER, 0, 0);
|
|
|
+ CommonUtil.setBackgroundAlpha(this, 0.5f);
|
|
|
+
|
|
|
+ mAccountBookPop.setOnDismissListener(new PopupWindow.OnDismissListener() {
|
|
|
+ @Override
|
|
|
+ public void onDismiss() {
|
|
|
+ closeAccountBookPop();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private void closeAccountBookPop() {
|
|
|
+ if (mAccountBookPop != null) {
|
|
|
+ mAccountBookPop.dismiss();
|
|
|
+ mAccountBookPop = null;
|
|
|
+ CommonUtil.setBackgroundAlpha(this, 1f);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 账套切换提交事件
|
|
|
+ *
|
|
|
+ * @param position
|
|
|
+ */
|
|
|
+ private void changeMasterItemClick(int position) {
|
|
|
+ progressDialog.show();
|
|
|
+ Map<String ,String> headMap= CookieUtil.getHeadersMap(SettingActivity.this);
|
|
|
+ HttpRequest.getInstance().sendRequest(CommonUtil.getAppBaseUrl(this),
|
|
|
+ new HttpParams.Builder()
|
|
|
+ .url("api/pda/changeMaster.action?master=" + allName.get(position))
|
|
|
+ .connectTimeOut(5)
|
|
|
+ .readTimeOut(5)
|
|
|
+ .method(Method.GET)
|
|
|
+ .addHeader(Constant.HEAD_COOKIE,headMap.get(Constant.HEAD_COOKIE))
|
|
|
+ .addHeader(Constant.HEAD_MASTER,headMap.get(Constant.HEAD_MASTER))
|
|
|
+ .addHeader(Constant.HEAD_USER_NAME,headMap.get(Constant.HEAD_USER_NAME))
|
|
|
+ .addHeader(Constant.HEAD_PWD,headMap.get(Constant.HEAD_PWD))
|
|
|
+ .addHeader(Constant.HEAD_VERSION_CODE,headMap.get(Constant.HEAD_VERSION_CODE))
|
|
|
+ .build(), new HttpCallback() {
|
|
|
+ @Override
|
|
|
+ public void onSuccess(int flag, Object o) throws Exception {
|
|
|
+ progressDialog.dismiss();
|
|
|
+ String result = o.toString();
|
|
|
+ com.alibaba.fastjson.JSONObject jsonObject = JSON.parseObject(result);
|
|
|
+ if (jsonObject != null) {
|
|
|
+ if (JSONUtil.getBoolean(jsonObject, "success")) {
|
|
|
+ com.alibaba.fastjson.JSONObject dataObject = JSONUtil.getJSONObject(jsonObject, "data");
|
|
|
+ try {
|
|
|
+ String ma_function = dataObject.getString("ma_function");
|
|
|
+ String em_master = dataObject.getString("em_master");
|
|
|
+ if (!TextUtils.isEmpty(em_master) && !TextUtils.isEmpty(em_master)) {
|
|
|
+ CommonUtil.setSharedPreferences(SettingActivity.this, Constant.ERP_MASTER_ZH, ma_function);
|
|
|
+ CommonUtil.setSharedPreferences(SettingActivity.this, Constant.ERP_MASTER, em_master);
|
|
|
+ showToast("账套切换成功");
|
|
|
+ closeAccountBookPop();
|
|
|
+ mAccountBookTv.setText(ma_function);
|
|
|
+ } else {
|
|
|
+ showToast("账套切换失败");
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ closeAccountBookPop();
|
|
|
+ showToast("账套切换失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onFail(int flag, String failStr) throws Exception {
|
|
|
+ progressDialog.dismiss();
|
|
|
+ showToast("账套切换失败");
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取缓存中的用户名
|
|
|
+ */
|
|
|
+ private void getUserName() {
|
|
|
+ String str = CommonUtil.getSharedPreferencesString(this, Constant.KEY_URI, null);
|
|
|
+ IPPORT ip = JsonTools.parseJsonToBean(str, IPPORT.class);
|
|
|
+ mIp = ip.uriArray.get(0).ip;
|
|
|
+ mPort = ip.uriArray.get(0).port;
|
|
|
+ mUserCache = CommonUtil.getSharedPreferencesString(this, mIp + ":" + mPort, null);
|
|
|
+ try {
|
|
|
+ JSONObject userCacheJsonObject = new JSONObject(mUserCache);
|
|
|
+ JSONArray userCacheArray = userCacheJsonObject.getJSONArray(DataSourceManager.KEY_INFOARRAY);
|
|
|
+ JSONObject userCacheObject = (JSONObject) userCacheArray.get(0);
|
|
|
+ mUserName = userCacheObject.getString(DataSourceManager.KEY_USERNAME);
|
|
|
+ mPassword = userCacheObject.getString(DataSourceManager.KEY_PASSWORD);
|
|
|
+ } catch (JSONException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ public String getIpAndPort(){
|
|
|
+ cacheUri = CommonUtil.getSharedPreferencesString(this, Constant.KEY_URI, null);
|
|
|
+ //当缓存不为空
|
|
|
+ if (cacheUri != null) {
|
|
|
+ //将缓存数据加载到数据源UriList
|
|
|
+ DataSourceManager.getDataSourceManager().setUriList(cacheUri);
|
|
|
+ List<Map<String, String>> list = DataSourceManager.getDataSourceManager().getUriList();
|
|
|
+ mIp = list.get(0).get(DataSourceManager.KEY_IP);
|
|
|
+ mPort = list.get(0).get(DataSourceManager.KEY_PORT);
|
|
|
+ }
|
|
|
+ return mIp+":"+mPort;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|