Search in sources :

Example 26 with AnyThread

use of androidx.annotation.AnyThread in project Signal-Android by signalapp.

the class PaymentSendJob method enqueuePayment.

/**
 * @param totalFee Total quoted totalFee to the user. This is expected to cover all defrags and the actual transaction.
 */
@AnyThread
@NonNull
public static UUID enqueuePayment(@Nullable RecipientId recipientId, @NonNull MobileCoinPublicAddress publicAddress, @NonNull String note, @NonNull Money amount, @NonNull Money totalFee) {
    UUID uuid = UUID.randomUUID();
    long timestamp = System.currentTimeMillis();
    Job sendJob = new PaymentSendJob(new Parameters.Builder().setQueue(QUEUE).setMaxAttempts(1).build(), uuid, timestamp, recipientId, Objects.requireNonNull(publicAddress), note, amount, totalFee);
    JobManager.Chain chain = ApplicationDependencies.getJobManager().startChain(sendJob).then(new PaymentTransactionCheckJob(uuid, QUEUE)).then(new MultiDeviceOutgoingPaymentSyncJob(uuid));
    if (recipientId != null) {
        chain.then(new PaymentNotificationSendJob(recipientId, uuid, recipientId.toQueueKey(true)));
    }
    chain.then(PaymentLedgerUpdateJob.updateLedgerToReflectPayment(uuid)).enqueue();
    return uuid;
}
Also used : JobManager(org.thoughtcrime.securesms.jobmanager.JobManager) UUID(java.util.UUID) Job(org.thoughtcrime.securesms.jobmanager.Job) NonNull(androidx.annotation.NonNull) AnyThread(androidx.annotation.AnyThread)

Example 27 with AnyThread

use of androidx.annotation.AnyThread in project nextcloud-notes by stefan-niedermann.

the class NotesRepository method modifyCategoryOrder.

/**
 * Modifies the sorting method for one category, the category can be normal category or
 * one of "All notes", "Favorite", and "Uncategorized".
 * If category is one of these three, sorting method will be modified in android.content.SharedPreference.
 * The user can determine use which sorting method to show the notes for a category.
 * When the user changes the sorting method, this method should be called.
 *
 * @param accountId        The user accountID
 * @param selectedCategory The category to be modified
 * @param sortingMethod    The sorting method in {@link CategorySortingMethod} enum format
 */
@AnyThread
public void modifyCategoryOrder(long accountId, @NonNull NavigationCategory selectedCategory, @NonNull CategorySortingMethod sortingMethod) {
    executor.submit(() -> {
        final var ctx = context.getApplicationContext();
        final var sp = PreferenceManager.getDefaultSharedPreferences(ctx).edit();
        int orderIndex = sortingMethod.getId();
        switch(selectedCategory.getType()) {
            case FAVORITES:
                {
                    sp.putInt(ctx.getString(R.string.action_sorting_method) + ' ' + ctx.getString(R.string.label_favorites), orderIndex);
                    break;
                }
            case UNCATEGORIZED:
                {
                    sp.putInt(ctx.getString(R.string.action_sorting_method) + ' ' + ctx.getString(R.string.action_uncategorized), orderIndex);
                    break;
                }
            case RECENT:
                {
                    sp.putInt(ctx.getString(R.string.action_sorting_method) + ' ' + ctx.getString(R.string.label_all_notes), orderIndex);
                    break;
                }
            case DEFAULT_CATEGORY:
            default:
                {
                    final String category = selectedCategory.getCategory();
                    if (category != null) {
                        if (db.getCategoryOptionsDao().modifyCategoryOrder(accountId, category, sortingMethod) == 0) {
                            // Nothing updated means we didn't have this yet
                            final var categoryOptions = new CategoryOptions();
                            categoryOptions.setAccountId(accountId);
                            categoryOptions.setCategory(category);
                            categoryOptions.setSortingMethod(sortingMethod);
                            db.getCategoryOptionsDao().addCategoryOptions(categoryOptions);
                        }
                    } else {
                        throw new IllegalStateException("Tried to modify category order for " + ENavigationCategoryType.DEFAULT_CATEGORY + "but category is null.");
                    }
                    break;
                }
        }
        sp.apply();
    });
}
Also used : CategoryOptions(it.niedermann.owncloud.notes.persistence.entity.CategoryOptions) AnyThread(androidx.annotation.AnyThread)

Aggregations

AnyThread (androidx.annotation.AnyThread)27 IOException (java.io.IOException)5 Cursor (android.database.Cursor)4 NonNull (androidx.annotation.NonNull)4 UUID (java.util.UUID)4 MegaphoneRecord (org.thoughtcrime.securesms.database.model.MegaphoneRecord)4 SuppressLint (android.annotation.SuppressLint)2 Paint (android.graphics.Paint)2 Point (android.graphics.Point)2 Uri (android.net.Uri)2 AlertDialog (androidx.appcompat.app.AlertDialog)2 ExifInterface (androidx.exifinterface.media.ExifInterface)2 ByteString (com.google.protobuf.ByteString)2 File (java.io.File)2 ArrayList (java.util.ArrayList)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 AtomicLong (java.util.concurrent.atomic.AtomicLong)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 Attachment (org.thoughtcrime.securesms.attachments.Attachment)2 DatabaseAttachment (org.thoughtcrime.securesms.attachments.DatabaseAttachment)2