feature_board_view #28

Merged
norangebit merged 19 commits from feature_board_view into develop 2020-01-16 18:33:24 +00:00
19 changed files with 152 additions and 152 deletions
Showing only changes of commit 8b6104e0fa - Show all commits

View File

@ -29,7 +29,7 @@
<activity <activity
android:name=".view.WListsListActivity" android:name=".view.WListsListActivity"
android:label="WList" android:label="WList"
android:theme="@style/AppTheme.NoActionBar"/> android:theme="@style/AppTheme.NoActionBar" />
<activity <activity

View File

@ -12,6 +12,7 @@ import it.unisannio.ding.ids.wedroid.app.data.entity.Board;
@Database(entities = Board.class, version = 1, exportSchema = false) @Database(entities = Board.class, version = 1, exportSchema = false)
public abstract class BoardDatabase extends RoomDatabase { public abstract class BoardDatabase extends RoomDatabase {
private static volatile BoardDatabase INSTANCE; private static volatile BoardDatabase INSTANCE;
public abstract BoardDao boardDao(); public abstract BoardDao boardDao();
public static BoardDatabase getDatabase(Context context) { public static BoardDatabase getDatabase(Context context) {

View File

@ -12,6 +12,7 @@ import it.unisannio.ding.ids.wedroid.app.data.entity.WList;
@Database(entities = WList.class, version = 2, exportSchema = false) @Database(entities = WList.class, version = 2, exportSchema = false)
public abstract class WListDatabase extends RoomDatabase { public abstract class WListDatabase extends RoomDatabase {
private static volatile WListDatabase INSTANCE; private static volatile WListDatabase INSTANCE;
public abstract WListDao wListDao(); public abstract WListDao wListDao();
public static WListDatabase getDatabase(Context context) { public static WListDatabase getDatabase(Context context) {

View File

@ -21,7 +21,7 @@ class WListRepository(
private val reader: PreferenceReader private val reader: PreferenceReader
) { ) {
val allWLists: LiveData<MutableList<WList>> by lazy{ val allWLists: LiveData<MutableList<WList>> by lazy {
dao.allWList dao.allWList
} }
@ -50,8 +50,8 @@ class WListRepository(
} }
private 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) {
logNetworkError("${response.code()} ${response.message()}") logNetworkError("${response.code()} ${response.message()}")
return return
@ -64,10 +64,13 @@ class WListRepository(
removeOldWListsFromDb(wLists) removeOldWListsFromDb(wLists)
} }
fun deleteWList(idBoard: String, idWList:String) { fun deleteWList(idBoard: String, idWList: String) {
service.deleteList(idBoard, idWList).enqueue( service.deleteList(idBoard, idWList).enqueue(
object : Callback<it.unisannio.ding.ids.wedroid.wrapper.entity.WList> { 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) { override fun onFailure(
call: Call<it.unisannio.ding.ids.wedroid.wrapper.entity.WList>,
t: Throwable
) {
logNetworkError(t.message) logNetworkError(t.message)
} }
@ -76,21 +79,21 @@ class WListRepository(
response: Response<it.unisannio.ding.ids.wedroid.wrapper.entity.WList> response: Response<it.unisannio.ding.ids.wedroid.wrapper.entity.WList>
) { ) {
CoroutineScope(Dispatchers.IO).launch { CoroutineScope(Dispatchers.IO).launch {
deleteWListCallBack(response,idWList) deleteWListCallBack(response, idWList)
} }
} }
}) })
} }
private fun deleteWListCallBack(response: Response<it.unisannio.ding.ids.wedroid.wrapper.entity.WList>, private fun deleteWListCallBack(
id: String) { response: Response<it.unisannio.ding.ids.wedroid.wrapper.entity.WList>,
id: String
) {
if (!response.isSuccessful) { if (!response.isSuccessful) {
logNetworkError("${response.code()} ${response.message()}") logNetworkError("${response.code()} ${response.message()}")
return return
} }
dao.delete(WList(id)) dao.delete(WList(id))
} }
private fun addNewWListToDb(wLists: Collection<WList>) { private fun addNewWListToDb(wLists: Collection<WList>) {
@ -99,7 +102,6 @@ class WListRepository(
} }
} }
private fun removeOldWListsFromDb(wLists: Collection<WList>) { private fun removeOldWListsFromDb(wLists: Collection<WList>) {
allWLists.value?.minus(wLists) allWLists.value?.minus(wLists)
?.forEach { ?.forEach {

View File

@ -2,7 +2,10 @@ package it.unisannio.ding.ids.wedroid.app.util;
public interface PreferenceReader { public interface PreferenceReader {
String getBaseUrl(); String getBaseUrl();
String getUserId(); String getUserId();
String getToken(); String getToken();
String getBoardId(); String getBoardId();
} }

View File

@ -2,7 +2,10 @@ package it.unisannio.ding.ids.wedroid.app.util;
public interface PreferenceWriter { public interface PreferenceWriter {
void setBaseUrl(String baseUrl); void setBaseUrl(String baseUrl);
void setUserId(String userId); void setUserId(String userId);
void setToken(String token); void setToken(String token);
void setBoardId(String boardId); void setBoardId(String boardId);
} }

View File

@ -1,6 +1,12 @@
package it.unisannio.ding.ids.wedroid.app.util package it.unisannio.ding.ids.wedroid.app.util
import it.unisannio.ding.ids.wedroid.wrapper.api.* 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 okhttp3.OkHttpClient import okhttp3.OkHttpClient
import retrofit2.Retrofit import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory import retrofit2.converter.gson.GsonConverterFactory

View File

@ -2,7 +2,7 @@ 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? {
@ -20,7 +20,6 @@ class SharedPreferenceHelper(context : Context) : PreferenceReader, PreferenceWr
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?) {

View File

@ -15,6 +15,7 @@ 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 androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.util.ArrayList; import java.util.ArrayList;
@ -56,7 +57,7 @@ public class BoardViewActivity extends AppCompatActivity {
swipeRefreshLayout.setRefreshing(false); swipeRefreshLayout.setRefreshing(false);
Intent i = getIntent(); Intent i = getIntent();
idBoard= i.getStringExtra("idBoard"); idBoard = i.getStringExtra("idBoard");
getListsButton = findViewById(R.id.getLists); getListsButton = findViewById(R.id.getLists);
Review

I think it would be better to group all these findViewById in one function to make the code more readable.

I think it would be better to group all these `findViewById` in one function to make the code more readable.
Review

ok, I review it

ok, I review it
description = findViewById(R.id.descriptionTxt); description = findViewById(R.id.descriptionTxt);
@ -66,7 +67,7 @@ public class BoardViewActivity extends AppCompatActivity {
lastModificationDate = findViewById(R.id.modifiedDate); lastModificationDate = findViewById(R.id.modifiedDate);
divider1 = findViewById(R.id.divider1); divider1 = findViewById(R.id.divider1);
divider2 = findViewById(R.id.divider2); divider2 = findViewById(R.id.divider2);
divider3= findViewById(R.id.divider3); divider3 = findViewById(R.id.divider3);
listView = findViewById(R.id.listViewID); listView = findViewById(R.id.listViewID);
sp = new SharedPreferenceHelper(this); sp = new SharedPreferenceHelper(this);
@ -101,7 +102,7 @@ public class BoardViewActivity extends AppCompatActivity {
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; assert response.body() != null;
board = response.body(); board = response.body();
if (board.getId()==null) { if (board.getId() == null) {
Toast.makeText( Toast.makeText(
getApplicationContext(), getApplicationContext(),
getApplicationContext().getString(R.string.board_deleted), getApplicationContext().getString(R.string.board_deleted),
@ -149,8 +150,9 @@ public class BoardViewActivity extends AppCompatActivity {
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) {
Toast.makeText(getApplicationContext(), Toast.makeText(getApplicationContext(),
getApplicationContext().getString(R.string.board_deleted), getApplicationContext().getString(R.string.board_deleted),
Toast.LENGTH_LONG).show(); Toast.LENGTH_LONG).show();
@ -158,48 +160,37 @@ public class BoardViewActivity extends AppCompatActivity {
}); });
} }
private String encodeColor(String color){ private String encodeColor(String color) {
String encodedColor; String encodedColor;
if(color.equalsIgnoreCase("belize")){ if (color.equalsIgnoreCase("belize")) {
encodedColor="#2980B9"; encodedColor = "#2980B9";
} } else if (color.equalsIgnoreCase("nephritis")) {
else if(color.equalsIgnoreCase("nephritis")){ encodedColor = "#27AE60";
encodedColor="#27AE60"; } else if (color.equalsIgnoreCase("pomegranate")) {
} encodedColor = "#C0392B";
else if(color.equalsIgnoreCase("pomegranate")){ } else if (color.equalsIgnoreCase("pumpkin")) {
encodedColor="#C0392B"; encodedColor = "#E67E22";
} } else if (color.equalsIgnoreCase("wisteria")) {
else if(color.equalsIgnoreCase("pumpkin")){ encodedColor = "#8E44AD";
encodedColor="#E67E22"; } else if (color.equalsIgnoreCase("moderatepink")) {
} encodedColor = "#CD5A91";
else if(color.equalsIgnoreCase("wisteria")){ } else if (color.equalsIgnoreCase("strongcyan")) {
encodedColor="#8E44AD"; encodedColor = "#00AECC";
} } else if (color.equalsIgnoreCase("dark")) {
else if(color.equalsIgnoreCase("moderatepink")){ encodedColor = "#2C3E51";
encodedColor="#CD5A91"; } else if (color.equalsIgnoreCase("midnight")) {
} encodedColor = "#2C3E50";
else if(color.equalsIgnoreCase("strongcyan")){ } else if (color.equalsIgnoreCase("relax")) {
encodedColor="#00AECC"; encodedColor = "#27AE61";
} } else if (color.equalsIgnoreCase("corteza")) {
else if(color.equalsIgnoreCase("dark")){ encodedColor = "#568BA2";
encodedColor="#2C3E51"; } else
}
else if(color.equalsIgnoreCase("midnight")){
encodedColor="#2C3E50";
}
else if(color.equalsIgnoreCase("relax")){
encodedColor="#27AE61";
}
else if(color.equalsIgnoreCase("corteza")){
encodedColor="#568BA2";
}
else
encodedColor = "#38DF87"; encodedColor = "#38DF87";
return encodedColor; return encodedColor;
} }
private void replaceIDUserToUsername(String idUser){ private void replaceIDUserToUsername(String idUser) {
service = new ServicesFactory(sp); service = new ServicesFactory(sp);
service.getUserService().getUser(idUser).enqueue(new Callback<User>() { service.getUserService().getUser(idUser).enqueue(new Callback<User>() {
@Override @Override
@ -207,10 +198,9 @@ public class BoardViewActivity extends AppCompatActivity {
User u = response.body(); User u = response.body();
assert u != null; assert u != null;
username = u.getUsername(); username = u.getUsername();
if(u.isAdmin()){ if (u.isAdmin()) {
members.append("Admin: " + username + ";\n"); members.append("Admin: " + username + ";\n");
} } else
else
members.append("Other member: " + username + ";\n"); members.append("Other member: " + username + ";\n");
} }

View File

@ -42,7 +42,7 @@ class LoginActivity : AppCompatActivity() {
val passwordText = password.text.toString() val passwordText = password.text.toString()
val instanceServerText = instanceServer.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) Toast.makeText(this, R.string.login_unformed_instance, Toast.LENGTH_LONG)
.show() .show()
return return

View File

@ -23,7 +23,7 @@ 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.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;
@ -50,7 +50,7 @@ public class WListsListActivity extends AppCompatActivity {
String boardTitle = i.getStringExtra("barTitle"); String boardTitle = i.getStringExtra("barTitle");
Objects.requireNonNull(getSupportActionBar()).setTitle(boardTitle); Objects.requireNonNull(getSupportActionBar()).setTitle(boardTitle);
barColor = i.getIntExtra("barColor", 0); barColor = i.getIntExtra("barColor", 0);
setResult(WListsListActivity.RESULT_OK,i); setResult(WListsListActivity.RESULT_OK, i);
myToolbar.setBackgroundColor(barColor); myToolbar.setBackgroundColor(barColor);

View File

@ -42,7 +42,6 @@ class BoardsListAdapter internal constructor(
val intent = Intent(holder.itemView.context, BoardViewActivity::class.java) val intent = Intent(holder.itemView.context, BoardViewActivity::class.java)
intent.putExtra("idBoard", board.id) intent.putExtra("idBoard", board.id)
holder.itemView.context.startActivity(intent) holder.itemView.context.startActivity(intent)
} }
} }

View File

@ -40,20 +40,21 @@ public class WListsAdapter extends RecyclerView.Adapter<WListsAdapter.WListViewH
private ServicesFactory service; private ServicesFactory service;
private SharedPreferenceHelper sp; private SharedPreferenceHelper sp;
public WListsAdapter(Context context){ public WListsAdapter(Context context) {
mInflater = LayoutInflater.from(context); mInflater = LayoutInflater.from(context);
mContext=context; mContext = context;
sp = new SharedPreferenceHelper(mContext); sp = new SharedPreferenceHelper(mContext);
service = new ServicesFactory(sp); service = new ServicesFactory(sp);
} }
class WListViewHolder extends RecyclerView.ViewHolder{ class WListViewHolder extends RecyclerView.ViewHolder {
private final TextView wListItemView; private final TextView wListItemView;
ListView listView; ListView listView;
Button button; Button button;
private WListViewHolder(View itemView){
private WListViewHolder(View itemView) {
super(itemView); super(itemView);
wListItemView= itemView.findViewById(R.id.wListTitle); wListItemView = itemView.findViewById(R.id.wListTitle);
listView = itemView.findViewById(R.id.listViewCard); listView = itemView.findViewById(R.id.listViewCard);
button = itemView.findViewById(R.id.buttonAddCard); button = itemView.findViewById(R.id.buttonAddCard);
} }
@ -77,7 +78,7 @@ public class WListsAdapter extends RecyclerView.Adapter<WListsAdapter.WListViewH
@Override @Override
public void onResponse(@NotNull Call<List<Card>> call, @NotNull Response<List<Card>> response) { public void onResponse(@NotNull Call<List<Card>> call, @NotNull Response<List<Card>> response) {
assert response.body() != null; assert response.body() != null;
for(int i = 0; i<response.body().size(); i++){ for (int i = 0; i < response.body().size(); i++) {
cardTitle.add(response.body().get(i).getTitle()); cardTitle.add(response.body().get(i).getTitle());
} }
ArrayAdapter<String> adapter = new ArrayAdapter<>(mContext, ArrayAdapter<String> adapter = new ArrayAdapter<>(mContext,
@ -92,6 +93,7 @@ public class WListsAdapter extends RecyclerView.Adapter<WListsAdapter.WListViewH
} }
}); });
} }
@Override @Override
public void onFailure(@NotNull Call<List<Card>> call, @NotNull Throwable t) { public void onFailure(@NotNull Call<List<Card>> call, @NotNull Throwable t) {
} }
@ -112,7 +114,7 @@ public class WListsAdapter extends RecyclerView.Adapter<WListsAdapter.WListViewH
else return 0; else return 0;
} }
public void setWLists(List<WList> wList){ public void setWLists(List<WList> wList) {
mWLists = wList; mWLists = wList;
notifyDataSetChanged(); notifyDataSetChanged();
} }
@ -130,7 +132,7 @@ public class WListsAdapter extends RecyclerView.Adapter<WListsAdapter.WListViewH
.setPositiveButton("OK", new DialogInterface.OnClickListener() { .setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) { public void onClick(DialogInterface dialog, int id) {
if(!editText.getText().toString().matches("")) { if (!editText.getText().toString().matches("")) {
service.getSwimlanesService().getAllSwimlanes(sp.getBoardId()) service.getSwimlanesService().getAllSwimlanes(sp.getBoardId())
.enqueue(new Callback<List<Swimlane>>() { .enqueue(new Callback<List<Swimlane>>() {
@Override @Override
@ -138,9 +140,9 @@ public class WListsAdapter extends RecyclerView.Adapter<WListsAdapter.WListViewH
@NotNull Response<List<Swimlane>> response) { @NotNull Response<List<Swimlane>> response) {
String idDefaultSwimlane = null; String idDefaultSwimlane = null;
assert response.body() != null; assert response.body() != null;
for(Swimlane swim: response.body()){ for (Swimlane swim : response.body()) {
if(swim.getTitle().equalsIgnoreCase("default")) if (swim.getTitle().equalsIgnoreCase("default"))
idDefaultSwimlane=swim.getTitle(); idDefaultSwimlane = swim.getTitle();
} }
final Card card = new Card(); final Card card = new Card();
card.setTitle(editText.getText().toString()); card.setTitle(editText.getText().toString());
@ -153,14 +155,15 @@ public class WListsAdapter extends RecyclerView.Adapter<WListsAdapter.WListViewH
service.getCardService().newCard(sp.getBoardId(), current, card).enqueue(new Callback<Card>() { service.getCardService().newCard(sp.getBoardId(), current, card).enqueue(new Callback<Card>() {
@Override @Override
public void onResponse(@NotNull Call<Card> call, @NotNull Response<Card> response){ public void onResponse(@NotNull Call<Card> call, @NotNull Response<Card> response) {
if(response.isSuccessful()) if (response.isSuccessful())
Toast.makeText(mContext, "card posted" , Toast.makeText(mContext, "card posted",
Toast.LENGTH_LONG).show(); Toast.LENGTH_LONG).show();
else else
Toast.makeText(mContext, "card doesn't posted" , Toast.makeText(mContext, "card doesn't posted",
Toast.LENGTH_LONG).show(); Toast.LENGTH_LONG).show();
} }
@Override @Override
public void onFailure(@NotNull Call<Card> call, @NotNull Throwable t) { public void onFailure(@NotNull Call<Card> call, @NotNull Throwable t) {
@ -180,8 +183,7 @@ public class WListsAdapter extends RecyclerView.Adapter<WListsAdapter.WListViewH
} }
}); });
} } else
else
Toast.makeText(mContext, "cancel", Toast.LENGTH_LONG).show(); Toast.makeText(mContext, "cancel", Toast.LENGTH_LONG).show();
} }
}) })

View File

@ -1,4 +1,4 @@
package it.unisannio.ding.ids.wedroid.app.viewmodel; package it.unisannio.ding.ids.wedroid.app.viewModel;
import android.app.Application; import android.app.Application;
@ -30,7 +30,7 @@ public class WListsListViewModel extends AndroidViewModel {
allWLists = wListRepository.getAllWLists(); allWLists = wListRepository.getAllWLists();
} }
public LiveData<List<WList>> getAllWLists(){ public LiveData<List<WList>> getAllWLists() {
return allWLists; return allWLists;
} }

View File

@ -1,12 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android"> <selector xmlns:android="http://schemas.android.com/apk/res/android">
<shape <shape android:shape="rectangle">
android:shape="rectangle" > <solid android:color="@color/colorAccent"></solid>
<solid <corners android:radius="11dp"></corners>
android:color="@color/colorAccent" >
</solid>
<corners
android:radius="11dp" >
</corners>
</shape> </shape>
</selector> </selector>

View File

@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"> android:layout_height="wrap_content"
android:orientation="vertical">
<TextView <TextView
android:id="@+id/wListTitle" android:id="@+id/wListTitle"
@ -17,8 +17,7 @@
<ListView <ListView
android:id="@+id/listViewCard" android:id="@+id/listViewCard"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" > android:layout_height="match_parent" />
</ListView>
<Button <Button
android:id="@+id/buttonAddCard" android:id="@+id/buttonAddCard"