Merge branch 'feature_board_view' of kanban/wedroid into develop
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:
commit
af7a9bb75d
@ -5,7 +5,7 @@
|
||||
<configuration PROFILE_NAME="Debug" CONFIG_NAME="Debug" />
|
||||
</configurations>
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" project-jdk-name="JDK" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/build/classes" />
|
||||
</component>
|
||||
<component name="ProjectType">
|
||||
|
@ -6,6 +6,7 @@ apply plugin: 'kotlin-android-extensions'
|
||||
|
||||
apply plugin: 'kotlin-kapt'
|
||||
|
||||
|
||||
apply plugin: 'io.gitlab.arturbosch.detekt'
|
||||
|
||||
android {
|
||||
@ -60,7 +61,8 @@ dependencies {
|
||||
// UI
|
||||
implementation "com.google.android.material:material:$rootProject.materialVersion"
|
||||
implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.0.0"
|
||||
|
||||
//Card view
|
||||
implementation 'androidx.cardview:cardview:1.0.0'
|
||||
|
||||
// TESTING
|
||||
testImplementation 'junit:junit:4.12'
|
||||
@ -78,4 +80,5 @@ dependencies {
|
||||
androidTestImplementation "androidx.room:room-testing:$rootProject.roomVersion"
|
||||
androidTestImplementation "androidx.arch.core:core-testing:$rootProject.androidxArchVersion"
|
||||
androidTestImplementation "androidx.arch.core:core-testing:$rootProject.coreTestingVersion"
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,111 @@
|
||||
package it.unisannio.ding.ids.wedroid.app.data.dao
|
||||
|
||||
import android.content.Context
|
||||
import androidx.arch.core.executor.testing.InstantTaskExecutorRule
|
||||
import androidx.room.Room
|
||||
import androidx.test.core.app.ApplicationProvider
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
import it.unisannio.ding.ids.wedroid.app.data.database.WListDatabase
|
||||
import it.unisannio.ding.ids.wedroid.app.data.entity.WList
|
||||
import it.unisannio.ding.ids.wedroid.app.observeOnce
|
||||
import junit.framework.TestCase.assertEquals
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import org.junit.After
|
||||
import org.junit.Before
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import java.io.IOException
|
||||
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
class WListDaoTest {
|
||||
private lateinit var dao: WListDao
|
||||
private lateinit var db: WListDatabase
|
||||
|
||||
@get:Rule
|
||||
val instantTaskExecutorRule = InstantTaskExecutorRule()
|
||||
|
||||
@Before
|
||||
fun createDb() {
|
||||
val context = ApplicationProvider.getApplicationContext<Context>()
|
||||
db = Room.inMemoryDatabaseBuilder(
|
||||
context, WListDatabase::class.java
|
||||
).build()
|
||||
dao = db.wListDao()
|
||||
}
|
||||
|
||||
@After
|
||||
@Throws(IOException::class)
|
||||
fun closeDb() {
|
||||
db.close()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun emptyDatabaseOnCreation() {
|
||||
dao.allWList.observeOnce {
|
||||
assertEquals(0, it.size)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun insert() {
|
||||
val wList = WList("id", "title")
|
||||
|
||||
runBlocking {
|
||||
dao.insert(wList)
|
||||
}
|
||||
|
||||
dao.allWList.observeOnce {
|
||||
assertEquals(1, it.size)
|
||||
assertEquals(wList, it[0])
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun replaceOnConflict() {
|
||||
val wList0 = WList("id", "title0")
|
||||
val wList1 = WList("id", "title1")
|
||||
|
||||
runBlocking {
|
||||
dao.insert(wList0)
|
||||
dao.insert(wList1)
|
||||
}
|
||||
|
||||
dao.allWList.observeOnce {
|
||||
assertEquals(1, it.size)
|
||||
assertEquals("title1", it[0].title)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun getInAscendingOrder() {
|
||||
val wList0 = WList("id0", "title0")
|
||||
val wList1 = WList("id1", "title1")
|
||||
|
||||
runBlocking {
|
||||
dao.insert(wList1)
|
||||
dao.insert(wList0)
|
||||
}
|
||||
|
||||
dao.allWList.observeOnce {
|
||||
assertEquals(2, it.size)
|
||||
assertEquals(wList0, it[0])
|
||||
assertEquals(wList1, it[1])
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun delete() {
|
||||
val wlist = WList("id", "title")
|
||||
|
||||
runBlocking {
|
||||
dao.insert(wlist)
|
||||
dao.delete(wlist)
|
||||
}
|
||||
|
||||
dao.allWList.observeOnce {
|
||||
assertEquals(0, it.size)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
package="it.unisannio.ding.ids.wedroid.app">
|
||||
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
@ -10,24 +11,36 @@
|
||||
android:label="@string/app_name"
|
||||
android:roundIcon="@mipmap/ic_launcher_round"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/AppTheme">
|
||||
|
||||
android:theme="@style/AppTheme"
|
||||
tools:ignore="AllowBackup,GoogleAppIndexingWarning">
|
||||
|
||||
<activity android:name=".view.LoginActivity" />
|
||||
|
||||
<activity
|
||||
android:name=".view.NewBoardActivity"
|
||||
android:label="@string/title_activity_new_board"
|
||||
android:theme="@style/AppTheme.NoActionBar"/>
|
||||
|
||||
<activity
|
||||
android:name=".view.BoardViewActivity"
|
||||
android:theme="@style/AppTheme.NoActionBar" />
|
||||
|
||||
<activity
|
||||
android:name=".view.WListsListActivity"
|
||||
android:label="WList"
|
||||
android:theme="@style/AppTheme.NoActionBar" />
|
||||
|
||||
|
||||
<activity
|
||||
android:name=".view.BoardsListsActivity"
|
||||
android:theme="@style/AppTheme.NoActionBar">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
</application>
|
||||
|
||||
</manifest>
|
@ -0,0 +1,27 @@
|
||||
package it.unisannio.ding.ids.wedroid.app.data.dao;
|
||||
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.room.Dao;
|
||||
import androidx.room.Delete;
|
||||
import androidx.room.Insert;
|
||||
import androidx.room.OnConflictStrategy;
|
||||
import androidx.room.Query;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
//import io.reactivex.Completable;
|
||||
import it.unisannio.ding.ids.wedroid.app.data.entity.WList;
|
||||
|
||||
@Dao
|
||||
public interface WListDao {
|
||||
|
||||
@Query("SELECT * from wlist_table ORDER BY title ASC")
|
||||
LiveData<List<WList>> getAllWList();
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
void insert(WList wList);
|
||||
|
||||
@Delete
|
||||
void delete(WList wList);
|
||||
|
||||
}
|
@ -12,6 +12,7 @@ import it.unisannio.ding.ids.wedroid.app.data.entity.Board;
|
||||
@Database(entities = Board.class, version = 1, exportSchema = false)
|
||||
public abstract class BoardDatabase extends RoomDatabase {
|
||||
private static volatile BoardDatabase INSTANCE;
|
||||
|
||||
public abstract BoardDao boardDao();
|
||||
|
||||
public static BoardDatabase getDatabase(Context context) {
|
||||
|
@ -0,0 +1,31 @@
|
||||
package it.unisannio.ding.ids.wedroid.app.data.database;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.room.Database;
|
||||
import androidx.room.Room;
|
||||
import androidx.room.RoomDatabase;
|
||||
|
||||
import it.unisannio.ding.ids.wedroid.app.data.dao.WListDao;
|
||||
import it.unisannio.ding.ids.wedroid.app.data.entity.WList;
|
||||
|
||||
@Database(entities = WList.class, version = 2, exportSchema = false)
|
||||
public abstract class WListDatabase extends RoomDatabase {
|
||||
private static volatile WListDatabase INSTANCE;
|
||||
|
||||
public abstract WListDao wListDao();
|
||||
|
||||
public static WListDatabase getDatabase(Context context) {
|
||||
if (INSTANCE != null)
|
||||
return INSTANCE;
|
||||
synchronized (WListDatabase.class) {
|
||||
INSTANCE = Room.databaseBuilder(
|
||||
context.getApplicationContext(),
|
||||
WListDatabase.class,
|
||||
"wlist_database"
|
||||
).fallbackToDestructiveMigration().build();
|
||||
|
||||
return INSTANCE;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
package it.unisannio.ding.ids.wedroid.app.data.entity
|
||||
|
||||
import androidx.room.ColumnInfo
|
||||
import androidx.room.Entity
|
||||
import androidx.room.PrimaryKey
|
||||
|
||||
@Entity(tableName = "wlist_table")
|
||||
data class WList(
|
||||
@PrimaryKey @ColumnInfo(name = "id") val id: String,
|
||||
@ColumnInfo(name = "title") val title: String = ""
|
||||
)
|
||||
|
||||
fun it.unisannio.ding.ids.wedroid.wrapper.entity.WList.convert(): WList {
|
||||
return WList(this.id, this.title)
|
||||
}
|
@ -151,7 +151,7 @@ class BoardRepository(
|
||||
private suspend fun removeOldBoardsFromDb(boards: Collection<Board>) {
|
||||
allBoards.value?.minus(boards)
|
||||
?.forEach {
|
||||
dao.delete(it)
|
||||
dao.delete(it)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,116 @@
|
||||
package it.unisannio.ding.ids.wedroid.app.data.repository
|
||||
|
||||
import android.util.Log
|
||||
|
||||
import androidx.lifecycle.LiveData
|
||||
import it.unisannio.ding.ids.wedroid.app.data.dao.WListDao
|
||||
import it.unisannio.ding.ids.wedroid.app.data.entity.WList
|
||||
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.ListService
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import retrofit2.Call
|
||||
import retrofit2.Callback
|
||||
import retrofit2.Response
|
||||
|
||||
class WListRepository(
|
||||
private val dao: WListDao,
|
||||
private val service: ListService,
|
||||
private val reader: PreferenceReader
|
||||
) {
|
||||
|
||||
val allWLists: LiveData<MutableList<WList>> by lazy {
|
||||
dao.allWList
|
||||
}
|
||||
|
||||
init {
|
||||
synchronize()
|
||||
}
|
||||
|
||||
fun synchronize() {
|
||||
service.getAllList(reader.boardId)
|
||||
.enqueue(object :
|
||||
Callback<MutableList<it.unisannio.ding.ids.wedroid.wrapper.entity.WList>> {
|
||||
override fun onFailure(
|
||||
call: Call<MutableList<it.unisannio.ding.ids.wedroid.wrapper.entity.WList>>,
|
||||
t: Throwable
|
||||
) = logNetworkError(t.message)
|
||||
|
||||
override fun onResponse(
|
||||
call: Call<MutableList<it.unisannio.ding.ids.wedroid.wrapper.entity.WList>>,
|
||||
response: Response<MutableList<it.unisannio.ding.ids.wedroid.wrapper.entity.WList>>
|
||||
) {
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
synchronizeCallback(response)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
private fun synchronizeCallback(
|
||||
response: Response<MutableList<it.unisannio.ding.ids.wedroid.wrapper.entity.WList>>
|
||||
) {
|
||||
if (!response.isSuccessful) {
|
||||
logNetworkError("${response.code()} ${response.message()}")
|
||||
return
|
||||
}
|
||||
|
||||
val wLists = (response.body() ?: return)
|
||||
.map { it.convert() }
|
||||
|
||||
addNewWListToDb(wLists)
|
||||
removeOldWListsFromDb(wLists)
|
||||
}
|
||||
|
||||
fun deleteWList(idBoard: String, idWList: String) {
|
||||
service.deleteList(idBoard, idWList).enqueue(
|
||||
object : Callback<it.unisannio.ding.ids.wedroid.wrapper.entity.WList> {
|
||||
override fun onFailure(
|
||||
call: Call<it.unisannio.ding.ids.wedroid.wrapper.entity.WList>,
|
||||
t: Throwable
|
||||
) {
|
||||
logNetworkError(t.message)
|
||||
}
|
||||
|
||||
override fun onResponse(
|
||||
call: Call<it.unisannio.ding.ids.wedroid.wrapper.entity.WList>,
|
||||
response: Response<it.unisannio.ding.ids.wedroid.wrapper.entity.WList>
|
||||
) {
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
deleteWListCallBack(response, idWList)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
private fun deleteWListCallBack(
|
||||
response: Response<it.unisannio.ding.ids.wedroid.wrapper.entity.WList>,
|
||||
id: String
|
||||
) {
|
||||
if (!response.isSuccessful) {
|
||||
logNetworkError("${response.code()} ${response.message()}")
|
||||
return
|
||||
}
|
||||
dao.delete(WList(id))
|
||||
}
|
||||
|
||||
private fun addNewWListToDb(wLists: Collection<WList>) {
|
||||
wLists.forEach {
|
||||
dao.insert(it)
|
||||
}
|
||||
}
|
||||
|
||||
private fun removeOldWListsFromDb(wLists: Collection<WList>) {
|
||||
allWLists.value?.minus(wLists)
|
||||
?.forEach {
|
||||
dao.delete(it)
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS")
|
||||
private fun logNetworkError(message: String?) {
|
||||
Log.e("RETROFIT", message)
|
||||
}
|
||||
}
|
@ -2,6 +2,10 @@ package it.unisannio.ding.ids.wedroid.app.util;
|
||||
|
||||
public interface PreferenceReader {
|
||||
String getBaseUrl();
|
||||
|
||||
String getUserId();
|
||||
|
||||
String getToken();
|
||||
|
||||
String getBoardId();
|
||||
}
|
||||
|
@ -2,6 +2,10 @@ package it.unisannio.ding.ids.wedroid.app.util;
|
||||
|
||||
public interface PreferenceWriter {
|
||||
void setBaseUrl(String baseUrl);
|
||||
|
||||
void setUserId(String userId);
|
||||
|
||||
void setToken(String token);
|
||||
|
||||
void setBoardId(String boardId);
|
||||
}
|
||||
|
@ -4,14 +4,14 @@ import it.unisannio.ding.ids.wedroid.wrapper.api.BoardService
|
||||
import it.unisannio.ding.ids.wedroid.wrapper.api.CardCommentService
|
||||
import it.unisannio.ding.ids.wedroid.wrapper.api.CardService
|
||||
import it.unisannio.ding.ids.wedroid.wrapper.api.ChecklistService
|
||||
import it.unisannio.ding.ids.wedroid.wrapper.api.UserService
|
||||
import it.unisannio.ding.ids.wedroid.wrapper.api.ListService
|
||||
import it.unisannio.ding.ids.wedroid.wrapper.api.SwimlanesService
|
||||
import it.unisannio.ding.ids.wedroid.wrapper.api.UserService
|
||||
import okhttp3.OkHttpClient
|
||||
import retrofit2.Retrofit
|
||||
import retrofit2.converter.gson.GsonConverterFactory
|
||||
|
||||
class ServicesFactory private constructor(
|
||||
class ServicesFactory(
|
||||
reader: PreferenceReader
|
||||
) {
|
||||
private val retrofit: Retrofit
|
||||
|
@ -31,4 +31,13 @@ class SharedPreferenceHelper(context: Context) : PreferenceReader, PreferenceWri
|
||||
val editor = sp.edit()
|
||||
editor.putString("token", token).apply()
|
||||
}
|
||||
|
||||
override fun getBoardId(): String? {
|
||||
return sp.getString("boardId", "")
|
||||
}
|
||||
|
||||
override fun setBoardId(token: String?) {
|
||||
val editor = sp.edit()
|
||||
editor.putString("boardId", token).apply()
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,231 @@
|
||||
package it.unisannio.ding.ids.wedroid.app.view;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.Button;
|
||||
import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Objects;
|
||||
|
||||
import it.unisannio.ding.ids.wedroid.app.R;
|
||||
import it.unisannio.ding.ids.wedroid.app.util.ServicesFactory;
|
||||
import it.unisannio.ding.ids.wedroid.app.util.SharedPreferenceHelper;
|
||||
import it.unisannio.ding.ids.wedroid.wrapper.entity.Board;
|
||||
import it.unisannio.ding.ids.wedroid.wrapper.entity.User;
|
||||
import retrofit2.Call;
|
||||
import retrofit2.Callback;
|
||||
import retrofit2.Response;
|
||||
|
||||
public class BoardViewActivity extends AppCompatActivity {
|
||||
|
||||
static final int WLISTS_REQUEST = 30;
|
||||
|
||||
private String idBoard, username, boardTitle;
|
||||
private int boardColor;
|
||||
private TextView description, members, permission, creationDate, lastModificationDate;
|
||||
private View divider1, divider2, divider3;
|
||||
private ListView listView;
|
||||
private Button getListsButton;
|
||||
private SharedPreferenceHelper sp;
|
||||
private ServicesFactory service;
|
||||
private Toolbar myToolbar;
|
||||
private Board board;
|
||||
private SwipeRefreshLayout swipeRefreshLayout;
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_board_view);
|
||||
|
||||
findViews();
|
||||
|
||||
setSupportActionBar(myToolbar);
|
||||
|
||||
swipeRefreshLayout.setRefreshing(false);
|
||||
|
||||
Intent i = getIntent();
|
||||
idBoard = i.getStringExtra("idBoard");
|
||||
|
||||
sp = new SharedPreferenceHelper(this);
|
||||
sp.setBoardId(idBoard);
|
||||
|
||||
initializeUI(idBoard);
|
||||
|
||||
getListsButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
Intent i = new Intent(getApplicationContext(), WListsListActivity.class);
|
||||
i.putExtra("idBoard", idBoard);
|
||||
i.putExtra("barTitle", boardTitle);
|
||||
i.putExtra("barColor", boardColor);
|
||||
startActivityForResult(i, WLISTS_REQUEST);
|
||||
}
|
||||
});
|
||||
|
||||
swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
|
||||
@Override
|
||||
public void onRefresh() {
|
||||
initializeUI(idBoard);
|
||||
swipeRefreshLayout.setRefreshing(false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void findViews() {
|
||||
myToolbar = findViewById(R.id.my_toolbar);
|
||||
getListsButton = findViewById(R.id.getLists);
|
||||
description = findViewById(R.id.descriptionTxt);
|
||||
members = findViewById(R.id.membersTxt);
|
||||
permission = findViewById(R.id.permissionTxt);
|
||||
creationDate = findViewById(R.id.createdDate);
|
||||
lastModificationDate = findViewById(R.id.modifiedDate);
|
||||
divider1 = findViewById(R.id.divider1);
|
||||
divider2 = findViewById(R.id.divider2);
|
||||
divider3 = findViewById(R.id.divider3);
|
||||
listView = findViewById(R.id.listViewID);
|
||||
swipeRefreshLayout = findViewById(R.id.pullToRefresh);
|
||||
}
|
||||
|
||||
private void initializeUI(String idBoard) {
|
||||
service = new ServicesFactory(sp);
|
||||
service.getBoardService().getBoard(idBoard).enqueue(new Callback<Board>() {
|
||||
@Override
|
||||
public void onResponse(@NotNull Call<Board> call, @NotNull Response<Board> response) {
|
||||
assert response.body() != null;
|
||||
board = response.body();
|
||||
if (board.getId() == null) {
|
||||
Toast.makeText(
|
||||
getApplicationContext(),
|
||||
getApplicationContext().getString(R.string.board_deleted),
|
||||
Toast.LENGTH_LONG)
|
||||
.show();
|
||||
getListsButton.setEnabled(false);
|
||||
} else {
|
||||
Objects.requireNonNull(getSupportActionBar()).setTitle(board.getTitle());
|
||||
myToolbar.setBackgroundColor(Color.parseColor(encodeColor(
|
||||
board.getBackgroundColor().toString())));
|
||||
|
||||
boardTitle = board.getTitle();
|
||||
|
||||
boardColor = Color.parseColor(encodeColor(
|
||||
board.getBackgroundColor().toString()));
|
||||
|
||||
Drawable background = getListsButton.getBackground();
|
||||
background.setTint(boardColor);
|
||||
getListsButton.setBackgroundDrawable(background);
|
||||
|
||||
description.setText(board.getDescription());
|
||||
permission.setText(board.getPermission().toString());
|
||||
members.setText("");
|
||||
for (int i = 0; i < board.getMembers().size(); i++) {
|
||||
replaceIDUserToUsername(board.getMembers().get(i).getUserId());
|
||||
}
|
||||
|
||||
creationDate.setText(R.string.created_at);
|
||||
creationDate.append("\n"
|
||||
+ board.getCreatedAt());
|
||||
lastModificationDate.setText(R.string.modified_at);
|
||||
lastModificationDate.append("\n"
|
||||
+ board.getModifiedAt());
|
||||
|
||||
divider1.setBackgroundColor(boardColor);
|
||||
divider2.setBackgroundColor(boardColor);
|
||||
divider3.setBackgroundColor(boardColor);
|
||||
|
||||
ArrayList<String> labelsTitle = new ArrayList<>();
|
||||
for (int i = 0; i < board.getLabels().size(); i++) {
|
||||
labelsTitle.add(board.getLabels().get(i).getName());
|
||||
}
|
||||
ArrayAdapter<String> adapter = new ArrayAdapter<>(getApplicationContext(),
|
||||
android.R.layout.simple_list_item_1, labelsTitle);
|
||||
listView.setAdapter(adapter);
|
||||
getListsButton.setEnabled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(@NotNull Call<Board> call, @NotNull Throwable t) {
|
||||
Toast.makeText(getApplicationContext(),
|
||||
"connection error",
|
||||
Toast.LENGTH_LONG).show();
|
||||
getListsButton.setEnabled(false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private String encodeColor(String color) {
|
||||
String encodedColor;
|
||||
if (color.equalsIgnoreCase("belize")) {
|
||||
encodedColor = "#2980B9";
|
||||
} else if (color.equalsIgnoreCase("nephritis")) {
|
||||
encodedColor = "#27AE60";
|
||||
} else if (color.equalsIgnoreCase("pomegranate")) {
|
||||
encodedColor = "#C0392B";
|
||||
} else if (color.equalsIgnoreCase("pumpkin")) {
|
||||
encodedColor = "#E67E22";
|
||||
} else if (color.equalsIgnoreCase("wisteria")) {
|
||||
encodedColor = "#8E44AD";
|
||||
} else if (color.equalsIgnoreCase("moderatepink")) {
|
||||
encodedColor = "#CD5A91";
|
||||
} else if (color.equalsIgnoreCase("strongcyan")) {
|
||||
encodedColor = "#00AECC";
|
||||
} else if (color.equalsIgnoreCase("dark")) {
|
||||
encodedColor = "#2C3E51";
|
||||
} else if (color.equalsIgnoreCase("midnight")) {
|
||||
encodedColor = "#2C3E50";
|
||||
} else if (color.equalsIgnoreCase("relax")) {
|
||||
encodedColor = "#27AE61";
|
||||
} else if (color.equalsIgnoreCase("corteza")) {
|
||||
encodedColor = "#568BA2";
|
||||
} else
|
||||
encodedColor = "#38DF87";
|
||||
|
||||
return encodedColor;
|
||||
}
|
||||
|
||||
private void replaceIDUserToUsername(String idUser) {
|
||||
service = new ServicesFactory(sp);
|
||||
service.getUserService().getUser(idUser).enqueue(new Callback<User>() {
|
||||
@Override
|
||||
public void onResponse(@NotNull Call<User> call, @NotNull Response<User> response) {
|
||||
User u = response.body();
|
||||
assert u != null;
|
||||
username = u.getUsername();
|
||||
if (u.isAdmin()) {
|
||||
members.append("Admin: " + username + ";\n");
|
||||
} else
|
||||
members.append("Other member: " + username + ";\n");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(@NotNull Call<User> call, @NotNull Throwable t) {
|
||||
//TODO
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
if (requestCode == WLISTS_REQUEST) {
|
||||
if (resultCode != WListsListActivity.RESULT_OK) {
|
||||
Toast.makeText(this, "It's not possible view the lists",
|
||||
Toast.LENGTH_LONG).show();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -42,7 +42,7 @@ class LoginActivity : AppCompatActivity() {
|
||||
val passwordText = password.text.toString()
|
||||
val instanceServerText = instanceServer.text.toString()
|
||||
|
||||
if (!URLUtil.isValidUrl(instanceServerText)){
|
||||
if (!URLUtil.isValidUrl(instanceServerText)) {
|
||||
Toast.makeText(this, R.string.login_unformed_instance, Toast.LENGTH_LONG)
|
||||
.show()
|
||||
return
|
||||
|
@ -0,0 +1,118 @@
|
||||
package it.unisannio.ding.ids.wedroid.app.view;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.content.res.ColorStateList;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
import androidx.lifecycle.Observer;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
import androidx.recyclerview.widget.ItemTouchHelper;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import it.unisannio.ding.ids.wedroid.app.R;
|
||||
|
||||
import it.unisannio.ding.ids.wedroid.app.data.entity.WList;
|
||||
import it.unisannio.ding.ids.wedroid.app.util.SharedPreferenceHelper;
|
||||
import it.unisannio.ding.ids.wedroid.app.view.adapter.WListsAdapter;
|
||||
import it.unisannio.ding.ids.wedroid.app.viewmodel.WListsListViewModel;
|
||||
|
||||
public class WListsListActivity extends AppCompatActivity {
|
||||
|
||||
Toolbar myToolbar;
|
||||
int barColor;
|
||||
WListsListViewModel viewModel;
|
||||
RecyclerView recyclerView;
|
||||
//SwipeRefreshLayout swipeRefreshLayout;
|
||||
SharedPreferenceHelper sp;
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_wlists_view);
|
||||
myToolbar = findViewById(R.id.my_toolbar);
|
||||
setSupportActionBar(myToolbar);
|
||||
//swipeRefreshLayout = findViewById(R.id.pullToRefresh);
|
||||
sp = new SharedPreferenceHelper(this);
|
||||
|
||||
Intent i = getIntent();
|
||||
String boardTitle = i.getStringExtra("barTitle");
|
||||
Objects.requireNonNull(getSupportActionBar()).setTitle(boardTitle);
|
||||
barColor = i.getIntExtra("barColor", 0);
|
||||
setResult(WListsListActivity.RESULT_OK, i);
|
||||
|
||||
myToolbar.setBackgroundColor(barColor);
|
||||
|
||||
recyclerView = findViewById(R.id.recyclerviewWList);
|
||||
initializeUi(sp.getBoardId());
|
||||
|
||||
FloatingActionButton fab = findViewById(R.id.synchronize);
|
||||
fab.setBackgroundTintList(ColorStateList.valueOf(barColor));
|
||||
fab.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
viewModel.refresh();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void initializeUi(final String idBoard) {
|
||||
final WListsAdapter adapter = new WListsAdapter(this);
|
||||
recyclerView.setAdapter(adapter);
|
||||
recyclerView.setLayoutManager(new LinearLayoutManager(this,
|
||||
LinearLayoutManager.HORIZONTAL, false));
|
||||
//recyclerView.setHasFixedSize(true);
|
||||
|
||||
viewModel = new ViewModelProvider(this).get(WListsListViewModel.class);
|
||||
|
||||
viewModel.getAllWLists().observe(this, new Observer<List<WList>>() {
|
||||
@Override
|
||||
public void onChanged(List<WList> wLists) {
|
||||
adapter.setWLists(wLists);
|
||||
}
|
||||
});
|
||||
|
||||
swipeBottomToDelete(idBoard);
|
||||
|
||||
/* BUG REPORT: Refresh of page enter in conflict with swipe down for delete list
|
||||
* swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
|
||||
@Override
|
||||
public void onRefresh() {
|
||||
viewModel.refresh();
|
||||
}
|
||||
});*/
|
||||
}
|
||||
|
||||
private void swipeBottomToDelete(final String idBoard) {
|
||||
ItemTouchHelper.SimpleCallback simpleCallback = new ItemTouchHelper.SimpleCallback(0,
|
||||
ItemTouchHelper.DOWN) {
|
||||
@Override
|
||||
public boolean onMove(@NonNull RecyclerView recyclerView,
|
||||
@NonNull RecyclerView.ViewHolder viewHolder,
|
||||
@NonNull RecyclerView.ViewHolder target) {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSwiped(@NonNull RecyclerView.ViewHolder viewHolder, int direction) {
|
||||
int pos = viewHolder.getAdapterPosition();
|
||||
viewModel.deleteWList(pos, idBoard);
|
||||
Toast.makeText(getApplicationContext(), "List deleted", Toast.LENGTH_LONG).show();
|
||||
|
||||
}
|
||||
};
|
||||
new ItemTouchHelper(simpleCallback).attachToRecyclerView(recyclerView);
|
||||
}
|
||||
}
|
@ -9,6 +9,7 @@ import android.widget.TextView
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import it.unisannio.ding.ids.wedroid.app.R
|
||||
import it.unisannio.ding.ids.wedroid.app.data.entity.Board
|
||||
import it.unisannio.ding.ids.wedroid.app.view.BoardViewActivity
|
||||
|
||||
class BoardsListAdapter internal constructor(
|
||||
context: Context
|
||||
@ -37,9 +38,10 @@ class BoardsListAdapter internal constructor(
|
||||
holder.boardTitle.text = board.title
|
||||
|
||||
holder.itemView.setOnClickListener {
|
||||
val intent = Intent(it.context, TODO())
|
||||
intent.putExtra(BOARD_ID, board.id)
|
||||
it.context.startActivity(intent)
|
||||
|
||||
val intent = Intent(holder.itemView.context, BoardViewActivity::class.java)
|
||||
intent.putExtra("idBoard", board.id)
|
||||
holder.itemView.context.startActivity(intent)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,201 @@
|
||||
package it.unisannio.ding.ids.wedroid.app.view.adapter;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import it.unisannio.ding.ids.wedroid.app.R;
|
||||
import it.unisannio.ding.ids.wedroid.app.data.entity.WList;
|
||||
import it.unisannio.ding.ids.wedroid.app.util.ServicesFactory;
|
||||
import it.unisannio.ding.ids.wedroid.app.util.SharedPreferenceHelper;
|
||||
import it.unisannio.ding.ids.wedroid.wrapper.entity.Card;
|
||||
import it.unisannio.ding.ids.wedroid.wrapper.entity.Swimlane;
|
||||
import retrofit2.Call;
|
||||
import retrofit2.Callback;
|
||||
import retrofit2.Response;
|
||||
|
||||
public class WListsAdapter extends RecyclerView.Adapter<WListsAdapter.WListViewHolder> {
|
||||
|
||||
private final LayoutInflater mInflater;
|
||||
private List<WList> mWLists; // Cached copy of lists
|
||||
private Context mContext;
|
||||
private ServicesFactory service;
|
||||
private SharedPreferenceHelper sp;
|
||||
|
||||
public WListsAdapter(Context context) {
|
||||
mInflater = LayoutInflater.from(context);
|
||||
mContext = context;
|
||||
sp = new SharedPreferenceHelper(mContext);
|
||||
service = new ServicesFactory(sp);
|
||||
}
|
||||
|
||||
class WListViewHolder extends RecyclerView.ViewHolder {
|
||||
private final TextView wListItemView;
|
||||
ListView listView;
|
||||
Button button;
|
||||
|
||||
private WListViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
wListItemView = itemView.findViewById(R.id.wListTitle);
|
||||
listView = itemView.findViewById(R.id.listViewCard);
|
||||
button = itemView.findViewById(R.id.buttonAddCard);
|
||||
}
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public WListViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
View itemView = mInflater.inflate(R.layout.wlist_recyclerview_item, parent, false);
|
||||
return new WListViewHolder(itemView);
|
||||
}
|
||||
|
||||
@SuppressLint("SetTextI18n")
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull final WListViewHolder holder, int position) {
|
||||
if (mWLists != null) {
|
||||
final WList current = mWLists.get(position);
|
||||
final List<String> cardTitle = new ArrayList<>();
|
||||
service.getCardService().getAllCards(sp.getBoardId(), current.getId()).enqueue(
|
||||
new Callback<List<Card>>() {
|
||||
@Override
|
||||
public void onResponse(@NotNull Call<List<Card>> call, @NotNull Response<List<Card>> response) {
|
||||
assert response.body() != null;
|
||||
for (int i = 0; i < response.body().size(); i++) {
|
||||
cardTitle.add(response.body().get(i).getTitle());
|
||||
}
|
||||
ArrayAdapter<String> adapter = new ArrayAdapter<>(mContext,
|
||||
android.R.layout.simple_list_item_1, cardTitle);
|
||||
holder.listView.setAdapter(adapter);
|
||||
holder.wListItemView.setText(current.getTitle());
|
||||
holder.button.setText("Add Card to " + current.getTitle());
|
||||
holder.button.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
showInputDialog(current.getId());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(@NotNull Call<List<Card>> call, @NotNull Throwable t) {
|
||||
}
|
||||
});
|
||||
|
||||
/*position of the old content holder**/
|
||||
|
||||
} else {
|
||||
// Covers the case of data not being ready yet.
|
||||
holder.wListItemView.setText("No wList");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
if (mWLists != null)
|
||||
return mWLists.size();
|
||||
else return 0;
|
||||
}
|
||||
|
||||
public void setWLists(List<WList> wList) {
|
||||
mWLists = wList;
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
private void showInputDialog(final String current) {
|
||||
LayoutInflater layoutInflater = LayoutInflater.from(mContext);
|
||||
@SuppressLint("InflateParams") View promptView = layoutInflater.inflate(
|
||||
R.layout.alert_new_card, null);
|
||||
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(mContext);
|
||||
alertDialogBuilder.setView(promptView);
|
||||
|
||||
final EditText editText = promptView.findViewById(R.id.edittext);
|
||||
// setup a dialog window
|
||||
alertDialogBuilder.setCancelable(false)
|
||||
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
|
||||
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
if (!editText.getText().toString().matches("")) {
|
||||
service.getSwimlanesService().getAllSwimlanes(sp.getBoardId())
|
||||
.enqueue(new Callback<List<Swimlane>>() {
|
||||
@Override
|
||||
public void onResponse(@NotNull Call<List<Swimlane>> call,
|
||||
@NotNull Response<List<Swimlane>> response) {
|
||||
String idDefaultSwimlane = null;
|
||||
assert response.body() != null;
|
||||
for (Swimlane swim : response.body()) {
|
||||
if (swim.getTitle().equalsIgnoreCase("default"))
|
||||
idDefaultSwimlane = swim.getTitle();
|
||||
}
|
||||
final Card card = new Card();
|
||||
card.setTitle(editText.getText().toString());
|
||||
card.setAuthorId(sp.getUserId());
|
||||
card.setSwimlaneId(idDefaultSwimlane);
|
||||
//card.setDescription("new card from app");
|
||||
service.getListService().getList(sp.getBoardId(), current).enqueue(new Callback<it.unisannio.ding.ids.wedroid.wrapper.entity.WList>() {
|
||||
@Override
|
||||
public void onResponse(@NotNull Call<it.unisannio.ding.ids.wedroid.wrapper.entity.WList> call, @NotNull Response<it.unisannio.ding.ids.wedroid.wrapper.entity.WList> response) {
|
||||
|
||||
service.getCardService().newCard(sp.getBoardId(), current, card).enqueue(new Callback<Card>() {
|
||||
@Override
|
||||
public void onResponse(@NotNull Call<Card> call, @NotNull Response<Card> response) {
|
||||
if (response.isSuccessful())
|
||||
Toast.makeText(mContext, "card posted",
|
||||
Toast.LENGTH_LONG).show();
|
||||
else
|
||||
Toast.makeText(mContext, "card doesn't posted",
|
||||
Toast.LENGTH_LONG).show();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(@NotNull Call<Card> call, @NotNull Throwable t) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(@NotNull Call<it.unisannio.ding.ids.wedroid.wrapper.entity.WList> call, @NotNull Throwable t) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(@NotNull Call<List<Swimlane>> call, @NotNull Throwable t) {
|
||||
|
||||
}
|
||||
});
|
||||
} else
|
||||
Toast.makeText(mContext, "cancel", Toast.LENGTH_LONG).show();
|
||||
}
|
||||
})
|
||||
.setNegativeButton("Cancel",
|
||||
new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
dialog.cancel();
|
||||
}
|
||||
});
|
||||
|
||||
// create an alert dialog
|
||||
AlertDialog alert = alertDialogBuilder.create();
|
||||
alert.show();
|
||||
}
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
package it.unisannio.ding.ids.wedroid.app.viewmodel;
|
||||
|
||||
import android.app.Application;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.lifecycle.AndroidViewModel;
|
||||
import androidx.lifecycle.LiveData;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import it.unisannio.ding.ids.wedroid.app.data.database.WListDatabase;
|
||||
import it.unisannio.ding.ids.wedroid.app.data.entity.WList;
|
||||
import it.unisannio.ding.ids.wedroid.app.data.repository.WListRepository;
|
||||
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 WListsListViewModel extends AndroidViewModel {
|
||||
private WListRepository wListRepository;
|
||||
private LiveData<List<WList>> allWLists;
|
||||
|
||||
public WListsListViewModel(@NonNull Application application) {
|
||||
super(application);
|
||||
PreferenceReader reader = new SharedPreferenceHelper(application);
|
||||
wListRepository = new WListRepository(
|
||||
WListDatabase.getDatabase(application).wListDao(),
|
||||
ServicesFactory.Companion.getInstance(reader).getListService(),
|
||||
reader);
|
||||
allWLists = wListRepository.getAllWLists();
|
||||
}
|
||||
|
||||
public LiveData<List<WList>> getAllWLists(){
|
||||
return allWLists;
|
||||
}
|
||||
|
||||
public void deleteWList(int position, String idBoard) {
|
||||
List<WList> wList = allWLists.getValue();
|
||||
|
||||
if (wList != null)
|
||||
wListRepository.deleteWList(idBoard, wList.get(position).getId());
|
||||
}
|
||||
|
||||
public void refresh() {
|
||||
wListRepository.synchronize();
|
||||
}
|
||||
}
|
7
app/src/main/res/drawable/rounded_shape.xml
Normal file
7
app/src/main/res/drawable/rounded_shape.xml
Normal file
@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<shape android:shape="rectangle">
|
||||
<solid android:color="@color/colorAccent"></solid>
|
||||
<corners android:radius="11dp"></corners>
|
||||
</shape>
|
||||
</selector>
|
212
app/src/main/res/layout/activity_board_view.xml
Normal file
212
app/src/main/res/layout/activity_board_view.xml
Normal file
@ -0,0 +1,212 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/pullToRefresh"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent">
|
||||
|
||||
<ScrollView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:scrollIndicators="right"
|
||||
android:scrollbarStyle="insideOverlay"
|
||||
android:scrollbars="vertical">
|
||||
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
|
||||
<androidx.appcompat.widget.Toolbar
|
||||
android:id="@+id/my_toolbar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="?attr/actionBarSize"
|
||||
android:background="?attr/colorPrimary"
|
||||
android:elevation="4dp"
|
||||
android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
|
||||
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textViewInfo"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingLeft="@dimen/padding"
|
||||
android:paddingRight="@dimen/padding"
|
||||
android:paddingTop="1dp"
|
||||
android:text="@string/info_board"
|
||||
android:textAlignment="center"
|
||||
android:textSize="18sp"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/description"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingLeft="@dimen/padding"
|
||||
android:paddingRight="@dimen/padding"
|
||||
android:text="@string/description"
|
||||
android:textSize="18sp"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/descriptionTxt"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingLeft="@dimen/padding"
|
||||
android:paddingRight="@dimen/padding"
|
||||
android:paddingTop="3dp"
|
||||
android:paddingBottom="3dp"
|
||||
android:text="@string/defaultTxt" />
|
||||
|
||||
<View
|
||||
android:id="@+id/divider1"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="3dp"
|
||||
android:background="#FF008577"
|
||||
android:visibility="visible" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/members"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingLeft="@dimen/padding"
|
||||
android:paddingRight="@dimen/padding"
|
||||
android:paddingTop="3dp"
|
||||
android:text="@string/members"
|
||||
android:textSize="18sp"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/membersTxt"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingLeft="10dp"
|
||||
android:paddingRight="10dp"
|
||||
android:paddingTop="3dp"
|
||||
android:paddingBottom="3dp"
|
||||
android:text="@string/defaultTxt" />
|
||||
|
||||
<View
|
||||
android:id="@+id/divider2"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="3dp"
|
||||
android:background="#FF008577"
|
||||
android:visibility="visible" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/permission"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingLeft="@dimen/padding"
|
||||
android:paddingRight="@dimen/padding"
|
||||
android:paddingTop="3dp"
|
||||
android:text="@string/permission"
|
||||
android:textSize="18sp"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/permissionTxt"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingLeft="@dimen/padding"
|
||||
android:paddingRight="@dimen/padding"
|
||||
android:paddingTop="3dp"
|
||||
android:paddingBottom="3dp"
|
||||
android:text="@string/defaultTxt" />
|
||||
|
||||
<View
|
||||
android:id="@+id/divider3"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="3dp"
|
||||
android:background="#FF008577"
|
||||
android:visibility="visible" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/labels"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingLeft="@dimen/padding"
|
||||
android:paddingRight="@dimen/padding"
|
||||
android:paddingTop="3dp"
|
||||
android:text="@string/labels"
|
||||
android:textSize="18sp"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<ListView
|
||||
android:id="@+id/listViewID"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="150dp"
|
||||
android:layout_marginLeft="8dp"
|
||||
android:layout_marginTop="3dp"
|
||||
android:layout_marginRight="8dp"
|
||||
android:nestedScrollingEnabled="true" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/getLists"
|
||||
style="@style/AppTheme.RoundedCornerMaterialButton"
|
||||
android:layout_width="271dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="70dp"
|
||||
android:layout_marginTop="40dp"
|
||||
android:layout_marginEnd="70dp"
|
||||
android:stateListAnimator="@android:anim/fade_in"
|
||||
android:text="@string/view_lists_button_name"
|
||||
android:textAlignment="center"
|
||||
app:backgroundTint="#80CBC4"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintHorizontal_bias="0.0"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/modifiedDate"
|
||||
android:layout_width="100dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="30dp"
|
||||
android:layout_marginEnd="12dp"
|
||||
android:layout_marginBottom="50dp"
|
||||
android:text="@string/modified_at"
|
||||
android:textAlignment="textEnd"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/getLists"
|
||||
app:layout_constraintVertical_bias="0.0" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/createdDate"
|
||||
android:layout_width="100dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="15dp"
|
||||
android:layout_marginTop="30dp"
|
||||
android:layout_marginBottom="50dp"
|
||||
android:text="@string/created_at"
|
||||
android:textAlignment="viewStart"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toStartOf="@+id/modifiedDate"
|
||||
app:layout_constraintHorizontal_bias="0.0"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/getLists"
|
||||
app:layout_constraintVertical_bias="0.0" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
</LinearLayout>
|
||||
</ScrollView>
|
||||
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
|
47
app/src/main/res/layout/activity_wlists_view.xml
Normal file
47
app/src/main/res/layout/activity_wlists_view.xml
Normal file
@ -0,0 +1,47 @@
|
||||
<?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">
|
||||
|
||||
<androidx.appcompat.widget.Toolbar
|
||||
android:id="@id/my_toolbar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="?attr/actionBarSize"
|
||||
android:background="?attr/colorPrimary"
|
||||
android:elevation="4dp"
|
||||
android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
|
||||
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
|
||||
|
||||
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/recyclerviewWList"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
android:background="@android:color/white"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintHorizontal_bias="0.0"
|
||||
app:layout_constraintLeft_toLeftOf="parent"
|
||||
app:layout_constraintRight_toRightOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/my_toolbar"
|
||||
tools:listitem="@layout/wlist_recyclerview_item" />
|
||||
|
||||
<com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||
android:id="@+id/synchronize"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="@dimen/fab_margin"
|
||||
android:clickable="true"
|
||||
android:focusable="true"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintRight_toRightOf="parent"
|
||||
app:srcCompat="@android:drawable/ic_popup_sync" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
20
app/src/main/res/layout/alert_new_card.xml
Normal file
20
app/src/main/res/layout/alert_new_card.xml
Normal file
@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical" android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:text="@string/enter_card_name"
|
||||
android:id="@+id/textView" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/edittext"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="@string/enter_text_here"
|
||||
android:padding="10dp" />
|
||||
|
||||
</LinearLayout>
|
28
app/src/main/res/layout/wlist_recyclerview_item.xml
Normal file
28
app/src/main/res/layout/wlist_recyclerview_item.xml
Normal file
@ -0,0 +1,28 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/wListTitle"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="#BBDEFB"
|
||||
android:orientation="horizontal"
|
||||
android:textAlignment="center"
|
||||
android:textSize="24sp"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<ListView
|
||||
android:id="@+id/listViewCard"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/buttonAddCard"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/add_card_button" />
|
||||
|
||||
</LinearLayout>
|
@ -1,4 +1,8 @@
|
||||
<resources>
|
||||
<dimen name="fab_margin">16dp</dimen>
|
||||
|
||||
<dimen name="padding">10dp</dimen>
|
||||
|
||||
<dimen name="board_item_padding">8dp</dimen>
|
||||
|
||||
</resources>
|
||||
|
@ -1,5 +1,17 @@
|
||||
<resources>
|
||||
<string name="app_name">wedroid</string>
|
||||
<string name="view_lists_button_name">View lists</string>
|
||||
<string name="info_board">Info board</string>
|
||||
<string name="description">-Description:</string>
|
||||
<string name="defaultTxt">***</string>
|
||||
<string name="members">-Members:</string>
|
||||
<string name="permission">-Permission:</string>
|
||||
<string name="labels">-Labels:</string>
|
||||
<string name="modified_at">Modified at:</string>
|
||||
<string name="created_at">Created at:</string>
|
||||
<string name="add_card_button">Add Card</string>
|
||||
<string name="enter_text_here">Enter text here...</string>
|
||||
<string name="enter_card_name">Enter card name</string>
|
||||
<string name="title_activity_boards_lists">BoardsListActivity</string>
|
||||
<string name="title_activity_new_board">NewBoardActivity</string>
|
||||
<string name="new_board_name_field">Board name</string>
|
||||
@ -9,6 +21,7 @@
|
||||
<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>
|
||||
<string name="on_add_new_board_empty_name">Name cannot be empty</string>
|
||||
<string name="board_deleted">The selected board has been deleted</string>
|
||||
|
||||
<string-array name="board_background_colors">
|
||||
<item>Belize</item>
|
||||
@ -29,4 +42,5 @@
|
||||
<string name="login_network_error">Controlla la tua connessione internet</string>
|
||||
<string name="login_wrong_field">Credenziali non corrette</string>
|
||||
<string name="login_success">Login effettuato con successo</string>
|
||||
|
||||
</resources>
|
||||
|
@ -17,4 +17,8 @@
|
||||
|
||||
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
|
||||
|
||||
<style name="AppTheme.RoundedCornerMaterialButton" parent="Widget.AppCompat.Button.Colored">
|
||||
<item name="android:background">@drawable/rounded_shape</item>
|
||||
</style>
|
||||
|
||||
</resources>
|
||||
|
@ -0,0 +1,203 @@
|
||||
package it.unisannio.ding.ids.wedroid.app.data.repository
|
||||
|
||||
import android.util.Log
|
||||
import androidx.lifecycle.LiveData
|
||||
import io.mockk.*
|
||||
import it.unisannio.ding.ids.wedroid.app.data.dao.WListDao
|
||||
import it.unisannio.ding.ids.wedroid.app.data.entity.WList
|
||||
import it.unisannio.ding.ids.wedroid.app.getPrivateFun
|
||||
import it.unisannio.ding.ids.wedroid.app.util.PreferenceReader
|
||||
import it.unisannio.ding.ids.wedroid.wrapper.api.ListService
|
||||
import junit.framework.TestCase
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import okhttp3.mockwebserver.MockWebServer
|
||||
import org.junit.After
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import retrofit2.Response
|
||||
import retrofit2.Retrofit
|
||||
import retrofit2.converter.gson.GsonConverterFactory
|
||||
import kotlin.reflect.full.callSuspend
|
||||
|
||||
class WListRepositoryTest {
|
||||
private val reader = mockk<PreferenceReader>()
|
||||
private val webServer = MockWebServer()
|
||||
private lateinit var service: ListService
|
||||
|
||||
@Before
|
||||
fun setUp() {
|
||||
webServer.start()
|
||||
service = Retrofit.Builder()
|
||||
.baseUrl(webServer.url("/"))
|
||||
.addConverterFactory(GsonConverterFactory.create())
|
||||
.build()
|
||||
.create(ListService::class.java)
|
||||
|
||||
mockkStatic(Log::class)
|
||||
every { reader.boardId } returns "board id"
|
||||
every { Log.e(any(), any()) } returns 0
|
||||
}
|
||||
|
||||
@After
|
||||
fun teardown() {
|
||||
webServer.close()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun addNewBoardsToDb() {
|
||||
val dao = mockk<WListDao>()
|
||||
var count = 0
|
||||
|
||||
coEvery {
|
||||
dao.insert(any())
|
||||
} answers {
|
||||
count++
|
||||
}
|
||||
|
||||
val addNewListToDb = getPrivateFun(
|
||||
"addNewWListToDb", WListRepository::class
|
||||
)
|
||||
|
||||
val repository = WListRepository(
|
||||
dao, service, reader
|
||||
)
|
||||
|
||||
val list0 = WList("id0", "title0")
|
||||
val list1 = WList("id1", "title1")
|
||||
val list2 = WList("id2", "title2")
|
||||
|
||||
runBlocking {
|
||||
addNewListToDb?.callSuspend(
|
||||
repository,
|
||||
listOf(list0, list1, list2)
|
||||
)
|
||||
}
|
||||
|
||||
coVerifyAll {
|
||||
dao.insert(list0)
|
||||
dao.insert(list1)
|
||||
dao.insert(list2)
|
||||
}
|
||||
|
||||
TestCase.assertEquals(3, count)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun deleteWListCallbackSuccess() {
|
||||
val dao = mockk<WListDao>()
|
||||
val response =
|
||||
mockk<Response<Void>>()
|
||||
|
||||
every { response.isSuccessful } returns true
|
||||
coEvery { dao.delete(any()) } answers {}
|
||||
|
||||
val deleteWList = getPrivateFun(
|
||||
"deleteWListCallBack", WListRepository::class
|
||||
)
|
||||
|
||||
val repository = WListRepository(
|
||||
dao, service, reader
|
||||
)
|
||||
|
||||
runBlocking {
|
||||
deleteWList?.callSuspend(
|
||||
repository,
|
||||
response,
|
||||
"id"
|
||||
)
|
||||
}
|
||||
|
||||
coVerify { dao.delete(WList("id")) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun deleteWListCallbackError() {
|
||||
val dao = mockk<WListDao>()
|
||||
val response = mockk<Response<Void>>()
|
||||
|
||||
every { response.isSuccessful } returns false
|
||||
every { response.code() } returns 400
|
||||
every { response.message() } returns "Error"
|
||||
|
||||
val repository = WListRepository(dao, service, reader)
|
||||
|
||||
val deleteWList = getPrivateFun(
|
||||
"deleteWListCallBack", WListRepository::class
|
||||
)
|
||||
|
||||
runBlocking {
|
||||
deleteWList?.callSuspend(
|
||||
repository,
|
||||
response,
|
||||
"id"
|
||||
)
|
||||
}
|
||||
verify { Log.e("RETROFIT", "400 Error") }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun deleteOldWListFromDb() {
|
||||
val dao = mockk<WListDao>()
|
||||
val dbWLists = mockk<LiveData<List<WList>>>()
|
||||
|
||||
val wList0 = WList("id0", "title0")
|
||||
val wList1 = WList("id1", "title1")
|
||||
val wList2 = WList("id2", "title2")
|
||||
val wList3 = WList("id2", "title3")
|
||||
|
||||
every { dbWLists.value } returns listOf(
|
||||
wList0, wList1, wList2, wList3
|
||||
)
|
||||
coEvery { dao.allWList } returns dbWLists
|
||||
coEvery { dao.delete(any()) } answers {}
|
||||
|
||||
val removeOldWLists = getPrivateFun(
|
||||
"removeOldWListsFromDb", WListRepository::class
|
||||
)
|
||||
|
||||
val repository = WListRepository(
|
||||
dao, service, reader
|
||||
)
|
||||
|
||||
runBlocking {
|
||||
removeOldWLists?.callSuspend(
|
||||
repository,
|
||||
listOf(
|
||||
wList0, wList2, wList3
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
coVerify { dao.delete(wList1) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun synchronizeCallbackError() {
|
||||
val dao = mockk<WListDao>()
|
||||
|
||||
val response =
|
||||
mockk<Response<MutableList<it.unisannio.ding.ids.wedroid.wrapper.entity.WList>>>()
|
||||
|
||||
every { response.isSuccessful } returns false
|
||||
every { response.code() } returns 400
|
||||
every { response.message() } returns "Error"
|
||||
|
||||
val synchronize = getPrivateFun(
|
||||
"synchronizeCallback", WListRepository::class
|
||||
)
|
||||
|
||||
val repository = WListRepository(
|
||||
dao, service, reader
|
||||
)
|
||||
|
||||
runBlocking {
|
||||
synchronize?.callSuspend(
|
||||
repository,
|
||||
response
|
||||
)
|
||||
}
|
||||
|
||||
verify { Log.e("RETROFIT", "400 Error") }
|
||||
}
|
||||
|
||||
}
|
@ -9,7 +9,7 @@ buildscript {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:3.5.2'
|
||||
classpath 'com.android.tools.build:gradle:3.5.3'
|
||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||
classpath "io.gitlab.arturbosch.detekt:detekt-gradle-plugin:1.2.2"
|
||||
// NOTE: Do not place your application dependencies here; they belong
|
||||
@ -27,8 +27,8 @@ allprojects {
|
||||
}
|
||||
|
||||
ext {
|
||||
roomVersion = '2.2.2'
|
||||
archLifecycleVersion = '2.2.0-rc02'
|
||||
roomVersion = '2.2.3'
|
||||
archLifecycleVersion = '2.2.0-rc03'
|
||||
androidxArchVersion = '2.1.0'
|
||||
coreTestingVersion = "2.1.0"
|
||||
coroutines = '1.3.2'
|
||||
|
Loading…
Reference in New Issue
Block a user