Search in sources :

Example 66 with WorkerThread

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);
    }
}
Also used : NoSuchMessageException(org.thoughtcrime.securesms.database.NoSuchMessageException) MessageRecord(org.thoughtcrime.securesms.database.model.MessageRecord) WorkerThread(androidx.annotation.WorkerThread)

Example 67 with WorkerThread

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;
    }
}
Also used : SignalStore(org.thoughtcrime.securesms.keyvalue.SignalStore) Context(android.content.Context) Stream(com.annimon.stream.Stream) NonNull(androidx.annotation.NonNull) LocalDateTime(java.time.LocalDateTime) WorkerThread(androidx.annotation.WorkerThread) Intent(android.content.Intent) R(org.thoughtcrime.securesms.R) LinkedHashMap(java.util.LinkedHashMap) LocaleFeatureFlags(org.thoughtcrime.securesms.util.LocaleFeatureFlags) SignalPinReminders(org.thoughtcrime.securesms.lock.SignalPinReminders) NotificationChannels(org.thoughtcrime.securesms.notifications.NotificationChannels) TranslationDetection(org.signal.core.util.TranslationDetection) Locale(java.util.Locale) Map(java.util.Map) Badge(org.thoughtcrime.securesms.badges.models.Badge) Settings(android.provider.Settings) Recipient(org.thoughtcrime.securesms.recipients.Recipient) KbsMigrationActivity(org.thoughtcrime.securesms.lock.v2.KbsMigrationActivity) Build(android.os.Build) PlayServicesUtil(org.thoughtcrime.securesms.util.PlayServicesUtil) AppSettingsActivity(org.thoughtcrime.securesms.components.settings.app.AppSettingsActivity) MegaphoneRecord(org.thoughtcrime.securesms.database.model.MegaphoneRecord) AvatarHelper(org.thoughtcrime.securesms.profiles.AvatarHelper) Month(java.time.Month) ApplicationDependencies(org.thoughtcrime.securesms.dependencies.ApplicationDependencies) Set(java.util.Set) NetworkConstraint(org.thoughtcrime.securesms.jobmanager.impl.NetworkConstraint) DynamicLanguageContextWrapper(org.thoughtcrime.securesms.util.dynamiclanguage.DynamicLanguageContextWrapper) SetUtil(org.thoughtcrime.securesms.util.SetUtil) CreateKbsPinActivity(org.thoughtcrime.securesms.lock.v2.CreateKbsPinActivity) SignalPinReminderDialog(org.thoughtcrime.securesms.lock.SignalPinReminderDialog) Objects(java.util.Objects) TimeUnit(java.util.concurrent.TimeUnit) Log(org.signal.core.util.logging.Log) FeatureFlags(org.thoughtcrime.securesms.util.FeatureFlags) List(java.util.List) Nullable(androidx.annotation.Nullable) VersionTracker(org.thoughtcrime.securesms.util.VersionTracker) ChatWallpaperActivity(org.thoughtcrime.securesms.wallpaper.ChatWallpaperActivity) ManageProfileActivity(org.thoughtcrime.securesms.profiles.manage.ManageProfileActivity) MegaphoneRecord(org.thoughtcrime.securesms.database.model.MegaphoneRecord) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) WorkerThread(androidx.annotation.WorkerThread) Nullable(androidx.annotation.Nullable)

Example 68 with WorkerThread

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 + "!");
    }
}
Also used : Uri(android.net.Uri) File(java.io.File) WorkerThread(androidx.annotation.WorkerThread)

Example 69 with WorkerThread

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;
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ChatWallpaper(org.thoughtcrime.securesms.wallpaper.ChatWallpaper) WorkerThread(androidx.annotation.WorkerThread) NonNull(androidx.annotation.NonNull)

Example 70 with WorkerThread

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;
    }
}
Also used : Bitmap(android.graphics.Bitmap) DecryptableStreamUriLoader(org.thoughtcrime.securesms.mms.DecryptableStreamUriLoader) ExecutionException(java.util.concurrent.ExecutionException) SuppressLint(android.annotation.SuppressLint) TimeoutException(java.util.concurrent.TimeoutException) WorkerThread(androidx.annotation.WorkerThread) Nullable(androidx.annotation.Nullable)

Aggregations

WorkerThread (androidx.annotation.WorkerThread)365 NonNull (androidx.annotation.NonNull)151 IOException (java.io.IOException)83 Recipient (org.thoughtcrime.securesms.recipients.Recipient)82 Nullable (androidx.annotation.Nullable)51 RecipientId (org.thoughtcrime.securesms.recipients.RecipientId)46 Cursor (android.database.Cursor)41 ArrayList (java.util.ArrayList)41 Context (android.content.Context)39 Uri (android.net.Uri)32 LinkedList (java.util.LinkedList)30 List (java.util.List)30 RecipientDatabase (org.thoughtcrime.securesms.database.RecipientDatabase)28 Stream (com.annimon.stream.Stream)26 HashMap (java.util.HashMap)26 Log (org.signal.core.util.logging.Log)26 HashSet (java.util.HashSet)24 Map (java.util.Map)21 Collections (java.util.Collections)20 ApplicationDependencies (org.thoughtcrime.securesms.dependencies.ApplicationDependencies)20