[+] Influx authentication check
This commit is contained in:
@@ -1,18 +1,18 @@
|
|||||||
package org.hydev.wearsync
|
package org.hydev.wearsync
|
||||||
|
|
||||||
|
import android.os.Build.MODEL
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import androidx.preference.Preference
|
import androidx.preference.Preference
|
||||||
import androidx.preference.PreferenceFragmentCompat
|
import androidx.preference.PreferenceFragmentCompat
|
||||||
|
import com.influxdb.client.domain.WritePrecision
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.SupervisorJob
|
import kotlinx.coroutines.SupervisorJob
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
|
||||||
|
|
||||||
class ActivitySettings : AppCompatActivity()
|
class ActivitySettings : AppCompatActivity()
|
||||||
{
|
{
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?)
|
override fun onCreate(savedInstanceState: Bundle?)
|
||||||
{
|
{
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
@@ -48,7 +48,23 @@ class ActivitySettings : AppCompatActivity()
|
|||||||
view?.snack("Error: ${e.message}")
|
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
|
true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,8 @@
|
|||||||
<string name="pref_influx_org">Organization</string>
|
<string name="pref_influx_org">Organization</string>
|
||||||
<string name="pref_influx_bucket">Bucket</string>
|
<string name="pref_influx_bucket">Bucket</string>
|
||||||
<string name="pref_influx_token">Token</string>
|
<string name="pref_influx_token">Token</string>
|
||||||
<string name="pref_influx_test">Test connection</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_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>
|
</resources>
|
||||||
@@ -32,6 +32,11 @@
|
|||||||
app:title="@string/pref_influx_test"
|
app:title="@string/pref_influx_test"
|
||||||
app:summary="@string/pref_influx_test_sub" />
|
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>
|
</PreferenceCategory>
|
||||||
|
|
||||||
</PreferenceScreen>
|
</PreferenceScreen>
|
||||||
Reference in New Issue
Block a user