fix: implement updateTrackingConfig and getStatus in BridgeModule
This commit is contained in:
parent
cb8c1ab43b
commit
4365084625
3 changed files with 32 additions and 8 deletions
|
|
@ -1,6 +1,7 @@
|
|||
package com.traccar.traccar_client
|
||||
|
||||
import android.content.Context
|
||||
import android.content.SharedPreferences
|
||||
import com.traccar.traccar_client.service.LocationTrackingService
|
||||
import io.flutter.embedding.engine.plugins.FlutterPlugin
|
||||
import io.flutter.plugin.common.EventChannel
|
||||
|
|
@ -12,9 +13,11 @@ class BridgeModule : FlutterPlugin, MethodChannel.MethodCallHandler {
|
|||
private lateinit var methodChannel: MethodChannel
|
||||
private lateinit var eventChannel: EventChannel
|
||||
private var context: Context? = null
|
||||
private lateinit var prefs: SharedPreferences
|
||||
|
||||
override fun onAttachedToEngine(binding: FlutterPlugin.FlutterPluginBinding) {
|
||||
context = binding.applicationContext
|
||||
prefs = binding.applicationContext.getSharedPreferences("traccar_prefs", Context.MODE_PRIVATE)
|
||||
|
||||
methodChannel = MethodChannel(binding.binaryMessenger, "com.traccar.client/tracking")
|
||||
methodChannel.setMethodCallHandler(this)
|
||||
|
|
@ -57,11 +60,7 @@ class BridgeModule : FlutterPlugin, MethodChannel.MethodCallHandler {
|
|||
result.success(true)
|
||||
}
|
||||
"getStatus" -> {
|
||||
result.success(mapOf(
|
||||
"isTracking" to false,
|
||||
"lastLatitude" to 0.0,
|
||||
"lastLongitude" to 0.0
|
||||
))
|
||||
result.success(getTrackingStatus())
|
||||
}
|
||||
else -> result.notImplemented()
|
||||
}
|
||||
|
|
@ -82,5 +81,30 @@ class BridgeModule : FlutterPlugin, MethodChannel.MethodCallHandler {
|
|||
}
|
||||
|
||||
private fun updateTrackingConfig(config: Map<*, *>?) {
|
||||
if (config == null) return
|
||||
prefs.edit().apply {
|
||||
config["serverUrl"]?.let { putString("server_url", it.toString()) }
|
||||
config["deviceId"]?.let { putString("device_id", it.toString()) }
|
||||
config["accuracy"]?.let { putInt("accuracy", (it as Number).toInt()) }
|
||||
config["distanceFilter"]?.let { putInt("distance_filter", (it as Number).toInt()) }
|
||||
config["interval"]?.let { putInt("interval", (it as Number).toInt()) }
|
||||
config["heartbeat"]?.let { putInt("heartbeat", (it as Number).toInt()) }
|
||||
config["offlineBuffer"]?.let { putBoolean("offline_buffer", it as Boolean) }
|
||||
config["stopDetection"]?.let { putBoolean("stop_detection", it as Boolean) }
|
||||
apply()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun getTrackingStatus(): Map<String, Any> {
|
||||
return mapOf(
|
||||
"isTracking" to prefs.getBoolean("tracking_active", false),
|
||||
"lastLatitude" to prefs.getFloat("last_latitude", 0f).toDouble(),
|
||||
"lastLongitude" to prefs.getFloat("last_longitude", 0f).toDouble(),
|
||||
"lastAccuracy" to prefs.getFloat("last_accuracy", 0f).toDouble(),
|
||||
"lastSpeed" to prefs.getFloat("last_speed", 0f).toDouble(),
|
||||
"lastHeading" to prefs.getFloat("last_heading", 0f).toDouble(),
|
||||
"lastAltitude" to prefs.getFloat("last_altitude", 0f).toDouble(),
|
||||
"lastTimestamp" to prefs.getLong("last_timestamp", 0L)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
@ -61,4 +61,4 @@ class LocationBridge {
|
|||
);
|
||||
return _locationStream!;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,4 +10,4 @@ void main() {
|
|||
// Verify the app title is displayed
|
||||
expect(find.text('Traccar Client'), findsOneWidget);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue