Skip to content

Commit

Permalink
Merge pull request #473 from splendo/release/0.2.3
Browse files Browse the repository at this point in the history
Release version 0.2.3
  • Loading branch information
Daeda88 authored Feb 18, 2022
2 parents 7b88ae4 + d4ec69e commit f9d779c
Show file tree
Hide file tree
Showing 846 changed files with 54,839 additions and 1,329 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ hs_err_pid*
build/
DerivedData/
.gradle/
/kotlin-js-store/

## Various settings
*.pbxuser
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ Module | Usage | Artifact Name
[architecture](architecture/) | MVVM architecture | com.splendo.kaluga:architecture
[architecture-compose](architecture-compose/) | Compose extensions for architecture | com.splendo.kaluga:architecture-compose
[base](base/) | Core components of Kaluga. Contains threading, flowables and localization features | com.splendo.kaluga.base
[date-time](date-time/) | Contains multiplatform classes to work with date and time | com.splendo.kaluga.date-time
[date-timepicker](date-time-picker/) | Used for showing a Date or Time Picker | com.splendo.kaluga.date-time-picker
[hud](hud/) | Used for showing a Loading indicator HUD | com.splendo.kaluga.hud
[keyboard](keyboard/) | Used for showing and hiding the keyboard | com.splendo.kaluga.keyboard
Expand All @@ -123,6 +124,7 @@ Module | Usage | Artifact Name
[storage-permissions](storage-permissions/) | Managing storage permissions | com.splendo.kaluga:storage-permissions
[resources](resources/) | Provides shared Strings, Images, Colors and Fonts | com.splendo.kaluga.resources
[review](review/) | Used for requesting the user to review the app | com.splendo.kaluga.review
[scientific](scientific/) | Scientific units and conversions | com.splendo.kaluga.scientific
[system](system/) | System APIs such as network, audio, battery | com.splendo.kaluga.system
[test-utils](test-utils/) | Enables easier testing of Kaluga components | com.splendo.kaluga.test-utils

