Search in sources :

Example 76 with WorkerThread

use of android.support.annotation.WorkerThread in project nextcloud-notes by stefan-niedermann.

the class NoteSQLiteOpenHelper method getFavoritesCount.

@NonNull
@WorkerThread
public Map<String, Integer> getFavoritesCount() {
    SQLiteDatabase db = getReadableDatabase();
    Cursor cursor = db.query(table_notes, new String[] { key_favorite, "COUNT(*)" }, key_status + " != ?", new String[] { DBStatus.LOCAL_DELETED.getTitle() }, key_favorite, null, key_favorite);
    Map<String, Integer> favorites = new HashMap<>(cursor.getCount());
    while (cursor.moveToNext()) {
        favorites.put(cursor.getString(0), cursor.getInt(1));
    }
    cursor.close();
    return favorites;
}
Also used : SQLiteDatabase(android.database.sqlite.SQLiteDatabase) HashMap(java.util.HashMap) Cursor(android.database.Cursor) WorkerThread(android.support.annotation.WorkerThread) NonNull(android.support.annotation.NonNull)

Example 77 with WorkerThread

use of android.support.annotation.WorkerThread in project XposedInstaller by rovo89.

the class FrameworkZips method analyze.

@WorkerThread
private static LocalFrameworkZip analyze(File file) {
    String filename = file.getName();
    ZipFile zipFile = null;
    try {
        zipFile = new ZipFile(file);
        ZipCheckResult zcr = InstallZipUtil.checkZip(zipFile);
        if (!zcr.isValidZip()) {
            return null;
        }
        LocalFrameworkZip zip = new LocalFrameworkZip();
        ZipEntry entry;
        if ((entry = zipFile.getEntry("system/xposed.prop")) != null) {
            XposedProp prop = InstallZipUtil.parseXposedProp(zipFile.getInputStream(entry));
            if (prop == null || !prop.isCompatible()) {
                Log.w(XposedApp.TAG, "ZIP file is not compatible: " + file);
                return null;
            }
            zip.title = "Version " + prop.getVersion();
        } else if (filename.startsWith("xposed-uninstaller-")) {
            // TODO provide more information inside uninstaller ZIPs
            zip.type = Type.UNINSTALLER;
            zip.title = "Uninstaller";
            int start = "xposed-uninstaller-".length();
            int end = filename.lastIndexOf('-');
            if (start < end) {
                zip.title += " (" + filename.substring(start, end) + ")";
            }
        } else {
            return null;
        }
        zip.path = file;
        return zip;
    } catch (IOException e) {
        Log.e(XposedApp.TAG, "Errors while checking " + file, e);
        return null;
    } finally {
        if (zipFile != null) {
            InstallZipUtil.closeSilently(zipFile);
        }
    }
}
Also used : XposedProp(de.robv.android.xposed.installer.util.InstallZipUtil.XposedProp) ZipFile(java.util.zip.ZipFile) ZipCheckResult(de.robv.android.xposed.installer.util.InstallZipUtil.ZipCheckResult) ZipEntry(java.util.zip.ZipEntry) IOException(java.io.IOException) WorkerThread(android.support.annotation.WorkerThread)

Example 78 with WorkerThread

use of android.support.annotation.WorkerThread in project XposedInstaller by rovo89.

the class FrameworkZips method refreshLocal.

@WorkerThread
private static void refreshLocal() {
    // noinspection unchecked
    Map<String, List<LocalFrameworkZip>>[] zipsArray = new Map[TYPE_COUNT];
    for (int i = 0; i < TYPE_COUNT; i++) {
        zipsArray[i] = new TreeMap<>();
    }
    for (File dir : DownloadsUtil.getDownloadDirs(DownloadsUtil.DOWNLOAD_FRAMEWORK)) {
        if (!dir.isDirectory()) {
            continue;
        }
        for (String filename : dir.list()) {
            if (!filename.endsWith(".zip")) {
                continue;
            }
            LocalFrameworkZip zip = analyze(new File(dir, filename));
            if (zip != null) {
                Map<String, List<LocalFrameworkZip>> zips = zipsArray[zip.type.ordinal()];
                List<LocalFrameworkZip> list = zips.get(zip.title);
                if (list == null) {
                    list = new ArrayList<>(1);
                    zips.put(zip.title, list);
                }
                list.add(zip);
            }
        }
    }
    synchronized (FrameworkZips.class) {
        sLocal = zipsArray;
    }
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) TreeMap(java.util.TreeMap) ZipFile(java.util.zip.ZipFile) File(java.io.File) WorkerThread(android.support.annotation.WorkerThread)

