use of android.support.annotation.WorkerThread in project materialistic by hidroh.
the class FavoriteManager method toFile.
@WorkerThread
private Uri toFile(Context context, Cursor cursor) throws IOException {
if (cursor.getCount() == 0) {
return null;
}
File dir = new File(context.getFilesDir(), PATH_SAVED);
if (!dir.exists() && !dir.mkdir()) {
return null;
}
File file = new File(dir, FILENAME_EXPORT);
if (!file.exists() && !file.createNewFile()) {
return null;
}
BufferedSink bufferedSink = Okio.buffer(Okio.sink(file));
do {
Favorite item = cursor.getFavorite();
bufferedSink.writeUtf8(item.getDisplayedTitle()).writeByte('\n').writeUtf8(item.getUrl()).writeByte('\n').writeUtf8(String.format(HackerNewsClient.WEB_ITEM_PATH, item.getId()));
if (!cursor.isLast()) {
bufferedSink.writeByte('\n').writeByte('\n');
}
} while (cursor.moveToNext());
Util.closeQuietly(bufferedSink);
return getUriForFile(context, file);
}
use of android.support.annotation.WorkerThread in project materialistic by hidroh.
the class SessionManager method insert.
@WorkerThread
private void insert(ContentResolver cr, String itemId) {
ContentValues contentValues = new ContentValues();
contentValues.put(MaterialisticProvider.ViewedEntry.COLUMN_NAME_ITEM_ID, itemId);
cr.insert(MaterialisticProvider.URI_VIEWED, contentValues);
}
use of android.support.annotation.WorkerThread in project materialistic by hidroh.
the class SessionManager method isViewed.
@WorkerThread
@NonNull
Observable<Boolean> isViewed(ContentResolver contentResolver, String itemId) {
if (TextUtils.isEmpty(itemId)) {
return Observable.just(false);
}
Cursor cursor = contentResolver.query(MaterialisticProvider.URI_VIEWED, null, MaterialisticProvider.ViewedEntry.COLUMN_NAME_ITEM_ID + " = ?", new String[] { itemId }, null);
boolean result = false;
if (cursor != null) {
result = cursor.getCount() > 0;
cursor.close();
}
return Observable.just(result);
}
use of android.support.annotation.WorkerThread in project materialistic by hidroh.
the class AdBlocker method loadFromAssets.
@WorkerThread
private static Void loadFromAssets(Context context) throws IOException {
InputStream stream = context.getAssets().open(AD_HOSTS_FILE);
BufferedSource buffer = Okio.buffer(Okio.source(stream));
String line;
while ((line = buffer.readUtf8Line()) != null) {
AD_HOSTS.add(line);
}
buffer.close();
stream.close();
return null;
}
use of android.support.annotation.WorkerThread in project k-9 by k9mail.
the class AttachmentController method getBestViewIntentAndSaveFile.
@WorkerThread
private Intent getBestViewIntentAndSaveFile() {
Uri intentDataUri;
try {
intentDataUri = AttachmentTempFileProvider.createTempUriForContentUri(context, attachment.internalUri);
} catch (IOException e) {
Timber.e(e, "Error creating temp file for attachment!");
return null;
}
String displayName = attachment.displayName;
String inferredMimeType = MimeUtility.getMimeTypeByExtension(displayName);
IntentAndResolvedActivitiesCount resolvedIntentInfo;
String mimeType = attachment.mimeType;
if (MimeUtility.isDefaultMimeType(mimeType)) {
resolvedIntentInfo = getBestViewIntentForMimeType(intentDataUri, inferredMimeType);
} else {
resolvedIntentInfo = getBestViewIntentForMimeType(intentDataUri, mimeType);
if (!resolvedIntentInfo.hasResolvedActivities() && !inferredMimeType.equals(mimeType)) {
resolvedIntentInfo = getBestViewIntentForMimeType(intentDataUri, inferredMimeType);
}
}
if (!resolvedIntentInfo.hasResolvedActivities()) {
resolvedIntentInfo = getBestViewIntentForMimeType(intentDataUri, MimeUtility.DEFAULT_ATTACHMENT_MIME_TYPE);
}
Intent viewIntent;
if (resolvedIntentInfo.hasResolvedActivities() && resolvedIntentInfo.containsFileUri()) {
try {
File tempFile = TemporaryAttachmentStore.getFileForWriting(context, displayName);
writeAttachmentToStorage(tempFile);
viewIntent = createViewIntentForFileUri(resolvedIntentInfo.getMimeType(), Uri.fromFile(tempFile));
} catch (IOException e) {
Timber.e(e, "Error while saving attachment to use file:// URI with ACTION_VIEW Intent");
viewIntent = createViewIntentForAttachmentProviderUri(intentDataUri, MimeUtility.DEFAULT_ATTACHMENT_MIME_TYPE);
}
} else {
viewIntent = resolvedIntentInfo.getIntent();
}
return viewIntent;
}
Aggregations