Merge remote-tracking branch 'origin/main'

This commit is contained in:
Hosted Weblate
2025-02-26 23:14:09 +01:00
23 changed files with 63 additions and 76 deletions
@@ -183,7 +183,7 @@ public class InputPanel extends ConstraintLayout
if (quoteView.getVisibility() == View.VISIBLE && quoteView.getBody() != null) {
return Optional.of(new QuoteModel(
quoteView.getDcContact(), quoteView.getBody().toString(),
false, quoteView.getAttachments(), quoteView.getOriginalMsg()
quoteView.getAttachments(), quoteView.getOriginalMsg()
));
} else {
return Optional.absent();
@@ -83,7 +83,7 @@ public class ContactSelectionListItem extends LinearLayout implements RecipientM
} else {
this.avatar.setAvatar(glideRequests, recipient, false);
}
this.avatar.setSeenRecently(contact!=null? contact.wasSeenRecently() : false);
this.avatar.setSeenRecently(contact != null && contact.wasSeenRecently());
setText(name, number, label, contact);
setEnabled(enabled);
@@ -110,7 +110,7 @@ public class ContactSelectionListItem extends LinearLayout implements RecipientM
this.nameView.setText(name==null? "#" : name);
if(number!=null) {
this.numberView.setText(number == null ? "" : number);
this.numberView.setText(number);
this.labelView.setText(label==null? "" : label);
this.numberContainer.setVisibility(View.VISIBLE);
}
@@ -154,7 +154,7 @@ public class ContactSelectionListItem extends LinearLayout implements RecipientM
Util.runOnMain(() -> {
avatar.setAvatar(glideRequests, recipient, false);
DcContact contact = recipient.getDcContact();
avatar.setSeenRecently(contact!=null? contact.wasSeenRecently() : false);
avatar.setSeenRecently(contact != null && contact.wasSeenRecently());
nameView.setText(recipient.toShortString());
});
}
@@ -55,7 +55,7 @@ public abstract class LocalFileContactPhoto implements ContactPhoto {
@Override
public boolean equals(Object other) {
if (other == null || !(other instanceof LocalFileContactPhoto)) return false;
if (!(other instanceof LocalFileContactPhoto)) return false;
LocalFileContactPhoto that = (LocalFileContactPhoto) other;
return this.address.equals(that.address) && this.id == that.id && this.path.equals(that.path);
@@ -115,7 +115,7 @@ public abstract class CursorRecyclerViewAdapter<VH extends RecyclerView.ViewHold
@SuppressWarnings("unchecked")
@Override
public final void onViewRecycled(ViewHolder holder) {
public final void onViewRecycled(@NonNull ViewHolder holder) {
if (!(holder instanceof HeaderFooterViewHolder)) {
onItemViewRecycled((VH)holder);
}
@@ -123,8 +123,9 @@ public abstract class CursorRecyclerViewAdapter<VH extends RecyclerView.ViewHold
public void onItemViewRecycled(VH holder) {}
@NonNull
@Override
public final ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
public final ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
switch (viewType) {
case HEADER_TYPE: return new HeaderFooterViewHolder(header);
case FOOTER_TYPE: return new HeaderFooterViewHolder(footer);
@@ -136,7 +137,7 @@ public abstract class CursorRecyclerViewAdapter<VH extends RecyclerView.ViewHold
@SuppressWarnings("unchecked")
@Override
public final void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int position) {
public final void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int position) {
if (!isHeaderPosition(position) && !isFooterPosition(position)) {
if (isFastAccessPosition(position)) onBindFastAccessItemViewHolder((VH)viewHolder, position);
else onBindItemViewHolder((VH)viewHolder, getCursorAtPositionOrThrow(position));
@@ -73,7 +73,7 @@ public class ThreadRecord {
}
public @NonNull String getBody() {
return body == null ? "" : body;
return body;
}
public Recipient getRecipient() {
@@ -29,7 +29,7 @@ public class DcLocation extends Observable {
public boolean isValid() {
return !lastLocation.getProvider().equals("?");
return !"?".equals(lastLocation.getProvider());
}
void updateLocation(Location location) {
@@ -47,8 +47,7 @@ public class DcLocation extends Observable {
}
private Location getDefault() {
Location location = new Location("?");
return location;
return new Location("?");
}
/** https://developer.android.com/guide/topics/location/strategies
@@ -28,7 +28,7 @@ public class DcLocationManager implements Observer {
public void onServiceConnected(ComponentName name, IBinder service) {
Log.d(TAG, "background service connected");
serviceBinder = (LocationBackgroundService.LocationBackgroundServiceBinder) service;
while (pendingShareLastLocation.size() > 0) {
while (!pendingShareLastLocation.isEmpty()) {
shareLastLocation(pendingShareLastLocation.pop());
}
}
@@ -12,6 +12,8 @@ import android.os.Bundle;
import android.os.IBinder;
import android.util.Log;
import androidx.annotation.NonNull;
public class LocationBackgroundService extends Service {
private static final int INITIAL_TIMEOUT = 1000 * 60 * 2;
@@ -111,7 +113,7 @@ public class LocationBackgroundService extends Service {
private class ServiceLocationListener implements LocationListener {
@Override
public void onLocationChanged(Location location) {
public void onLocationChanged(@NonNull Location location) {
Log.d(TAG, "onLocationChanged: " + location);
if (location == null) {
return;
@@ -120,12 +122,12 @@ public class LocationBackgroundService extends Service {
}
@Override
public void onProviderDisabled(String provider) {
public void onProviderDisabled(@NonNull String provider) {
Log.e(TAG, "onProviderDisabled: " + provider);
}
@Override
public void onProviderEnabled(String provider) {
public void onProviderEnabled(@NonNull String provider) {
Log.e(TAG, "onProviderEnabled: " + provider);
}
@@ -27,7 +27,7 @@ class ContactPhotoFetcher implements DataFetcher<InputStream> {
}
@Override
public void loadData(Priority priority, DataCallback<? super InputStream> callback) {
public void loadData(@NonNull Priority priority, DataCallback<? super InputStream> callback) {
try {
inputStream = contactPhoto.openInputStream(context);
callback.onDataReady(inputStream);
@@ -40,7 +40,7 @@ class ContactPhotoFetcher implements DataFetcher<InputStream> {
public void cleanup() {
try {
if (inputStream != null) inputStream.close();
} catch (IOException e) {}
} catch (IOException ignored) {}
}
@Override
@@ -2,6 +2,7 @@ package org.thoughtcrime.securesms.glide;
import android.content.Context;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.bumptech.glide.load.Options;
@@ -23,12 +24,12 @@ public class ContactPhotoLoader implements ModelLoader<ContactPhoto, InputStream
@Nullable
@Override
public LoadData<InputStream> buildLoadData(ContactPhoto contactPhoto, int width, int height, Options options) {
public LoadData<InputStream> buildLoadData(@NonNull ContactPhoto contactPhoto, int width, int height, @NonNull Options options) {
return new LoadData<>(contactPhoto, new ContactPhotoFetcher(context, contactPhoto));
}
@Override
public boolean handles(ContactPhoto contactPhoto) {
public boolean handles(@NonNull ContactPhoto contactPhoto) {
return true;
}
@@ -40,8 +41,9 @@ public class ContactPhotoLoader implements ModelLoader<ContactPhoto, InputStream
this.context = context.getApplicationContext();
}
@NonNull
@Override
public ModelLoader<ContactPhoto, InputStream> build(MultiModelLoaderFactory multiFactory) {
public ModelLoader<ContactPhoto, InputStream> build(@NonNull MultiModelLoaderFactory multiFactory) {
return new ContactPhotoLoader(context);
}
@@ -273,7 +273,7 @@ public class AttachmentManager {
if (slide == null) {
setAttachmentPresent(false);
result.set(false);
} else if (slide.getFileSize()>1*1024*1024*1024) {
} else if (slide.getFileSize() > 1024 * 1024 * 1024) {
// this is only a rough check, videos and images may be recoded
// and the core checks more carefully later.
setAttachmentPresent(false);
@@ -333,28 +333,24 @@ public class AttachmentManager {
}
private @Nullable Slide getContentResolverSlideInfo(Uri uri, int width, int height, int chatId) {
Cursor cursor = null;
long start = System.currentTimeMillis();
try {
cursor = context.getContentResolver().query(uri, null, null, null, null);
long start = System.currentTimeMillis();
try (Cursor cursor = context.getContentResolver().query(uri, null, null, null, null)) {
if (cursor != null && cursor.moveToFirst()) {
String fileName = cursor.getString(cursor.getColumnIndexOrThrow(OpenableColumns.DISPLAY_NAME));
long fileSize = cursor.getLong(cursor.getColumnIndexOrThrow(OpenableColumns.SIZE));
long fileSize = cursor.getLong(cursor.getColumnIndexOrThrow(OpenableColumns.SIZE));
String mimeType = context.getContentResolver().getType(uri);
if (width == 0 || height == 0) {
Pair<Integer, Integer> dimens = MediaUtil.getDimensions(context, mimeType, uri);
width = dimens.first;
width = dimens.first;
height = dimens.second;
}
Log.w(TAG, "remote slide with size " + fileSize + " took " + (System.currentTimeMillis() - start) + "ms");
return mediaType.createSlide(context, uri, fileName, mimeType, fileSize, width, height, chatId);
}
} finally {
if (cursor != null) cursor.close();
}
return null;
@@ -395,7 +391,7 @@ public class AttachmentManager {
try {
fileName = new File(uri.getPath()).getName();
} catch(Exception e) {
Log.w(TAG, "Could not get file name from uri: " + e.toString());
Log.w(TAG, "Could not get file name from uri: " + e);
}
}
@@ -431,14 +427,11 @@ public class AttachmentManager {
public static @Nullable String getFileName(Context context, Uri uri) {
String result = null;
if (uri.getScheme().equals("content")) {
Cursor cursor = context.getContentResolver().query(uri, new String[]{OpenableColumns.DISPLAY_NAME}, null, null, null);
try {
if ("content".equals(uri.getScheme())) {
try (Cursor cursor = context.getContentResolver().query(uri, new String[]{OpenableColumns.DISPLAY_NAME}, null, null, null)) {
if (cursor != null && cursor.moveToFirst()) {
result = cursor.getString(cursor.getColumnIndexOrThrow(OpenableColumns.DISPLAY_NAME));
}
} finally {
if (cursor != null) cursor.close();
}
}
if (result == null) {
@@ -495,11 +488,10 @@ public class AttachmentManager {
.withPermanentDenialDialog(activity.getString(R.string.perm_explain_access_to_location_denied))
.onAllGranted(() -> {
ShareLocationDialog.show(activity, durationInSeconds -> {
switch (durationInSeconds) {
case 1: dcLocationManager.shareLastLocation(chatId); break;
default:
dcLocationManager.shareLocation(durationInSeconds, chatId);
break;
if (durationInSeconds == 1) {
dcLocationManager.shareLastLocation(chatId);
} else {
dcLocationManager.shareLocation(durationInSeconds, chatId);
}
});
});
@@ -704,7 +696,7 @@ public class AttachmentManager {
return slide;
}
} catch (RpcException e) {
e.printStackTrace();
Log.e(TAG, "Error in call to rpc.parseVcard()", e);
}
}
@@ -58,11 +58,6 @@ public class AudioSlide extends Slide {
return null;
}
@Override
public boolean hasImage() {
return false;
}
@Override
public boolean hasAudio() {
return true;
@@ -3,8 +3,6 @@ package org.thoughtcrime.securesms.mms;
import android.content.Context;
import android.net.Uri;
import androidx.annotation.Nullable;
import com.b44t.messenger.DcMsg;
import org.thoughtcrime.securesms.util.MediaUtil;
@@ -19,9 +17,4 @@ public class GifSlide extends ImageSlide {
super(context, constructAttachmentFromUri(context, uri, MediaUtil.IMAGE_GIF, size, width, height, uri, fileName, false));
}
@Override
@Nullable
public Uri getThumbnailUri() {
return getUri();
}
}
@@ -17,7 +17,7 @@ public class QuoteModel {
private final List<Attachment> attachments;
private final DcMsg quotedMsg;
public QuoteModel(DcContact author, String text, boolean missing, @Nullable List<Attachment> attachments, DcMsg quotedMsg) {
public QuoteModel(DcContact author, String text, @Nullable List<Attachment> attachments, DcMsg quotedMsg) {
this.author = author;
this.text = text;
this.attachments = attachments;
@@ -32,7 +32,7 @@ public class SignalGlideModule extends AppGlideModule {
}
@Override
public void applyOptions(Context context, GlideBuilder builder) {
public void applyOptions(@NonNull Context context, GlideBuilder builder) {
builder.setLogLevel(Log.ERROR);
// builder.setDiskCache(new NoopDiskCacheFactory());
}
@@ -1,7 +1,7 @@
package org.thoughtcrime.securesms.notifications;
import android.content.Context;
import android.media.AudioManager;
import android.media.AudioAttributes;
import android.media.SoundPool;
import android.util.Log;
@@ -28,7 +28,11 @@ public class InChatSounds {
private InChatSounds(Context context) {
try {
soundPool = new SoundPool(3, AudioManager.STREAM_SYSTEM, 0);
AudioAttributes audioAttrs = new AudioAttributes.Builder()
.setUsage(AudioAttributes.USAGE_ASSISTANCE_SONIFICATION)
.setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
.build();
soundPool = new SoundPool.Builder().setMaxStreams(3).setAudioAttributes(audioAttrs).build();
soundIn = soundPool.load(context, R.raw.sound_in, 1);
soundOut = soundPool.load(context, R.raw.sound_out, 1);
} catch(Exception e) {
@@ -241,7 +241,7 @@ public class NotificationCenter {
return new ChatData(accountId, chatId);
}
}
} catch(Exception e) { }
} catch(Exception ignored) { }
return null;
}
@@ -326,7 +326,7 @@ public class NotificationCenter {
}
}
catch(Exception e) {
e.printStackTrace();
Log.e(TAG, "Error in getNotificationChannel()", e);
}
}
@@ -604,7 +604,7 @@ public class NotificationCenter {
.setGroup(GRP_MSG + "." + accountId)
.setGroupSummary(true)
.setSmallIcon(R.drawable.icon_notification)
.setColor(context.getResources().getColor(R.color.delta_primary))
.setColor(context.getResources().getColor(R.color.delta_primary, null))
.setCategory(NotificationCompat.CATEGORY_MESSAGE)
.setContentTitle("Delta Chat") // content title would only be used on SDK <24
.setContentText("New messages") // content text would only be used on SDK <24
@@ -692,7 +692,7 @@ public class NotificationCenter {
}
}
private class ChatData {
private static class ChatData {
public final int accountId;
public final int chatId;
@@ -66,18 +66,18 @@ class PermissionsRequest {
}
}
if (allGrantedListener != null && granted.size() > 0 && (denied.size() == 0 && permanentlyDenied.size() == 0)) {
if (allGrantedListener != null && !granted.isEmpty() && (denied.isEmpty() && permanentlyDenied.isEmpty())) {
allGrantedListener.run();
} else if (someGrantedListener != null && granted.size() > 0) {
} else if (someGrantedListener != null && !granted.isEmpty()) {
someGrantedListener.accept(granted);
}
if (denied.size() > 0) {
if (!denied.isEmpty()) {
if (anyDeniedListener != null) anyDeniedListener.run();
if (someDeniedListener != null) someDeniedListener.accept(denied);
}
if (permanentlyDenied.size() > 0) {
if (!permanentlyDenied.isEmpty()) {
if (anyPermanentlyDeniedListener != null) anyPermanentlyDeniedListener.run();
if (somePermanentlyDeniedListener != null) somePermanentlyDeniedListener.accept(permanentlyDenied);
}
@@ -4,6 +4,7 @@ import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.preference.ListPreference;
import androidx.preference.Preference;
@@ -82,9 +83,9 @@ public class AppearancePreferenceFragment extends ListSummaryPreferenceFragment
private class BackgroundClickListener implements Preference.OnPreferenceClickListener {
@Override
public boolean onPreferenceClick(Preference preference) {
public boolean onPreferenceClick(@NonNull Preference preference) {
Intent intent = new Intent(getContext(), ChatBackgroundActivity.class);
getActivity().startActivity(intent);
requireActivity().startActivity(intent);
return true;
}
}
@@ -134,11 +134,7 @@ public class ChatBackgroundActivity extends PassphraseRequiredActionBarActivity
.get();
FileOutputStream outStream = new FileOutputStream(destinationPath);
scaledBitmap.compress(Bitmap.CompressFormat.JPEG, 85, outStream);
} catch (InterruptedException e) {
e.printStackTrace();
Prefs.setBackgroundImagePath(context, accountId, "");
showBackgroundSaveError();
} catch (ExecutionException e) {
} catch (InterruptedException | ExecutionException e) {
e.printStackTrace();
Prefs.setBackgroundImagePath(context, accountId, "");
showBackgroundSaveError();
@@ -4,6 +4,7 @@ package org.thoughtcrime.securesms.preferences;
import android.os.Bundle;
import android.view.View;
import androidx.annotation.NonNull;
import androidx.fragment.app.DialogFragment;
import androidx.preference.Preference;
import androidx.preference.PreferenceFragmentCompat;
@@ -26,7 +27,7 @@ public abstract class CorrectedPreferenceFragment extends PreferenceFragmentComp
}
@Override
public void onDisplayPreferenceDialog(Preference preference) {
public void onDisplayPreferenceDialog(@NonNull Preference preference) {
DialogFragment dialogFragment = null;
if (preference instanceof CustomDefaultPreference) {
@@ -72,7 +72,7 @@ public abstract class ListSummaryPreferenceFragment extends CorrectedPreferenceF
protected class ListSummaryListener implements Preference.OnPreferenceChangeListener {
@Override
public boolean onPreferenceChange(Preference preference, Object value) {
public boolean onPreferenceChange(@NonNull Preference preference, Object value) {
updateListSummary(preference, value);
return true;
}
@@ -7,6 +7,7 @@ import android.util.AttributeSet;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.preference.Preference;
import androidx.preference.PreferenceViewHolder;
@@ -50,7 +51,7 @@ public class ProfilePreference extends Preference {
}
@Override
public void onBindViewHolder(PreferenceViewHolder viewHolder) {
public void onBindViewHolder(@NonNull PreferenceViewHolder viewHolder) {
super.onBindViewHolder(viewHolder);
avatarView = (ImageView)viewHolder.findViewById(R.id.avatar);
profileNameView = (TextView)viewHolder.findViewById(R.id.profile_name);