diff --git a/app/build.gradle b/app/build.gradle index c0fc443..cc33006 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -32,4 +32,6 @@ dependencies { testImplementation 'junit:junit:4.12' androidTestImplementation 'androidx.test.ext:junit:1.1.1' androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' + implementation "com.squareup.retrofit2:retrofit:2.6.2" + implementation "com.squareup.retrofit2:converter-gson:2.6.2" } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 253fb67..558d39e 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,6 +1,7 @@ + + diff --git a/app/src/main/java/it/unisannio/ding/ids/wedroid/app/LoginActivity.kt b/app/src/main/java/it/unisannio/ding/ids/wedroid/app/LoginActivity.kt new file mode 100644 index 0000000..4107b45 --- /dev/null +++ b/app/src/main/java/it/unisannio/ding/ids/wedroid/app/LoginActivity.kt @@ -0,0 +1,75 @@ +package it.unisannio.ding.ids.wedroid.app + +import androidx.appcompat.app.AppCompatActivity +import android.os.Bundle +import android.util.Log +import android.view.View +import android.widget.Toast +import it.unisannio.ding.ids.wedroid.wrapper.api.LoginService +import it.unisannio.ding.ids.wedroid.wrapper.entity.UserPrototype +import kotlinx.android.synthetic.main.activity_login.* +import retrofit2.Call +import retrofit2.Callback +import retrofit2.Response +import retrofit2.Retrofit +import retrofit2.converter.gson.GsonConverterFactory + +class LoginActivity : AppCompatActivity() { + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_login) + + + + } + + fun loginButton(v: View) { + if (username.text.isBlank() || istanceServer.text.isBlank() || password.text.isBlank()) { + Toast.makeText(this, "Riempire tutti i campi", Toast.LENGTH_LONG) + .show() + return + } + + + + val userNameText = username.text.toString() + val passwordText = password.text.toString() + + val service = Retrofit.Builder() + .addConverterFactory(GsonConverterFactory.create()) + .baseUrl(istanceServer.text.toString()) + .build() + .create(LoginService::class.java) + + + + service.login(userNameText, passwordText).enqueue(object : Callback { + override fun onFailure(call: Call, t: Throwable) { + Toast.makeText( + applicationContext, + "Controlla la tua connessione internet", + Toast.LENGTH_LONG + ).show() + } + + override fun onResponse(call: Call, response: Response) { + if (response.code() != 200) { + Toast.makeText( + applicationContext, + "Credenziali non corrette", + Toast.LENGTH_LONG + ).show() + return + } + Toast.makeText( + applicationContext, + "Login effettuato con successo", + Toast.LENGTH_LONG + ).show() + + } + + }) + } +} diff --git a/app/src/main/java/it/unisannio/ding/ids/wedroid/app/MainActivity.kt b/app/src/main/java/it/unisannio/ding/ids/wedroid/app/MainActivity.kt index e5390c0..97c3848 100644 --- a/app/src/main/java/it/unisannio/ding/ids/wedroid/app/MainActivity.kt +++ b/app/src/main/java/it/unisannio/ding/ids/wedroid/app/MainActivity.kt @@ -1,7 +1,9 @@ package it.unisannio.ding.ids.wedroid.app +import android.content.Intent import androidx.appcompat.app.AppCompatActivity import android.os.Bundle +import android.view.View import it.unisannio.ding.ids.wedroid.wrapper.api.BoardService class MainActivity : AppCompatActivity() { @@ -10,5 +12,12 @@ class MainActivity : AppCompatActivity() { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) val service : BoardService? = null + + } + + fun login(v: View) { + startActivity( + Intent(this, LoginActivity::class.java) + ) } } diff --git a/app/src/main/res/layout/activity_login.xml b/app/src/main/res/layout/activity_login.xml new file mode 100644 index 0000000..b48dab0 --- /dev/null +++ b/app/src/main/res/layout/activity_login.xml @@ -0,0 +1,56 @@ + + + + + + + +