Search in sources :

Example 1 with AppRecord

use of rocks.tbog.tblauncher.db.AppRecord in project TBLauncher by TBog.

the class AppsHandler method loadFromDB.

public void loadFromDB(boolean wait) {
    Log.d(TAG, "loadFromDB(wait= " + wait + " )");
    synchronized (this) {
        mIsLoaded = false;
    }
    final Timer timer = Timer.startMilli();
    final HashMap<String, AppEntry> apps = new HashMap<>();
    final Runnable load = () -> {
        TagsHandler tagsHandler = mApplication.tagsHandler();
        Context context = getContext();
        Map<String, AppRecord> dbApps = DBHelper.getAppsData(context);
        apps.clear();
        // convert from AppRecord to AppEntry
        for (AppRecord rec : dbApps.values()) {
            AppEntry appEntry = record2app(context, rec);
            apps.put(appEntry.id, appEntry);
        }
        setTagsForApps(apps.values(), tagsHandler);
    };
    final Runnable apply = () -> {
        synchronized (AppsHandler.this) {
            mAppsCache.clear();
            mAppsCache.putAll(apps);
            mIsLoaded = true;
            timer.stop();
            Log.d("time", "Time to load all DB apps: " + timer);
            // run and remove tasks
            Runnable task;
            while (null != (task = mAfterLoadedTasks.poll())) task.run();
        }
    };
    if (wait) {
        load.run();
        apply.run();
    } else
        Utilities.runAsync((t) -> load.run(), (t) -> apply.run());
}
Also used : Context(android.content.Context) Context(android.content.Context) ComponentName(android.content.ComponentName) NonNull(androidx.annotation.NonNull) Collection(java.util.Collection) WorkerThread(androidx.annotation.WorkerThread) AppRecord(rocks.tbog.tblauncher.db.AppRecord) HashMap(java.util.HashMap) Timer(rocks.tbog.tblauncher.utils.Timer) DBHelper(rocks.tbog.tblauncher.db.DBHelper) ArrayList(java.util.ArrayList) TBApplication(rocks.tbog.tblauncher.TBApplication) AppEntry(rocks.tbog.tblauncher.entry.AppEntry) Nullable(androidx.annotation.Nullable) Map(java.util.Map) AppCacheProvider(rocks.tbog.tblauncher.dataprovider.AppCacheProvider) Utilities(rocks.tbog.tblauncher.utils.Utilities) UserHandleCompat(rocks.tbog.tblauncher.utils.UserHandleCompat) ArrayDeque(java.util.ArrayDeque) Collections(java.util.Collections) Log(android.util.Log) Timer(rocks.tbog.tblauncher.utils.Timer) AppEntry(rocks.tbog.tblauncher.entry.AppEntry) HashMap(java.util.HashMap) AppRecord(rocks.tbog.tblauncher.db.AppRecord) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with AppRecord

use of rocks.tbog.tblauncher.db.AppRecord in project TBLauncher by TBog.

the class IconsHandler method changeIcon.

public void changeIcon(AppEntry appEntry, Drawable drawable) {
    Bitmap bitmap = getIconBitmap(ctx, drawable);
    TBApplication app = TBApplication.getApplication(ctx);
    AppRecord appRecord = app.getDataHandler().setCustomAppIcon(appEntry.getUserComponentName(), bitmap);
    app.drawableCache().cacheDrawable(appEntry.getIconCacheId(), null);
    appEntry.setCustomIcon(appRecord.dbId);
    app.drawableCache().cacheDrawable(appEntry.getIconCacheId(), drawable);
}
Also used : Bitmap(android.graphics.Bitmap) TBApplication(rocks.tbog.tblauncher.TBApplication) AppRecord(rocks.tbog.tblauncher.db.AppRecord)

Aggregations

TBApplication (rocks.tbog.tblauncher.TBApplication)2 AppRecord (rocks.tbog.tblauncher.db.AppRecord)2 ComponentName (android.content.ComponentName)1 Context (android.content.Context)1 Bitmap (android.graphics.Bitmap)1 Log (android.util.Log)1 NonNull (androidx.annotation.NonNull)1 Nullable (androidx.annotation.Nullable)1 WorkerThread (androidx.annotation.WorkerThread)1 ArrayDeque (java.util.ArrayDeque)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 AppCacheProvider (rocks.tbog.tblauncher.dataprovider.AppCacheProvider)1 DBHelper (rocks.tbog.tblauncher.db.DBHelper)1 AppEntry (rocks.tbog.tblauncher.entry.AppEntry)1 Timer (rocks.tbog.tblauncher.utils.Timer)1 UserHandleCompat (rocks.tbog.tblauncher.utils.UserHandleCompat)1