Search in sources :

Example 71 with WorkerThread

use of android.support.annotation.WorkerThread in project AppCenter-SDK-Android by Microsoft.

the class AppCenter method finishConfiguration.

@WorkerThread
private void finishConfiguration() {
    /* Load some global constants. */
    Constants.loadFromContext(mApplication);
    /* If parameters are valid, init context related resources. */
    StorageHelper.initialize(mApplication);
    /* Initialize session storage. */
    SessionContext.getInstance();
    /* Get enabled state. */
    boolean enabled = isInstanceEnabled();
    /* Init uncaught exception handler. */
    mUncaughtExceptionHandler = new UncaughtExceptionHandler();
    if (enabled) {
        mUncaughtExceptionHandler.register();
    }
    /* Init channel. */
    mLogSerializer = new DefaultLogSerializer();
    mLogSerializer.addLogFactory(StartServiceLog.TYPE, new StartServiceLogFactory());
    mLogSerializer.addLogFactory(CustomPropertiesLog.TYPE, new CustomPropertiesLogFactory());
    mChannel = new DefaultChannel(mApplication, mAppSecret, mLogSerializer, mHandler);
    mChannel.setEnabled(enabled);
    mChannel.addGroup(CORE_GROUP, DEFAULT_TRIGGER_COUNT, DEFAULT_TRIGGER_INTERVAL, DEFAULT_TRIGGER_MAX_PARALLEL_REQUESTS, null);
    if (mLogUrl != null) {
        mChannel.setLogUrl(mLogUrl);
    }
    if (!enabled) {
        NetworkStateHelper.getSharedInstance(mApplication).close();
    }
    AppCenterLog.debug(LOG_TAG, "App Center storage initialized.");
}
Also used : StartServiceLogFactory(com.microsoft.appcenter.ingestion.models.json.StartServiceLogFactory) CustomPropertiesLogFactory(com.microsoft.appcenter.ingestion.models.json.CustomPropertiesLogFactory) DefaultChannel(com.microsoft.appcenter.channel.DefaultChannel) DefaultLogSerializer(com.microsoft.appcenter.ingestion.models.json.DefaultLogSerializer) WorkerThread(android.support.annotation.WorkerThread)

Example 72 with WorkerThread

use of android.support.annotation.WorkerThread in project AppCenter-SDK-Android by Microsoft.

the class AppCenter method sendStartServiceLog.

/**
 * Queue start service log.
 *
 * @param serviceNames the services to send.
 */
@WorkerThread
private void sendStartServiceLog(List<String> serviceNames) {
    if (isInstanceEnabled()) {
        StartServiceLog startServiceLog = new StartServiceLog();
        startServiceLog.setServices(serviceNames);
        mChannel.enqueue(startServiceLog, CORE_GROUP);
    } else {
        if (mStartedServicesNamesToLog == null) {
            mStartedServicesNamesToLog = new ArrayList<>();
        }
        mStartedServicesNamesToLog.addAll(serviceNames);
    }
}
Also used : StartServiceLog(com.microsoft.appcenter.ingestion.models.StartServiceLog) WorkerThread(android.support.annotation.WorkerThread)

Example 73 with WorkerThread

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

the class NoteSQLiteOpenHelper method getIdMap.

@NonNull
@WorkerThread
public Map<Long, Long> getIdMap() {
    Map<Long, Long> result = new HashMap<>();
    SQLiteDatabase db = getReadableDatabase();
    Cursor cursor = db.query(table_notes, new String[] { key_remote_id, key_id }, key_status + " != ?", new String[] { DBStatus.LOCAL_DELETED.getTitle() }, null, null, null);
    while (cursor.moveToNext()) {
        result.put(cursor.getLong(0), cursor.getLong(1));
    }
    cursor.close();
    return result;
}
Also used : HashMap(java.util.HashMap) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) Cursor(android.database.Cursor) WorkerThread(android.support.annotation.WorkerThread) NonNull(android.support.annotation.NonNull)

Example 74 with WorkerThread

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

the class NoteSQLiteOpenHelper method getNotesCustom.

/**
 * Query the database with a custom raw query.
 * @param selection      A filter declaring which rows to return, formatted as an SQL WHERE clause (excluding the WHERE itself).
 * @param selectionArgs  You may include ?s in selection, which will be replaced by the values from selectionArgs, in order that they appear in the selection. The values will be bound as Strings.
 * @param orderBy        How to order the rows, formatted as an SQL ORDER BY clause (excluding the ORDER BY itself). Passing null will use the default sort order, which may be unordered.
 * @return List of Notes
 */
