Skip to content
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 @@ -916,6 +916,7 @@ class GutenbergView : FrameLayout {
val dialog = BlockPickerDialog(
context = context,
payload = payload,
showMediaStrip = configuration.enableInserterMediaStrip,
onBlockSelected = { block -> insertBlock(block.id) },
)
dialog.setOnDismissListener {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ private const val DISABLED_ALPHA = 0.5f
internal class BlockPickerDialog(
context: Context,
private val payload: BlockInserterPayload,
private val showMediaStrip: Boolean,
private val onBlockSelected: (BlockType) -> Unit,
) : BottomSheetDialog(context) {

Expand All @@ -200,6 +201,7 @@ internal class BlockPickerDialog(
setContent {
BlockPickerSheet(
payload = payload,
showMediaStrip = showMediaStrip,
onBlockSelected = { block ->
onBlockSelected(block)
dismiss()
Expand Down Expand Up @@ -229,6 +231,7 @@ internal class BlockPickerDialog(
@Composable
private fun BlockPickerSheet(
payload: BlockInserterPayload,
showMediaStrip: Boolean,
onBlockSelected: (BlockType) -> Unit,
onClose: () -> Unit,
) {
Expand Down Expand Up @@ -257,6 +260,7 @@ private fun BlockPickerSheet(
onQueryChange = { query = it },
debouncedQuery = debounced,
blocks = filtered,
showMediaStrip = showMediaStrip,
onBlockSelected = onBlockSelected,
onClose = onClose,
surface = colorScheme.surfaceContainerLow,
Expand All @@ -273,6 +277,7 @@ private fun SheetContent(
onQueryChange: (String) -> Unit,
debouncedQuery: String,
blocks: List<BlockType>,
showMediaStrip: Boolean,
onBlockSelected: (BlockType) -> Unit,
onClose: () -> Unit,
surface: ComposeColor,
Expand All @@ -291,7 +296,9 @@ private fun SheetContent(
) {
DragHandle()
Header(onClose = onClose)
MediaStrip()
if (showMediaStrip) {
MediaStrip()
}
CategoryTabs(selected = selectedTab, onSelect = onSelectTab)
SearchField(query = query, onQueryChange = onQueryChange)
BlockGridContent(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,14 @@ data class EditorConfiguration(
* showing the built-in Gutenberg inserter. Defaults to false so existing
* consumers keep the web-based inserter until they opt in.
*/
val enableNativeBlockInserter: Boolean = false
val enableNativeBlockInserter: Boolean = false,
/**
* When true, the native block inserter sheet shows a Photos + Camera media
* strip above the category tabs. Defaults to false because the result
* callbacks are still inert pending the media hand-off to the JS editor —
* consumers should keep this off until that work lands.
*/
val enableInserterMediaStrip: Boolean = false
): Parcelable {

/**
Expand Down Expand Up @@ -82,6 +89,7 @@ data class EditorConfiguration(
private var enableNetworkLogging: Boolean = false
private var enableOfflineMode: Boolean = false
private var enableNativeBlockInserter: Boolean = false
private var enableInserterMediaStrip: Boolean = false

fun setTitle(title: String) = apply { this.title = title }
fun setContent(content: String) = apply { this.content = content }
Expand Down Expand Up @@ -137,6 +145,9 @@ data class EditorConfiguration(
fun setEnableNativeBlockInserter(enabled: Boolean) = apply {
this.enableNativeBlockInserter = enabled
}
fun setEnableInserterMediaStrip(enabled: Boolean) = apply {
this.enableInserterMediaStrip = enabled
}

fun build(): EditorConfiguration = EditorConfiguration(
title = title,
Expand All @@ -160,7 +171,8 @@ data class EditorConfiguration(
editorAssetsEndpoint = editorAssetsEndpoint,
enableNetworkLogging = enableNetworkLogging,
enableOfflineMode = enableOfflineMode,
enableNativeBlockInserter = enableNativeBlockInserter
enableNativeBlockInserter = enableNativeBlockInserter,
enableInserterMediaStrip = enableInserterMediaStrip
)
}

Expand Down Expand Up @@ -189,6 +201,7 @@ data class EditorConfiguration(
.setEnableNetworkLogging(enableNetworkLogging)
.setEnableOfflineMode(enableOfflineMode)
.setEnableNativeBlockInserter(enableNativeBlockInserter)
.setEnableInserterMediaStrip(enableInserterMediaStrip)

override fun equals(other: Any?): Boolean {
if (this === other) return true
Expand Down Expand Up @@ -218,6 +231,7 @@ data class EditorConfiguration(
if (enableNetworkLogging != other.enableNetworkLogging) return false
if (enableOfflineMode != other.enableOfflineMode) return false
if (enableNativeBlockInserter != other.enableNativeBlockInserter) return false
if (enableInserterMediaStrip != other.enableInserterMediaStrip) return false
if (siteId != other.siteId) return false

return true
Expand Down Expand Up @@ -246,6 +260,7 @@ data class EditorConfiguration(
result = 31 * result + enableNetworkLogging.hashCode()
result = 31 * result + enableOfflineMode.hashCode()
result = 31 * result + enableNativeBlockInserter.hashCode()
result = 31 * result + enableInserterMediaStrip.hashCode()
result = 31 * result + siteId.hashCode()
return result
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class EditorConfigurationBuilderTest {
assertFalse(config.enableNetworkLogging)
assertFalse(config.enableOfflineMode)
assertFalse(config.enableNativeBlockInserter)
assertFalse(config.enableInserterMediaStrip)
}

// MARK: - Individual Setter Tests
Expand Down Expand Up @@ -304,6 +305,15 @@ class EditorConfigurationBuilderTest {
assertTrue(config.enableNativeBlockInserter)
}

@Test
fun `setEnableInserterMediaStrip updates enableInserterMediaStrip`() {
val config = builder()
.setEnableInserterMediaStrip(true)
.build()

assertTrue(config.enableInserterMediaStrip)
}

// MARK: - Method Chaining Tests

@Test
Expand Down Expand Up @@ -366,12 +376,14 @@ class EditorConfigurationBuilderTest {
.setEnableNetworkLogging(true)
.setEnableOfflineMode(true)
.setEnableNativeBlockInserter(true)
.setEnableInserterMediaStrip(true)
.build()

val rebuilt = original.toBuilder().build()

assertEquals(original, rebuilt)
assertTrue(rebuilt.enableNativeBlockInserter)
assertTrue(rebuilt.enableInserterMediaStrip)
}

@Test
Expand Down Expand Up @@ -853,6 +865,20 @@ class EditorConfigurationTest {
assertNotEquals(config1.hashCode(), config2.hashCode())
}

@Test
fun `Configurations with different enableInserterMediaStrip are not equal`() {
val config1 = builder()
.setEnableInserterMediaStrip(true)
.build()

val config2 = builder()
.setEnableInserterMediaStrip(false)
.build()

assertNotEquals(config1, config2)
assertNotEquals(config1.hashCode(), config2.hashCode())
}

@Test
fun `Configurations with different siteId are not equal`() {
// siteId is derived from siteURL, so different URLs with different hosts produce different siteIds
Expand Down Expand Up @@ -948,6 +974,7 @@ class EditorConfigurationTest {
.setEnableNetworkLogging(true)
.setEnableOfflineMode(false)
.setEnableNativeBlockInserter(true)
.setEnableInserterMediaStrip(true)
.build()

assertEquals("Test Title", config.title)
Expand All @@ -972,5 +999,6 @@ class EditorConfigurationTest {
assertTrue(config.enableNetworkLogging)
assertFalse(config.enableOfflineMode)
assertTrue(config.enableNativeBlockInserter)
assertTrue(config.enableInserterMediaStrip)
}
}
4 changes: 2 additions & 2 deletions android/app/detekt-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
<ID>LongMethod:MainActivity.kt$@OptIn(ExperimentalMaterial3Api::class) @Composable fun MainScreen( configurations: List&lt;ConfigurationItem&gt;, onConfigurationClick: (ConfigurationItem) -&gt; Unit, onConfigurationLongClick: (ConfigurationItem) -&gt; Boolean, onAddConfiguration: (String) -&gt; Unit, onDeleteConfiguration: (ConfigurationItem) -&gt; Unit, onMediaProxyServer: () -&gt; Unit = {}, isDiscoveringSite: Boolean = false, onDismissDiscovering: () -&gt; Unit = {}, isLoadingCapabilities: Boolean = false, authError: String? = null, onDismissAuthError: () -&gt; Unit = {} )</ID>
<ID>LongMethod:MediaProxyServerActivity.kt$@OptIn(ExperimentalMaterial3Api::class) @Composable fun MediaProxyServerScreen(onBack: () -&gt; Unit)</ID>
<ID>LongMethod:PostsListActivity.kt$@OptIn(ExperimentalMaterial3Api::class) @Composable fun PostsListScreen( viewModel: PostsListViewModel, onClose: () -&gt; Unit, onPostSelected: (AnyPostWithEditContext) -&gt; Unit )</ID>
<ID>LongMethod:SitePreparationActivity.kt$@Composable private fun FeatureConfigurationCard( enableNativeInserter: Boolean, onEnableNativeInserterChange: (Boolean) -&gt; Unit, enableNetworkLogging: Boolean, onEnableNetworkLoggingChange: (Boolean) -&gt; Unit, postTypes: List&lt;PostTypeDetails&gt;, selectedPostType: PostTypeDetails?, onPostTypeChange: (PostTypeDetails) -&gt; Unit, showBrowseButton: Boolean = false, onBrowsePosts: () -&gt; Unit = {} )</ID>
<ID>LongMethod:SitePreparationActivity.kt$@Composable private fun FeatureConfigurationCard( enableNativeInserter: Boolean, onEnableNativeInserterChange: (Boolean) -&gt; Unit, enableInserterMediaStrip: Boolean, onEnableInserterMediaStripChange: (Boolean) -&gt; Unit, enableNetworkLogging: Boolean, onEnableNetworkLoggingChange: (Boolean) -&gt; Unit, postTypes: List&lt;PostTypeDetails&gt;, selectedPostType: PostTypeDetails?, onPostTypeChange: (PostTypeDetails) -&gt; Unit, showBrowseButton: Boolean = false, onBrowsePosts: () -&gt; Unit = {} )</ID>
<ID>LongParameterList:MainActivity.kt$( configurations: List&lt;ConfigurationItem&gt;, onConfigurationClick: (ConfigurationItem) -&gt; Unit, onConfigurationLongClick: (ConfigurationItem) -&gt; Boolean, onAddConfiguration: (String) -&gt; Unit, onDeleteConfiguration: (ConfigurationItem) -&gt; Unit, onMediaProxyServer: () -&gt; Unit = {}, isDiscoveringSite: Boolean = false, onDismissDiscovering: () -&gt; Unit = {}, isLoadingCapabilities: Boolean = false, authError: String? = null, onDismissAuthError: () -&gt; Unit = {} )</ID>
<ID>LongParameterList:SitePreparationActivity.kt$( enableNativeInserter: Boolean, onEnableNativeInserterChange: (Boolean) -&gt; Unit, enableNetworkLogging: Boolean, onEnableNetworkLoggingChange: (Boolean) -&gt; Unit, postTypes: List&lt;PostTypeDetails&gt;, selectedPostType: PostTypeDetails?, onPostTypeChange: (PostTypeDetails) -&gt; Unit, showBrowseButton: Boolean = false, onBrowsePosts: () -&gt; Unit = {} )</ID>
<ID>LongParameterList:SitePreparationActivity.kt$( enableNativeInserter: Boolean, onEnableNativeInserterChange: (Boolean) -&gt; Unit, enableInserterMediaStrip: Boolean, onEnableInserterMediaStripChange: (Boolean) -&gt; Unit, enableNetworkLogging: Boolean, onEnableNetworkLoggingChange: (Boolean) -&gt; Unit, postTypes: List&lt;PostTypeDetails&gt;, selectedPostType: PostTypeDetails?, onPostTypeChange: (PostTypeDetails) -&gt; Unit, showBrowseButton: Boolean = false, onBrowsePosts: () -&gt; Unit = {} )</ID>
<ID>MaxLineLength:MediaProxyServerActivity.kt$Text("Size", fontFamily = FontFamily.Monospace, style = MaterialTheme.typography.labelSmall, color = MaterialTheme.colorScheme.onSurfaceVariant, modifier = Modifier.weight(1f))</ID>
<ID>MaxLineLength:MediaProxyServerActivity.kt$Text("Throughput", fontFamily = FontFamily.Monospace, style = MaterialTheme.typography.labelSmall, color = MaterialTheme.colorScheme.onSurfaceVariant, modifier = Modifier.weight(1f))</ID>
<ID>MaxLineLength:MediaProxyServerActivity.kt$Text("Time", fontFamily = FontFamily.Monospace, style = MaterialTheme.typography.labelSmall, color = MaterialTheme.colorScheme.onSurfaceVariant, modifier = Modifier.weight(1f))</ID>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,8 @@ private fun LoadedView(
FeatureConfigurationCard(
enableNativeInserter = uiState.enableNativeInserter,
onEnableNativeInserterChange = viewModel::setEnableNativeInserter,
enableInserterMediaStrip = uiState.enableInserterMediaStrip,
onEnableInserterMediaStripChange = viewModel::setEnableInserterMediaStrip,
enableNetworkLogging = uiState.enableNetworkLogging,
onEnableNetworkLoggingChange = viewModel::setEnableNetworkLogging,
postTypes = uiState.postTypes,
Expand Down Expand Up @@ -383,6 +385,8 @@ private fun DependenciesStatusCard(hasDependencies: Boolean) {
private fun FeatureConfigurationCard(
enableNativeInserter: Boolean,
onEnableNativeInserterChange: (Boolean) -> Unit,
enableInserterMediaStrip: Boolean,
onEnableInserterMediaStripChange: (Boolean) -> Unit,
enableNetworkLogging: Boolean,
onEnableNetworkLoggingChange: (Boolean) -> Unit,
postTypes: List<PostTypeDetails>,
Expand Down Expand Up @@ -414,6 +418,22 @@ private fun FeatureConfigurationCard(

HorizontalDivider(modifier = Modifier.padding(vertical = 8.dp))

// Enable Inserter Media Strip Toggle
Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.CenterVertically
) {
Text("Enable Inserter Media Strip")
Switch(
checked = enableInserterMediaStrip,
onCheckedChange = onEnableInserterMediaStripChange,
enabled = enableNativeInserter
)
}

HorizontalDivider(modifier = Modifier.padding(vertical = 8.dp))

// Enable Network Logging Toggle
Row(
modifier = Modifier.fillMaxWidth(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import uniffi.wp_api.PostType as WpPostType

data class SitePreparationUiState(
val enableNativeInserter: Boolean = false,
val enableInserterMediaStrip: Boolean = false,
val enableNetworkLogging: Boolean = false,
/** All viewable post types fetched from the site, or empty while loading. */
val postTypes: List<PostTypeDetails> = emptyList(),
Expand Down Expand Up @@ -85,6 +86,10 @@ class SitePreparationViewModel(
_uiState.update { it.copy(enableNativeInserter = enabled) }
}

fun setEnableInserterMediaStrip(enabled: Boolean) {
_uiState.update { it.copy(enableInserterMediaStrip = enabled) }
}

fun setEnableNetworkLogging(enabled: Boolean) {
_uiState.update { it.copy(enableNetworkLogging = enabled) }
}
Expand Down Expand Up @@ -337,6 +342,7 @@ class SitePreparationViewModel(
return baseConfig.toBuilder()
.setEnableNetworkLogging(_uiState.value.enableNetworkLogging)
.setEnableNativeBlockInserter(_uiState.value.enableNativeInserter)
.setEnableInserterMediaStrip(_uiState.value.enableInserterMediaStrip)
.setPostType(selectedPostType)
.build()
}
Expand Down
Loading