- add repleceOnConflict test
This commit is contained in:
parent
75e88ef617
commit
2b0a9b690b
@ -57,7 +57,6 @@ dependencies {
|
||||
implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.0.0"
|
||||
|
||||
|
||||
|
||||
// TESTING
|
||||
testImplementation 'junit:junit:4.12'
|
||||
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
|
||||
|
@ -62,15 +62,29 @@ class BoardDaoTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun replaceOnConflict() {
|
||||
val board0 = Board("id", "title0")
|
||||
val board1 = Board("id", "title1")
|
||||
|
||||
runBlocking {
|
||||
dao.insert(board0)
|
||||
dao.insert(board1)
|
||||
}
|
||||
|
||||
dao.getAllBoard().observeOnce {
|
||||
assertEquals(1, it.size)
|
||||
assertEquals("title1", it[0].title)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun getInAscendingOrder() {
|
||||
val board0 = Board("id0", "title0")
|
||||
val board1 = Board("id1", "title1")
|
||||
|
||||
runBlocking {
|
||||
dao.insert(board1)
|
||||
}
|
||||
|
||||
runBlocking {
|
||||
dao.insert(board0)
|
||||
}
|
||||
|
||||
@ -81,14 +95,12 @@ class BoardDaoTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun delete() {
|
||||
val board = Board("id", "title")
|
||||
|
||||
runBlocking {
|
||||
dao.insert(board)
|
||||
}
|
||||
|
||||
runBlocking {
|
||||
dao.delete(board)
|
||||
}
|
||||
|
||||
|
@ -11,11 +11,14 @@
|
||||
android:roundIcon="@mipmap/ic_launcher_round"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/AppTheme">
|
||||
<activity
|
||||
android:name=".view.NewBoardActivity"
|
||||
android:label="@string/title_activity_new_board"
|
||||
android:theme="@style/AppTheme.NoActionBar"></activity>
|
||||
<activity
|
||||
android:name=".view.BoardsListsActivity"
|
||||
android:label="@string/title_activity_boards_lists"
|
||||
android:theme="@style/AppTheme.NoActionBar">
|
||||
</activity>
|
||||
android:theme="@style/AppTheme.NoActionBar"></activity>
|
||||
<activity android:name=".MainActivity">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
@ -7,6 +7,7 @@ import it.unisannio.ding.ids.wedroid.app.data.entity.convert
|
||||
import it.unisannio.ding.ids.wedroid.app.util.PreferenceReader
|
||||
import it.unisannio.ding.ids.wedroid.wrapper.api.BoardService
|
||||
import it.unisannio.ding.ids.wedroid.wrapper.entity.BoardBackgroundColor
|
||||
import it.unisannio.ding.ids.wedroid.wrapper.entity.BoardPermission
|
||||
import it.unisannio.ding.ids.wedroid.wrapper.entity.BoardPrototype
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
@ -28,12 +29,15 @@ class BoardRepository(
|
||||
synchronize()
|
||||
}
|
||||
|
||||
fun insertBoard(title: String) {
|
||||
fun insertBoard(title: String, isPrivate: Boolean, color: BoardBackgroundColor) {
|
||||
val permission = if (isPrivate) BoardPermission.PRIVATE else BoardPermission.PUBLIC
|
||||
|
||||
service.newBoard(
|
||||
BoardPrototype.Builder()
|
||||
.setOwner(reader.userId)
|
||||
.setTitle(title)
|
||||
.setBackgroundColor(BoardBackgroundColor.LIMEGREEN)
|
||||
.setBackgroundColor(color)
|
||||
.setBoardPermission(permission)
|
||||
.build()
|
||||
).enqueue(object : Callback<it.unisannio.ding.ids.wedroid.wrapper.entity.Board> {
|
||||
override fun onFailure(
|
||||
|
@ -1,6 +1,8 @@
|
||||
package it.unisannio.ding.ids.wedroid.app.view
|
||||
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.widget.Toast
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.lifecycle.Observer
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
@ -10,6 +12,7 @@ import androidx.recyclerview.widget.RecyclerView
|
||||
import it.unisannio.ding.ids.wedroid.app.R
|
||||
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.wrapper.entity.BoardBackgroundColor
|
||||
|
||||
import kotlinx.android.synthetic.main.activity_boards_lists.*
|
||||
import kotlinx.android.synthetic.main.content_boards_lists.*
|
||||
@ -37,7 +40,10 @@ class BoardsListsActivity : AppCompatActivity() {
|
||||
})
|
||||
|
||||
fab.setOnClickListener {
|
||||
viewModel.insertBoard("New board")
|
||||
startActivityForResult(
|
||||
Intent(this, NewBoardActivity::class.java),
|
||||
NEW_BOARD_CODE
|
||||
)
|
||||
}
|
||||
|
||||
pullToRefresh.setOnRefreshListener {
|
||||
@ -67,5 +73,35 @@ class BoardsListsActivity : AppCompatActivity() {
|
||||
|
||||
swipeToDelete.attachToRecyclerView(boardList)
|
||||
}
|
||||
|
||||
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
||||
super.onActivityResult(requestCode, resultCode, data)
|
||||
when (requestCode) {
|
||||
NEW_BOARD_CODE -> if (data != null) addBoard(resultCode, data)
|
||||
}
|
||||
}
|
||||
|
||||
private fun addBoard(resultCode: Int, data: Intent) {
|
||||
if (resultCode != NewBoardActivity.RESULT_OK) {
|
||||
Toast.makeText(this, R.string.on_add_new_board_error, Toast.LENGTH_LONG)
|
||||
.show()
|
||||
return
|
||||
}
|
||||
|
||||
val title = data.getStringExtra(NewBoardActivity.BOARD_NAME)
|
||||
if (title == null) {
|
||||
Toast.makeText(this, R.string.on_null_new_board_name, Toast.LENGTH_LONG)
|
||||
.show()
|
||||
return
|
||||
}
|
||||
|
||||
val isPrivate = data.getBooleanExtra(NewBoardActivity.BOARD_PRIVATE, true)
|
||||
|
||||
viewModel.insertBoard(title, isPrivate, BoardBackgroundColor.LIMEGREEN) //TODO
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val NEW_BOARD_CODE = 17
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,45 @@
|
||||
package it.unisannio.ding.ids.wedroid.app.view;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
|
||||
import android.view.View;
|
||||
import android.widget.EditText;
|
||||
import android.widget.Switch;
|
||||
|
||||
import it.unisannio.ding.ids.wedroid.app.R;
|
||||
|
||||
public class NewBoardActivity extends AppCompatActivity {
|
||||
private EditText boardName;
|
||||
private Switch isPrivate;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_new_board);
|
||||
Toolbar toolbar = findViewById(R.id.toolbar);
|
||||
setSupportActionBar(toolbar);
|
||||
|
||||
boardName = findViewById(R.id.newBoardName);
|
||||
isPrivate = findViewById(R.id.newBoardPermission);
|
||||
}
|
||||
|
||||
public void onDone(View v) {
|
||||
Intent data = new Intent();
|
||||
data.putExtra(BOARD_NAME, boardName.getText().toString());
|
||||
data.putExtra(BOARD_PRIVATE, isPrivate.isChecked());
|
||||
setResult(RESULT_OK, data);
|
||||
finish();
|
||||
}
|
||||
|
||||
public void onCancel(View v) {
|
||||
finish();
|
||||
}
|
||||
|
||||
public static final int RESULT_OK = 17;
|
||||
public static final String BOARD_NAME = "BOARD_NAME";
|
||||
public static final String BOARD_PRIVATE = "BOARD_PRIVATE";
|
||||
}
|
@ -13,6 +13,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.wrapper.entity.BoardBackgroundColor;
|
||||
|
||||
public class BoardsListViewModel extends AndroidViewModel {
|
||||
private BoardRepository repository;
|
||||
@ -34,12 +35,15 @@ public class BoardsListViewModel extends AndroidViewModel {
|
||||
return allBoards;
|
||||
}
|
||||
|
||||
public void insertBoard(String title) {
|
||||
repository.insertBoard(title);
|
||||
public void insertBoard(String title, boolean isPrivate, BoardBackgroundColor color) {
|
||||
repository.insertBoard(title, isPrivate, color);
|
||||
}
|
||||
|
||||
public void deleteBoard(int position) {
|
||||
repository.deleteBoard(allBoards.getValue().get(position).getId());
|
||||
List<Board> boards = allBoards.getValue();
|
||||
|
||||
if (boards != null)
|
||||
repository.deleteBoard(boards.get(position).getId());
|
||||
}
|
||||
|
||||
public void refresh() {
|
||||
|
25
app/src/main/res/layout/activity_new_board.xml
Normal file
25
app/src/main/res/layout/activity_new_board.xml
Normal file
@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".view.NewBoardActivity">
|
||||
|
||||
<com.google.android.material.appbar.AppBarLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:theme="@style/AppTheme.AppBarOverlay">
|
||||
|
||||
<androidx.appcompat.widget.Toolbar
|
||||
android:id="@+id/toolbar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="?attr/actionBarSize"
|
||||
android:background="?attr/colorPrimary"
|
||||
app:popupTheme="@style/AppTheme.PopupOverlay" />
|
||||
|
||||
</com.google.android.material.appbar.AppBarLayout>
|
||||
|
||||
<include layout="@layout/content_new_board" />
|
||||
|
||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
62
app/src/main/res/layout/content_new_board.xml
Normal file
62
app/src/main/res/layout/content_new_board.xml
Normal file
@ -0,0 +1,62 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
app:layout_behavior="@string/appbar_scrolling_view_behavior"
|
||||
tools:context=".view.NewBoardActivity"
|
||||
tools:showIn="@layout/activity_new_board">
|
||||
|
||||
<EditText
|
||||
android:id="@+id/newBoardName"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:ems="10"
|
||||
android:hint="@string/new_board_name_field"
|
||||
android:inputType="textPersonName"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintVertical_bias="0.25"
|
||||
android:importantForAutofill="no" />
|
||||
|
||||
<Switch
|
||||
android:id="@+id/newBoardPermission"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:checked="true"
|
||||
android:text="@string/new_board_switch"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="@+id/newBoardName"
|
||||
app:layout_constraintStart_toStartOf="@+id/newBoardName"
|
||||
app:layout_constraintTop_toBottomOf="@+id/newBoardName"
|
||||
app:layout_constraintVertical_bias="0.1" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/newBoardDone"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:onClick="onDone"
|
||||
android:text="@string/new_board_done_button"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toStartOf="@+id/newBoardPermission"
|
||||
app:layout_constraintHorizontal_bias="1.0"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/newBoardPermission"
|
||||
app:layout_constraintVertical_bias="0.40" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/newBoardCancel"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:onClick="onCancel"
|
||||
android:text="@string/new_board_cancel_button"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintHorizontal_bias="0.0"
|
||||
app:layout_constraintStart_toEndOf="@+id/newBoardPermission"
|
||||
app:layout_constraintTop_toBottomOf="@+id/newBoardPermission"
|
||||
app:layout_constraintVertical_bias="0.40" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
@ -2,4 +2,11 @@
|
||||
<string name="app_name">wedroid</string>
|
||||
<string name="title_activity_boards_list">BoardsListActivity</string>
|
||||
<string name="title_activity_boards_lists">Boards</string>
|
||||
<string name="title_activity_new_board">NewBoardActivity</string>
|
||||
<string name="new_board_name_field">Board name</string>
|
||||
<string name="new_board_switch">Private</string>
|
||||
<string name="new_board_cancel_button">Cancel</string>
|
||||
<string name="new_board_done_button">Done</string>
|
||||
<string name="on_null_new_board_name">There was a problem with the name of the new board</string>
|
||||
<string name="on_add_new_board_error">It was not possible to add a new board</string>
|
||||
</resources>
|
||||
|
Loading…
Reference in New Issue
Block a user