package com.haicaojie.android.ui.mine;
|
|
import android.content.Intent;
|
import android.content.SharedPreferences;
|
import android.os.Build;
|
import android.os.Bundle;
|
import android.view.View;
|
import android.view.Window;
|
import android.view.WindowManager;
|
import android.widget.CheckBox;
|
import android.widget.CompoundButton;
|
import android.widget.LinearLayout;
|
import android.widget.TextView;
|
import android.widget.Toast;
|
|
import com.alibaba.baichuan.trade.biz.login.AlibcLogin;
|
import com.alibaba.baichuan.trade.biz.login.AlibcLoginCallback;
|
import com.bumptech.glide.Glide;
|
import com.haicaojie.android.BuXinConstant;
|
import com.haicaojie.android.R;
|
import com.haicaojie.android.ShoppingApi;
|
import com.haicaojie.android.ui.BaseActivity;
|
import com.lcjian.library.util.DataCleanManager;
|
import com.lcjian.library.util.SingleToast;
|
import com.lcjian.library.util.SystemCommon;
|
import com.loopj.android.http.JsonHttpResponseHandler;
|
import com.nostra13.universalimageloader.core.ImageLoader;
|
import com.umeng.socialize.UMAuthListener;
|
import com.umeng.socialize.bean.SHARE_MEDIA;
|
import com.xiaomi.mipush.sdk.MiPushClient;
|
import com.ysh.wpc.appupdate.AppUpdate;
|
|
import java.util.Map;
|
|
/**
|
* Created by weikou2015 on 2017/2/21.
|
* 设置
|
*/
|
|
public class SettingActivity extends BaseActivity implements View.OnClickListener {
|
private TextView tv_left;
|
private TextView tv_middle;
|
private TextView tv_version;
|
private TextView tv_cache_num;
|
private CheckBox cb_msg;
|
private LinearLayout ll_clear_cache;
|
private LinearLayout ll_check_update;
|
private LinearLayout ll_exit_account;
|
private LinearLayout ll_person_info;
|
|
@Override
|
protected void onCreate(Bundle savedInstanceState) {
|
super.onCreate(savedInstanceState);
|
setContentView(R.layout.activity_settings);
|
/*
|
* 计算状态栏高度并设置
|
*/
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
Window window = getWindow();
|
window.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS,
|
WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
|
int result = 0;
|
int resourceId = getResources().getIdentifier("status_bar_height",
|
"dimen", "android");
|
if (resourceId > 0) {
|
result = getResources().getDimensionPixelSize(resourceId);
|
}
|
//设置状态栏文字颜色及图标为深色
|
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
|
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
|
result);
|
findViewById(R.id.v_status_bar).setLayoutParams(params);
|
} else {
|
findViewById(R.id.v_status_bar).setVisibility(View.GONE);
|
}
|
tv_left = (TextView) findViewById(R.id.tv_top_bar_left);
|
tv_middle = (TextView) findViewById(R.id.tv_top_bar_middle);
|
tv_cache_num = (TextView) findViewById(R.id.tv_cache_num);
|
tv_version = (TextView) findViewById(R.id.tv_version);
|
cb_msg = (CheckBox) findViewById(R.id.cb_msg);
|
ll_clear_cache = (LinearLayout) findViewById(R.id.ll_clear_cache);
|
ll_check_update = (LinearLayout) findViewById(R.id.ll_check_update);
|
ll_exit_account = (LinearLayout) findViewById(R.id.ll_exit_account);
|
ll_person_info = (LinearLayout) findViewById(R.id.ll_person_info);
|
final SharedPreferences sp = getSharedPreferences("user", MODE_PRIVATE);
|
if (!sp.getBoolean("isLogin", false)) {
|
ll_exit_account.setVisibility(View.GONE);
|
} else {
|
ll_exit_account.setVisibility(View.VISIBLE);
|
}
|
// tv_left.setText("返回");
|
tv_middle.setText("设置");
|
String cache = "";
|
try {
|
cache = DataCleanManager.getOutsideCacheSize(this);
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
tv_cache_num.setText(cache);
|
tv_version.setText("版本号:" + SystemCommon.getVersonName(SettingActivity.this));
|
tv_left.setOnClickListener(this);
|
ll_clear_cache.setOnClickListener(this);
|
ll_check_update.setOnClickListener(this);
|
ll_exit_account.setOnClickListener(this);
|
ll_person_info.setOnClickListener(this);
|
|
cb_msg.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
@Override
|
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
SharedPreferences.Editor editor = sp.edit();
|
if (isChecked) {
|
editor.putBoolean("doNotDisturb", true);
|
// if (MobileUtil.getDeviceBrand().equalsIgnoreCase("HUAWEI") || MobileUtil.getDeviceBrand().equalsIgnoreCase("HONOR")) {
|
// HMSAgent.Push.enableReceiveNormalMsg(false, null);
|
// HMSAgent.Push.enableReceiveNotifyMsg(false, null);
|
// } else {
|
MiPushClient.unregisterPush(SettingActivity.this);
|
// }
|
} else {
|
editor.putBoolean("doNotDisturb", false);
|
// if (MobileUtil.getDeviceBrand().equalsIgnoreCase("HUAWEI") || MobileUtil.getDeviceBrand().equalsIgnoreCase("HONOR")) {
|
// HMSAgent.Push.enableReceiveNormalMsg(true, null);
|
// HMSAgent.Push.enableReceiveNotifyMsg(true, null);
|
// } else {
|
MiPushClient.registerPush(SettingActivity.this, BuXinConstant.MIPUSH_ID, BuXinConstant.MIPUSH_KEY);
|
// }
|
}
|
editor.commit();
|
}
|
});
|
if (sp.getBoolean("doNotDisturb", false)) {
|
cb_msg.setChecked(true);
|
} else {
|
cb_msg.setChecked(false);
|
}
|
}
|
|
@Override
|
public void onClick(View v) {
|
switch (v.getId()) {
|
case R.id.tv_top_bar_left:
|
finish();
|
break;
|
case R.id.ll_clear_cache:
|
ImageLoader.getInstance().clearDiskCache();
|
ImageLoader.getInstance().clearMemoryCache();
|
DataCleanManager.clearAllCache(SettingActivity.this, tv_cache_num);
|
new Thread(new Runnable() {
|
@Override
|
public void run() {
|
Glide.get(SettingActivity.this).clearMemory();
|
Glide.get(SettingActivity.this).clearDiskCache();
|
}
|
});
|
break;
|
case R.id.ll_check_update:
|
//自动更新
|
AppUpdate.setAppUpdateActivity(this);
|
AppUpdate.setAppUpdateKey(BuXinConstant.APP_UPDATE_KEY);
|
AppUpdate.initAppUpdate(true);
|
break;
|
case R.id.ll_exit_account:
|
if (getSharedPreferences("user", MODE_PRIVATE).getBoolean("isLogin", false)) {
|
tbLoginOut();
|
loginOut();
|
// boolean isauth = UMShareAPI.get(SettingActivity.this).isAuthorize(SettingActivity.this, SHARE_MEDIA.WEIXIN);
|
// if (isauth)
|
// UMShareAPI.get(SettingActivity.this).deleteOauth(SettingActivity.this, SHARE_MEDIA.WEIXIN, authListener);
|
SharedPreferences sp = getSharedPreferences("user", MODE_PRIVATE);
|
MiPushClient.unsetAlias(SettingActivity.this, sp.getString("uid", "0"), null);
|
SharedPreferences.Editor editor = sp.edit();
|
editor.putBoolean("isLogin", false);
|
editor.putBoolean("isTBBind", false);
|
editor.putBoolean("isWxBind", false);
|
// editor.putBoolean("haveHongbao", false);
|
editor.putString("uid", "0");
|
editor.commit();
|
ll_exit_account.setVisibility(View.GONE);
|
SingleToast.showToast(SettingActivity.this, "退出登录成功");
|
}
|
break;
|
case R.id.ll_person_info:
|
if (getSharedPreferences("user", MODE_PRIVATE).getBoolean("isLogin", false)) {
|
startActivity(new Intent(SettingActivity.this, MyInfoActivity.class));
|
} else {
|
SingleToast.showToast(SettingActivity.this, "登录后才能查看信息!");
|
startActivity(new Intent(SettingActivity.this, LoginSelectActivity.class));
|
}
|
break;
|
}
|
}
|
|
|
private void loginOut() {
|
ShoppingApi.loginOut(this, getSharedPreferences("user", MODE_PRIVATE).getString("uid", "0"), new JsonHttpResponseHandler());
|
}
|
|
/**
|
* 退出登录
|
*/
|
private void tbLoginOut() {
|
AlibcLogin alibcLogin = AlibcLogin.getInstance();
|
|
alibcLogin.logout(new AlibcLoginCallback() {
|
@Override
|
public void onSuccess(int i) {
|
SingleToast.showToast(SettingActivity.this, "退出登录成功");
|
SharedPreferences sp = getSharedPreferences("user", MODE_PRIVATE);
|
SharedPreferences.Editor editor = sp.edit();
|
editor.putBoolean("isLogin", false);
|
editor.putString("uid", "0");
|
// editor.putBoolean("haveHongbao", false);
|
editor.commit();
|
ll_exit_account.setVisibility(View.GONE);
|
}
|
|
@Override
|
public void onFailure(int code, String msg) {
|
Toast.makeText(SettingActivity.this, "退出登录失败 " + code + msg,
|
Toast.LENGTH_SHORT).show();
|
}
|
});
|
}
|
|
@Override
|
protected void onDestroy() {
|
super.onDestroy();
|
AppUpdate.destoryAppUpdate();
|
}
|
|
UMAuthListener authListener = new UMAuthListener() {
|
@Override
|
public void onStart(SHARE_MEDIA platform) {
|
// SocializeUtils.safeShowDialog(dialog);
|
}
|
|
@Override
|
public void onComplete(SHARE_MEDIA platform, int action, Map<String, String> data) {
|
// SocializeUtils.safeCloseDialog(dialog);
|
// Toast.makeText(SettingActivity.this, "成功了", Toast.LENGTH_LONG).show();
|
}
|
|
@Override
|
public void onError(SHARE_MEDIA platform, int action, Throwable t) {
|
// SocializeUtils.safeCloseDialog(dialog);
|
// Toast.makeText(SettingActivity.this, "失败:" + t.getMessage(), Toast.LENGTH_LONG).show();
|
}
|
|
@Override
|
public void onCancel(SHARE_MEDIA platform, int action) {
|
// SocializeUtils.safeCloseDialog(dialog);
|
// Toast.makeText(SettingActivity.this, "取消了", Toast.LENGTH_LONG).show();
|
}
|
};
|
}
|