diff --git a/android/app/build.gradle b/android/app/build.gradle index 0eab8f5..c015307 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -45,4 +45,7 @@ dependencies { implementation 'androidx.navigation:navigation-ui-ktx:2.2.2' implementation "android.arch.navigation:navigation-fragment-ktx:2.2.2" implementation "android.arch.navigation:navigation-ui-ktx:2.2.2" + + implementation 'com.squareup.retrofit2:retrofit:2.1.0' + implementation 'com.squareup.retrofit2:converter-gson:2.1.0' } diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index 1e18427..357f575 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -1,6 +1,7 @@ + + + + + +} \ No newline at end of file diff --git a/android/app/src/main/java/de/hft/geotracker/JWToken.kt b/android/app/src/main/java/de/hft/geotracker/JWToken.kt new file mode 100644 index 0000000..c9af2dd --- /dev/null +++ b/android/app/src/main/java/de/hft/geotracker/JWToken.kt @@ -0,0 +1,3 @@ +package de.hft.geotracker + +data class JWToken (var token : String) \ No newline at end of file diff --git a/android/app/src/main/java/de/hft/geotracker/Login.kt b/android/app/src/main/java/de/hft/geotracker/Login.kt index 8fa2428..2904a1c 100644 --- a/android/app/src/main/java/de/hft/geotracker/Login.kt +++ b/android/app/src/main/java/de/hft/geotracker/Login.kt @@ -5,6 +5,17 @@ import android.os.Bundle import androidx.fragment.app.Fragment import android.widget.TextView import androidx.appcompat.app.AppCompatActivity +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.launch +import kotlinx.coroutines.withContext +import okhttp3.OkHttpClient +import retrofit2.Call +import retrofit2.Callback +import retrofit2.Response +import retrofit2.Retrofit +import retrofit2.converter.gson.GsonConverterFactory +import java.net.HttpRetryException /** * A simple [Fragment] subclass. @@ -12,9 +23,18 @@ import androidx.appcompat.app.AppCompatActivity class Login : AppCompatActivity() { lateinit var login : TextView lateinit var reg : TextView + lateinit var service : GeofenceService + lateinit var token : JWToken override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_login) + + val retrofit = Retrofit.Builder() + .baseUrl("http://localhost:5000") + .addConverterFactory(GsonConverterFactory.create()) + .build() + service = retrofit.create(GeofenceService::class.java) + login = findViewById(R.id.button_create_account) login.setOnClickListener { login() @@ -31,7 +51,24 @@ class Login : AppCompatActivity() { } private fun login() { - val intent = Intent(this, MainActivity::class.java) - startActivity(intent) + var call : Call = service.login("wito","tobias") + call.enqueue(object : Callback { + override fun onResponse(call: Call?, response: Response?) { + if(response != null && response.isSuccessful) { + response.body() + token = JWToken(call.toString()) + println("Erfolg") + } else { + println("Fehler1") + } + } + + override fun onFailure(call: Call?, t: Throwable?) { + println("Fehler2 ${t.toString()}") + } + }) +// var token = call.execute().body() +// val intent = Intent(this, MainActivity::class.java) +// startActivity(intent) } } diff --git a/android/app/src/main/res/drawable/ic_search_black_24dp.xml b/android/app/src/main/res/drawable/ic_search_black_24dp.xml deleted file mode 100644 index e69de29..0000000