@NonNull
@WorkerThread
private List<DBNote> getNotesCustom(@NonNull String selection, @NonNull String[] selectionArgs, @Nullable String orderBy) {
    SQLiteDatabase db = getReadableDatabase();
    if (selectionArgs.length > 2) {
        Log.v("Note", selection + "   ----   " + selectionArgs[0] + " " + selectionArgs[1] + " " + selectionArgs[2]);
    }
    Cursor cursor = db.query(table_notes, columns, selection, selectionArgs, null, null, orderBy);
    List<DBNote> notes = new ArrayList<>();
    while (cursor.moveToNext()) {
        notes.add(getNoteFromCursor(cursor));
    }
    cursor.close();
    return notes;
}
Also used : DBNote(it.niedermann.owncloud.notes.model.DBNote) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) ArrayList(java.util.ArrayList) Cursor(android.database.Cursor) WorkerThread(android.support.annotation.WorkerThread) NonNull(android.support.annotation.NonNull)

Example 75 with WorkerThread

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

the class LoadNotesListTask method fillListByTime.

@NonNull
@WorkerThread
private List<Item> fillListByTime(@NonNull List<DBNote> noteList) {
    List<Item> itemList = new ArrayList<>();
    // #12 Create Sections depending on Time
    boolean todaySet, yesterdaySet, weekSet, monthSet, earlierSet;
    todaySet = yesterdaySet = weekSet = monthSet = earlierSet = false;
    Calendar today = Calendar.getInstance();
    today.set(Calendar.HOUR_OF_DAY, 0);
    today.set(Calendar.MINUTE, 0);
    today.set(Calendar.SECOND, 0);
    today.set(Calendar.MILLISECOND, 0);
    Calendar yesterday = Calendar.getInstance();
    yesterday.set(Calendar.DAY_OF_YEAR, yesterday.get(Calendar.DAY_OF_YEAR) - 1);
    yesterday.set(Calendar.HOUR_OF_DAY, 0);
    yesterday.set(Calendar.MINUTE, 0);
    yesterday.set(Calendar.SECOND, 0);
    yesterday.set(Calendar.MILLISECOND, 0);
    Calendar week = Calendar.getInstance();
    week.set(Calendar.DAY_OF_WEEK, week.getFirstDayOfWeek());
    week.set(Calendar.HOUR_OF_DAY, 0);
    week.set(Calendar.MINUTE, 0);
    week.set(Calendar.SECOND, 0);
    week.set(Calendar.MILLISECOND, 0);
    Calendar month = Calendar.getInstance();
    month.set(Calendar.DAY_OF_MONTH, 0);
    month.set(Calendar.HOUR_OF_DAY, 0);
    month.set(Calendar.MINUTE, 0);
    month.set(Calendar.SECOND, 0);
    month.set(Calendar.MILLISECOND, 0);
    for (int i = 0; i < noteList.size(); i++) {
        DBNote currentNote = noteList.get(i);
        if (currentNote.isFavorite()) {
        // don't show as new section
        } else if (!todaySet && currentNote.getModified().getTimeInMillis() >= today.getTimeInMillis()) {
            // after 00:00 today
            if (i > 0) {
                itemList.add(new SectionItem(context.getResources().getString(R.string.listview_updated_today)));
            }
            todaySet = true;
        } else if (!yesterdaySet && currentNote.getModified().getTimeInMillis() < today.getTimeInMillis() && currentNote.getModified().getTimeInMillis() >= yesterday.getTimeInMillis()) {
            // between today 00:00 and yesterday 00:00
            if (i > 0) {
                itemList.add(new SectionItem(context.getResources().getString(R.string.listview_updated_yesterday)));
            }
            yesterdaySet = true;
        } else if (!weekSet && currentNote.getModified().getTimeInMillis() < yesterday.getTimeInMillis() && currentNote.getModified().getTimeInMillis() >= week.getTimeInMillis()) {
            // between yesterday 00:00 and start of the week 00:00
            if (i > 0) {
                itemList.add(new SectionItem(context.getResources().getString(R.string.listview_updated_this_week)));
            }
            weekSet = true;
        } else if (!monthSet && currentNote.getModified().getTimeInMillis() < week.getTimeInMillis() && currentNote.getModified().getTimeInMillis() >= month.getTimeInMillis()) {
            // between start of the week 00:00 and start of the month 00:00
            if (i > 0) {
                itemList.add(new SectionItem(context.getResources().getString(R.string.listview_updated_this_month)));
            }
            monthSet = true;
        } else if (!earlierSet && currentNote.getModified().getTimeInMillis() < month.getTimeInMillis()) {
            // before start of the month 00:00
            if (i > 0) {
                itemList.add(new SectionItem(context.getResources().getString(R.string.listview_updated_earlier)));
            }
            earlierSet = true;
        }
        itemList.add(currentNote);
    }
    return itemList;
}
Also used : DBNote(it.niedermann.owncloud.notes.model.DBNote) SectionItem(it.niedermann.owncloud.notes.model.SectionItem) SectionItem(it.niedermann.owncloud.notes.model.SectionItem) Item(it.niedermann.owncloud.notes.model.Item) Calendar(java.util.Calendar) ArrayList(java.util.ArrayList) WorkerThread(android.support.annotation.WorkerThread) NonNull(android.support.annotation.NonNull)

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