use of androidx.annotation.WorkerThread in project Signal-Android by WhisperSystems.
the class MessageRecordLiveData method retrieve.
@WorkerThread
private synchronized void retrieve(MessageDatabase messageDatabase) {
try {
final MessageRecord record = messageDatabase.getMessageRecord(messageId.getId());
postValue(record);
ApplicationDependencies.getDatabaseObserver().registerVerboseConversationObserver(record.getThreadId(), observer);
} catch (NoSuchMessageException ignored) {
postValue(null);
}
}
use of androidx.annotation.WorkerThread in project Signal-Android by WhisperSystems.
the class Megaphones method getNextMegaphone.
@WorkerThread
@Nullable
static Megaphone getNextMegaphone(@NonNull Context context, @NonNull Map<Event, MegaphoneRecord> records) {
long currentTime = System.currentTimeMillis();
List<Megaphone> megaphones = Stream.of(buildDisplayOrder(context, records)).filter(e -> {
MegaphoneRecord record = Objects.requireNonNull(records.get(e.getKey()));
MegaphoneSchedule schedule = e.getValue();
return !record.isFinished() && schedule.shouldDisplay(record.getSeenCount(), record.getLastSeen(), record.getFirstVisible(), currentTime);
}).map(Map.Entry::getKey).map(records::get).map(record -> Megaphones.forRecord(context, record)).toList();
if (megaphones.size() > 0) {
return megaphones.get(0);
} else {
return null;
}
}
use of androidx.annotation.WorkerThread in project Signal-Android by WhisperSystems.
the class WallpaperStorage method onWallpaperDeselected.
/**
* Called when wallpaper is deselected. This will check anywhere the wallpaper could be used, and
* if we discover it's unused, we'll delete the file.
*/
@WorkerThread
public static void onWallpaperDeselected(@NonNull Context context, @NonNull Uri uri) {
Uri globalUri = SignalStore.wallpaper().getWallpaperUri();
if (Objects.equals(uri, globalUri)) {
return;
}
int recipientCount = SignalDatabase.recipients().getWallpaperUriUsageCount(uri);
if (recipientCount > 0) {
return;
}
String filename = PartAuthority.getWallpaperFilename(uri);
File directory = context.getDir(DIRECTORY, Context.MODE_PRIVATE);
File wallpaperFile = new File(directory, filename);
if (!wallpaperFile.delete()) {
Log.w(TAG, "Failed to delete " + filename + "!");
}
}
use of androidx.annotation.WorkerThread in project Signal-Android by WhisperSystems.
the class WallpaperCropRepository method setWallPaper.
@WorkerThread
@NonNull
ChatWallpaper setWallPaper(byte[] bytes) throws IOException {
try (InputStream inputStream = new ByteArrayInputStream(bytes)) {
ChatWallpaper wallpaper = WallpaperStorage.save(context, inputStream, "webp");
if (recipientId != null) {
Log.i(TAG, "Setting image wallpaper for " + recipientId);
SignalDatabase.recipients().setWallpaper(recipientId, wallpaper);
} else {
Log.i(TAG, "Setting image wallpaper for default");
SignalStore.wallpaper().setWallpaper(context, wallpaper);
}
return wallpaper;
}
}
use of androidx.annotation.WorkerThread in project Signal-Android by WhisperSystems.
the class ConversationParentFragment method getKeyboardImageDetails.
@WorkerThread
@Nullable
private KeyboardImageDetails getKeyboardImageDetails(@NonNull Uri uri) {
try {
Bitmap bitmap = glideRequests.asBitmap().load(new DecryptableStreamUriLoader.DecryptableUri(uri)).skipMemoryCache(true).diskCacheStrategy(DiskCacheStrategy.NONE).submit().get(1000, TimeUnit.MILLISECONDS);
int topLeft = bitmap.getPixel(0, 0);
return new KeyboardImageDetails(bitmap.getWidth(), bitmap.getHeight(), Color.alpha(topLeft) < 255);
} catch (InterruptedException | ExecutionException | TimeoutException e) {
return null;
}
}
Aggregations