[-] Remove test2 button
This commit is contained in:
@@ -1,11 +1,9 @@
|
|||||||
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
|
||||||
@@ -39,24 +37,7 @@ class ActivitySettings : AppCompatActivity()
|
|||||||
findPreference<Preference>("infTestButton")!!.setOnPreferenceClickListener {
|
findPreference<Preference>("infTestButton")!!.setOnPreferenceClickListener {
|
||||||
scope.launch {
|
scope.launch {
|
||||||
try {
|
try {
|
||||||
val ver = act.prefs.createInflux().version()
|
act.prefs.influxPing()
|
||||||
println("Success, version is $ver")
|
|
||||||
view?.snack("Success, version is $ver")
|
|
||||||
}
|
|
||||||
catch (e: Exception) {
|
|
||||||
e.printStackTrace()
|
|
||||||
view?.snack("Error: ${e.message}")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
true
|
|
||||||
}
|
|
||||||
|
|
||||||
findPreference<Preference>("infTest2Button")!!.setOnPreferenceClickListener {
|
|
||||||
scope.launch {
|
|
||||||
try {
|
|
||||||
with(act.prefs.createInflux()) {
|
|
||||||
getWriteKotlinApi().writeRecord("ping host=\"$MODEL\"", WritePrecision.MS)
|
|
||||||
}
|
|
||||||
println("Success!")
|
println("Success!")
|
||||||
view?.snack("Success!")
|
view?.snack("Success!")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,10 +4,12 @@ import android.app.Activity
|
|||||||
import android.bluetooth.BluetoothManager
|
import android.bluetooth.BluetoothManager
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
|
import android.os.Build
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import androidx.core.content.edit
|
import androidx.core.content.edit
|
||||||
import androidx.preference.PreferenceManager
|
import androidx.preference.PreferenceManager
|
||||||
import com.google.android.material.snackbar.Snackbar
|
import com.google.android.material.snackbar.Snackbar
|
||||||
|
import com.influxdb.client.domain.WritePrecision
|
||||||
import com.influxdb.client.kotlin.InfluxDBClientKotlin
|
import com.influxdb.client.kotlin.InfluxDBClientKotlin
|
||||||
import com.influxdb.client.kotlin.InfluxDBClientKotlinFactory
|
import com.influxdb.client.kotlin.InfluxDBClientKotlinFactory
|
||||||
import kotlin.reflect.KProperty
|
import kotlin.reflect.KProperty
|
||||||
@@ -30,6 +32,7 @@ interface Prefs {
|
|||||||
var infToken: String?
|
var infToken: String?
|
||||||
|
|
||||||
fun createInflux(): InfluxDBClientKotlin
|
fun createInflux(): InfluxDBClientKotlin
|
||||||
|
suspend fun influxPing()
|
||||||
}
|
}
|
||||||
|
|
||||||
val Context.pref get() = PreferenceManager.getDefaultSharedPreferences(this)
|
val Context.pref get() = PreferenceManager.getDefaultSharedPreferences(this)
|
||||||
@@ -49,6 +52,10 @@ val Context.prefs get() = object : Prefs {
|
|||||||
|
|
||||||
override fun createInflux() = InfluxDBClientKotlinFactory
|
override fun createInflux() = InfluxDBClientKotlinFactory
|
||||||
.create(infUrl ?: "", (infToken ?: "").toCharArray(), infOrg ?: "", infBucket ?: "")
|
.create(infUrl ?: "", (infToken ?: "").toCharArray(), infOrg ?: "", infBucket ?: "")
|
||||||
|
|
||||||
|
override suspend fun influxPing() = with(createInflux()) {
|
||||||
|
getWriteKotlinApi().writeRecord("ping host=\"${Build.MODEL}\"", WritePrecision.MS)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inline fun <reified T : Activity> Context.act() = startActivity(Intent(this, T::class.java))
|
inline fun <reified T : Activity> Context.act() = startActivity(Intent(this, T::class.java))
|
||||||
|
|||||||
@@ -11,6 +11,4 @@
|
|||||||
<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">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,11 +32,6 @@
|
|||||||
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