Enable Media Preview to respond to media changes.

This commit is contained in:
Cody Henthorne
2020-07-09 12:19:58 -04:00
committed by Greyson Parrelli
parent 1fe38f5ed1
commit 3c069fb588
8 changed files with 139 additions and 19 deletions

View File

@@ -309,6 +309,23 @@ public class AttachmentDatabase extends Database {
}
}
public boolean hasAttachment(@NonNull AttachmentId id) {
SQLiteDatabase database = databaseHelper.getReadableDatabase();
try (Cursor cursor = database.query(TABLE_NAME,
new String[]{ROW_ID, UNIQUE_ID},
PART_ID_WHERE,
id.toStrings(),
null,
null,
null)) {
if (cursor != null && cursor.getCount() > 0) {
return true;
}
}
return false;
}
public boolean hasAttachmentFilesForMessage(long mmsId) {
String selection = MMS_ID + " = ? AND (" + DATA + " NOT NULL OR " + TRANSFER_STATE + " != ?)";
String[] args = new String[] { String.valueOf(mmsId), String.valueOf(TRANSFER_PROGRESS_DONE) };

View File

@@ -67,6 +67,10 @@ public abstract class Database {
cursor.setNotificationUri(context.getContentResolver(), DatabaseContentProviders.Conversation.getUriForThread(threadId));
}
protected void setNotifyConversationListeners(Cursor cursor) {
cursor.setNotificationUri(context.getContentResolver(), DatabaseContentProviders.Conversation.getUriForAllThreads());
}
protected void setNotifyVerboseConversationListeners(Cursor cursor, long threadId) {
cursor.setNotificationUri(context.getContentResolver(), DatabaseContentProviders.Conversation.getVerboseUriForThread(threadId));
}

View File

@@ -27,6 +27,10 @@ public class DatabaseContentProviders {
public static Uri getVerboseUriForThread(long threadId) {
return Uri.parse(CONTENT_URI_STRING + "verbose/" + threadId);
}
public static Uri getUriForAllThreads() {
return Uri.parse(CONTENT_URI_STRING);
}
}
public static class Attachment extends NoopContentProvider {

View File

@@ -89,11 +89,19 @@ public class MediaDatabase extends Database {
}
public @NonNull Cursor getGalleryMediaForThread(long threadId, @NonNull Sorting sorting) {
return getGalleryMediaForThread(threadId, sorting, false);
}
public @NonNull Cursor getGalleryMediaForThread(long threadId, @NonNull Sorting sorting, boolean listenToAllThreads) {
SQLiteDatabase database = databaseHelper.getReadableDatabase();
String query = sorting.applyToQuery(applyEqualityOperator(threadId, GALLERY_MEDIA_QUERY));
String[] args = {threadId + ""};
Cursor cursor = database.rawQuery(query, args);
setNotifyConversationListeners(cursor, threadId);
if (listenToAllThreads) {
setNotifyConversationListeners(cursor);
} else {
setNotifyConversationListeners(cursor, threadId);
}
return cursor;
}

View File

@@ -11,6 +11,7 @@ import androidx.core.util.Pair;
import org.thoughtcrime.securesms.attachments.AttachmentId;
import org.thoughtcrime.securesms.database.AttachmentDatabase;
import org.thoughtcrime.securesms.database.DatabaseFactory;
import org.thoughtcrime.securesms.database.MediaDatabase;
import org.thoughtcrime.securesms.database.MediaDatabase.Sorting;
import org.thoughtcrime.securesms.mms.PartAuthority;
import org.thoughtcrime.securesms.util.AsyncLoader;
@@ -35,7 +36,7 @@ public final class PagingMediaLoader extends AsyncLoader<Pair<Cursor, Integer>>
@Override
public @Nullable Pair<Cursor, Integer> loadInBackground() {
Cursor cursor = DatabaseFactory.getMediaDatabase(getContext()).getGalleryMediaForThread(threadId, sorting);
Cursor cursor = DatabaseFactory.getMediaDatabase(getContext()).getGalleryMediaForThread(threadId, sorting, threadId == MediaDatabase.ALL_THREADS);
while (cursor.moveToNext()) {
AttachmentId attachmentId = new AttachmentId(cursor.getLong(cursor.getColumnIndexOrThrow(AttachmentDatabase.ROW_ID)), cursor.getLong(cursor.getColumnIndexOrThrow(AttachmentDatabase.UNIQUE_ID)));