diff --git a/app/build.gradle b/app/build.gradle index 4cd08255d6..de71e3209a 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -10,29 +10,26 @@ buildscript { classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion" classpath "org.jetbrains.kotlin:kotlin-serialization:$kotlinVersion" classpath "com.google.gms:google-services:$googleServicesVersion" - classpath "com.google.dagger:hilt-android-gradle-plugin:$daggerVersion" } } plugins { - id 'kotlin-kapt' + id 'com.google.devtools.ksp' id 'com.google.dagger.hilt.android' } apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply plugin: 'witness' -apply plugin: 'kotlin-kapt' apply plugin: 'kotlin-parcelize' apply plugin: 'kotlinx-serialization' -apply plugin: 'dagger.hilt.android.plugin' configurations.all { exclude module: "commons-logging" } -def canonicalVersionCode = 374 -def canonicalVersionName = "1.18.5" +def canonicalVersionCode = 376 +def canonicalVersionName = "1.18.6" def postFixSize = 10 def abiPostFix = ['armeabi-v7a' : 1, @@ -89,7 +86,7 @@ android { compose true } composeOptions { - kotlinCompilerExtensionVersion '1.4.7' + kotlinCompilerExtensionVersion '1.5.14' } defaultConfig { @@ -239,8 +236,9 @@ android { dependencies { - implementation("com.google.dagger:hilt-android:2.46.1") - kapt("com.google.dagger:hilt-android-compiler:2.44") + implementation("com.google.dagger:hilt-android:$daggerHiltVersion") + ksp("com.google.dagger:hilt-compiler:$daggerHiltVersion") + ksp("androidx.hilt:hilt-compiler:$jetpackHiltVersion") implementation "androidx.appcompat:appcompat:$appcompatVersion" implementation 'androidx.recyclerview:recyclerview:1.2.1' @@ -281,8 +279,7 @@ dependencies { implementation 'commons-net:commons-net:3.7.2' implementation 'com.github.chrisbanes:PhotoView:2.1.3' implementation "com.github.bumptech.glide:glide:$glideVersion" - annotationProcessor "com.github.bumptech.glide:compiler:$glideVersion" - kapt "com.github.bumptech.glide:compiler:$glideVersion" + ksp "com.github.bumptech.glide:ksp:$glideVersion" implementation 'com.makeramen:roundedimageview:2.1.0' implementation 'com.pnikosis:materialish-progress:1.5' implementation 'org.greenrobot:eventbus:3.0.0' @@ -290,8 +287,6 @@ dependencies { implementation 'com.theartofdev.edmodo:android-image-cropper:2.8.0' implementation 'com.melnykov:floatingactionbutton:1.3.0' implementation 'com.google.zxing:android-integration:3.1.0' - implementation "com.google.dagger:hilt-android:$daggerVersion" - kapt "com.google.dagger:hilt-compiler:$daggerVersion" implementation 'mobi.upod:time-duration-picker:1.1.3' implementation 'com.google.zxing:core:3.2.1' implementation ('com.davemorrissey.labs:subsampling-scale-image-view:3.6.0') { @@ -415,8 +410,3 @@ def autoResConfig() { .collect { matcher -> matcher.group(1) } .sort() } - -// Allow references to generated code -kapt { - correctErrorTypes = true -} diff --git a/app/src/androidTest/java/network/loki/messenger/HomeActivityTests.kt b/app/src/androidTest/java/network/loki/messenger/HomeActivityTests.kt index f1889c9217..d39ec624e3 100644 --- a/app/src/androidTest/java/network/loki/messenger/HomeActivityTests.kt +++ b/app/src/androidTest/java/network/loki/messenger/HomeActivityTests.kt @@ -40,7 +40,7 @@ import org.session.libsignal.utilities.guava.Optional import org.thoughtcrime.securesms.conversation.v2.ConversationActivityV2 import org.thoughtcrime.securesms.conversation.v2.input_bar.InputBar import org.thoughtcrime.securesms.home.HomeActivity -import org.thoughtcrime.securesms.mms.GlideApp +import com.bumptech.glide.Glide @RunWith(AndroidJUnit4::class) @LargeTest @@ -71,7 +71,7 @@ class HomeActivityTests { onView(allOf(isDescendantOfA(withId(R.id.inputBar)),withId(R.id.inputBarEditText))).perform(ViewActions.replaceText(messageToSend)) if (linkPreview != null) { val activity = activityMonitor.waitForActivity() as ConversationActivityV2 - val glide = GlideApp.with(activity) + val glide = Glide.with(activity) activity.findViewById(R.id.inputBar).updateLinkPreviewDraft(glide, linkPreview) } onView(allOf(isDescendantOfA(withId(R.id.inputBar)),inputButtonWithDrawable(R.drawable.ic_arrow_up))).perform(ViewActions.click()) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 7e04ad44ca..9737a77d2e 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -60,7 +60,6 @@ - diff --git a/app/src/main/java/org/thoughtcrime/securesms/ApplicationContext.java b/app/src/main/java/org/thoughtcrime/securesms/ApplicationContext.java index d04dcb420f..878e052ced 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/ApplicationContext.java +++ b/app/src/main/java/org/thoughtcrime/securesms/ApplicationContext.java @@ -203,6 +203,17 @@ public class ApplicationContext extends Application implements DefaultLifecycleO DatabaseModule.init(this); super.onCreate(); + + // we need to clear the snode and onionrequest databases once on first launch + // in order to apply a patch that adds a version number to the Snode objects. + if(!getPrefs().getHasAppliedPatchSnodeVersion()) { + ThreadUtils.queue(() -> { + lokiAPIDatabase.clearSnodePool(); + lokiAPIDatabase.clearOnionRequestPaths(); + getPrefs().setHasAppliedPatchSnodeVersion(true); + }); + } + MessagingModuleConfiguration.shared = new MessagingModuleConfiguration( this, storage, diff --git a/app/src/main/java/org/thoughtcrime/securesms/MediaGalleryAdapter.java b/app/src/main/java/org/thoughtcrime/securesms/MediaGalleryAdapter.java index 62766d1cd7..9a262a2b0a 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/MediaGalleryAdapter.java +++ b/app/src/main/java/org/thoughtcrime/securesms/MediaGalleryAdapter.java @@ -29,7 +29,7 @@ import com.codewaves.stickyheadergrid.StickyHeaderGridAdapter; import org.thoughtcrime.securesms.conversation.v2.utilities.ThumbnailView; import org.thoughtcrime.securesms.database.MediaDatabase.MediaRecord; import org.thoughtcrime.securesms.database.loaders.BucketedThreadMediaLoader.BucketedThreadMedia; -import org.thoughtcrime.securesms.mms.GlideRequests; +import com.bumptech.glide.RequestManager; import org.thoughtcrime.securesms.mms.Slide; import org.thoughtcrime.securesms.util.MediaUtil; @@ -46,7 +46,7 @@ class MediaGalleryAdapter extends StickyHeaderGridAdapter { private static final String TAG = MediaGalleryAdapter.class.getSimpleName(); private final Context context; - private final GlideRequests glideRequests; + private final RequestManager glideRequests; private final Locale locale; private final ItemClickListener itemClickListener; private final Set selected; @@ -74,7 +74,7 @@ class MediaGalleryAdapter extends StickyHeaderGridAdapter { } MediaGalleryAdapter(@NonNull Context context, - @NonNull GlideRequests glideRequests, + @NonNull RequestManager glideRequests, BucketedThreadMedia media, Locale locale, ItemClickListener clickListener) diff --git a/app/src/main/java/org/thoughtcrime/securesms/MediaOverviewActivity.java b/app/src/main/java/org/thoughtcrime/securesms/MediaOverviewActivity.java index 95ba15c82e..7715eab01e 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/MediaOverviewActivity.java +++ b/app/src/main/java/org/thoughtcrime/securesms/MediaOverviewActivity.java @@ -61,7 +61,7 @@ import org.thoughtcrime.securesms.database.MediaDatabase; import org.thoughtcrime.securesms.database.loaders.BucketedThreadMediaLoader; import org.thoughtcrime.securesms.database.loaders.BucketedThreadMediaLoader.BucketedThreadMedia; import org.thoughtcrime.securesms.database.loaders.ThreadMediaLoader; -import org.thoughtcrime.securesms.mms.GlideApp; +import com.bumptech.glide.Glide; import org.thoughtcrime.securesms.permissions.Permissions; import org.session.libsession.utilities.recipients.Recipient; import org.thoughtcrime.securesms.util.AttachmentUtil; @@ -227,7 +227,7 @@ public class MediaOverviewActivity extends PassphraseRequiredActionBarActivity { this.gridManager = new StickyHeaderGridLayoutManager(getResources().getInteger(R.integer.media_overview_cols)); this.recyclerView.setAdapter(new MediaGalleryAdapter(getContext(), - GlideApp.with(this), + Glide.with(this), new BucketedThreadMedia(getContext()), locale, this)); diff --git a/app/src/main/java/org/thoughtcrime/securesms/MediaPreviewActivity.java b/app/src/main/java/org/thoughtcrime/securesms/MediaPreviewActivity.java index 2e67becbfd..b609b54fc6 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/MediaPreviewActivity.java +++ b/app/src/main/java/org/thoughtcrime/securesms/MediaPreviewActivity.java @@ -72,8 +72,8 @@ import org.thoughtcrime.securesms.database.loaders.PagingMediaLoader; import org.thoughtcrime.securesms.database.model.MmsMessageRecord; import org.thoughtcrime.securesms.mediapreview.MediaPreviewViewModel; import org.thoughtcrime.securesms.mediapreview.MediaRailAdapter; -import org.thoughtcrime.securesms.mms.GlideApp; -import org.thoughtcrime.securesms.mms.GlideRequests; +import com.bumptech.glide.Glide; +import com.bumptech.glide.RequestManager; import org.thoughtcrime.securesms.mms.Slide; import org.thoughtcrime.securesms.permissions.Permissions; import org.thoughtcrime.securesms.util.AttachmentUtil; @@ -281,7 +281,7 @@ public class MediaPreviewActivity extends PassphraseRequiredActionBarActivity im mediaPager.setOffscreenPageLimit(1); albumRail = findViewById(R.id.media_preview_album_rail); - albumRailAdapter = new MediaRailAdapter(GlideApp.with(this), this, false); + albumRailAdapter = new MediaRailAdapter(Glide.with(this), this, false); albumRail.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false)); albumRail.setAdapter(albumRailAdapter); @@ -370,7 +370,7 @@ public class MediaPreviewActivity extends PassphraseRequiredActionBarActivity im if (conversationRecipient != null) { getSupportLoaderManager().restartLoader(0, null, this); } else { - adapter = new SingleItemPagerAdapter(this, GlideApp.with(this), getWindow(), initialMediaUri, initialMediaType, initialMediaSize); + adapter = new SingleItemPagerAdapter(this, Glide.with(this), getWindow(), initialMediaUri, initialMediaType, initialMediaSize); mediaPager.setAdapter(adapter); if (initialCaption != null) { @@ -518,7 +518,7 @@ public class MediaPreviewActivity extends PassphraseRequiredActionBarActivity im mediaPager.removeOnPageChangeListener(viewPagerListener); - adapter = new CursorPagerAdapter(this, GlideApp.with(this), getWindow(), data.first, data.second, leftIsRecent); + adapter = new CursorPagerAdapter(this, Glide.with(this), getWindow(), data.first, data.second, leftIsRecent); mediaPager.setAdapter(adapter); viewModel.setCursor(this, data.first, leftIsRecent); @@ -588,7 +588,7 @@ public class MediaPreviewActivity extends PassphraseRequiredActionBarActivity im private static class SingleItemPagerAdapter extends MediaItemAdapter { - private final GlideRequests glideRequests; + private final RequestManager glideRequests; private final Window window; private final Uri uri; private final String mediaType; @@ -596,7 +596,7 @@ public class MediaPreviewActivity extends PassphraseRequiredActionBarActivity im private final LayoutInflater inflater; - SingleItemPagerAdapter(@NonNull Context context, @NonNull GlideRequests glideRequests, + SingleItemPagerAdapter(@NonNull Context context, @NonNull RequestManager glideRequests, @NonNull Window window, @NonNull Uri uri, @NonNull String mediaType, long size) { @@ -663,14 +663,14 @@ public class MediaPreviewActivity extends PassphraseRequiredActionBarActivity im private final WeakHashMap mediaViews = new WeakHashMap<>(); private final Context context; - private final GlideRequests glideRequests; + private final RequestManager glideRequests; private final Window window; private final Cursor cursor; private final boolean leftIsRecent; private int autoPlayPosition; - CursorPagerAdapter(@NonNull Context context, @NonNull GlideRequests glideRequests, + CursorPagerAdapter(@NonNull Context context, @NonNull RequestManager glideRequests, @NonNull Window window, @NonNull Cursor cursor, int autoPlayPosition, boolean leftIsRecent) { diff --git a/app/src/main/java/org/thoughtcrime/securesms/PassphraseRequiredActionBarActivity.java b/app/src/main/java/org/thoughtcrime/securesms/PassphraseRequiredActionBarActivity.java index cd2b5a776d..08efd32cb1 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/PassphraseRequiredActionBarActivity.java +++ b/app/src/main/java/org/thoughtcrime/securesms/PassphraseRequiredActionBarActivity.java @@ -34,7 +34,7 @@ public abstract class PassphraseRequiredActionBarActivity extends BaseActionBarA private BroadcastReceiver clearKeyReceiver; @Override - protected final void onCreate(Bundle savedInstanceState) { + protected void onCreate(Bundle savedInstanceState) { Log.i(TAG, "onCreate(" + savedInstanceState + ")"); onPreCreate(); diff --git a/app/src/main/java/org/thoughtcrime/securesms/calls/WebRtcCallActivity.kt b/app/src/main/java/org/thoughtcrime/securesms/calls/WebRtcCallActivity.kt index df27405426..300f5f3d49 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/calls/WebRtcCallActivity.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/calls/WebRtcCallActivity.kt @@ -22,6 +22,7 @@ import androidx.core.content.ContextCompat import androidx.core.view.isVisible import androidx.lifecycle.lifecycleScope import androidx.localbroadcastmanager.content.LocalBroadcastManager +import com.bumptech.glide.Glide import com.bumptech.glide.load.engine.DiskCacheStrategy import dagger.hilt.android.AndroidEntryPoint import kotlinx.coroutines.Job @@ -38,7 +39,6 @@ import org.session.libsession.utilities.truncateIdForDisplay import org.session.libsignal.utilities.Log import org.thoughtcrime.securesms.PassphraseRequiredActionBarActivity import org.thoughtcrime.securesms.dependencies.DatabaseComponent -import org.thoughtcrime.securesms.mms.GlideApp import org.thoughtcrime.securesms.permissions.Permissions import org.thoughtcrime.securesms.service.WebRtcCallService import org.thoughtcrime.securesms.util.AvatarPlaceholderGenerator @@ -73,7 +73,7 @@ class WebRtcCallActivity : PassphraseRequiredActionBarActivity() { @Inject lateinit var prefs: TextSecurePreferences private val viewModel by viewModels() - private val glide by lazy { GlideApp.with(this) } + private val glide by lazy { Glide.with(this) } private lateinit var binding: ActivityWebrtcBinding private var uiJob: Job? = null private var wantsToAnswer = false diff --git a/app/src/main/java/org/thoughtcrime/securesms/components/AvatarImageView.java b/app/src/main/java/org/thoughtcrime/securesms/components/AvatarImageView.java index 573e8d2d2b..0139e9932c 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/components/AvatarImageView.java +++ b/app/src/main/java/org/thoughtcrime/securesms/components/AvatarImageView.java @@ -25,8 +25,8 @@ import org.session.libsession.utilities.Address; import org.session.libsession.utilities.ThemeUtil; import org.session.libsession.utilities.recipients.Recipient; import org.session.libsession.utilities.recipients.RecipientExporter; -import org.thoughtcrime.securesms.mms.GlideApp; -import org.thoughtcrime.securesms.mms.GlideRequests; +import com.bumptech.glide.Glide; +import com.bumptech.glide.RequestManager; import org.thoughtcrime.securesms.util.AvatarPlaceholderGenerator; import java.util.Objects; @@ -117,10 +117,10 @@ public class AvatarImageView extends AppCompatImageView { } private void updateAvatar(Recipient recipient) { - setAvatar(GlideApp.with(getContext()), recipient, false); + setAvatar(Glide.with(getContext()), recipient, false); } - public void setAvatar(@NonNull GlideRequests requestManager, @Nullable Recipient recipient, boolean quickContactEnabled) { + public void setAvatar(@NonNull RequestManager requestManager, @Nullable Recipient recipient, boolean quickContactEnabled) { if (recipient != null) { if (recipient.isLocalNumber()) { setImageDrawable(new ResourceContactPhoto(R.drawable.ic_note_to_self).asDrawable(getContext(), recipient.getColor().toAvatarColor(getContext()), inverted)); @@ -156,7 +156,7 @@ public class AvatarImageView extends AppCompatImageView { } } - public void clear(@NonNull GlideRequests glideRequests) { + public void clear(@NonNull RequestManager glideRequests) { glideRequests.clear(this); } diff --git a/app/src/main/java/org/thoughtcrime/securesms/components/MediaView.java b/app/src/main/java/org/thoughtcrime/securesms/components/MediaView.java index 14b70a53d6..bb973c23ff 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/components/MediaView.java +++ b/app/src/main/java/org/thoughtcrime/securesms/components/MediaView.java @@ -13,7 +13,7 @@ import android.view.Window; import android.widget.FrameLayout; import network.loki.messenger.R; -import org.thoughtcrime.securesms.mms.GlideRequests; +import com.bumptech.glide.RequestManager; import org.thoughtcrime.securesms.mms.VideoSlide; import org.thoughtcrime.securesms.video.VideoPlayer; @@ -54,7 +54,7 @@ public class MediaView extends FrameLayout { this.videoView = new Stub<>(findViewById(R.id.video_player_stub)); } - public void set(@NonNull GlideRequests glideRequests, + public void set(@NonNull RequestManager glideRequests, @NonNull Window window, @NonNull Uri source, @NonNull String mediaType, diff --git a/app/src/main/java/org/thoughtcrime/securesms/components/ProfilePictureView.kt b/app/src/main/java/org/thoughtcrime/securesms/components/ProfilePictureView.kt index 2e13197f7d..b22f03f80d 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/components/ProfilePictureView.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/components/ProfilePictureView.kt @@ -21,8 +21,8 @@ import org.session.libsession.utilities.prefs import org.session.libsession.utilities.recipients.Recipient import org.session.libsignal.utilities.Log import org.thoughtcrime.securesms.dependencies.DatabaseComponent -import org.thoughtcrime.securesms.mms.GlideApp -import org.thoughtcrime.securesms.mms.GlideRequests +import com.bumptech.glide.Glide +import com.bumptech.glide.RequestManager class ProfilePictureView @JvmOverloads constructor( context: Context, attrs: AttributeSet? = null @@ -30,7 +30,7 @@ class ProfilePictureView @JvmOverloads constructor( private val TAG = "ProfilePictureView" private val binding = ViewProfilePictureBinding.inflate(LayoutInflater.from(context), this) - private val glide: GlideRequests = GlideApp.with(this) + private val glide: RequestManager = Glide.with(this) private val prefs = context.prefs private val userPublicKey = prefs.getLocalNumber() var publicKey: String? = null diff --git a/app/src/main/java/org/thoughtcrime/securesms/components/RecentPhotoViewRail.java b/app/src/main/java/org/thoughtcrime/securesms/components/RecentPhotoViewRail.java index 542b7e8ba2..e1d3236a96 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/components/RecentPhotoViewRail.java +++ b/app/src/main/java/org/thoughtcrime/securesms/components/RecentPhotoViewRail.java @@ -28,7 +28,7 @@ import com.bumptech.glide.signature.MediaStoreSignature; import network.loki.messenger.R; import org.thoughtcrime.securesms.database.CursorRecyclerViewAdapter; import org.thoughtcrime.securesms.database.loaders.RecentPhotosLoader; -import org.thoughtcrime.securesms.mms.GlideApp; +import com.bumptech.glide.Glide; import org.session.libsession.utilities.ViewUtil; @@ -118,7 +118,7 @@ public class RecentPhotoViewRail extends FrameLayout implements LoaderManager.Lo Key signature = new MediaStoreSignature(mimeType, dateModified, orientation); - GlideApp.with(getContext().getApplicationContext()) + Glide.with(getContext().getApplicationContext()) .load(uri) .signature(signature) .diskCacheStrategy(DiskCacheStrategy.NONE) diff --git a/app/src/main/java/org/thoughtcrime/securesms/components/StickerView.java b/app/src/main/java/org/thoughtcrime/securesms/components/StickerView.java index 98a623eef3..fd20283ae1 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/components/StickerView.java +++ b/app/src/main/java/org/thoughtcrime/securesms/components/StickerView.java @@ -8,7 +8,7 @@ import android.view.View; import android.widget.FrameLayout; import org.thoughtcrime.securesms.conversation.v2.utilities.ThumbnailView; -import org.thoughtcrime.securesms.mms.GlideRequests; +import com.bumptech.glide.RequestManager; import org.thoughtcrime.securesms.mms.Slide; import org.thoughtcrime.securesms.mms.SlideClickListener; diff --git a/app/src/main/java/org/thoughtcrime/securesms/components/ZoomingImageView.java b/app/src/main/java/org/thoughtcrime/securesms/components/ZoomingImageView.java index 265f707df9..b246bca4d3 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/components/ZoomingImageView.java +++ b/app/src/main/java/org/thoughtcrime/securesms/components/ZoomingImageView.java @@ -25,7 +25,7 @@ import network.loki.messenger.R; import org.thoughtcrime.securesms.components.subsampling.AttachmentBitmapDecoder; import org.thoughtcrime.securesms.components.subsampling.AttachmentRegionDecoder; import org.thoughtcrime.securesms.mms.DecryptableStreamUriLoader.DecryptableUri; -import org.thoughtcrime.securesms.mms.GlideRequests; +import com.bumptech.glide.RequestManager; import org.thoughtcrime.securesms.mms.PartAuthority; import org.thoughtcrime.securesms.util.BitmapDecodingException; import org.thoughtcrime.securesms.util.BitmapUtil; @@ -62,7 +62,7 @@ public class ZoomingImageView extends FrameLayout { } @SuppressLint("StaticFieldLeak") - public void setImageUri(@NonNull GlideRequests glideRequests, @NonNull Uri uri, @NonNull String contentType) + public void setImageUri(@NonNull RequestManager glideRequests, @NonNull Uri uri, @NonNull String contentType) { final Context context = getContext(); final int maxTextureSize = BitmapUtil.getMaxTextureSize(); @@ -97,7 +97,7 @@ public class ZoomingImageView extends FrameLayout { }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } - private void setImageViewUri(@NonNull GlideRequests glideRequests, @NonNull Uri uri) { + private void setImageViewUri(@NonNull RequestManager glideRequests, @NonNull Uri uri) { photoView.setVisibility(View.VISIBLE); subsamplingImageView.setVisibility(View.GONE); diff --git a/app/src/main/java/org/thoughtcrime/securesms/components/emoji/EmojiKeyboardProvider.java b/app/src/main/java/org/thoughtcrime/securesms/components/emoji/EmojiKeyboardProvider.java index 72419f24c6..d34db1d810 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/components/emoji/EmojiKeyboardProvider.java +++ b/app/src/main/java/org/thoughtcrime/securesms/components/emoji/EmojiKeyboardProvider.java @@ -12,7 +12,7 @@ import android.widget.ImageView; import org.thoughtcrime.securesms.components.emoji.EmojiPageViewGridAdapter.VariationSelectorListener; -import org.thoughtcrime.securesms.mms.GlideRequests; +import com.bumptech.glide.RequestManager; import org.thoughtcrime.securesms.util.ResUtil; import org.session.libsession.utilities.ThemeUtil; @@ -87,7 +87,7 @@ public class EmojiKeyboardProvider implements MediaKeyboardProvider, } @Override - public void loadCategoryTabIcon(@NonNull GlideRequests glideRequests, @NonNull ImageView imageView, int index) { + public void loadCategoryTabIcon(@NonNull RequestManager glideRequests, @NonNull ImageView imageView, int index) { Drawable drawable = ResUtil.getDrawable(context, models.get(index).getIconAttr()); imageView.setImageDrawable(drawable); } diff --git a/app/src/main/java/org/thoughtcrime/securesms/components/emoji/MediaKeyboard.java b/app/src/main/java/org/thoughtcrime/securesms/components/emoji/MediaKeyboard.java index 0aa3c33c71..acb53f7767 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/components/emoji/MediaKeyboard.java +++ b/app/src/main/java/org/thoughtcrime/securesms/components/emoji/MediaKeyboard.java @@ -17,7 +17,7 @@ import android.widget.FrameLayout; import org.thoughtcrime.securesms.components.InputAwareLayout.InputView; import org.thoughtcrime.securesms.components.RepeatableImageKey; import org.session.libsignal.utilities.Log; -import org.thoughtcrime.securesms.mms.GlideApp; +import com.bumptech.glide.Glide; import java.util.Arrays; @@ -158,7 +158,7 @@ public class MediaKeyboard extends FrameLayout implements InputView, this.searchButton = view.findViewById(R.id.media_keyboard_search); this.addButton = view.findViewById(R.id.media_keyboard_add); - this.categoryTabAdapter = new MediaKeyboardBottomTabAdapter(GlideApp.with(this), this); + this.categoryTabAdapter = new MediaKeyboardBottomTabAdapter(Glide.with(this), this); categoryTabs.setLayoutManager(new LinearLayoutManager(getContext(), LinearLayoutManager.HORIZONTAL, false)); categoryTabs.setAdapter(categoryTabAdapter); diff --git a/app/src/main/java/org/thoughtcrime/securesms/components/emoji/MediaKeyboardBottomTabAdapter.java b/app/src/main/java/org/thoughtcrime/securesms/components/emoji/MediaKeyboardBottomTabAdapter.java index 0d1b98d474..08a2ec528f 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/components/emoji/MediaKeyboardBottomTabAdapter.java +++ b/app/src/main/java/org/thoughtcrime/securesms/components/emoji/MediaKeyboardBottomTabAdapter.java @@ -9,20 +9,20 @@ import android.widget.ImageView; import org.thoughtcrime.securesms.components.emoji.MediaKeyboardProvider.TabIconProvider; -import org.thoughtcrime.securesms.mms.GlideRequests; +import com.bumptech.glide.RequestManager; import network.loki.messenger.R; public class MediaKeyboardBottomTabAdapter extends RecyclerView.Adapter { - private final GlideRequests glideRequests; + private final RequestManager glideRequests; private final EventListener eventListener; private TabIconProvider tabIconProvider; private int activePosition; private int count; - public MediaKeyboardBottomTabAdapter(@NonNull GlideRequests glideRequests, @NonNull EventListener eventListener) { + public MediaKeyboardBottomTabAdapter(@NonNull RequestManager glideRequests, @NonNull EventListener eventListener) { this.glideRequests = glideRequests; this.eventListener = eventListener; } @@ -71,7 +71,7 @@ public class MediaKeyboardBottomTabAdapter extends RecyclerView.Adapter() { - lateinit var glide: GlideRequests + lateinit var glide: RequestManager val selectedContacts = mutableSetOf() var items = listOf() set(value) { field = value; notifyDataSetChanged() } diff --git a/app/src/main/java/org/thoughtcrime/securesms/contacts/ContactSelectionListFragment.kt b/app/src/main/java/org/thoughtcrime/securesms/contacts/ContactSelectionListFragment.kt index 0b0ddf4b3d..7c74fb8983 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/contacts/ContactSelectionListFragment.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/contacts/ContactSelectionListFragment.kt @@ -11,7 +11,7 @@ import androidx.recyclerview.widget.LinearLayoutManager import network.loki.messenger.databinding.ContactSelectionListFragmentBinding import org.session.libsession.utilities.recipients.Recipient import org.session.libsignal.utilities.Log -import org.thoughtcrime.securesms.mms.GlideApp +import com.bumptech.glide.Glide class ContactSelectionListFragment : Fragment(), LoaderManager.LoaderCallbacks>, ContactClickListener { private lateinit var binding: ContactSelectionListFragmentBinding @@ -27,7 +27,7 @@ class ContactSelectionListFragment : Fragment(), LoaderManager.LoaderCallbacks> { private lateinit var binding: ActivitySelectContactsBinding @@ -21,7 +21,7 @@ class SelectContactsActivity : PassphraseRequiredActionBarActivity(), LoaderMana private lateinit var usersToExclude: Set private val selectContactsAdapter by lazy { - SelectContactsAdapter(this, GlideApp.with(this)) + SelectContactsAdapter(this, Glide.with(this)) } companion object { diff --git a/app/src/main/java/org/thoughtcrime/securesms/contacts/SelectContactsAdapter.kt b/app/src/main/java/org/thoughtcrime/securesms/contacts/SelectContactsAdapter.kt index 5e3ae1213c..2a788f71a2 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/contacts/SelectContactsAdapter.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/contacts/SelectContactsAdapter.kt @@ -4,10 +4,10 @@ import android.content.Context import androidx.recyclerview.widget.RecyclerView import android.view.ViewGroup import org.session.libsession.utilities.Address -import org.thoughtcrime.securesms.mms.GlideRequests +import com.bumptech.glide.RequestManager import org.session.libsession.utilities.recipients.Recipient -class SelectContactsAdapter(private val context: Context, private val glide: GlideRequests) : RecyclerView.Adapter() { +class SelectContactsAdapter(private val context: Context, private val glide: RequestManager) : RecyclerView.Adapter() { val selectedMembers = mutableSetOf() var members = listOf() set(value) { field = value; notifyDataSetChanged() } diff --git a/app/src/main/java/org/thoughtcrime/securesms/contacts/UserView.kt b/app/src/main/java/org/thoughtcrime/securesms/contacts/UserView.kt index f9fd528707..e0ca2a4242 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/contacts/UserView.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/contacts/UserView.kt @@ -10,7 +10,7 @@ import network.loki.messenger.databinding.ViewUserBinding import org.session.libsession.messaging.contacts.Contact import org.session.libsession.utilities.recipients.Recipient import org.thoughtcrime.securesms.dependencies.DatabaseComponent -import org.thoughtcrime.securesms.mms.GlideRequests +import com.bumptech.glide.RequestManager class UserView : LinearLayout { private lateinit var binding: ViewUserBinding @@ -45,7 +45,7 @@ class UserView : LinearLayout { // endregion // region Updating - fun bind(user: Recipient, glide: GlideRequests, actionIndicator: ActionIndicator, isSelected: Boolean = false) { + fun bind(user: Recipient, glide: RequestManager, actionIndicator: ActionIndicator, isSelected: Boolean = false) { val isLocalUser = user.isLocalNumber fun getUserDisplayName(publicKey: String): String { if (isLocalUser) return context.getString(R.string.MessageRecord_you) diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationActivityV2.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationActivityV2.kt index 62ea2e52d4..98f300dc66 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationActivityV2.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationActivityV2.kt @@ -37,7 +37,6 @@ import androidx.activity.result.contract.ActivityResultContracts import androidx.activity.viewModels import androidx.core.text.set import androidx.core.text.toSpannable -import androidx.core.view.drawToBitmap import androidx.core.view.isGone import androidx.core.view.isVisible import androidx.fragment.app.DialogFragment @@ -156,7 +155,7 @@ import org.thoughtcrime.securesms.mediasend.Media import org.thoughtcrime.securesms.mediasend.MediaSendActivity import org.thoughtcrime.securesms.mms.AudioSlide import org.thoughtcrime.securesms.mms.GifSlide -import org.thoughtcrime.securesms.mms.GlideApp +import com.bumptech.glide.Glide import org.thoughtcrime.securesms.mms.ImageSlide import org.thoughtcrime.securesms.mms.MediaConstraints import org.thoughtcrime.securesms.mms.Slide @@ -173,6 +172,7 @@ import org.thoughtcrime.securesms.util.DateUtils import org.thoughtcrime.securesms.util.MediaUtil import org.thoughtcrime.securesms.util.NetworkUtils import org.thoughtcrime.securesms.util.SaveAttachmentTask +import org.thoughtcrime.securesms.util.drawToBitmap import org.thoughtcrime.securesms.util.isScrolledToBottom import org.thoughtcrime.securesms.util.isScrolledToWithin30dpOfBottom import org.thoughtcrime.securesms.util.push @@ -349,7 +349,7 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe adapter } - private val glide by lazy { GlideApp.with(this) } + private val glide by lazy { Glide.with(this) } private val lockViewHitMargin by lazy { toPx(40, resources) } private val gifButton by lazy { InputBarButton(this, R.drawable.ic_gif_white_24dp, hasOpaqueBackground = true, isGIFButton = true) } private val documentButton by lazy { InputBarButton(this, R.drawable.ic_document_small_dark, hasOpaqueBackground = true) } diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationAdapter.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationAdapter.kt index 40a089d4f6..1c57dc8d5f 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationAdapter.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationAdapter.kt @@ -26,7 +26,7 @@ import org.thoughtcrime.securesms.conversation.v2.messages.VisibleMessageViewDel import org.thoughtcrime.securesms.database.CursorRecyclerViewAdapter import org.thoughtcrime.securesms.database.model.MessageRecord import org.thoughtcrime.securesms.dependencies.DatabaseComponent -import org.thoughtcrime.securesms.mms.GlideRequests +import com.bumptech.glide.RequestManager import org.thoughtcrime.securesms.preferences.PrivacySettingsActivity import org.thoughtcrime.securesms.showSessionDialog import java.util.concurrent.atomic.AtomicLong @@ -42,7 +42,7 @@ class ConversationAdapter( private val onItemLongPress: (MessageRecord, Int, VisibleMessageView) -> Unit, private val onDeselect: (MessageRecord, Int) -> Unit, private val onAttachmentNeedsDownload: (DatabaseAttachment) -> Unit, - private val glide: GlideRequests, + private val glide: RequestManager, lifecycleCoroutineScope: LifecycleCoroutineScope ) : CursorRecyclerViewAdapter(context, cursor) { private val messageDB by lazy { DatabaseComponent.get(context).mmsSmsDatabase() } diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/components/AlbumThumbnailView.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/components/AlbumThumbnailView.kt index 57c42a7719..dba6bf5b7b 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/components/AlbumThumbnailView.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/components/AlbumThumbnailView.kt @@ -20,7 +20,7 @@ import org.thoughtcrime.securesms.MediaPreviewActivity import org.thoughtcrime.securesms.components.CornerMask import org.thoughtcrime.securesms.conversation.v2.utilities.ThumbnailView import org.thoughtcrime.securesms.database.model.MmsMessageRecord -import org.thoughtcrime.securesms.mms.GlideRequests +import com.bumptech.glide.RequestManager import org.thoughtcrime.securesms.mms.Slide import org.thoughtcrime.securesms.util.ActivityDispatcher @@ -80,7 +80,7 @@ class AlbumThumbnailView : RelativeLayout { slideSize = -1 } - fun bind(glideRequests: GlideRequests, message: MmsMessageRecord, + fun bind(glideRequests: RequestManager, message: MmsMessageRecord, isStart: Boolean, isEnd: Boolean) { slides = message.slideDeck.thumbnailSlides if (slides.isEmpty()) { diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/components/LinkPreviewDraftView.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/components/LinkPreviewDraftView.kt index 9c414f34fd..9bad72f296 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/components/LinkPreviewDraftView.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/components/LinkPreviewDraftView.kt @@ -7,7 +7,7 @@ import android.widget.LinearLayout import androidx.core.view.isVisible import network.loki.messenger.databinding.ViewLinkPreviewDraftBinding import org.session.libsession.messaging.sending_receiving.link_preview.LinkPreview -import org.thoughtcrime.securesms.mms.GlideRequests +import com.bumptech.glide.RequestManager import org.thoughtcrime.securesms.mms.ImageSlide import org.thoughtcrime.securesms.util.toPx @@ -27,7 +27,7 @@ class LinkPreviewDraftView : LinearLayout { binding.linkPreviewDraftCancelButton.setOnClickListener { cancel() } } - fun update(glide: GlideRequests, linkPreview: LinkPreview) { + fun update(glide: RequestManager, linkPreview: LinkPreview) { // Hide the loader and show the content view binding.linkPreviewDraftContainer.isVisible = true binding.linkPreviewDraftLoader.isVisible = false diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/components/MentionCandidateSelectionView.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/components/MentionCandidateSelectionView.kt index 303c17c5a5..5698ddd0bb 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/components/MentionCandidateSelectionView.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/components/MentionCandidateSelectionView.kt @@ -9,13 +9,13 @@ import android.widget.BaseAdapter import android.widget.ListView import org.session.libsession.messaging.mentions.Mention import org.thoughtcrime.securesms.dependencies.DatabaseComponent -import org.thoughtcrime.securesms.mms.GlideRequests +import com.bumptech.glide.RequestManager import org.thoughtcrime.securesms.util.toPx class MentionCandidateSelectionView(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : ListView(context, attrs, defStyleAttr) { private var mentionCandidates = listOf() set(newValue) { field = newValue; mentionCandidateSelectionViewAdapter.mentionCandidates = newValue } - var glide: GlideRequests? = null + var glide: RequestManager? = null set(newValue) { field = newValue; mentionCandidateSelectionViewAdapter.glide = newValue } var openGroupServer: String? = null set(newValue) { field = newValue; mentionCandidateSelectionViewAdapter.openGroupServer = openGroupServer } @@ -28,7 +28,7 @@ class MentionCandidateSelectionView(context: Context, attrs: AttributeSet?, defS private class Adapter(private val context: Context) : BaseAdapter() { var mentionCandidates = listOf() set(newValue) { field = newValue; notifyDataSetChanged() } - var glide: GlideRequests? = null + var glide: RequestManager? = null var openGroupServer: String? = null var openGroupRoom: String? = null diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/components/MentionCandidateView.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/components/MentionCandidateView.kt index d544263915..14dc6263ab 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/components/MentionCandidateView.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/components/MentionCandidateView.kt @@ -8,13 +8,13 @@ import android.widget.LinearLayout import network.loki.messenger.databinding.ViewMentionCandidateBinding import org.session.libsession.messaging.mentions.Mention import org.thoughtcrime.securesms.groups.OpenGroupManager -import org.thoughtcrime.securesms.mms.GlideRequests +import com.bumptech.glide.RequestManager class MentionCandidateView : LinearLayout { private lateinit var binding: ViewMentionCandidateBinding var mentionCandidate = Mention("", "") set(newValue) { field = newValue; update() } - var glide: GlideRequests? = null + var glide: RequestManager? = null var openGroupServer: String? = null var openGroupRoom: String? = null diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/input_bar/InputBar.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/input_bar/InputBar.kt index 152a0e67a1..69a327c537 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/input_bar/InputBar.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/input_bar/InputBar.kt @@ -29,7 +29,7 @@ import org.thoughtcrime.securesms.conversation.v2.messages.QuoteView import org.thoughtcrime.securesms.conversation.v2.messages.QuoteViewDelegate import org.thoughtcrime.securesms.database.model.MessageRecord import org.thoughtcrime.securesms.database.model.MmsMessageRecord -import org.thoughtcrime.securesms.mms.GlideRequests +import com.bumptech.glide.RequestManager import org.thoughtcrime.securesms.util.addTextChangedListener import org.thoughtcrime.securesms.util.contains @@ -190,7 +190,7 @@ class InputBar @JvmOverloads constructor( private fun startRecordingVoiceMessage() { delegate?.startRecordingVoiceMessage() } - fun draftQuote(thread: Recipient, message: MessageRecord, glide: GlideRequests) { + fun draftQuote(thread: Recipient, message: MessageRecord, glide: RequestManager) { quoteView?.let(binding.inputBarAdditionalContentContainer::removeView) quote = message @@ -240,7 +240,7 @@ class InputBar @JvmOverloads constructor( requestLayout() } - fun updateLinkPreviewDraft(glide: GlideRequests, updatedLinkPreview: LinkPreview) { + fun updateLinkPreviewDraft(glide: RequestManager, updatedLinkPreview: LinkPreview) { // Update our `linkPreview` property with the new (provided as an argument to this function) // then update the View from that. linkPreview = updatedLinkPreview.also { linkPreviewDraftView?.update(glide, it) } diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/LinkPreviewView.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/LinkPreviewView.kt index 4e6066edb3..8cf80dc090 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/LinkPreviewView.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/LinkPreviewView.kt @@ -15,7 +15,7 @@ import org.thoughtcrime.securesms.components.CornerMask import org.thoughtcrime.securesms.conversation.v2.ModalUrlBottomSheet import org.thoughtcrime.securesms.conversation.v2.utilities.MessageBubbleUtilities import org.thoughtcrime.securesms.database.model.MmsMessageRecord -import org.thoughtcrime.securesms.mms.GlideRequests +import com.bumptech.glide.RequestManager import org.thoughtcrime.securesms.mms.ImageSlide class LinkPreviewView : LinearLayout { @@ -32,7 +32,7 @@ class LinkPreviewView : LinearLayout { // region Updating fun bind( message: MmsMessageRecord, - glide: GlideRequests, + glide: RequestManager, isStartOfMessageCluster: Boolean, isEndOfMessageCluster: Boolean ) { diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/QuoteView.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/QuoteView.kt index 6bfa70efe9..a1ebd778be 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/QuoteView.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/QuoteView.kt @@ -20,7 +20,7 @@ import org.session.libsession.utilities.prefs import org.session.libsession.utilities.recipients.Recipient import org.thoughtcrime.securesms.conversation.v2.utilities.MentionUtilities import org.thoughtcrime.securesms.database.SessionContactDatabase -import org.thoughtcrime.securesms.mms.GlideRequests +import com.bumptech.glide.RequestManager import org.thoughtcrime.securesms.mms.SlideDeck import org.thoughtcrime.securesms.util.MediaUtil import org.thoughtcrime.securesms.util.getAccentColor @@ -70,7 +70,7 @@ class QuoteView @JvmOverloads constructor(context: Context, attrs: AttributeSet? // region Updating fun bind(authorPublicKey: String, body: String?, attachments: SlideDeck?, thread: Recipient, isOutgoingMessage: Boolean, isOpenGroupInvitation: Boolean, threadID: Long, - isOriginalMissing: Boolean, glide: GlideRequests) { + isOriginalMissing: Boolean, glide: RequestManager) { // Author val author = contactDb.getContactWithAccountID(authorPublicKey) val localNumber = context.prefs.getLocalNumber() diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/VisibleMessageContentView.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/VisibleMessageContentView.kt index b320e72e26..dcce528234 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/VisibleMessageContentView.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/VisibleMessageContentView.kt @@ -38,8 +38,8 @@ import org.thoughtcrime.securesms.conversation.v2.utilities.TextUtilities.getInt import org.thoughtcrime.securesms.database.model.MessageRecord import org.thoughtcrime.securesms.database.model.MmsMessageRecord import org.thoughtcrime.securesms.database.model.SmsMessageRecord -import org.thoughtcrime.securesms.mms.GlideApp -import org.thoughtcrime.securesms.mms.GlideRequests +import com.bumptech.glide.Glide +import com.bumptech.glide.RequestManager import org.thoughtcrime.securesms.util.GlowViewUtilities import org.thoughtcrime.securesms.util.SearchUtil import org.thoughtcrime.securesms.util.getAccentColor @@ -63,7 +63,7 @@ class VisibleMessageContentView : ConstraintLayout { message: MessageRecord, isStartOfMessageCluster: Boolean = true, isEndOfMessageCluster: Boolean = true, - glide: GlideRequests = GlideApp.with(this), + glide: RequestManager = Glide.with(this), thread: Recipient, searchQuery: String? = null, contactIsTrusted: Boolean = true, diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/VisibleMessageView.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/VisibleMessageView.kt index b2e3bba81b..9f7f620ab5 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/VisibleMessageView.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/VisibleMessageView.kt @@ -52,8 +52,8 @@ import org.thoughtcrime.securesms.database.ThreadDatabase import org.thoughtcrime.securesms.database.model.MessageRecord import org.thoughtcrime.securesms.groups.OpenGroupManager import org.thoughtcrime.securesms.home.UserDetailsBottomSheet -import org.thoughtcrime.securesms.mms.GlideApp -import org.thoughtcrime.securesms.mms.GlideRequests +import com.bumptech.glide.Glide +import com.bumptech.glide.RequestManager import org.thoughtcrime.securesms.util.DateUtils import org.thoughtcrime.securesms.util.disableClipping import org.thoughtcrime.securesms.util.toDp @@ -141,7 +141,7 @@ class VisibleMessageView : FrameLayout { message: MessageRecord, previous: MessageRecord? = null, next: MessageRecord? = null, - glide: GlideRequests = GlideApp.with(this), + glide: RequestManager = Glide.with(this), searchQuery: String? = null, contact: Contact? = null, senderAccountID: String, diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/utilities/AttachmentManager.java b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/utilities/AttachmentManager.java index 76b95d7b17..ee98f623f2 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/utilities/AttachmentManager.java +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/utilities/AttachmentManager.java @@ -44,7 +44,7 @@ import org.thoughtcrime.securesms.mediasend.MediaSendActivity; import org.thoughtcrime.securesms.mms.AudioSlide; import org.thoughtcrime.securesms.mms.DocumentSlide; import org.thoughtcrime.securesms.mms.GifSlide; -import org.thoughtcrime.securesms.mms.GlideRequests; +import com.bumptech.glide.RequestManager; import org.thoughtcrime.securesms.mms.ImageSlide; import org.thoughtcrime.securesms.mms.MediaConstraints; import org.thoughtcrime.securesms.mms.PartAuthority; @@ -126,7 +126,7 @@ public class AttachmentManager { } @SuppressLint("StaticFieldLeak") - public ListenableFuture setMedia(@NonNull final GlideRequests glideRequests, + public ListenableFuture setMedia(@NonNull final RequestManager glideRequests, @NonNull final Uri uri, @NonNull final MediaType mediaType, @NonNull final MediaConstraints constraints, diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/utilities/ThumbnailView.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/utilities/ThumbnailView.kt index 02c683aac6..83932b2ce4 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/utilities/ThumbnailView.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/utilities/ThumbnailView.kt @@ -25,8 +25,8 @@ import org.session.libsignal.utilities.SettableFuture import org.thoughtcrime.securesms.components.GlideBitmapListeningTarget import org.thoughtcrime.securesms.components.GlideDrawableListeningTarget import org.thoughtcrime.securesms.mms.DecryptableStreamUriLoader.DecryptableUri -import org.thoughtcrime.securesms.mms.GlideRequest -import org.thoughtcrime.securesms.mms.GlideRequests +import com.bumptech.glide.RequestBuilder +import com.bumptech.glide.RequestManager import org.thoughtcrime.securesms.mms.Slide open class ThumbnailView @JvmOverloads constructor( @@ -104,13 +104,13 @@ open class ThumbnailView @JvmOverloads constructor( } fun setImageResource( - glide: GlideRequests, + glide: RequestManager, slide: Slide, isPreview: Boolean ): ListenableFuture = setImageResource(glide, slide, isPreview, 0, 0) fun setImageResource( - glide: GlideRequests, slide: Slide, + glide: RequestManager, slide: Slide, isPreview: Boolean, naturalWidth: Int, naturalHeight: Int ): ListenableFuture { @@ -152,9 +152,9 @@ open class ThumbnailView @JvmOverloads constructor( } private fun buildThumbnailGlideRequest( - glide: GlideRequests, + glide: RequestManager, slide: Slide - ): GlideRequest = glide.load(DecryptableUri(slide.thumbnailUri!!)) + ): RequestBuilder = glide.load(DecryptableUri(slide.thumbnailUri!!)) .diskCacheStrategy(DiskCacheStrategy.NONE) .overrideDimensions() .transition(DrawableTransitionOptions.withCrossFade()) @@ -162,21 +162,21 @@ open class ThumbnailView @JvmOverloads constructor( .missingThumbnailPicture(slide.isInProgress) private fun buildPlaceholderGlideRequest( - glide: GlideRequests, + glide: RequestManager, slide: Slide - ): GlideRequest = glide.asBitmap() + ): RequestBuilder = glide.asBitmap() .load(slide.getPlaceholderRes(context.theme)) .diskCacheStrategy(DiskCacheStrategy.NONE) .overrideDimensions() .fitCenter() - open fun clear(glideRequests: GlideRequests) { + open fun clear(glideRequests: RequestManager) { glideRequests.clear(binding.thumbnailImage) slide = null } fun setImageResource( - glideRequests: GlideRequests, + glideRequests: RequestManager, uri: Uri ): ListenableFuture = glideRequests.load(DecryptableUri(uri)) .diskCacheStrategy(DiskCacheStrategy.NONE) @@ -184,19 +184,19 @@ open class ThumbnailView @JvmOverloads constructor( .transform(CenterCrop()) .intoDrawableTargetAsFuture() - private fun GlideRequest.intoDrawableTargetAsFuture() = + private fun RequestBuilder.intoDrawableTargetAsFuture() = SettableFuture().also { binding.run { GlideDrawableListeningTarget(thumbnailImage, thumbnailLoadIndicator, it) }.let { into(it) } } - private fun GlideRequest.overrideDimensions() = + private fun RequestBuilder.overrideDimensions() = dimensDelegate.resourceSize().takeIf { 0 !in it } ?.let { override(it[WIDTH], it[HEIGHT]) } ?: override(getDefaultWidth(), getDefaultHeight()) } -private fun GlideRequest.missingThumbnailPicture( +private fun RequestBuilder.missingThumbnailPicture( inProgress: Boolean ) = takeIf { inProgress } ?: apply(RequestOptions.errorOf(R.drawable.ic_missing_thumbnail_picture)) diff --git a/app/src/main/java/org/thoughtcrime/securesms/database/LokiAPIDatabase.kt b/app/src/main/java/org/thoughtcrime/securesms/database/LokiAPIDatabase.kt index 01b2e9a6e5..adce541211 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/database/LokiAPIDatabase.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/database/LokiAPIDatabase.kt @@ -168,6 +168,8 @@ class LokiAPIDatabase(context: Context, helper: SQLCipherOpenHelper) : Database( const val RESET_SEQ_NO = "UPDATE $lastMessageServerIDTable SET $lastMessageServerID = 0;" + const val EMPTY_VERSION = "0.0.0" + // endregion } @@ -181,7 +183,8 @@ class LokiAPIDatabase(context: Context, helper: SQLCipherOpenHelper) : Database( val port = components.getOrNull(1)?.toIntOrNull() ?: return@mapNotNull null val ed25519Key = components.getOrNull(2) ?: return@mapNotNull null val x25519Key = components.getOrNull(3) ?: return@mapNotNull null - Snode(address, port, Snode.KeySet(ed25519Key, x25519Key)) + val version = components.getOrNull(4) ?: EMPTY_VERSION + Snode(address, port, Snode.KeySet(ed25519Key, x25519Key), version) } }?.toSet() ?: setOf() } @@ -194,6 +197,7 @@ class LokiAPIDatabase(context: Context, helper: SQLCipherOpenHelper) : Database( if (keySet != null) { string += "-${keySet.ed25519Key}-${keySet.x25519Key}" } + string += "-${snode.version}" string } val row = wrap(mapOf( Companion.dummyKey to "dummy_key", snodePool to snodePoolAsString )) @@ -209,6 +213,7 @@ class LokiAPIDatabase(context: Context, helper: SQLCipherOpenHelper) : Database( if (keySet != null) { snodeAsString += "-${keySet.ed25519Key}-${keySet.x25519Key}" } + snodeAsString += "-${snode.version}" val row = wrap(mapOf( Companion.indexPath to indexPath, Companion.snode to snodeAsString )) database.insertOrUpdate(onionRequestPathTable, row, "${Companion.indexPath} = ?", wrap(indexPath)) } @@ -234,8 +239,9 @@ class LokiAPIDatabase(context: Context, helper: SQLCipherOpenHelper) : Database( val port = components.getOrNull(1)?.toIntOrNull() val ed25519Key = components.getOrNull(2) val x25519Key = components.getOrNull(3) + val version = components.getOrNull(4) ?: EMPTY_VERSION if (port != null && ed25519Key != null && x25519Key != null) { - Snode(address, port, Snode.KeySet(ed25519Key, x25519Key)) + Snode(address, port, Snode.KeySet(ed25519Key, x25519Key), version) } else { null } @@ -253,6 +259,11 @@ class LokiAPIDatabase(context: Context, helper: SQLCipherOpenHelper) : Database( return result } + override fun clearSnodePool() { + val database = databaseHelper.writableDatabase + database.delete(snodePoolTable, null, null) + } + override fun clearOnionRequestPaths() { val database = databaseHelper.writableDatabase fun delete(indexPath: String) { @@ -273,7 +284,8 @@ class LokiAPIDatabase(context: Context, helper: SQLCipherOpenHelper) : Database( val port = components.getOrNull(1)?.toIntOrNull() ?: return@mapNotNull null val ed25519Key = components.getOrNull(2) ?: return@mapNotNull null val x25519Key = components.getOrNull(3) ?: return@mapNotNull null - Snode(address, port, Snode.KeySet(ed25519Key, x25519Key)) + val version = components.getOrNull(4) ?: EMPTY_VERSION + Snode(address, port, Snode.KeySet(ed25519Key, x25519Key), version) } }?.toSet() } diff --git a/app/src/main/java/org/thoughtcrime/securesms/giph/ui/GiphyAdapter.java b/app/src/main/java/org/thoughtcrime/securesms/giph/ui/GiphyAdapter.java index 8972fd8e88..b884ef6a19 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/giph/ui/GiphyAdapter.java +++ b/app/src/main/java/org/thoughtcrime/securesms/giph/ui/GiphyAdapter.java @@ -29,8 +29,8 @@ import org.session.libsession.utilities.ViewUtil; import org.session.libsignal.utilities.Log; import org.thoughtcrime.securesms.giph.model.ChunkedImageUrl; import org.thoughtcrime.securesms.giph.model.GiphyImage; -import org.thoughtcrime.securesms.mms.GlideApp; -import org.thoughtcrime.securesms.mms.GlideRequests; +import com.bumptech.glide.Glide; +import com.bumptech.glide.RequestManager; import java.util.List; import java.util.concurrent.ExecutionException; @@ -43,7 +43,7 @@ class GiphyAdapter extends RecyclerView.Adapter { private static final String TAG = GiphyAdapter.class.getSimpleName(); private final Context context; - private final GlideRequests glideRequests; + private final RequestManager glideRequests; private List images; private OnItemClickListener listener; @@ -117,7 +117,7 @@ class GiphyAdapter extends RecyclerView.Adapter { } } - GiphyAdapter(@NonNull Context context, @NonNull GlideRequests glideRequests, @NonNull List images) { + GiphyAdapter(@NonNull Context context, @NonNull RequestManager glideRequests, @NonNull List images) { this.context = context.getApplicationContext(); this.glideRequests = glideRequests; this.images = images; @@ -150,7 +150,7 @@ class GiphyAdapter extends RecyclerView.Adapter { holder.thumbnail.setAspectRatio(image.getGifAspectRatio()); holder.gifProgress.setVisibility(View.GONE); - RequestBuilder thumbnailRequest = GlideApp.with(context) + RequestBuilder thumbnailRequest = Glide.with(context) .load(new ChunkedImageUrl(image.getStillUrl(), image.getStillSize())) .diskCacheStrategy(DiskCacheStrategy.NONE); diff --git a/app/src/main/java/org/thoughtcrime/securesms/giph/ui/GiphyFragment.java b/app/src/main/java/org/thoughtcrime/securesms/giph/ui/GiphyFragment.java index f9c35125b3..7b7c11532e 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/giph/ui/GiphyFragment.java +++ b/app/src/main/java/org/thoughtcrime/securesms/giph/ui/GiphyFragment.java @@ -20,7 +20,7 @@ import org.session.libsession.messaging.MessagingModuleConfiguration; import org.thoughtcrime.securesms.giph.model.GiphyImage; import org.thoughtcrime.securesms.giph.net.GiphyLoader; import org.thoughtcrime.securesms.giph.util.InfiniteScrollListener; -import org.thoughtcrime.securesms.mms.GlideApp; +import com.bumptech.glide.Glide; import org.session.libsession.utilities.ViewUtil; import java.util.LinkedList; @@ -54,7 +54,7 @@ public abstract class GiphyFragment extends Fragment implements LoaderManager.Lo public void onActivityCreated(Bundle bundle) { super.onActivityCreated(bundle); - this.giphyAdapter = new GiphyAdapter(getActivity(), GlideApp.with(this), new LinkedList<>()); + this.giphyAdapter = new GiphyAdapter(getActivity(), Glide.with(this), new LinkedList<>()); this.giphyAdapter.setListener(this); setLayoutManager(MessagingModuleConfiguration.getShared().getPrefs().isGifSearchInGridLayout()); diff --git a/app/src/main/java/org/thoughtcrime/securesms/groups/CreateGroupFragment.kt b/app/src/main/java/org/thoughtcrime/securesms/groups/CreateGroupFragment.kt index cdfd9d9454..3a9288716f 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/groups/CreateGroupFragment.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/groups/CreateGroupFragment.kt @@ -31,7 +31,7 @@ import org.thoughtcrime.securesms.conversation.start.StartConversationDelegate import org.thoughtcrime.securesms.conversation.v2.ConversationActivityV2 import org.thoughtcrime.securesms.dependencies.DatabaseComponent import org.thoughtcrime.securesms.keyboard.emoji.KeyboardPageSearchView -import org.thoughtcrime.securesms.mms.GlideApp +import com.bumptech.glide.Glide import org.thoughtcrime.securesms.util.fadeIn import org.thoughtcrime.securesms.util.fadeOut import javax.inject.Inject @@ -57,7 +57,7 @@ class CreateGroupFragment : Fragment() { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - val adapter = SelectContactsAdapter(requireContext(), GlideApp.with(requireContext())) + val adapter = SelectContactsAdapter(requireContext(), Glide.with(requireContext())) binding.backButton.setOnClickListener { delegate.onDialogBackPressed() } binding.closeButton.setOnClickListener { delegate.onDialogClosePressed() } binding.contactSearch.callbacks = object : KeyboardPageSearchView.Callbacks { diff --git a/app/src/main/java/org/thoughtcrime/securesms/groups/EditClosedGroupActivity.kt b/app/src/main/java/org/thoughtcrime/securesms/groups/EditClosedGroupActivity.kt index e5e63b668b..91ac7c82d0 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/groups/EditClosedGroupActivity.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/groups/EditClosedGroupActivity.kt @@ -39,7 +39,7 @@ import org.thoughtcrime.securesms.database.Storage import org.thoughtcrime.securesms.dependencies.ConfigFactory import org.thoughtcrime.securesms.dependencies.DatabaseComponent import org.thoughtcrime.securesms.groups.ClosedGroupManager.updateLegacyGroup -import org.thoughtcrime.securesms.mms.GlideApp +import com.bumptech.glide.Glide import org.thoughtcrime.securesms.util.fadeIn import org.thoughtcrime.securesms.util.fadeOut import java.io.IOException @@ -78,9 +78,9 @@ class EditClosedGroupActivity : PassphraseRequiredActionBarActivity() { private val memberListAdapter by lazy { if (isSelfAdmin) - EditClosedGroupMembersAdapter(this, GlideApp.with(this), isSelfAdmin, this::onMemberClick) + EditClosedGroupMembersAdapter(this, Glide.with(this), isSelfAdmin, this::onMemberClick) else - EditClosedGroupMembersAdapter(this, GlideApp.with(this), isSelfAdmin) + EditClosedGroupMembersAdapter(this, Glide.with(this), isSelfAdmin) } private lateinit var mainContentContainer: LinearLayout diff --git a/app/src/main/java/org/thoughtcrime/securesms/groups/EditClosedGroupMembersAdapter.kt b/app/src/main/java/org/thoughtcrime/securesms/groups/EditClosedGroupMembersAdapter.kt index e89d3cc4d0..8d5bae9c14 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/groups/EditClosedGroupMembersAdapter.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/groups/EditClosedGroupMembersAdapter.kt @@ -6,14 +6,14 @@ import android.view.ViewGroup import org.session.libsession.messaging.MessagingModuleConfiguration import org.session.libsession.utilities.Address import org.thoughtcrime.securesms.contacts.UserView -import org.thoughtcrime.securesms.mms.GlideRequests +import com.bumptech.glide.RequestManager import org.session.libsession.utilities.recipients.Recipient import org.session.libsession.utilities.TextSecurePreferences import org.session.libsession.utilities.prefs class EditClosedGroupMembersAdapter( private val context: Context, - private val glide: GlideRequests, + private val glide: RequestManager, private val admin: Boolean, private val memberClickListener: ((String) -> Unit)? = null ) : RecyclerView.Adapter() { diff --git a/app/src/main/java/org/thoughtcrime/securesms/home/HomeActivity.kt b/app/src/main/java/org/thoughtcrime/securesms/home/HomeActivity.kt index 966795e146..38f7c07f3c 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/home/HomeActivity.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/home/HomeActivity.kt @@ -62,8 +62,8 @@ import org.thoughtcrime.securesms.home.search.GlobalSearchInputLayout import org.thoughtcrime.securesms.home.search.GlobalSearchResult import org.thoughtcrime.securesms.home.search.GlobalSearchViewModel import org.thoughtcrime.securesms.messagerequests.MessageRequestsActivity -import org.thoughtcrime.securesms.mms.GlideApp -import org.thoughtcrime.securesms.mms.GlideRequests +import com.bumptech.glide.Glide +import com.bumptech.glide.RequestManager import org.thoughtcrime.securesms.notifications.PushRegistry import org.thoughtcrime.securesms.permissions.Permissions import org.thoughtcrime.securesms.preferences.SettingsActivity @@ -91,7 +91,7 @@ class HomeActivity : PassphraseRequiredActionBarActivity(), } private lateinit var binding: ActivityHomeBinding - private lateinit var glide: GlideRequests + private lateinit var glide: RequestManager @Inject lateinit var threadDb: ThreadDatabase @Inject lateinit var mmsSmsDatabase: MmsSmsDatabase @@ -151,7 +151,7 @@ class HomeActivity : PassphraseRequiredActionBarActivity(), // Set custom toolbar setSupportActionBar(binding.toolbar) // Set up Glide - glide = GlideApp.with(this) + glide = Glide.with(this) // Set up toolbar buttons binding.profileButton.setOnClickListener { openSettings() } binding.searchViewContainer.setOnClickListener { diff --git a/app/src/main/java/org/thoughtcrime/securesms/home/HomeAdapter.kt b/app/src/main/java/org/thoughtcrime/securesms/home/HomeAdapter.kt index 5410df9d47..47b6252165 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/home/HomeAdapter.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/home/HomeAdapter.kt @@ -7,10 +7,10 @@ import androidx.recyclerview.widget.DiffUtil import androidx.recyclerview.widget.ListUpdateCallback import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView.NO_ID +import com.bumptech.glide.RequestManager import network.loki.messenger.R import network.loki.messenger.databinding.ViewMessageRequestBannerBinding import org.thoughtcrime.securesms.dependencies.ConfigFactory -import org.thoughtcrime.securesms.mms.GlideRequests class HomeAdapter( private val context: Context, @@ -74,7 +74,7 @@ class HomeAdapter( return data.threads[offsetPosition].threadId } - lateinit var glide: GlideRequests + lateinit var glide: RequestManager override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder = when (viewType) { diff --git a/app/src/main/java/org/thoughtcrime/securesms/mediapreview/MediaRailAdapter.java b/app/src/main/java/org/thoughtcrime/securesms/mediapreview/MediaRailAdapter.java index 6492069780..e695274847 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/mediapreview/MediaRailAdapter.java +++ b/app/src/main/java/org/thoughtcrime/securesms/mediapreview/MediaRailAdapter.java @@ -14,7 +14,7 @@ import network.loki.messenger.R; import org.thoughtcrime.securesms.conversation.v2.utilities.ThumbnailView; import org.thoughtcrime.securesms.mediasend.Media; -import org.thoughtcrime.securesms.mms.GlideRequests; +import com.bumptech.glide.RequestManager; import org.thoughtcrime.securesms.util.StableIdGenerator; import java.util.ArrayList; @@ -25,7 +25,7 @@ public class MediaRailAdapter extends RecyclerView.Adapter media; private final RailItemListener listener; private final boolean editable; @@ -34,7 +34,7 @@ public class MediaRailAdapter extends RecyclerView.Adapter(); this.listener = listener; @@ -148,7 +148,7 @@ public class MediaRailAdapter extends RecyclerView.Adapter transformation = frontFacing ? new MultiTransformation<>(new CenterCrop(), new FlipTransformation()) : new CenterCrop(); - GlideApp.with(this) + Glide.with(this) .asBitmap() .load(jpegData) .transform(transformation) diff --git a/app/src/main/java/org/thoughtcrime/securesms/mediasend/MediaPickerFolderAdapter.java b/app/src/main/java/org/thoughtcrime/securesms/mediasend/MediaPickerFolderAdapter.java index 778883849b..1973ad1700 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/mediasend/MediaPickerFolderAdapter.java +++ b/app/src/main/java/org/thoughtcrime/securesms/mediasend/MediaPickerFolderAdapter.java @@ -14,18 +14,18 @@ import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions; import network.loki.messenger.R; -import org.thoughtcrime.securesms.mms.GlideRequests; +import com.bumptech.glide.RequestManager; import java.util.ArrayList; import java.util.List; class MediaPickerFolderAdapter extends RecyclerView.Adapter { - private final GlideRequests glideRequests; + private final RequestManager glideRequests; private final EventListener eventListener; private final List folders; - MediaPickerFolderAdapter(@NonNull GlideRequests glideRequests, @NonNull EventListener eventListener) { + MediaPickerFolderAdapter(@NonNull RequestManager glideRequests, @NonNull EventListener eventListener) { this.glideRequests = glideRequests; this.eventListener = eventListener; this.folders = new ArrayList<>(); @@ -74,7 +74,7 @@ class MediaPickerFolderAdapter extends RecyclerView.Adapter { - private final GlideRequests glideRequests; + private final RequestManager glideRequests; private final EventListener eventListener; private final List media; private final List selected; @@ -33,7 +33,7 @@ public class MediaPickerItemAdapter extends RecyclerView.Adapter(); @@ -109,7 +109,7 @@ public class MediaPickerItemAdapter extends RecyclerView.Adapter selected, int maxSelection, @NonNull GlideRequests glideRequests, @NonNull EventListener eventListener) { + void bind(@NonNull Media media, boolean multiSelect, List selected, int maxSelection, @NonNull RequestManager glideRequests, @NonNull EventListener eventListener) { glideRequests.load(media.getUri()) .diskCacheStrategy(DiskCacheStrategy.NONE) .transition(DrawableTransitionOptions.withCrossFade()) diff --git a/app/src/main/java/org/thoughtcrime/securesms/mediasend/MediaPickerItemFragment.java b/app/src/main/java/org/thoughtcrime/securesms/mediasend/MediaPickerItemFragment.java index 9e3db73bfc..8fd7559b4d 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/mediasend/MediaPickerItemFragment.java +++ b/app/src/main/java/org/thoughtcrime/securesms/mediasend/MediaPickerItemFragment.java @@ -21,7 +21,7 @@ import android.view.ViewGroup; import android.view.WindowManager; import android.widget.Toast; -import org.thoughtcrime.securesms.mms.GlideApp; +import com.bumptech.glide.Glide; import org.session.libsession.utilities.Util; import java.util.ArrayList; @@ -91,7 +91,7 @@ public class MediaPickerItemFragment extends Fragment implements MediaPickerItem RecyclerView imageList = view.findViewById(R.id.mediapicker_item_list); - adapter = new MediaPickerItemAdapter(GlideApp.with(this), this, maxSelection); + adapter = new MediaPickerItemAdapter(Glide.with(this), this, maxSelection); layoutManager = new GridLayoutManager(requireContext(), 4); imageList.setLayoutManager(layoutManager); diff --git a/app/src/main/java/org/thoughtcrime/securesms/mediasend/MediaSendFragment.java b/app/src/main/java/org/thoughtcrime/securesms/mediasend/MediaSendFragment.java index ea60c47c0a..9c12d81972 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/mediasend/MediaSendFragment.java +++ b/app/src/main/java/org/thoughtcrime/securesms/mediasend/MediaSendFragment.java @@ -42,7 +42,7 @@ import org.thoughtcrime.securesms.util.SimpleTextWatcher; import org.thoughtcrime.securesms.imageeditor.model.EditorModel; import org.session.libsignal.utilities.Log; import org.thoughtcrime.securesms.mediapreview.MediaRailAdapter; -import org.thoughtcrime.securesms.mms.GlideApp; +import com.bumptech.glide.Glide; import org.thoughtcrime.securesms.providers.BlobProvider; import org.session.libsession.utilities.recipients.Recipient; import org.thoughtcrime.securesms.scribbles.ImageEditorFragment; @@ -187,7 +187,7 @@ public class MediaSendFragment extends Fragment implements ViewTreeObserver.OnGl fragmentPager.addOnPageChangeListener(pageChangeListener); fragmentPager.post(() -> pageChangeListener.onPageSelected(fragmentPager.getCurrentItem())); - mediaRailAdapter = new MediaRailAdapter(GlideApp.with(this), this, true); + mediaRailAdapter = new MediaRailAdapter(Glide.with(this), this, true); mediaRail.setLayoutManager(new LinearLayoutManager(requireContext(), LinearLayoutManager.HORIZONTAL, false)); mediaRail.setAdapter(mediaRailAdapter); diff --git a/app/src/main/java/org/thoughtcrime/securesms/mediasend/MediaSendGifFragment.java b/app/src/main/java/org/thoughtcrime/securesms/mediasend/MediaSendGifFragment.java index fec59e0705..41293c6256 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/mediasend/MediaSendGifFragment.java +++ b/app/src/main/java/org/thoughtcrime/securesms/mediasend/MediaSendGifFragment.java @@ -12,7 +12,7 @@ import android.widget.ImageView; import network.loki.messenger.R; import org.thoughtcrime.securesms.mms.DecryptableStreamUriLoader; -import org.thoughtcrime.securesms.mms.GlideApp; +import com.bumptech.glide.Glide; public class MediaSendGifFragment extends Fragment implements MediaSendPageFragment { @@ -40,7 +40,7 @@ public class MediaSendGifFragment extends Fragment implements MediaSendPageFragm super.onViewCreated(view, savedInstanceState); uri = getArguments().getParcelable(KEY_URI); - GlideApp.with(this).load(new DecryptableStreamUriLoader.DecryptableUri(uri)).into((ImageView) view); + Glide.with(this).load(new DecryptableStreamUriLoader.DecryptableUri(uri)).into((ImageView) view); } @Override diff --git a/app/src/main/java/org/thoughtcrime/securesms/messagerequests/MessageRequestView.kt b/app/src/main/java/org/thoughtcrime/securesms/messagerequests/MessageRequestView.kt index 6584f4e519..1fb1f38ce4 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/messagerequests/MessageRequestView.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/messagerequests/MessageRequestView.kt @@ -11,7 +11,7 @@ import network.loki.messenger.databinding.ViewMessageRequestBinding import org.session.libsession.utilities.recipients.Recipient import org.thoughtcrime.securesms.conversation.v2.utilities.MentionUtilities.highlightMentions import org.thoughtcrime.securesms.database.model.ThreadRecord -import org.thoughtcrime.securesms.mms.GlideRequests +import com.bumptech.glide.RequestManager import org.thoughtcrime.securesms.util.DateUtils import java.util.Locale @@ -32,7 +32,7 @@ class MessageRequestView : LinearLayout { // endregion // region Updating - fun bind(thread: ThreadRecord, glide: GlideRequests) { + fun bind(thread: ThreadRecord, glide: RequestManager) { this.thread = thread val senderDisplayName = getUserDisplayName(thread.recipient) ?: thread.recipient.address.toString() diff --git a/app/src/main/java/org/thoughtcrime/securesms/messagerequests/MessageRequestsActivity.kt b/app/src/main/java/org/thoughtcrime/securesms/messagerequests/MessageRequestsActivity.kt index caecbcd87d..233222dabb 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/messagerequests/MessageRequestsActivity.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/messagerequests/MessageRequestsActivity.kt @@ -17,8 +17,8 @@ import org.thoughtcrime.securesms.PassphraseRequiredActionBarActivity import org.thoughtcrime.securesms.conversation.v2.ConversationActivityV2 import org.thoughtcrime.securesms.database.ThreadDatabase import org.thoughtcrime.securesms.database.model.ThreadRecord -import org.thoughtcrime.securesms.mms.GlideApp -import org.thoughtcrime.securesms.mms.GlideRequests +import com.bumptech.glide.Glide +import com.bumptech.glide.RequestManager import org.thoughtcrime.securesms.showSessionDialog import org.thoughtcrime.securesms.util.ConfigurationMessageUtilities import org.thoughtcrime.securesms.util.push @@ -28,7 +28,7 @@ import javax.inject.Inject class MessageRequestsActivity : PassphraseRequiredActionBarActivity(), ConversationClickListener, LoaderManager.LoaderCallbacks { private lateinit var binding: ActivityMessageRequestsBinding - private lateinit var glide: GlideRequests + private lateinit var glide: RequestManager @Inject lateinit var threadDb: ThreadDatabase @@ -43,7 +43,7 @@ class MessageRequestsActivity : PassphraseRequiredActionBarActivity(), Conversat binding = ActivityMessageRequestsBinding.inflate(layoutInflater) setContentView(binding.root) - glide = GlideApp.with(this) + glide = Glide.with(this) adapter.setHasStableIds(true) adapter.glide = glide diff --git a/app/src/main/java/org/thoughtcrime/securesms/messagerequests/MessageRequestsAdapter.kt b/app/src/main/java/org/thoughtcrime/securesms/messagerequests/MessageRequestsAdapter.kt index 3040bb774f..36e51e35be 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/messagerequests/MessageRequestsAdapter.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/messagerequests/MessageRequestsAdapter.kt @@ -14,7 +14,7 @@ import org.session.libsession.utilities.ThemeUtil import org.thoughtcrime.securesms.database.CursorRecyclerViewAdapter import org.thoughtcrime.securesms.database.model.ThreadRecord import org.thoughtcrime.securesms.dependencies.DatabaseComponent -import org.thoughtcrime.securesms.mms.GlideRequests +import com.bumptech.glide.RequestManager class MessageRequestsAdapter( context: Context, @@ -22,7 +22,7 @@ class MessageRequestsAdapter( val listener: ConversationClickListener ) : CursorRecyclerViewAdapter(context, cursor) { private val threadDatabase = DatabaseComponent.get(context).threadDatabase() - lateinit var glide: GlideRequests + lateinit var glide: RequestManager class ViewHolder(val view: MessageRequestView) : RecyclerView.ViewHolder(view) diff --git a/app/src/main/java/org/thoughtcrime/securesms/notifications/SingleRecipientNotificationBuilder.java b/app/src/main/java/org/thoughtcrime/securesms/notifications/SingleRecipientNotificationBuilder.java index 64e43c1ffd..4167ead26a 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/notifications/SingleRecipientNotificationBuilder.java +++ b/app/src/main/java/org/thoughtcrime/securesms/notifications/SingleRecipientNotificationBuilder.java @@ -39,7 +39,7 @@ import org.session.libsignal.utilities.Log; import org.thoughtcrime.securesms.database.SessionContactDatabase; import org.thoughtcrime.securesms.dependencies.DatabaseComponent; import org.thoughtcrime.securesms.mms.DecryptableStreamUriLoader; -import org.thoughtcrime.securesms.mms.GlideApp; +import com.bumptech.glide.Glide; import org.thoughtcrime.securesms.mms.Slide; import org.thoughtcrime.securesms.mms.SlideDeck; import org.thoughtcrime.securesms.util.AvatarPlaceholderGenerator; @@ -90,7 +90,7 @@ public class SingleRecipientNotificationBuilder extends AbstractNotificationBuil try { // AC: For some reason, if not use ".asBitmap()" method, the returned BitmapDrawable // wraps a recycled bitmap and leads to a crash. - Bitmap iconBitmap = GlideApp.with(context.getApplicationContext()) + Bitmap iconBitmap = Glide.with(context.getApplicationContext()) .asBitmap() .load(contactPhoto) .diskCacheStrategy(DiskCacheStrategy.NONE) @@ -292,7 +292,7 @@ public class SingleRecipientNotificationBuilder extends AbstractNotificationBuil @SuppressWarnings("ConstantConditions") Uri uri = slideDeck.getThumbnailSlide().getThumbnailUri(); - return GlideApp.with(context.getApplicationContext()) + return Glide.with(context.getApplicationContext()) .asBitmap() .load(new DecryptableStreamUriLoader.DecryptableUri(uri)) .diskCacheStrategy(DiskCacheStrategy.NONE) diff --git a/app/src/main/java/org/thoughtcrime/securesms/preferences/BlockedContactsAdapter.kt b/app/src/main/java/org/thoughtcrime/securesms/preferences/BlockedContactsAdapter.kt index e0b92bdbea..e59d86c912 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/preferences/BlockedContactsAdapter.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/preferences/BlockedContactsAdapter.kt @@ -9,7 +9,7 @@ import androidx.recyclerview.widget.RecyclerView import network.loki.messenger.R import network.loki.messenger.databinding.BlockedContactLayoutBinding import org.session.libsession.utilities.recipients.Recipient -import org.thoughtcrime.securesms.mms.GlideApp +import com.bumptech.glide.Glide import org.thoughtcrime.securesms.util.adapter.SelectableItem typealias SelectableRecipient = SelectableItem @@ -43,7 +43,7 @@ class BlockedContactsAdapter(val viewModel: BlockedContactsViewModel) : ListAdap class ViewHolder(itemView: View): RecyclerView.ViewHolder(itemView) { - val glide = GlideApp.with(itemView) + val glide = Glide.with(itemView) val binding = BlockedContactLayoutBinding.bind(itemView) fun bind(selectable: SelectableRecipient, toggle: (SelectableRecipient) -> Unit) { diff --git a/app/src/main/java/org/thoughtcrime/securesms/preferences/HelpSettingsActivity.kt b/app/src/main/java/org/thoughtcrime/securesms/preferences/HelpSettingsActivity.kt index e7e5f2d5f6..339047bbf6 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/preferences/HelpSettingsActivity.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/preferences/HelpSettingsActivity.kt @@ -36,7 +36,7 @@ class HelpSettingsFragment: CorrectedPreferenceFragment() { private const val FAQ = "faq" private const val SUPPORT = "support" - private const val CROWDIN_URL = "https://crowdin.com/project/session-android" + private const val CROWDIN_URL = "https://getsession.org/translate" private const val FEEDBACK_URL = "https://getsession.org/survey" private const val FAQ_URL = "https://getsession.org/faq" private const val SUPPORT_URL = "https://sessionapp.zendesk.com/hc/en-us" diff --git a/app/src/main/java/org/thoughtcrime/securesms/preferences/RadioOptionAdapter.kt b/app/src/main/java/org/thoughtcrime/securesms/preferences/RadioOptionAdapter.kt index 60b5fb8b2c..1e0bcd27c0 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/preferences/RadioOptionAdapter.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/preferences/RadioOptionAdapter.kt @@ -10,7 +10,7 @@ import androidx.recyclerview.widget.ListAdapter import androidx.recyclerview.widget.RecyclerView import network.loki.messenger.R import network.loki.messenger.databinding.ItemSelectableBinding -import org.thoughtcrime.securesms.mms.GlideApp +import com.bumptech.glide.Glide import org.thoughtcrime.securesms.ui.GetString import java.util.Objects @@ -45,7 +45,7 @@ class RadioOptionAdapter( } class ViewHolder(itemView: View): RecyclerView.ViewHolder(itemView) { - val glide = GlideApp.with(itemView) + val glide = Glide.with(itemView) val binding = ItemSelectableBinding.bind(itemView) fun bind(option: RadioOption, isSelected: Boolean, toggleSelection: (RadioOption) -> Unit) { diff --git a/app/src/main/java/org/thoughtcrime/securesms/reactions/ReactionRecipientsAdapter.java b/app/src/main/java/org/thoughtcrime/securesms/reactions/ReactionRecipientsAdapter.java index 34a427547b..79717eabb1 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/reactions/ReactionRecipientsAdapter.java +++ b/app/src/main/java/org/thoughtcrime/securesms/reactions/ReactionRecipientsAdapter.java @@ -13,7 +13,7 @@ import org.session.libsession.messaging.utilities.AccountId; import org.thoughtcrime.securesms.components.ProfilePictureView; import org.thoughtcrime.securesms.components.emoji.EmojiImageView; import org.thoughtcrime.securesms.database.model.MessageId; -import org.thoughtcrime.securesms.mms.GlideApp; +import com.bumptech.glide.Glide; import java.util.Collections; import java.util.List; diff --git a/app/src/main/java/org/thoughtcrime/securesms/scribbles/StickerSelectFragment.java b/app/src/main/java/org/thoughtcrime/securesms/scribbles/StickerSelectFragment.java index ae19d13b64..70547b4670 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/scribbles/StickerSelectFragment.java +++ b/app/src/main/java/org/thoughtcrime/securesms/scribbles/StickerSelectFragment.java @@ -37,13 +37,13 @@ import com.bumptech.glide.load.engine.DiskCacheStrategy; import network.loki.messenger.R; -import org.thoughtcrime.securesms.mms.GlideApp; -import org.thoughtcrime.securesms.mms.GlideRequests; +import com.bumptech.glide.Glide; +import com.bumptech.glide.RequestManager; public class StickerSelectFragment extends Fragment implements LoaderManager.LoaderCallbacks { private RecyclerView recyclerView; - private GlideRequests glideRequests; + private RequestManager glideRequests; private String assetDirectory; private StickerSelectionListener listener; @@ -71,7 +71,7 @@ public class StickerSelectFragment extends Fragment implements LoaderManager.Loa public void onActivityCreated(Bundle bundle) { super.onActivityCreated(bundle); - this.glideRequests = GlideApp.with(this); + this.glideRequests = Glide.with(this); this.assetDirectory = getArguments().getString("assetDirectory"); getLoaderManager().initLoader(0, null, this); @@ -99,11 +99,11 @@ public class StickerSelectFragment extends Fragment implements LoaderManager.Loa class StickersAdapter extends RecyclerView.Adapter { - private final GlideRequests glideRequests; + private final RequestManager glideRequests; private final String[] stickerFiles; private final LayoutInflater layoutInflater; - StickersAdapter(@NonNull Context context, @NonNull GlideRequests glideRequests, @NonNull String[] stickerFiles) { + StickersAdapter(@NonNull Context context, @NonNull RequestManager glideRequests, @NonNull String[] stickerFiles) { this.glideRequests = glideRequests; this.stickerFiles = stickerFiles; this.layoutInflater = LayoutInflater.from(context); diff --git a/app/src/main/java/org/thoughtcrime/securesms/scribbles/UriGlideRenderer.java b/app/src/main/java/org/thoughtcrime/securesms/scribbles/UriGlideRenderer.java index 15d4d52434..f7e028c0fd 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/scribbles/UriGlideRenderer.java +++ b/app/src/main/java/org/thoughtcrime/securesms/scribbles/UriGlideRenderer.java @@ -11,6 +11,7 @@ import android.os.Parcel; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import com.bumptech.glide.RequestBuilder; import com.bumptech.glide.load.engine.DiskCacheStrategy; import com.bumptech.glide.request.target.SimpleTarget; import com.bumptech.glide.request.transition.Transition; @@ -20,8 +21,7 @@ import org.thoughtcrime.securesms.imageeditor.Bounds; import org.thoughtcrime.securesms.imageeditor.Renderer; import org.thoughtcrime.securesms.imageeditor.RendererContext; import org.thoughtcrime.securesms.mms.DecryptableStreamUriLoader; -import org.thoughtcrime.securesms.mms.GlideApp; -import org.thoughtcrime.securesms.mms.GlideRequest; +import com.bumptech.glide.Glide; import java.util.concurrent.ExecutionException; @@ -97,8 +97,8 @@ final class UriGlideRenderer implements Renderer { } } - private GlideRequest getBitmapGlideRequest(@NonNull Context context) { - return GlideApp.with(context) + private RequestBuilder getBitmapGlideRequest(@NonNull Context context) { + return Glide.with(context) .asBitmap() .diskCacheStrategy(DiskCacheStrategy.NONE) .override(maxWidth, maxHeight) diff --git a/app/src/main/java/org/thoughtcrime/securesms/service/DirectShareService.java b/app/src/main/java/org/thoughtcrime/securesms/service/DirectShareService.java index 0516dc2856..c8a67926a1 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/service/DirectShareService.java +++ b/app/src/main/java/org/thoughtcrime/securesms/service/DirectShareService.java @@ -19,7 +19,7 @@ import org.thoughtcrime.securesms.ShareActivity; import org.thoughtcrime.securesms.database.ThreadDatabase; import org.thoughtcrime.securesms.database.model.ThreadRecord; import org.thoughtcrime.securesms.dependencies.DatabaseComponent; -import org.thoughtcrime.securesms.mms.GlideApp; +import com.bumptech.glide.Glide; import org.thoughtcrime.securesms.util.BitmapUtil; import java.util.LinkedList; @@ -50,7 +50,7 @@ public class DirectShareService extends ChooserTargetService { if (recipient.getContactPhoto() != null) { try { - avatar = GlideApp.with(this) + avatar = Glide.with(this) .asBitmap() .load(recipient.getContactPhoto()) .circleCrop() diff --git a/app/src/main/java/org/thoughtcrime/securesms/service/TelephonyHandler.kt b/app/src/main/java/org/thoughtcrime/securesms/service/TelephonyHandler.kt new file mode 100644 index 0000000000..3e78c223fa --- /dev/null +++ b/app/src/main/java/org/thoughtcrime/securesms/service/TelephonyHandler.kt @@ -0,0 +1,46 @@ +package org.thoughtcrime.securesms.service + +import android.os.Build +import android.telephony.PhoneStateListener +import android.telephony.PhoneStateListener.LISTEN_NONE +import android.telephony.TelephonyManager +import androidx.annotation.RequiresApi +import org.thoughtcrime.securesms.webrtc.HangUpRtcOnPstnCallAnsweredListener +import org.thoughtcrime.securesms.webrtc.HangUpRtcTelephonyCallback +import java.util.concurrent.ExecutorService + +internal interface TelephonyHandler { + fun register(telephonyManager: TelephonyManager) + fun unregister(telephonyManager: TelephonyManager) +} + +internal fun TelephonyHandler(serviceExecutor: ExecutorService, callback: () -> Unit) = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { + TelephonyHandlerV31(serviceExecutor, callback) +} else { + TelephonyHandlerV23(callback) +} + +@RequiresApi(Build.VERSION_CODES.S) +private class TelephonyHandlerV31(val serviceExecutor: ExecutorService, callback: () -> Unit): TelephonyHandler { + private val callback = HangUpRtcTelephonyCallback(callback) + + override fun register(telephonyManager: TelephonyManager) { + telephonyManager.registerTelephonyCallback(serviceExecutor, callback) + } + + override fun unregister(telephonyManager: TelephonyManager) { + telephonyManager.unregisterTelephonyCallback(callback) + } +} + +private class TelephonyHandlerV23(callback: () -> Unit): TelephonyHandler { + val callback = HangUpRtcOnPstnCallAnsweredListener(callback) + + override fun register(telephonyManager: TelephonyManager) { + telephonyManager.listen(callback, PhoneStateListener.LISTEN_CALL_STATE) + } + + override fun unregister(telephonyManager: TelephonyManager) { + telephonyManager.listen(callback, LISTEN_NONE) + } +} diff --git a/app/src/main/java/org/thoughtcrime/securesms/service/WebRtcCallService.kt b/app/src/main/java/org/thoughtcrime/securesms/service/WebRtcCallService.kt index 36106123a8..f40a075d8d 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/service/WebRtcCallService.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/service/WebRtcCallService.kt @@ -1,6 +1,5 @@ package org.thoughtcrime.securesms.service -import android.app.ForegroundServiceStartNotAllowedException import android.content.BroadcastReceiver import android.content.Context import android.content.Intent @@ -9,11 +8,7 @@ import android.content.Intent.FLAG_ACTIVITY_NEW_TASK import android.content.IntentFilter import android.content.pm.PackageManager import android.media.AudioManager -import android.os.Build -import android.os.IBinder import android.os.ResultReceiver -import android.telephony.PhoneStateListener -import android.telephony.PhoneStateListener.LISTEN_NONE import android.telephony.TelephonyManager import androidx.core.content.ContextCompat import androidx.core.os.bundleOf @@ -34,13 +29,29 @@ import org.thoughtcrime.securesms.util.CallNotificationBuilder.Companion.TYPE_IN import org.thoughtcrime.securesms.util.CallNotificationBuilder.Companion.TYPE_INCOMING_PRE_OFFER import org.thoughtcrime.securesms.util.CallNotificationBuilder.Companion.TYPE_INCOMING_RINGING import org.thoughtcrime.securesms.util.CallNotificationBuilder.Companion.TYPE_OUTGOING_RINGING -import org.thoughtcrime.securesms.webrtc.* +import org.thoughtcrime.securesms.webrtc.AudioManagerCommand +import org.thoughtcrime.securesms.webrtc.CallManager +import org.thoughtcrime.securesms.webrtc.CallViewModel +import org.thoughtcrime.securesms.webrtc.IncomingPstnCallReceiver +import org.thoughtcrime.securesms.webrtc.NetworkChangeReceiver +import org.thoughtcrime.securesms.webrtc.PeerConnectionException +import org.thoughtcrime.securesms.webrtc.PowerButtonReceiver +import org.thoughtcrime.securesms.webrtc.ProximityLockRelease +import org.thoughtcrime.securesms.webrtc.UncaughtExceptionHandlerManager +import org.thoughtcrime.securesms.webrtc.WiredHeadsetStateReceiver import org.thoughtcrime.securesms.webrtc.audio.OutgoingRinger import org.thoughtcrime.securesms.webrtc.data.Event import org.thoughtcrime.securesms.webrtc.locks.LockManager -import org.webrtc.* -import org.webrtc.PeerConnection.IceConnectionState.* -import java.util.* +import org.webrtc.DataChannel +import org.webrtc.IceCandidate +import org.webrtc.MediaStream +import org.webrtc.PeerConnection +import org.webrtc.PeerConnection.IceConnectionState.CONNECTED +import org.webrtc.PeerConnection.IceConnectionState.DISCONNECTED +import org.webrtc.PeerConnection.IceConnectionState.FAILED +import org.webrtc.RtpReceiver +import org.webrtc.SessionDescription +import java.util.UUID import java.util.concurrent.ExecutionException import java.util.concurrent.Executors import java.util.concurrent.ScheduledFuture @@ -209,16 +220,8 @@ class WebRtcCallService : LifecycleService(), CallManager.WebRtcListener { private val serviceExecutor = Executors.newSingleThreadExecutor() private val timeoutExecutor = Executors.newScheduledThreadPool(1) - private val hangupOnCallAnswered by lazy { - HangUpRtcOnPstnCallAnsweredListener { - ContextCompat.startForegroundService(this, hangupIntent(this)) - } - } - - private val hangupTelephonyCallback by lazy { - HangUpRtcTelephonyCallback { - ContextCompat.startForegroundService(this, hangupIntent(this)) - } + private val telephonyHandler = TelephonyHandler(serviceExecutor) { + ContextCompat.startForegroundService(this, hangupIntent(this)) } private var networkChangedReceiver: NetworkChangeReceiver? = null @@ -251,17 +254,12 @@ class WebRtcCallService : LifecycleService(), CallManager.WebRtcListener { return callManager.callId == expectedCallId } - private fun isPreOffer() = callManager.isPreOffer() private fun isBusy(intent: Intent) = callManager.isBusy(this, getCallId(intent)) private fun isIdle() = callManager.isIdle() - override fun onBind(intent: Intent): IBinder? { - return super.onBind(intent) - } - override fun onHangup() { serviceExecutor.execute { callManager.handleRemoteHangup() @@ -276,38 +274,38 @@ class WebRtcCallService : LifecycleService(), CallManager.WebRtcListener { } override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { + super.onStartCommand(intent, flags, startId) if (intent == null || intent.action == null) return START_NOT_STICKY serviceExecutor.execute { val action = intent.action val callId = ((intent.getSerializableExtra(EXTRA_CALL_ID) as? UUID)?.toString() ?: "No callId") Log.i("Loki", "Handling ${intent.action} for call: ${callId}") - when { - action == ACTION_INCOMING_RING && isSameCall(intent) && callManager.currentConnectionState == CallState.Reconnecting -> handleNewOffer( - intent - ) - action == ACTION_PRE_OFFER && isIdle() -> handlePreOffer(intent) - action == ACTION_INCOMING_RING && isBusy(intent) -> handleBusyCall(intent) - action == ACTION_INCOMING_RING && isPreOffer() -> handleIncomingRing(intent) - action == ACTION_OUTGOING_CALL && isIdle() -> handleOutgoingCall(intent) - action == ACTION_ANSWER_CALL -> handleAnswerCall(intent) - action == ACTION_DENY_CALL -> handleDenyCall(intent) - action == ACTION_LOCAL_HANGUP -> handleLocalHangup(intent) - action == ACTION_REMOTE_HANGUP -> handleRemoteHangup(intent) - action == ACTION_SET_MUTE_AUDIO -> handleSetMuteAudio(intent) - action == ACTION_SET_MUTE_VIDEO -> handleSetMuteVideo(intent) - action == ACTION_FLIP_CAMERA -> handleSetCameraFlip(intent) - action == ACTION_WIRED_HEADSET_CHANGE -> handleWiredHeadsetChanged(intent) - action == ACTION_SCREEN_OFF -> handleScreenOffChange(intent) - action == ACTION_RESPONSE_MESSAGE && isSameCall(intent) && callManager.currentConnectionState == CallState.Reconnecting -> handleResponseMessage( - intent - ) - action == ACTION_RESPONSE_MESSAGE -> handleResponseMessage(intent) - action == ACTION_ICE_MESSAGE -> handleRemoteIceCandidate(intent) - action == ACTION_ICE_CONNECTED -> handleIceConnected(intent) - action == ACTION_CHECK_TIMEOUT -> handleCheckTimeout(intent) - action == ACTION_CHECK_RECONNECT -> handleCheckReconnect(intent) - action == ACTION_IS_IN_CALL_QUERY -> handleIsInCallQuery(intent) - action == ACTION_UPDATE_AUDIO -> handleUpdateAudio(intent) + when (action) { + ACTION_PRE_OFFER -> if (isIdle()) handlePreOffer(intent) + ACTION_INCOMING_RING -> when { + isSameCall(intent) && callManager.currentConnectionState == CallState.Reconnecting -> { + handleNewOffer(intent) + } + isBusy(intent) -> handleBusyCall(intent) + isPreOffer() -> handleIncomingRing(intent) + } + ACTION_OUTGOING_CALL -> if (isIdle()) handleOutgoingCall(intent) + ACTION_ANSWER_CALL -> handleAnswerCall(intent) + ACTION_DENY_CALL -> handleDenyCall(intent) + ACTION_LOCAL_HANGUP -> handleLocalHangup(intent) + ACTION_REMOTE_HANGUP -> handleRemoteHangup(intent) + ACTION_SET_MUTE_AUDIO -> handleSetMuteAudio(intent) + ACTION_SET_MUTE_VIDEO -> handleSetMuteVideo(intent) + ACTION_FLIP_CAMERA -> handleSetCameraFlip(intent) + ACTION_WIRED_HEADSET_CHANGE -> handleWiredHeadsetChanged(intent) + ACTION_SCREEN_OFF -> handleScreenOffChange(intent) + ACTION_RESPONSE_MESSAGE -> handleResponseMessage(intent) + ACTION_ICE_MESSAGE -> handleRemoteIceCandidate(intent) + ACTION_ICE_CONNECTED -> handleIceConnected(intent) + ACTION_CHECK_TIMEOUT -> handleCheckTimeout(intent) + ACTION_CHECK_RECONNECT -> handleCheckReconnect(intent) + ACTION_IS_IN_CALL_QUERY -> handleIsInCallQuery(intent) + ACTION_UPDATE_AUDIO -> handleUpdateAudio(intent) } } return START_NOT_STICKY @@ -322,13 +320,7 @@ class WebRtcCallService : LifecycleService(), CallManager.WebRtcListener { registerWiredHeadsetStateReceiver() registerWantsToAnswerReceiver() if (checkSelfPermission(android.Manifest.permission.READ_PHONE_STATE) == PackageManager.PERMISSION_GRANTED) { - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.S) { - getSystemService(TelephonyManager::class.java) - .listen(hangupOnCallAnswered, PhoneStateListener.LISTEN_CALL_STATE) - } else { - getSystemService(TelephonyManager::class.java) - .registerTelephonyCallback(serviceExecutor, hangupTelephonyCallback) - } + telephonyHandler.register(getSystemService(TelephonyManager::class.java)) } registerUncaughtExceptionHandler() networkChangedReceiver = NetworkChangeReceiver(::networkChange) @@ -735,9 +727,8 @@ class WebRtcCallService : LifecycleService(), CallManager.WebRtcListener { CallNotificationBuilder.WEBRTC_NOTIFICATION, CallNotificationBuilder.getCallInProgressNotification(this, type, recipient) ) - } - catch(e: ForegroundServiceStartNotAllowedException) { - Log.e(TAG, "Failed to setCallInProgressNotification as a foreground service for type: ${type}, trying to update instead") + } catch (e: IllegalStateException) { + Log.e(TAG, "Failed to setCallInProgressNotification as a foreground service for type: ${type}, trying to update instead", e) } if (!CallNotificationBuilder.areNotificationsEnabled(this) && type == TYPE_INCOMING_PRE_OFFER) { @@ -750,11 +741,7 @@ class WebRtcCallService : LifecycleService(), CallManager.WebRtcListener { } private fun getOptionalRemoteRecipient(intent: Intent): Recipient? = - if (intent.hasExtra(EXTRA_RECIPIENT_ADDRESS)) { - getRemoteRecipient(intent) - } else { - null - } + intent.takeIf { it.hasExtra(EXTRA_RECIPIENT_ADDRESS) }?.let(::getRemoteRecipient) private fun getRemoteRecipient(intent: Intent): Recipient { val remoteAddress = intent.getParcelableExtra
(EXTRA_RECIPIENT_ADDRESS) @@ -763,10 +750,9 @@ class WebRtcCallService : LifecycleService(), CallManager.WebRtcListener { return Recipient.from(this, remoteAddress, true) } - private fun getCallId(intent: Intent): UUID { - return intent.getSerializableExtra(EXTRA_CALL_ID) as? UUID + private fun getCallId(intent: Intent): UUID = + intent.getSerializableExtra(EXTRA_CALL_ID) as? UUID ?: throw AssertionError("No callId in intent!") - } private fun insertMissedCall(recipient: Recipient, signal: Boolean) { callManager.insertCallMessage( @@ -788,8 +774,8 @@ class WebRtcCallService : LifecycleService(), CallManager.WebRtcListener { callReceiver?.let { receiver -> unregisterReceiver(receiver) } - wiredHeadsetStateReceiver?.let { unregisterReceiver(it) } - powerButtonReceiver?.let { unregisterReceiver(it) } + wiredHeadsetStateReceiver?.let(::unregisterReceiver) + powerButtonReceiver?.let(::unregisterReceiver) networkChangedReceiver?.unregister(this) wantsToAnswerReceiver?.let { receiver -> LocalBroadcastManager.getInstance(this).unregisterReceiver(receiver) @@ -804,14 +790,7 @@ class WebRtcCallService : LifecycleService(), CallManager.WebRtcListener { currentTimeouts = 0 isNetworkAvailable = false if (checkSelfPermission(android.Manifest.permission.READ_PHONE_STATE) == PackageManager.PERMISSION_GRANTED) { - val telephonyManager = getSystemService(TelephonyManager::class.java) - with(telephonyManager) { - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.S) { - this.listen(hangupOnCallAnswered, LISTEN_NONE) - } else { - this.unregisterTelephonyCallback(hangupTelephonyCallback) - } - } + telephonyHandler.unregister(getSystemService(TelephonyManager::class.java)) } super.onDestroy() } @@ -819,13 +798,12 @@ class WebRtcCallService : LifecycleService(), CallManager.WebRtcListener { private fun networkChange(networkAvailable: Boolean) { Log.d("Loki", "flipping network available to $networkAvailable") isNetworkAvailable = networkAvailable - if (networkAvailable && !callManager.isReestablishing && callManager.currentConnectionState == CallState.Connected) { + if (networkAvailable && callManager.currentConnectionState == CallState.Connected) { Log.d("Loki", "Should reconnected") } } - private class CheckReconnectedRunnable(private val callId: UUID, private val context: Context) : - Runnable { + private class CheckReconnectedRunnable(private val callId: UUID, private val context: Context) : Runnable { override fun run() { val intent = Intent(context, WebRtcCallService::class.java) .setAction(ACTION_CHECK_RECONNECT) @@ -834,18 +812,7 @@ class WebRtcCallService : LifecycleService(), CallManager.WebRtcListener { } } - private class ReconnectTimeoutRunnable(private val callId: UUID, private val context: Context) : - Runnable { - override fun run() { - val intent = Intent(context, WebRtcCallService::class.java) - .setAction(ACTION_CHECK_RECONNECT_TIMEOUT) - .putExtra(EXTRA_CALL_ID, callId) - context.startService(intent) - } - } - - private class TimeoutRunnable(private val callId: UUID, private val context: Context) : - Runnable { + private class TimeoutRunnable(private val callId: UUID, private val context: Context) : Runnable { override fun run() { val intent = Intent(context, WebRtcCallService::class.java) .setAction(ACTION_CHECK_TIMEOUT) diff --git a/app/src/main/java/org/thoughtcrime/securesms/ui/components/RadioButton.kt b/app/src/main/java/org/thoughtcrime/securesms/ui/components/RadioButton.kt index 154c9ea3a1..cabe536767 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/ui/components/RadioButton.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/ui/components/RadioButton.kt @@ -1,6 +1,5 @@ package org.thoughtcrime.securesms.ui.components -import android.content.ContentProvider import androidx.compose.animation.AnimatedVisibility import androidx.compose.animation.scaleIn import androidx.compose.animation.scaleOut @@ -24,11 +23,9 @@ import androidx.compose.material3.LocalContentColor import androidx.compose.material3.Text import androidx.compose.material3.TextButton import androidx.compose.runtime.Composable -import androidx.compose.runtime.CompositionLocalProvider import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clip -import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.RectangleShape import androidx.compose.ui.semantics.Role import androidx.compose.ui.tooling.preview.Preview @@ -42,8 +39,6 @@ import org.thoughtcrime.securesms.ui.theme.LocalColors import org.thoughtcrime.securesms.ui.theme.LocalDimensions import org.thoughtcrime.securesms.ui.theme.LocalType import org.thoughtcrime.securesms.ui.theme.PreviewTheme -import org.thoughtcrime.securesms.ui.theme.sessionTypography -import org.thoughtcrime.securesms.ui.theme.textEnabled import org.thoughtcrime.securesms.ui.theme.transparentButtonColors import kotlin.time.Duration.Companion.days diff --git a/app/src/main/java/org/thoughtcrime/securesms/ui/theme/ThemeColors.kt b/app/src/main/java/org/thoughtcrime/securesms/ui/theme/ThemeColors.kt index 8d080b65b7..252497f023 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/ui/theme/ThemeColors.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/ui/theme/ThemeColors.kt @@ -43,7 +43,6 @@ val ThemeColors.textSelectionColors fun ThemeColors.text(isError: Boolean): Color = if (isError) danger else text fun ThemeColors.textSecondary(isError: Boolean): Color = if (isError) danger else textSecondary -fun ThemeColors.textEnabled(enabled: Boolean) = if (enabled) text else disabled fun ThemeColors.borders(isError: Boolean): Color = if (isError) danger else borders fun ThemeColors.toMaterialColors() = if (isLight) { diff --git a/app/src/main/java/org/thoughtcrime/securesms/util/BitmapUtil.java b/app/src/main/java/org/thoughtcrime/securesms/util/BitmapUtil.java index 3bb0d2db21..93b21512ea 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/util/BitmapUtil.java +++ b/app/src/main/java/org/thoughtcrime/securesms/util/BitmapUtil.java @@ -20,7 +20,7 @@ import com.bumptech.glide.load.engine.DiskCacheStrategy; import org.session.libsession.utilities.MediaTypes; import org.session.libsignal.utilities.Log; -import org.thoughtcrime.securesms.mms.GlideApp; +import com.bumptech.glide.Glide; import org.thoughtcrime.securesms.mms.MediaConstraints; import org.session.libsession.utilities.Util; @@ -98,7 +98,7 @@ public class BitmapUtil { int attempts = 0; byte[] bytes; - Bitmap scaledBitmap = GlideApp.with(context.getApplicationContext()) + Bitmap scaledBitmap = Glide.with(context.getApplicationContext()) .asBitmap() .load(model) .skipMemoryCache(true) @@ -164,7 +164,7 @@ public class BitmapUtil { throws BitmapDecodingException { try { - return GlideApp.with(context.getApplicationContext()) + return Glide.with(context.getApplicationContext()) .asBitmap() .load(model) .centerInside() diff --git a/app/src/main/java/org/thoughtcrime/securesms/util/MediaUtil.java b/app/src/main/java/org/thoughtcrime/securesms/util/MediaUtil.java index 5c4894c12b..fa2fd6b503 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/util/MediaUtil.java +++ b/app/src/main/java/org/thoughtcrime/securesms/util/MediaUtil.java @@ -22,7 +22,7 @@ import org.thoughtcrime.securesms.mms.AudioSlide; import org.thoughtcrime.securesms.mms.DecryptableStreamUriLoader.DecryptableUri; import org.thoughtcrime.securesms.mms.DocumentSlide; import org.thoughtcrime.securesms.mms.GifSlide; -import org.thoughtcrime.securesms.mms.GlideApp; +import com.bumptech.glide.Glide; import org.thoughtcrime.securesms.mms.ImageSlide; import org.thoughtcrime.securesms.mms.MmsSlide; import org.thoughtcrime.securesms.mms.PartAuthority; @@ -115,7 +115,7 @@ public class MediaUtil { if (MediaUtil.isGif(contentType)) { try { - GifDrawable drawable = GlideApp.with(context) + GifDrawable drawable = Glide.with(context) .asGif() .skipMemoryCache(true) .diskCacheStrategy(DiskCacheStrategy.NONE) diff --git a/app/src/main/java/org/thoughtcrime/securesms/webrtc/CallManager.kt b/app/src/main/java/org/thoughtcrime/securesms/webrtc/CallManager.kt index e2f8a9f21c..90e1ce6085 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/webrtc/CallManager.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/webrtc/CallManager.kt @@ -118,7 +118,7 @@ class CallManager( remoteVideoEnabled = false ) ) - val videoState = _videoState + val videoState = _videoState.asStateFlow() private val stateProcessor = StateProcessor(CallState.Idle) @@ -137,7 +137,7 @@ class CallManager( val currentCallState get() = _callStateEvents.value - var iceState = IceConnectionState.CLOSED + private var iceState = IceConnectionState.CLOSED private var eglBase: EglBase? = null @@ -151,7 +151,6 @@ class CallManager( _recipientEvents.value = RecipientUpdate(value) } var callStartTime: Long = -1 - var isReestablishing: Boolean = false private var peerConnection: PeerConnectionWrapper? = null private var dataChannel: DataChannel? = null @@ -628,12 +627,10 @@ class CallManager( if (_videoState.value.swapped) { peerConnection?.rotationVideoSink?.setSink(fullscreenRenderer) - floatingRenderer?.let{remoteRotationSink?.setSink(it) } + floatingRenderer?.let { remoteRotationSink?.setSink(it) } } else { - peerConnection?.rotationVideoSink?.apply { - setSink(floatingRenderer) - } - fullscreenRenderer?.let{ remoteRotationSink?.setSink(it) } + peerConnection?.rotationVideoSink?.setSink(floatingRenderer) + fullscreenRenderer?.let { remoteRotationSink?.setSink(it) } } } @@ -645,12 +642,12 @@ class CallManager( /** * Returns the renderer currently showing the user's video, not the contact's */ - private fun getUserRenderer() = if(_videoState.value.swapped) fullscreenRenderer else floatingRenderer + private fun getUserRenderer() = if (_videoState.value.swapped) fullscreenRenderer else floatingRenderer /** * Returns the renderer currently showing the contact's video, not the user's */ - private fun getRemoteRenderer() = if(_videoState.value.swapped) floatingRenderer else fullscreenRenderer + private fun getRemoteRenderer() = if (_videoState.value.swapped) floatingRenderer else fullscreenRenderer /** * Makes sure the user's renderer applies mirroring if necessary @@ -659,12 +656,12 @@ class CallManager( val videoState = _videoState.value // if we have user video and the camera is front facing, make sure to mirror stream - if(videoState.userVideoEnabled) { + if (videoState.userVideoEnabled) { getUserRenderer()?.setMirror(isCameraFrontFacing()) } // the remote video is never mirrored - if(videoState.remoteVideoEnabled){ + if (videoState.remoteVideoEnabled){ getRemoteRenderer()?.setMirror(false) } } diff --git a/app/src/main/java/org/thoughtcrime/securesms/webrtc/CallViewModel.kt b/app/src/main/java/org/thoughtcrime/securesms/webrtc/CallViewModel.kt index f49e2d3333..da5eb07549 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/webrtc/CallViewModel.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/webrtc/CallViewModel.kt @@ -2,7 +2,6 @@ package org.thoughtcrime.securesms.webrtc import androidx.lifecycle.ViewModel import dagger.hilt.android.lifecycle.HiltViewModel -import kotlinx.coroutines.flow.SharedFlow import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.onEach @@ -32,29 +31,25 @@ class CallViewModel @Inject constructor(private val callManager: CallManager): V } val floatingRenderer: SurfaceViewRenderer? - get() = callManager.floatingRenderer + get() = callManager.floatingRenderer val fullscreenRenderer: SurfaceViewRenderer? - get() = callManager.fullscreenRenderer + get() = callManager.fullscreenRenderer - private var _microphoneEnabled: Boolean = true + var microphoneEnabled: Boolean = true + private set - val microphoneEnabled: Boolean - get() = _microphoneEnabled - - private var _isSpeaker: Boolean = false - val isSpeaker: Boolean - get() = _isSpeaker + var isSpeaker: Boolean = false + private set val audioDeviceState - get() = callManager.audioDeviceEvents - .onEach { - _isSpeaker = it.selectedDevice == SignalAudioManager.AudioDevice.SPEAKER_PHONE - } + get() = callManager.audioDeviceEvents.onEach { + isSpeaker = it.selectedDevice == SignalAudioManager.AudioDevice.SPEAKER_PHONE + } val localAudioEnabledState get() = callManager.audioEvents.map { it.isEnabled } - .onEach { _microphoneEnabled = it } + .onEach { microphoneEnabled = it } val videoState: StateFlow get() = callManager.videoState @@ -65,17 +60,10 @@ class CallViewModel @Inject constructor(private val callManager: CallManager): V callManager.setDeviceOrientation(value) } - val currentCallState - get() = callManager.currentCallState - - val callState - get() = callManager.callStateEvents - - val recipient - get() = callManager.recipientEvents - - val callStartTime: Long - get() = callManager.callStartTime + val currentCallState get() = callManager.currentCallState + val callState get() = callManager.callStateEvents + val recipient get() = callManager.recipientEvents + val callStartTime: Long get() = callManager.callStartTime fun swapVideos() { callManager.swapVideos() diff --git a/app/src/main/java/org/thoughtcrime/securesms/webrtc/video/RemoteRotationVideoProxySink.kt b/app/src/main/java/org/thoughtcrime/securesms/webrtc/video/RemoteRotationVideoProxySink.kt index 62b78d6ec8..a2609187f0 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/webrtc/video/RemoteRotationVideoProxySink.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/webrtc/video/RemoteRotationVideoProxySink.kt @@ -14,7 +14,7 @@ class RemoteRotationVideoProxySink: VideoSink { val thisSink = targetSink ?: return val thisFrame = frame ?: return - val modifiedRotation = thisFrame.rotation - rotation + val modifiedRotation = (thisFrame.rotation - rotation + 360) % 360 val newFrame = VideoFrame(thisFrame.buffer, modifiedRotation, thisFrame.timestampNs) thisSink.onFrame(newFrame) diff --git a/build.gradle b/build.gradle index 70d1f63fa4..505f874e65 100644 --- a/build.gradle +++ b/build.gradle @@ -17,13 +17,15 @@ buildscript { classpath "org.jetbrains.kotlin:kotlin-serialization:$kotlinVersion" classpath "com.google.gms:google-services:$googleServicesVersion" classpath "com.squareup:javapoet:1.13.0" - classpath "com.google.dagger:hilt-android-gradle-plugin:$daggerVersion" if (project.hasProperty('huawei')) classpath 'com.huawei.agconnect:agcp:1.9.1.300' } } -plugins{ - id("com.google.dagger.hilt.android") version "2.44" apply false +// List plugins AND their versions here, but don't apply. This allows you to use the plugin +// in your module without specifying the version. +plugins { + id 'com.google.devtools.ksp' version "$kotlinVersion-1.0.20" apply false + id 'com.google.dagger.hilt.android' version "$daggerHiltVersion" apply false } allprojects { diff --git a/gradle.properties b/gradle.properties index 6154652583..b40f4b59ca 100644 --- a/gradle.properties +++ b/gradle.properties @@ -14,19 +14,19 @@ android.enableJetifier=true org.gradle.jvmargs=-Xmx2048M -Dkotlin.daemon.jvm.options\="-Xmx2048M" -org.gradle.unsafe.configuration-cache=true gradlePluginVersion=7.3.1 googleServicesVersion=4.3.12 -kotlinVersion=1.8.21 +kotlinVersion=1.9.24 android.useAndroidX=true appcompatVersion=1.6.1 coreVersion=1.13.1 composeVersion=1.6.4 coroutinesVersion=1.6.4 curve25519Version=0.6.0 -daggerVersion=2.46.1 -glideVersion=4.11.0 +jetpackHiltVersion=1.2.0 +daggerHiltVersion=2.51.1 +glideVersion=4.16.0 jacksonDatabindVersion=2.9.8 junitVersion=4.13.2 kotlinxJsonVersion=1.3.3 diff --git a/libsession/build.gradle b/libsession/build.gradle index 55146823ec..2856e88a2c 100644 --- a/libsession/build.gradle +++ b/libsession/build.gradle @@ -2,6 +2,8 @@ plugins { id 'com.android.library' id 'kotlin-android' id 'kotlinx-serialization' + id 'com.google.devtools.ksp' + id 'com.google.dagger.hilt.android' } android { @@ -21,6 +23,11 @@ dependencies { implementation project(":libsignal") implementation project(":libsession-util") implementation project(":liblazysodium") + + implementation("com.google.dagger:hilt-android:$daggerHiltVersion") + ksp("com.google.dagger:hilt-compiler:$daggerHiltVersion") + ksp("androidx.hilt:hilt-compiler:$jetpackHiltVersion") + implementation "net.java.dev.jna:jna:5.12.1@aar" implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion" implementation "androidx.core:core-ktx:$coreVersion" @@ -28,7 +35,6 @@ dependencies { implementation "androidx.preference:preference-ktx:$preferenceVersion" implementation "com.google.android.material:material:$materialVersion" implementation "com.google.protobuf:protobuf-java:$protobufVersion" - implementation "com.google.dagger:hilt-android:$daggerVersion" androidTestImplementation 'androidx.test.ext:junit:1.1.5' androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1' implementation "com.github.bumptech.glide:glide:$glideVersion" diff --git a/libsession/src/main/java/org/session/libsession/snode/OnionRequestAPI.kt b/libsession/src/main/java/org/session/libsession/snode/OnionRequestAPI.kt index 8e55f286bc..3dcfc5b958 100644 --- a/libsession/src/main/java/org/session/libsession/snode/OnionRequestAPI.kt +++ b/libsession/src/main/java/org/session/libsession/snode/OnionRequestAPI.kt @@ -10,6 +10,7 @@ import okhttp3.Request import org.session.libsession.messaging.file_server.FileServerApi import org.session.libsession.utilities.AESGCM import org.session.libsession.utilities.AESGCM.EncryptionResult +import org.session.libsession.utilities.Util import org.session.libsession.utilities.getBodyForOnionRequest import org.session.libsession.utilities.getHeadersForOnionRequest import org.session.libsignal.crypto.getRandomElement @@ -189,8 +190,21 @@ object OnionRequestAPI { if (unusedSnodes.count() < pathSnodeCount) { throw InsufficientSnodesException() } // Don't test path snodes as this would reveal the user's IP to them guardSnodes.minus(reusableGuardSnodes).map { guardSnode -> - val result = listOf( guardSnode ) + (0 until (pathSize - 1)).map { - val pathSnode = unusedSnodes.getRandomElement() + val result = listOf( guardSnode ) + (0 until (pathSize - 1)).mapIndexed() { index, _ -> + var pathSnode = unusedSnodes.getRandomElement() + + // For the last node: We need to make sure the version is >= 2.8.0 + // to help with an issue that will disappear once the nodes are all updated + if(index == pathSize - 2) { + val suitableSnodes = unusedSnodes.filter { Util.compareVersions(it.version, "2.8.0") >= 0 } + pathSnode = if (suitableSnodes.isNotEmpty()) { + suitableSnodes.random() + } else { + throw InsufficientSnodesException() + } + } + + // remove the snode from the unused list and return it unusedSnodes = unusedSnodes.minus(pathSnode) pathSnode } diff --git a/libsession/src/main/java/org/session/libsession/snode/SnodeAPI.kt b/libsession/src/main/java/org/session/libsession/snode/SnodeAPI.kt index 0713065b2a..034ef0e7d2 100644 --- a/libsession/src/main/java/org/session/libsession/snode/SnodeAPI.kt +++ b/libsession/src/main/java/org/session/libsession/snode/SnodeAPI.kt @@ -88,6 +88,14 @@ object SnodeAPI { const val useTestnet = false + const val KEY_IP = "public_ip" + const val KEY_PORT = "storage_port" + const val KEY_X25519 = "pubkey_x25519" + const val KEY_ED25519 = "pubkey_ed25519" + const val KEY_VERSION = "storage_server_version" + + const val EMPTY_VERSION = "0.0.0" + // Error sealed class Error(val description: String) : Exception(description) { object Generic : Error("An error occurred.") @@ -146,6 +154,7 @@ object SnodeAPI { internal fun getRandomSnode(): Promise { val snodePool = this.snodePool + if (snodePool.count() < minimumSnodePoolCount) { val target = seedNodePool.random() val url = "$target/json_rpc" @@ -154,8 +163,11 @@ object SnodeAPI { "method" to "get_n_service_nodes", "params" to mapOf( "active_only" to true, - "limit" to 256, - "fields" to mapOf("public_ip" to true, "storage_port" to true, "pubkey_x25519" to true, "pubkey_ed25519" to true) + "fields" to mapOf( + KEY_IP to true, KEY_PORT to true, + KEY_X25519 to true, KEY_ED25519 to true, + KEY_VERSION to true + ) ) ) val deferred = deferred() @@ -173,12 +185,22 @@ object SnodeAPI { if (rawSnodes != null) { val snodePool = rawSnodes.mapNotNull { rawSnode -> val rawSnodeAsJSON = rawSnode as? Map<*, *> - val address = rawSnodeAsJSON?.get("public_ip") as? String - val port = rawSnodeAsJSON?.get("storage_port") as? Int - val ed25519Key = rawSnodeAsJSON?.get("pubkey_ed25519") as? String - val x25519Key = rawSnodeAsJSON?.get("pubkey_x25519") as? String - if (address != null && port != null && ed25519Key != null && x25519Key != null && address != "0.0.0.0") { - Snode("https://$address", port, Snode.KeySet(ed25519Key, x25519Key)) + val address = rawSnodeAsJSON?.get(KEY_IP) as? String + val port = rawSnodeAsJSON?.get(KEY_PORT) as? Int + val ed25519Key = rawSnodeAsJSON?.get(KEY_ED25519) as? String + val x25519Key = rawSnodeAsJSON?.get(KEY_X25519) as? String + val version = (rawSnodeAsJSON?.get(KEY_VERSION) as? ArrayList<*>) + ?.filterIsInstance() // get the array as Integers + ?.joinToString(separator = ".") // turn it int a version string + + if (address != null && port != null && ed25519Key != null && x25519Key != null + && address != "0.0.0.0" && version != null) { + Snode( + address = "https://$address", + port = port, + publicKeySet = Snode.KeySet(ed25519Key, x25519Key), + version = version + ) } else { Log.d("Loki", "Failed to parse: ${rawSnode?.prettifiedDescription()}.") null @@ -206,6 +228,10 @@ object SnodeAPI { } } + private fun extractVersionString(jsonVersion: String): String{ + return jsonVersion.removeSurrounding("[", "]").split(", ").joinToString(separator = ".") + } + internal fun dropSnodeFromSwarmIfNeeded(snode: Snode, publicKey: String) { val swarm = database.getSwarm(publicKey)?.toMutableSet() if (swarm != null && swarm.contains(snode)) { @@ -716,10 +742,11 @@ object SnodeAPI { val address = rawSnodeAsJSON?.get("ip") as? String val portAsString = rawSnodeAsJSON?.get("port") as? String val port = portAsString?.toInt() - val ed25519Key = rawSnodeAsJSON?.get("pubkey_ed25519") as? String - val x25519Key = rawSnodeAsJSON?.get("pubkey_x25519") as? String + val ed25519Key = rawSnodeAsJSON?.get(KEY_ED25519) as? String + val x25519Key = rawSnodeAsJSON?.get(KEY_X25519) as? String + if (address != null && port != null && ed25519Key != null && x25519Key != null && address != "0.0.0.0") { - Snode("https://$address", port, Snode.KeySet(ed25519Key, x25519Key)) + Snode("https://$address", port, Snode.KeySet(ed25519Key, x25519Key), EMPTY_VERSION) } else { Log.d("Loki", "Failed to parse snode from: ${rawSnode?.prettifiedDescription()}.") null diff --git a/libsession/src/main/java/org/session/libsession/utilities/TextSecurePreferences.kt b/libsession/src/main/java/org/session/libsession/utilities/TextSecurePreferences.kt index 9277f01172..3d75566c1c 100644 --- a/libsession/src/main/java/org/session/libsession/utilities/TextSecurePreferences.kt +++ b/libsession/src/main/java/org/session/libsession/utilities/TextSecurePreferences.kt @@ -138,6 +138,8 @@ class TextSecurePreferences @Inject constructor( val HAS_RECEIVED_LEGACY_CONFIG = Pref("has_received_legacy_config", false) + val PATCH_SNODE_VERSION_2024_07_23 = Pref("libsession.patch_snode_version_2024_07_23", false) + const val GREEN_ACCENT = "accent_green" const val BLUE_ACCENT = "accent_blue" const val PURPLE_ACCENT = "accent_purple" @@ -288,6 +290,10 @@ class TextSecurePreferences @Inject constructor( fun hasSelectedAccentColor() = has(SELECTED_ACCENT_COLOR) fun getSelectedAccentColor(): String? = sharedPreferences[SELECTED_ACCENT_COLOR] + var hasAppliedPatchSnodeVersion: Boolean + get() = sharedPreferences[PATCH_SNODE_VERSION_2024_07_23] + set(value) = set(PATCH_SNODE_VERSION_2024_07_23, value) + @StyleRes fun getAccentColorStyle(): Int? = when (getSelectedAccentColor()) { GREEN_ACCENT -> R.style.PrimaryGreen diff --git a/libsession/src/main/java/org/session/libsession/utilities/Util.kt b/libsession/src/main/java/org/session/libsession/utilities/Util.kt index d9592656b0..5f076ec286 100644 --- a/libsession/src/main/java/org/session/libsession/utilities/Util.kt +++ b/libsession/src/main/java/org/session/libsession/utilities/Util.kt @@ -367,6 +367,34 @@ object Util { val digitGroups = (Math.log10(sizeBytes.toDouble()) / Math.log10(1024.0)).toInt() return DecimalFormat("#,##0.#").format(sizeBytes / Math.pow(1024.0, digitGroups.toDouble())) + " " + units[digitGroups] } + + /** + * Compares two version strings (for example "1.8.0") + * + * @param version1 the first version string to compare. + * @param version2 the second version string to compare. + * @return an integer indicating the result of the comparison: + * - 0 if the versions are equal + * - a positive number if version1 is greater than version2 + * - a negative number if version1 is less than version2 + */ + @JvmStatic + fun compareVersions(version1: String, version2: String): Int { + val parts1 = version1.split(".").map { it.toIntOrNull() ?: 0 } + val parts2 = version2.split(".").map { it.toIntOrNull() ?: 0 } + + val maxLength = maxOf(parts1.size, parts2.size) + val paddedParts1 = parts1 + List(maxLength - parts1.size) { 0 } + val paddedParts2 = parts2 + List(maxLength - parts2.size) { 0 } + + for (i in 0 until maxLength) { + val compare = paddedParts1[i].compareTo(paddedParts2[i]) + if (compare != 0) { + return compare + } + } + return 0 + } } fun T.runIf(condition: Boolean, block: T.() -> R): R where T: R = if (condition) block() else this diff --git a/libsignal/src/main/java/org/session/libsignal/database/LokiAPIDatabaseProtocol.kt b/libsignal/src/main/java/org/session/libsignal/database/LokiAPIDatabaseProtocol.kt index 37c00a037d..d7458ff651 100644 --- a/libsignal/src/main/java/org/session/libsignal/database/LokiAPIDatabaseProtocol.kt +++ b/libsignal/src/main/java/org/session/libsignal/database/LokiAPIDatabaseProtocol.kt @@ -10,6 +10,7 @@ interface LokiAPIDatabaseProtocol { fun getSnodePool(): Set fun setSnodePool(newValue: Set) fun getOnionRequestPaths(): List> + fun clearSnodePool() fun clearOnionRequestPaths() fun setOnionRequestPaths(newValue: List>) fun getSwarm(publicKey: String): Set? diff --git a/libsignal/src/main/java/org/session/libsignal/utilities/HTTP.kt b/libsignal/src/main/java/org/session/libsignal/utilities/HTTP.kt index 0c1b2f8317..fd4a3f3702 100644 --- a/libsignal/src/main/java/org/session/libsignal/utilities/HTTP.kt +++ b/libsignal/src/main/java/org/session/libsignal/utilities/HTTP.kt @@ -115,18 +115,26 @@ object HTTP { } Verb.DELETE -> request.delete() } - lateinit var response: Response - try { - val connection: OkHttpClient = if (timeout != HTTP.timeout) { // Custom timeout - if (useSeedNodeConnection) { - throw IllegalStateException("Setting a custom timeout is only allowed for requests to snodes.") + return try { + when { + // Custom timeout + timeout != HTTP.timeout -> { + if (useSeedNodeConnection) { + throw IllegalStateException("Setting a custom timeout is only allowed for requests to snodes.") + } + getDefaultConnection(timeout) + } + useSeedNodeConnection -> seedNodeConnection + else -> defaultConnection + }.newCall(request.build()).execute().use { response -> + when (val statusCode = response.code) { + 200 -> response.body!!.bytes() + else -> { + Log.d("Loki", "${verb.rawValue} request to $url failed with status code: $statusCode.") + throw HTTPRequestFailedException(statusCode, null) + } } - getDefaultConnection(timeout) - } else { - if (useSeedNodeConnection) seedNodeConnection else defaultConnection } - - response = connection.newCall(request.build()).execute() } catch (exception: Exception) { Log.d("Loki", "${verb.rawValue} request to $url failed due to error: ${exception.localizedMessage}.") @@ -135,14 +143,5 @@ object HTTP { // Override the actual error so that we can correctly catch failed requests in OnionRequestAPI throw HTTPRequestFailedException(0, null, "HTTP request failed due to: ${exception.message}") } - return when (val statusCode = response.code) { - 200 -> { - response.body!!.bytes() - } - else -> { - Log.d("Loki", "${verb.rawValue} request to $url failed with status code: $statusCode.") - throw HTTPRequestFailedException(statusCode, null) - } - } } } diff --git a/libsignal/src/main/java/org/session/libsignal/utilities/Snode.kt b/libsignal/src/main/java/org/session/libsignal/utilities/Snode.kt index 28f8aeb03b..f6b11754ad 100644 --- a/libsignal/src/main/java/org/session/libsignal/utilities/Snode.kt +++ b/libsignal/src/main/java/org/session/libsignal/utilities/Snode.kt @@ -1,6 +1,6 @@ package org.session.libsignal.utilities -class Snode(val address: String, val port: Int, val publicKeySet: KeySet?) { +class Snode(val address: String, val port: Int, val publicKeySet: KeySet?, val version: String) { val ip: String get() = address.removePrefix("https://") public enum class Method(val rawValue: String) {