version:2.6
fix:更新retrofit,优化请求次数 update:
This commit is contained in:
81
app/src/main/java/com/aoleyun/sn/manager/ConnectManager.java
Normal file
81
app/src/main/java/com/aoleyun/sn/manager/ConnectManager.java
Normal file
@@ -0,0 +1,81 @@
|
||||
package com.aoleyun.sn.manager;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
|
||||
import com.aoleyun.sn.utils.TimeUtils;
|
||||
import com.tencent.mmkv.MMKV;
|
||||
|
||||
public class ConnectManager {
|
||||
private static final String TAG = ConnectManager.class.getSimpleName();
|
||||
|
||||
/*重启后连接成功的时间*/
|
||||
public static final String REBOOT_LAST_ONNECT_TIME = "reboot_last_connect_time";
|
||||
/*WiFi连接后连接成功的时间*/
|
||||
public static final String WIFI_LAST_CONNECT_TIME = "WiFi_last_connect_time";
|
||||
/*打开设备信息连接成功的时间*/
|
||||
public static final String OPENINFO_LAST_ONNECT_TIME = "opneinfo_last_connect_time";
|
||||
|
||||
|
||||
@SuppressLint("StaticFieldLeak")
|
||||
private static ConnectManager sInstance;
|
||||
private Context mContext;
|
||||
private MMKV mMMKV = MMKV.defaultMMKV();
|
||||
|
||||
private ConnectManager(Context context) {
|
||||
if (context == null) {
|
||||
throw new RuntimeException("Context is NULL");
|
||||
}
|
||||
this.mContext = context;
|
||||
|
||||
}
|
||||
|
||||
public static void init(Context context) {
|
||||
if (sInstance == null) {
|
||||
Log.e(TAG, "init: ");
|
||||
sInstance = new ConnectManager(context);
|
||||
}
|
||||
}
|
||||
|
||||
public static ConnectManager getInstance() {
|
||||
if (sInstance == null) {
|
||||
throw new IllegalStateException("You must be init ConnectManager first");
|
||||
}
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return 今天重启后是否连接
|
||||
*/
|
||||
public boolean isRebootFistConnect() {
|
||||
long time = mMMKV.decodeLong(REBOOT_LAST_ONNECT_TIME, 0);
|
||||
return !TimeUtils.isTodayTime(time);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return 今天WiFi连接是否有连接
|
||||
*/
|
||||
public boolean isWiFiFistConnect() {
|
||||
long time = mMMKV.decodeLong(WIFI_LAST_CONNECT_TIME, 0);
|
||||
return !TimeUtils.isTodayTime(time);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return 今天打开设备信息后是否连接
|
||||
*/
|
||||
public boolean isOpenInfoFistConnect() {
|
||||
long time = mMMKV.decodeLong(OPENINFO_LAST_ONNECT_TIME, 0);
|
||||
return !TimeUtils.isTodayTime(time);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param WiFiAlias
|
||||
* @return 今天切换WiFi后是否连接
|
||||
*/
|
||||
public boolean isWiFiCutoverFistConnect(String WiFiAlias) {
|
||||
long time = mMMKV.decodeLong(WiFiAlias, 0);
|
||||
return !TimeUtils.isTodayTime(time);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user