Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
ad2ca94
added cancel auto upload to menu
jd-alexander Feb 6, 2020
b9b8ca7
made the menu actions mutable so it can be modified for dynamic items
jd-alexander Feb 6, 2020
d31ee95
Revert "made the menu actions mutable so it can be modified for dynam…
jd-alexander Feb 6, 2020
1bade7c
Merge remote-tracking branch 'origin/feature/master-pages-offline-sup…
jd-alexander Feb 7, 2020
d2fd956
added logic to setup PageItem Actions.
jd-alexander Feb 7, 2020
10f5abb
override actions in base class so that they can be set at initialization
jd-alexander Feb 7, 2020
e921872
renamed helper to uistatehelper since it contains logic for other stuff
jd-alexander Feb 7, 2020
6b31147
simplified action set creation.
jd-alexander Feb 7, 2020
76be9bf
added dynamic action generation to pages.
jd-alexander Feb 7, 2020
c412101
fixed test issue in SearchListViewModelTest due to page action changes
jd-alexander Feb 7, 2020
3f1c9c0
Added logic to do cancel of auto upload. Fixed import logic.
jd-alexander Feb 7, 2020
b89ffec
fixed formatting issues.
jd-alexander Feb 7, 2020
eee0dbc
add cancel auto upload action to scheduled pages.
jd-alexander Feb 7, 2020
e63146a
removed unused imports from PageItem.
jd-alexander Feb 7, 2020
4caff1c
added local id to page.renamed id to remoteId to avoid confusion.
jd-alexander Feb 7, 2020
da89959
use local id to avoid crash that occurs when a post hasnt been uploaded
jd-alexander Feb 7, 2020
0a035ad
added a null check to ensure there's a post. This will be investigated.
jd-alexander Feb 8, 2020
8038af7
fixed style issues
jd-alexander Feb 8, 2020
1a0d3ee
utilized PageStatus.DRAFT for consistency.
jd-alexander Feb 8, 2020
d139230
fixed naming of PageItemUiStateHelper in test.
jd-alexander Feb 10, 2020
a9562ef
canCancelPendingAutoUpload public; the dynamic actions can be tested
jd-alexander Feb 10, 2020
a9b2003
Scheduled and Published Pages have the same actions. duplicate removed.
jd-alexander Feb 11, 2020
f39dc69
added tests for CANCEL_AUTO_UPLOAD behavior.
jd-alexander Feb 11, 2020
33cd966
removed unnecessary whitespace.
jd-alexander Feb 11, 2020
17f16d9
utilized assertThat and contains assertion instead of list api
jd-alexander Feb 12, 2020
ac5c9e1
Merge branch 'feature/master-pages-offline-support' into issue-11150/…
malinajirka Feb 13, 2020
5e00b56
Fix merge issues
malinajirka Feb 13, 2020
220f0aa
fixed style issue
jd-alexander Feb 13, 2020
aa8231a
Moved page actions to it's own use case
jd-alexander Feb 13, 2020
cb18e91
PageListItemActionsUseCase used instead of helper.
jd-alexander Feb 13, 2020
9da40ef
Changed the helper to a use case for consistency.
jd-alexander Feb 13, 2020
d7b40b7
refactored tests to support use case approach by the diff actions.
jd-alexander Feb 13, 2020
adfffae
Created test for menu action use case.
jd-alexander Feb 13, 2020
3cbea5b
Removed menu action use case related tests and simplified page test
jd-alexander Feb 13, 2020
78dda37
Fixed schedule page list type
jd-alexander Feb 13, 2020
e036fa0
uploadUiState is now passed from ViewModel.Refactored tests and behavior
jd-alexander Feb 13, 2020
990764d
fixed naming in PageListViewModelTest
jd-alexander Feb 13, 2020
39daf2a
removed extra lines from menu actions test
jd-alexander Feb 13, 2020
e4efebb
Fixed lint issues.
jd-alexander Feb 13, 2020
88aa7ec
added unit test to verify scheduled and published actions.
jd-alexander Feb 13, 2020
8bd3cb1
added test for draft action
jd-alexander Feb 13, 2020
440f0d5
made set immutable.
jd-alexander Feb 13, 2020
546a824
added more tests to use case.
jd-alexander Feb 13, 2020
b97737c
Merge branch 'feature/master-pages-offline-support' into issue-11150/…
jd-alexander Feb 15, 2020
4e6dc61
made use case menu actions test clearer.
jd-alexander Feb 17, 2020
fd35b8c
split the test so the intent is clearer
jd-alexander Feb 17, 2020
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
46 changes: 27 additions & 19 deletions WordPress/src/main/java/org/wordpress/android/ui/pages/PageItem.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,6 @@ import androidx.annotation.ColorRes
import androidx.annotation.IdRes
import androidx.annotation.StringRes
import org.wordpress.android.R
import org.wordpress.android.ui.pages.PageItem.Action.DELETE_PERMANENTLY
import org.wordpress.android.ui.pages.PageItem.Action.MOVE_TO_DRAFT
import org.wordpress.android.ui.pages.PageItem.Action.MOVE_TO_TRASH
import org.wordpress.android.ui.pages.PageItem.Action.PUBLISH_NOW
import org.wordpress.android.ui.pages.PageItem.Action.SET_PARENT
import org.wordpress.android.ui.pages.PageItem.Action.VIEW_PAGE
import org.wordpress.android.ui.pages.PageItem.Type.DIVIDER
import org.wordpress.android.ui.pages.PageItem.Type.EMPTY
import org.wordpress.android.ui.pages.PageItem.Type.PAGE
Expand All @@ -19,7 +13,8 @@ import java.util.Date

