Добавить app/src/main/java/ru/myitschool/work/ui/profile/comment.kt
This commit is contained in:
parent
852108826a
commit
7e41c2cf4b
81
app/src/main/java/ru/myitschool/work/ui/profile/comment.kt
Normal file
81
app/src/main/java/ru/myitschool/work/ui/profile/comment.kt
Normal file
@ -0,0 +1,81 @@
|
|||||||
|
// import android.os.Bundle
|
||||||
|
// import android.widget.Button
|
||||||
|
// import android.widget.EditText
|
||||||
|
// import android.widget.Toast
|
||||||
|
// import androidx.appcompat.app.AppCompatActivity
|
||||||
|
// import com.google.gson.Gson
|
||||||
|
// import com.google.gson.annotations.SerializedName
|
||||||
|
// import okhttp3.OkHttpClient
|
||||||
|
// import okhttp3.Request
|
||||||
|
// import okhttp3.Response
|
||||||
|
// import okhttp3.MediaType.Companion.toMediaType
|
||||||
|
// import okhttp3.RequestBody.Companion.toRequestBody
|
||||||
|
// import kotlinx.coroutines.CoroutineScope
|
||||||
|
// import kotlinx.coroutines.Dispatchers
|
||||||
|
// import kotlinx.coroutines.launch
|
||||||
|
// import kotlinx.coroutines.withContext
|
||||||
|
|
||||||
|
// data class UserCredentials(
|
||||||
|
// @SerializedName("username") val username: String,
|
||||||
|
// @SerializedName("password") val password: String
|
||||||
|
// )
|
||||||
|
|
||||||
|
// class MainActivity : AppCompatActivity() {
|
||||||
|
|
||||||
|
// private lateinit var usernameEditText: EditText
|
||||||
|
// private lateinit var passwordEditText: EditText
|
||||||
|
// private lateinit var submitButton: Button
|
||||||
|
|
||||||
|
// override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
|
// super.onCreate(savedInstanceState)
|
||||||
|
// setContentView(R.layout.activity_main)
|
||||||
|
|
||||||
|
// usernameEditText = findViewById(R.id.usernameEditText)
|
||||||
|
// passwordEditText = findViewById(R.id.passwordEditText)
|
||||||
|
// submitButton = findViewById(R.id.submitButton)
|
||||||
|
|
||||||
|
// submitButton.setOnClickListener {
|
||||||
|
// val username = usernameEditText.text.toString()
|
||||||
|
// val password = passwordEditText.text.toString()
|
||||||
|
// sendDataToServer(username, password)
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// private fun sendDataToServer(username: String, password: String) {
|
||||||
|
// val userCredentials = UserCredentials(username, password)
|
||||||
|
// val json = Gson().toJson(userCredentials)
|
||||||
|
|
||||||
|
// CoroutineScope(Dispatchers.IO).launch {
|
||||||
|
// val response = postData(json)
|
||||||
|
// withContext(Dispatchers.Main) {
|
||||||
|
// if (response != null) {
|
||||||
|
// Toast.makeText(this@MainActivity, "Response: $response", Toast.LENGTH_LONG).show()
|
||||||
|
// } else {
|
||||||
|
// Toast.makeText(this@MainActivity, "Failed to send data", Toast.LENGTH_LONG).show()
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// private suspend fun postData(json: String): String? {
|
||||||
|
// val client = OkHttpClient()
|
||||||
|
// val requestBody = json.toRequestBody("application/json; charset=utf-8".toMediaType())
|
||||||
|
|
||||||
|
// val request = Request.Builder()
|
||||||
|
// .url("http://192.168.1.142:8080")
|
||||||
|
// .post(requestBody)
|
||||||
|
// .build()
|
||||||
|
|
||||||
|
// return try {
|
||||||
|
// val response: Response = client.newCall(request).execute()
|
||||||
|
// if (response.isSuccessful) {
|
||||||
|
// response.body?.string()
|
||||||
|
// } else {
|
||||||
|
// null
|
||||||
|
// }
|
||||||
|
// } catch (e: Exception) {
|
||||||
|
// e.printStackTrace()
|
||||||
|
// null
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
Loading…
x
Reference in New Issue
Block a user