[+] Influx authentication check

This commit is contained in:
Azalea Gui
2023-01-23 20:56:53 -05:00
parent df84e3a22d
commit dcd063c677
3 changed files with 28 additions and 5 deletions
@@ -1,18 +1,18 @@
package org.hydev.wearsync
import android.os.Build.MODEL
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat
import com.influxdb.client.domain.WritePrecision
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.launch
class ActivitySettings : AppCompatActivity()
{
override fun onCreate(savedInstanceState: Bundle?)
{
super.onCreate(savedInstanceState)
@@ -48,7 +48,23 @@ class ActivitySettings : AppCompatActivity()
view?.snack("Error: ${e.message}")
}
}
println("Clicked")
true
}
findPreference<Preference>("infTest2Button")!!.setOnPreferenceClickListener {
scope.launch {
try {
with(act.prefs.createInflux()) {
getWriteKotlinApi().writeRecord("ping host=\"$MODEL\"", WritePrecision.MS)
}
println("Success!")
view?.snack("Success!")
}
catch (e: Exception) {
e.printStackTrace()
view?.snack("Error: ${e.message}")
}
}
true
}
}
+4 -2
View File
@@ -9,6 +9,8 @@
<string name="pref_influx_org">Organization</string>
<string name="pref_influx_bucket">Bucket</string>
<string name="pref_influx_token">Token</string>
<string name="pref_influx_test">Test connection</string>
<string name="pref_influx_test_sub">Click here to test your connection to the influxdb server.</string>
<string name="pref_influx_test">Test Connection</string>
<string name="pref_influx_test_sub">Test your connection to the influxdb server.</string>
<string name="pref_influx_test2">Test Authentication</string>
<string name="pref_influx_test2_sub">Test if your token has permissions.</string>
</resources>
@@ -32,6 +32,11 @@
app:title="@string/pref_influx_test"
app:summary="@string/pref_influx_test_sub" />
<Preference
android:key="infTest2Button"
app:title="@string/pref_influx_test2"
app:summary="@string/pref_influx_test2_sub" />
</PreferenceCategory>
</PreferenceScreen>