ADD: Network Communication
This commit is contained in:
parent
c8e9452a7e
commit
c7a71fd1bf
@ -63,4 +63,7 @@ dependencies {
|
||||
implementation(libs.compose.runtime.livedata)
|
||||
implementation(libs.coil.compose)
|
||||
ksp(libs.androidx.room.compiler)
|
||||
implementation(libs.retrofit)
|
||||
implementation(libs.converter.gson)
|
||||
implementation(libs.logging.interceptor)
|
||||
}
|
@ -1,6 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools">
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
|
@ -1,7 +1,9 @@
|
||||
package come.stormborntales.notevault.data.local.entity
|
||||
|
||||
import androidx.room.Entity
|
||||
import androidx.room.PrimaryKey
|
||||
|
||||
@Entity(tableName = "sync_time_table")
|
||||
data class SyncTime(
|
||||
@PrimaryKey val id: Long = 1, // Einziger Eintrag für das Gerät
|
||||
val lastSyncTimestamp: Long = System.currentTimeMillis() // Zeitstempel des letzten Syncsy
|
||||
|
@ -0,0 +1,13 @@
|
||||
package come.stormborntales.notevault.data.remote
|
||||
|
||||
import come.stormborntales.notevault.data.remote.model.user.RegisterRequest
|
||||
import retrofit2.Response
|
||||
|
||||
import retrofit2.http.Body
|
||||
import retrofit2.http.GET
|
||||
import retrofit2.http.POST
|
||||
|
||||
interface ApiInterface {
|
||||
@POST("user/register")
|
||||
suspend fun register(@Body user: RegisterRequest): Response<Unit>
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
package come.stormborntales.notevault.data.remote
|
||||
|
||||
import okhttp3.OkHttpClient
|
||||
import okhttp3.logging.HttpLoggingInterceptor
|
||||
import retrofit2.Retrofit
|
||||
import retrofit2.converter.gson.GsonConverterFactory
|
||||
import kotlin.getValue
|
||||
|
||||
object ApiClient {
|
||||
|
||||
private const val BASE_URL = "https://notevault.fawkes100.de" // <– Anpassen!
|
||||
|
||||
val logging = HttpLoggingInterceptor().apply {
|
||||
level = HttpLoggingInterceptor.Level.BODY
|
||||
}
|
||||
val client = OkHttpClient.Builder()
|
||||
.addInterceptor(logging)
|
||||
.build()
|
||||
|
||||
val retrofit = Retrofit.Builder()
|
||||
.baseUrl(BASE_URL)
|
||||
.client(client)
|
||||
.addConverterFactory(GsonConverterFactory.create())
|
||||
.build()
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
package come.stormborntales.notevault.data.remote.model.user
|
||||
|
||||
data class RegisterRequest(
|
||||
val email: String,
|
||||
val password: String
|
||||
)
|
||||
|
||||
data class RegisterResponse(
|
||||
val userId: String
|
||||
)
|
@ -1,5 +1,6 @@
|
||||
package come.stormborntales.notevault.ui.screens
|
||||
|
||||
import android.util.Log
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
@ -13,12 +14,20 @@ import androidx.compose.material3.OutlinedButton
|
||||
import androidx.compose.material3.Switch
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.rememberCoroutineScope
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.unit.dp
|
||||
import come.stormborntales.notevault.data.remote.ApiClient
|
||||
import come.stormborntales.notevault.data.remote.ApiInterface
|
||||
import come.stormborntales.notevault.data.remote.model.user.RegisterRequest
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
@Composable
|
||||
fun SettingsScreen() {
|
||||
val coroutineScope = rememberCoroutineScope()
|
||||
val syncApi = remember { ApiClient.retrofit.create(ApiInterface::class.java) }
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
@ -70,10 +79,25 @@ fun SettingsScreen() {
|
||||
Spacer(modifier = Modifier.height(32.dp))
|
||||
|
||||
OutlinedButton(
|
||||
onClick = { /* TODO: Impressum anzeigen */ },
|
||||
onClick = {
|
||||
coroutineScope.launch {
|
||||
try {
|
||||
val request = RegisterRequest("test@example.com", "123456")
|
||||
val response = syncApi.register(request)
|
||||
|
||||
if(response.isSuccessful) {
|
||||
Log.d("Response", "Response was successful")
|
||||
} else {
|
||||
Log.d("Response", "Error: ${response.errorBody()}")
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
println("Netzwerkfehler: ${e.message}")
|
||||
}
|
||||
}
|
||||
},
|
||||
modifier = Modifier.fillMaxWidth()
|
||||
) {
|
||||
Text("Impressum")
|
||||
Text("Registrierung testen")
|
||||
}
|
||||
}
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
[versions]
|
||||
agp = "8.8.2"
|
||||
composeBomVersion = "2024.01.00"
|
||||
converterGson = "2.9.0"
|
||||
kotlin = "2.0.0"
|
||||
coreKtx = "1.10.1"
|
||||
junit = "4.13.2"
|
||||
@ -9,14 +10,17 @@ espressoCore = "3.6.1"
|
||||
lifecycleRuntimeKtx = "2.8.7"
|
||||
activityCompose = "1.8.0"
|
||||
composeBom = "2024.04.01"
|
||||
loggingInterceptor = "4.12.0"
|
||||
navigationCompose = "2.8.9"
|
||||
retrofit = "2.9.0"
|
||||
room = "2.7.1"
|
||||
ksp="2.1.21-RC-2.0.0"
|
||||
ksp="2.0.0-1.0.21"
|
||||
compose = "1.6.0" # oder was immer deine aktuelle Compose-Version ist
|
||||
|
||||
[libraries]
|
||||
coil-compose = { group = "io.coil-kt", name = "coil-compose", version = "2.5.0" } # oder aktueller
|
||||
compose-runtime-livedata = { group = "androidx.compose.runtime", name = "runtime-livedata", version.ref = "compose" }
|
||||
converter-gson = { module = "com.squareup.retrofit2:converter-gson", version.ref = "converterGson" }
|
||||
lifecycle-livedata-ktx = "androidx.lifecycle:lifecycle-livedata-ktx:2.8.7"
|
||||
androidx-compose-bom-v20240100 = { module = "androidx.compose:compose-bom", version.ref = "composeBomVersion" }
|
||||
androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" }
|
||||
@ -39,6 +43,8 @@ androidx-ui-test-junit4 = { group = "androidx.compose.ui", name = "ui-test-junit
|
||||
androidx-material3 = { group = "androidx.compose.material3", name = "material3" }
|
||||
androidx-room-ktx = { module = "androidx.room:room-ktx", version.ref = "room" }
|
||||
androidx-room-compiler = { module = "androidx.room:room-compiler", version.ref = "room" }
|
||||
logging-interceptor = { module = "com.squareup.okhttp3:logging-interceptor", version.ref = "loggingInterceptor" }
|
||||
retrofit = { module = "com.squareup.retrofit2:retrofit", version.ref = "retrofit" }
|
||||
|
||||
|
||||
[plugins]
|
||||
|
Loading…
Reference in New Issue
Block a user