Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Declare gallery v2 field as optional #2740

Merged
merged 3 commits into from
May 29, 2023
Merged
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 @@ -63,7 +63,7 @@ class MockedStack_EditorThemeStoreTest : MockedStack_Base() {
assertNotEmpty(cachedTheme)

// Validate Bundle
val themeBundle = editorTheme!!.themeSupport.toBundle()
val themeBundle = editorTheme!!.themeSupport.toBundle(site)
assertNotEmpty(themeBundle)
}

Expand All @@ -83,7 +83,7 @@ class MockedStack_EditorThemeStoreTest : MockedStack_Base() {
assertEmpty(cachedTheme)

// Validate Bundle
val themeBundle = editorTheme!!.themeSupport.toBundle()
val themeBundle = editorTheme!!.themeSupport.toBundle(site)
assertEmpty(themeBundle)
}

Expand Down Expand Up @@ -135,7 +135,7 @@ class MockedStack_EditorThemeStoreTest : MockedStack_Base() {
assertEmpty(cachedTheme)

// Validate Bundle
val themeBundle = editorTheme!!.themeSupport.toBundle()
val themeBundle = editorTheme!!.themeSupport.toBundle(site)
assertEmpty(themeBundle)
}

Expand All @@ -155,7 +155,7 @@ class MockedStack_EditorThemeStoreTest : MockedStack_Base() {
assertNotEmpty(cachedTheme)

// Validate Bundle
val themeBundle = editorTheme!!.themeSupport.toBundle()
val themeBundle = editorTheme!!.themeSupport.toBundle(site)
assertNotEmpty(themeBundle)
}

Expand All @@ -177,7 +177,7 @@ class MockedStack_EditorThemeStoreTest : MockedStack_Base() {
Assert.assertNotNull(cachedTheme?.themeSupport?.rawStyles)

// Validate Bundle
val themeBundle = editorTheme!!.themeSupport.toBundle()
val themeBundle = editorTheme!!.themeSupport.toBundle(site)
assertEmpty(themeBundle)
val styles = themeBundle.getString("rawStyles")
val features = themeBundle.getString("rawFeatures")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@ import com.google.gson.reflect.TypeToken
import org.wordpress.android.fluxc.persistence.EditorThemeElementType
import org.wordpress.android.fluxc.persistence.EditorThemeSqlUtils.EditorThemeBuilder
import org.wordpress.android.fluxc.persistence.EditorThemeSqlUtils.EditorThemeElementBuilder
import org.wordpress.android.util.VersionUtils
import java.lang.reflect.Type

private const val GALLERY_V2_WP_VERSION = "5.9"

const val MAP_KEY_ELEMENT_DISPLAY_NAME: String = "name"
const val MAP_KEY_ELEMENT_SLUG: String = "slug"
const val MAP_KEY_ELEMENT_COLORS: String = "colors"
Expand Down Expand Up @@ -46,15 +49,15 @@ data class EditorTheme(
version = null
)

fun toBuilder(siteId: Int): EditorThemeBuilder {
fun toBuilder(site: SiteModel): EditorThemeBuilder {
val element = EditorThemeBuilder()
element.localSiteId = siteId
element.localSiteId = site.id
element.stylesheet = stylesheet
element.version = version
element.rawStyles = themeSupport.rawStyles
element.rawFeatures = themeSupport.rawFeatures
element.isBlockBasedTheme = themeSupport.isBlockBasedTheme
element.galleryWithImageBlocks = themeSupport.galleryWithImageBlocks
element.galleryWithImageBlocks = themeSupport.galleryWithImageBlocks ?: site.coreSupportsGalleryV2
element.quoteBlockV2 = themeSupport.quoteBlockV2
element.listBlockV2 = themeSupport.listBlockV2
element.hasBlockTemplates = themeSupport.hasBlockTemplates ?: false
Expand Down Expand Up @@ -94,11 +97,11 @@ data class EditorThemeSupport(
val rawStyles: String?,
val rawFeatures: String?,
val isBlockBasedTheme: Boolean,
val galleryWithImageBlocks: Boolean,
val galleryWithImageBlocks: Boolean?,
val quoteBlockV2: Boolean,
val listBlockV2: Boolean
) {
fun toBundle(): Bundle {
fun toBundle(site: SiteModel): Bundle {
val bundle = Bundle()

colors?.map { it.toBundle() }?.let {
Expand All @@ -118,7 +121,7 @@ data class EditorThemeSupport(
}

bundle.putBoolean(MAP_KEY_IS_BLOCK_BASED_THEME, isBlockBasedTheme)
bundle.putBoolean(MAP_KEY_GALLERY_WITH_IMAGE_BLOCKS, galleryWithImageBlocks)
bundle.putBoolean(MAP_KEY_GALLERY_WITH_IMAGE_BLOCKS, galleryWithImageBlocks ?: site.coreSupportsGalleryV2)
bundle.putBoolean(MAP_KEY_QUOTE_BLOCK_V2, quoteBlockV2)
bundle.putBoolean(MAP_KEY_LIST_BLOCK_V2, listBlockV2)
bundle.putBoolean(MAP_KEY_HAS_BLOCK_TEMPLATES, hasBlockTemplates ?: false)
Expand All @@ -128,7 +131,6 @@ data class EditorThemeSupport(
fun isEditorThemeBlockBased(): Boolean = isBlockBasedTheme || (hasBlockTemplates ?: false)
}


data class EditorThemeElement(
val name: String?,
val slug: String?,
Expand Down Expand Up @@ -182,3 +184,6 @@ class EditorThemeElementListSerializer : JsonDeserializer<List<EditorThemeElemen
}
}
}

private val SiteModel.coreSupportsGalleryV2: Boolean
get() = VersionUtils.checkMinimalVersion(softwareVersion, GALLERY_V2_WP_VERSION)
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class EditorThemeSqlUtils {
}

private fun makeEditorTheme(site: SiteModel, editorTheme: EditorTheme) {
val editorThemeBuilder = editorTheme.toBuilder(site.id)
val editorThemeBuilder = editorTheme.toBuilder(site)
val items = (editorTheme.themeSupport.colors ?: emptyList()) +
(editorTheme.themeSupport.gradients ?: emptyList())

Expand Down