release 0.1 #30

Manually merged
noemi3 merged 150 commits from release/0.1 into master 2020-01-18 14:59:02 +00:00
2 changed files with 51 additions and 4 deletions
Showing only changes of commit d1636ac9d9 - Show all commits

View File

@ -1,10 +1,13 @@
package it.unisannio.ding.ids.wedroid.app
import android.content.Context
import android.content.SharedPreferences
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.app.util.SharedPreferenceHelper
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.*
@ -15,13 +18,17 @@ import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
class LoginActivity : AppCompatActivity() {
lateinit var sph: SharedPreferenceHelper
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_login)
sph = SharedPreferenceHelper(this)
val id = sph.userId
val token = sph.token
val url = sph.baseUrl
Log.d("sharedPreference", "userId: $id\n token: $token\n url: $url")
}
fun loginButton(v: View) {
@ -32,7 +39,6 @@ class LoginActivity : AppCompatActivity() {
}
val userNameText = username.text.toString()
val passwordText = password.text.toString()
@ -54,6 +60,7 @@ class LoginActivity : AppCompatActivity() {
}
override fun onResponse(call: Call<UserPrototype>, response: Response<UserPrototype>) {
if (response.code() != 200) {
Toast.makeText(
applicationContext,
@ -62,6 +69,11 @@ class LoginActivity : AppCompatActivity() {
).show()
return
}
val users = response.body()
sph.baseUrl = istanceServer.text.toString()
sph.token = users?.token
sph.userId = users?.id
Toast.makeText(
applicationContext,
"Login effettuato con successo",

View File

@ -0,0 +1,35 @@
package it.unisannio.ding.ids.wedroid.app.util
import android.content.Context
class SharedPreferenceHelper(context : Context) : PreferenceReader, PreferenceWriter {
private val sp = context.getSharedPreferences("userinfo", Context.MODE_PRIVATE)
override fun getBaseUrl(): String? {
return sp.getString("url", "")
}
override fun getUserId(): String? {
return sp.getString("id", "")
}
override fun getToken(): String? {
return sp.getString("token", "")
}
override fun setBaseUrl(baseUrl: String?) {
val editor = sp.edit()
editor.putString("url", baseUrl).apply()
}
override fun setUserId(userId: String?) {
val editor = sp.edit()
editor.putString("id", userId).apply()
}
override fun setToken(token: String?) {
val editor = sp.edit()
editor.putString("token", token).apply()
}
}