Skip to content
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

Private & Pending Pages #8316

Merged
merged 23 commits into from
Sep 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
54153ff
Add a reference to FluxC version that has private & pending pages
0nko Sep 16, 2018
deb2018
Add string resources for pending & private pages
0nko Sep 16, 2018
0ed8f09
Add a new page list type
0nko Sep 16, 2018
efb4043
Replace the use of page status with the new page list type
0nko Sep 16, 2018
d9c004b
Handle the private and pending status type in search
0nko Sep 16, 2018
4093d27
Use FluxC build with the fixed search
0nko Sep 16, 2018
4970f9f
Add page list tag resources
0nko Sep 16, 2018
83f9315
Update the FluxC reference to the latest version
0nko Sep 17, 2018
20aba75
Update the 2nd label and implement multiple tag support
0nko Sep 17, 2018
357d0bf
Use the page list type instead of page status in search grouping
0nko Sep 17, 2018
4284159
Extract the suspendCoroutineWithTimeout into a public helper
0nko Sep 17, 2018
d7cd949
Implement groupedSearch using page list type
0nko Sep 17, 2018
5264ac7
Fix a problem when local changes not shown after update when offline
0nko Sep 17, 2018
e4bbef7
Optimize imports
0nko Sep 17, 2018
8fea0e0
Fix ktlint: long line
0nko Sep 17, 2018
52d1027
Remove unused drawable
0nko Sep 17, 2018
fbfc6df
Make constant private
0nko Sep 17, 2018
0a6228d
Remove unused variable
0nko Sep 17, 2018
b446df6
Remove redundant cast
0nko Sep 17, 2018
6ad8646
Fix page search unit tests
0nko Sep 17, 2018
c617108
Fix the missing FAB bug
0nko Sep 17, 2018
f12173b
Fix another page status vs page list type error
0nko Sep 17, 2018
565c0b4
Temporarily ignore the pages unit tests because they don't run reliably
0nko Sep 17, 2018
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 @@ -17,7 +17,7 @@ sealed class PageItem(open val type: Type) {
abstract class Page(
open val id: Long,
open val title: String,
open val labelRes: Int?,
open val labels: List<Int>,
open var indent: Int,
open val actions: Set<Action>,
open var actionsEnabled: Boolean
Expand All @@ -26,29 +26,29 @@ sealed class PageItem(open val type: Type) {
data class PublishedPage(
override val id: Long,
override val title: String,
override val labelRes: Int? = null,
override val labels: List<Int> = emptyList(),
override var indent: Int = 0,
override var actionsEnabled: Boolean = true
) : Page(id, title, labelRes, indent, setOf(VIEW_PAGE, SET_PARENT, MOVE_TO_DRAFT, MOVE_TO_TRASH), actionsEnabled)
) : Page(id, title, labels, indent, setOf(VIEW_PAGE, SET_PARENT, MOVE_TO_DRAFT, MOVE_TO_TRASH), actionsEnabled)

data class DraftPage(
override val id: Long,
override val title: String,
override val labelRes: Int? = null,
override val labels: List<Int> = emptyList(),
override var actionsEnabled: Boolean = true
) : Page(id, title, labelRes, 0, setOf(VIEW_PAGE, SET_PARENT, PUBLISH_NOW, MOVE_TO_TRASH), actionsEnabled)
) : Page(id, title, labels, 0, setOf(VIEW_PAGE, SET_PARENT, PUBLISH_NOW, MOVE_TO_TRASH), actionsEnabled)

data class ScheduledPage(
override val id: Long,
override val title: String,
override var actionsEnabled: Boolean = true
) : Page(id, title, null, 0, setOf(VIEW_PAGE, SET_PARENT, MOVE_TO_DRAFT, MOVE_TO_TRASH), actionsEnabled)
) : Page(id, title, emptyList(), 0, setOf(VIEW_PAGE, SET_PARENT, MOVE_TO_DRAFT, MOVE_TO_TRASH), actionsEnabled)

data class TrashedPage(
override val id: Long,
override val title: String,
override var actionsEnabled: Boolean = true
) : Page(id, title, null, 0, setOf(VIEW_PAGE, MOVE_TO_DRAFT, DELETE_PERMANENTLY), actionsEnabled)
) : Page(id, title, emptyList(), 0, setOf(VIEW_PAGE, MOVE_TO_DRAFT, DELETE_PERMANENTLY), actionsEnabled)

