Skip to content

feat(android): implement auto-reverse route for Android widget#577

Merged
guytepper merged 10 commits intomainfrom
feature/widget-auto-reverse
Feb 17, 2026
Merged

feat(android): implement auto-reverse route for Android widget#577
guytepper merged 10 commits intomainfrom
feature/widget-auto-reverse

Conversation

@drehelis
Copy link
Copy Markdown
Member

image

@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello @drehelis, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a significant quality-of-life improvement for Android widget users by implementing an 'auto-reverse route' functionality. This feature intelligently swaps the origin and destination of a widget's displayed route based on the time of day, catering to typical morning and evening commute patterns. It also provides users with the ability to temporarily override this automatic behavior. The changes span across UI, data storage, and core logic to seamlessly integrate this new smart commuting option.

Highlights

  • New Feature: Auto-Reverse Route for Android Widget: Implemented a new 'Smart Commute Window' option for Android widgets that automatically reverses the route direction based on predefined morning (1 AM - 1 PM) and evening (1 PM - 1 AM) time windows. This feature aims to streamline daily commutes by intelligently adapting the displayed route.
  • Manual Override for Auto-Reverse: Users can now manually override the auto-reverse behavior for the current time window by tapping the widget. The override remains active until the start of the next time window, providing flexibility.
  • Widget Configuration UI Updates: Added a new checkbox and descriptive text in the widget configuration activity to enable and explain the auto-reverse route feature. The advanced options section now auto-expands if auto-reverse is enabled.
  • Data Model and Persistence Changes: The WidgetData model and ModernWidgetPreferencesRepository were updated to store the new autoReverseRoute boolean and manualOverrideUntil timestamp, ensuring the feature's state is persisted across app sessions.
  • Refactored Date Calculation Logic: Improved the getDaysFromToday method in ModernBaseWidgetProvider.kt for more accurate date comparisons by stripping time components, and introduced a new stripTime helper function.
  • Internationalization Updates: Updated string resources for English, Hebrew, and Russian to include new texts for the auto-reverse route feature and refined existing widget-related descriptions for clarity.
  • Minor UI/UX Improvements: Adjusted the status bar icon color based on the current theme in BaseWidgetConfigActivity.kt and wrapped the advanced options chevron in a FrameLayout for improved touch target.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • android/app/src/main/java/com/betterrail/widget/BaseWidgetConfigActivity.kt
    • Added autoReverseRouteCheckbox declaration and initialization.
    • Implemented logic to set status bar icon color based on theme.
    • Initialized autoReverseRouteCheckbox to false by default.
    • Updated loadWidgetData to set the state of autoReverseRouteCheckbox and modified the condition for auto-expanding advanced options.
    • Adjusted isFilterChange logic to consider changes in autoReverseRouteCheckbox state.
    • Included autoReverseRoute and manualOverrideUntil when creating WidgetData.
  • android/app/src/main/java/com/betterrail/widget/ModernBaseWidgetProvider.kt
    • Modified onUpdate to retrieve effective widget data using getEffectiveWidgetData.
    • Updated handleAction for ACTION_TOGGLE_ROUTE_REVERSAL to incorporate smart override logic for auto-reverse routes, while maintaining legacy swap logic for non-auto-reverse routes.
    • Introduced getEffectiveWidgetData method to apply auto-reverse logic based on time and manual override status.
    • Added calculateNextWindowStart method to determine the timestamp for the start of the next time window.
    • Refactored getDaysFromToday to use stripTime for more accurate date comparisons.
    • Added a private stripTime helper function to clear time components from Calendar instances.
  • android/app/src/main/java/com/betterrail/widget/data/TrainModels.kt
    • Added autoReverseRoute (Boolean) and manualOverrideUntil (Long) fields to the WidgetData data class.
  • android/app/src/main/java/com/betterrail/widget/repository/ModernWidgetPreferencesRepository.kt
    • Added new preference keys for autoReverseRoute and manualOverrideUntil.
    • Updated getWidgetData, saveWidgetData, deleteWidgetData, and getAllWidgetData to correctly handle the new autoReverseRoute and manualOverrideUntil fields for persistence.
  • android/app/src/main/res/layout/activity_widget_config.xml
    • Wrapped the advanced_chevron TextView within a FrameLayout to improve its touch target area.
    • Added a new CheckBox with ID auto_reverse_route_checkbox and a descriptive TextView for the auto-reverse route option.
  • android/app/src/main/res/values-iw/strings.xml
    • Updated existing widget-related string resources for clarity.
    • Added new string resources for widget_auto_reverse_route and widget_auto_reverse_description.
  • android/app/src/main/res/values-ru/strings.xml
    • Updated existing widget-related string resources for clarity.
    • Added new string resources for widget_auto_reverse_route and widget_auto_reverse_description.
  • android/app/src/main/res/values/strings.xml
    • Updated existing widget-related string resources for clarity.
    • Added new string resources for widget_auto_reverse_route and widget_auto_reverse_description.
Activity
  • No specific activity (comments, reviews, or progress updates) has been recorded for this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces an auto-reverse route feature for the Android widget, which automatically swaps the origin and destination based on the time of day. The implementation includes the necessary UI in the widget configuration screen, data model updates, and the core logic in the widget provider.

My review has identified a few areas for improvement:

  • There's an opportunity to modernize the code by replacing deprecated APIs for status bar styling.
  • The date and time logic relies on the legacy java.util.Calendar API, which could be updated to the more robust java.time API.
  • I also found a bug in a user-facing string for the new feature in the Hebrew translation.

Overall, this is a great addition. The code is well-structured, and the new feature logic is cleverly implemented.

<item>רכבות ישירות בלבד</item>
<item>החלפה אחת לכל היותר</item>
</string-array>
<string name="widget_auto_reverse_route">היפוך מסלול אוטומטי (01:00 - 13:00)</string>
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The time window specified in the Hebrew string for widget_auto_reverse_route is (01:00 - 13:00), which corresponds to the morning window. However, the implementation in getEffectiveWidgetData reverses the route during the evening window (13:00 - 01:00). The English and Russian translations correctly reflect this. This discrepancy will likely confuse users. The string should be updated to show the correct time window for the automatic reversal.

Suggested change
<string name="widget_auto_reverse_route">היפוך מסלול אוטומטי (01:00 - 13:00)</string>
<string name="widget_auto_reverse_route">היפוך מסלול אוטומטי (13:00 - 01:00)</string>

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

even thought this is in hebrew, we read time left->right, no? @guytepper wdys?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i wouldn't use timestamps here. perhaps היפוך מסלול בוקר/ערב

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i want user to have clarity when widget scheduled to swap, otherwise, how would they know?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you're giving them enough clarity - morning & evening.
why would it matter if they know the exact times?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I later plan to add a drop down to customize those, android users wants their freedom 😎

Comment thread android/app/src/main/java/com/betterrail/widget/BaseWidgetConfigActivity.kt Outdated
@guytepper
Copy link
Copy Markdown
Member

/publish

@guytepper
Copy link
Copy Markdown
Member

/publish

@guytepper guytepper merged commit 99654eb into main Feb 17, 2026
1 of 2 checks passed
@guytepper guytepper deleted the feature/widget-auto-reverse branch February 17, 2026 11:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants