version:1.0
fix: update:更换包名
This commit is contained in:
@@ -0,0 +1,111 @@
|
||||
package com.uiui.zyos.iconpostition;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.ContentValues;
|
||||
import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
|
||||
import com.uiui.zyos.bean.NetDesktopIcon;
|
||||
import com.uiui.zyos.utils.ApkUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
public class IconPositionManager {
|
||||
@SuppressLint("StaticFieldLeak")
|
||||
private static IconPositionManager sInstance;
|
||||
private Context mContext;
|
||||
private IconPositionDBHelper mDBHelper;
|
||||
|
||||
private static final String TABLE_NAME = "DesktopIcon";
|
||||
private static String TAG = IconPositionManager.class.getSimpleName();
|
||||
|
||||
private IconPositionManager(Context context) {
|
||||
if (context == null) {
|
||||
throw new RuntimeException("Context is NULL");
|
||||
}
|
||||
mContext = context;
|
||||
mDBHelper = new IconPositionDBHelper(context);
|
||||
}
|
||||
|
||||
public static void init(Context context) {
|
||||
if (sInstance == null) {
|
||||
sInstance = new IconPositionManager(context);
|
||||
}
|
||||
}
|
||||
|
||||
public static IconPositionManager getInstance() {
|
||||
if (sInstance == null) {
|
||||
throw new IllegalStateException("You must be init IconPositionManager first");
|
||||
}
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
public IconPositionDBHelper getDBHelper() {
|
||||
if (mDBHelper == null) {
|
||||
mDBHelper = new IconPositionDBHelper(mContext);
|
||||
}
|
||||
return mDBHelper;
|
||||
}
|
||||
|
||||
public void setOnlinePosition(List<NetDesktopIcon> desktopIconList) {
|
||||
HashMap hashMap = new HashMap();
|
||||
|
||||
List<NetDesktopIcon> dbList = getLogList();
|
||||
for (int i = 0; i < dbList.size(); i++) {
|
||||
NetDesktopIcon icon = dbList.get(i);
|
||||
if (!ApkUtils.isAvailable(mContext, icon.getPackages())) {
|
||||
dbList.remove(i);
|
||||
deleteIcon(icon.getPackages());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public List<NetDesktopIcon> getLogList() {
|
||||
List<NetDesktopIcon> logBeanList = new ArrayList<>();
|
||||
SQLiteDatabase db = mDBHelper.getReadableDatabase();
|
||||
String sql = "select * from " + TABLE_NAME;
|
||||
Cursor cursor = null;
|
||||
try {
|
||||
cursor = db.rawQuery(sql, null);
|
||||
while (cursor.moveToNext()) {
|
||||
NetDesktopIcon desktopIcon = new NetDesktopIcon();
|
||||
desktopIcon.setId(cursor.getInt(cursor.getColumnIndex("id")));
|
||||
desktopIcon.setName(cursor.getString(cursor.getColumnIndex("name")));
|
||||
desktopIcon.setPackages(cursor.getString(cursor.getColumnIndex("package")));
|
||||
desktopIcon.setNum(cursor.getInt(cursor.getColumnIndex("position")));
|
||||
desktopIcon.setIcon(IconUtils.Bytes2Bimap(cursor.getBlob(cursor.getColumnIndex("icon"))));
|
||||
logBeanList.add(desktopIcon);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if (cursor != null) {
|
||||
cursor.close();
|
||||
}
|
||||
db.close();
|
||||
}
|
||||
return logBeanList;
|
||||
}
|
||||
|
||||
public void updateIcon(NetDesktopIcon netDesktopIcon) {
|
||||
SQLiteDatabase db = mDBHelper.getWritableDatabase();
|
||||
ContentValues values = new ContentValues();
|
||||
values.put("name", netDesktopIcon.getName());
|
||||
values.put("package", netDesktopIcon.getPackages());
|
||||
values.put("position", netDesktopIcon.getNum());
|
||||
values.put("icon", IconUtils.getPackageIcon(mContext, netDesktopIcon.getPackages()));
|
||||
db.update(TABLE_NAME, values, "package=?", new String[]{netDesktopIcon.getPackages()});
|
||||
}
|
||||
|
||||
public void deleteIcon(String pkg) {
|
||||
SQLiteDatabase db = mDBHelper.getWritableDatabase();
|
||||
db.delete(TABLE_NAME, "package=?", new String[]{pkg});
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user