integration branch

This commit is contained in:
Umberto Furno 2020-01-06 22:47:04 +01:00
parent bb4b4a91c8
commit 7295be413d
11 changed files with 336 additions and 242 deletions

View File

@ -13,7 +13,7 @@
android:supportsRtl="true" android:supportsRtl="true"
android:theme="@style/AppTheme" android:theme="@style/AppTheme"
tools:ignore="GoogleAppIndexingWarning"> tools:ignore="AllowBackup,GoogleAppIndexingWarning">
<activity android:name=".view.LoginActivity" /> <activity android:name=".view.LoginActivity" />
@ -22,6 +22,16 @@
android:label="@string/title_activity_new_board" android:label="@string/title_activity_new_board"
android:theme="@style/AppTheme.NoActionBar" /> 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 <activity
android:name=".view.BoardsListsActivity" android:name=".view.BoardsListsActivity"
android:theme="@style/AppTheme.NoActionBar"> android:theme="@style/AppTheme.NoActionBar">
@ -31,11 +41,6 @@
</intent-filter> </intent-filter>
</activity> </activity>
<activity android:name=".view.BoardViewActivity"
android:theme="@style/Theme.AppCompat.Light.NoActionBar" />
<activity android:name=".view.WListsListActivity"
android:label="WList"
android:theme="@style/AppTheme.NoActionBar"/>
</application> </application>
</manifest> </manifest>

View File

