From 861a9e32360c8305efa321f400d8b3ee56f8813a Mon Sep 17 00:00:00 2001 From: noemi3 Date: Mon, 2 Dec 2019 13:30:48 +0100 Subject: [PATCH] connected LoginActivity and BoardsListActivity --- app/src/main/AndroidManifest.xml | 2 +- .../wedroid/app/view/BoardsListsActivity.kt | 30 ++++++++++++++++++- .../wedroid/app/{ => view}/LoginActivity.kt | 16 +++++++--- .../app/viewmodel/BoardsListViewModel.java | 4 ++- app/src/main/res/layout/activity_login.xml | 2 +- 5 files changed, 46 insertions(+), 8 deletions(-) rename app/src/main/java/it/unisannio/ding/ids/wedroid/app/{ => view}/LoginActivity.kt (89%) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index a3bab34..0e63a51 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -11,7 +11,7 @@ android:supportsRtl="true" android:theme="@style/AppTheme"> - + { + when (resultCode) { + LoginActivity.LOGIN_ERROR -> finish() + LoginActivity.LOGIN_OK -> initializeUi() + else -> finish() + } + } + else -> finish() + } + } } 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/view/LoginActivity.kt similarity index 89% rename from app/src/main/java/it/unisannio/ding/ids/wedroid/app/LoginActivity.kt rename to app/src/main/java/it/unisannio/ding/ids/wedroid/app/view/LoginActivity.kt index da250cf..82b6806 100644 --- a/app/src/main/java/it/unisannio/ding/ids/wedroid/app/LoginActivity.kt +++ b/app/src/main/java/it/unisannio/ding/ids/wedroid/app/view/LoginActivity.kt @@ -1,12 +1,11 @@ -package it.unisannio.ding.ids.wedroid.app +package it.unisannio.ding.ids.wedroid.app.view -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.R 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 @@ -25,10 +24,11 @@ class LoginActivity : AppCompatActivity() { setContentView(R.layout.activity_login) sph = SharedPreferenceHelper(this) + setResult(LOGIN_ERROR) + 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) { @@ -80,8 +80,16 @@ class LoginActivity : AppCompatActivity() { Toast.LENGTH_LONG ).show() + setResult(LOGIN_OK) + finish() } }) } + + companion object { + const val LOGIN_REQUEST_CODE = 13 + const val LOGIN_OK = 0 + const val LOGIN_ERROR = 1 + } } diff --git a/app/src/main/java/it/unisannio/ding/ids/wedroid/app/viewmodel/BoardsListViewModel.java b/app/src/main/java/it/unisannio/ding/ids/wedroid/app/viewmodel/BoardsListViewModel.java index 79ab9c2..847a760 100644 --- a/app/src/main/java/it/unisannio/ding/ids/wedroid/app/viewmodel/BoardsListViewModel.java +++ b/app/src/main/java/it/unisannio/ding/ids/wedroid/app/viewmodel/BoardsListViewModel.java @@ -3,6 +3,7 @@ package it.unisannio.ding.ids.wedroid.app.viewmodel; import android.app.Application; import androidx.annotation.NonNull; +import androidx.core.app.SharedElementCallback; import androidx.lifecycle.AndroidViewModel; import androidx.lifecycle.LiveData; @@ -13,6 +14,7 @@ import it.unisannio.ding.ids.wedroid.app.data.entity.Board; import it.unisannio.ding.ids.wedroid.app.data.repository.BoardRepository; import it.unisannio.ding.ids.wedroid.app.util.PreferenceReader; import it.unisannio.ding.ids.wedroid.app.util.ServicesFactory; +import it.unisannio.ding.ids.wedroid.app.util.SharedPreferenceHelper; public class BoardsListViewModel extends AndroidViewModel { private BoardRepository repository; @@ -20,7 +22,7 @@ public class BoardsListViewModel extends AndroidViewModel { public BoardsListViewModel(@NonNull Application application) { super(application); - PreferenceReader reader = null; //TODO + PreferenceReader reader = new SharedPreferenceHelper(application); repository = new BoardRepository( BoardDatabase.getDatabase(application).boardDao(), ServicesFactory.Companion.getInstance(reader).getBoardService(), diff --git a/app/src/main/res/layout/activity_login.xml b/app/src/main/res/layout/activity_login.xml index b48dab0..0d5a258 100644 --- a/app/src/main/res/layout/activity_login.xml +++ b/app/src/main/res/layout/activity_login.xml @@ -4,7 +4,7 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" - tools:context=".LoginActivity"> + tools:context=".view.LoginActivity">