-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from hotwired/session-config
Simplify initial app setup with a `SessionConfiguration`
- Loading branch information
Showing
23 changed files
with
257 additions
and
217 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
core/src/main/kotlin/dev/hotwire/core/navigation/activities/HotwireActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package dev.hotwire.core.navigation.activities | ||
|
||
import androidx.appcompat.app.AppCompatActivity | ||
import dev.hotwire.core.navigation.session.SessionConfiguration | ||
import dev.hotwire.core.navigation.session.SessionNavHostFragment | ||
|
||
/** | ||
* Interface that should be implemented by any Activity using Turbo. Ensures that the | ||
* Activity provides a [HotwireActivityDelegate] so the framework can initialize the | ||
* [SessionNavHostFragment] hosted in your Activity's layout resource. | ||
*/ | ||
interface HotwireActivity { | ||
val delegate: HotwireActivityDelegate | ||
val appCompatActivity: AppCompatActivity | ||
fun sessionConfigurations(): List<SessionConfiguration> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 12 additions & 4 deletions
16
core/src/main/kotlin/dev/hotwire/core/navigation/routing/AppNavigationRoute.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,26 @@ | ||
package dev.hotwire.core.navigation.routing | ||
|
||
import androidx.appcompat.app.AppCompatActivity | ||
import androidx.core.net.toUri | ||
import dev.hotwire.core.navigation.activities.HotwireActivity | ||
import dev.hotwire.core.navigation.session.SessionConfiguration | ||
|
||
class AppNavigationRoute : Router.Route { | ||
override val name = "app-navigation" | ||
|
||
override val result = Router.RouteResult.NAVIGATE | ||
|
||
override fun matches(location: String): Boolean { | ||
return appUrl.toUri().host == location.toUri().host | ||
override fun matches( | ||
location: String, | ||
sessionConfiguration: SessionConfiguration | ||
): Boolean { | ||
return sessionConfiguration.startLocation.toUri().host == location.toUri().host | ||
} | ||
|
||
override fun handle(location: String, activity: AppCompatActivity) { | ||
override fun handle( | ||
location: String, | ||
sessionConfiguration: SessionConfiguration, | ||
activity: HotwireActivity | ||
) { | ||
// No-op | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
core/src/main/kotlin/dev/hotwire/core/navigation/session/SessionConfiguration.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package dev.hotwire.core.navigation.session | ||
|
||
import androidx.annotation.IdRes | ||
|
||
data class SessionConfiguration( | ||
val name: String, | ||
val startLocation: String, | ||
@IdRes val navHostFragmentId: Int, | ||
) |
Oops, something went wrong.