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

Fix Crash when Rotating from Portrait to Landscape Mode #30

Merged
merged 4 commits into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ plugins {
id("com.android.application")
id("com.google.devtools.ksp")
alias(libs.plugins.kotlin.serialization)
kotlin("kapt")
alias(libs.plugins.hilt.android)
kotlin("android")
}

Expand All @@ -34,8 +36,8 @@ android {
applicationId = "org.eclipse.kuksa.companion"
minSdk = 27
targetSdk = 33
versionCode = 1
versionName = "1.0"
versionCode = rootProject.extra["projectVersionCode"].toString().toInt()

Choose a reason for hiding this comment

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

this I could not check/didn't know how to check.

Choose a reason for hiding this comment

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

found it in App Infos looks good :)

versionName = rootProject.extra["projectVersion"].toString()

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
Expand Down Expand Up @@ -133,4 +135,12 @@ dependencies {

debugImplementation(libs.androidx.compose.ui.tooling)
debugImplementation(libs.androidx.compose.ui.tooling.test.manifest)

implementation(libs.hilt.android)
kapt(libs.hilt.android.compiler)
}

// Allow references to generated code
kapt {
correctErrorTypes = true
}
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<uses-permission android:name="android.permission.INTERNET" />

<application
android:name=".CompanionApplication"
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright (c) 2023 Contributors to the Eclipse Foundation
*
* 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.
*
* SPDX-License-Identifier: Apache-2.0
*
*/

package org.eclipse.kuksa.companion

import android.app.Application
import dagger.hilt.android.HiltAndroidApp

@HiltAndroidApp
class CompanionApplication : Application()
13 changes: 7 additions & 6 deletions app/src/main/kotlin/org/eclipse/kuksa/companion/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import androidx.activity.viewModels
import androidx.lifecycle.lifecycleScope
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.rememberNavController
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.launch
import org.eclipse.kuksa.DataBrokerConnection
Expand Down Expand Up @@ -65,10 +66,14 @@ import org.eclipse.kuksa.vss.VssStation
import org.eclipse.kuksa.vss.VssTrunk
import org.eclipse.kuksa.vsscore.annotation.VssDefinition
import org.eclipse.kuksa.vsscore.model.VssSpecification
import javax.inject.Inject

