Skip to content

Commit

Permalink
#200: Bluetooth fixes and error UI implementations
Browse files Browse the repository at this point in the history
  • Loading branch information
janoliver20 committed May 14, 2024
1 parent f5f435a commit 6548083
Show file tree
Hide file tree
Showing 40 changed files with 669 additions and 342 deletions.
18 changes: 9 additions & 9 deletions androidApp/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ android {
}
}

val composeVersion = "1.6.0"
val composeVersion = "1.6.7"
val workVersion = "2.9.0"
val navVersion = "2.7.6"
val polarSDKVersion = "5.1.0"
val navVersion = "2.7.7"
val polarSDKVersion = "5.5.0"

dependencies {
implementation(project(":shared"))
Expand All @@ -61,19 +61,19 @@ dependencies {
implementation("androidx.compose.material:material:$composeVersion")
implementation("androidx.compose.material:material-icons-core:$composeVersion")
implementation("androidx.compose.material:material-icons-extended:$composeVersion")
implementation("androidx.fragment:fragment:1.6.2")
implementation("androidx.activity:activity-compose:1.8.2")
implementation("androidx.fragment:fragment:1.7.0")
implementation("androidx.activity:activity-compose:1.9.0")
implementation("io.realm.kotlin:library-base:1.13.0")
implementation("androidx.navigation:navigation-compose:$navVersion")
implementation("androidx.work:work-runtime-ktx:$workVersion")
implementation("com.google.android.gms:play-services-location:21.1.0")
implementation("com.google.firebase:firebase-analytics-ktx:21.5.0")
implementation("com.google.firebase:firebase-messaging-ktx:23.4.0")
implementation("com.google.android.gms:play-services-location:21.2.0")
implementation("com.google.firebase:firebase-analytics-ktx:22.0.0")
implementation("com.google.firebase:firebase-messaging-ktx:24.0.0")
implementation("io.github.aakira:napier:2.7.1")
implementation("com.github.polarofficial:polar-ble-sdk:${polarSDKVersion}")
implementation("io.reactivex.rxjava3:rxjava:3.1.8")
implementation("io.reactivex.rxjava3:rxandroid:3.0.2")
implementation(platform("com.google.firebase:firebase-bom:32.2.2"))
implementation(platform("com.google.firebase:firebase-bom:33.0.0"))
implementation("com.google.firebase:firebase-analytics")
implementation("com.google.firebase:firebase-crashlytics-ktx")
implementation("com.google.firebase:firebase-inappmessaging-ktx")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import io.redlink.more.app.android.R
import io.redlink.more.app.android.extensions.getStringResource
import io.redlink.more.app.android.services.sensorsListener.GPSStateListener
import io.redlink.more.app.android.shared_composables.BasicText
import io.redlink.more.app.android.shared_composables.EmptyListView
import io.redlink.more.app.android.shared_composables.Heading
Expand All @@ -51,6 +52,7 @@ import io.redlink.more.app.android.ui.theme.MoreColors

class BLEConnectionActivity : ComponentActivity() {
val viewModel = BluetoothViewModel()
private var gpsListenerSelfActivated = false

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand All @@ -63,11 +65,19 @@ class BLEConnectionActivity : ComponentActivity() {
override fun onResume() {
super.onResume()
viewModel.viewDidAppear()
if (!GPSStateListener.listenerActive) {
gpsListenerSelfActivated = true
GPSStateListener.startListening(this)
}
}

override fun onDestroy() {
super.onDestroy()
viewModel.viewDidDisappear()
if (gpsListenerSelfActivated) {
gpsListenerSelfActivated = false
GPSStateListener.stopListening(this)
}
}

companion object {
Expand Down Expand Up @@ -122,7 +132,7 @@ fun LoginBLESetupView(viewModel: BluetoothViewModel, showDescrPart2: Boolean) {
Box(modifier = Modifier)
}
}
if (viewModel.bluetoothPowerState.value) {
if (viewModel.bluetoothPowerState.value && viewModel.gpsActive.value) {
if (viewModel.connectedDevices.isEmpty()) {
item {
EmptyListView(text = getStringResource(id = R.string.more_ble_no_connected))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import androidx.compose.runtime.mutableStateOf
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import io.redlink.more.app.android.MoreApplication
import io.redlink.more.app.android.services.sensorsListener.GPSStateListener
import io.redlink.more.more_app_mutliplatform.AlertController
import io.redlink.more.more_app_mutliplatform.models.AlertDialogModel
import io.redlink.more.more_app_mutliplatform.services.bluetooth.BluetoothDevice
Expand All @@ -40,17 +41,24 @@ class BluetoothViewModel : ViewModel() {
val neededDevices = mutableStateListOf<String>()

val alertDialogOpen = mutableStateOf<AlertDialogModel?>(null)

val gpsActive = mutableStateOf(false)

init {
viewModelScope.launch(Dispatchers.IO) {
GPSStateListener.gpsEnabled.collect {
withContext(Dispatchers.Main) {
gpsActive.value = it
}
}
}
viewModelScope.launch(Dispatchers.IO) {
AlertController.alertDialogModel.collect {
withContext(Dispatchers.Main) {
alertDialogOpen.value = it
}
}
}
viewModelScope.launch(Dispatchers.Default) {
viewModelScope.launch(Dispatchers.IO) {
BluetoothDeviceManager.discoveredDevices.collect {
discoveredDevices.clear()
discoveredDevices.addAll(it)
Expand Down Expand Up @@ -91,18 +99,15 @@ class BluetoothViewModel : ViewModel() {
}

fun viewDidAppear() {
coreBluetoothViewModel.viewDidAppear()
ViewManager.bleViewOpen(true)
coreBluetoothViewModel.viewDidAppear()
}

fun viewDidDisappear() {
ViewManager.bleViewOpen(false)
coreBluetoothViewModel.viewDidDisappear()
connectingDevices.clear()
connectedDevices.clear()
discoveredDevices.clear()
isScanning.value = false
bluetoothPowerState.value = false
ViewManager.bleViewOpen(false)
}

fun connectToDevice(device: BluetoothDevice) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,17 @@ class ScheduleViewModel(

private val jobs = mutableListOf<Job>()

init {
viewModelScope.launch(Dispatchers.IO) {
MoreApplication.shared!!.observationFactory.observationErrors.collect {
withContext(Dispatchers.Main) {
observationErrors.clear()
observationErrors.putAll(it)
}
}
}
}

fun viewDidAppear() {
coreViewModel.viewDidAppear()
jobs.add(viewModelScope.launch {
Expand All @@ -73,14 +84,6 @@ class ScheduleViewModel(
}
}
})
jobs.add(viewModelScope.launch(Dispatchers.IO) {
MoreApplication.shared!!.observationFactory.observationErrors.collect {
withContext(Dispatchers.Main) {
observationErrors.clear()
observationErrors.putAll(it)
}
}
})
}

fun viewDidDisappear() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,20 +73,28 @@ fun ScheduleListItem(
.width(15.dp)
)
}
if (observationErrors.isEmpty()) {
Icon(Icons.Default.Warning, contentDescription = null, tint = MoreColors.Primary)
}
}
Row(
horizontalArrangement = Arrangement.SpaceBetween,
modifier = Modifier.fillMaxWidth()
) {
BasicText(text = scheduleModel.observationType, color = MoreColors.Secondary)
Icon(
Icons.AutoMirrored.Rounded.KeyboardArrowRight,
contentDescription = getStringResource(id = R.string.more_schedule_details),
tint = MoreColors.Primary
)
Row(horizontalArrangement = Arrangement.End) {
if (observationErrors.isNotEmpty()) {
BasicText(text = "${observationErrors.count()}")
Icon(
Icons.Default.Warning,
contentDescription = null,
tint = MoreColors.Important,
modifier = Modifier.padding(end = 4.dp)
)
}
Icon(
Icons.AutoMirrored.Rounded.KeyboardArrowRight,
contentDescription = getStringResource(id = R.string.more_schedule_details),
tint = MoreColors.Primary
)
}
}

TimeframeHours(
Expand Down
Loading

0 comments on commit 6548083

Please sign in to comment.