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.");
}
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);
}
}
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;
}
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;
}
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;
}
Aggregations