-
Notifications
You must be signed in to change notification settings - Fork 1.4k
refactor: Fetch and cache GutenbergKit editor settings #21791
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
Merged
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
550a588
refactor: Provide editor settings to GutenbergKit
dcalhoun 2727408
refactor: Move onEditorSettingsChanged subscription to EditPostActivity
dcalhoun 14f99cc
style: Automated formatting changes
dcalhoun 0de6ee0
feat: Dispatch editor settings request
dcalhoun 00438a3
refactor: Improve editor settings parsing
dcalhoun a9710cb
refactor: Simplify EditorSettings
dcalhoun 7ae1aa5
refactor: Pass editor settings as JSON string
dcalhoun 37df679
feat: Display activity indicator while fetching editor settings
dcalhoun dd7a59d
feat: Add cache-while-revalidate for editor settings
dcalhoun 2e0a1dc
feat: Persist editor settings in SQLite
dcalhoun 6ea9561
build: Update GutenbergKit ref
dcalhoun 1434de3
style: Address lint errors
dcalhoun acad23b
style: Address lint warnings
dcalhoun d38bf79
fix: Use -1 post ID for new drafts
dcalhoun c6f73b0
Revert "style: Automated formatting changes"
dcalhoun 119bf6c
refactor: Remove unnecessary style configuration
dcalhoun 074a3f6
refactor: Avoid redundant editor starts
dcalhoun c9c358a
build: Update GutenbergKit ref
dcalhoun 948efd9
style: Address lint warning
dcalhoun dd7f3a8
fix: Start editor with default settings on failed editor settings
dcalhoun 9067f91
fix: Emit available cached editor settings on fetch failure
dcalhoun d99dc81
build: Update GutenbergKit ref
dcalhoun File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
libs/editor/src/main/res/layout/fragment_gutenberg_kit_editor.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
| android:id="@+id/gutenberg_kit_container" | ||
| android:layout_height="match_parent" | ||
| android:layout_width="match_parent"> | ||
|
|
||
| <FrameLayout | ||
| android:id="@+id/gutenberg_view_container" | ||
| android:layout_width="match_parent" | ||
| android:layout_height="match_parent" /> | ||
|
|
||
| <ProgressBar | ||
| android:id="@+id/editor_progress" | ||
| style="?android:attr/progressBarStyle" | ||
| android:layout_width="wrap_content" | ||
| android:layout_height="wrap_content" | ||
| android:layout_gravity="center"/> | ||
| </FrameLayout> |
12 changes: 12 additions & 0 deletions
12
libs/fluxc/src/main/java/org/wordpress/android/fluxc/action/EditorSettingsAction.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| package org.wordpress.android.fluxc.action | ||
|
|
||
| import org.wordpress.android.fluxc.annotations.Action | ||
| import org.wordpress.android.fluxc.annotations.ActionEnum | ||
| import org.wordpress.android.fluxc.annotations.action.IAction | ||
| import org.wordpress.android.fluxc.store.EditorSettingsStore.FetchEditorSettingsPayload | ||
|
|
||
| @ActionEnum | ||
| enum class EditorSettingsAction : IAction { | ||
| @Action(payloadType = FetchEditorSettingsPayload::class) | ||
| FETCH_EDITOR_SETTINGS | ||
| } |
10 changes: 10 additions & 0 deletions
10
libs/fluxc/src/main/java/org/wordpress/android/fluxc/action/EditorSettingsActionBuilder.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| package org.wordpress.android.fluxc.action | ||
|
|
||
| import org.wordpress.android.fluxc.annotations.action.Action | ||
| import org.wordpress.android.fluxc.store.EditorSettingsStore.FetchEditorSettingsPayload | ||
|
|
||
| object EditorSettingsActionBuilder { | ||
| fun newFetchEditorSettingsAction(payload: FetchEditorSettingsPayload): Action<FetchEditorSettingsPayload> { | ||
| return Action(EditorSettingsAction.FETCH_EDITOR_SETTINGS, payload) | ||
| } | ||
| } |
17 changes: 17 additions & 0 deletions
17
libs/fluxc/src/main/java/org/wordpress/android/fluxc/model/EditorSettings.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| package org.wordpress.android.fluxc.model | ||
|
|
||
| import com.google.gson.JsonObject | ||
| import org.wordpress.android.fluxc.persistence.EditorSettingsSqlUtils.EditorSettingsBuilder | ||
|
|
||
| class EditorSettings(val rawSettings: JsonObject) { | ||
| fun toJsonString(): String { | ||
| return rawSettings.toString() | ||
| } | ||
|
|
||
| fun toBuilder(site: SiteModel): EditorSettingsBuilder { | ||
| return EditorSettingsBuilder().apply { | ||
| localSiteId = site.id | ||
| rawSettings = this@EditorSettings.rawSettings.toString() | ||
| } | ||
| } | ||
| } |
66 changes: 66 additions & 0 deletions
66
libs/fluxc/src/main/java/org/wordpress/android/fluxc/persistence/EditorSettingsSqlUtils.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| package org.wordpress.android.fluxc.persistence | ||
|
|
||
| import com.google.gson.JsonParser | ||
| import com.wellsql.generated.EditorSettingsTable | ||
| import com.yarolegovich.wellsql.WellSql | ||
| import com.yarolegovich.wellsql.core.Identifiable | ||
| import com.yarolegovich.wellsql.core.annotation.Column | ||
| import com.yarolegovich.wellsql.core.annotation.PrimaryKey | ||
| import com.yarolegovich.wellsql.core.annotation.Table | ||
| import org.wordpress.android.fluxc.model.EditorSettings | ||
| import org.wordpress.android.fluxc.model.SiteModel | ||
|
|
||
| class EditorSettingsSqlUtils { | ||
| fun replaceEditorSettingsForSite(site: SiteModel, editorSettings: EditorSettings?) { | ||
| deleteEditorSettingsForSite(site) | ||
| if (editorSettings == null) return | ||
| makeEditorSettings(site, editorSettings) | ||
| } | ||
|
|
||
| fun getEditorSettingsForSite(site: SiteModel): EditorSettings? { | ||
| return WellSql.select(EditorSettingsBuilder::class.java) | ||
| .limit(1) | ||
| .where() | ||
| .equals(EditorSettingsTable.LOCAL_SITE_ID, site.id) | ||
| .endWhere() | ||
| .asModel | ||
| .firstOrNull() | ||
| ?.toEditorSettings() | ||
| } | ||
|
|
||
| fun deleteEditorSettingsForSite(site: SiteModel) { | ||
| WellSql.delete(EditorSettingsBuilder::class.java) | ||
| .where() | ||
| .equals(EditorSettingsTable.LOCAL_SITE_ID, site.id) | ||
| .endWhere() | ||
| .execute() | ||
| } | ||
|
|
||
| private fun makeEditorSettings(site: SiteModel, editorSettings: EditorSettings) { | ||
| val builder = editorSettings.toBuilder(site) | ||
| WellSql.insert(builder).execute() | ||
| } | ||
|
|
||
| @Table(name = "EditorSettings") | ||
| data class EditorSettingsBuilder(@PrimaryKey @Column private var mId: Int = -1) : Identifiable { | ||
| @Column var localSiteId: Int = -1 | ||
| @JvmName("getLocalSiteId") | ||
| get | ||
| @JvmName("setLocalSiteId") | ||
| set | ||
| @Column var rawSettings: String? = null | ||
|
|
||
| override fun setId(id: Int) { | ||
| this.mId = id | ||
| } | ||
|
|
||
| override fun getId() = mId | ||
|
|
||
| fun toEditorSettings(): EditorSettings? { | ||
| return rawSettings?.let { | ||
| val jsonObject = JsonParser.parseString(it).asJsonObject | ||
| EditorSettings(jsonObject) | ||
| } | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The timing of this content refresh is currently incompatible with/unnecessary for GutenbergKit.