@ -19,7 +19,7 @@ public interface WListDao {
LiveData<List<WList>> getAllWList(); LiveData<List<WList>> getAllWList();
@Insert(onConflict = OnConflictStrategy.REPLACE) @Insert(onConflict = OnConflictStrategy.REPLACE)
/**Completable**/ void insert(WList wList); void insert(WList wList);
@Delete @Delete
void delete(WList wList); void delete(WList wList);

View File

@ -1,6 +1,8 @@
package it.unisannio.ding.ids.wedroid.app.data.repository package it.unisannio.ding.ids.wedroid.app.data.repository
import android.util.Log 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.dao.WListDao
import it.unisannio.ding.ids.wedroid.app.data.entity.WList 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.data.entity.convert
@ -18,8 +20,9 @@ class WListRepository(
private val service: ListService, private val service: ListService,
private val reader: PreferenceReader private val reader: PreferenceReader
) { ) {
val allWLists by lazy{
dao.getAllWList() val allWLists: LiveData<MutableList<WList>> by lazy{
dao.allWList
} }
init { init {
@ -46,7 +49,7 @@ class WListRepository(
}) })
} }
private suspend fun synchronizeCallback( private fun synchronizeCallback(
response: Response<MutableList<it.unisannio.ding.ids.wedroid.wrapper.entity.WList>>) response: Response<MutableList<it.unisannio.ding.ids.wedroid.wrapper.entity.WList>>)
{ {
if (!response.isSuccessful) { if (!response.isSuccessful) {
@ -90,19 +93,21 @@ class WListRepository(
} }
private suspend fun addNewWListToDb(wLists: Collection<WList>) { private fun addNewWListToDb(wLists: Collection<WList>) {
wLists.forEach { wLists.forEach {
dao.insert(it) dao.insert(it)
} }
} }
private suspend fun removeOldWListsFromDb(wLists: Collection<WList>) {
private fun removeOldWListsFromDb(wLists: Collection<WList>) {
allWLists.value?.minus(wLists) allWLists.value?.minus(wLists)
?.forEach { ?.forEach {
dao.delete(it) dao.delete(it)
} }
} }
@Suppress("NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS")
private fun logNetworkError(message: String?) { private fun logNetworkError(message: String?) {
Log.e("RETROFIT", message) Log.e("RETROFIT", message)
} }

View File

@ -1,17 +1,10 @@
package it.unisannio.ding.ids.wedroid.app.util package it.unisannio.ding.ids.wedroid.app.util
import it.unisannio.ding.ids.wedroid.wrapper.api.BoardService import it.unisannio.ding.ids.wedroid.wrapper.api.*
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.ListService
import it.unisannio.ding.ids.wedroid.wrapper.api.SwimlanesService
import it.unisannio.ding.ids.wedroid.wrapper.api.UserService
import okhttp3.OkHttpClient import okhttp3.OkHttpClient
import retrofit2.Retrofit import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory import retrofit2.converter.gson.GsonConverterFactory
class ServicesFactory( class ServicesFactory(
reader: PreferenceReader reader: PreferenceReader
) { ) {

View File

@ -3,7 +3,6 @@ package it.unisannio.ding.ids.wedroid.app.util
import android.content.Context import android.content.Context
class SharedPreferenceHelper(context : Context) : PreferenceReader, PreferenceWriter { class SharedPreferenceHelper(context : Context) : PreferenceReader, PreferenceWriter {
private val sp = context.getSharedPreferences("userinfo", Context.MODE_PRIVATE) private val sp = context.getSharedPreferences("userinfo", Context.MODE_PRIVATE)
override fun getBaseUrl(): String? { override fun getBaseUrl(): String? {
@ -21,6 +20,7 @@ class SharedPreferenceHelper(context: Context) : PreferenceReader, PreferenceWri
override fun setBaseUrl(baseUrl: String?) { override fun setBaseUrl(baseUrl: String?) {
val editor = sp.edit() val editor = sp.edit()
editor.putString("url", baseUrl).apply() editor.putString("url", baseUrl).apply()
} }
override fun setUserId(userId: String?) { override fun setUserId(userId: String?) {
@ -42,4 +42,3 @@ class SharedPreferenceHelper(context: Context) : PreferenceReader, PreferenceWri
editor.putString("boardId", token).apply() editor.putString("boardId", token).apply()
} }
} }

View File

@ -14,7 +14,7 @@ import android.widget.Toast;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar; import androidx.appcompat.widget.Toolbar;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.util.ArrayList; import java.util.ArrayList;
@ -43,6 +43,7 @@ public class BoardViewActivity extends AppCompatActivity {
private ServicesFactory service; private ServicesFactory service;
private Toolbar myToolbar; private Toolbar myToolbar;
private Board board; private Board board;
private SwipeRefreshLayout swipeRefreshLayout;
@Override @Override
protected void onCreate(@Nullable Bundle savedInstanceState) { protected void onCreate(@Nullable Bundle savedInstanceState) {
@ -51,6 +52,9 @@ public class BoardViewActivity extends AppCompatActivity {
myToolbar = findViewById(R.id.my_toolbar); myToolbar = findViewById(R.id.my_toolbar);
setSupportActionBar(myToolbar); setSupportActionBar(myToolbar);
swipeRefreshLayout = findViewById(R.id.pullToRefresh);
swipeRefreshLayout.setRefreshing(false);
Intent i = getIntent(); Intent i = getIntent();
idBoard= i.getStringExtra("idBoard"); idBoard= i.getStringExtra("idBoard");
@ -80,6 +84,14 @@ public class BoardViewActivity extends AppCompatActivity {
startActivityForResult(i, WLISTS_REQUEST); startActivityForResult(i, WLISTS_REQUEST);
} }
}); });
swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
initializeUI(idBoard);
swipeRefreshLayout.setRefreshing(false);
}
});
} }
private void initializeUI(String idBoard) { private void initializeUI(String idBoard) {
@ -87,8 +99,16 @@ public class BoardViewActivity extends AppCompatActivity {
service.getBoardService().getBoard(idBoard).enqueue(new Callback<Board>() { service.getBoardService().getBoard(idBoard).enqueue(new Callback<Board>() {
@Override @Override
public void onResponse(@NotNull Call<Board> call, @NotNull Response<Board> response) { public void onResponse(@NotNull Call<Board> call, @NotNull Response<Board> response) {
assert response.body() != null;
board = response.body(); 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()); Objects.requireNonNull(getSupportActionBar()).setTitle(board.getTitle());
myToolbar.setBackgroundColor(Color.parseColor(encodeColor( myToolbar.setBackgroundColor(Color.parseColor(encodeColor(
board.getBackgroundColor().toString()))); board.getBackgroundColor().toString())));
@ -108,8 +128,13 @@ public class BoardViewActivity extends AppCompatActivity {
for (int i = 0; i < board.getMembers().size(); i++) { for (int i = 0; i < board.getMembers().size(); i++) {
replaceIDUserToUsername(board.getMembers().get(i).getUserId()); replaceIDUserToUsername(board.getMembers().get(i).getUserId());
} }
creationDate.append("\n" + board.getCreatedAt());
lastModificationDate.append("\n" + board.getModifiedAt()); 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); divider1.setBackgroundColor(boardColor);
divider2.setBackgroundColor(boardColor); divider2.setBackgroundColor(boardColor);
@ -123,10 +148,12 @@ public class BoardViewActivity extends AppCompatActivity {
android.R.layout.simple_list_item_1, labelsTitle); android.R.layout.simple_list_item_1, labelsTitle);
listView.setAdapter(adapter); listView.setAdapter(adapter);
} }
}
@Override @Override
public void onFailure (@NotNull Call < Board > call, @NotNull Throwable t){ public void onFailure (@NotNull Call < Board > call, @NotNull Throwable t){
//TODO Toast.makeText(getApplicationContext(),
getApplicationContext().getString(R.string.board_deleted),
Toast.LENGTH_LONG).show();
} }
}); });
} }

