Skip to content

Commit

Permalink
merged the PR openvehicles#176 and add a options menu switch for on/o…
Browse files Browse the repository at this point in the history
…ff notification

added some stats at battery screen when charging
  • Loading branch information
zorgms committed Oct 22, 2024
1 parent f0117a7 commit 363d0dc
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 3 deletions.
Binary file modified app/release/app-release.apk
Binary file not shown.
27 changes: 25 additions & 2 deletions app/src/main/java/com/openvehicles/OVMS/api/ApiService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ import com.openvehicles.OVMS.api.ApiObservable.deleteObserver
import com.openvehicles.OVMS.api.ApiObservable.notifyLoggedIn
import com.openvehicles.OVMS.api.ApiObservable.notifyUpdate
import com.openvehicles.OVMS.entities.CarData
import com.openvehicles.OVMS.utils.AppPrefs
import com.openvehicles.OVMS.ui.MainActivity
import com.openvehicles.OVMS.ui.utils.Database
import com.openvehicles.OVMS.utils.AppPrefs
import com.openvehicles.OVMS.utils.CarsStorage
import com.openvehicles.OVMS.utils.Sys
import java.io.Serializable
Expand Down Expand Up @@ -314,7 +314,7 @@ class ApiService : Service(), ApiTask.ApiTaskListener, ApiObserver {
try {
if (apiTask != null) {
Log.v(TAG, "closeConnection: shutting down TCP connection")
apiTask!!.cancel(true)
//apiTask!!.cancel(true)
apiTask = null
notifyLoggedIn(this, false)
sendApiEvent("UpdateStatus")
Expand Down Expand Up @@ -485,6 +485,29 @@ class ApiService : Service(), ApiTask.ApiTaskListener, ApiObserver {
override fun onPushNotification(msgClass: Char, msgText: String?) {
// This callback only receives MP push notifications for the currently selected vehicle.
// See MyFirebaseMessagingService for system notification broadcasting.
val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
createNotificationChannel()
// Define the notification channel (required for Android O and above)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val channelName = getString(R.string.app_name)
val channelDescription = "OVMS"
val channel = NotificationChannel("your_channel_id", channelName, NotificationManager.IMPORTANCE_DEFAULT).apply {
description = channelDescription
}
notificationManager.createNotificationChannel(channel)
}
// Create the notification
val notificationBuilder = NotificationCompat.Builder(this, "your_channel_id")
.setSmallIcon(R.drawable.ic_service)
.setContentTitle("OVMS")
.setContentText(msgText ?: msgText)
.setPriority(NotificationCompat.PRIORITY_DEFAULT)
.setAutoCancel(true)

// Show the notification
if(appPrefs!!.getData("option_notification_enabled_" + carData!!.sel_vehicleid,"1") == "1"){
notificationManager.notify(1, notificationBuilder.build())
}
}

// ApiObserver interface:
Expand Down
14 changes: 13 additions & 1 deletion app/src/main/java/com/openvehicles/OVMS/ui/InfoFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -847,6 +847,7 @@ class InfoFragment : BaseFragment(), View.OnClickListener, OnResultCommandListen
bar.visibility = View.INVISIBLE
cmtv.visibility = View.INVISIBLE
coiv.visibility = View.INVISIBLE
tv.visibility = View.VISIBLE
tv_or.visibility = View.INVISIBLE
tvl.visibility = View.INVISIBLE
tvr.visibility = View.INVISIBLE
Expand Down Expand Up @@ -885,7 +886,7 @@ class InfoFragment : BaseFragment(), View.OnClickListener, OnResultCommandListen
cmtv.visibility = View.VISIBLE
if ((this.carData!!.car_type == "RT") || (this.carData!!.car_type == "SQ")) {
// Renault Twizy: no charge control
findViewById(R.id.tabInfoImageCharger)!!.visibility = View.VISIBLE
findViewById(R.id.tabInfoImageCharger).visibility = View.VISIBLE
bar.visibility = View.INVISIBLE
tvl.visibility = View.INVISIBLE
tvr.visibility = View.INVISIBLE
Expand All @@ -898,6 +899,17 @@ class InfoFragment : BaseFragment(), View.OnClickListener, OnResultCommandListen
4 -> chargeStateInfo = R.string.state_done
21 -> chargeStateInfo = R.string.state_stopped
}
if (this.carData!!.car_type == "SQ") {
tvPowerInput.text = String.format("▾ %s min.",(carData.car_charge_duration_raw/60).toString())
tvPowerInput.visibility = View.VISIBLE
tvPowerLoss.text = String.format("⚡ %s %%",carData.car_charger_efficiency)
tvPowerLoss.visibility = View.VISIBLE
tvPowerInput.translationY = "160".toFloat()
tvPowerInput.translationX = "60".toFloat()
tvPowerLoss.translationY = "280".toFloat()
tvPowerLoss.translationX = "-190".toFloat()
tvPowerLoss.setTextColor(-0xFFAA44)
}
if (chargeStateInfo != 0) {
tvf.text = String.format(
getText(chargeStateInfo).toString(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class GlobalOptionsFragment : BaseFragment(), View.OnClickListener, OnFocusChang
// Currently unused, may be reused if single messages shall be sent
private var broadcastCodes: String? = null
private var commandsEnabled = false
private var notificationEnabled = false
private var pluginEnabled = false
private var firmwareEnabled = false

Expand All @@ -56,6 +57,7 @@ class GlobalOptionsFragment : BaseFragment(), View.OnClickListener, OnFocusChang
broadcastEnabled = appPrefs!!.getData("option_broadcast_enabled", "0") == "1"
broadcastCodes = appPrefs!!.getData("option_broadcast_codes", DEFAULT_BROADCAST_CODES)
commandsEnabled = appPrefs!!.getData("option_commands_enabled", "0") == "1"
notificationEnabled = appPrefs!!.getData("option_notification_enabled_" + app_Car_ID, "1") == "1"
pluginEnabled = appPrefs!!.getData("option_plugin_enabled_" + app_Car_ID, "0") == "1"
firmwareEnabled = appPrefs!!.getData("option_firmware_enabled_" + app_Car_ID, "0") == "1"
var checkBox: CheckBox = findViewById(R.id.cb_options_service) as CheckBox
Expand All @@ -74,6 +76,9 @@ class GlobalOptionsFragment : BaseFragment(), View.OnClickListener, OnFocusChang
checkBox = findViewById(R.id.cb_options_commands) as CheckBox
checkBox.setChecked(commandsEnabled)
checkBox.setOnClickListener(this)
checkBox = findViewById(R.id.cb_options_notification) as CheckBox
checkBox.setChecked(notificationEnabled)
checkBox.setOnClickListener(this)
checkBox = findViewById(R.id.cb_options_plugin) as CheckBox
checkBox.setChecked(pluginEnabled)
checkBox.setOnClickListener(this)
Expand Down Expand Up @@ -122,6 +127,10 @@ class GlobalOptionsFragment : BaseFragment(), View.OnClickListener, OnFocusChang
commandsEnabled = (v as CheckBox).isChecked
appPrefs!!.saveData("option_commands_enabled", if (commandsEnabled) "1" else "0")
}
R.id.cb_options_notification -> {
notificationEnabled = (v as CheckBox).isChecked
appPrefs!!.saveData("option_notification_enabled_" + app_Car_ID, if (notificationEnabled) "1" else "0")
}
R.id.cb_options_plugin -> {
pluginEnabled = (v as CheckBox).isChecked
appPrefs!!.saveData("option_plugin_enabled_" + app_Car_ID, if (pluginEnabled) "1" else "0")
Expand Down
21 changes: 21 additions & 0 deletions app/src/main/res/layout/fragment_globaloptions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,27 @@

</TableRow>

<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="4dp">

<TextView
android:text="@string/lb_options_notification"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
tools:ignore="DuplicateIds" />

<CheckBox
android:text="@string/lb_options_notification_cb"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="@+id/cb_options_notification"
android:layout_gravity="center_vertical"
android:layout_weight="1"/>
</TableRow>

<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,8 @@
<string name="lb_options_broadcast">Weitergabe:</string>
<string name="lb_options_broadcast_cb">Daten an andere Apps weiterleiten</string>
<string name="lb_options_broadcast_codes">Codes eingeben</string>
<string name="lb_options_notification">Meldungen:</string>
<string name="lb_options_notification_cb">Aktiviere Meldungen anzeigen</string>
<string name="lb_options_commands">Befehle:</string>
<string name="lb_options_commands_cb">Fahrzeug-Kommandos freigeben</string>
<string name="lb_options_apikey">API-Schlüssel:</string>
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,8 @@
<string name="lb_options_broadcast">Broadcast:</string>
<string name="lb_options_broadcast_cb">Enable data broadcasts to other Apps</string>
<string name="lb_options_broadcast_codes">Enter code letters</string>
<string name="lb_options_notification">Notification:</string>
<string name="lb_options_notification_cb">Enable show notification</string>
<string name="lb_options_commands">Commands:</string>
<string name="lb_options_commands_cb">Enable vehicle command service</string>
<string name="lb_options_apikey">API key:</string>
Expand Down

0 comments on commit 363d0dc

Please sign in to comment.