doc:Added typing to the Anilist module

This commit is contained in:
Benex254
2024-08-05 09:46:54 +03:00
parent 047ce29da3
commit 2eca3f480d
28 changed files with 786 additions and 389 deletions

View File

@@ -23,4 +23,5 @@
text:"Status"
FilterDropDown:
id:status_filter
text:root.filters["status"]
on_release: root.open_filter_menu(self,"status")

View File

@@ -1,37 +1,80 @@
from kivy.properties import StringProperty,DictProperty
from kivy.properties import StringProperty, DictProperty
from kivymd.uix.boxlayout import MDBoxLayout
from kivymd.uix.dropdownitem import MDDropDownItem
from kivymd.uix.menu import MDDropdownMenu
class FilterDropDown(MDDropDownItem):
text:str = StringProperty()
text: str = StringProperty()
class Filters(MDBoxLayout):
filters:dict = DictProperty({
"sort":"SEARCH_MATCH"
})
filters: dict = DictProperty({"sort": "SEARCH_MATCH", "status": "FINISHED"})
def open_filter_menu(self, menu_item,filter_name):
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"]
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"]
items = [
"FINISHED",
"RELEASING",
"NOT_YET_RELEASED",
"CANCELLED",
"HIATUS",
]
case _:
items = []
if 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
"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):
def filter_menu_callback(self, filter_name, filter_value):
match filter_name:
case "sort":
self.ids.sort_filter.text = filter_value
@@ -39,4 +82,3 @@ class Filters(MDBoxLayout):
case "status":
self.ids.status_filter.text = filter_value
self.filters["status"] = filter_value

View File

@@ -1,12 +1,12 @@
<PaginationLabel@MDLabel>
<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

View File

@@ -1,9 +1,9 @@
from kivy.properties import ObjectProperty,NumericProperty
from kivy.properties import ObjectProperty, NumericProperty
from kivymd.uix.boxlayout import MDBoxLayout
class SearchResultsPagination(MDBoxLayout):
current_page = NumericProperty()
total_pages = NumericProperty()
search_view = ObjectProperty()

View File

@@ -1,4 +1,5 @@
from kivymd.uix.boxlayout import MDBoxLayout
class TrendingAnimeSideBar(MDBoxLayout):
pass

View File

@@ -50,18 +50,16 @@
size_hint_x:None
width: dp(250)
MDLabel:
md_bg_color:self.theme_cls.secondaryContainerColor
text:"Trending"
adaptive_height:True
halign:"center"
max_lines:0
# md_bg_color:Stat
shorten:False
bold:True
markup:True
font_style: "Label"
role: "large"
text:"Trending"
padding:"10dp"
MDScrollView:
TrendingAnimeSideBar:
id:trending_anime_sidebar

View File

@@ -1,44 +1,56 @@
from kivy.properties import ObjectProperty,StringProperty
from kivy.properties import ObjectProperty, StringProperty
from kivy.clock import Clock
from View.base_screen import BaseScreenView
from .components import TrendingAnimeSideBar,Filters,SearchResultsPagination
from .components import TrendingAnimeSideBar, Filters, SearchResultsPagination
class SearchScreenView(BaseScreenView):
trending_anime_sidebar:TrendingAnimeSideBar = ObjectProperty()
search_results_pagination:SearchResultsPagination = ObjectProperty()
filters:Filters = ObjectProperty()
class SearchScreenView(BaseScreenView):
trending_anime_sidebar: TrendingAnimeSideBar = ObjectProperty()
search_results_pagination: SearchResultsPagination = ObjectProperty()
filters: Filters = ObjectProperty()
search_results_container = ObjectProperty()
search_term:str = StringProperty()
search_term: str = StringProperty()
is_searching = False
has_next_page = False
current_page = 0
total_pages = 0
def handle_search_for_anime(self,search_widget=None,page=None):
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):
if search_term and not (self.is_searching):
self.search_term = search_term
self.search_results_container.clear_widgets()
if filters:=self.filters.filters:
Clock.schedule_once(lambda _:self.controller.requested_search_for_anime(search_term,**filters,page=page))
if filters := self.filters.filters:
Clock.schedule_once(
lambda _: self.controller.requested_search_for_anime(
search_term, **filters, page=page
)
)
else:
Clock.schedule_once(lambda _:self.controller.requested_search_for_anime(search_term,page=page))
def update_layout(self,widget):
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 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 = max(int(pagination_info["total"]/30),1)
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 = max(
int(pagination_info["total"] / 30), 1
)
self.has_next_page = pagination_info["hasNextPage"]
def next_page(self):
@@ -51,5 +63,5 @@ class SearchScreenView(BaseScreenView):
page = self.current_page - 1
self.handle_search_for_anime(page=page)
def update_trending_sidebar(self,trending_anime):
def update_trending_sidebar(self, trending_anime):
self.trending_anime_sidebar.add_widget(trending_anime)