feature_board_view #28
@ -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
|
||||||
|
@ -19,7 +19,7 @@ public interface WListDao {
|
|||||||
LiveData<List<WList>> getAllWList();
|
LiveData<List<WList>> getAllWList();
|
||||||
|
|
||||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||||
void insert(WList wList);
|
void insert(WList wList);
|
||||||
|
|
||||||
@Delete
|
@Delete
|
||||||
void delete(WList wList);
|
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)
|
@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) {
|
||||||
|
@ -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) {
|
||||||
|
@ -151,7 +151,7 @@ class BoardRepository(
|
|||||||
private suspend fun removeOldBoardsFromDb(boards: Collection<Board>) {
|
private suspend fun removeOldBoardsFromDb(boards: Collection<Board>) {
|
||||||
allBoards.value?.minus(boards)
|
allBoards.value?.minus(boards)
|
||||||
?.forEach {
|
?.forEach {
|
||||||
dao.delete(it)
|
dao.delete(it)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -29,7 +29,7 @@ class WListRepository(
|
|||||||
synchronize()
|
synchronize()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun synchronize() {
|
fun synchronize() {
|
||||||
service.getAllList(reader.boardId)
|
service.getAllList(reader.boardId)
|
||||||
.enqueue(object :
|
.enqueue(object :
|
||||||
Callback<MutableList<it.unisannio.ding.ids.wedroid.wrapper.entity.WList>> {
|
Callback<MutableList<it.unisannio.ding.ids.wedroid.wrapper.entity.WList>> {
|
||||||
@ -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 {
|
||||||
|
@ -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();
|
||||||
}
|
}
|
||||||
|
@ -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);
|
||||||
}
|
}
|
||||||
|
@ -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
|
||||||
|
@ -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,8 +20,7 @@ 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?) {
|
||||||
val editor = sp.edit()
|
val editor = sp.edit()
|
||||||
|
@ -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;
|
||||||
@ -38,7 +39,7 @@ public class BoardViewActivity extends AppCompatActivity {
|
|||||||
private TextView description, members, permission, creationDate, lastModificationDate;
|
private TextView description, members, permission, creationDate, lastModificationDate;
|
||||||
private View divider1, divider2, divider3;
|
private View divider1, divider2, divider3;
|
||||||
private ListView listView;
|
private ListView listView;
|
||||||
private Button getListsButton;
|
private Button getListsButton;
|
||||||
private SharedPreferenceHelper sp;
|
private SharedPreferenceHelper sp;
|
||||||
private ServicesFactory service;
|
private ServicesFactory service;
|
||||||
private Toolbar myToolbar;
|
private Toolbar myToolbar;
|
||||||
@ -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);
|
||||||
|
|||||||
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),
|
||||||
@ -134,7 +135,7 @@ public class BoardViewActivity extends AppCompatActivity {
|
|||||||
+ board.getCreatedAt());
|
+ board.getCreatedAt());
|
||||||
lastModificationDate.setText(R.string.modified_at);
|
lastModificationDate.setText(R.string.modified_at);
|
||||||
lastModificationDate.append("\n"
|
lastModificationDate.append("\n"
|
||||||
+ board.getModifiedAt());
|
+ board.getModifiedAt());
|
||||||
|
|
||||||
divider1.setBackgroundColor(boardColor);
|
divider1.setBackgroundColor(boardColor);
|
||||||
divider2.setBackgroundColor(boardColor);
|
divider2.setBackgroundColor(boardColor);
|
||||||
@ -149,57 +150,47 @@ public class BoardViewActivity extends AppCompatActivity {
|
|||||||
listView.setAdapter(adapter);
|
listView.setAdapter(adapter);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@Override
|
|
||||||
public void onFailure (@NotNull Call < Board > call, @NotNull Throwable t){
|
@Override
|
||||||
Toast.makeText(getApplicationContext(),
|
public void onFailure(@NotNull Call<Board> call, @NotNull Throwable t) {
|
||||||
getApplicationContext().getString(R.string.board_deleted),
|
Toast.makeText(getApplicationContext(),
|
||||||
Toast.LENGTH_LONG).show();
|
getApplicationContext().getString(R.string.board_deleted),
|
||||||
}
|
Toast.LENGTH_LONG).show();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
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");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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
|
||||||
|
@ -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);
|
||||||
|
|
||||||
|
@ -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)
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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);
|
||||||
}
|
}
|
||||||
@ -74,28 +75,29 @@ public class WListsAdapter extends RecyclerView.Adapter<WListsAdapter.WListViewH
|
|||||||
final List<String> cardTitle = new ArrayList<>();
|
final List<String> cardTitle = new ArrayList<>();
|
||||||
service.getCardService().getAllCards(sp.getBoardId(), current.getId()).enqueue(
|
service.getCardService().getAllCards(sp.getBoardId(), current.getId()).enqueue(
|
||||||
new Callback<List<Card>>() {
|
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
|
@Override
|
||||||
public void onClick(View view) {
|
public void onResponse(@NotNull Call<List<Card>> call, @NotNull Response<List<Card>> response) {
|
||||||
showInputDialog(current.getId());
|
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) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public void onFailure(@NotNull Call<List<Card>> call, @NotNull Throwable t) {
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
/*position of the old content holder**/
|
/*position of the old content holder**/
|
||||||
|
|
||||||
@ -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();
|
||||||
}
|
}
|
||||||
@ -124,64 +126,64 @@ public class WListsAdapter extends RecyclerView.Adapter<WListsAdapter.WListViewH
|
|||||||
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(mContext);
|
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(mContext);
|
||||||
alertDialogBuilder.setView(promptView);
|
alertDialogBuilder.setView(promptView);
|
||||||
|
|
||||||
final EditText editText = promptView.findViewById(R.id.edittext);
|
final EditText editText = promptView.findViewById(R.id.edittext);
|
||||||
// setup a dialog window
|
// setup a dialog window
|
||||||
alertDialogBuilder.setCancelable(false)
|
alertDialogBuilder.setCancelable(false)
|
||||||
.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
|
|
||||||
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
|
@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) {
|
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>() {
|
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
|
||||||
|
public void onFailure(@NotNull Call<Card> call, @NotNull Throwable t) {
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFailure(@NotNull Call<Card> call, @NotNull Throwable t) {
|
public void onFailure(@NotNull Call<it.unisannio.ding.ids.wedroid.wrapper.entity.WList> call, @NotNull Throwable t) {
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFailure(@NotNull Call<it.unisannio.ding.ids.wedroid.wrapper.entity.WList> call, @NotNull Throwable t) {
|
public void onFailure(@NotNull Call<List<Swimlane>> call, @NotNull Throwable t) {
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
} else
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onFailure(@NotNull Call<List<Swimlane>> call, @NotNull Throwable t) {
|
|
||||||
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
else
|
|
||||||
Toast.makeText(mContext, "cancel", Toast.LENGTH_LONG).show();
|
Toast.makeText(mContext, "cancel", Toast.LENGTH_LONG).show();
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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>
|
@ -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"
|
||||||
|
Loading…
Reference in New Issue
Block a user
I think it would be better to group all these
findViewById
in one function to make the code more readable.ok, I review it