-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Issue/11119 search in set parent page #11269
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 20 commits into
wordpress-mobile:feature/master-search-in-set-parent-page
from
zwarm:issue/11119-search-in-set-parent-page
Feb 14, 2020
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
a3c55d4
Introduce new classes to manage the searching functionality
57cfc44
Update AppComponent to inject PageParentSearchFragment
163de54
Update ViewModelModule to for PageParentSearchViewModel
00f594b
Set up the search on the menu
b567f8f
Switch in a new xml file for PageParentFragment so it can be adjusted…
5a483ff
updated to include liveData searchPages
75c606f
Tie the search all together in the PageParentFragment (initializing, …
fb3a414
Added view model test for pageparentSearch
049978c
remove log line from hideSearchList fun
7af8211
Make sure the search icon shows on back tap
33aff7c
Fixed klint style errors
26a5c89
Merge branch 'feature/master-search-in-set-parent-page' into issue/11…
5f5832b
removed unused variables
13a5268
Moved pageParentSearchViewModel to the correct package to align with …
39aff7c
remove the search tap from the onOptionsItemSelected fun
8f30c21
guard null check with ?.let instead of separate statements
39bd891
Maintain search text across configuration change
eb0a0af
Removes the conversion to lowercase and uses contains with ignoreCase…
e9b4991
adjusted save button and parent selected functionality
d4000c0
reverting idea-codingStyles-project.xml back to the commit right befo…
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
57 changes: 57 additions & 0 deletions
57
WordPress/src/main/java/org/wordpress/android/ui/pages/PageParentSearchAdapter.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,57 @@ | ||
| package org.wordpress.android.ui.pages | ||
|
|
||
| import android.view.ViewGroup | ||
| import androidx.recyclerview.widget.DiffUtil | ||
| import androidx.recyclerview.widget.RecyclerView.Adapter | ||
| import kotlinx.coroutines.CoroutineScope | ||
| import kotlinx.coroutines.delay | ||
| import kotlinx.coroutines.launch | ||
| import org.wordpress.android.R.layout | ||
| import org.wordpress.android.ui.pages.PageItem.ParentPage | ||
| import org.wordpress.android.ui.pages.PageItemViewHolder.EmptyViewHolder | ||
| import org.wordpress.android.ui.pages.PageItemViewHolder.PageDividerViewHolder | ||
| import org.wordpress.android.ui.pages.PageItemViewHolder.PageParentViewHolder | ||
|
|
||
| class PageParentSearchAdapter( | ||
| private val onParentSelected: (ParentPage) -> Unit, | ||
| private val uiScope: CoroutineScope | ||
| ) : Adapter<PageItemViewHolder>() { | ||
| private val items = mutableListOf<PageItem>() | ||
| override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): PageItemViewHolder { | ||
| return when (viewType) { | ||
| PageItem.Type.PARENT.viewType -> PageParentViewHolder(parent, | ||
| this::selectParent, | ||
| layout.page_parent_list_item) | ||
| PageItem.Type.TOP_LEVEL_PARENT.viewType -> PageParentViewHolder(parent, | ||
| this::selectParent, | ||
| layout.page_parent_top_level_item) | ||
| PageItem.Type.DIVIDER.viewType -> PageDividerViewHolder(parent) | ||
| PageItem.Type.EMPTY.viewType -> EmptyViewHolder(parent) { } | ||
| else -> throw Throwable("Unexpected view type") | ||
| } | ||
| } | ||
|
|
||
| private fun selectParent(parent: ParentPage) { | ||
| onParentSelected(parent) | ||
| uiScope.launch { | ||
| delay(200) // let the selection animation play out before refreshing the list | ||
| notifyDataSetChanged() | ||
| } | ||
| } | ||
| override fun getItemCount(): Int = items.size | ||
|
|
||
| override fun getItemViewType(position: Int): Int { | ||
| return items[position].type.viewType | ||
| } | ||
|
|
||
| override fun onBindViewHolder(holder: PageItemViewHolder, position: Int) { | ||
| holder.onBind(items[position]) | ||
| } | ||
|
|
||
| fun update(result: List<PageItem>) { | ||
| val diffResult = DiffUtil.calculateDiff(PageItemDiffUtil(items.toList(), result)) | ||
| items.clear() | ||
| items.addAll(result) | ||
| diffResult.dispatchUpdatesTo(this) | ||
| } | ||
| } |
104 changes: 104 additions & 0 deletions
104
WordPress/src/main/java/org/wordpress/android/ui/pages/PageParentSearchFragment.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,104 @@ | ||
| package org.wordpress.android.ui.pages | ||
|
|
||
| import android.os.Bundle | ||
| import android.os.Parcelable | ||
| import android.view.LayoutInflater | ||
| import android.view.View | ||
| import android.view.ViewGroup | ||
| import androidx.fragment.app.Fragment | ||
| import androidx.fragment.app.FragmentActivity | ||
| import androidx.lifecycle.Observer | ||
| import androidx.lifecycle.ViewModelProvider | ||
| import androidx.lifecycle.ViewModelProviders | ||
| import androidx.recyclerview.widget.LinearLayoutManager | ||
| import androidx.recyclerview.widget.RecyclerView | ||
| import kotlinx.android.synthetic.main.pages_list_fragment.* | ||
| import kotlinx.coroutines.CoroutineScope | ||
| import org.wordpress.android.R | ||
| import org.wordpress.android.WordPress | ||
| import org.wordpress.android.modules.UI_SCOPE | ||
| import org.wordpress.android.util.DisplayUtils | ||
| import org.wordpress.android.viewmodel.pages.PageParentSearchViewModel | ||
| import org.wordpress.android.viewmodel.pages.PageParentViewModel | ||
| import org.wordpress.android.widgets.RecyclerItemDecoration | ||
| import javax.inject.Inject | ||
| import javax.inject.Named | ||
|
|
||
| class PageParentSearchFragment : Fragment() { | ||
| @Inject lateinit var viewModelFactory: ViewModelProvider.Factory | ||
| private lateinit var viewModel: PageParentSearchViewModel | ||
| @field:[Inject Named(UI_SCOPE)] lateinit var uiScope: CoroutineScope | ||
| private var linearLayoutManager: LinearLayoutManager? = null | ||
|
|
||
| private val listStateKey = "list_state" | ||
|
|
||
| companion object { | ||
| fun newInstance(): PageParentSearchFragment { | ||
| return PageParentSearchFragment() | ||
| } | ||
| } | ||
|
|
||
| override fun onCreateView( | ||
| inflater: LayoutInflater, | ||
| container: ViewGroup?, | ||
| savedInstanceState: Bundle? | ||
| ): View? { | ||
| return inflater.inflate(R.layout.pages_list_fragment, container, false) | ||
| } | ||
|
|
||
| override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||
| super.onViewCreated(view, savedInstanceState) | ||
| val nonNullActivity = checkNotNull(activity) | ||
| (nonNullActivity.application as? WordPress)?.component()?.inject(this) | ||
|
|
||
| initializeViews(savedInstanceState) | ||
| initializeViewModels(nonNullActivity) | ||
| } | ||
|
|
||
| override fun onSaveInstanceState(outState: Bundle) { | ||
| linearLayoutManager?.let { | ||
| outState.putParcelable(listStateKey, it.onSaveInstanceState()) | ||
| } | ||
| super.onSaveInstanceState(outState) | ||
| } | ||
|
|
||
| private fun initializeViewModels(activity: FragmentActivity) { | ||
| val pageParentViewModel = ViewModelProviders.of(activity, viewModelFactory) | ||
| .get(PageParentViewModel::class.java) | ||
|
|
||
| viewModel = ViewModelProviders.of(this, viewModelFactory) | ||
| .get(PageParentSearchViewModel::class.java) | ||
| viewModel.start(pageParentViewModel) | ||
|
|
||
| setupObservers() | ||
| } | ||
|
|
||
| private fun initializeViews(savedInstanceState: Bundle?) { | ||
| val layoutManager = LinearLayoutManager(activity, RecyclerView.VERTICAL, false) | ||
| savedInstanceState?.getParcelable<Parcelable>(listStateKey)?.let { | ||
| layoutManager.onRestoreInstanceState(it) | ||
| } | ||
|
|
||
| linearLayoutManager = layoutManager | ||
| recyclerView.layoutManager = linearLayoutManager | ||
| recyclerView.addItemDecoration(RecyclerItemDecoration(0, DisplayUtils.dpToPx(activity, 1))) | ||
| } | ||
|
|
||
| private fun setupObservers() { | ||
| viewModel.searchResult.observe(this, Observer { data -> | ||
| data?.let { setSearchResult(data) } | ||
| }) | ||
| } | ||
|
|
||
| private fun setSearchResult(pages: List<PageItem>) { | ||
| val adapter: PageParentSearchAdapter | ||
| if (recyclerView.adapter == null) { | ||
| adapter = PageParentSearchAdapter( | ||
| { page -> viewModel.onParentSelected(page) }, uiScope) | ||
| recyclerView.adapter = adapter | ||
| } else { | ||
| adapter = recyclerView.adapter as PageParentSearchAdapter | ||
| } | ||
| adapter.update(pages) | ||
| } | ||
| } |
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.