更换包名

This commit is contained in:
2022-09-27 19:11:46 +08:00
parent 35c747a334
commit 4f671a3b75
148 changed files with 585 additions and 630 deletions

View File

@@ -0,0 +1,75 @@
package com.fuying.sn.desktop;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import java.io.Serializable;
public class AppRunTimeBean implements Serializable {
private static final long serialVersionUID = 3699088127005434759L;
String packageName;
Long appRunTime;
AppRunTimeBean() {
this.appRunTime = 0L;
}
AppRunTimeBean(String pkg) {
this.packageName = pkg;
this.appRunTime = 0L;
}
AppRunTimeBean(String pkg, long time) {
this.packageName = pkg;
this.appRunTime = time;
}
public String getPackageName() {
return packageName;
}
public void setPackageName(String packageName) {
this.packageName = packageName;
}
public void reduceTime(Long time) {
this.appRunTime -= time;
}
public Long getAppRunTime() {
return appRunTime;
}
public void setAppRunTime(Long appRunTime) {
this.appRunTime = appRunTime;
}
@NonNull
@Override
public String toString() {
Gson gson = new Gson();
JsonObject jsonObject = JsonParser.parseString(gson.toJson(this)).getAsJsonObject();
return jsonObject.toString();
}
@Override
public int hashCode() {
return super.hashCode();
}
@Override
public boolean equals(@Nullable Object obj) {
if (obj instanceof AppRunTimeBean) {
AppRunTimeBean appRunTimeBean = (AppRunTimeBean) obj;
return appRunTimeBean.packageName.equals(packageName)
&& appRunTimeBean.appRunTime.equals(appRunTime);
} else {
return false;
}
}
}

View File

@@ -0,0 +1,140 @@
package com.fuying.sn.desktop;
import androidx.annotation.NonNull;
import com.google.gson.Gson;
import com.google.gson.JsonParser;
import com.fuying.sn.bean.PartTime;
import java.io.Serializable;
import java.util.List;
public class AppTimeControl implements Serializable {
private static final long serialVersionUID = -240088037272271214L;
String app_package;
//使用控制方式 0始终可用 1分类 2整机 3自由
int tc_use_type;
//分类使用控制方式 0始终可用 1整机 2自由
int class_use_type;
//控制方式开关 0关1开
int is_control;
//使用额度开关 0关1开
int is_quota;
//使用时间段开关 0关1开
int is_part;
//上学日可使用时间 单位秒
long work_time;
//休息日可使用时间 单位秒
long rest_time;
//使用时间段类型 0禁用 1开放
int part_type;
//使用时间段
List<PartTime> time_part;
//今日可用时间
long today_time;
//分类ID
int tc_class_id;
public String getApp_package() {
return app_package;
}
public void setApp_package(String app_package) {
this.app_package = app_package;
}
public int getTc_use_type() {
return tc_use_type;
}
public void setTc_use_type(int tc_use_type) {
this.tc_use_type = tc_use_type;
}
public int getClass_use_type() {
return class_use_type;
}
public void setClass_use_type(int class_use_type) {
this.class_use_type = class_use_type;
}
public int getIs_control() {
return is_control;
}
public void setIs_control(int is_control) {
this.is_control = is_control;
}
public int getIs_quota() {
return is_quota;
}
public void setIs_quota(int is_quota) {
this.is_quota = is_quota;
}
public int getIs_part() {
return is_part;
}
public void setIs_part(int is_part) {
this.is_part = is_part;
}
public long getWork_time() {
return work_time;
}
public void setWork_time(long work_time) {
this.work_time = work_time;
}
public long getRest_time() {
return rest_time;
}
public void setRest_time(long rest_time) {
this.rest_time = rest_time;
}
public int getPart_type() {
return part_type;
}
public void setPart_type(int part_type) {
this.part_type = part_type;
}
public List<PartTime> getTime_part() {
return time_part;
}
public void setTime_part(List<PartTime> time_part) {
this.time_part = time_part;
}
public long getToday_time() {
return today_time;
}
public void setToday_time(long today_time) {
this.today_time = today_time;
}
public int getTc_class_id() {
return tc_class_id;
}
public void setTc_class_id(int tc_class_id) {
this.tc_class_id = tc_class_id;
}
@NonNull
@Override
public String toString() {
return JsonParser.parseString(new Gson().toJson(this)).getAsJsonObject().toString();
}
}

