Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ object EditorConfigurationBuilder {
setContent(settings.getSetting<String>("postContent") ?: "")
setPostId(postId)
setPostType(settings.getSetting<String>("postType"))
setStatus(settings.getSetting<String>("status"))

// Site settings
setSiteURL(siteURL)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2955,6 +2955,10 @@ class GutenbergKitActivity : BaseAppCompatActivity(), EditorImageSettingsListene
Handler(Looper.getMainLooper()).post { invalidateOptionsMenu() }
}

override fun getPersistedTitle(): String = editPostRepository.title

override fun getPersistedContent(): String = editPostRepository.content

// FluxC events
@Suppress("unused", "CyclomaticComplexMethod")
@Subscribe(threadMode = ThreadMode.MAIN)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,17 @@ object GutenbergKitSettingsBuilder {
val remotePostId: Long?,
val isPage: Boolean,
val title: String?,
val content: String?
val content: String?,
val status: String?
) {
companion object {
fun fromPostModel(postModel: PostImmutableModel?): PostConfig {
return PostConfig(
remotePostId = postModel?.remotePostId,
isPage = postModel?.isPage ?: false,
title = postModel?.title,
content = postModel?.content
content = postModel?.content,
status = postModel?.status
)
}
}
Expand Down Expand Up @@ -127,6 +129,7 @@ object GutenbergKitSettingsBuilder {
return mutableMapOf(
"postId" to postConfig.remotePostId?.toInt(),
"postType" to if (postConfig.isPage) "page" else "post",
"status" to postConfig.status,
"postTitle" to postConfig.title,
"postContent" to postConfig.content,
"siteURL" to siteConfig.url,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ class GutenbergKitWarmupHelper @Inject constructor(
remotePostId = null,
isPage = false,
title = "",
content = ""
content = "",
status = "draft"
)

val appConfig = GutenbergKitSettingsBuilder.AppConfig(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,16 @@ class GutenbergKitEditorFragment : GutenbergKitEditorFragmentBase() {
modalDialogStateListener?.let(gutenbergView::setModalDialogStateListener)
networkRequestListener?.let(gutenbergView::setNetworkRequestListener)

// Set up content provider for WebView refresh recovery
gutenbergView.setLatestContentProvider(object : GutenbergView.LatestContentProvider {
override fun getLatestContent(): GutenbergView.LatestContent {
return GutenbergView.LatestContent(
mEditorFragmentListener.persistedTitle,
mEditorFragmentListener.persistedContent
)
}
})

// Set up autocomplete listener for user mentions and cross-post suggestions
gutenbergView.setAutocompleterTriggeredListener(object : GutenbergView.AutocompleterTriggeredListener {
override fun onAutocompleterTriggered(type: String) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,5 +151,17 @@ public interface EditorFragmentListener extends DialogVisibilityProvider {
void onOpenMediaLibraryRequested(org.wordpress.gutenberg.GutenbergView.OpenMediaLibraryConfig config);
void onModalDialogOpened(String dialogType);
void onModalDialogClosed(String dialogType);

/**
* Returns the persisted post title for content recovery after WebView refresh.
* @return The most recently persisted title from autosave.
*/
String getPersistedTitle();

/**
* Returns the persisted post content for content recovery after WebView refresh.
* @return The most recently persisted content from autosave.
*/
String getPersistedContent();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,8 @@ class GutenbergKitSettingsBuilderTest {
remotePostId = 456L,
isPage = false,
title = "Test Post",
content = "Test Content"
content = "Test Content",
status = "publish"
)

val settings = GutenbergKitSettingsBuilder.buildSettings(
Expand Down Expand Up @@ -461,7 +462,8 @@ class GutenbergKitSettingsBuilderTest {
remotePostId = 100L,
isPage = true,
title = "Test Page",
content = "Page Content"
content = "Page Content",
status = "draft"
)

val settings = GutenbergKitSettingsBuilder.buildSettings(
Expand Down Expand Up @@ -579,7 +581,8 @@ class GutenbergKitSettingsBuilderTest {
remotePostId = null,
isPage = false,
title = null,
content = null
content = null,
status = null
)

val settings = GutenbergKitSettingsBuilder.buildSettings(
Expand All @@ -594,9 +597,30 @@ class GutenbergKitSettingsBuilderTest {
assertThat(settings["postId"]).isNull()
assertThat(settings["postTitle"]).isNull()
assertThat(settings["postContent"]).isNull()
assertThat(settings["status"]).isNull()
assertThat(settings["postType"]).isEqualTo("post") // Still defaults to post
}

@Test
fun `post status is included in settings`() {
val testCases = listOf("draft", "publish", "pending", "private", "future", "trash")

testCases.forEach { status ->
val postConfig = createPostConfig(status = status)

val settings = GutenbergKitSettingsBuilder.buildSettings(
siteConfig = createSiteConfig(),
postConfig = postConfig,
appConfig = createAppConfig(),
featureConfig = createFeatureConfig()
)

assertThat(settings["status"])
.withFailMessage("Expected status=$status in settings")
.isEqualTo(status)
}
}

// ===== Helper Methods =====

private fun createFeatureConfig(
Expand Down Expand Up @@ -651,11 +675,13 @@ class GutenbergKitSettingsBuilderTest {
remotePostId: Long? = 1L,
isPage: Boolean = false,
title: String? = "Test",
content: String? = "Content"
content: String? = "Content",
status: String? = "draft"
) = GutenbergKitSettingsBuilder.PostConfig(
remotePostId = remotePostId,
isPage = isPage,
title = title,
content = content
content = content,
status = status
)
}
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ google-play-services-auth = '20.4.1'
google-services = '4.4.4'
gravatar = '2.5.0'
greenrobot-eventbus = '3.3.1'
gutenberg-kit = 'v0.11.1'
gutenberg-kit = '283-3110b008df0edceac04a1c6f18724476ce67b3ce'
gutenberg-mobile = 'v1.121.0'
indexos-media-for-mobile = '43a9026f0973a2f0a74fa813132f6a16f7499c3a'
jackson-databind = '2.12.7.1'
Expand Down
Loading