-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Offline Pages : Added Support for unpublished revision to Page List #11228
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
malinajirka
merged 32 commits into
feature/master-pages-offline-support
from
unhandled_autosave
Feb 12, 2020
Merged
Changes from all commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
b0f6d19
started PageListDialogHelper
jd-alexander def1b79
added logic to edit local or auto revision version.
jd-alexander 3dfcfa1
refactored delete dialog implementation
jd-alexander abff27e
added logic to enable auto revision checks
jd-alexander 7087c23
refactored parameter name since type provides enough context.
jd-alexander bc5d7a4
style changes.
jd-alexander 41b5d04
used names for pair and fixed activity launcher function.
jd-alexander c1193eb
dialog now says page instead of post for auto revision
jd-alexander e9c140f
added page title to delete dialog.
jd-alexander dc26429
fixed style errors.
jd-alexander 45cc77d
style fixes.
jd-alexander 09eef06
utilize page that is stored in pageMap to perform edit.
jd-alexander 6ca5d59
changed post to page for more clarity and consistency.
jd-alexander fd53523
Merge branch 'feature/master-pages-offline-support' into issue-11131/…
jd-alexander 42a636a
fixed a minor test issue with viewmodel initialization
jd-alexander 98946e5
fixed formatting issue.
jd-alexander f6cbb9f
refactored naming of click actions.
jd-alexander 28a76e4
added an exception to the else clause of this event; fail fast principle
jd-alexander aa7d8db
removed isPage from function parameter and used the PostModel directly.
jd-alexander d522cd2
added params to UiString & UiHelpers functionality.
jd-alexander d5f27b7
convert to an array that can be passed as a vararg
jd-alexander 8dd300b
Removed unneeded parameter since value is being accessed inside
jd-alexander d276c95
utilize the UIiStringResWithParams functionality for the arguments.
jd-alexander ca2ccdc
throw NullPointerException for appropriate dialog click events.
jd-alexander 155b6dd
added a TODO comment to link to the issue related to refactoring.
jd-alexander b2f073b
Merge branch 'feature/master-pages-offline-support' into issue-11131/…
jd-alexander 65bf483
removed unneeded space.
jd-alexander 9c3dfcb
fixed indentation issue.
jd-alexander ac2129b
added post type to events that are being tracked for the dialogs.
jd-alexander 0ef669e
Fixed spacing issue
jd-alexander 4b912f0
Utilized UiString instead of any for string resource formatting.
jd-alexander 2a6afe5
simplified how exceptions are thrown
jd-alexander 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
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
11 changes: 11 additions & 0 deletions
11
WordPress/src/main/java/org/wordpress/android/viewmodel/pages/PageConflictResolver.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,11 @@ | ||
| package org.wordpress.android.viewmodel.pages | ||
|
|
||
| import org.wordpress.android.fluxc.model.PostModel | ||
| import org.wordpress.android.ui.posts.PostUtils | ||
| import javax.inject.Inject | ||
|
|
||
| class PageConflictResolver @Inject constructor() { | ||
| fun hasUnhandledAutoSave(post: PostModel): Boolean { | ||
| return PostUtils.hasAutoSave(post) | ||
| } | ||
| } |
100 changes: 100 additions & 0 deletions
100
WordPress/src/main/java/org/wordpress/android/viewmodel/pages/PageListDialogHelper.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,100 @@ | ||
| package org.wordpress.android.viewmodel.pages | ||
|
|
||
| import org.wordpress.android.R | ||
| import org.wordpress.android.analytics.AnalyticsTracker.Stat.UNPUBLISHED_REVISION_DIALOG_LOAD_LOCAL_VERSION_CLICKED | ||
| import org.wordpress.android.analytics.AnalyticsTracker.Stat.UNPUBLISHED_REVISION_DIALOG_LOAD_UNPUBLISHED_VERSION_CLICKED | ||
| import org.wordpress.android.analytics.AnalyticsTracker.Stat.UNPUBLISHED_REVISION_DIALOG_SHOWN | ||
| import org.wordpress.android.fluxc.model.LocalOrRemoteId.RemoteId | ||
| import org.wordpress.android.fluxc.model.PostModel | ||
| import org.wordpress.android.ui.posts.PostUtils | ||
| import org.wordpress.android.ui.utils.UiString.UiStringRes | ||
| import org.wordpress.android.ui.utils.UiString.UiStringResWithParams | ||
| import org.wordpress.android.ui.utils.UiString.UiStringText | ||
| import org.wordpress.android.util.analytics.AnalyticsTrackerWrapper | ||
| import org.wordpress.android.viewmodel.helpers.DialogHolder | ||
| import java.lang.NullPointerException | ||
|
|
||
| private const val CONFIRM_ON_AUTOSAVE_REVISION_DIALOG_TAG = "CONFIRM_ON_AUTOSAVE_REVISION_DIALOG_TAG" | ||
| private const val CONFIRM_DELETE_PAGE_DIALOG_TAG = "CONFIRM_DELETE_PAGE_DIALOG_TAG" | ||
| private const val POST_TYPE = "post_type" | ||
|
|
||
| class PageListDialogHelper( | ||
|
malinajirka marked this conversation as resolved.
|
||
| private val showDialog: (DialogHolder) -> Unit, | ||
| private val analyticsTracker: AnalyticsTrackerWrapper | ||
| ) { | ||
| private var pageIdForAutosaveRevisionResolutionDialog: RemoteId? = null | ||
| private var pageIdForDeleteDialog: RemoteId? = null | ||
|
|
||
| fun showAutoSaveRevisionDialog(page: PostModel) { | ||
| analyticsTracker.track(UNPUBLISHED_REVISION_DIALOG_SHOWN, mapOf(POST_TYPE to "page")) | ||
| val dialogHolder = DialogHolder( | ||
| tag = CONFIRM_ON_AUTOSAVE_REVISION_DIALOG_TAG, | ||
| title = UiStringRes(R.string.dialog_confirm_autosave_title), | ||
| message = PostUtils.getCustomStringForAutosaveRevisionDialog(page), | ||
| positiveButton = UiStringRes(R.string.dialog_confirm_autosave_restore_button), | ||
| negativeButton = UiStringRes(R.string.dialog_confirm_autosave_dont_restore_button) | ||
| ) | ||
| pageIdForAutosaveRevisionResolutionDialog = RemoteId(page.remotePostId) | ||
| showDialog.invoke(dialogHolder) | ||
| } | ||
|
|
||
| fun showDeletePageConfirmationDialog(pageId: RemoteId, pageTitle: String) { | ||
| val dialogHolder = DialogHolder( | ||
| tag = CONFIRM_DELETE_PAGE_DIALOG_TAG, | ||
| title = UiStringRes(R.string.delete_page), | ||
| message = UiStringResWithParams( | ||
| R.string.page_delete_dialog_message, | ||
| listOf(UiStringText(pageTitle)) | ||
| ), | ||
| positiveButton = UiStringRes(R.string.delete), | ||
| negativeButton = UiStringRes(R.string.cancel) | ||
| ) | ||
| pageIdForDeleteDialog = pageId | ||
| showDialog.invoke(dialogHolder) | ||
| } | ||
|
|
||
| fun onPositiveClickedForBasicDialog( | ||
| instanceTag: String, | ||
| deletePage: (RemoteId) -> Unit, | ||
| editPage: (RemoteId, LoadAutoSaveRevision) -> Unit | ||
| ) { | ||
| when (instanceTag) { | ||
| CONFIRM_DELETE_PAGE_DIALOG_TAG -> pageIdForDeleteDialog?.let { | ||
| pageIdForDeleteDialog = null | ||
| deletePage(it) | ||
| } ?: throw NullPointerException("pageIdForDeleteDialog shouldn't be null.") | ||
| CONFIRM_ON_AUTOSAVE_REVISION_DIALOG_TAG -> pageIdForAutosaveRevisionResolutionDialog?.let { | ||
| // open the editor with the restored auto save | ||
| pageIdForAutosaveRevisionResolutionDialog = null | ||
| editPage(it, true) | ||
| analyticsTracker.track( | ||
| UNPUBLISHED_REVISION_DIALOG_LOAD_UNPUBLISHED_VERSION_CLICKED, | ||
| mapOf(POST_TYPE to "page") | ||
| ) | ||
| } | ||
|
malinajirka marked this conversation as resolved.
|
||
| ?: throw NullPointerException("pageIdForAutosaveRevisionResolutionDialog shouldn't be null.") | ||
|
|
||
| else -> throw IllegalArgumentException("Dialog's positive button click is not handled: $instanceTag") | ||
| } | ||
| } | ||
|
|
||
| fun onNegativeClickedForBasicDialog( | ||
| instanceTag: String, | ||
| editPage: (RemoteId, LoadAutoSaveRevision) -> Unit | ||
| ) { | ||
| when (instanceTag) { | ||
| CONFIRM_DELETE_PAGE_DIALOG_TAG -> pageIdForDeleteDialog = null | ||
| CONFIRM_ON_AUTOSAVE_REVISION_DIALOG_TAG -> pageIdForAutosaveRevisionResolutionDialog?.let { | ||
| // open the editor with the local page (don't use the auto save version) | ||
| editPage(it, false) | ||
| analyticsTracker.track( | ||
| UNPUBLISHED_REVISION_DIALOG_LOAD_LOCAL_VERSION_CLICKED, | ||
| mapOf(POST_TYPE to "page") | ||
| ) | ||
| } | ||
|
malinajirka marked this conversation as resolved.
|
||
| ?: throw NullPointerException("pageIdForAutosaveRevisionResolutionDialog shouldn't be null.") | ||
|
|
||
| else -> throw IllegalArgumentException("Dialog's negative button click is not handled: $instanceTag") | ||
| } | ||
| } | ||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.