Move all Pair usage to kotlin.Pair

This commit is contained in:
Greyson Parrelli
2025-11-10 12:03:18 -05:00
parent 66f136903f
commit 2147ad29fa
20 changed files with 72 additions and 72 deletions

View File

@@ -9,7 +9,7 @@ import android.content.ContentResolver;
import android.content.Context;
import android.graphics.Bitmap;
import android.net.Uri;
import android.util.Pair;
import kotlin.Pair;
import com.bumptech.glide.load.data.StreamLocalUriFetcher;
@@ -84,7 +84,7 @@ class DecryptableStreamLocalUriFetcher extends StreamLocalUriFetcher {
try {
InputStream stream = PartAuthority.getAttachmentThumbnailStream(context, uri);
Pair<Integer, Integer> dimensions = BitmapUtil.getDimensions(stream);
long totalPixels = (long) dimensions.first * dimensions.second;
long totalPixels = (long) dimensions.getFirst() * dimensions.getSecond();
return totalPixels < TOTAL_PIXEL_SIZE_LIMIT;
} catch (BitmapDecodingException e) {
Long size = PartAuthority.getAttachmentSize(context, uri);

View File

@@ -6,7 +6,7 @@ import android.content.ContentValues;
import android.content.Context;
import android.content.SharedPreferences;
import android.net.Uri;
import android.util.Pair;
import kotlin.Pair;
import androidx.annotation.NonNull;
import androidx.annotation.VisibleForTesting;
@@ -224,10 +224,10 @@ public class FullBackupImporter extends FullBackupBase {
ContentValues contentValues = new ContentValues();
try {
inputStream.readAttachmentTo(output.second, attachment.length);
inputStream.readAttachmentTo(output.getSecond(), attachment.length);
contentValues.put(dataFileColumnName, dataFile.getAbsolutePath());
contentValues.put(dataRandomColumnName, output.first);
contentValues.put(dataRandomColumnName, output.getFirst());
} catch (BackupRecordInputStream.BadMacException e) {
Log.w(TAG, "Bad MAC for attachment " + attachment.attachmentId + "! Can't restore it.", e);
dataFile.delete();
@@ -249,12 +249,12 @@ public class FullBackupImporter extends FullBackupBase {
Pair<byte[], OutputStream> output = ModernEncryptingPartOutputStream.createFor(attachmentSecret, dataFile, false);
inputStream.readAttachmentTo(output.second, sticker.length);
inputStream.readAttachmentTo(output.getSecond(), sticker.length);
ContentValues contentValues = new ContentValues();
contentValues.put(StickerTable.FILE_PATH, dataFile.getAbsolutePath());
contentValues.put(StickerTable.FILE_LENGTH, sticker.length);
contentValues.put(StickerTable.FILE_RANDOM, output.first);
contentValues.put(StickerTable.FILE_RANDOM, output.getFirst());
db.update(StickerTable.TABLE_NAME, contentValues,
StickerTable.ID + " = ?",

View File

@@ -43,8 +43,10 @@ open class ConversationSettingsActivity : DSLSettingsActivity(), ConversationSet
return if (context is Activity) {
ActivityOptionsCompat.makeSceneTransitionAnimation(
context,
Pair.create(avatar, "avatar"),
Pair.create(windowContent, "window_content")
*arrayOf(
androidx.core.util.Pair.create(avatar, "avatar"),
androidx.core.util.Pair.create(windowContent, "window_content")
)
).toBundle()
} else {
null

View File

@@ -1,7 +1,7 @@
package org.thoughtcrime.securesms.crypto;
import android.util.Pair;
import kotlin.Pair;
import androidx.annotation.NonNull;

View File

@@ -5,7 +5,7 @@ import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.text.TextUtils;
import android.util.Pair;
import kotlin.Pair;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
@@ -78,11 +78,11 @@ public class SQLCipherMigrationHelper {
row.getAsLong("type"),
row.getAsString("body"));
row.put("body", plaintext.second);
row.put("type", plaintext.first);
row.put("body", plaintext.getSecond());
row.put("type", plaintext.getFirst());
if (listener != null && (progress.first % 1000 == 0)) {
listener.setProgress(getTotalProgress(0, progress.first, progress.second), total);
if (listener != null && (progress.getFirst() % 1000 == 0)) {
listener.setProgress(getTotalProgress(0, progress.getFirst(), progress.getSecond()), total);
}
return row;
@@ -93,11 +93,11 @@ public class SQLCipherMigrationHelper {
row.getAsLong("msg_box"),
row.getAsString("body"));
row.put("body", plaintext.second);
row.put("msg_box", plaintext.first);
row.put("body", plaintext.getSecond());
row.put("msg_box", plaintext.getFirst());
if (listener != null && (progress.first % 1000 == 0)) {
listener.setProgress(getTotalProgress(1000, progress.first, progress.second), total);
if (listener != null && (progress.getFirst() % 1000 == 0)) {
listener.setProgress(getTotalProgress(1000, progress.getFirst(), progress.getSecond()), total);
}
return row;
@@ -131,8 +131,8 @@ public class SQLCipherMigrationHelper {
Log.w(TAG, e);
}
if (listener != null && (progress.first % 1000 == 0)) {
listener.setProgress(getTotalProgress(2000, progress.first, progress.second), total);
if (listener != null && (progress.getFirst() % 1000 == 0)) {
listener.setProgress(getTotalProgress(2000, progress.getFirst(), progress.getSecond()), total);
}
return row;
@@ -145,11 +145,11 @@ public class SQLCipherMigrationHelper {
Pair<Long, String> plaintext = getPlaintextBody(legacyCipher, legacyAsymmetricCipher,
snippetType, row.getAsString("snippet"));
row.put("snippet", plaintext.second);
row.put("snippet_type", plaintext.first);
row.put("snippet", plaintext.getSecond());
row.put("snippet_type", plaintext.getFirst());
if (listener != null && (progress.first % 1000 == 0)) {
listener.setProgress(getTotalProgress(3000, progress.first, progress.second), total);
if (listener != null && (progress.getFirst() % 1000 == 0)) {
listener.setProgress(getTotalProgress(3000, progress.getFirst(), progress.getSecond()), total);
}
return row;
@@ -167,8 +167,8 @@ public class SQLCipherMigrationHelper {
Log.w(TAG, e);
}
if (listener != null && (progress.first % 1000 == 0)) {
listener.setProgress(getTotalProgress(4000, progress.first, progress.second), total);
if (listener != null && (progress.getFirst() % 1000 == 0)) {
listener.setProgress(getTotalProgress(4000, progress.getFirst(), progress.getSecond()), total);
}
return row;

View File

@@ -268,7 +268,7 @@ public final class AttachmentCompressionJob extends BaseJob {
boolean faststart = false;
try {
int mdatLength;
try (OutputStream outputStream = ModernEncryptingPartOutputStream.createFor(attachmentSecret, file, true).second) {
try (OutputStream outputStream = ModernEncryptingPartOutputStream.createFor(attachmentSecret, file, true).getSecond()) {
mdatLength = (int) transcoder.transcode(percent -> {
if (notification != null) {
notification.updateProgress(percent / 100f);

View File

@@ -9,7 +9,7 @@ import android.provider.MediaStore;
import android.provider.MediaStore.Images;
import android.provider.MediaStore.Video;
import android.provider.OpenableColumns;
import android.util.Pair;
import kotlin.Pair;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
@@ -364,8 +364,8 @@ public class MediaRepository {
if (width == 0 || height == 0) {
Pair<Integer, Integer> dimens = MediaUtil.getDimensions(context, media.getContentType(), media.getUri());
width = dimens.first;
height = dimens.second;
width = dimens.getFirst();
height = dimens.getSecond();
}
return new Media(media.getUri(), media.getContentType(), media.getDate(), width, height, size, 0, media.isBorderless(), media.isVideoGif(), media.getBucketId(), media.getCaption(), null, null);
@@ -390,8 +390,8 @@ public class MediaRepository {
if (width == 0 || height == 0) {
Pair<Integer, Integer> dimens = MediaUtil.getDimensions(context, media.getContentType(), media.getUri());
width = dimens.first;
height = dimens.second;
width = dimens.getFirst();
height = dimens.getSecond();
}
return new Media(media.getUri(), media.getContentType(), media.getDate(), width, height, size, 0, media.isBorderless(), media.isVideoGif(), media.getBucketId(), media.getCaption(), null, null);

View File

@@ -13,7 +13,7 @@ import android.hardware.camera2.CameraCharacteristics;
import android.hardware.camera2.CameraManager;
import android.hardware.camera2.CameraMetadata;
import android.os.Build;
import android.util.Pair;
import kotlin.Pair;
import android.util.Size;
import androidx.annotation.NonNull;
@@ -69,9 +69,9 @@ public class CameraXUtil {
try {
Pair<Integer, Integer> dimens = BitmapUtil.getDimensions(new ByteArrayInputStream(data));
if (dimens.first != image.getWidth() && dimens.second != image.getHeight()) {
if (dimens.getFirst() != image.getWidth() && dimens.getSecond() != image.getHeight()) {
Log.w(TAG, String.format(Locale.ENGLISH, "Decoded image dimensions differed from stated dimensions! Stated: %d x %d, Decoded: %d x %d",
image.getWidth(), image.getHeight(), dimens.first, dimens.second));
image.getWidth(), image.getHeight(), dimens.getFirst(), dimens.getSecond()));
Log.w(TAG, "Ignoring the stated rotation and rotating the crop rect 90 degrees (stated rotation is " + rotation + " degrees).");
rotation = 0;

View File

@@ -3,7 +3,7 @@ package org.thoughtcrime.securesms.mms;
import android.content.Context;
import android.net.Uri;
import android.os.Build;
import android.util.Pair;
import kotlin.Pair;
import androidx.annotation.IntRange;
import androidx.annotation.NonNull;
@@ -107,8 +107,8 @@ public abstract class MediaConstraints {
try {
InputStream is = PartAuthority.getAttachmentStream(context, uri);
Pair<Integer, Integer> dimensions = BitmapUtil.getDimensions(is);
return dimensions.first > 0 && dimensions.first <= getImageMaxWidth(context) &&
dimensions.second > 0 && dimensions.second <= getImageMaxHeight(context);
return dimensions.getFirst() > 0 && dimensions.getFirst() <= getImageMaxWidth(context) &&
dimensions.getSecond() > 0 && dimensions.getSecond() <= getImageMaxHeight(context);
} catch (BitmapDecodingException e) {
throw new IOException(e);
}

View File

@@ -5,7 +5,7 @@ import android.database.Cursor;
import android.net.Uri;
import android.provider.OpenableColumns;
import android.text.TextUtils;
import android.util.Pair;
import kotlin.Pair;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
@@ -77,8 +77,8 @@ public final class SlideFactory {
if (width == 0 || height == 0) {
Pair<Integer, Integer> dimens = MediaUtil.getDimensions(context, mimeType, uri);
width = dimens.first;
height = dimens.second;
width = dimens.getFirst();
height = dimens.getSecond();
}
if (mediaType == null) {
@@ -125,8 +125,8 @@ public final class SlideFactory {
if (width == 0 || height == 0) {
Pair<Integer, Integer> dimens = MediaUtil.getDimensions(context, mimeType, uri);
width = dimens.first;
height = dimens.second;
width = dimens.getFirst();
height = dimens.getSecond();
}
if (mediaType == null) {

View File

@@ -1,6 +1,6 @@
package org.thoughtcrime.securesms.payments.preferences;
import android.util.Pair;
import kotlin.Pair;
import androidx.annotation.NonNull;
import androidx.annotation.WorkerThread;
@@ -41,7 +41,7 @@ public class PaymentsRepository {
LiveData<MobileCoinLedgerWrapper> ledger = SignalStore.payments().liveMobileCoinLedger();
//noinspection NullableProblems
this.recentPayments = LiveDataUtil.mapAsync(LiveDataUtil.combineLatest(localPayments, ledger, Pair::create), p -> reconcile(p.first, p.second));
this.recentPayments = LiveDataUtil.mapAsync(LiveDataUtil.combineLatest(localPayments, ledger, (a, b) -> new Pair<>(a, b)), p -> reconcile(p.getFirst(), p.getSecond()));
this.recentSentPayments = LiveDataUtil.mapAsync(this.recentPayments, p -> filterPayments(p, Direction.SENT));
this.recentReceivedPayments = LiveDataUtil.mapAsync(this.recentPayments, p -> filterPayments(p, Direction.RECEIVED));
}

View File

@@ -180,7 +180,7 @@ public class AvatarHelper {
public static @NonNull OutputStream getOutputStream(@NonNull Context context, @NonNull RecipientId recipientId, boolean isSyncAvatar) throws IOException {
AttachmentSecret attachmentSecret = AttachmentSecretProvider.getInstance(context).getOrCreateAttachmentSecret();
File targetFile = getAvatarFile(context, recipientId, isSyncAvatar);
return ModernEncryptingPartOutputStream.createFor(attachmentSecret, targetFile, true).second;
return ModernEncryptingPartOutputStream.createFor(attachmentSecret, targetFile, true).getSecond();
}
/**

View File

@@ -3,7 +3,7 @@ package org.thoughtcrime.securesms.profiles.spoofing;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.text.SpannableStringBuilder;
import android.util.Pair;
import kotlin.Pair;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
@@ -45,10 +45,10 @@ class ReviewCardViewHolder extends RecyclerView.ViewHolder {
this.binding = ReviewCardBinding.bind(itemView);
this.subtextGroups = Arrays.asList(
Pair.create(binding.cardSubtextLine1, binding.cardSubtextIcon1),
Pair.create(binding.cardSubtextLine2, binding.cardSubtextIcon2),
Pair.create(binding.cardSubtextLine3, binding.cardSubtextIcon3),
Pair.create(binding.cardSubtextLine4, binding.cardSubtextIcon4)
new Pair(binding.cardSubtextLine1, binding.cardSubtextIcon1),
new Pair(binding.cardSubtextLine2, binding.cardSubtextIcon2),
new Pair(binding.cardSubtextLine3, binding.cardSubtextIcon3),
new Pair(binding.cardSubtextLine4, binding.cardSubtextIcon4)
);
itemView.findViewById(R.id.card_tap_target).setOnClickListener(unused -> {
@@ -136,21 +136,21 @@ class ReviewCardViewHolder extends RecyclerView.ViewHolder {
private void presentReviewTextRows(@NonNull List<ReviewTextRow> reviewTextRows, @NonNull Context context, @NonNull ReviewCard reviewCard) {
for (Pair<TextView, ImageView> group : subtextGroups) {
setVisibility(View.GONE, group.first, group.second);
setVisibility(View.GONE, group.getFirst(), group.getSecond());
}
for (int i = 0; i < Math.min(reviewTextRows.size(), subtextGroups.size()); i++) {
ReviewTextRow row = reviewTextRows.get(i);
Pair<TextView, ImageView> group = subtextGroups.get(i);
setVisibility(View.VISIBLE, group.first, group.second);
setVisibility(View.VISIBLE, group.getFirst(), group.getSecond());
switch (row) {
case SIGNAL_CONNECTION -> presentSignalConnection(group.first, group.second, context, reviewCard);
case PHONE_NUMBER -> presentPhoneNumber(group.first, group.second, reviewCard);
case RECENTLY_CHANGED -> presentRecentlyChanged(group.first, group.second, context, reviewCard);
case GROUPS_IN_COMMON -> presentGroupsInCommon(group.first, group.second, reviewCard);
case SYSTEM_CONTACTS -> presentSystemContacts(group.first, group.second, context, reviewCard);
case SIGNAL_CONNECTION -> presentSignalConnection(group.getFirst(), group.getSecond(), context, reviewCard);
case PHONE_NUMBER -> presentPhoneNumber(group.getFirst(), group.getSecond(), reviewCard);
case RECENTLY_CHANGED -> presentRecentlyChanged(group.getFirst(), group.getSecond(), context, reviewCard);
case GROUPS_IN_COMMON -> presentGroupsInCommon(group.getFirst(), group.getSecond(), reviewCard);
case SYSTEM_CONTACTS -> presentSystemContacts(group.getFirst(), group.getSecond(), context, reviewCard);
}
}
}

View File

@@ -1,6 +1,6 @@
package org.thoughtcrime.securesms.profiles.spoofing;
import android.util.Pair;
import kotlin.Pair;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
@@ -46,7 +46,7 @@ public class ReviewCardViewModel extends ViewModel {
LiveData<Pair<Boolean, List<ReviewRecipient>>> adminStatusAndReviewRecipients = LiveDataUtil.combineLatest(isSelfGroupAdmin, reviewRecipients, Pair::new);
this.reviewCards = LiveDataUtil.mapAsync(adminStatusAndReviewRecipients, pair -> transformReviewRecipients(pair.first, pair.second));
this.reviewCards = LiveDataUtil.mapAsync(adminStatusAndReviewRecipients, pair -> transformReviewRecipients(pair.getFirst(), pair.getSecond()));
this.reviewEvents = new SingleLiveEvent<>();
repository.loadRecipients(new OnRecipientsLoadedListener());

View File

@@ -397,7 +397,7 @@ public class BlobProvider {
AttachmentSecret attachmentSecret = AttachmentSecretProvider.getInstance(context).getOrCreateAttachmentSecret();
String directory = getDirectory(blobSpec.getStorageType());
File outputFile = new File(getOrCreateDirectory(context, directory), buildFileName(blobSpec.id));
OutputStream outputStream = ModernEncryptingPartOutputStream.createFor(attachmentSecret, outputFile, true).second;
OutputStream outputStream = ModernEncryptingPartOutputStream.createFor(attachmentSecret, outputFile, true).getSecond();
final Uri uri = buildUri(blobSpec);

View File

@@ -5,7 +5,6 @@ import android.net.Uri
import android.provider.OpenableColumns
import androidx.annotation.NonNull
import androidx.annotation.WorkerThread
import androidx.core.util.toKotlinPair
import io.reactivex.rxjava3.core.Single
import io.reactivex.rxjava3.schedulers.Schedulers
import org.signal.core.util.logging.Log
@@ -92,7 +91,7 @@ class ShareRepository(context: Context) {
} ?: return@map null
val size = getSize(appContext, uri)
val dimens: Pair<Int, Int> = MediaUtil.getDimensions(appContext, mimeType, uri).toKotlinPair()
val dimens: Pair<Int, Int> = MediaUtil.getDimensions(appContext, mimeType, uri)
val duration = 0L
val blobUri = try {
BlobProvider.getInstance()

View File

@@ -11,7 +11,7 @@ import android.graphics.YuvImage;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.util.Pair;
import kotlin.Pair;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
@@ -271,7 +271,7 @@ public class BitmapUtil {
public static Pair<Integer, Integer> getDimensions(InputStream inputStream) throws BitmapDecodingException {
BitmapFactory.Options options = getImageDimensions(inputStream);
return new Pair<>(options.outWidth, options.outHeight);
return new Pair(options.outWidth, options.outHeight);
}
public static ByteArrayInputStream toCompressedJpeg(Bitmap bitmap) {

View File

@@ -14,7 +14,7 @@ import android.media.ThumbnailUtils;
import android.net.Uri;
import android.provider.MediaStore;
import android.text.TextUtils;
import android.util.Pair;
import kotlin.Pair;
import android.webkit.MimeTypeMap;
import androidx.annotation.NonNull;
@@ -279,9 +279,9 @@ public class MediaUtil {
}
}
if (dimens == null) {
dimens = new Pair<>(0, 0);
dimens = new Pair(0, 0);
}
Log.d(TAG, "Dimensions for [" + uri + "] are " + dimens.first + " x " + dimens.second);
Log.d(TAG, "Dimensions for [" + uri + "] are " + dimens.getFirst() + " x " + dimens.getSecond());
return dimens;
}

View File

@@ -94,7 +94,7 @@ public final class FileStorage {
private static @NonNull OutputStream getOutputStream(@NonNull Context context, File outputFile) throws IOException {
AttachmentSecret attachmentSecret = AttachmentSecretProvider.getInstance(context).getOrCreateAttachmentSecret();
return ModernEncryptingPartOutputStream.createFor(attachmentSecret, outputFile, true).second;
return ModernEncryptingPartOutputStream.createFor(attachmentSecret, outputFile, true).getSecond();
}
private static @NonNull InputStream getInputStream(@NonNull Context context, File inputFile) throws IOException {

View File

@@ -7,7 +7,6 @@ import android.database.sqlite.SQLiteDatabase
import android.database.sqlite.SQLiteOpenHelper
import android.database.sqlite.SQLiteTransactionListener
import android.os.CancellationSignal
import android.util.Pair
import androidx.sqlite.db.SupportSQLiteDatabase
import androidx.sqlite.db.SupportSQLiteQuery
import androidx.sqlite.db.SupportSQLiteStatement
@@ -160,7 +159,7 @@ class SpinnerTestSqliteOpenHelper(context: Context) : SQLiteOpenHelper(context,
override val isWriteAheadLoggingEnabled: Boolean
get() = readableDatabase.isWriteAheadLoggingEnabled
override val attachedDbs: List<Pair<String, String>>?
override val attachedDbs: List<android.util.Pair<String, String>>?
get() = readableDatabase.attachedDbs
override val isDatabaseIntegrityOk: Boolean