release 0.1 #30
@ -11,7 +11,7 @@
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/AppTheme">
|
||||
|
||||
<activity android:name=".LoginActivity"></activity>
|
||||
<activity android:name=".view.LoginActivity"></activity>
|
||||
|
||||
<activity
|
||||
android:name=".view.BoardsListsActivity"
|
||||
|
@ -1,6 +1,8 @@
|
||||
package it.unisannio.ding.ids.wedroid.app.view
|
||||
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.lifecycle.Observer
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
@ -8,6 +10,8 @@ import androidx.recyclerview.widget.ItemTouchHelper
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
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.viewmodel.BoardsListViewModel
|
||||
|
||||
@ -21,6 +25,17 @@ class BoardsListsActivity : AppCompatActivity() {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_boards_lists)
|
||||
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)
|
||||
|
||||
val adapter = BoardsListAdapter(this)
|
||||
@ -43,7 +58,6 @@ class BoardsListsActivity : AppCompatActivity() {
|
||||
pullToRefresh.setOnRefreshListener {
|
||||
viewModel.refresh()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private fun swipeLeftToDelete() {
|
||||
@ -67,5 +81,19 @@ class BoardsListsActivity : AppCompatActivity() {
|
||||
|
||||
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 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
|
||||
}
|
||||
}
|
@ -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(),
|
||||
|
@ -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">
|
||||
|
||||
<EditText
|
||||
android:id="@+id/username"
|
||||
|
Loading…
Reference in New Issue
Block a user