View File

@ -22,10 +22,11 @@ import java.util.List;
import java.util.Objects; import java.util.Objects;
import it.unisannio.ding.ids.wedroid.app.R; import it.unisannio.ding.ids.wedroid.app.R;
import it.unisannio.ding.ids.wedroid.app.viewmodel.WListsListViewModel;
import it.unisannio.ding.ids.wedroid.app.data.entity.WList; 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.util.SharedPreferenceHelper;
import it.unisannio.ding.ids.wedroid.app.view.adapter.WListsAdapter; import it.unisannio.ding.ids.wedroid.app.view.adapter.WListsAdapter;
import it.unisannio.ding.ids.wedroid.app.viewModel.WListsListViewModel;
public class WListsListActivity extends AppCompatActivity { public class WListsListActivity extends AppCompatActivity {

View File

@ -38,9 +38,11 @@ class BoardsListAdapter internal constructor(
holder.boardTitle.text = board.title holder.boardTitle.text = board.title
holder.itemView.setOnClickListener { holder.itemView.setOnClickListener {
val intent = Intent(it.context, BoardViewActivity::class.java)
val intent = Intent(holder.itemView.context, BoardViewActivity::class.java)
intent.putExtra("idBoard", board.id) intent.putExtra("idBoard", board.id)
it.context.startActivity(intent) holder.itemView.context.startActivity(intent)
} }
} }

View File

@ -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();
}
}

View File

@ -1,16 +1,29 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" <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_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:scrollIndicators="right" android:scrollIndicators="right"
android:scrollbarStyle="insideOverlay" android:scrollbarStyle="insideOverlay"
android:scrollbars="vertical"> android:scrollbars="vertical">
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical"> android:orientation="vertical">
<androidx.appcompat.widget.Toolbar <androidx.appcompat.widget.Toolbar
android:id="@+id/my_toolbar" android:id="@+id/my_toolbar"
android:layout_width="match_parent" android:layout_width="match_parent"
@ -196,3 +209,4 @@
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
</LinearLayout> </LinearLayout>
</ScrollView> </ScrollView>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>

View File

@ -21,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_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_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="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"> <string-array name="board_background_colors">
<item>Belize</item> <item>Belize</item>