Example 79 with WorkerThread

use of android.support.annotation.WorkerThread in project sqlbrite by square.

the class BriteDatabase method insert.

/**
 * Insert a row into the specified {@code table} and notify any subscribed queries.
 *
 * @see SupportSQLiteDatabase#insert(String, int, ContentValues)
 */
@WorkerThread
public long insert(@NonNull String table, @ConflictAlgorithm int conflictAlgorithm, @NonNull ContentValues values) {
    SupportSQLiteDatabase db = getWritableDatabase();
    if (logging) {
        log("INSERT\n  table: %s\n  values: %s\n  conflictAlgorithm: %s", table, values, conflictString(conflictAlgorithm));
    }
    long rowId = db.insert(table, conflictAlgorithm, values);
    if (logging)
        log("INSERT id: %s", rowId);
    if (rowId != -1) {
        // Only send a table trigger if the insert was successful.
        sendTableTrigger(Collections.singleton(table));
    }
    return rowId;
}
Also used : SupportSQLiteDatabase(android.arch.persistence.db.SupportSQLiteDatabase) WorkerThread(android.support.annotation.WorkerThread)

Example 80 with WorkerThread

use of android.support.annotation.WorkerThread in project sqlbrite by square.

the class BriteDatabase method update.

/**
 * Update rows in the specified {@code table} and notify any subscribed queries. This method
 * will not trigger a notification if no rows were updated.
 *
 * @see SupportSQLiteDatabase#update(String, int, ContentValues, String, Object[])
 */
@WorkerThread
public int update(@NonNull String table, @ConflictAlgorithm int conflictAlgorithm, @NonNull ContentValues values, @Nullable String whereClause, @Nullable String... whereArgs) {
    SupportSQLiteDatabase db = getWritableDatabase();
    if (logging) {
        log("UPDATE\n  table: %s\n  values: %s\n  whereClause: %s\n  whereArgs: %s\n  conflictAlgorithm: %s", table, values, whereClause, Arrays.toString(whereArgs), conflictString(conflictAlgorithm));
    }
    int rows = db.update(table, conflictAlgorithm, values, whereClause, whereArgs);
    if (logging)
        log("UPDATE affected %s %s", rows, rows != 1 ? "rows" : "row");
    if (rows > 0) {
        // Only send a table trigger if rows were affected.
        sendTableTrigger(Collections.singleton(table));
    }
    return rows;
}
Also used : SupportSQLiteDatabase(android.arch.persistence.db.SupportSQLiteDatabase) WorkerThread(android.support.annotation.WorkerThread)

Aggregations

WorkerThread (android.support.annotation.WorkerThread)152 Cursor (android.database.Cursor)37 ArrayList (java.util.ArrayList)36 NonNull (android.support.annotation.NonNull)34 File (java.io.File)20 HashMap (java.util.HashMap)17 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)15 StorIOException (com.pushtorefresh.storio.StorIOException)15 IOException (java.io.IOException)13 ContentValues (android.content.ContentValues)11 Resources (android.content.res.Resources)10 Bitmap (android.graphics.Bitmap)10 Context (android.content.Context)8 Intent (android.content.Intent)7 SharedPreferences (android.content.SharedPreferences)7 Uri (android.net.Uri)7 Nullable (android.support.annotation.Nullable)7 VisibleForTesting (android.support.annotation.VisibleForTesting)7 Media (com.doctoror.fuckoffmusicplayer.domain.queue.Media)7 DashboardCategory (com.android.settingslib.drawer.DashboardCategory)6