Skip to content

Commit

Permalink
Merge pull request #155 from Ixam97/0_24_1_release
Browse files Browse the repository at this point in the history
0.24.1 release
  • Loading branch information
Ixam97 authored May 18, 2023
2 parents 2bfcbd8 + c32f9ee commit c09da6b
Show file tree
Hide file tree
Showing 25 changed files with 875 additions and 71 deletions.
40 changes: 36 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ Please let me now if you do not want to be listed in the supporters list.
* Peter Füllhase
* Lukas Bruckenberger
* Stefan Süssenguth
* Jürgen Bereuter
* Markus Enseroth
* Jacob Frostholm
* Christoffer Gennerud
* Samuel Lodyga

</details>

Expand All @@ -56,6 +61,28 @@ Currently the following languages are already available:
- :sweden: Swedish
- :norway: Norwegian
- :denmark: Danish
- :fr: French
- :pt: Portuguese
- :fn: Finnish

<details>
<summary><h3>Translators</h3></summary>

* DoubleYouEl
* Robin Hellström
* Jakob Schlyter
* Oddvarr
* Emil Blixt Hansen
* Ian Mascarenhas
* Dominik Brüning
* Juha Mönkkönen
* Ossi Lahtinen
* J-P
* Laurent Vitalis
* Jere Kataja
* Pedro Leite

</details>

### Rules for contributing code:
<details>
Expand All @@ -72,12 +99,9 @@ Please also be aware that I will not just include everything. It has to fit into

## Contributors:
- Dario Bosshard (Consumption and charge curve diagrams)
- Dutch translation: DoubleYouEl
- Swedish translation: Robin Hellström, jschlyter
- Norwegian translation: Oddvarr
- Danish translation: Emil Blixt Hansen
- FreshDave29
- rdu
- Jannick Fahlbusch

## Links:

