From 169f6f4a7974d501ae89f1f9a2d4aa5885ba99d2 Mon Sep 17 00:00:00 2001 From: Lucas Ruston Date: Sun, 28 Apr 2024 17:46:33 +0200 Subject: [PATCH] fix(like-recent): fix recent post by hashtag --- GramAddict/core/navigation.py | 6 ++---- GramAddict/core/resources.py | 2 ++ GramAddict/core/views.py | 40 ++++++++++++++++++++++++++--------- 3 files changed, 34 insertions(+), 14 deletions(-) diff --git a/GramAddict/core/navigation.py b/GramAddict/core/navigation.py index 49fa76e5..923feade 100644 --- a/GramAddict/core/navigation.py +++ b/GramAddict/core/navigation.py @@ -70,10 +70,8 @@ def nav_to_hashtag_or_place(device, target, current_job): if current_job.endswith("recent"): logger.info("Switching to Recent tab.") - recent_tab = TargetView(device)._getRecentTab() - if recent_tab.exists(Timeout.MEDIUM): - recent_tab.click() - else: + recent_tab_exists = TargetView(device)._navigateToRecentTab() + if not recent_tab_exists: return False if UniversalActions(device)._check_if_no_posts(): diff --git a/GramAddict/core/resources.py b/GramAddict/core/resources.py index af31e55d..fc6ae9d9 100644 --- a/GramAddict/core/resources.py +++ b/GramAddict/core/resources.py @@ -223,6 +223,8 @@ class TabBarText: POSTS_CONTENT_DESC = "Grid View" PROFILE_CONTENT_DESC = "Profile" RECENT_CONTENT_DESC = "Recent" + FILTER_CONTENT = "Filter" + FILTER_RECENT_CONTENT = "Recent top posts" REELS_CONTENT_DESC = "Reels" SEARCH_CONTENT_DESC = "Search and Explore" diff --git a/GramAddict/core/views.py b/GramAddict/core/views.py index fb2d0c07..ea2e6e4e 100644 --- a/GramAddict/core/views.py +++ b/GramAddict/core/views.py @@ -243,19 +243,30 @@ def _getFistImageView(self, recycler): logger.debug("First image in view doesn't exists.") return obj - def _getRecentTab(self): + def _navigateToRecentTab(self): obj = self.device.find( - className=ClassName.TEXT_VIEW, - textMatches=case_insensitive_re(TabBarText.RECENT_CONTENT_DESC), + textMatches=case_insensitive_re(TabBarText.FILTER_CONTENT), ) if obj.exists(Timeout.LONG): - logger.debug("Recent Tab exists.") + logger.debug("Filter option exists.") + obj.click() else: - logger.debug("Recent Tab doesn't exists.") - return obj + logger.debug("Filter option doesn't exists.") + return False + + obj = self.device.find( + textMatches=case_insensitive_re(TabBarText.FILTER_RECENT_CONTENT), + ) + if obj.exists(Timeout.SHORT): + logger.debug("Filter by recent posts") + obj.click() + else: + logger.debug("Filter by recent posts doesn't exists") + return False + return True -# The place view for the moment It's only a copy/paste of HashTagView +# The place view for the moment # Maybe we can add the com.instagram.android:id/category_name == "Country/Region" (or other obv) @@ -281,11 +292,16 @@ def _getFistImageView(self, recycler): logger.debug("First image in view doesn't exists.") return obj - def _getRecentTab(self): - return self.device.find( + def _navigateToRecentTab(self): + recent_tab = self.device.find( className=ClassName.TEXT_VIEW, textMatches=case_insensitive_re(TabBarText.RECENT_CONTENT_DESC), ) + if recent_tab.exists(Timeout.MEDIUM): + recent_tab.click() + return True + else: + return False def _getInformBody(self): return self.device.find( @@ -358,7 +374,9 @@ def _getTabTextView(self, tab: SearchTabs): tab_text_view = obj break return tab_text_view - return None + else: + logger.debug("Tabs container doesn't exists.") + return None def _searchTabWithTextPlaceholder(self, tab: SearchTabs): tab_layout = self.device.find( @@ -434,6 +452,8 @@ def _switch_to_target_tag(self, job: str): if obj is not None: logger.info(f"Switching to {tab.name}") obj.click() + else: + logger.debug("Impossible to switch to the target tab.") def _check_current_view( self, target: str, job: str, in_place_tab: bool = False