Skip to content

Commit

Permalink
fix: fix ev bg
Browse files Browse the repository at this point in the history
feat: better default settings
  • Loading branch information
agronick committed Jan 3, 2024
1 parent 2c65078 commit db48d46
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 15 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ dependencies {

implementation 'androidx.annotation:annotation:1.7.1'
implementation "androidx.datastore:datastore:1.0.0"
implementation 'com.google.protobuf:protobuf-javalite:3.25.1'
implementation 'com.google.protobuf:protobuf-java-util:3.25.1'
implementation 'rongi.rotate-layout:rotate-layout:3.0.0'
implementation 'androidx.databinding:databinding-runtime:8.2.0'
// implementation 'com.google.dagger:hilt-android:2.48'
Expand All @@ -141,7 +141,7 @@ protobuf {
// Configures the task output type
java {
// Java Lite has smaller code size and is recommended for Android
option 'lite'
// option 'lite'
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion app/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
<fields>;
}

-keepclassmembers class * extends com.google.protobuf.GeneratedMessageLite* {
-keepclassmembers class * extends com.google.protobuf.GeneratedMessageV3 {
<fields>;
}

Expand Down
64 changes: 61 additions & 3 deletions app/src/main/java/com/aatorque/prefs/PrefStore.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,57 @@ import androidx.datastore.preferences.protobuf.InvalidProtocolBufferException
import com.aatorque.datastore.Display
import com.aatorque.datastore.Screen
import com.aatorque.datastore.UserPreference
import com.google.protobuf.TextFormat
import timber.log.Timber
import java.io.InputStream
import java.io.OutputStream


const val DEFAULT_SETTINGS = """
screens {
gauges {
pid: "torque_0c,0"
showLabel: true
label: "RPM"
icon: "ic_cylinder"
maxValue: 10000
unit: "rpm"
wholeNumbers: true
ticksActive: true
chartColor: -12734743
}
gauges {
pid: "torque_0d,0"
showLabel: true
label: "Speed"
icon: "ic_barometer"
maxValue: 160
unit: "km/h"
highVisActive: true
ticksActive: true
chartColor: -5314243
}
gauges {
pid: "torque_11,0"
showLabel: true
label: "Throttle"
icon: "ic_throttle"
maxValue: 100
unit: "%"
ticksActive: true
chartColor: -1476547
}
displays {}
displays {}
displays {}
displays {}
}
selectedTheme: "Electro Vehicle"
selectedFont: "ev"
selectedBackground: "background_incar_ev"
centerGaugeLarge: true
"""

object UserPreferenceSerializer : Serializer<UserPreference> {
val defaultGauge = Display.newBuilder()
.setShowLabel(true)
Expand All @@ -25,9 +73,19 @@ object UserPreferenceSerializer : Serializer<UserPreference> {
.addDisplays(defaultDisplay)
.addDisplays(defaultDisplay)

override val defaultValue: UserPreference = UserPreference.newBuilder().addScreens(
defaultScreen
).build()
override var defaultValue: UserPreference

init {
try {
defaultValue = TextFormat.parse(
DEFAULT_SETTINGS,
UserPreference::class.java
)
} catch (e: Exception) {
Timber.e("Failed to load defaults", e)
defaultValue = UserPreference.newBuilder().addScreens(defaultScreen).build()
}
}

override suspend fun readFrom(input: InputStream): UserPreference {
try {
Expand Down
10 changes: 3 additions & 7 deletions app/src/main/java/com/aatorque/stats/DashboardFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import android.graphics.BitmapFactory
import android.graphics.Color
import android.graphics.PorterDuff
import android.graphics.PorterDuffColorFilter
Expand Down Expand Up @@ -36,7 +35,6 @@ import com.aatorque.stats.databinding.FragmentDashboardBinding
import com.aatorque.utils.CountDownLatch
import com.google.android.apps.auto.sdk.StatusBarController
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.launch
Expand Down Expand Up @@ -371,8 +369,8 @@ open class DashboardFragment : AlbumArt() {
albumArtReady.await()
if (!shouldDisplayArtwork) return
if (medadata != null) {
binding.background = metaDataToArt(medadata)
if (binding.background != null) {
binding.backgroundBitmap = metaDataToArt(medadata)
if (binding.backgroundBitmap != null) {
binding.blurEffect = albumBlurEffect
binding.colorFilter = albumColorFilter
displayingArtwork = true
Expand Down Expand Up @@ -401,9 +399,7 @@ open class DashboardFragment : AlbumArt() {
binding.blurEffect = null
binding.colorFilter = null
displayingArtwork = false
if (resource != 0) {
binding.background = BitmapFactory.decodeResource(resources, resource)
}
binding.backgroundResource = resource
}

fun configureRotaryInput(enabled: Boolean) {
Expand Down
13 changes: 13 additions & 0 deletions app/src/main/java/com/aatorque/stats/ViewAdapter.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package com.aatorque.stats

import android.content.res.Resources
import android.graphics.Bitmap
import android.util.DisplayMetrics
import android.view.View
import android.view.ViewGroup
import android.view.ViewGroup.MarginLayoutParams
import android.widget.ImageView
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.constraintlayout.widget.Guideline
import androidx.databinding.BindingAdapter
Expand Down Expand Up @@ -97,4 +99,15 @@ fun setLayoutMargin(view: View, top: Int?, left: Int?, right: Int?, bottom: Int?
fun setLayoutMargin(view: Guideline, end: Int?, begin: Int?) {
convertDp(end)?.let { view.setGuidelineEnd(it) }
convertDp(begin)?.let { view.setGuidelineBegin(it) }
}

@BindingAdapter("bitmap", "resource", requireAll = false)
fun bitmapOrResource(view: ImageView, bitmap: Bitmap?, resource: Int?) {
if (bitmap != null) {
view.setImageBitmap(bitmap)
} else if (resource != null) {
view.setImageResource(resource)
} else {
view.setImageResource(0)
}
}
9 changes: 7 additions & 2 deletions app/src/main/res/layout/fragment_dashboard.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,13 @@
<import type="android.graphics.ColorFilter" />

<variable
name="background"
name="backgroundBitmap"
type="Bitmap" />

<variable
name="backgroundResource"
type="Integer" />

<variable
name="blurEffect"
type="RenderEffect" />
Expand Down Expand Up @@ -80,7 +84,8 @@
app:colorFilter="@{colorFilter}"
android:elevation="0dp"
android:adjustViewBounds="true"
app:imageBitmap="@{background}"
app:bitmap="@{backgroundBitmap}"
app:resource="@{backgroundResource}"
app:renderEffect="@{blurEffect}" />

<androidx.constraintlayout.widget.ConstraintLayout
Expand Down

0 comments on commit db48d46

Please sign in to comment.