connected LoginActivity and BoardsListActivity
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
c0200cf445
commit
861a9e3236
@ -11,7 +11,7 @@
|
|||||||
android:supportsRtl="true"
|
android:supportsRtl="true"
|
||||||
android:theme="@style/AppTheme">
|
android:theme="@style/AppTheme">
|
||||||
|
|
||||||
<activity android:name=".LoginActivity"></activity>
|
<activity android:name=".view.LoginActivity"></activity>
|
||||||
|
|
||||||
<activity
|
<activity
|
||||||
android:name=".view.BoardsListsActivity"
|
android:name=".view.BoardsListsActivity"
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
package it.unisannio.ding.ids.wedroid.app.view
|
package it.unisannio.ding.ids.wedroid.app.view
|
||||||
|
|
||||||
|
import android.content.Intent
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import android.util.Log
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import androidx.lifecycle.Observer
|
import androidx.lifecycle.Observer
|
||||||
import androidx.lifecycle.ViewModelProvider
|
import androidx.lifecycle.ViewModelProvider
|
||||||
@ -8,6 +10,8 @@ import androidx.recyclerview.widget.ItemTouchHelper
|
|||||||
import androidx.recyclerview.widget.LinearLayoutManager
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import it.unisannio.ding.ids.wedroid.app.R
|
import it.unisannio.ding.ids.wedroid.app.R
|
||||||
|
import it.unisannio.ding.ids.wedroid.app.util.PreferenceReader
|
||||||
|
import it.unisannio.ding.ids.wedroid.app.util.SharedPreferenceHelper
|
||||||
import it.unisannio.ding.ids.wedroid.app.view.adapter.BoardsListAdapter
|
import it.unisannio.ding.ids.wedroid.app.view.adapter.BoardsListAdapter
|
||||||
import it.unisannio.ding.ids.wedroid.app.viewmodel.BoardsListViewModel
|
import it.unisannio.ding.ids.wedroid.app.viewmodel.BoardsListViewModel
|
||||||
|
|
||||||
@ -21,6 +25,17 @@ class BoardsListsActivity : AppCompatActivity() {
|
|||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
setContentView(R.layout.activity_boards_lists)
|
setContentView(R.layout.activity_boards_lists)
|
||||||
setSupportActionBar(toolbar)
|
setSupportActionBar(toolbar)
|
||||||
|
|
||||||
|
val reader: PreferenceReader = SharedPreferenceHelper(this)
|
||||||
|
if (reader.token == "")
|
||||||
|
startActivityForResult(
|
||||||
|
Intent(this, LoginActivity::class.java),
|
||||||
|
LoginActivity.LOGIN_REQUEST_CODE
|
||||||
|
)
|
||||||
|
else initializeUi()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun initializeUi() {
|
||||||
viewModel = ViewModelProvider(this).get(BoardsListViewModel::class.java)
|
viewModel = ViewModelProvider(this).get(BoardsListViewModel::class.java)
|
||||||
|
|
||||||
val adapter = BoardsListAdapter(this)
|
val adapter = BoardsListAdapter(this)
|
||||||
@ -43,7 +58,6 @@ class BoardsListsActivity : AppCompatActivity() {
|
|||||||
pullToRefresh.setOnRefreshListener {
|
pullToRefresh.setOnRefreshListener {
|
||||||
viewModel.refresh()
|
viewModel.refresh()
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun swipeLeftToDelete() {
|
private fun swipeLeftToDelete() {
|
||||||
@ -67,5 +81,19 @@ class BoardsListsActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
swipeToDelete.attachToRecyclerView(boardList)
|
swipeToDelete.attachToRecyclerView(boardList)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
||||||
|
super.onActivityResult(requestCode, resultCode, data)
|
||||||
|
when (requestCode) {
|
||||||
|
LoginActivity.LOGIN_REQUEST_CODE -> {
|
||||||
|
when (resultCode) {
|
||||||
|
LoginActivity.LOGIN_ERROR -> finish()
|
||||||
|
LoginActivity.LOGIN_OK -> initializeUi()
|
||||||
|
else -> finish()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else -> finish()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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 androidx.appcompat.app.AppCompatActivity
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.widget.Toast
|
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.app.util.SharedPreferenceHelper
|
||||||
import it.unisannio.ding.ids.wedroid.wrapper.api.LoginService
|
import it.unisannio.ding.ids.wedroid.wrapper.api.LoginService
|
||||||
import it.unisannio.ding.ids.wedroid.wrapper.entity.UserPrototype
|
import it.unisannio.ding.ids.wedroid.wrapper.entity.UserPrototype
|
||||||
@ -25,10 +24,11 @@ class LoginActivity : AppCompatActivity() {
|
|||||||
setContentView(R.layout.activity_login)
|
setContentView(R.layout.activity_login)
|
||||||
sph = SharedPreferenceHelper(this)
|
sph = SharedPreferenceHelper(this)
|
||||||
|
|
||||||
|
setResult(LOGIN_ERROR)
|
||||||
|
|
||||||
val id = sph.userId
|
val id = sph.userId
|
||||||
val token = sph.token
|
val token = sph.token
|
||||||
val url = sph.baseUrl
|
val url = sph.baseUrl
|
||||||
Log.d("sharedPreference", "userId: $id\n token: $token\n url: $url")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun loginButton(v: View) {
|
fun loginButton(v: View) {
|
||||||
@ -80,8 +80,16 @@ class LoginActivity : AppCompatActivity() {
|
|||||||
Toast.LENGTH_LONG
|
Toast.LENGTH_LONG
|
||||||
).show()
|
).show()
|
||||||
|
|
||||||
|
setResult(LOGIN_OK)
|
||||||
|
finish()
|
||||||
}
|
}
|
||||||
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
const val LOGIN_REQUEST_CODE = 13
|
||||||
|
const val LOGIN_OK = 0
|
||||||
|
const val LOGIN_ERROR = 1
|
||||||
|
}
|
||||||
}
|
}
|
@ -3,6 +3,7 @@ package it.unisannio.ding.ids.wedroid.app.viewmodel;
|
|||||||
import android.app.Application;
|
import android.app.Application;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.core.app.SharedElementCallback;
|
||||||
import androidx.lifecycle.AndroidViewModel;
|
import androidx.lifecycle.AndroidViewModel;
|
||||||
import androidx.lifecycle.LiveData;
|
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.data.repository.BoardRepository;
|
||||||
import it.unisannio.ding.ids.wedroid.app.util.PreferenceReader;
|
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.ServicesFactory;
|
||||||
|
import it.unisannio.ding.ids.wedroid.app.util.SharedPreferenceHelper;
|
||||||
|
|
||||||
public class BoardsListViewModel extends AndroidViewModel {
|
public class BoardsListViewModel extends AndroidViewModel {
|
||||||
private BoardRepository repository;
|
private BoardRepository repository;
|
||||||
@ -20,7 +22,7 @@ public class BoardsListViewModel extends AndroidViewModel {
|
|||||||
|
|
||||||
public BoardsListViewModel(@NonNull Application application) {
|
public BoardsListViewModel(@NonNull Application application) {
|
||||||
super(application);
|
super(application);
|
||||||
PreferenceReader reader = null; //TODO
|
PreferenceReader reader = new SharedPreferenceHelper(application);
|
||||||
repository = new BoardRepository(
|
repository = new BoardRepository(
|
||||||
BoardDatabase.getDatabase(application).boardDao(),
|
BoardDatabase.getDatabase(application).boardDao(),
|
||||||
ServicesFactory.Companion.getInstance(reader).getBoardService(),
|
ServicesFactory.Companion.getInstance(reader).getBoardService(),
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
tools:context=".LoginActivity">
|
tools:context=".view.LoginActivity">
|
||||||
|
|
||||||
<EditText
|
<EditText
|
||||||
android:id="@+id/username"
|
android:id="@+id/username"
|
||||||
|
Loading…
Reference in New Issue
Block a user