Initial commit
This commit is contained in:
255
sources/com/ubt/jimu/base/cache/Cache.java
vendored
Normal file
255
sources/com/ubt/jimu/base/cache/Cache.java
vendored
Normal file
@@ -0,0 +1,255 @@
|
||||
package com.ubt.jimu.base.cache;
|
||||
|
||||
import android.bluetooth.BluetoothDevice;
|
||||
import android.text.TextUtils;
|
||||
import com.ubt.jimu.JimuApplication;
|
||||
import com.ubt.jimu.base.db.robot.RobotDbHandler;
|
||||
import com.ubt.jimu.base.db.user.UserDbHandler;
|
||||
import com.ubt.jimu.base.entities.Constant;
|
||||
import com.ubt.jimu.base.entities.Robot;
|
||||
import com.ubt.jimu.base.entities.User;
|
||||
import com.ubt.jimu.course.repository.JimuCourse;
|
||||
import com.ubt.jimu.course.repository.JimuCourseMission;
|
||||
import com.ubt.jimu.course.repository.JimuCourseTask;
|
||||
import com.ubtech.utils.XLog;
|
||||
import com.ubtrobot.jimu.robotapi.BoardInfo;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public class Cache {
|
||||
private static final String TAG = "Cache";
|
||||
private static Cache instance;
|
||||
private boolean connected;
|
||||
private JimuCourseMission courseMission;
|
||||
private List<JimuCourseTask> courseTaskList;
|
||||
private JimuCourse jimuCourse;
|
||||
private JimuCourseTask jimuCourseTask;
|
||||
private String mBlocklyTestUrl;
|
||||
private BoardInfo mBoardInfo;
|
||||
private BluetoothDevice mLastConnectedDevice;
|
||||
private long packageId;
|
||||
private String packageImagePath;
|
||||
private String packageName;
|
||||
private Robot robot;
|
||||
private User user;
|
||||
private boolean showMobileDataTips = false;
|
||||
public long differ = 0;
|
||||
private SharePreferenceHelper settings = new SharePreferenceHelper();
|
||||
|
||||
private Cache() {
|
||||
}
|
||||
|
||||
public static synchronized Cache getInstance() {
|
||||
Cache cache;
|
||||
synchronized (Cache.class) {
|
||||
if (instance == null) {
|
||||
instance = new Cache();
|
||||
}
|
||||
cache = instance;
|
||||
}
|
||||
return cache;
|
||||
}
|
||||
|
||||
public void clearCacheUser() {
|
||||
setUser(null);
|
||||
this.settings.put(SharePreferenceHelper.SP_KEY_USER_ID, "local");
|
||||
this.settings.put(SharePreferenceHelper.AUTHOR_TOKEN, "");
|
||||
}
|
||||
|
||||
public String getBlocklyTest() {
|
||||
return this.mBlocklyTestUrl;
|
||||
}
|
||||
|
||||
public BoardInfo getBoardInfo() {
|
||||
return this.mBoardInfo;
|
||||
}
|
||||
|
||||
public JimuCourseMission getCourseMission() {
|
||||
return this.courseMission;
|
||||
}
|
||||
|
||||
public List<JimuCourseTask> getCourseTaskList() {
|
||||
return this.courseTaskList;
|
||||
}
|
||||
|
||||
public JimuCourse getJimuCourse() {
|
||||
return this.jimuCourse;
|
||||
}
|
||||
|
||||
public JimuCourseTask getJimuCourseTask() {
|
||||
return this.jimuCourseTask;
|
||||
}
|
||||
|
||||
public BluetoothDevice getLastConnectedDevice() {
|
||||
return this.mLastConnectedDevice;
|
||||
}
|
||||
|
||||
public long getLoginUserIntId() {
|
||||
String string = this.settings.getString(SharePreferenceHelper.SP_KEY_USER_ID, "");
|
||||
if (TextUtils.isEmpty(string) || string.equals("local") || Integer.parseInt(string) <= 0) {
|
||||
return 0L;
|
||||
}
|
||||
return Integer.parseInt(string);
|
||||
}
|
||||
|
||||
public long getPackageId() {
|
||||
this.packageId = this.settings.getLong(SharePreferenceHelper.SP_KEY_PACKAGE_ID, 0L).longValue();
|
||||
return this.packageId;
|
||||
}
|
||||
|
||||
public String getPackageImagePath() {
|
||||
return this.settings.getString(SharePreferenceHelper.CURRENT_PACKAGE_IMAGE_PATH, null);
|
||||
}
|
||||
|
||||
public String getPackageName() {
|
||||
this.packageName = this.settings.getString(SharePreferenceHelper.SP_KEY_PACKAGE_NAME, "");
|
||||
return this.packageName;
|
||||
}
|
||||
|
||||
public Robot getRobot() {
|
||||
if (this.robot == null) {
|
||||
long longValue = this.settings.getLong(SharePreferenceHelper.SP_KEY_ROBOT_ID, -1L).longValue();
|
||||
long longValue2 = this.settings.getLong(SharePreferenceHelper.SP_KEY_PACKAGE_ID, -1L).longValue();
|
||||
if (longValue < 0 || longValue2 < 0) {
|
||||
return null;
|
||||
}
|
||||
Robot robotById = RobotDbHandler.getRobotById(longValue);
|
||||
if (robotById != null) {
|
||||
setRobot(robotById);
|
||||
}
|
||||
}
|
||||
return this.robot;
|
||||
}
|
||||
|
||||
public SharePreferenceHelper getSettings() {
|
||||
return this.settings;
|
||||
}
|
||||
|
||||
public String getTTSToken() {
|
||||
return this.settings.getString(Constant.Cache.SP_KEY_TTS_TOKEN, "");
|
||||
}
|
||||
|
||||
public User getUser() {
|
||||
if (this.user == null) {
|
||||
this.user = UserDbHandler.getUser();
|
||||
}
|
||||
return this.user;
|
||||
}
|
||||
|
||||
public String getUserId() {
|
||||
return this.settings.getString(SharePreferenceHelper.SP_KEY_USER_ID, "local");
|
||||
}
|
||||
|
||||
public String getUserToken() {
|
||||
return this.settings.getString(SharePreferenceHelper.AUTHOR_TOKEN, "");
|
||||
}
|
||||
|
||||
public String getUuid() {
|
||||
String string = this.settings.getString(SharePreferenceHelper.SP_KEY_UUID, "");
|
||||
if (!TextUtils.isEmpty(string)) {
|
||||
return string;
|
||||
}
|
||||
String replace = UUID.randomUUID().toString().replace("-", "");
|
||||
XLog.d("woo", "UUID.rancomUUID: " + replace, new Object[0]);
|
||||
this.settings.put(SharePreferenceHelper.SP_KEY_UUID, replace);
|
||||
return replace;
|
||||
}
|
||||
|
||||
public int getVersionCode() {
|
||||
return this.settings.getInt(Constant.Cache.APP_VERSION_CODE, 0);
|
||||
}
|
||||
|
||||
public boolean isConnected() {
|
||||
return this.connected;
|
||||
}
|
||||
|
||||
public boolean isShowMobileDataTips() {
|
||||
return this.showMobileDataTips;
|
||||
}
|
||||
|
||||
public boolean isWifiOnly() {
|
||||
return this.settings.getBoolean(SharePreferenceHelper.SP_KEY_WIFI_VIEW, true).booleanValue();
|
||||
}
|
||||
|
||||
public void putBoolean(String str, boolean z) {
|
||||
this.settings.put(str, Boolean.valueOf(z));
|
||||
}
|
||||
|
||||
public void putInt(String str, int i) {
|
||||
this.settings.put(str, Integer.valueOf(i));
|
||||
}
|
||||
|
||||
public void putString(String str, String str2) {
|
||||
this.settings.put(str, str2);
|
||||
}
|
||||
|
||||
public void setBlocklyTestUrl(String str) {
|
||||
this.mBlocklyTestUrl = str;
|
||||
}
|
||||
|
||||
public void setBoardInfo(BoardInfo boardInfo) {
|
||||
this.mBoardInfo = boardInfo;
|
||||
}
|
||||
|
||||
public void setConnected(boolean z) {
|
||||
this.connected = z;
|
||||
}
|
||||
|
||||
public void setCourseMission(JimuCourseMission jimuCourseMission) {
|
||||
this.courseMission = jimuCourseMission;
|
||||
}
|
||||
|
||||
public void setCourseTaskList(List<JimuCourseTask> list) {
|
||||
this.courseTaskList = list;
|
||||
}
|
||||
|
||||
public void setJimuCourse(JimuCourse jimuCourse) {
|
||||
this.jimuCourse = jimuCourse;
|
||||
}
|
||||
|
||||
public void setJimuCourseTask(JimuCourseTask jimuCourseTask) {
|
||||
this.jimuCourseTask = jimuCourseTask;
|
||||
}
|
||||
|
||||
public void setLastConnectedDevice(BluetoothDevice bluetoothDevice) {
|
||||
this.mLastConnectedDevice = bluetoothDevice;
|
||||
}
|
||||
|
||||
public void setPackageId(long j) {
|
||||
this.packageId = j;
|
||||
this.settings.put(SharePreferenceHelper.SP_KEY_PACKAGE_ID, Long.valueOf(j));
|
||||
}
|
||||
|
||||
public void setPackageImagePath(String str) {
|
||||
this.packageImagePath = str;
|
||||
this.settings.put(SharePreferenceHelper.CURRENT_PACKAGE_IMAGE_PATH, str);
|
||||
}
|
||||
|
||||
public void setPackageName(String str) {
|
||||
this.packageName = str;
|
||||
this.settings.put(SharePreferenceHelper.SP_KEY_PACKAGE_NAME, str);
|
||||
}
|
||||
|
||||
public void setRobot(Robot robot) {
|
||||
Robot robot2;
|
||||
if (robot == null) {
|
||||
return;
|
||||
}
|
||||
if (robot.getModelName() != null && (robot2 = this.robot) != null && robot2.getModelName() != null && !robot.getModelName().equals(this.robot.getModelName())) {
|
||||
JimuApplication.l().f().c();
|
||||
}
|
||||
this.robot = robot;
|
||||
this.settings.put(SharePreferenceHelper.SP_KEY_ROBOT_NAME, robot.getModelNameLanguage());
|
||||
this.settings.put(SharePreferenceHelper.SP_KEY_ROBOT_IMAGE, robot.getFilePath());
|
||||
this.settings.put(SharePreferenceHelper.SP_KEY_ROBOT_ID, Long.valueOf(robot.getModelId()));
|
||||
}
|
||||
|
||||
public void setShowMobileDataTips(boolean z) {
|
||||
this.showMobileDataTips = z;
|
||||
}
|
||||
|
||||
public void setUser(User user) {
|
||||
this.user = user;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user