package com.video.youth.util;
|
|
import android.content.Context;
|
import android.content.SharedPreferences;
|
|
import com.lcjian.library.util.common.StringUtils;
|
import com.video.youth.entity.YouthModeChange;
|
|
import org.greenrobot.eventbus.EventBus;
|
|
|
public class YouthUtil {
|
|
/**
|
* 是否开启了青少年模式
|
*
|
* @param context
|
* @return
|
*/
|
public static boolean isOpenYouthMode(Context context) {
|
SharedPreferences sharedPreferences = context.getSharedPreferences("youth_setting", Context.MODE_PRIVATE);
|
return sharedPreferences.getBoolean("open", false);
|
}
|
|
/**
|
* 关闭青少年模式
|
*
|
* @param context
|
*/
|
public static void openYouthMode(Context context) {
|
SharedPreferences sharedPreferences = context.getSharedPreferences("youth_setting", Context.MODE_PRIVATE);
|
SharedPreferences.Editor editor = sharedPreferences.edit();
|
editor.putBoolean("open", true);
|
editor.commit();
|
EventBus.getDefault().post(new YouthModeChange(true));
|
}
|
|
/**
|
* 关闭青少年模式
|
*
|
* @param context
|
*/
|
public static void closeYouthMode(Context context) {
|
SharedPreferences sharedPreferences = context.getSharedPreferences("youth_setting", Context.MODE_PRIVATE);
|
SharedPreferences.Editor editor = sharedPreferences.edit();
|
editor.putBoolean("open", false);
|
editor.commit();
|
EventBus.getDefault().post(new YouthModeChange(false));
|
}
|
|
/**
|
* 设置密码
|
*
|
* @param context
|
* @param pwd
|
*/
|
public static void setPwd(Context context, String pwd) {
|
SharedPreferences sharedPreferences = context.getSharedPreferences("youth_setting", Context.MODE_PRIVATE);
|
SharedPreferences.Editor editor = sharedPreferences.edit();
|
editor.putString("pwd", pwd);
|
editor.commit();
|
}
|
|
/**
|
* 密码是否正确
|
*
|
* @param context
|
* @param pwd
|
* @return
|
*/
|
public static boolean isPwdRight(Context context, String pwd) {
|
SharedPreferences sharedPreferences = context.getSharedPreferences("youth_setting", Context.MODE_PRIVATE);
|
String old = sharedPreferences.getString("pwd", "");
|
return old.equalsIgnoreCase(pwd);
|
}
|
|
|
/**
|
* 是否设置了密码
|
*
|
* @param context
|
* @return
|
*/
|
public static boolean isSetPwd(Context context) {
|
SharedPreferences sharedPreferences = context.getSharedPreferences("youth_setting", Context.MODE_PRIVATE);
|
String old = sharedPreferences.getString("pwd", "");
|
return !StringUtils.isBlank(old);
|
}
|
|
|
}
|