optimised the unnecessary code in json
added sever info in home fragment removed basic data test
This commit is contained in:
@@ -70,19 +70,19 @@ class DatabaseRepository @Inject constructor(
|
||||
|
||||
|
||||
|
||||
// Example function to add data to Firestore
|
||||
@RequiresApi(Build.VERSION_CODES.O)
|
||||
fun addtodb(data: String) {
|
||||
val date = LocalTime.now()
|
||||
localdb.collection("BasicData")
|
||||
.add(mapOf("data $date" to data))
|
||||
.addOnSuccessListener {
|
||||
Log.d("UPLOAD", "Data uploaded successfully ${localdb.app.name}")
|
||||
}
|
||||
.addOnFailureListener { exception ->
|
||||
Log.d("UPLOAD", "Failed to upload data: ${exception.message} ${localdb.app.name}")
|
||||
}
|
||||
}
|
||||
// // Example function to add data to Firestore , like the basic data as test data
|
||||
// @RequiresApi(Build.VERSION_CODES.O)
|
||||
// fun addtodb(data: String) {
|
||||
// val date = LocalTime.now()
|
||||
// localdb.collection("BasicData")
|
||||
// .add(mapOf("data $date" to data))
|
||||
// .addOnSuccessListener {
|
||||
// Log.d("UPLOAD", "Data uploaded successfully ${localdb.app.name}")
|
||||
// }
|
||||
// .addOnFailureListener { exception ->
|
||||
// Log.d("UPLOAD", "Failed to upload data: ${exception.message} ${localdb.app.name}")
|
||||
// }
|
||||
// }
|
||||
private suspend fun <T : Any> safeApiCall(apiCall: suspend () -> T): Result<T> {
|
||||
return try {
|
||||
val response = apiCall.invoke()
|
||||
|
||||
@@ -86,6 +86,7 @@ class DashboardActivity : AppCompatActivity(), IDataCollector {
|
||||
super.attachBaseContext(newBase)
|
||||
}
|
||||
|
||||
|
||||
override fun onMessageReceived(topic: String, message: String) {
|
||||
// Handle incoming messages from NATS
|
||||
|
||||
@@ -102,12 +103,7 @@ class DashboardActivity : AppCompatActivity(), IDataCollector {
|
||||
setSupportActionBar(binding.appBarDashboard.toolbar)
|
||||
nats = NatsManager(this)
|
||||
|
||||
|
||||
// Load the last selected server or default to Server 1
|
||||
val lastSelectedServer = firebaseManager.getLastSelectedServer()
|
||||
|
||||
// Switch to the last selected server
|
||||
|
||||
val currentServer = firebaseManager.getLastSelectedServer().serverName
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
nats.connect()
|
||||
@@ -117,7 +113,7 @@ class DashboardActivity : AppCompatActivity(), IDataCollector {
|
||||
Log.d("DashboardActivity", "Saved Kit Serial: $savedKitSerial")
|
||||
// Toast.makeText(this, "Saved Kit Serial: $savedKitSerial", Toast.LENGTH_SHORT).show()
|
||||
|
||||
val versionName = getAppVersion(this@DashboardActivity) + " [ " + getAppEnvironment(this@DashboardActivity) + " ]"
|
||||
val versionName = getAppVersion(this@DashboardActivity) + " [ " + getAppEnvironment(this@DashboardActivity) +"->"+currentServer+"]"
|
||||
binding.appBarDashboard.versionName.text = versionName
|
||||
|
||||
|
||||
@@ -259,10 +255,10 @@ class DashboardActivity : AppCompatActivity(), IDataCollector {
|
||||
|
||||
|
||||
|
||||
fun sendData(data:String){
|
||||
databaseRepository.addtodb(data)
|
||||
Toast.makeText(this, "data uploaded", Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
// fun sendData(data:String){ this was used to send the basic data for server validation
|
||||
// databaseRepository.addtodb(data)
|
||||
// Toast.makeText(this, "data uploaded", Toast.LENGTH_SHORT).show()
|
||||
// }
|
||||
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
||||
@@ -390,6 +386,7 @@ class DashboardActivity : AppCompatActivity(), IDataCollector {
|
||||
return try {
|
||||
val pInfo = context.packageManager.getPackageInfo(context.packageName, 0)
|
||||
pInfo.versionName
|
||||
|
||||
} catch (e: PackageManager.NameNotFoundException) {
|
||||
"N/A"
|
||||
}
|
||||
|
||||
@@ -182,9 +182,9 @@ class PrefsFragment : PreferenceFragmentCompat(){
|
||||
icon = ContextCompat.getDrawable(requireContext(), R.drawable.baseline_cloud_done_24)
|
||||
|
||||
setOnPreferenceClickListener {
|
||||
(activity as? DashboardActivity)?.sendData("hello test data")
|
||||
Toast.makeText(context, "data sent", Toast.LENGTH_SHORT).show()
|
||||
true
|
||||
// (activity as? DashboardActivity)?.sendData("hello test data")
|
||||
// Toast.makeText(context, "data sent", Toast.LENGTH_SHORT).show() this was used to send the basic data as test data
|
||||
true
|
||||
}
|
||||
}
|
||||
preferenceScreen.addPreference(currentServerPreference)
|
||||
|
||||
Reference in New Issue
Block a user