@AndroidEntryPoint
@VssDefinition("vss_rel_4.0.yaml")
class MainActivity : ComponentActivity() {
private lateinit var connectionInfoRepository: ConnectionInfoRepository
@Inject
lateinit var connectionInfoRepository: ConnectionInfoRepository

private lateinit var doorVehicleScene: DoorVehicleScene

private val disconnectListener = DisconnectListener {
Expand All @@ -82,9 +87,7 @@ class MainActivity : ComponentActivity() {
private val lightControlViewModel: LightControlViewModel by viewModels()
private val wheelPressureViewModel: WheelPressureViewModel by viewModels()

private val settingsViewModel: SettingsViewModel by viewModels {
SettingsViewModel.Factory(connectionInfoRepository)
}
private val settingsViewModel: SettingsViewModel by viewModels()

private var dataBrokerConnection: DataBrokerConnection? = null
private val dataBrokerConnectorFactory = DataBrokerConnectorFactory()
Expand Down Expand Up @@ -172,8 +175,6 @@ class MainActivity : ComponentActivity() {
override fun onPostCreate(savedInstanceState: Bundle?) {
super.onPostCreate(savedInstanceState)

connectionInfoRepository = ConnectionInfoRepository(this)

connectionStatusViewModel.onClickReconnect = {
connectToDataBroker {
subscribe()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,17 @@ package org.eclipse.kuksa.companion.feature.connection.repository
import android.content.Context
import androidx.datastore.core.DataStore
import androidx.datastore.dataStore
import dagger.hilt.android.qualifiers.ApplicationContext
import kotlinx.coroutines.flow.Flow
import org.eclipse.kuksa.companion.feature.connection.model.ConnectionInfo
import org.eclipse.kuksa.companion.feature.connection.model.ConnectionInfoSerializer
import javax.inject.Inject
import javax.inject.Singleton

class ConnectionInfoRepository(context: Context) {
@Singleton
class ConnectionInfoRepository @Inject constructor(
@ApplicationContext context: Context,
) {

private val Context.dataStore: DataStore<ConnectionInfo> by dataStore(PREFERENCES_NAME, ConnectionInfoSerializer)
private val dataStore = context.dataStore
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@
package org.eclipse.kuksa.companion.feature.settings.viewModel

import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.viewModelScope
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.launch
import org.eclipse.kuksa.companion.feature.connection.model.ConnectionInfo
import org.eclipse.kuksa.companion.feature.connection.repository.ConnectionInfoRepository
import javax.inject.Inject

class SettingsViewModel(
@HiltViewModel
class SettingsViewModel @Inject constructor(
private val repository: ConnectionInfoRepository,
) : ViewModel() {
val connectionInfoFlow = repository.connectionInfoFlow
Expand All @@ -36,13 +38,4 @@ class SettingsViewModel(
repository.updateConnectionInfo(connectionInfo)
}
}

class Factory(
private val connectionInfoRepository: ConnectionInfoRepository,
) : ViewModelProvider.Factory {
@Suppress("UNCHECKED_CAST")
override fun <T : ViewModel> create(modelClass: Class<T>): T {
return SettingsViewModel(connectionInfoRepository) as T
}
}
}
2 changes: 2 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ plugins {
base
detekt
version
alias(libs.plugins.hilt.android) apply false
alias(libs.plugins.ksp) apply false
}

subprojects {
Expand Down
1 change: 1 addition & 0 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,5 @@ dependencies {
implementation(libs.android.gradlePlugin)
implementation(libs.kotlin.gradlePlugin)
implementation(libs.detekt.gradlePlugin)
implementation(libs.javapoet)
}
10 changes: 9 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ androidGradlePlugin = "8.1.4" # Check with detekt table first: https://detekt.de
coreKtx = "1.12.0"
datastore = "1.0.0"
espressoCore = "3.5.1"
hiltAndroid = "2.49"
javapoet = "1.13.0"
junitVersion = "1.1.5"
junit = "4.13.2"
kotlin = "1.9.20"
Expand All @@ -21,14 +23,17 @@ navigationCompose = "2.7.5"
kotlinxSerializationJson = "1.6.1"
constraintlayoutCompose = "1.0.1"
kotlinSerializationPlugin = "1.9.20"
devtoolsKsp = "1.9.20-1.0.14"
ksp = "1.9.20-1.0.14"

[libraries]
androidx-core-ktx = { module = "androidx.core:core-ktx", version.ref = "coreKtx" }
androidx-datastore = { module = "androidx.datastore:datastore", version.ref = "datastore" }
androidx-espresso-core = { module = "androidx.test.espresso:espresso-core", version.ref = "espressoCore" }
androidx-junit = { module = "androidx.test.ext:junit", version.ref = "junitVersion" }
androidx-lifecycle-runtime-compose = { module = "androidx.lifecycle:lifecycle-runtime-compose", version.ref = "lifecycleRuntimeCompose" }
hilt-android = { module = "com.google.dagger:hilt-android", version.ref = "hiltAndroid" }
hilt-android-compiler = { module = "com.google.dagger:hilt-android-compiler", version.ref = "hiltAndroid" }
javapoet = { module = "com.squareup:javapoet", version.ref = "javapoet" }
junit = { module = "junit:junit", version.ref = "junit" }

# app
Expand Down Expand Up @@ -60,3 +65,6 @@ detekt-formatting = { group = "io.gitlab.arturbosch.detekt", name = "detekt-form

[plugins]
kotlin-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlinSerializationPlugin" }
hilt-android = { id = "com.google.dagger.hilt.android", version.ref = "hiltAndroid" }
ksp = { id = "com.google.devtools.ksp", version.ref ="ksp"}

1 change: 0 additions & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ pluginManagement {
}

plugins {
id("com.google.devtools.ksp") version "1.9.20-1.0.14"
id("de.fayard.refreshVersions") version "0.60.3"
}
}
Expand Down