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

UI Modernization Post: Remove post list compact layout #19424

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -8,7 +8,6 @@ import android.view.ViewGroup
import android.widget.Button
import android.widget.ProgressBar
import androidx.fragment.app.FragmentActivity
import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProvider
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
Expand All @@ -18,8 +17,6 @@ import org.wordpress.android.fluxc.model.SiteModel
import org.wordpress.android.ui.ActionableEmptyView
import org.wordpress.android.ui.ViewPagerFragment
import org.wordpress.android.ui.posts.PostListType.SEARCH
import org.wordpress.android.ui.posts.PostListViewLayoutType.COMPACT
import org.wordpress.android.ui.posts.PostListViewLayoutType.STANDARD
import org.wordpress.android.ui.posts.adapters.PostListAdapter
import org.wordpress.android.ui.utils.UiHelpers
import org.wordpress.android.ui.utils.UiString
Expand Down Expand Up @@ -61,7 +58,6 @@ class PostListFragment : ViewPagerFragment() {
private var actionableEmptyView: ActionableEmptyView? = null
private var progressLoadMore: ProgressBar? = null

private lateinit var itemDecorationCompactLayout: RecyclerItemDecoration
private lateinit var itemDecorationStandardLayout: RecyclerItemDecoration

private lateinit var postListType: PostListType
Expand Down Expand Up @@ -107,26 +103,6 @@ class PostListFragment : ViewPagerFragment() {

mainViewModel = ViewModelProvider(nonNullActivity, viewModelFactory)[PostListMainViewModel::class.java]

mainViewModel.viewLayoutType.observe(viewLifecycleOwner, Observer { optionaLayoutType ->
optionaLayoutType?.let { layoutType ->
recyclerView?.removeItemDecoration(itemDecorationCompactLayout)
recyclerView?.removeItemDecoration(itemDecorationStandardLayout)

when (layoutType) {
STANDARD -> {
recyclerView?.addItemDecoration(itemDecorationStandardLayout)
}
COMPACT -> {
recyclerView?.addItemDecoration(itemDecorationCompactLayout)
}
}

if (postListAdapter.updateItemLayoutType(layoutType)) {
recyclerView?.scrollToPosition(0)
}
}
})

mainViewModel.authorSelectionUpdated.observe(viewLifecycleOwner) {
if (it != null) {
if (viewModel.updateAuthorFilterIfNotSearch(it)) {
Expand Down Expand Up @@ -157,34 +133,34 @@ class PostListFragment : ViewPagerFragment() {

private fun initObservers() {
if (postListType == SEARCH) {
mainViewModel.searchQuery.observe(viewLifecycleOwner, Observer {
mainViewModel.searchQuery.observe(viewLifecycleOwner) {
if (TextUtils.isEmpty(it)) {
postListAdapter.submitList(null)
}
viewModel.search(it)
})
}
}

viewModel.emptyViewState.observe(viewLifecycleOwner, Observer {
viewModel.emptyViewState.observe(viewLifecycleOwner) {
it?.let { emptyViewState -> updateEmptyViewForState(emptyViewState) }
})
}

viewModel.isFetchingFirstPage.observe(viewLifecycleOwner, Observer {
viewModel.isFetchingFirstPage.observe(viewLifecycleOwner) {
swipeRefreshLayout?.isRefreshing = it == true
})
}

viewModel.pagedListData.observe(viewLifecycleOwner, Observer {
viewModel.pagedListData.observe(viewLifecycleOwner) {
it?.let { pagedListData -> updatePagedListData(pagedListData) }
})
}

viewModel.isLoadingMore.observe(viewLifecycleOwner, Observer {
viewModel.isLoadingMore.observe(viewLifecycleOwner) {
progressLoadMore?.visibility = if (it == true) View.VISIBLE else View.GONE
})
viewModel.scrollToPosition.observe(viewLifecycleOwner, Observer {
}
viewModel.scrollToPosition.observe(viewLifecycleOwner) {
it?.let { index ->
recyclerView?.scrollToPosition(index)
}
})
}
}

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
Expand All @@ -200,12 +176,9 @@ class PostListFragment : ViewPagerFragment() {
0,
context.resources.getDimensionPixelSize(R.dimen.margin_medium)
)
itemDecorationCompactLayout = RecyclerItemDecoration(
0,
context.resources.getDimensionPixelSize(R.dimen.list_divider_height)
)
recyclerView?.layoutManager = LinearLayoutManager(context)
recyclerView?.adapter = postListAdapter
recyclerView?.addItemDecoration(itemDecorationStandardLayout)

swipeRefreshLayout?.let {
swipeToRefreshHelper = buildSwipeToRefreshHelper(it) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import android.view.Menu
import android.view.View
import android.view.ViewGroup
import android.widget.FrameLayout
import android.widget.ImageButton
import android.widget.ImageView
import android.widget.ImageView.ScaleType
import android.widget.PopupMenu
Expand All @@ -26,7 +25,6 @@ import androidx.recyclerview.widget.RecyclerView
import org.wordpress.android.R
import org.wordpress.android.ui.utils.UiHelpers
import org.wordpress.android.ui.utils.UiString
import org.wordpress.android.util.extensions.expandTouchTargetArea
import org.wordpress.android.util.extensions.getColorFromAttribute
import org.wordpress.android.util.extensions.getDrawableFromAttribute
import org.wordpress.android.util.image.ImageManager
Expand Down Expand Up @@ -135,23 +133,6 @@ sealed class PostListItemViewHolder(
}
}

class Compact(
parent: ViewGroup,
imageManager: ImageManager,
private val uiHelpers: UiHelpers
) : PostListItemViewHolder(R.layout.post_list_item_compact, parent, imageManager, uiHelpers) {
private val moreButton: ImageButton = itemView.findViewById(R.id.more_button)

override fun onBind(item: PostListItemUiState) {
setBasicValues(item.data)

itemView.setOnClickListener { item.onSelected.invoke() }
uiHelpers.updateVisibility(moreButton, item.compactActions.actions.isNotEmpty())
moreButton.expandTouchTargetArea(R.dimen.post_list_more_button_extra_padding)
moreButton.setOnClickListener { onMoreClicked(item.compactActions.actions, moreButton) }
}
}

protected fun setBasicValues(data: PostListItemUiStateData) {
uiHelpers.setTextOrHide(titleTextView, data.title)
updatePostInfoLabel(postInfoTextView, data.postInfo)
Expand Down Expand Up @@ -249,7 +230,7 @@ sealed class PostListItemViewHolder(
private fun getMenuItemTitleWithIcon(context: Context, item: PostListItemAction): SpannableStringBuilder {
var icon: Drawable? = setTint(
context,
context.getDrawable(item.buttonType.iconResId)!!, item.buttonType.colorAttrId
ContextCompat.getDrawable(context, item.buttonType.iconResId)!!, item.buttonType.colorAttrId
)
// If there's no icon, we insert a transparent one to keep the title aligned with the items which have icons.
if (icon == null) icon = ColorDrawable(Color.TRANSPARENT)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,6 @@ import org.wordpress.android.ui.posts.PostListType.DRAFTS
import org.wordpress.android.ui.posts.PostListType.PUBLISHED
import org.wordpress.android.ui.posts.PostListType.SCHEDULED
import org.wordpress.android.ui.posts.PostListType.TRASHED
import org.wordpress.android.ui.posts.PostListViewLayoutType.COMPACT
import org.wordpress.android.ui.posts.PostListViewLayoutType.STANDARD
import org.wordpress.android.ui.posts.PostListViewLayoutTypeMenuUiState.CompactViewLayoutTypeMenuUiState
import org.wordpress.android.ui.posts.PostListViewLayoutTypeMenuUiState.StandardViewLayoutTypeMenuUiState
import org.wordpress.android.ui.prefs.AppPrefsWrapper
import org.wordpress.android.ui.uploads.UploadActionUseCase
import org.wordpress.android.ui.uploads.UploadStarter
Expand Down Expand Up @@ -134,12 +130,6 @@ class PostListMainViewModel @Inject constructor(
private val _postUploadAction = SingleLiveEvent<PostUploadAction>()
val postUploadAction: LiveData<PostUploadAction> = _postUploadAction

private val _viewLayoutType = MutableLiveData<PostListViewLayoutType>()
val viewLayoutType: LiveData<PostListViewLayoutType> = _viewLayoutType

private val _viewLayoutTypeMenuUiState = MutableLiveData<PostListViewLayoutTypeMenuUiState>()
val viewLayoutTypeMenuUiState: LiveData<PostListViewLayoutTypeMenuUiState> = _viewLayoutTypeMenuUiState

private val _isSearchExpanded = MutableLiveData<Boolean>()
val isSearchExpanded: LiveData<Boolean> = _isSearchExpanded

Expand Down Expand Up @@ -243,12 +233,6 @@ class PostListMainViewModel @Inject constructor(
this.site = site
this.editPostRepository = editPostRepository

if (isSearchExpanded.value == true) {
setViewLayoutAndIcon(COMPACT, false)
} else {
setUserPreferredViewLayoutType()
}

val authorFilterSelection: AuthorFilterSelection = if (isFilteringByAuthorSupported) {
prefs.postListAuthorSelection
} else {
Expand Down Expand Up @@ -334,7 +318,6 @@ class PostListMainViewModel @Inject constructor(

fun onSearchExpanded(restorePreviousSearch: Boolean) {
if (isSearchExpanded.value != true) {
setViewLayoutAndIcon(COMPACT, false)
AnalyticsUtils.trackWithSiteDetails(POST_LIST_SEARCH_ACCESSED, site)

if (!restorePreviousSearch) {
Expand All @@ -347,7 +330,6 @@ class PostListMainViewModel @Inject constructor(
}

fun onSearchCollapsed(delay: Long = SEARCH_COLLAPSE_DELAY) {
setUserPreferredViewLayoutType()
_isSearchExpanded.value = false
clearSearch()

Expand Down Expand Up @@ -569,32 +551,6 @@ class PostListMainViewModel @Inject constructor(
)
}

fun toggleViewLayout() {
val currentLayoutType = viewLayoutType.value ?: PostListViewLayoutType.defaultValue
val toggledValue = when (currentLayoutType) {
STANDARD -> COMPACT
COMPACT -> STANDARD
}
AnalyticsUtils.trackAnalyticsPostListToggleLayout(toggledValue)
setViewLayoutAndIcon(toggledValue, true)
}

private fun setViewLayoutAndIcon(layout: PostListViewLayoutType, storeIntoPreferences: Boolean = true) {
_viewLayoutType.value = layout
_viewLayoutTypeMenuUiState.value = when (layout) {
STANDARD -> StandardViewLayoutTypeMenuUiState
COMPACT -> CompactViewLayoutTypeMenuUiState
}
if (storeIntoPreferences) {
prefs.postListViewLayoutType = layout
}
}

private fun setUserPreferredViewLayoutType() {
val savedLayoutType = prefs.postListViewLayoutType
setViewLayoutAndIcon(savedLayoutType, false)
}

fun onBottomSheetPublishButtonClicked() {
editPostRepository.getEditablePost()?.let {
postActionHandler.publishPost(it)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,6 @@ data class PostListMainViewState(
val authorFilterItems: List<AuthorFilterListItemUIState>
)

sealed class PostListViewLayoutTypeMenuUiState(@DrawableRes val iconRes: Int, val title: UiString) {
object StandardViewLayoutTypeMenuUiState : PostListViewLayoutTypeMenuUiState(
iconRes = R.drawable.ic_view_post_compact_white_24dp,
title = UiStringRes(R.string.post_list_toggle_item_layout_list_view)
)

object CompactViewLayoutTypeMenuUiState : PostListViewLayoutTypeMenuUiState(
iconRes = R.drawable.ic_view_post_full_white_24dp,
title = UiStringRes(R.string.post_list_toggle_item_layout_cards_view)
)
}

sealed class AuthorFilterListItemUIState(
val id: Long,
val text: UiString,
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ import org.wordpress.android.R
import org.wordpress.android.fluxc.model.LocalOrRemoteId.LocalId
import org.wordpress.android.fluxc.model.LocalOrRemoteId.RemoteId
import org.wordpress.android.ui.posts.PostListItemViewHolder
import org.wordpress.android.ui.posts.PostListViewLayoutType
import org.wordpress.android.ui.posts.PostListViewLayoutType.COMPACT
import org.wordpress.android.ui.posts.PostListViewLayoutType.STANDARD
import org.wordpress.android.ui.utils.UiHelpers
import org.wordpress.android.util.extensions.setVisible
import org.wordpress.android.util.image.ImageManager
Expand All @@ -24,34 +21,21 @@ import org.wordpress.android.viewmodel.posts.PostListItemType.PostListItemUiStat
import org.wordpress.android.viewmodel.uistate.ProgressBarUiState

private const val VIEW_TYPE_POST = 0
private const val VIEW_TYPE_POST_COMPACT = 1
private const val VIEW_TYPE_ENDLIST_INDICATOR = 2
private const val VIEW_TYPE_LOADING = 3
private const val VIEW_TYPE_LOADING_COMPACT = 4

class PostListAdapter(
context: Context,
private val imageManager: ImageManager,
private val uiHelpers: UiHelpers
) : PagedListAdapter<PostListItemType, ViewHolder>(PostListDiffItemCallback) {
private val layoutInflater: LayoutInflater = LayoutInflater.from(context)
private var itemLayoutType: PostListViewLayoutType = PostListViewLayoutType.defaultValue

override fun getItemViewType(position: Int): Int {
return when (getItem(position)) {
is EndListIndicatorItem -> VIEW_TYPE_ENDLIST_INDICATOR
is PostListItemUiState -> {
when (itemLayoutType) {
STANDARD -> VIEW_TYPE_POST
COMPACT -> VIEW_TYPE_POST_COMPACT
}
}
is LoadingItem, null -> {
when (itemLayoutType) {
STANDARD -> VIEW_TYPE_LOADING
COMPACT -> VIEW_TYPE_LOADING_COMPACT
}
}
is PostListItemUiState -> VIEW_TYPE_POST
is LoadingItem, null -> VIEW_TYPE_LOADING
}
}

Expand All @@ -66,16 +50,9 @@ class PostListAdapter(
val view = layoutInflater.inflate(R.layout.post_list_item_skeleton, parent, false)
LoadingViewHolder(view)
}
VIEW_TYPE_LOADING_COMPACT -> {
val view = layoutInflater.inflate(R.layout.post_list_item_skeleton_compact, parent, false)
LoadingViewHolder(view)
}
VIEW_TYPE_POST -> {
PostListItemViewHolder.Standard(parent, imageManager, uiHelpers)
}
VIEW_TYPE_POST_COMPACT -> {
PostListItemViewHolder.Compact(parent, imageManager, uiHelpers)
}
else -> {
// Fail fast if a new view type is added so the we can handle it
throw IllegalStateException("The view type '$viewType' needs to be handled")
Expand Down Expand Up @@ -104,15 +81,6 @@ class PostListAdapter(
}
}

fun updateItemLayoutType(updatedItemLayoutType: PostListViewLayoutType): Boolean {
if (updatedItemLayoutType == itemLayoutType) {
return false
}
itemLayoutType = updatedItemLayoutType
notifyDataSetChanged()
return true
}

private class LoadingViewHolder(view: View) : ViewHolder(view) {
val editButton: View? = view.findViewById(R.id.skeleton_button_edit)
val viewButton: View? = view.findViewById(R.id.skeleton_button_view)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import org.wordpress.android.ui.mysite.SelectedSiteRepository;
import org.wordpress.android.ui.mysite.tabs.MySiteTabType;
import org.wordpress.android.ui.posts.AuthorFilterSelection;
import org.wordpress.android.ui.posts.PostListViewLayoutType;
import org.wordpress.android.ui.quickstart.QuickStartType;
import org.wordpress.android.ui.quickstart.QuickStartType.NewSiteQuickStartType;
import org.wordpress.android.ui.reader.tracker.ReaderTab;
Expand Down Expand Up @@ -1131,16 +1130,6 @@ public static void setAuthorFilterSelection(@NonNull AuthorFilterSelection selec
setLong(DeletablePrefKey.POST_LIST_AUTHOR_FILTER, selection.getId());
}

@NonNull public static PostListViewLayoutType getPostsListViewLayoutType() {
long id = getLong(DeletablePrefKey.POST_LIST_VIEW_LAYOUT_TYPE,
PostListViewLayoutType.getDefaultValue().getId());
return PostListViewLayoutType.fromId(id);
}

public static void setPostsListViewLayoutType(@NonNull PostListViewLayoutType type) {
setLong(DeletablePrefKey.POST_LIST_VIEW_LAYOUT_TYPE, type.getId());
}

public static void setStatsWidgetSelectedSiteId(long siteId, int appWidgetId) {
prefs().edit().putLong(getSiteIdWidgetKey(appWidgetId), siteId).apply();
}
Expand Down
Loading
Loading