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

Fix recent post by hashtag #397

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
6 changes: 2 additions & 4 deletions GramAddict/core/navigation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
2 changes: 2 additions & 0 deletions GramAddict/core/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
40 changes: 30 additions & 10 deletions GramAddict/core/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand All @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand Down