package com.tejia.lijin.app.ui.mine;
|
|
import android.content.Context;
|
import android.content.DialogInterface;
|
import android.content.Intent;
|
import android.content.SharedPreferences;
|
import android.net.Uri;
|
import android.os.Bundle;
|
import android.text.TextUtils;
|
import android.view.KeyEvent;
|
import android.view.View;
|
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.nostra13.universalimageloader.core.ImageLoader;
|
import com.tejia.lijin.app.ShoppingApplication;
|
import com.wpc.library.util.DataCleanManager;
|
import com.wpc.library.util.GetManifestDataUtil;
|
import com.wpc.library.util.SystemCommon;
|
import com.tejia.lijin.app.BasicTextHttpResponseHandler;
|
import com.tejia.lijin.app.R;
|
import com.tejia.lijin.app.ShoppingApi;
|
import com.tejia.lijin.app.ui.BaseActivity;
|
import com.tejia.lijin.app.ui.dialog.AddZFBInfoDialog2;
|
import com.tejia.lijin.app.ui.invite.ShareBrowserActivity;
|
import com.tejia.lijin.app.updateApp.UpdateApp;
|
import com.tejia.lijin.app.util.SystemParamsUtil;
|
import com.tejia.lijin.app.util.ToolUtil;
|
import com.tejia.lijin.app.util.TopStatusSettings;
|
import com.tejia.lijin.app.util.umengCustomEvent.UserCustomEvent;
|
import com.tejia.lijin.app.util.user.LoginAndInviteStatusUtil;
|
import com.tejia.lijin.app.util.user.UserUtil;
|
|
import org.json.JSONException;
|
import org.json.JSONObject;
|
|
/**
|
* 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, cb_no_see_red_point, cb_no_see_reward_statistics,
|
cb_no_see_share_and_selection, cb_no_see_phone;// cb_no_see_invite_reward;, cb_open_share_red_packet//开启推广红包
|
private LinearLayout ll_clear_cache, ll_check_update, ll_person_info, ll_account_grade,
|
ll_about_us, ll_exit_account;
|
private int shareRedPacket, noBonusCount, noNewsRedDot, noShareRecordAndStorage, noDisplayPhoneNum;
|
private int noInvitationBonus;//开启推广红包标记
|
|
@Override
|
protected void onCreate(Bundle savedInstanceState) {
|
super.onCreate(savedInstanceState);
|
setContentView(R.layout.activity_settings);
|
TopStatusSettings.setStatusViewAndDeepColor(this);
|
tv_left = findViewById(R.id.tv_top_bar_left);
|
tv_middle = findViewById(R.id.tv_top_bar_middle);
|
tv_cache_num = findViewById(R.id.tv_cache_num);
|
tv_version = findViewById(R.id.tv_version);
|
cb_msg = findViewById(R.id.cb_msg);
|
// cb_open_share_red_packet = findViewById(R.id.cb_open_share_red_packet);
|
cb_no_see_red_point = findViewById(R.id.cb_no_see_red_point);
|
cb_no_see_reward_statistics = findViewById(R.id.cb_no_see_reward_statistics);
|
cb_no_see_share_and_selection = findViewById(R.id.cb_no_see_share_and_selection);
|
|
cb_no_see_phone = findViewById(R.id.cb_no_see_phone);
|
// cb_no_see_invite_reward = findViewById(R.id.cb_no_see_invite_reward);
|
ll_clear_cache = findViewById(R.id.ll_clear_cache);
|
ll_check_update = findViewById(R.id.ll_check_update);
|
ll_exit_account = findViewById(R.id.ll_exit_account);
|
ll_person_info = findViewById(R.id.ll_person_info);
|
ll_account_grade = findViewById(R.id.ll_account_grade);
|
ll_about_us = findViewById(R.id.ll_about_us);
|
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.getTotalCacheSize(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);
|
ll_account_grade.setOnClickListener(this);
|
ll_about_us.setOnClickListener(this);
|
findViewById(R.id.ll_evaluate).setOnClickListener(this);
|
/**
|
* 消息免打扰
|
*/
|
cb_msg.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
@Override
|
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
UserCustomEvent.userSettingCommon(SettingActivity.this, "消息免打扰");
|
SharedPreferences.Editor editor = sp.edit();
|
ToolUtil.notDisturb(SettingActivity.this, isChecked);
|
if (isChecked)
|
editor.putBoolean("doNotDisturb", true);
|
else
|
editor.putBoolean("doNotDisturb", false);
|
editor.commit();
|
}
|
});
|
cb_no_see_red_point.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
@Override
|
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
UserCustomEvent.userSettingCommon(SettingActivity.this, "红点提醒");
|
}
|
});
|
// cb_no_see_invite_reward.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
// @Override
|
// public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
// UserCustomEvent.userSettingCommon(SettingActivity.this, "邀请拿奖金");
|
// }
|
// });
|
cb_no_see_reward_statistics.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
@Override
|
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
UserCustomEvent.userSettingCommon(SettingActivity.this, "奖金统计");
|
}
|
});
|
|
cb_no_see_share_and_selection.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
@Override
|
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
UserCustomEvent.userSettingCommon(SettingActivity.this, "分享记录与分享库");
|
}
|
});
|
|
cb_no_see_phone.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
@Override
|
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
UserCustomEvent.userSettingCommon(SettingActivity.this, "查看手机号");
|
}
|
});
|
|
noBonusCount = getIntent().getIntExtra("noBonusCount", 0);
|
shareRedPacket = getIntent().getIntExtra("shareRedPacket", 0);
|
noInvitationBonus = getIntent().getIntExtra("noInvitationBonus", 0);
|
noNewsRedDot = getIntent().getIntExtra("noNewsRedDot", 0);
|
noShareRecordAndStorage = getIntent().getIntExtra("noShareRecordAndStorage", 0);
|
noDisplayPhoneNum = getIntent().getIntExtra("noDisplayPhoneNum", 0);
|
|
cb_msg.setChecked(sp.getBoolean("doNotDisturb", false));
|
// cb_open_share_red_packet.setChecked(shareRedPacket == 1 ? true : false);
|
cb_no_see_red_point.setChecked(noNewsRedDot == 1 ? true : false);
|
cb_no_see_reward_statistics.setChecked(noBonusCount == 1 ? true : false);
|
cb_no_see_share_and_selection.setChecked(noShareRecordAndStorage == 1 ? true : false);
|
cb_no_see_phone.setChecked(noDisplayPhoneNum == 1 ? true : false);
|
}
|
|
@Override
|
protected void onResume() {
|
super.onResume();
|
// SharedPreferences sp = cb_msg.getContext().getSharedPreferences("user", MODE_PRIVATE);
|
// if (!sp.getString("push_off_no", "").equals("true_02")) {
|
// cb_msg.setChecked(false);
|
// }
|
}
|
|
@Override
|
public void onClick(View v) {
|
switch (v.getId()) {
|
case R.id.tv_top_bar_left:
|
// if (noBonusCount != (cb_no_see_reward_statistics.isChecked() ? 1 : 0)
|
// || noInvitationBonus != (cb_open_share_red_packet.isChecked() ? 1 : 0)
|
// || noNewsRedDot != (cb_no_see_red_point.isChecked() ? 1 : 0)
|
// || shareRedPacket != (cb_open_share_red_packet.isChecked() ? 1 : 0)
|
// || noShareRecordAndStorage != (cb_no_see_share_and_selection.isChecked() ? 1 : 0)) {
|
if (noBonusCount != (cb_no_see_reward_statistics.isChecked() ? 1 : 0)
|
|| noInvitationBonus != (1)
|
|| noNewsRedDot != (cb_no_see_red_point.isChecked() ? 1 : 0)
|
|| shareRedPacket != (1)
|
|| noShareRecordAndStorage != (cb_no_see_share_and_selection.isChecked() ? 1 : 0) || noDisplayPhoneNum != (cb_no_see_phone.isChecked() ? 1 : 0)) {
|
setModuleState();
|
} else {
|
finish();
|
}
|
break;
|
case R.id.ll_clear_cache:
|
if (tv_cache_num.getText().toString().equalsIgnoreCase("0.0M")) {
|
// SingleToast.showToast(SettingActivity.this, "已经没有缓存了!");
|
Toast.makeText(SettingActivity.this, "已经没有缓存了", Toast.LENGTH_SHORT).show();
|
return;
|
}
|
AddZFBInfoDialog2.Builder builder = new AddZFBInfoDialog2.Builder(SettingActivity.this);
|
builder.setTitle("温馨提示").setMessage("确定清除缓存")
|
.setPositiveButton("确定", new DialogInterface.OnClickListener() {
|
@Override
|
public void onClick(DialogInterface dialog, int which) {
|
DataCleanManager.clearAllCache(SettingActivity.this, tv_cache_num);
|
ImageLoader.getInstance().clearDiskCache();
|
ImageLoader.getInstance().clearMemoryCache();
|
new Thread(new Runnable() {
|
@Override
|
public void run() {
|
Glide.get(SettingActivity.this).clearMemory();
|
Glide.get(SettingActivity.this).clearDiskCache();
|
}
|
});
|
dialog.dismiss();
|
}
|
}).setNegativeButton("不了", new DialogInterface.OnClickListener() {
|
@Override
|
public void onClick(DialogInterface dialog, int which) {
|
dialog.dismiss();
|
}
|
}).create().show();
|
break;
|
case R.id.ll_check_update:
|
//自动更新
|
// AppUpdate.setAppUpdateActivity(this);
|
// AppUpdate.setAppUpdateKey(BuXinConstant.APP_UPDATE_KEY);
|
// AppUpdate.initAppUpdate(true);
|
UpdateApp app = new UpdateApp(this, getResources().getString(R.string.update_key));
|
app.getUpdateInfo(new UpdateApp.UpdateJudgeCallback() {
|
|
@Override
|
public void onSuccess(boolean show) {
|
|
}
|
|
@Override
|
public void closeUpdate(boolean close) {
|
|
}
|
|
@Override
|
public void onFinish() {
|
|
}
|
}, true);//强制检测更新
|
break;
|
case R.id.ll_exit_account://退出登陆
|
SharedPreferences sp = getSharedPreferences("user", MODE_PRIVATE);
|
if (sp.getBoolean("isLogin", false)) {
|
ShoppingApi.loginOut(SettingActivity.this, UserUtil.getUid(ShoppingApplication.application), null);
|
UserUtil.logout(SettingActivity.this);
|
loginOut();
|
}
|
break;
|
case R.id.ll_person_info:
|
|
if (!LoginAndInviteStatusUtil.acessNext(getApplicationContext(), UserUtil.getUid(getApplicationContext()) , true))
|
return;
|
|
if (getSharedPreferences("user", MODE_PRIVATE).getBoolean("isLogin", false)) {
|
startActivity(new Intent(SettingActivity.this, MyInfoActivity.class));
|
} else {
|
startActivity(new Intent(SettingActivity.this, LoginSelectActivity.class));
|
}
|
break;
|
case R.id.ll_account_grade:
|
if (!LoginAndInviteStatusUtil.acessNext(getApplicationContext(), UserUtil.getUid(getApplicationContext()) , true))
|
return;
|
startActivity(new Intent(SettingActivity.this, AccountGradeActivity.class));
|
break;
|
case R.id.ll_about_us:
|
Intent intent2 = new Intent(ll_about_us.getContext(), ShareBrowserActivity.class);
|
intent2.putExtra("url", SystemParamsUtil.getParam(getApplicationContext(), "about"));
|
intent2.putExtra("title", "关于我们");
|
startActivity(intent2);
|
break;
|
|
case R.id.ll_evaluate:
|
try {
|
String channel = GetManifestDataUtil.getAppMetaData(this, "UMENG_CHANNEL");
|
if ("huawei".equalsIgnoreCase(channel)) {
|
launchAppDetail(this, getPackageName(), "com.huawei.appmarket");
|
} else {
|
launchAppDetail(this, getPackageName(), "");
|
}
|
|
|
} catch (Exception e) { //找不到activity
|
// 打开应用商店失败 可能是没有手机没有安装应用市场
|
e.printStackTrace();
|
Toast.makeText(this, "未安装应用市场", Toast.LENGTH_SHORT).show();
|
}
|
break;
|
}
|
}
|
|
private static void launchAppDetail(Context context, String appPkg, String marketPkg) {
|
try {
|
if (TextUtils.isEmpty(appPkg)) return;
|
Uri uri = Uri.parse("market://details?id=" + appPkg);
|
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
|
if (!TextUtils.isEmpty(marketPkg)) {
|
intent.setPackage(marketPkg);
|
}
|
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
context.startActivity(intent);
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
}
|
|
|
/**
|
* 退出登录
|
*/
|
private void loginOut() {
|
AlibcLogin alibcLogin = AlibcLogin.getInstance();
|
alibcLogin.logout(new AlibcLoginCallback() {
|
|
@Override
|
public void onSuccess(int i, String s, String s1) {
|
ll_exit_account.setVisibility(View.GONE);
|
}
|
|
@Override
|
public void onFailure(int code, String msg) {
|
|
}
|
});
|
finish();
|
}
|
|
private void loginOutEditor() {
|
SharedPreferences sp = getSharedPreferences("user", MODE_PRIVATE);
|
SharedPreferences.Editor editor = sp.edit();
|
editor.putBoolean("isLogin", 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, "退出登录成功");
|
Toast.makeText(SettingActivity.this, "退出登录成功", Toast.LENGTH_SHORT).show();
|
finish();
|
}
|
|
/**
|
* 设置开关
|
*/
|
private void setModuleState() {
|
SharedPreferences sp = getSharedPreferences("user", MODE_PRIVATE);
|
JSONObject params1 = new JSONObject();
|
try {
|
params1.put("cancelNotice", (cb_msg.isChecked() ? 1 : 0));
|
params1.put("noNewsRedDot", (cb_no_see_red_point.isChecked() ? 1 : 0));
|
params1.put("noBonusCount", (cb_no_see_reward_statistics.isChecked() ? 1 : 0));
|
params1.put("noShareRecordAndStorage", (cb_no_see_share_and_selection.isChecked() ? 1 : 0));
|
params1.put("noDisplayPhoneNum", (cb_no_see_phone.isChecked() ? 1 : 0));
|
} catch (JSONException e) {
|
|
}
|
|
ShoppingApi.setModuleState(getApplicationContext(), UserUtil.getUid(ShoppingApplication.application), params1.toString(), new BasicTextHttpResponseHandler() {
|
|
@Override
|
public void onFinish() {
|
super.onFinish();
|
finish();
|
}
|
|
});
|
}
|
|
@Override
|
protected void onDestroy() {
|
super.onDestroy();
|
// AppUpdate.destoryAppUpdate();
|
}
|
|
@Override
|
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
if (keyCode == event.KEYCODE_BACK) {
|
// if (noBonusCount != (cb_no_see_reward_statistics.isChecked() ? 1 : 0)
|
// || noInvitationBonus != (cb_open_share_red_packet.isChecked() ? 1 : 0)
|
// || noNewsRedDot != (cb_no_see_red_point.isChecked() ? 1 : 0)
|
// || shareRedPacket != (cb_open_share_red_packet.isChecked() ? 1 : 0)
|
// || noShareRecordAndStorage != (cb_no_see_share_and_selection.isChecked() ? 1 : 0)) {
|
if (noBonusCount != (cb_no_see_reward_statistics.isChecked() ? 1 : 0)
|
|| noInvitationBonus != (1)
|
|| noNewsRedDot != (cb_no_see_red_point.isChecked() ? 1 : 0)
|
|| shareRedPacket != (1)
|
|| noShareRecordAndStorage != (cb_no_see_share_and_selection.isChecked() ? 1 : 0)) {
|
setModuleState();
|
return true;
|
} else {
|
return super.onKeyDown(keyCode, event);
|
}
|
|
} else {
|
return super.onKeyDown(keyCode, event);
|
}
|
}
|
}
|