sealed class PageItem(open val type: Type) {
abstract class Page(
open val id: Long,
open val remoteId: Long,
open val localId: Int,
open val title: String,
open val date: Date,
open val labels: List<UiString>,
Expand All @@ -34,100 +29,112 @@ sealed class PageItem(open val type: Type) {
) : PageItem(PAGE)

data class PublishedPage(
override val id: Long,
override val remoteId: Long,
override val localId: Int,
override val title: String,
override val date: Date,
override val labels: List<UiString> = emptyList(),
override val labelsColor: Int? = null,
override var indent: Int = 0,
override var imageUrl: String? = null,
override val actions: Set<Action>,
override var actionsEnabled: Boolean = true,
override val progressBarUiState: ProgressBarUiState,
override val showOverlay: Boolean
) : Page(
id = id,
remoteId = remoteId,
localId = localId,
title = title,
date = date,
labels = labels,
labelsColor = labelsColor,
indent = indent,
imageUrl = imageUrl,
actions = setOf(VIEW_PAGE, SET_PARENT, MOVE_TO_DRAFT, MOVE_TO_TRASH),
actions = actions,
actionsEnabled = actionsEnabled,
tapActionEnabled = true,
progressBarUiState = progressBarUiState,
showOverlay = showOverlay
)

data class DraftPage(
override val id: Long,
override val remoteId: Long,
override val localId: Int,
override val title: String,
override val date: Date,
override val labels: List<UiString> = emptyList(),
override val labelsColor: Int? = null,
override var imageUrl: String? = null,
override val actions: Set<Action>,
override var actionsEnabled: Boolean = true,
override val progressBarUiState: ProgressBarUiState,
override val showOverlay: Boolean
) : Page(
id = id,
remoteId = remoteId,
localId = localId,
title = title,
date = date,
labels = labels,
labelsColor = labelsColor,
indent = 0,
imageUrl = imageUrl,
actions = setOf(VIEW_PAGE, SET_PARENT, PUBLISH_NOW, MOVE_TO_TRASH),
actions = actions,
actionsEnabled = actionsEnabled,
tapActionEnabled = true,
progressBarUiState = progressBarUiState,
showOverlay = showOverlay
)

data class ScheduledPage(
override val id: Long,
override val remoteId: Long,
override val localId: Int,
override val title: String,
override val date: Date,
override val labels: List<UiString> = emptyList(),
override val labelsColor: Int? = null,
override var imageUrl: String? = null,
override val actions: Set<Action>,
override var actionsEnabled: Boolean = true,
override val progressBarUiState: ProgressBarUiState,
override val showOverlay: Boolean
) : Page(
id = id,
remoteId = remoteId,
localId = localId,
title = title,
date = date,
labels = labels,
labelsColor = labelsColor,
indent = 0,
imageUrl = imageUrl,
actions = setOf(VIEW_PAGE, SET_PARENT, MOVE_TO_DRAFT, MOVE_TO_TRASH),
actions = actions,
actionsEnabled = actionsEnabled,
tapActionEnabled = true,
progressBarUiState = progressBarUiState,
showOverlay = showOverlay
)

data class TrashedPage(
override val id: Long,
override val remoteId: Long,
override val localId: Int,
override val title: String,
override val date: Date,
override val labels: List<UiString> = emptyList(),
override val labelsColor: Int? = null,
override var imageUrl: String? = null,
override val actions: Set<Action>,
override var actionsEnabled: Boolean = true,
override val progressBarUiState: ProgressBarUiState,
override val showOverlay: Boolean
) : Page(
id = id,
remoteId = remoteId,
localId = localId,
title = title,
date = date,
labels = labels,
labelsColor = labelsColor,
indent = 0,
imageUrl = imageUrl,
actions = setOf(MOVE_TO_DRAFT, DELETE_PERMANENTLY),
actions = actions,
actionsEnabled = actionsEnabled,
tapActionEnabled = false,
progressBarUiState = progressBarUiState,
Expand Down Expand Up @@ -160,6 +167,7 @@ sealed class PageItem(open val type: Type) {

enum class Action(@IdRes val itemId: Int) {
VIEW_PAGE(R.id.view_page),
CANCEL_AUTO_UPLOAD(R.id.cancel_auto_upload),
SET_PARENT(R.id.set_parent),
PUBLISH_NOW(R.id.publish_now),
MOVE_TO_DRAFT(R.id.move_to_draft),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class PageItemDiffUtil(val items: List<PageItem>, val result: List<PageItem>) :
val oldItem = items[oldItemPosition]
val newItem = result[newItemPosition]
return oldItem.type == newItem.type && when (oldItem) {
is Page -> oldItem.id == (newItem as Page).id
is Page -> oldItem.remoteId == (newItem as Page).remoteId
is ParentPage -> oldItem.id == (newItem as ParentPage).id
else -> oldItem == newItem
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package org.wordpress.android.viewmodel.pages

import org.wordpress.android.ui.pages.PageItem.Action
import org.wordpress.android.ui.pages.PageItem.Action.CANCEL_AUTO_UPLOAD
import org.wordpress.android.ui.pages.PageItem.Action.DELETE_PERMANENTLY
import org.wordpress.android.ui.pages.PageItem.Action.MOVE_TO_DRAFT
import org.wordpress.android.ui.pages.PageItem.Action.MOVE_TO_TRASH
import org.wordpress.android.ui.pages.PageItem.Action.PUBLISH_NOW
import org.wordpress.android.ui.pages.PageItem.Action.SET_PARENT
import org.wordpress.android.ui.pages.PageItem.Action.VIEW_PAGE
import org.wordpress.android.viewmodel.pages.CreatePageUploadUiStateUseCase.PostUploadUiState
import org.wordpress.android.viewmodel.pages.CreatePageUploadUiStateUseCase.PostUploadUiState.UploadFailed
import org.wordpress.android.viewmodel.pages.CreatePageUploadUiStateUseCase.PostUploadUiState.UploadWaitingForConnection
import org.wordpress.android.viewmodel.pages.PageListViewModel.PageListType
import org.wordpress.android.viewmodel.pages.PageListViewModel.PageListType.DRAFTS
import org.wordpress.android.viewmodel.pages.PageListViewModel.PageListType.PUBLISHED
import org.wordpress.android.viewmodel.pages.PageListViewModel.PageListType.SCHEDULED
import org.wordpress.android.viewmodel.pages.PageListViewModel.PageListType.TRASHED
import javax.inject.Inject

class CreatePageListItemActionsUseCase @Inject constructor() {
fun setupPageActions(listType: PageListType, uploadUiState: PostUploadUiState): Set<Action> {
return when (listType) {
SCHEDULED, PUBLISHED -> mutableSetOf(
VIEW_PAGE,
SET_PARENT,
MOVE_TO_DRAFT,
MOVE_TO_TRASH
).apply {
if (canCancelPendingAutoUpload(uploadUiState)) {
add(CANCEL_AUTO_UPLOAD)
}
}
DRAFTS -> mutableSetOf(VIEW_PAGE, SET_PARENT, PUBLISH_NOW, MOVE_TO_TRASH).apply {
if (canCancelPendingAutoUpload(uploadUiState)) {
add(CANCEL_AUTO_UPLOAD)
}
}
TRASHED -> setOf(MOVE_TO_DRAFT, DELETE_PERMANENTLY)
}
}

private fun canCancelPendingAutoUpload(uploadUiState: PostUploadUiState) =
(uploadUiState is UploadWaitingForConnection ||
(uploadUiState is UploadFailed && uploadUiState.isEligibleForAutoUpload))
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import javax.inject.Inject

typealias ShouldShowOverlay = Boolean

class PageItemUploadProgressHelper @Inject constructor(
class PageItemProgressUiStateUseCase @Inject constructor(
private val appPrefsWrapper: AppPrefsWrapper
) {
fun getProgressStateForPage(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,13 @@ private const val DEFAULT_INDENT = 0
class PageListViewModel @Inject constructor(
private val createPageListItemLabelsUseCase: CreatePageListItemLabelsUseCase,
private val createPageUploadUiStateUseCase: CreatePageUploadUiStateUseCase,
private val pageListItemActionsUseCase: CreatePageListItemActionsUseCase,
private val pageItemProgressUiStateUseCase: PageItemProgressUiStateUseCase,
private val mediaStore: MediaStore,
private val postStore: PostStore,
private val dispatcher: Dispatcher,
private val localeManagerWrapper: LocaleManagerWrapper,
@Named(BG_THREAD) private val coroutineDispatcher: CoroutineDispatcher,
private val progressHelper: PageItemUploadProgressHelper
@Named(BG_THREAD) private val coroutineDispatcher: CoroutineDispatcher
) : ScopedViewModel(coroutineDispatcher) {
private val _pages: MutableLiveData<List<PageItem>> = MutableLiveData()
val pages: LiveData<Pair<List<PageItem>, Boolean>> = Transformations.map(_pages) {
Expand Down Expand Up @@ -147,7 +148,7 @@ class PageListViewModel @Inject constructor(
}

fun onScrollToPageRequested(remotePageId: Long) {
val position = _pages.value?.indexOfFirst { it is Page && it.id == remotePageId } ?: -1
val position = _pages.value?.indexOfFirst { it is Page && it.remoteId == remotePageId } ?: -1
if (position != -1) {
_scrollToPosition.postValue(position)
} else {
Expand Down Expand Up @@ -253,9 +254,15 @@ class PageListViewModel @Inject constructor(
val itemUiStateData = createItemUiStateData(it)

PublishedPage(
it.remoteId, it.title, it.date, itemUiStateData.labels, itemUiStateData.labelsColor,
it.remoteId,
it.pageId,
it.title,
it.date,
itemUiStateData.labels,
itemUiStateData.labelsColor,
pageItemIndent,
getFeaturedImageUrl(it.featuredImageId),
itemUiStateData.actions,
actionsEnabled,
itemUiStateData.progressBarUiState,
itemUiStateData.showOverlay
Expand All @@ -274,9 +281,13 @@ class PageListViewModel @Inject constructor(
val itemUiStateData = createItemUiStateData(it)

ScheduledPage(
it.remoteId, it.title, it.date, itemUiStateData.labels,
it.remoteId, it.pageId,
it.title,
it.date,
itemUiStateData.labels,
itemUiStateData.labelsColor,
getFeaturedImageUrl(it.featuredImageId),
itemUiStateData.actions,
actionsEnabled,
itemUiStateData.progressBarUiState,
itemUiStateData.showOverlay
Expand All @@ -294,11 +305,13 @@ class PageListViewModel @Inject constructor(
val itemUiStateData = createItemUiStateData(it)
DraftPage(
it.remoteId,
it.pageId,
it.title,
it.date,
itemUiStateData.labels,
itemUiStateData.labelsColor,
getFeaturedImageUrl(it.featuredImageId),
itemUiStateData.actions,
actionsEnabled,
itemUiStateData.progressBarUiState,
itemUiStateData.showOverlay
Expand All @@ -314,11 +327,13 @@ class PageListViewModel @Inject constructor(
val itemUiStateData = createItemUiStateData(it)
TrashedPage(
it.remoteId,
it.pageId,
it.title,
it.date,
itemUiStateData.labels,
itemUiStateData.labelsColor,
getFeaturedImageUrl(it.featuredImageId),
itemUiStateData.actions,
actionsEnabled,
itemUiStateData.progressBarUiState,
itemUiStateData.showOverlay
Expand Down Expand Up @@ -373,17 +388,19 @@ class PageListViewModel @Inject constructor(
)
val (labels, labelColor) = createPageListItemLabelsUseCase.createLabels(postModel, uploadUiState)

val (progressBarUiState, showOverlay) = progressHelper.getProgressStateForPage(
val (progressBarUiState, showOverlay) = pageItemProgressUiStateUseCase.getProgressStateForPage(
postModel,
uploadUiState
)
return ItemUiStateData(labels, labelColor, progressBarUiState, showOverlay)
val actions = pageListItemActionsUseCase.setupPageActions(listType, uploadUiState)
return ItemUiStateData(labels, labelColor, progressBarUiState, showOverlay, actions)
}

private data class ItemUiStateData(
val labels: List<UiString>,
@ColorRes val labelsColor: Int?,
val progressBarUiState: ProgressBarUiState,
val showOverlay: Boolean
val showOverlay: Boolean,
val actions: Set<Action>
)
}
Loading