data class ParentPage(
val id: Long,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ sealed class PageItemViewHolder(internal val parent: ViewGroup, @LayoutRes layou
) : PageItemViewHolder(parentView, layout.page_list_item) {
private val pageTitle = itemView.findViewById<TextView>(id.page_title)
private val pageMore = itemView.findViewById<ImageButton>(id.page_more)
private val pageLabel = itemView.findViewById<TextView>(id.page_label)
private val firstLabel = itemView.findViewById<TextView>(id.first_label)
private val secondLabel = itemView.findViewById<TextView>(id.second_label)
private val pageItemContainer = itemView.findViewById<ViewGroup>(id.page_item)
private val largeStretcher = itemView.findViewById<View>(id.large_stretcher)
private val smallStretcher = itemView.findViewById<View>(id.small_stretcher)
Expand All @@ -48,17 +49,24 @@ sealed class PageItemViewHolder(internal val parent: ViewGroup, @LayoutRes layou
else
pageItem.title

if (pageItem.labelRes == null) {
pageLabel.visibility = View.GONE
if (pageItem.labels.isEmpty()) {
firstLabel.visibility = View.GONE
smallStretcher.visibility = View.VISIBLE
largeStretcher.visibility = View.GONE
} else {
pageLabel.text = parent.context.getString(pageItem.labelRes!!)
pageLabel.visibility = View.VISIBLE
firstLabel.text = parent.context.getString(pageItem.labels.first())
firstLabel.visibility = View.VISIBLE
smallStretcher.visibility = View.GONE
largeStretcher.visibility = View.VISIBLE
}

if (pageItem.labels.size <= 1) {
secondLabel.visibility = View.GONE
} else {
secondLabel.text = parent.context.getString(pageItem.labels[1])
secondLabel.visibility = View.VISIBLE
}

itemView.setOnClickListener { onItemTapped(pageItem) }

pageMore.setOnClickListener { moreClick(pageItem, it) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ import android.view.ViewGroup
import kotlinx.android.synthetic.main.pages_list_fragment.*
import org.wordpress.android.R
import org.wordpress.android.WordPress
import org.wordpress.android.fluxc.model.page.PageStatus
import org.wordpress.android.util.DisplayUtils
import org.wordpress.android.viewmodel.pages.PageListViewModel
import org.wordpress.android.viewmodel.pages.PageListViewModel.PageListType
import org.wordpress.android.viewmodel.pages.PagesViewModel
import org.wordpress.android.widgets.RecyclerItemDecoration
import javax.inject.Inject
Expand All @@ -29,12 +29,12 @@ class PageListFragment : Fragment() {
private val listStateKey = "list_state"

companion object {
private const val statusKey = "status_key"
private const val typeKey = "type_key"

fun newInstance(pageStatus: PageStatus): PageListFragment {
fun newInstance(listType: PageListType): PageListFragment {
val fragment = PageListFragment()
val bundle = Bundle()
bundle.putSerializable(statusKey, pageStatus)
bundle.putSerializable(typeKey, listType)
fragment.arguments = bundle
return fragment
}
Expand Down Expand Up @@ -64,11 +64,11 @@ class PageListFragment : Fragment() {
private fun initializeViewModels(activity: FragmentActivity) {
val pagesViewModel = ViewModelProviders.of(activity, viewModelFactory).get(PagesViewModel::class.java)

val pageStatus = checkNotNull(arguments?.getSerializable(statusKey) as PageStatus?)
val listType = arguments?.getSerializable(typeKey) as PageListType
viewModel = ViewModelProviders.of(this, viewModelFactory)
.get(pageStatus.name, PageListViewModel::class.java)
.get(listType.name, PageListViewModel::class.java)

viewModel.start(pageStatus, pagesViewModel)
viewModel.start(listType, pagesViewModel)

setupObservers()
}
Expand Down Expand Up @@ -96,7 +96,7 @@ class PageListFragment : Fragment() {
adapter = PagesAdapter(
onMenuAction = { action, page -> viewModel.onMenuAction(action, page) },
onItemTapped = { page -> viewModel.onItemTapped(page) },
onEmptyActionButtonTapped = { (viewModel as PageListViewModel).onEmptyListNewPageButtonTapped() })
onEmptyActionButtonTapped = { viewModel.onEmptyListNewPageButtonTapped() })
recyclerView.adapter = adapter
} else {
adapter = recyclerView.adapter as PagesAdapter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ import org.wordpress.android.R
import org.wordpress.android.R.string
import org.wordpress.android.WordPress
import org.wordpress.android.fluxc.model.SiteModel
import org.wordpress.android.fluxc.model.page.PageStatus.DRAFT
import org.wordpress.android.fluxc.model.page.PageStatus.PUBLISHED
import org.wordpress.android.fluxc.model.page.PageStatus.SCHEDULED
import org.wordpress.android.fluxc.model.page.PageStatus.TRASHED
import org.wordpress.android.ui.ActivityLauncher
import org.wordpress.android.ui.RequestCodes
import org.wordpress.android.ui.pages.PageItem.Page
Expand All @@ -41,8 +37,11 @@ import org.wordpress.android.util.WPSwipeToRefreshHelper
import org.wordpress.android.util.helpers.SwipeToRefreshHelper
import org.wordpress.android.viewmodel.pages.PageListViewModel.PageListState
import org.wordpress.android.viewmodel.pages.PageListViewModel.PageListState.FETCHING
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 org.wordpress.android.viewmodel.pages.PagesViewModel
import org.wordpress.android.viewmodel.pages.getTitle
import javax.inject.Inject

class PagesFragment : Fragment() {
Expand Down Expand Up @@ -291,7 +290,7 @@ class PagesFragment : Fragment() {

class PagesPagerAdapter(val context: Context, fm: FragmentManager) : FragmentPagerAdapter(fm) {
companion object {
val pageTypes = listOf(PUBLISHED, DRAFT, SCHEDULED, TRASHED)
val pageTypes = listOf(PUBLISHED, DRAFTS, SCHEDULED, TRASHED)
}

override fun getCount(): Int = pageTypes.size
Expand All @@ -301,6 +300,6 @@ class PagesPagerAdapter(val context: Context, fm: FragmentManager) : FragmentPag
}

override fun getPageTitle(position: Int): CharSequence? {
return context.getString(pageTypes[position].getTitle())
return context.getString(pageTypes[position].title)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.wordpress.android.util.coroutines

import kotlinx.coroutines.experimental.suspendCancellableCoroutine
import kotlinx.coroutines.experimental.withTimeoutOrNull
import java.util.concurrent.TimeUnit.MILLISECONDS
import kotlin.coroutines.experimental.Continuation

suspend inline fun <T> suspendCoroutineWithTimeout(
timeout: Long,
crossinline block: (Continuation<T>) -> Unit
) = withTimeoutOrNull(timeout, MILLISECONDS) {
suspendCancellableCoroutine(block = block)
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@ import org.greenrobot.eventbus.ThreadMode
import org.wordpress.android.fluxc.Dispatcher
import org.wordpress.android.fluxc.store.PostStore.OnPostUploaded
import javax.inject.Inject
import kotlinx.coroutines.experimental.suspendCancellableCoroutine
import kotlinx.coroutines.experimental.withTimeoutOrNull
import org.wordpress.android.fluxc.action.PostAction
import org.wordpress.android.fluxc.action.PostAction.DELETE_POST
import org.wordpress.android.fluxc.action.PostAction.UPDATE_POST
import org.wordpress.android.fluxc.store.PostStore.OnPostChanged
import org.wordpress.android.util.coroutines.suspendCoroutineWithTimeout
import org.wordpress.android.viewmodel.pages.ActionPerformer.PageAction.EventType
import org.wordpress.android.viewmodel.pages.ActionPerformer.PageAction.EventType.UPLOAD
import java.util.concurrent.TimeUnit.SECONDS
import kotlin.coroutines.experimental.Continuation

class ActionPerformer
Expand All @@ -22,7 +20,7 @@ class ActionPerformer
private lateinit var eventType: EventType

companion object {
private const val ACTION_TIMEOUT = 30L
private const val ACTION_TIMEOUT = 30L * 1000
}

init {
Expand Down Expand Up @@ -62,13 +60,6 @@ class ActionPerformer
}
}

private suspend inline fun <T> suspendCoroutineWithTimeout(
timeout: Long,
crossinline block: (Continuation<T>) -> Unit
) = withTimeoutOrNull(timeout, SECONDS) {
suspendCancellableCoroutine(block = block)
}

data class PageAction(val event: EventType, val perform: () -> Unit) {
var onSuccess: () -> Unit = { }
var onError: () -> Unit = { }
Expand Down
Loading