Expand All @@ -91,6 +115,14 @@ Discussion in the international Polestar forums: [Polestar Forum](https://www.po

## Changelog [DE]:

### 0.24.1 (18.05.2023)
- Höhenunterschied in der Zusammenfassung hinzugefügt (experimentell)
- Falsche Einheitem im Diagramm der Zusammenfassung behoben
- Falsche Datumsangaben der Ladekurven in der Zusammenfassung behoben
- Bedingungen für Neustart-Benachrichtigungen verbessert
- Bedingungen für Energieerfassung angepasst (experimentell)
- Französische, portugisische und finnische Übersetzungen hinzugefügt

### 0.24.0 (02.04.2023)
- Mehrere Live-Daten-APIs hinzugefügt:
- ABRP OTA Live Data
Expand Down
4 changes: 2 additions & 2 deletions automotive/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ android {
applicationId "com.ixam97.carStatsViewer"
minSdkVersion 29
targetSdkVersion 33
versionCode 106
versionName "0.24.0"
versionCode 111
versionName "0.24.1.0005"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,32 @@ class AutoStartReceiver: BroadcastReceiver() {
"crash" to context.getString(R.string.restart_notification_reason_crash),
"reboot" to context.getString(R.string.restart_notification_reason_reboot),
"update" to context.getString(R.string.restart_notification_reason_update),
"termination" to "an unexpected termination"
)
var reason: String? = null

InAppLogger.d("AutoStartReceiver, Service started: ${CarStatsViewer.foregroundServiceStarted}, dismissed: ${CarStatsViewer.restartNotificationDismissed}")

if (!CarStatsViewer.appPreferences.autostart) return
if (CarStatsViewer.foregroundServiceStarted) return
if (CarStatsViewer.restartNotificationDismissed) return

intent?.let {
InAppLogger.d("${intent.toString()} ${intent.extras?.keySet().let { key ->
val stringBuilder = StringBuilder()
key?.forEach {
stringBuilder.append("$it ")
}
stringBuilder.toString()
}}")
if (intent.hasExtra("dismiss"))
{
CarStatsViewer.restartNotificationDismissed = true
CarStatsViewer.notificationManager.cancel(CarStatsViewer.RESTART_NOTIFICATION_ID)
return
if (intent.getBooleanExtra("dismiss", false)) {
CarStatsViewer.restartNotificationDismissed = true
CarStatsViewer.notificationManager.cancel(CarStatsViewer.RESTART_NOTIFICATION_ID)
InAppLogger.d("AutoStartReceiver: Dismiss intent")
return
}
}
reason = if (intent.hasExtra("reason")) {
reasonMap[intent.getStringExtra("reason")]
Expand All @@ -42,7 +57,7 @@ class AutoStartReceiver: BroadcastReceiver() {
}
}

InAppLogger.i("AutStartReceiver fired. Reason: $reason")
InAppLogger.i("AutoStartReceiver fired. Reason: $reason")

val notificationText =
if (reason != null) {
Expand All @@ -59,15 +74,6 @@ class AutoStartReceiver: BroadcastReceiver() {
},
PendingIntent.FLAG_IMMUTABLE
)

val actionDismissPendingIntent = PendingIntent.getBroadcast(
context.applicationContext,
0,
Intent(context.applicationContext, this.javaClass).apply {
putExtra("dismiss", "")
},
PendingIntent.FLAG_ONE_SHOT
)
val actionActivityPendingIntent = PendingIntent.getActivity(
context.applicationContext,
0,
Expand All @@ -82,7 +88,7 @@ class AutoStartReceiver: BroadcastReceiver() {
.setContentTitle(notificationText)
.setContentText(context.getString(R.string.restart_notification_message))
.setSmallIcon(R.drawable.ic_launcher_foreground)
.setOngoing(true)
.setOngoing(false)

startupNotificationBuilder.apply {
addAction(Notification.Action.Builder(
Expand All @@ -98,7 +104,14 @@ class AutoStartReceiver: BroadcastReceiver() {
addAction(Notification.Action.Builder(
null,
context.getString(R.string.restart_notification_dismiss),
actionDismissPendingIntent
PendingIntent.getBroadcast(
context.applicationContext,
0,
Intent(context.applicationContext, AutoStartReceiver::class.java).apply {
putExtra("dismiss", true)
},
PendingIntent.FLAG_UPDATE_CURRENT
)
).build())
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,26 @@ class AboutActivity : Activity() {
}
about_contributors_text.text = contributors


about_translators.setOnClickListener {
val translatorsDialog = AlertDialog.Builder(this).apply {
setPositiveButton(getString(R.string.dialog_close)) { dialog, _ ->
dialog.cancel()
}
setTitle(getString(R.string.about_translators))
val translatorsArray = resources.getStringArray(R.array.translators)
var translators = ""
for ((index, translator) in translatorsArray.withIndex()) {
translators += translator
if (index < translatorsArray.size - 1) translators += ", "
}
setMessage(translators)
setCancelable(true)
create()
}
translatorsDialog.show()
}

about_supporters.setOnClickListener {
val supportersDialog = AlertDialog.Builder(this).apply {
setPositiveButton(getString(R.string.dialog_close)) { dialog, _ ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,8 @@ class MainActivity : FragmentActivity(), SummaryFragment.OnSelectedTripChangedLi

main_button_performance.isEnabled = true
main_button_performance.colorFilter = PorterDuffColorFilter(getColor(R.color.disabled_tint), PorterDuff.Mode.SRC_IN)
main_button_history.isEnabled = false
main_button_history.colorFilter = PorterDuffColorFilter(getColor(R.color.disabled_tint), PorterDuff.Mode.SRC_IN)

enableUiUpdates()

Expand All @@ -238,8 +240,8 @@ class MainActivity : FragmentActivity(), SummaryFragment.OnSelectedTripChangedLi
setPositiveButton(getString(R.string.dialog_close)) { dialog, _ ->
dialog.cancel()
}
setTitle(getString(R.string.main_changelog_dialog_title, BuildConfig.VERSION_NAME))
val changesArray = resources.getStringArray(R.array.changes_0_24)
setTitle(getString(R.string.main_changelog_dialog_title, BuildConfig.VERSION_NAME.dropLast(5)))
val changesArray = resources.getStringArray(R.array.changes_0_24_1)
var changelog = ""
for ((index, change) in changesArray.withIndex()) {
changelog += "$change"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.ixam97.carStatsViewer.dataManager

import android.app.*
import android.car.Car
import android.car.VehicleIgnitionState
import android.car.VehiclePropertyIds
import android.car.VehicleUnit
import android.car.hardware.CarPropertyValue
Expand Down Expand Up @@ -135,6 +136,7 @@ class DataCollector : Service() {

Thread.setDefaultUncaughtExceptionHandler { t, e ->
InAppLogger.e("Car Stats Viewer has crashed!\n ${e.stackTraceToString()}")
/*
val alarmManager = getSystemService(Context.ALARM_SERVICE) as AlarmManager
val serviceIntent = Intent(applicationContext, AutoStartReceiver::class.java)
serviceIntent.action = "com.ixam97.carStatsViewer.RestartAction"
Expand All @@ -146,6 +148,8 @@ class DataCollector : Service() {
PendingIntent.FLAG_ONE_SHOT
)
alarmManager.set(AlarmManager.RTC, System.currentTimeMillis() + 100, pendingIntent)
*/
exitProcess(0)
}

Expand Down Expand Up @@ -293,6 +297,25 @@ class DataCollector : Service() {
delay(10_000)
}
}

serviceScope.launch {
val serviceIntent = Intent(applicationContext, AutoStartReceiver::class.java)
val pendingIntent = PendingIntent.getBroadcast(
applicationContext,
0,
serviceIntent,
PendingIntent.FLAG_ONE_SHOT
)
while (true) {
InAppLogger.d("Keep Alive Alarm")
serviceIntent.action = "com.ixam97.carStatsViewer.RestartAction"
serviceIntent.putExtra("reason", "termination")
// serviceIntent.putExtra("dismiss", false)
val alarmManager = getSystemService(Context.ALARM_SERVICE) as AlarmManager
alarmManager.set(AlarmManager.RTC, System.currentTimeMillis() + 5000, pendingIntent)
delay(4000)
}
}
}

override fun onDestroy() {
Expand Down Expand Up @@ -390,13 +413,13 @@ class DataCollector : Service() {
if (gageValueChanged) sendBroadcast(Intent(getString(R.string.ui_update_gages_broadcast)))
}
when (dataManager.driveState) {
DrivingState.DRIVE -> {
if (!dataManager.CurrentPower.isInitialValue) {
val usedEnergyDelta = (dataManager.currentPower / 1_000) * ((dataManager.CurrentPower.timeDelta / 3.6E12).toFloat())
dataManager.usedEnergy += usedEnergyDelta
dataManager.consumptionPlotEnergyDelta += usedEnergyDelta
}
}
// DrivingState.DRIVE -> {
// if (!dataManager.CurrentPower.isInitialValue) {
// val usedEnergyDelta = (dataManager.currentPower / 1_000) * ((dataManager.CurrentPower.timeDelta / 3.6E12).toFloat())
// dataManager.usedEnergy += usedEnergyDelta
// dataManager.consumptionPlotEnergyDelta += usedEnergyDelta
// }
// }
DrivingState.CHARGE -> {
refreshProperty(dataManager.BatteryLevel.propertyId, dataManager)
if (!dataManager.CurrentPower.isInitialValue && !dataManager.BatteryLevel.isInitialValue && dataManager.CurrentPower.timeDelta < CHARGE_PLOT_MARKER_THRESHOLD_NANOS && dataManager.BatteryLevel.timeDelta < CHARGE_PLOT_MARKER_THRESHOLD_NANOS) {
Expand Down Expand Up @@ -425,6 +448,11 @@ class DataCollector : Service() {
}
else -> {
// Supplemental energy usage?
if (!dataManager.CurrentPower.isInitialValue && dataManager.currentIgnitionState >= VehicleIgnitionState.ON) {
val usedEnergyDelta = (dataManager.currentPower / 1_000) * ((dataManager.CurrentPower.timeDelta / 3.6E12).toFloat())
dataManager.usedEnergy += usedEnergyDelta
dataManager.consumptionPlotEnergyDelta += usedEnergyDelta
}
}
}
}
Expand Down Expand Up @@ -527,13 +555,17 @@ class DataCollector : Service() {
private fun ignitionUpdater(dataManager: DataManager) {
if (dataManager == DataManagers.values().first().dataManager) {
InAppLogger.d("Ignition switched to: ${ignitionList[dataManager.currentIgnitionState]}")

}
val previousDrivingState = dataManager.DriveState.lastDriveState
resetAutoTrips(previousDrivingState, dataManager, dataManager.currentIgnitionState)
driveStateUpdater(dataManager)
}

private fun driveState(previousDrivingState: Int, dataManager: DataManager) {
if (dataManager == DataManagers.CURRENT_TRIP.dataManager) startLocationClient()
resetAutoTrips(previousDrivingState, DrivingState.DRIVE, dataManager)
// resetAutoTrips(previousDrivingState, DrivingState.DRIVE, dataManager)
resetAutoTrips(previousDrivingState, dataManager, dataManager.currentIgnitionState)
resumeTrip(dataManager)
if (previousDrivingState == DrivingState.CHARGE) stopChargingSession(dataManager)
if (previousDrivingState != DrivingState.UNKNOWN) dataManager.plotMarkers.endMarker(System.currentTimeMillis(), dataManager.traveledDistance)
Expand All @@ -551,7 +583,8 @@ class DataCollector : Service() {
}

private fun parkState(previousDrivingState: Int, dataManager: DataManager) {
resetAutoTrips(previousDrivingState, DrivingState.PARKED, dataManager)
// resetAutoTrips(previousDrivingState, DrivingState.PARKED, dataManager)
resetAutoTrips(previousDrivingState, dataManager, dataManager.currentIgnitionState)
if (previousDrivingState == DrivingState.DRIVE){
pauseTrip(dataManager)
dataManager.plotMarkers.addMarker(PlotMarkerType.PARK, System.currentTimeMillis(), dataManager.traveledDistance)
Expand Down Expand Up @@ -786,11 +819,12 @@ class DataCollector : Service() {
}
}

private fun resetAutoTrips(previousDrivingState: Int, newDrivingState: Int, dataManager: DataManager) {
private fun resetAutoTrips(previousDrivingState: Int, /*newDrivingState: Int, */ dataManager: DataManager, newIgnitionState: Int) {
// Handle resets on different dataManagers
if (DataManagers.CURRENT_MONTH.dataManager == dataManager &&
DataManagers.CURRENT_MONTH.doTrack &&
newDrivingState == DrivingState.DRIVE) {
// newDrivingState == DrivingState.DRIVE) {
newIgnitionState == VehicleIgnitionState.ON) {
// Reset if in different Month than start and save old month
if (Date().month != DataManagers.CURRENT_MONTH.dataManager.tripStartDate.month) {
InAppLogger.i("TRIP DATA: Saving past Month")
Expand All @@ -804,7 +838,8 @@ class DataCollector : Service() {
}
if (DataManagers.AUTO_DRIVE.dataManager == dataManager &&
DataManagers.AUTO_DRIVE.doTrack &&
newDrivingState == DrivingState.DRIVE) {
// newDrivingState == DrivingState.DRIVE) {
newIgnitionState == VehicleIgnitionState.ON) {
// Reset if parked for x hours
if (DataManagers.AUTO_DRIVE.dataManager.plotMarkers.markers.isNotEmpty()) {
if (
Expand Down
Loading

0 comments on commit c09da6b

Please sign in to comment.