View File

@@ -0,0 +1,101 @@
package com.fuying.sn.desktop;
import androidx.annotation.NonNull;
import com.google.gson.Gson;
import com.google.gson.JsonParser;
import com.fuying.sn.bean.PartTime;
import java.io.Serializable;
import java.util.List;
public class MachineControl implements Serializable {
private static final long serialVersionUID = 8554412088242960068L;
int id;
/*是否开启整机额度*/
int is_quota;
/*上学日额度*/
long work_time;
/*休息日额度*/
long rest_time;
/*整机使用时间段控制*/
int is_part;
/*开放或者禁用类型*/
int part_type;
/*今日剩余时长*/
long today_time;
/*上学日时间段*/
List<PartTime> time_part;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public int getIs_quota() {
return is_quota;
}
public void setIs_quota(int is_quota) {
this.is_quota = is_quota;
}
public long getWork_time() {
return work_time;
}
public void setWork_time(long work_time) {
this.work_time = work_time;
}
public long getRest_time() {
return rest_time;
}
public void setRest_time(long rest_time) {
this.rest_time = rest_time;
}
public int getIs_part() {
return is_part;
}
public void setIs_part(int is_part) {
this.is_part = is_part;
}
public int getPart_type() {
return part_type;
}
public void setPart_type(int part_type) {
this.part_type = part_type;
}
public long getToday_time() {
return today_time;
}
public void setToday_time(long today_time) {
this.today_time = today_time;
}
public List<PartTime> getTime_part() {
return time_part;
}
public void setTime_part(List<PartTime> time_part) {
this.time_part = time_part;
}
@NonNull
@Override
public String toString() {
return JsonParser.parseString(new Gson().toJson(this)).getAsJsonObject().toString();
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,186 @@
package com.fuying.sn.desktop;
import android.annotation.SuppressLint;
import android.content.Context;
import android.text.TextUtils;
import android.util.Log;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.fuying.sn.disklrucache.CacheHelper;
import com.fuying.sn.network.UrlAddress;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.stream.Collectors;
public class TimeControlManager {
private static final String TAG = TimeControlManager.class.getSimpleName();
@SuppressLint("StaticFieldLeak")
private static TimeControlManager mTimeControlManager;
private Context mContext;
private CacheHelper mCacheHelper;
private HashMap<Integer, AppTimeControl> mClassifyTimeControlHashMap = new HashMap<>();
/*分类的所有包名列表*/
private HashMap<String, AppTimeControl> mAppTimeControlMap = new HashMap<>();
/*整机分类*/
private MachineControl mGlobalMachineControl;
private TimeControlManager(Context context) {
if (context == null) {
throw new RuntimeException("Context is NULL");
}
this.mContext = context;
this.mCacheHelper = new CacheHelper(context);
String appTimeControlJson = mCacheHelper.getAsString(UrlAddress.GET_APP_TIME_CONTROL);
if (!TextUtils.isEmpty(appTimeControlJson)) {
Gson gson = new Gson();
Type type = new TypeToken<List<AppTimeControl>>() {
}.getType();
List<AppTimeControl> appTimeControls = gson.fromJson(appTimeControlJson, type);
setAppTimeControlMap(appTimeControls);
}
}
public static void init(Context context) {
if (mTimeControlManager == null) {
mTimeControlManager = new TimeControlManager(context);
}
}
public static TimeControlManager getInstance() {
if (mTimeControlManager == null) {
throw new IllegalStateException("You must be init TimeControlManager first");
}
return mTimeControlManager;
}
public HashMap<String, AppTimeControl> getAppTimeControlMap() {
return mAppTimeControlMap;
}
/**
* 判断是否有配置存在
*
* @param pkg
* @return
*/
public boolean havaConfigure(String pkg) {
AppTimeControl appTimeControl = mAppTimeControlMap.get(pkg);
if (appTimeControl == null) {
Log.e(TAG, "havaConfigure: not");
return false;
} else {
if (appTimeControl.getTc_use_type() == 1) {
Log.e(TAG, "havaConfigure: classify");
return mClassifyTimeControlHashMap.get(appTimeControl.getTc_class_id()) != null;
}
Log.e(TAG, "havaConfigure: hava");
return true;
}
}
/**
* 获取整机配置
*
* @return
*/
public MachineControl getGlobalMachineControl() {
if (mGlobalMachineControl == null) {
String jsonString = mCacheHelper.getAsString(UrlAddress.GET_SN_TIME_CONTROL);
//为 "" 是已经请求成功的
if (jsonString == null) {
return null;
} else {
Gson gson = new Gson();
Type Type = new TypeToken<MachineControl>() {
}.getType();
MachineControl machineControl = gson.fromJson(jsonString, Type);
return machineControl;
}
} else {
return mGlobalMachineControl;
}
}
public void setGlobalMachineControl(MachineControl machineControl) {
this.mGlobalMachineControl = machineControl;
if (machineControl != null) {
RunningAppManager.getInstance().setGlobalUsageTime(machineControl.getRest_time());
}
}
/**
* 获取app的配置
*
* @param pkg
* @return
*/
public AppTimeControl getAppTimeControl(String pkg) {
AppTimeControl temp = mAppTimeControlMap.get(pkg);
if (temp == null) {
String jsonString = mCacheHelper.getAsString(UrlAddress.GET_APP_TIME_CONTROL);
//为 "" 是已经请求成功的
if (jsonString == null) {
return null;
} else {
Gson gson = new Gson();
Type Type = new TypeToken<List<AppTimeControl>>() {
}.getType();
List<AppTimeControl> appTimeControlList = gson.fromJson(jsonString, Type);
if (appTimeControlList == null) {
return null;
}
HashMap<String, AppTimeControl> appTimeControlMap = new HashMap<>();
for (AppTimeControl appTimeControl : appTimeControlList) {
appTimeControlMap.put(appTimeControl.getApp_package(), appTimeControl);
}
setAppTimeControlMap(appTimeControlList);
return appTimeControlMap.get(pkg);
}
} else {
return temp;
}
}
public void setAppTimeControl(String pkg, AppTimeControl appTimeControl) {
this.mAppTimeControlMap.put(pkg, appTimeControl);
}
/**
* 设置app的配置
*
* @param appTimeControlList
*/
public void setAppTimeControlMap(List<AppTimeControl> appTimeControlList) {
if (appTimeControlList == null || appTimeControlList.size() == 0) {
return;
}
HashMap<Integer, AppTimeControl> classifyTimeControlHashMap = new HashMap<>();
List<AppTimeControl> filterAppTimeControlList = appTimeControlList.stream().filter(appTimeControl -> {
//tc_use_type == 1 时用的是分类配置,配置都是一样的
return appTimeControl.getTc_use_type() == 1;
}).collect(Collectors.toList());
for (AppTimeControl appTimeControl : filterAppTimeControlList) {
classifyTimeControlHashMap.put(appTimeControl.getTc_class_id(), appTimeControl);
}
this.mClassifyTimeControlHashMap = classifyTimeControlHashMap;
HashMap<String, AppTimeControl> appTimeControlMap = new HashMap<>();
List<AppTimeControl> appTimeControls = new ArrayList<>();
for (AppTimeControl appTimeControl : appTimeControlList) {
// TODO: 2022/6/30 修改为全部配置
// if (appTimeControl.getTc_use_type() != 1) {
appTimeControlMap.put(appTimeControl.getApp_package(), appTimeControl);
appTimeControls.add(appTimeControl);
// }
}
RunningAppManager.getInstance().syncAppRemainingTime(appTimeControls);
this.mAppTimeControlMap = appTimeControlMap;
}
}