Expand Down
1 change: 1 addition & 0 deletions alerts/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ kotlin {
val ext = (gradle as ExtensionAware).extra
implementation(project(":architecture", ""))
implementation(project(":base", ""))
implementation(project(":resources", ""))
}
}
getByName("commonTest") {
Expand Down
12 changes: 2 additions & 10 deletions alerts/src/androidLibMain/kotlin/AlertPresenter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import android.content.Context
import android.text.Editable
import android.text.InputType
import android.text.TextWatcher
import android.util.TypedValue
import android.view.ViewGroup
import android.widget.EditText
import android.widget.LinearLayout
Expand All @@ -32,6 +31,7 @@ import com.splendo.kaluga.architecture.lifecycle.LifecycleSubscribable
import com.splendo.kaluga.architecture.lifecycle.getOrPutAndRemoveOnDestroyFromCache
import com.splendo.kaluga.architecture.lifecycle.lifecycleManagerObserver
import com.splendo.kaluga.base.utils.applyIf
import com.splendo.kaluga.resources.dpToPixel
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.collect
Expand Down Expand Up @@ -167,7 +167,7 @@ actual class AlertPresenter(
editText.layoutParams = layoutParams
linearLayout.addView(editText)
val padding =
context.resources.getDimension(R.dimen.dialog_text_input_padding).dpToPx(context)
context.resources.getDimension(R.dimen.dialog_text_input_padding).dpToPixel(context).toInt()
linearLayout.setPaddingRelative(padding, 0, padding, 0)
editText.inputType = InputType.TYPE_CLASS_TEXT
editText.addTextChangedListener(object : TextWatcher {
Expand Down Expand Up @@ -212,11 +212,3 @@ fun AppCompatActivity.alertPresenterBuilder(): AlertPresenter.Builder =
getOrPutAndRemoveOnDestroyFromCache {
AlertPresenter.Builder(lifecycleManagerObserver())
}

fun Float.dpToPx(context: Context): Int {
return TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_DIP,
this,
context.resources.displayMetrics
).toInt()
}
3 changes: 2 additions & 1 deletion androidtesthelper/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ dependencies {
androidTestImplementation("co.touchlab:stately-iso-collections:$gradle.stately_isolate_version")

def excluded = ["androidtesthelper", // this project
"architecture-compose" // TODO, Compose in test helper not yet supported
"architecture-compose",
"resources-compose" // TODO, Compose in test helper not yet supported
]
rootProject.subprojects.findAll{ !excluded.contains(it.name) }.each {
implementation project(path: ":$it.name")
Expand Down
190 changes: 163 additions & 27 deletions architecture-compose/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ dependencies {
```

## Usage
###Examples
### Examples

#### Display content using a local data model

Expand Down Expand Up @@ -71,48 +71,66 @@ fun ContactDetailsLayout(

```kotlin
// Define an action mapper for a route navigator
fun routeMapper(action: ContactsNavigation<*>): String =
fun listRouteMapper(action: ContactsListNavigation<*>): String =
when (action) {
is Close -> BACK_ROUTE
is ShowContactsList -> action.route() // route with no parameters
is ShowContactDetails -> { // route with encoded contact details as a parameter
val json = Json.encodeToString(action.bundle!!.get(action.type))
action.route(json)
}
is ContactsListNavigation.ShowContactDetails -> action.next
//...
}

fun detailRouteMapper(action: ContactDetailsNavigation<*>): Route {
return when (action) {
is ContactDetailsNavigation.Close -> Route.Back
}
}

// Root view of the Activity. Contains a navigation graph with destinations
@Composable
fun ContactsLayout() {
// Construct a route navigator
val routeNavigator = RouteNavigator(
rememberNavController(),
::routeMapper
)

val routeController = NavHostRouteController(rememberNavHostController())
// set up nav host with routes
routeNavigator.SetupNavHost(
startDestination = route<ShowContactsList>(),
builder = {
composable(route<ShowContactsList>()) {
// Display a contacts list
ContactsListLayout()
routeController.SetupNavHost(
rootView = { navHostController ->
// Display a contact list
ContactsListLayout(navHostController)
}
composable(route<ShowContactDetails>("{json}")) {
// Extract contact details from route arguments
val details: ContactDetails =
Json.decodeFromString(it.arguments!!.getString("json")!!)
// Display contact details
ContactDetailsLayout(details, routeNavigator)
) { navHostController ->
composable<ContactDetails, ContactsListNavigation.ShowContactDetails>(
type = NavigationBundleSpecType.SerializedType(
ContactDetails.serializer()
)
) { details ->
ContactDetailsLayout(details, navHostController)
}
// other routes
}
}

@Composable
fun ContactsListLayout(navHostController: NavHostController) {
// Construct a route navigator
val routeNavigator = RouteNavigator(
rememberNavController(),
::listRouteMapper
)

// Setup Contact List view
}

@Composable
fun ContactDetailsLayout(contactDetails: ContactDetails, navHostController: NavHostController) {
val routeNavigator = RouteNavigator(
navHostController,
::detailRouteMapper
)

// Setup Details View
// No need to set up NavHost since it is managed by the parent
}
```

You can also call `SetupNavHost` directly from a `RouteNavigator`, bearing in mind that the navHostController linked to the Navigator can only be setup once.

#### Mix NavHost and Kaluga navigation

Sometimes it's necessary to mix a route navigation within the same activity and navigate to
other activities

Expand Down Expand Up @@ -157,3 +175,121 @@ class ContactDetailsViewModel(
fun onBackPressed() = navigator.navigate(Close)
}
```

#### Modal Bottom Sheet

A special case is provided for using `ModalBottomSheet` navigation

````kotlin
internal fun bottomSheetParentNavigationRouteMapper(action: BottomSheetParentNavigation): BottomSheetRoute {
return when (action) {
is BottomSheetParentNavigation.SubPage -> action.next.bottomSheetContent
is BottomSheetParentNavigation.ShowSheet -> action.next.bottomSheetSheetContent
}
}

internal fun bottomSheetParentSubPageNavigationRouteMapper(action: BottomSheetParentSubPageNavigation): Route {
return when (action) {
is BottomSheetParentSubPageNavigation.Back -> Route.Back
}
}

internal fun bottomSheetNavigationRouteMapper(action: BottomSheetNavigation): BottomSheetRoute {
return when (action) {
is BottomSheetNavigation.Close -> Route.Close.bottomSheetSheetContent
is BottomSheetNavigation.SubPage -> action.next.bottomSheetSheetContent
}
}

internal fun bottomSheetSubPageNavigationRouteMapper(action: BottomSheetSubPageNavigation): BottomSheetRoute {
return when (action) {
is BottomSheetSubPageNavigation.Close -> Route.Close.bottomSheetSheetContent
is BottomSheetSubPageNavigation.Back -> Route.Back.bottomSheetSheetContent
}
}

@Composable
fun BottomSheetParentLayout() {
val bottomSheetRouteController = BottomSheetRouteController(
NavHostRouteController(rememberNavController()),
BottomSheetSheetContentRouteController(
rememberNavController(),
rememberModalBottomSheetState(initialValue = ModalBottomSheetValue.Hidden),
rememberCoroutineScope()
)
)

bottomSheetRouteController.NavigatingModalBottomSheetLayout(
sheetContent = { contentNavHostController, sheetContentNavHostController, sheetState ->
composable(BottomSheetParentNavigation.ShowSheet.route()) {
BottomSheetLayout(contentNavHostController, sheetContentNavHostController, sheetState)
}
composable(BottomSheetNavigation.SubPage.route()) {
BottomSheetSubPageLayout(
contentNavHostController, sheetContentNavHostController, sheetState
)
}
},
contentRoot = { contentNavHostController, sheetContentNavHostController, sheetState ->
BottomSheetParentLayoutContent(contentNavHostController, sheetContentNavHostController, sheetState)
},
content = { contentNavHostController, _, _ ->
composable(BottomSheetParentNavigation.SubPage.route()) {
BottomSheetParentSubPageLayout(contentNavHostController)
}
}
)
}

@Composable
fun BottomSheetParentLayoutContent(contentNavHostController: NavHostController, sheetNavHostController: NavHostController, sheetState: ModalBottomSheetState) {

val navigator = ModalBottomSheetNavigator(
NavHostRouteController(contentNavHostController),
BottomSheetSheetContentRouteController(
sheetNavHostController,
sheetState,
rememberCoroutineScope()
),
::bottomSheetParentNavigationRouteMapper
)
// Show Content View
}

@Composable
fun BottomSheetParentSubPageLayout(navHostController: NavHostController) {
val navigator = RouteNavigator(
navHostController,
::bottomSheetParentSubPageNavigationRouteMapper
)

// Show Content Sub View
}

@Composable
fun BottomSheetLayout(contentNavHostController: NavHostController, sheetContentNavHostController: NavHostController, sheetState: ModalBottomSheetState) {
val navigator = ModalBottomSheetNavigator(
contentNavHostController,
sheetContentNavHostController,
sheetState,
rememberCoroutineScope(),
::bottomSheetNavigationRouteMapper,
)

// Show Bottom Sheet Content
}

@Composable
fun BottomSheetSubPageLayout(contentNavHostController: NavHostController, sheetContentNavHostController: NavHostController, sheetState: ModalBottomSheetState) {
val navigator = ModalBottomSheetNavigator(
contentNavHostController,
sheetContentNavHostController,
sheetState,
rememberCoroutineScope(),
::bottomSheetSubPageNavigationRouteMapper
)

// Show Bottom Sheet Sub Content
}
````

2 changes: 2 additions & 0 deletions architecture-compose/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
plugins {
id("com.android.library")
kotlin("android")
kotlin("plugin.serialization")
id("jacoco")
id("convention.publication")
id("org.jlleitschuh.gradle.ktlint")
Expand All @@ -38,6 +39,7 @@ version = ext["library_version"]!!
ext["component_type"] = ext["component_type_default"]

dependencies {
api(project(":base"))
api(project(":architecture"))
val ext = (gradle as ExtensionAware).extra
implementation("androidx.compose.material:material:" + ext["androidx_compose_version"])
Expand Down
Loading

0 comments on commit f9d779c

Please sign in to comment.