._.
This commit is contained in:
parent
13429ca61d
commit
56593401d3
@ -5,7 +5,7 @@
|
||||
<uses-permission android:name="android.permission.INTERNET"/>
|
||||
|
||||
<application
|
||||
android:allowClearUserData="true"
|
||||
android:usesCleartextTraffic="true"
|
||||
android:allowBackup="true"
|
||||
android:dataExtractionRules="@xml/data_extraction_rules"
|
||||
android:fullBackupContent="@xml/backup_rules"
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
package com.example.russionroadsapp
|
||||
|
||||
import kotlinx.coroutines.DelicateCoroutinesApi
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.GlobalScope
|
||||
import kotlinx.coroutines.launch
|
||||
@ -9,8 +10,9 @@ import java.net.HttpURLConnection
|
||||
import java.net.URL
|
||||
|
||||
object API {
|
||||
private val API_BASE_URL = "http://192.168.0.124:5000"
|
||||
private const val API_BASE_URL = "http://192.168.0.124:5000"
|
||||
|
||||
@OptIn(DelicateCoroutinesApi::class)
|
||||
fun getNews(onFinish: (String) -> Unit) {
|
||||
GlobalScope.launch(Dispatchers.IO) {
|
||||
val reqURL = URL("$API_BASE_URL/rss")
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
package com.example.russionroadsapp
|
||||
|
||||
import android.os.Bundle
|
||||
import android.widget.Toast
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.activity.compose.setContent
|
||||
import androidx.activity.enableEdgeToEdge
|
||||
@ -26,6 +27,11 @@ import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
@ -41,6 +47,39 @@ class MainActivity : ComponentActivity() {
|
||||
enableEdgeToEdge()
|
||||
setContent {
|
||||
|
||||
var messageToast by remember {
|
||||
mutableStateOf("")
|
||||
}
|
||||
|
||||
var requestNews by remember {
|
||||
mutableStateOf(true)
|
||||
}
|
||||
|
||||
var newsString by remember {
|
||||
mutableStateOf("")
|
||||
}
|
||||
|
||||
if (messageToast != "") {
|
||||
Toast.makeText(
|
||||
this@MainActivity,
|
||||
messageToast,
|
||||
Toast.LENGTH_LONG
|
||||
).show()
|
||||
messageToast = ""
|
||||
}
|
||||
|
||||
LaunchedEffect(requestNews) {
|
||||
if (requestNews) {
|
||||
API.getNews { resp ->
|
||||
if (resp != "Error") {
|
||||
newsString = resp
|
||||
} else {
|
||||
messageToast = "Ошибка при получении новостей"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Column(
|
||||
Modifier
|
||||
.fillMaxSize()
|
||||
@ -108,7 +147,7 @@ class MainActivity : ComponentActivity() {
|
||||
.padding(20.dp)
|
||||
)
|
||||
|
||||
|
||||
Text(newsString)
|
||||
|
||||
Icon(
|
||||
Icons.AutoMirrored.Filled.ArrowForward,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user