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

Start migration to Compose Navigation #1211

Open
wants to merge 8 commits into
base: main-ose
Choose a base branch
from

Conversation

ArnyminerZ
Copy link
Member

@ArnyminerZ ArnyminerZ commented Jan 1, 2025

Purpose

As the first step of #1172, started by renaming AccountsActivity to MainActivity, and start adding navigation functionality.

Short description

  • Renamed AccountsActivity and its usages to MainActivity.
  • Added the compose navigation dependency.
  • Added the first route to the nav graph: accounts list.
  • Added a method for initializing AccountsRoute from the intent data of MainActivity.
  • Added LocalNavController which holds a reference to the currently being used nav controller.
  • Moved injection of AccountsDrawerHandler from activity to model to decouple it completely from activities.

Checklist

  • The PR has a proper title, description and label.
  • I have self-reviewed the PR.
  • I have added documentation to complex functions and functions that can be used by other modules.
  • I have added reasonable tests or consciously decided to not add tests.

@ArnyminerZ ArnyminerZ added the refactoring Internal improvement of existing functions label Jan 1, 2025
@ArnyminerZ ArnyminerZ self-assigned this Jan 1, 2025
Signed-off-by: Arnau Mora <[email protected]>
@ArnyminerZ ArnyminerZ marked this pull request as ready for review January 1, 2025 16:31
@ArnyminerZ
Copy link
Member Author

I think this can be a good first PR on the topic.

@ArnyminerZ ArnyminerZ requested a review from rfc2822 January 1, 2025 16:31
Signed-off-by: Arnau Mora <[email protected]>
@ArnyminerZ ArnyminerZ removed the request for review from rfc2822 January 1, 2025 16:33
Signed-off-by: Arnau Mora <[email protected]>
@ArnyminerZ ArnyminerZ requested a review from rfc2822 January 1, 2025 16:34
Signed-off-by: Arnau Mora <[email protected]>
@ArnyminerZ
Copy link
Member Author

LocalNavController is used in order to access the nav controller from outside MainActivity. For example, from a composable:

@Composable
fun Example() {
  val navController = LocalNavController.current

  navController.navigate(ExampleRoute)

@ArnyminerZ ArnyminerZ changed the title Rename AccountsActivity to MainActivity Start migration to Compose Navigation Jan 1, 2025
Copy link
Member

@rfc2822 rfc2822 left a comment

Choose a reason for hiding this comment

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

Can we move the NavController to the navigation package? Just so that there are no packages that only contain one class.

But didn't have an in-depth look yet. Please @sunkup also have a look first (we can talk tomorrow about it).

@sunkup
Copy link
Member

sunkup commented Jan 2, 2025

Can we move the NavController to the navigation package? Just so that there are no packages that only contain one class.

But didn't have an in-depth look yet. Please @sunkup also have a look first (we can talk tomorrow about it).

@ArnyminerZ maybe you can make the suggested change and request a new review from me? I will use the opportunity to get to know compose navigation.

Signed-off-by: Arnau Mora <[email protected]>
@ArnyminerZ ArnyminerZ requested a review from sunkup January 2, 2025 13:53
# Conflicts:
#	app/src/main/kotlin/at/bitfire/davdroid/sync/account/AddressBookAuthenticatorService.kt
#	app/src/main/res/xml/sync_prefs.xml
@ArnyminerZ
Copy link
Member Author

maybe you can make the suggested change and request a new review from me?

Done

Copy link
Member

@sunkup sunkup left a comment

Choose a reason for hiding this comment

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

Looks really good!

For some reason I am sceptical about moving the AccountsDrawerHandler injection to the model. I feel like it does not really belong there, but in favor of the new navigation paradigm I can't give a good reason not to do it ...

See the comment about broken reference, but yeah, otherwise it's really nice.

Copy link
Member

Choose a reason for hiding this comment

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

Deleting the AccountsActivity breaks a reference from jtxBoard: "Drawermenu > Synchronization > Go to collections".

For now, since we don't want to break external references we would need to keep an AccountsActivity and have it redirect to the new MainActivity. See #1172 (comment)

@rfc2822
Copy link
Member

rfc2822 commented Jan 7, 2025

Also I think we could inject the AccountsDrawerHandler directly in MainActivity, rather than in a model. Because it's not really a state, and models are basically state holders (+ maybe a little logic).

Also, the idea is that the intro check occurs / the intro is potentially shown when the app UI starts. In the past we could only put it into the launcher activity (AccountsActivity) and hope that this is the first activity started.

In the future we could put it into the MainActivity.onCreate, and later maybe even in the MainActivity's composition.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactoring Internal improvement of existing functions
Projects
Status: Todo
Development

Successfully merging this pull request may close these issues.

3 participants