Observe link preview changes

This commit is contained in:
Niels Andriesse
2021-06-24 15:46:36 +10:00
parent 11c2983f66
commit c4bac842dd
3 changed files with 40 additions and 21 deletions

View File

@@ -95,7 +95,7 @@ public class LinkPreviewRepository implements InjectableType {
private @NonNull RequestController fetchMetadata(@NonNull String url, Callback<Metadata> callback) {
Call call = client.newCall(new Request.Builder().url(url).removeHeader("User-Agent").addHeader("User-Agent",
"WhatsApp").cacheControl(NO_CACHE).build());
"WhatsApp").cacheControl(NO_CACHE).build());
call.enqueue(new okhttp3.Callback() {
@Override
@@ -186,18 +186,18 @@ public class LinkPreviewRepository implements InjectableType {
byte[] bytes = baos.toByteArray();
Uri uri = BlobProvider.getInstance().forData(bytes).createForSingleSessionInMemory();
return Optional.of(new UriAttachment(uri,
uri,
contentType,
AttachmentTransferProgress.TRANSFER_PROGRESS_STARTED,
bytes.length,
bitmap.getWidth(),
bitmap.getHeight(),
null,
null,
false,
false,
null));
return Optional.of(new UriAttachment(uri,
uri,
contentType,
AttachmentTransferProgress.TRANSFER_PROGRESS_STARTED,
bytes.length,
bitmap.getWidth(),
bitmap.getHeight(),
null,
null,
false,
false,
null));
}

View File

@@ -74,7 +74,7 @@ public class LinkPreviewViewModel extends ViewModel {
activeRequest = null;
}
if (!link.isPresent() || !isCursorPositionValid(text, link.get(), cursorStart, cursorEnd)) {
if (!link.isPresent()) {
activeUrl = null;
linkPreviewState.setValue(LinkPreviewState.forEmpty());
return;