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

Mobileapps 842 #49

Merged
merged 20 commits into from
Nov 3, 2021
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 @@ -39,7 +39,6 @@ class SearchRepository(val session: Session = SessionManager.requireSession) {
skipCount: Int,
maxItems: Int
) = if (filters.contains(SearchFilter.Libraries)) {
println("type filter query libraries")
ResponsePaging.with(
queryService.findSites(
terms,
Expand All @@ -48,7 +47,6 @@ class SearchRepository(val session: Session = SessionManager.requireSession) {
)
)
} else if (advanceSearchFilters.isNotEmpty()) {
println("type filter query advance")
ResponsePaging.with(
searchService.advanceSearch(
terms,
Expand All @@ -59,7 +57,6 @@ class SearchRepository(val session: Session = SessionManager.requireSession) {
)
)
} else {
println("type filter query simple")
ResponsePaging.with(
searchService.simpleSearch(
terms,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,17 @@ data class SearchChipCategory(
selectedQuery = "+TYPE:'${contextual.name}'"
)
}

/**
* returns the default searchChipCategory object
*/
fun resetData(searchChipCategory: SearchChipCategory): SearchChipCategory {
return SearchChipCategory(
category = searchChipCategory.category,
isSelected = searchChipCategory.category.component == null,
selectedName = "",
selectedQuery = ""
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,11 @@ class SearchFragment : Fragment(), MavericksView {
private fun setAdvanceSearchFiltersData() {
withState(viewModel) {
if (viewModel.isShowAdvanceFilterView(it.listSearchFilters)) {
binding.rlDropDownSearch.visibility = View.VISIBLE
binding.parentAdvanceSearch.visibility = View.VISIBLE
binding.chipGroup.visibility = View.GONE
setupDropDown()
} else {
binding.rlDropDownSearch.visibility = View.GONE
binding.parentAdvanceSearch.visibility = View.GONE
binding.chipGroup.visibility = View.VISIBLE
setupChips()
}
Expand Down Expand Up @@ -202,8 +202,15 @@ class SearchFragment : Fragment(), MavericksView {
searchFilterPopup.setAdapter(adapter)

withState(viewModel) { state ->
if (state.selectedFilterIndex == -1)
viewModel.copyFilterIndex(viewModel.getDefaultSearchFilterIndex(state.listSearchFilters))
var index = state.selectedFilterIndex
if (state.selectedFilterIndex == -1) {
index = viewModel.getDefaultSearchFilterIndex(state.listSearchFilters)
viewModel.copyFilterIndex(index)
}
when (searchFilters?.get(index)?.resetButton) {
true -> binding.actionReset.visibility = View.VISIBLE
false -> binding.actionReset.visibility = View.GONE
}
}

searchFilterPopup.setOnItemClickListener { _: AdapterView<*>?, _: View?, position: Int, _: Long ->
Expand All @@ -228,6 +235,12 @@ class SearchFragment : Fragment(), MavericksView {
}
}
binding.rlDropDownSearch.setOnClickListener { searchFilterPopup.show() }
binding.actionReset.setOnClickListener { resetAllFilters() }
}

private fun resetAllFilters() = withState(viewModel) { state ->
val listReset = viewModel.resetChips(state)
applyAdvanceFilters(state.selectedFilterIndex, listReset)
}

private fun setSearchFilterLocalizedName(state: SearchResultsState) {
Expand Down Expand Up @@ -304,6 +317,7 @@ class SearchFragment : Fragment(), MavericksView {

if (filterIndex != -1) {
val searchChipCategory = state.listSearchCategoryChips?.toMutableList()

var contextualSearchChipCategory: SearchChipCategory? = null
if (state.filters.contains(SearchFilter.Contextual)) {
contextualSearchChipCategory = SearchChipCategory.withContextual(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,13 +248,26 @@ class SearchViewModel(
return list
}

/**
* reset all the selected filters to default values
*/
fun resetChips(state: SearchResultsState): MutableList<SearchChipCategory> {
val list = mutableListOf<SearchChipCategory>()
state.listSearchCategoryChips?.forEach { obj ->
list.add(SearchChipCategory.resetData(obj))
}
setState { copy(listSearchCategoryChips = list) }

return list
}

/**
* update isSelected when chip is selected
*/
fun updateSelected(state: SearchResultsState, model: SearchChipCategory, isSelected: Boolean) {
val list = mutableListOf<SearchChipCategory>()

state.listSearchCategoryChips?.forEachIndexed { index, obj ->
state.listSearchCategoryChips?.forEach { obj ->
if (obj == model) {
list.add(
SearchChipCategory(
Expand Down
10 changes: 10 additions & 0 deletions search/src/main/res/drawable/ic_component_reset.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="32dp"
android:height="32dp"
android:viewportWidth="32"
android:viewportHeight="32">
<path
android:fillAlpha="0.6"
android:fillColor="?attr/colorOnSurface"
android:pathData="M21.645,10.35C20.195,8.9 18.205,8 15.995,8C11.575,8 8.005,11.58 8.005,16C8.005,20.42 11.575,24 15.995,24C19.725,24 22.835,21.45 23.725,18H21.645C20.825,20.33 18.605,22 15.995,22C12.685,22 9.995,19.31 9.995,16C9.995,12.69 12.685,10 15.995,10C17.655,10 19.135,10.69 20.215,11.78L16.995,15H23.995V8L21.645,10.35Z" />
</vector>
68 changes: 44 additions & 24 deletions search/src/main/res/layout/fragment_search.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,37 +17,57 @@
android:layout_gravity="top" />
</FrameLayout>

<RelativeLayout
android:id="@+id/rl_drop_down_search"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="24dp"
android:orientation="horizontal"
android:visibility="gone">

<TextView
android:id="@+id/text_search_filter_title"
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/parent_advance_search"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<RelativeLayout
android:id="@+id/rl_drop_down_search"
android:layout_width="wrap_content"
android:layout_height="32dp"
android:layout_centerVertical="true"
android:gravity="center_vertical"
android:text="@string/advance_search_title"
android:textAppearance="?attr/textAppearanceSubtitle2"
android:textColor="@color/color_search_filter"
android:textStyle="bold" />
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="24dp"
android:visibility="visible"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">

<TextView
android:id="@+id/text_search_filter_title"
android:layout_width="wrap_content"
android:layout_height="32dp"
android:layout_centerVertical="true"
android:gravity="center_vertical"
android:text="@string/advance_search_title"
android:textAppearance="?attr/textAppearanceSubtitle2"
android:textColor="@color/color_search_filter"
android:textStyle="bold" />

<ImageView
android:id="@+id/action_down"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="18dp"
android:layout_toEndOf="@id/text_search_filter_title"
android:contentDescription="@string/advance_search_title"
android:src="@drawable/ic_arrow_down_24" />


</RelativeLayout>

<ImageView
android:id="@+id/action_down"
android:id="@+id/action_reset"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="18dp"
android:layout_toEndOf="@id/text_search_filter_title"
android:layout_alignParentEnd="true"
android:layout_marginEnd="16dp"
android:contentDescription="@string/advance_search_title"
android:src="@drawable/ic_arrow_down_24" />

android:src="@drawable/ic_component_reset"
app:layout_constraintBottom_toBottomOf="@id/rl_drop_down_search"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="@id/rl_drop_down_search" />

</RelativeLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

<RelativeLayout
android:layout_width="match_parent"
Expand Down