PageRenderTime 41ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/dateLoveInternational/src/main/java/com/datelove/online/International/activity/SettingActivity.java

https://bitbucket.org/juzhiwiscom/datelove
Java | 173 lines | 143 code | 18 blank | 12 comment | 5 complexity | cff8d9f5cf56144e5b0442497b0e379f MD5 | raw file
  1. package com.datelove.online.International.activity;
  2. import android.content.Intent;
  3. import android.os.Bundle;
  4. import android.text.TextUtils;
  5. import android.view.View;
  6. import android.widget.Button;
  7. import android.widget.LinearLayout;
  8. import android.widget.TextView;
  9. import com.alibaba.fastjson.JSON;
  10. import com.datelove.online.International.R;
  11. import com.datelove.online.International.base.BaseTitleActivity;
  12. import com.datelove.online.International.bean.BaseModel;
  13. import com.datelove.online.International.constant.IConfigConstant;
  14. import com.datelove.online.International.constant.IUrlConstant;
  15. import com.datelove.online.International.event.CloseMainActivityEvent;
  16. import com.datelove.online.International.utils.FileUtil;
  17. import com.datelove.online.International.utils.Utils;
  18. import com.datelove.online.International.xml.PlatformInfoXml;
  19. import com.datelove.online.International.xml.UserInfoXml;
  20. import com.library.dialog.OnDoubleDialogClickListener;
  21. import com.library.utils.DialogUtil;
  22. import com.library.utils.SharedPreferenceUtil;
  23. import com.library.utils.ToastUtil;
  24. import com.library.utils.Util;
  25. import com.zhy.http.okhttp.OkHttpUtils;
  26. import com.zhy.http.okhttp.callback.Callback;
  27. import org.greenrobot.eventbus.EventBus;
  28. import butterknife.BindView;
  29. import butterknife.ButterKnife;
  30. import okhttp3.Call;
  31. import okhttp3.Response;
  32. /**
  33. * 设置
  34. * Created by Administrator on 2016/10/22.
  35. */
  36. public class SettingActivity extends BaseTitleActivity {
  37. @BindView(R.id.uid)
  38. TextView mTvUid;
  39. @BindView(R.id.setting_email)
  40. TextView mTvEmail;
  41. @BindView(R.id.change_pwd)
  42. LinearLayout mLlChangePwd;
  43. @BindView(R.id.log_out)
  44. Button mBtnLogOut;
  45. @BindView(R.id.cancel)
  46. Button mbtnCancel;
  47. @BindView(R.id.user_name)
  48. TextView userName;
  49. @Override
  50. protected int getLayoutResId() {
  51. return R.layout.activity_setting;
  52. }
  53. @Override
  54. protected String getCenterTitle() {
  55. return getString(R.string.my_set);
  56. }
  57. @Override
  58. protected void initViewsAndVariables() {
  59. mTvUid.setText(UserInfoXml.getUID());
  60. userName.setText(UserInfoXml.getUsername());
  61. mTvEmail.setText(IConfigConstant.E_MAIL);
  62. }
  63. @Override
  64. protected void addListeners() {
  65. mBtnLogOut.setOnClickListener(new View.OnClickListener() {
  66. @Override
  67. public void onClick(View v) {
  68. // 删除用户本地头像
  69. FileUtil.deleteFile(IConfigConstant.LOCAL_AVATAR_PATH);
  70. String username = UserInfoXml.getUsername();
  71. String password = UserInfoXml.getPassword();
  72. SharedPreferenceUtil.clearXml(SettingActivity.this, UserInfoXml.XML_NAME);
  73. UserInfoXml.setUsername(username);
  74. UserInfoXml.setPassword(password);
  75. // 关闭MainActivity事件
  76. EventBus.getDefault().post(new CloseMainActivityEvent());
  77. SharedPreferenceUtil.setBooleanValue(Utils.getContext(), "INTERCEPT_DIALOG", "DIALOG", true);
  78. // 删除定位信息
  79. SharedPreferenceUtil.setStringValue(Utils.getContext(),"LOCATION","getLatitude",null);
  80. SharedPreferenceUtil.setStringValue(Utils.getContext(),"LOCATION","getLongitude",null);
  81. // Util.gotoActivity(SettingActivity.this, LoginActivity.class, true);
  82. Intent intent = new Intent(SettingActivity.this, LoginActivity.class);
  83. startActivity(intent);
  84. finish();
  85. overridePendingTransition(R.anim.login_anim_in, R.anim.login_anim_out);
  86. }
  87. });
  88. mLlChangePwd.setOnClickListener(new View.OnClickListener() {
  89. @Override
  90. public void onClick(View v) {
  91. Util.gotoActivity(SettingActivity.this, ChangePwdActivity.class, false);
  92. }
  93. });
  94. mbtnCancel.setOnClickListener(new View.OnClickListener() {
  95. @Override
  96. public void onClick(View view) {
  97. DialogUtil.showDoubleBtnDialog(getSupportFragmentManager(), getString(R.string.switch_cancel), getString(R.string.cancel_warn), getString(R.string.sure), getString(R.string.cancel), false, new OnDoubleDialogClickListener() {
  98. @Override
  99. public void onPositiveClick(View view) {
  100. OkHttpUtils.post()
  101. .url(IUrlConstant.URL_LOG_OUT)
  102. .addParams("platformInfo", PlatformInfoXml.getPlatformJsonString())
  103. .build()
  104. .execute(new Callback<BaseModel>() {
  105. @Override
  106. public BaseModel parseNetworkResponse(Response response, int id) throws Exception {
  107. String resultJson = response.body().string();
  108. if (!TextUtils.isEmpty(resultJson)) {
  109. return JSON.parseObject(resultJson, BaseModel.class);
  110. }
  111. return null;
  112. }
  113. @Override
  114. public void onError(Call call, Exception e, int id) {
  115. // ToastUtil.showShortToast(Utils.getContext(), Utils.getContext().getString(R.string.log_out_success));
  116. }
  117. @Override
  118. public void onResponse(BaseModel response, int id) {
  119. if (response != null) {
  120. String isSucceed = response.getIsSucceed();
  121. if (!TextUtils.isEmpty(isSucceed) && "1".equals(isSucceed)) {
  122. ToastUtil.showShortToast(Utils.getContext(), Utils.getContext().getString(R.string.log_out_success));
  123. // 删除用户本地头像
  124. FileUtil.deleteFile(IConfigConstant.LOCAL_AVATAR_PATH);
  125. String username = UserInfoXml.getUsername();
  126. String password = UserInfoXml.getPassword();
  127. SharedPreferenceUtil.clearXml(SettingActivity.this, UserInfoXml.XML_NAME);
  128. UserInfoXml.setUsername(username);
  129. UserInfoXml.setPassword(password);
  130. // 关闭MainActivity事件
  131. EventBus.getDefault().post(new CloseMainActivityEvent());
  132. SharedPreferenceUtil.setBooleanValue(Utils.getContext(), "INTERCEPT_DIALOG", "DIALOG", true);
  133. Intent intent = new Intent(SettingActivity.this, RegisterActivity.class);
  134. startActivity(intent);
  135. finish();
  136. overridePendingTransition(R.anim.login_anim_in, R.anim.login_anim_out);
  137. }
  138. }
  139. }
  140. });
  141. }
  142. @Override
  143. public void onNegativeClick(View view) {
  144. }
  145. });
  146. }
  147. });
  148. }
  149. @Override
  150. protected void onCreate(Bundle savedInstanceState) {
  151. super.onCreate(savedInstanceState);
  152. // TODO: add setContentView(...) invocation
  153. ButterKnife.bind(this);
  154. }
  155. }