Skip to content

Commit

Permalink
Merge branch 'trunk' into andy/tablet-hacks
Browse files Browse the repository at this point in the history
  • Loading branch information
notandyvee committed Jun 7, 2024
2 parents 515b32d + e56dcc8 commit a5347bb
Show file tree
Hide file tree
Showing 22 changed files with 421 additions and 259 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.wordpress.android.ui.media.services;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import org.wordpress.android.fluxc.model.PostModel;
Expand All @@ -14,7 +15,7 @@ public interface MediaUploadReadyListener {
// TODO: We're passing a SiteModel parameter here in order to debug a crash on SaveStoryGutenbergBlockUseCase.
// Once that's done, the parameter should be replaced with a site url String, like it was before.
// See: https://git.io/JqfhK
PostModel replaceMediaFileWithUrlInPost(@Nullable PostModel post, String localMediaId, MediaFile mediaFile,
PostModel replaceMediaFileWithUrlInPost(@Nullable PostModel post, @NonNull String localMediaId, MediaFile mediaFile,
@Nullable SiteModel site);
PostModel markMediaUploadFailedInPost(@Nullable PostModel post, String localMediaId, MediaFile mediaFile);
}
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,8 @@ class PostListEventListener(
@Suppress("unused", "SpreadOperator")
@Subscribe(threadMode = BACKGROUND)
fun onMediaChanged(event: OnMediaChanged) {
featuredMediaChanged(*event.mediaList.map { it.mediaId }.toLongArray())
if (!event.isError) {
featuredMediaChanged(*event.mediaList.map { it.mediaId }.toLongArray())
uploadStatusChanged(*event.mediaList.map { it.localPostId }.toIntArray())
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.wordpress.android.ui.posts

import android.annotation.SuppressLint
import androidx.annotation.VisibleForTesting
import org.wordpress.android.fluxc.Dispatcher
import org.wordpress.android.fluxc.generated.MediaActionBuilder
import org.wordpress.android.fluxc.model.MediaModel
Expand All @@ -22,21 +23,39 @@ class PostListFeaturedImageTracker(private val dispatcher: Dispatcher, private v
https://github.com/wordpress-mobile/WordPress-Android/issues/11487
*/
@SuppressLint("UseSparseArrays")
private val featuredImageMap = HashMap<Long, String>()
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
internal val featuredImageMap = HashMap<Long, String>()

@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
internal val ongoingRequests = HashSet<Long>()

fun getFeaturedImageUrl(site: SiteModel, featuredImageId: Long): String? {
if (featuredImageId == 0L) {
return null
}
featuredImageMap[featuredImageId]?.let { return it }

featuredImageMap[featuredImageId]?.let {
return it
}

// Check if a request for this image is already ongoing
if (ongoingRequests.contains(featuredImageId)) {
// If the request is ongoing, just return. The callback will be invoked upon completion.
return null
}

mediaStore.getSiteMediaWithId(site, featuredImageId)?.let { media ->
// This should be a pretty rare case, but some media seems to be missing url
return if (media.url.isNotBlank()) {
featuredImageMap[featuredImageId] = media.url
media.url
} else null
}

// Media is not in the Store, we need to download it
// Mark the request as ongoing
ongoingRequests.add(featuredImageId)

val mediaToDownload = MediaModel(
site.id,
featuredImageId
Expand All @@ -47,6 +66,9 @@ class PostListFeaturedImageTracker(private val dispatcher: Dispatcher, private v
}

fun invalidateFeaturedMedia(featuredImageIds: List<Long>) {
featuredImageIds.forEach { featuredImageMap.remove(it) }
featuredImageIds.forEach {
featuredImageMap.remove(it)
ongoingRequests.remove(it)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,8 @@ public static boolean shouldShowGutenbergEditor(boolean isNewPost, String postCo
}

public static String replaceMediaFileWithUrlInGutenbergPost(@NonNull String postContent,
String localMediaId, MediaFile mediaFile, String siteUrl) {
@NonNull String localMediaId, MediaFile mediaFile,
String siteUrl) {
if (mediaFile != null && contentContainsGutenbergBlocks(postContent)) {
MediaUploadCompletionProcessor processor = new MediaUploadCompletionProcessor(localMediaId, mediaFile,
siteUrl);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import com.google.gson.JsonObject
import org.jsoup.nodes.Document
import org.wordpress.android.util.helpers.MediaFile

class AudioBlockProcessor(localId: String?, mediaFile: MediaFile?) : BlockProcessor(localId, mediaFile) {
class AudioBlockProcessor(localId: String, mediaFile: MediaFile) : BlockProcessor(localId, mediaFile) {
override fun processBlockContentDocument(document: Document?): Boolean {
val audioElements = document?.select(AUDIO_TAG)

audioElements?.let { elements ->
for (element in elements) {
// replaces the src attribute's local url with the remote counterpart.
element.attr(SRC_ATTRIBUTE, mRemoteUrl)
element.attr(SRC_ATTRIBUTE, remoteUrl)
}
return true
}
Expand All @@ -21,9 +21,9 @@ class AudioBlockProcessor(localId: String?, mediaFile: MediaFile?) : BlockProces
override fun processBlockJsonAttributes(jsonAttributes: JsonObject?): Boolean {
val id = jsonAttributes?.get(ID_ATTRIBUTE)

return if (id != null && !id.isJsonNull && id.asString == mLocalId) {
return if (id != null && !id.isJsonNull && id.asString == localId) {
jsonAttributes.apply {
addIntPropertySafely(this, ID_ATTRIBUTE, mRemoteId)
addIntPropertySafely(this, ID_ATTRIBUTE, remoteId)
}
true
} else {
Expand Down

This file was deleted.

Loading

0 comments on commit a5347bb

Please sign in to comment.