|
@@ -7,10 +7,10 @@ import com.sheep.gamegroup.model.entity.AppRecord;
|
|
|
import com.sheep.gamegroup.model.entity.AppUsage;
|
|
import com.sheep.gamegroup.model.entity.AppUsage;
|
|
|
import com.sheep.gamegroup.model.entity.LoginUser;
|
|
import com.sheep.gamegroup.model.entity.LoginUser;
|
|
|
import com.sheep.gamegroup.model.entity.NewbieTaskRecord;
|
|
import com.sheep.gamegroup.model.entity.NewbieTaskRecord;
|
|
|
|
|
+import com.sheep.gamegroup.model.entity.SearchAppRecord;
|
|
|
import com.sheep.gamegroup.model.entity.SearchGameRecord;
|
|
import com.sheep.gamegroup.model.entity.SearchGameRecord;
|
|
|
import com.sheep.gamegroup.model.entity.UserEntity;
|
|
import com.sheep.gamegroup.model.entity.UserEntity;
|
|
|
import com.sheep.jiuyan.samllsheep.SheepApp;
|
|
import com.sheep.jiuyan.samllsheep.SheepApp;
|
|
|
-import com.sheep.jiuyan.samllsheep.utils.SpUtils;
|
|
|
|
|
|
|
|
|
|
import org.xutils.DbManager;
|
|
import org.xutils.DbManager;
|
|
|
import org.xutils.ex.DbException;
|
|
import org.xutils.ex.DbException;
|
|
@@ -34,18 +34,18 @@ public class MyDbManager {
|
|
|
db = x.getDb(daoConfig);
|
|
db = x.getDb(daoConfig);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public static MyDbManager getInstance(){
|
|
|
|
|
- if (myDbManager == null){
|
|
|
|
|
|
|
+ public static MyDbManager getInstance() {
|
|
|
|
|
+ if (myDbManager == null) {
|
|
|
myDbManager = new MyDbManager();
|
|
myDbManager = new MyDbManager();
|
|
|
}
|
|
}
|
|
|
return myDbManager;
|
|
return myDbManager;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- *保存或更新表表
|
|
|
|
|
|
|
+ * 保存或更新表表
|
|
|
*/
|
|
*/
|
|
|
public void saveOrUpdateUser(final UserEntity user) throws DbException {
|
|
public void saveOrUpdateUser(final UserEntity user) throws DbException {
|
|
|
- if(user != null){
|
|
|
|
|
|
|
+ if (user != null) {
|
|
|
DataUtil.getInstance().setUserEntity(user);
|
|
DataUtil.getInstance().setUserEntity(user);
|
|
|
deleteTable(UserEntity.class);//先清空表
|
|
deleteTable(UserEntity.class);//先清空表
|
|
|
new Handler().postDelayed(new Runnable() {
|
|
new Handler().postDelayed(new Runnable() {
|
|
@@ -66,66 +66,70 @@ public class MyDbManager {
|
|
|
/**
|
|
/**
|
|
|
* 查找NewbieTaskRecord
|
|
* 查找NewbieTaskRecord
|
|
|
*/
|
|
*/
|
|
|
- public NewbieTaskRecord dbFindNewbieTaskRecord(String invitation_code) throws DbException{
|
|
|
|
|
|
|
+ public NewbieTaskRecord dbFindNewbieTaskRecord(String invitation_code) throws DbException {
|
|
|
return db.findById(NewbieTaskRecord.class, invitation_code);
|
|
return db.findById(NewbieTaskRecord.class, invitation_code);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- *保存或更新表表
|
|
|
|
|
|
|
+ * 保存或更新表表
|
|
|
*/
|
|
*/
|
|
|
public void saveOrUpdate(Object o) {
|
|
public void saveOrUpdate(Object o) {
|
|
|
- try{
|
|
|
|
|
|
|
+ try {
|
|
|
db.saveOrUpdate(o);
|
|
db.saveOrUpdate(o);
|
|
|
- }catch (Exception e){
|
|
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- *删除表
|
|
|
|
|
|
|
+ * 删除表
|
|
|
|
|
+ *
|
|
|
* @param o
|
|
* @param o
|
|
|
*/
|
|
*/
|
|
|
- public void deleteTable(Class<?> o){
|
|
|
|
|
|
|
+ public void deleteTable(Class<?> o) {
|
|
|
try {
|
|
try {
|
|
|
db.dropTable(o);
|
|
db.dropTable(o);
|
|
|
- }catch (Exception e){
|
|
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- public List<AppRecord> getAppRecordList(String packageName){
|
|
|
|
|
- try{
|
|
|
|
|
|
|
+
|
|
|
|
|
+ public List<AppRecord> getAppRecordList(String packageName) {
|
|
|
|
|
+ try {
|
|
|
return db.selector(AppRecord.class)
|
|
return db.selector(AppRecord.class)
|
|
|
.where("package_name", "=", packageName)
|
|
.where("package_name", "=", packageName)
|
|
|
.findAll();
|
|
.findAll();
|
|
|
- }catch (Exception e){
|
|
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
|
}
|
|
}
|
|
|
return ListUtil.emptyList();
|
|
return ListUtil.emptyList();
|
|
|
}
|
|
}
|
|
|
- public void removeAppRecord(){
|
|
|
|
|
- try{
|
|
|
|
|
|
|
+
|
|
|
|
|
+ public void removeAppRecord() {
|
|
|
|
|
+ try {
|
|
|
db.dropTable(AppRecord.class);
|
|
db.dropTable(AppRecord.class);
|
|
|
// String sql = String.format(Locale.CHINA,"delete from app_record where package_name in('%s')" , packageName);
|
|
// String sql = String.format(Locale.CHINA,"delete from app_record where package_name in('%s')" , packageName);
|
|
|
// Cursor cursor = db.execQuery(sql);
|
|
// Cursor cursor = db.execQuery(sql);
|
|
|
// cursor.close();
|
|
// cursor.close();
|
|
|
- }catch (Exception e){
|
|
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- public long getAppRunTime(String packageName){
|
|
|
|
|
- try{
|
|
|
|
|
- //type_id 为32时对应 AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED
|
|
|
|
|
|
|
+
|
|
|
|
|
+ public long getAppRunTime(String packageName) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ //type_id 为32时对应 AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED
|
|
|
// Cursor cursor = db.execQuery(String.format(Locale.CHINA,"select sum(time) as all_time from app_record where package_name = '%s' and type_id = 32" , packageName));
|
|
// Cursor cursor = db.execQuery(String.format(Locale.CHINA,"select sum(time) as all_time from app_record where package_name = '%s' and type_id = 32" , packageName));
|
|
|
// Cursor cursor = db.execQuery(String.format(Locale.CHINA,"select sum(time) from app_record where package_name = '%s' and time > %d" , packageName, AutoTaskListUtil.getInstance().getFindTime()));
|
|
// Cursor cursor = db.execQuery(String.format(Locale.CHINA,"select sum(time) from app_record where package_name = '%s' and time > %d" , packageName, AutoTaskListUtil.getInstance().getFindTime()));
|
|
|
- Cursor cursor = db.execQuery(String.format(Locale.CHINA,"select sum(time) from app_record where package_name = '%s'" , packageName));
|
|
|
|
|
|
|
+ Cursor cursor = db.execQuery(String.format(Locale.CHINA, "select sum(time) from app_record where package_name = '%s'", packageName));
|
|
|
cursor.moveToFirst();
|
|
cursor.moveToFirst();
|
|
|
long time = cursor.getLong(0);
|
|
long time = cursor.getLong(0);
|
|
|
- LogUtil.println( "MyDbManager","getAppRunTime","runTime", "=", time);
|
|
|
|
|
|
|
+ LogUtil.println("MyDbManager", "getAppRunTime", "runTime", "=", time);
|
|
|
cursor.close();
|
|
cursor.close();
|
|
|
return time;
|
|
return time;
|
|
|
- }catch (Exception e){
|
|
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
|
}
|
|
}
|
|
|
return 0;
|
|
return 0;
|
|
@@ -140,39 +144,60 @@ public class MyDbManager {
|
|
|
// }
|
|
// }
|
|
|
|
|
|
|
|
public List<LoginUser> getAllLoginUser() {
|
|
public List<LoginUser> getAllLoginUser() {
|
|
|
- try{
|
|
|
|
|
|
|
+ try {
|
|
|
return db.selector(LoginUser.class)
|
|
return db.selector(LoginUser.class)
|
|
|
.where("service_name", "=", SheepApp.getInstance().getConnectAddress().getName())
|
|
.where("service_name", "=", SheepApp.getInstance().getConnectAddress().getName())
|
|
|
.findAll();
|
|
.findAll();
|
|
|
- }catch (Exception e){
|
|
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
|
}
|
|
}
|
|
|
return ListUtil.emptyList();
|
|
return ListUtil.emptyList();
|
|
|
}
|
|
}
|
|
|
- public long getAppUsageTime(String packageName){
|
|
|
|
|
|
|
+
|
|
|
|
|
+ public long getAppUsageTime(String packageName) {
|
|
|
AppUsage appUsage = getAppUsage(packageName);
|
|
AppUsage appUsage = getAppUsage(packageName);
|
|
|
return appUsage == null ? 0 : appUsage.getTotalTimeInForeground();
|
|
return appUsage == null ? 0 : appUsage.getTotalTimeInForeground();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public AppUsage getAppUsage(String packageName){
|
|
|
|
|
- try{
|
|
|
|
|
|
|
+ public AppUsage getAppUsage(String packageName) {
|
|
|
|
|
+ try {
|
|
|
return db.selector(AppUsage.class)
|
|
return db.selector(AppUsage.class)
|
|
|
.where("package_name", "=", packageName)
|
|
.where("package_name", "=", packageName)
|
|
|
.findFirst();
|
|
.findFirst();
|
|
|
- }catch (Exception e){
|
|
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
|
}
|
|
}
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public List<SearchGameRecord> getAllSearchGameRecord(int type) {
|
|
public List<SearchGameRecord> getAllSearchGameRecord(int type) {
|
|
|
- try{
|
|
|
|
|
|
|
+ try {
|
|
|
return db.selector(SearchGameRecord.class)
|
|
return db.selector(SearchGameRecord.class)
|
|
|
- .where("type","=", type)
|
|
|
|
|
|
|
+ .where("type", "=", type)
|
|
|
.findAll();
|
|
.findAll();
|
|
|
- }catch (Exception e){
|
|
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
|
}
|
|
}
|
|
|
return ListUtil.emptyList();
|
|
return ListUtil.emptyList();
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ public List<SearchAppRecord> getAllSearchAppRecord() {
|
|
|
|
|
+ try {
|
|
|
|
|
+ return db.selector(SearchAppRecord.class)
|
|
|
|
|
+ .where("count", ">", 0)
|
|
|
|
|
+ .findAll();
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ }
|
|
|
|
|
+ return ListUtil.emptyList();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public void hideSearchApp(SearchAppRecord item) {
|
|
|
|
|
+ item.setCount(0);
|
|
|
|
|
+ try {
|
|
|
|
|
+ db.save(item);
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|