|
@@ -2,6 +2,8 @@ package tech.xiongweixp.touchaction
|
|
|
|
|
|
import android.os.Bundle
|
|
|
import android.util.Log
|
|
|
+import android.widget.Button
|
|
|
+import android.widget.TextView
|
|
|
import androidx.activity.ComponentActivity
|
|
|
import androidx.activity.compose.setContent
|
|
|
import androidx.activity.enableEdgeToEdge
|
|
@@ -12,19 +14,39 @@ import androidx.compose.material3.Text
|
|
|
import androidx.compose.runtime.Composable
|
|
|
import androidx.compose.ui.Modifier
|
|
|
import androidx.compose.ui.tooling.preview.Preview
|
|
|
+import androidx.constraintlayout.widget.ConstraintLayout
|
|
|
import tech.xiongweixp.touchaction.ui.theme.TouchActionTheme
|
|
|
import java.net.HttpURLConnection
|
|
|
import java.net.URL
|
|
|
|
|
|
class MainActivity : ComponentActivity() {
|
|
|
+ private var computerLayout: ConstraintLayout? = null
|
|
|
+ private var lightLayout: ConstraintLayout? = null
|
|
|
+ private var mainLayout: ConstraintLayout? = null
|
|
|
+ private var computerTextView: TextView? = null
|
|
|
+ private var compterCloseBtn: Button? = null
|
|
|
+
|
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
|
super.onCreate(savedInstanceState)
|
|
|
+ setContentView(R.layout.mainlayout)
|
|
|
+ computerLayout = findViewById(R.id.computerLayout)
|
|
|
+ lightLayout = findViewById(R.id.lightLayout)
|
|
|
+ mainLayout = findViewById(R.id.mainLayout)
|
|
|
+ computerTextView = findViewById(R.id.computerText)
|
|
|
+ compterCloseBtn = findViewById(R.id.computerCloseButton)
|
|
|
+
|
|
|
+ compterCloseBtn!!.setOnClickListener {
|
|
|
+ //退出APP
|
|
|
+ finish()
|
|
|
+ }
|
|
|
enableEdgeToEdge()
|
|
|
Log.i("MainActivity", "打开APP")
|
|
|
Log.i("MainActivity", intent.data.toString())
|
|
|
- setContentView(R.layout.mainlayout)
|
|
|
+
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
private fun hassioRequest(webhookID: String) {
|
|
|
Thread {
|
|
|
try {
|
|
@@ -55,12 +77,25 @@ class MainActivity : ComponentActivity() {
|
|
|
when (action) {
|
|
|
"computer" -> {
|
|
|
// 电脑
|
|
|
+ computerLayout!!.visibility = ConstraintLayout.VISIBLE
|
|
|
+ lightLayout!!.visibility = ConstraintLayout.INVISIBLE
|
|
|
+ mainLayout!!.visibility = ConstraintLayout.INVISIBLE
|
|
|
+ computerTextView!!.text = "操作电脑开关"
|
|
|
hassioRequest("computer")
|
|
|
}
|
|
|
"light" -> {
|
|
|
// 灯
|
|
|
+ computerLayout!!.visibility = ConstraintLayout.INVISIBLE
|
|
|
+ lightLayout!!.visibility = ConstraintLayout.VISIBLE
|
|
|
+ mainLayout!!.visibility = ConstraintLayout.INVISIBLE
|
|
|
hassioRequest("light")
|
|
|
}
|
|
|
+ else -> {
|
|
|
+ // 主界面
|
|
|
+ computerLayout!!.visibility = ConstraintLayout.INVISIBLE
|
|
|
+ lightLayout!!.visibility = ConstraintLayout.INVISIBLE
|
|
|
+ mainLayout!!.visibility = ConstraintLayout.VISIBLE
|
|
|
+ }
|
|
|
// "save" -> {
|
|
|
// // 保存
|
|
|
// }
|