Skip to content

Commit

Permalink
Merge pull request #492 from splendo/release/0.3.0
Browse files Browse the repository at this point in the history
Release/0.3.0
  • Loading branch information
carmelogallo authored Mar 23, 2022
2 parents f9d779c + c5a2d84 commit 45e2d24
Show file tree
Hide file tree
Showing 84 changed files with 1,116 additions and 373 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ build/
DerivedData/
.gradle/
/kotlin-js-store/
**/kotlin-js-store/

## Various settings
*.pbxuser
Expand Down
24 changes: 24 additions & 0 deletions .idea/runConfigurations/_all__iosSimulatorArm64Test.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions .idea/runConfigurations/_architecture__iosTest_.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions .idea/runConfigurations/_base__iosTest.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions .idea/runConfigurations/_bluetooth__iosTest.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions .idea/runConfigurations/_test_utils__iosTest.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ Kaluga also uses some multiplatform libraries itself, so our thanks to:

Project | Usage
--- | ---
[kydra](https://github.com/PocketByte/kotlin-kydra-log) | powers the logging module
[Napier](https://github.com/AAkira/Napier) | powers the logging module
[stately](https://github.com/touchlab/Stately) | concurrency
[Koin](https://insert-koin.io/) | dependency injection

Expand Down
8 changes: 0 additions & 8 deletions architecture/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,6 @@ kotlin {
val ext = (gradle as ExtensionAware).extra
val serialization_version: String by ext

// For IDE
val ios_primary_arch: String by ext
getByName("${ios_primary_arch}Main") {
dependencies {
api(project(":base", ""))
}
}

getByName("commonMain") {
dependencies {
implementation(project(":base", ""))
Expand Down
22 changes: 22 additions & 0 deletions architecture/src/iosArm64Main/kotlin/SetMessageWorkAround.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
Copyright 2022 Splendo Consulting B.V. The Netherlands
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package com.splendo.kaluga.architecture.navigation

import platform.MessageUI.MFMessageComposeViewController

actual fun MFMessageComposeViewController.setMessageWorkAround(message: platform.Messages.MSMessage?) = this.setMessage(message)
5 changes: 4 additions & 1 deletion architecture/src/iosMain/kotlin/navigation/Navigator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ class ViewControllerNavigator<A : NavigationAction<*>>(
}
}
settings.body?.let { composeVC.setBody(it) }
settings.message?.let { composeVC.setMessage(it) }
settings.message?.let { composeVC.setMessageWorkAround(it) }

if (MFMessageComposeViewController.canSendAttachments()) {
settings.attachments.forEach {
Expand Down Expand Up @@ -352,3 +352,6 @@ class ViewControllerNavigator<A : NavigationAction<*>>(

private fun assertParent() = parent.get().also { assert(it != null) }
}

// Seems to be a bug on commonizer using new targets sourcesets which is preventing to infer the correct type
expect fun MFMessageComposeViewController.setMessageWorkAround(message: platform.Messages.MSMessage?)
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
Copyright 2022 Splendo Consulting B.V. The Netherlands
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package com.splendo.kaluga.architecture.navigation

import platform.MessageUI.MFMessageComposeViewController

actual fun MFMessageComposeViewController.setMessageWorkAround(message: platform.Messages.MSMessage?) = this.setMessage(message)
22 changes: 22 additions & 0 deletions architecture/src/iosX64Main/kotlin/SetMessageWorkAround.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
Copyright 2022 Splendo Consulting B.V. The Netherlands
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package com.splendo.kaluga.architecture.navigation

import platform.MessageUI.MFMessageComposeViewController

actual fun MFMessageComposeViewController.setMessageWorkAround(message: platform.Messages.MSMessage?) = this.setMessage(message)
4 changes: 2 additions & 2 deletions base-permissions/src/commonMain/kotlin/PermissionState.kt
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,12 @@ abstract class PermissionStateRepo<P : Permission>(
initChangeStateWithRepo = { state, repo ->
val pm = (repo as PermissionStateRepo<P>).permissionManager
pm.startMonitoring(monitoringInterval)
if (state == null || state is PermissionState.Unknown<P>)
if (state is PermissionState.Unknown<P>)
suspend { pm.initializeState() }
else
suspend { state }
},
deinitChangeStateWithRepo = { state, repo ->
deinitChangeStateWithRepo = { _, repo ->
(repo as PermissionStateRepo<P>).permissionManager.stopMonitoring() // TODO: could also be replaced by a state
null
},
Expand Down
18 changes: 8 additions & 10 deletions base/src/commonMain/kotlin/state/State.kt
Original file line number Diff line number Diff line change
Expand Up @@ -414,9 +414,9 @@ abstract class BaseColdStateRepo<S : State, F : MutableSharedFlow<S>>(
*/
open class ColdStateFlowRepo<S : State>(
coroutineContext: CoroutineContext = Dispatchers.Main.immediate,
val initChangeStateWithRepo: suspend (S?, ColdStateFlowRepo<S>) -> (suspend () -> S),
val initChangeStateWithRepo: suspend (S, ColdStateFlowRepo<S>) -> (suspend () -> S),
val deinitChangeStateWithRepo: suspend (S, ColdStateFlowRepo<S>) -> (suspend () -> S)?,
val firstState: (suspend() -> S)? = null
val firstState: () -> S
) : StateFlowRepo<S>,
BaseColdStateRepo<S, MutableStateFlow<S>>(
context = coroutineContext,
Expand All @@ -425,12 +425,12 @@ open class ColdStateFlowRepo<S : State>(
constructor(
coroutineContext: CoroutineContext = Dispatchers.Main.immediate,
// order is different than below because here firstState is mandatory, and to avoid JVM signature clashes
firstState: suspend() -> S,
firstState: () -> S,
initChangeState: suspend (S) -> (suspend () -> S),
deinitChangeState: suspend (S) -> (suspend () -> S)
) : this(
coroutineContext,
initChangeStateWithRepo = { state, _ -> state?.let { initChangeState(state) } ?: firstState },
initChangeStateWithRepo = { state, _ -> initChangeState(state) },
deinitChangeStateWithRepo = { state, _ -> deinitChangeState(state) },
firstState = firstState
)
Expand All @@ -439,7 +439,7 @@ open class ColdStateFlowRepo<S : State>(
coroutineContext: CoroutineContext = Dispatchers.Main.immediate,
init: suspend (ColdStateFlowRepo<S>) -> S,
deinit: suspend (ColdStateFlowRepo<S>) -> S?,
firstState: (suspend() -> S)? = null
firstState: () -> S
) : this(
coroutineContext,
initChangeStateWithRepo = { _, repo -> { init(repo) } },
Expand All @@ -459,11 +459,9 @@ open class ColdStateFlowRepo<S : State>(

override val lazyMutableFlow: Lazy<MutableStateFlow<S>> =
lazy {
runBlocking {
MutableStateFlow(
firstState?.invoke() ?: initChangeStateWithRepo(null, this@ColdStateFlowRepo)()
)
}
MutableStateFlow(
firstState()
)
}

override suspend fun firstCollection() {
Expand Down
14 changes: 12 additions & 2 deletions base/src/iosMain/kotlin/text/DateFormatter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,21 @@ actual class DateFormatter private constructor(private val format: NSDateFormatt
}
)

private fun defaultDate(timeZone: TimeZone) = Date.now(timeZone = timeZone).apply {
// Due to a problem related to the commonizer we need to supply all the
// default arguments expected from the method signature
private fun defaultDate(timeZone: TimeZone) = Date.now(
offsetInMilliseconds = 0L,
timeZone = timeZone,
locale = Locale.defaultLocale
).apply {
// Cannot use .utc since it may not be available when this method is called
// This is likely caused by https://youtrack.jetbrains.com/issue/KT-38181
// TODO When moving Date and Date formatter to separate modules, this should be updated to use .utc
val epoch = Date.epoch(timeZone = TimeZone.get("UTC")!!)
val epoch = Date.epoch(
offsetInMilliseconds = 0L,
timeZone = TimeZone.get("UTC")!!,
locale = Locale.defaultLocale
)
this.era = epoch.era
this.year = epoch.year
this.month = epoch.month
Expand Down
2 changes: 1 addition & 1 deletion beacons/src/commonMain/kotlin/Beacons.kt
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class Beacons(
}
cache[beacon.beaconID] = beacon to coroutineScope.launch {
debug(TAG, "[Added] $beacon")
delay(timeoutMs)
delay(beacon.lastSeen.millisecondSinceEpoch + timeoutMs - Date.now().millisecondSinceEpoch)
debug(TAG, "[Lost] $beacon")
cache.remove(beacon.beaconID)
updateList()
Expand Down
8 changes: 1 addition & 7 deletions bluetooth/src/androidLibMain/kotlin/Characteristic.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ actual interface CharacteristicWrapper {
val service: ServiceWrapper
actual val descriptors: List<DescriptorWrapper>
val permissions: Int
val properties: Int
actual val properties: Int
var writeType: Int

fun setValue(newValue: String): Boolean
Expand All @@ -40,12 +40,6 @@ actual interface CharacteristicWrapper {
fun intValue(formatType: Int, offset: Int): Int
}

fun CharacteristicWrapper.containsAnyOf(vararg property: Int) =
if (property.count() > 0)
properties and property.reduce { acc, i -> acc.or(i) } != 0
else
false

class DefaultCharacteristicWrapper(private val gattCharacteristic: BluetoothGattCharacteristic) : CharacteristicWrapper {

override val uuid: java.util.UUID
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ interface BluetoothGattWrapper {
fun disconnect()
fun close()
fun readRemoteRssi(): Boolean
/** Request MTU, returns `true` if the new MTU value has been requested successfully */
fun requestMtu(mtu: Int): Boolean

fun readCharacteristic(wrapper: CharacteristicWrapper): Boolean
fun readDescriptor(wrapper: DescriptorWrapper): Boolean
Expand Down Expand Up @@ -59,6 +61,10 @@ class DefaultBluetoothGattWrapper(private val gatt: BluetoothGatt) : BluetoothGa
return gatt.readRemoteRssi()
}

override fun requestMtu(mtu: Int): Boolean {
return gatt.requestMtu(mtu)
}

override fun readCharacteristic(wrapper: CharacteristicWrapper): Boolean {
val characteristic = getCharacteristic(wrapper) ?: return false
return gatt.readCharacteristic(characteristic)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import com.splendo.kaluga.bluetooth.Service
import com.splendo.kaluga.bluetooth.UUID
import com.splendo.kaluga.bluetooth.containsAnyOf
import com.splendo.kaluga.bluetooth.uuidString
import com.splendo.kaluga.logging.debug
import com.splendo.kaluga.logging.warn
import kotlinx.coroutines.CompletableDeferred
import kotlinx.coroutines.CoroutineScope
Expand Down Expand Up @@ -78,6 +79,13 @@ internal actual class DeviceConnectionManager(
}
}

override fun onMtuChanged(gatt: BluetoothGatt?, mtu: Int, status: Int) {
debug(TAG) { "onMtuChanged($gatt, $mtu, $status)" }
if (status == GATT_SUCCESS) {
handleNewMtu(mtu)
}
}

override fun onCharacteristicRead(gatt: BluetoothGatt?, characteristic: BluetoothGattCharacteristic?, status: Int) {
characteristic ?: return
updateCharacteristic(characteristic, status)
Expand Down Expand Up @@ -178,6 +186,10 @@ internal actual class DeviceConnectionManager(
gatt.await().readRemoteRssi()
}

override suspend fun requestMtu(mtu: Int): Boolean {
return gatt.await().requestMtu(mtu)
}

override suspend fun performAction(action: DeviceAction) {
currentAction = action
val succeeded = when (action) {
Expand Down
Loading

0 comments on commit 45e2d24

Please sign in to comment.