conflict fixed
This commit is contained in:
@@ -114,7 +114,7 @@ class DeviceListAdapter(
|
||||
}
|
||||
}
|
||||
val inflater = popup.menuInflater
|
||||
popup.setForceShowIcon(true)
|
||||
// popup.setForceShowIcon(true)
|
||||
inflater.inflate(R.menu.device_menu, popup.menu)
|
||||
popup.show()
|
||||
}
|
||||
|
||||
@@ -173,6 +173,7 @@ class KirbyDevice(
|
||||
Log.i("BleListener", "Char received: $payload")
|
||||
val base64Payload = Base64.getEncoder().encodeToString(characteristic.value)
|
||||
publishMeasurement(base64Payload)
|
||||
// publishMeasurementAutoServer(measurement)
|
||||
|
||||
loggerDb.writeLog(measurement)
|
||||
}
|
||||
@@ -216,6 +217,50 @@ class KirbyDevice(
|
||||
queue.add(request)
|
||||
}
|
||||
|
||||
private fun publishMeasurementAutoServer(measurement: DecoderIaq.Measurement) {
|
||||
// Read url from SharedPreferences
|
||||
val sharedPref = context.getSharedPreferences(context.getString(R.string.app_name), Context.MODE_PRIVATE)
|
||||
val url = sharedPref.getString(
|
||||
"kirby_data_post_url",
|
||||
context.getString(R.string.kirby_data_post_url_default)) ?: context.getString(R.string.kirby_data_post_url_default)
|
||||
val accessKey = BuildConfig.API_KEY
|
||||
|
||||
if(url.isEmpty()) {
|
||||
return
|
||||
}
|
||||
|
||||
val eui = "0000${bleDevice.address.replace(":", "")}"
|
||||
|
||||
val postData = JSONObject()
|
||||
|
||||
try {
|
||||
// Log.i("POST", "Transmitting for $eui: $payload")
|
||||
postData.put("accessKey", "${accessKey}_fromAndroid")
|
||||
postData.put("eui", eui)
|
||||
postData.put("deviceId", measurement.deviceId)
|
||||
postData.put("msgType", measurement.msgType)
|
||||
postData.put("co2", measurement.co2)
|
||||
postData.put("voc", measurement.voc)
|
||||
postData.put("humidity", measurement.humidity)
|
||||
postData.put("temperature", measurement.temperature)
|
||||
postData.put("pressure", measurement.pressure)
|
||||
postData.put("occupancy", measurement.occupancy)
|
||||
postData.put("pm25", measurement.pm25)
|
||||
postData.put("pm10", measurement.pm10)
|
||||
} catch (e: JSONException) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
|
||||
val request = JsonObjectRequest(
|
||||
Request.Method.POST, url, postData,
|
||||
{ response ->
|
||||
Log.i("sendDataResponse", "Response is: $response")
|
||||
}
|
||||
) { error -> error.printStackTrace() }
|
||||
|
||||
queue.add(request)
|
||||
}
|
||||
|
||||
private val measurements = ArrayList<Payload>()
|
||||
private val maxMeasurements = 20
|
||||
|
||||
|
||||
@@ -330,6 +330,13 @@ class MainActivity : AppCompatActivity() {
|
||||
return true
|
||||
}
|
||||
|
||||
R.id.action_server_setting -> {
|
||||
// Goto server setting intent
|
||||
val intent = Intent(this, ServerSettingActivity::class.java)
|
||||
startActivity(intent)
|
||||
return true
|
||||
}
|
||||
|
||||
else -> super.onOptionsItemSelected(item)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
package com.logitech.vc.kirbytest
|
||||
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import android.widget.Button
|
||||
import android.widget.EditText
|
||||
import androidx.activity.enableEdgeToEdge
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.core.view.ViewCompat
|
||||
import androidx.core.view.WindowInsetsCompat
|
||||
|
||||
class ServerSettingActivity : AppCompatActivity() {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
enableEdgeToEdge()
|
||||
setContentView(R.layout.activity_server_setting)
|
||||
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
|
||||
val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
|
||||
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
|
||||
insets
|
||||
}
|
||||
|
||||
// Get current server setting from SharedPreferences
|
||||
val sharedPref = getSharedPreferences(getString(R.string.app_name), MODE_PRIVATE)
|
||||
var currentUrl = sharedPref.getString(
|
||||
"kirby_data_post_url",
|
||||
getString(R.string.kirby_data_post_url_default)) ?: getString(R.string.kirby_data_post_url_default)
|
||||
val editTextServerSetting = findViewById<EditText>(R.id.editTextServerSetting)
|
||||
editTextServerSetting.setText(currentUrl)
|
||||
|
||||
val doneButton = findViewById<Button>(R.id.buttonDone)
|
||||
doneButton.setOnClickListener {
|
||||
// Save editTextServerSetting to SharedPreferences
|
||||
val serverSetting = editTextServerSetting.text.toString()
|
||||
sharedPref.edit().putString("kirby_data_post_url", serverSetting).apply()
|
||||
finish()
|
||||
}
|
||||
|
||||
val cancelButton = findViewById<Button>(R.id.buttonCancel)
|
||||
cancelButton.setOnClickListener {
|
||||
finish()
|
||||
}
|
||||
|
||||
val defaultButton = findViewById<Button>(R.id.buttonDefault)
|
||||
defaultButton.setOnClickListener {
|
||||
editTextServerSetting.setText(getString(R.string.kirby_data_post_url_default))
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user