successfully completed search page

This commit is contained in:
Benedict Xavier Wanyonyi
2024-05-22 09:39:19 +03:00
parent 58e57f45c8
commit 0154f109bf
60 changed files with 4819 additions and 678 deletions

View File

@@ -0,0 +1,27 @@
<FilterDropDown>:
MDDropDownItemText:
text: root.text
<FilterLabel@MDLabel>:
adaptive_width:True
<Filters>:
adaptive_height:True
spacing:"10dp"
size_hint_x:.95
pos_hint:{"center_x":.5}
padding:"10dp"
md_bg_color:self.theme_cls.surfaceContainerLowColor
FilterLabel:
text:"Sort By"
FilterDropDown:
id:sort_filter
text:root.filters["sort"]
on_release: root.open_filter_menu(self,"sort")
FilterLabel:
text:"Status"
FilterDropDown:
id:status_filter
# text:root.filters["status"]
on_release: root.open_filter_menu(self,"status")

View File

@@ -0,0 +1,21 @@
<PaginationLabel@MDLabel>
max_lines:0
shorten:False
markup:True
adaptive_height:True
font_style: "Label"
pos_hint:{"center_y":.5}
halign:"center"
role: "medium"
<SearchResultsPagination>:
md_bg_color:self.theme_cls.surfaceContainerLowColor
radius:8
adaptive_height:True
MDIconButton:
icon:"arrow-left"
on_release:root.search_view.previous_page()
PaginationLabel:
text:"Page {} of {}".format(root.current_page,root.total_pages)
MDIconButton:
icon:"arrow-right"
on_release:root.search_view.next_page()

View File

@@ -0,0 +1,6 @@
<TrendingAnimeSideBar>:
orientation: 'vertical'
adaptive_height:True
md_bg_color:self.theme_cls.surfaceContainerLowColor
pos_hint: {'center_x': 0.5}
padding:"25dp","25dp","25dp","200dp"

View File

@@ -1,40 +1,13 @@
<SearchScreenView>
md_bg_color: self.theme_cls.backgroundColor
search_results_container:search_results_container
trending_anime_sidebar:trending_anime_sidebar
search_results_pagination:search_results_pagination
filters:filters
MDBoxLayout:
size_hint:1,1
MDNavigationRail:
anchor:"top"
type: "selected"
md_bg_color: self.theme_cls.secondaryContainerColor
MDNavigationRailFabButton:
icon: "home"
on_release:
root.manager_screens.current = "main screen"
CommonNavigationRailItem:
icon: "magnify"
text: "Search"
# on_release:
# root.manager_screens.current_screen = "search screen"
CommonNavigationRailItem:
icon: "bookmark-outline"
text: "My Anime List"
on_release:
root.manager_screens.current = "my list screen"
CommonNavigationRailItem:
icon: "library-outline"
text: "Library"
CommonNavigationRailItem:
icon: "cog"
text: "settings"
# ScreenManager:
# MDScreen:
# name:"main"
NavRail:
screen:root
MDAnchorLayout:
anchor_y: 'top'
padding:"10dp"
@@ -42,39 +15,53 @@
MDBoxLayout:
orientation: 'vertical'
id:p
size_hint:1,1
SearchBar:
MDBoxLayout:
pos_hint: {'center_x': 0.5,'top': 1}
padding: "10dp"
size_hint_y:None
height: self.minimum_height
size_hint_x:.75
spacing: '20dp'
MDTextField:
size_hint_x:1
required:True
on_text_validate:
root.handle_search_for_anime(args[0])
MDTextFieldLeadingIcon:
icon: "magnify"
MDTextFieldHintText:
text: "Search for anime"
# MDTextFieldTrailingIcon:
# icon: "filter"
MDIconButton:
pos_hint: {'center_y': 0.5}
icon: "account-circle"
# size: 32,32
MDScrollView:
size_hint:1,1
MDGridLayout:
id:search_results_container
spacing: '10dp'
padding: "75dp","75dp","10dp","200dp"
cols:5
size_hint_y:None
height:self.minimum_height
spacing:"20dp"
padding:"75dp","10dp","100dp","0dp"
MDBoxLayout:
orientation: 'vertical'
size_hint:1,1
Filters:
id:filters
MDBoxLayout:
spacing:"20dp"
MDScrollView:
size_hint:1,1
MDBoxLayout:
orientation: 'vertical'
size_hint_y:None
height:self.minimum_height
MDGridLayout:
pos_hint: {'center_x': 0.5}
id:search_results_container
spacing: '40dp'
padding: "75dp","50dp","75dp","200dp"
cols:5
size_hint_y:None
height:self.minimum_height
SearchResultsPagination:
id:search_results_pagination
search_view:root
MDBoxLayout:
orientation:"vertical"
size_hint_y:1
size_hint_x:None
width: dp(250)
MDLabel:
adaptive_height:True
halign:"center"
max_lines:0
shorten:False
bold:True
markup:True
font_style: "Label"
role: "large"
text:"Trending"
md_bg_color:self.theme_cls.secondaryContainerColor
padding:"10dp"
MDScrollView:
TrendingAnimeSideBar:
id:trending_anime_sidebar

View File

@@ -1,12 +1,64 @@
from kivy.properties import ObjectProperty,StringProperty,DictProperty
from kivy.properties import ObjectProperty,StringProperty,DictProperty,NumericProperty
from View.base_screen import BaseScreenView
from kivymd.uix.dropdownitem import MDDropDownItem
from kivymd.uix.menu import MDDropdownMenu
from kivymd.uix.boxlayout import MDBoxLayout
from kivy.clock import Clock
class SearchScreenView(BaseScreenView):
class FilterDropDown(MDDropDownItem):
text = StringProperty()
class Filters(MDBoxLayout):
filters = DictProperty({
"sort":"SEARCH_MATCH"
})
def open_filter_menu(self, menu_item,filter_name):
items = []
match filter_name:
case "sort":
items = ["ID","ID_DESC", "TITLE_ROMANJI", "TITLE_ROMANJI_DESC", "TITLE_ENGLISH", "TITLE_ENGLISH_DESC", "TITLE_NATIVE", "TITLE_NATIVE_DESC", "TYPE", "TYPE_DESC", "FORMAT", "FORMAT_DESC", "START_DATE", "START_DATE_DESC", "END_DATE", "END_DATE_DESC", "SCORE", "SCORE_DESC", "TRENDING", "TRENDING_DESC", "EPISODES", "EPISODES_DESC", "DURATION", "DURATION_DESC", "STATUS", "STATUS_DESC", "UPDATED_AT", "UPDATED_AT_DESC", "SEARCH_MATCH" "POPULARITY","POPULARITY_DESC","FAVOURITES","FAVOURITES_DESC"]
case "status":
items = ["FINISHED", "RELEASING", "NOT_YET_RELEASED", "CANCELLED", "HIATUS"]
case _:
items = []
if items:
menu_items = [
{
"text": f"{item}",
"on_release": lambda filter_value=f"{item}": self.filter_menu_callback(filter_name,filter_value),
} for item in items
]
MDDropdownMenu(caller=menu_item, items=menu_items).open()
def filter_menu_callback(self, filter_name,filter_value):
match filter_name:
case "sort":
self.ids.sort_filter.text = filter_value
self.filters["sort"] = filter_value
case "status":
self.ids.status_filter.text = filter_value
self.filters["status"] = filter_value
class SearchResultsPagination(MDBoxLayout):
current_page = NumericProperty()
total_pages = NumericProperty()
search_view = ObjectProperty()
class TrendingAnimeSideBar(MDBoxLayout):
pass
class SearchScreenView(BaseScreenView):
search_results_container = ObjectProperty()
trending_anime_sidebar = ObjectProperty()
search_results_pagination = ObjectProperty()
search_term = StringProperty()
filters = DictProperty()
filters = ObjectProperty()
is_searching = False
has_next_page = False
current_page = 0
total_pages = 0
def model_is_changed(self) -> None:
"""
Called whenever any change has occurred in the data model.
@@ -14,18 +66,39 @@ class SearchScreenView(BaseScreenView):
according to these changes.
"""
def handle_search_for_anime(self,search_widget):
search_term = search_widget.text
def handle_search_for_anime(self,search_widget=None,page=None):
if search_widget:
search_term = search_widget.text
elif page:
search_term = self.search_term
else:
return
if search_term and not(self.is_searching):
self.search_term = search_term
self.search_results_container.clear_widgets()
if self.filters:
self.controller.requested_search_for_anime(search_term,**self.filters)
if filters:=self.filters.filters:
Clock.schedule_once(lambda _:self.controller.requested_search_for_anime(search_term,**filters,page=page))
else:
self.controller.requested_search_for_anime(search_term)
Clock.schedule_once(lambda _:self.controller.requested_search_for_anime(search_term,page=page))
def update_layout(self,widget):
self.search_results_container.add_widget(widget)
def add_pagination(self,pagination_info):
pass
def update_pagination(self,pagination_info):
self.search_results_pagination.current_page =self.current_page = pagination_info["currentPage"]
self.search_results_pagination.total_pages = self.total_pages = pagination_info["total"]
self.has_next_page = pagination_info["hasNextPage"]
def next_page(self):
if self.has_next_page:
page = self.current_page + 1
self.handle_search_for_anime(page=page)
def previous_page(self):
if self.current_page > 1:
page = self.current_page - 1
self.handle_search_for_anime(page=page)
def update_trending_sidebar(self,trending_anime):
self.trending_anime_sidebar.add_widget(trending_anime)