-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Automatically upload local drafts #9774
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
23 commits
Select commit
Hold shift + click to select a range
7e0e43d
Add hooks for when to auto-upload local drafts
shiki f8dd996
Make PostListViewModel inherit from ScopedVM
shiki 023c1ee
Auto upload local drafts in Posts list
shiki b612b2e
LocalDraftUploadStarter: Use FluxC call
shiki b88021d
Remove @Singleton from LocalDraftUploadStarter
shiki 9135289
LocalDraftUploadStarter: Add network check
shiki d6f3de3
Add PostListViewModelTest for swipe to refresh
shiki d2218c9
Convert ConnectionStatus to data class
shiki a2432d2
PostListMainVM: Move connection status to start
shiki 1ae0614
Make PostListMainViewModel useable in unit tests
shiki e8f0a79
Add PostListMainViewModelTest
shiki 5e47049
Rename mocked* methods to create*
shiki b454336
Update FluxC to b6f8aa3
shiki 9e73e5f
Update release notes (12.5)
shiki 514ce10
LocalDraftUploadStarter: Remove unused import
shiki bcff503
LocalDraftUploadStarter: Use retry when uploading
shiki 74b26b0
Update FluxC to 5aad0a2
shiki e26e540
Make PostListEventListener injectable
shiki 56fb755
Merge branch 'issue/9568-connectionstatuslivedata-revamp' into issue/…
shiki f44e29e
Fix PostListMainViewModelTest
shiki fa94f00
LocalDraftUploader: Filter posts already in queue
shiki 5aadbd9
Merge branch 'develop' into issue/9568-upload-local-drafts
shiki 2e106cd
Merge develop into issue/9568-upload-local-drafts
shiki 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| 12.5 | ||
| ----- | ||
| * Fixed local drafts not automatically pushed to the server. | ||
|
|
||
| 12.4 | ||
| ----- | ||
|
|
||
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
41 changes: 41 additions & 0 deletions
41
WordPress/src/main/java/org/wordpress/android/ui/uploads/LocalDraftUploadStarter.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,41 @@ | ||
| package org.wordpress.android.ui.uploads | ||
|
|
||
| import android.content.Context | ||
| import kotlinx.coroutines.CoroutineDispatcher | ||
| import kotlinx.coroutines.CoroutineScope | ||
| import kotlinx.coroutines.launch | ||
| import org.wordpress.android.fluxc.model.SiteModel | ||
| import org.wordpress.android.fluxc.store.PostStore | ||
| import org.wordpress.android.modules.BG_THREAD | ||
| import org.wordpress.android.util.NetworkUtilsWrapper | ||
| import javax.inject.Inject | ||
| import javax.inject.Named | ||
|
|
||
| /** | ||
| * Provides a way to find and upload all local drafts. | ||
| */ | ||
| class LocalDraftUploadStarter @Inject constructor( | ||
| /** | ||
| * The Application context | ||
| */ | ||
| private val context: Context, | ||
| private val postStore: PostStore, | ||
| /** | ||
| * The Coroutine dispatcher used for querying in FluxC. | ||
| */ | ||
| @Named(BG_THREAD) private val bgDispatcher: CoroutineDispatcher, | ||
| private val networkUtilsWrapper: NetworkUtilsWrapper | ||
| ) { | ||
| fun uploadLocalDrafts(scope: CoroutineScope, site: SiteModel) = scope.launch(bgDispatcher) { | ||
| if (!networkUtilsWrapper.isNetworkAvailable()) { | ||
| return@launch | ||
| } | ||
|
|
||
| postStore.getLocalDraftPosts(site) | ||
| .filterNot { UploadService.isPostUploadingOrQueued(it) } | ||
| .forEach { localDraft -> | ||
| val intent = UploadService.getUploadPostServiceIntent(context, localDraft, false, false, true) | ||
| context.startService(intent) | ||
| } | ||
| } | ||
| } |
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
91 changes: 91 additions & 0 deletions
91
WordPress/src/test/java/org/wordpress/android/ui/posts/PostListMainViewModelTest.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,91 @@ | ||
| package org.wordpress.android.ui.posts | ||
|
|
||
| import android.arch.core.executor.testing.InstantTaskExecutorRule | ||
| import android.arch.lifecycle.LiveData | ||
| import android.arch.lifecycle.MutableLiveData | ||
| import com.nhaarman.mockitokotlin2.doReturn | ||
| import com.nhaarman.mockitokotlin2.eq | ||
| import com.nhaarman.mockitokotlin2.mock | ||
| import com.nhaarman.mockitokotlin2.times | ||
| import com.nhaarman.mockitokotlin2.verify | ||
| import org.junit.Rule | ||
| import org.junit.Test | ||
| import org.wordpress.android.fluxc.model.SiteModel | ||
| import org.wordpress.android.ui.posts.PostListViewLayoutType.STANDARD | ||
| import org.wordpress.android.ui.prefs.AppPrefsWrapper | ||
| import org.wordpress.android.ui.uploads.LocalDraftUploadStarter | ||
| import org.wordpress.android.viewmodel.helpers.ConnectionStatus | ||
| import org.wordpress.android.viewmodel.helpers.ConnectionStatus.AVAILABLE | ||
| import org.wordpress.android.viewmodel.helpers.ConnectionStatus.UNAVAILABLE | ||
|
|
||
| class PostListMainViewModelTest { | ||
| @get:Rule val rule = InstantTaskExecutorRule() | ||
|
|
||
| @Test | ||
| fun `when started, it uploads all local drafts`() { | ||
| // Given | ||
| val site = SiteModel() | ||
| val localDraftUploadStarter = mock<LocalDraftUploadStarter>() | ||
| val connectionStatus = MutableLiveData<ConnectionStatus>().apply { value = AVAILABLE } | ||
|
|
||
| val viewModel = createPostListMainViewModel( | ||
| localDraftUploadStarter = localDraftUploadStarter, | ||
| connectionStatus = connectionStatus | ||
| ) | ||
|
|
||
| // When | ||
| viewModel.start(site = site) | ||
|
|
||
| // Then | ||
| verify(localDraftUploadStarter, times(1)).uploadLocalDrafts(scope = eq(viewModel), site = eq(site)) | ||
| } | ||
|
|
||
| @Test | ||
| fun `when the internet connection changes, it uploads all local drafts`() { | ||
| // Given | ||
| val site = SiteModel() | ||
| val localDraftUploadStarter = mock<LocalDraftUploadStarter>() | ||
| val connectionStatus = MutableLiveData<ConnectionStatus>().apply { value = AVAILABLE } | ||
|
|
||
| val viewModel = createPostListMainViewModel( | ||
| localDraftUploadStarter = localDraftUploadStarter, | ||
| connectionStatus = connectionStatus | ||
| ) | ||
| viewModel.start(site = site) | ||
|
|
||
| // When | ||
| connectionStatus.postValue(UNAVAILABLE) | ||
| connectionStatus.postValue(AVAILABLE) | ||
|
|
||
| // Then | ||
| // The upload should be executed 3 times because we have 2 connections status changes plus the auto-upload | ||
| // during `viewModel.start()`. | ||
| verify(localDraftUploadStarter, times(3)).uploadLocalDrafts(scope = eq(viewModel), site = eq(site)) | ||
| } | ||
|
|
||
| private companion object { | ||
| fun createPostListMainViewModel( | ||
| localDraftUploadStarter: LocalDraftUploadStarter, | ||
| connectionStatus: LiveData<ConnectionStatus> | ||
| ): PostListMainViewModel { | ||
| val prefs = mock<AppPrefsWrapper> { | ||
| on { postListViewLayoutType } doReturn STANDARD | ||
| } | ||
|
|
||
| return PostListMainViewModel( | ||
| dispatcher = mock(), | ||
| postStore = mock(), | ||
| accountStore = mock(), | ||
| uploadStore = mock(), | ||
| mediaStore = mock(), | ||
| networkUtilsWrapper = mock(), | ||
| prefs = prefs, | ||
| localDraftUploadStarter = localDraftUploadStarter, | ||
| connectionStatus = connectionStatus, | ||
| mainDispatcher = mock(), | ||
| bgDispatcher = mock(), | ||
| postListEventListenerFactory = mock() | ||
| ) | ||
| } | ||
| } | ||
| } |
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.