feature_board_view #28
@ -61,6 +61,35 @@ class WListRepository(
|
|||||||
removeOldWListsFromDb(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 suspend fun addNewWListToDb(wLists: Collection<WList>) {
|
private suspend fun addNewWListToDb(wLists: Collection<WList>) {
|
||||||
wLists.forEach {
|
wLists.forEach {
|
||||||
dao.insert(it)
|
dao.insert(it)
|
||||||
|
@ -9,6 +9,7 @@ import android.widget.ArrayAdapter;
|
|||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
@ -30,16 +31,18 @@ import retrofit2.Response;
|
|||||||
|
|
||||||
public class BoardViewActivity extends AppCompatActivity {
|
public class BoardViewActivity extends AppCompatActivity {
|
||||||
|
|
||||||
String idBoard, username, boardTitle;
|
static final int WLISTS_REQUEST = 30;
|
||||||
int boardColor;
|
|
||||||
TextView description, members, permission, creationDate, lastModificationDate;
|
private String idBoard, username, boardTitle;
|
||||||
View divider1, divider2, divider3;
|
private int boardColor;
|
||||||
ListView listView;
|
private TextView description, members, permission, creationDate, lastModificationDate;
|
||||||
Button getListsButton;
|
private View divider1, divider2, divider3;
|
||||||
SharedPreferenceHelper sp;
|
private ListView listView;
|
||||||
ServicesFactory service;
|
private Button getListsButton;
|
||||||
Toolbar myToolbar;
|
private SharedPreferenceHelper sp;
|
||||||
Board board;
|
private ServicesFactory service;
|
||||||
|
private Toolbar myToolbar;
|
||||||
|
private Board board;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||||
@ -50,6 +53,7 @@ public class BoardViewActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
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);
|
||||||
members = findViewById(R.id.membersTxt);
|
members = findViewById(R.id.membersTxt);
|
||||||
@ -66,7 +70,6 @@ public class BoardViewActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
initializeUI(idBoard);
|
initializeUI(idBoard);
|
||||||
|
|
||||||
|
|
||||||
getListsButton.setOnClickListener(new View.OnClickListener() {
|
getListsButton.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
@ -74,7 +77,7 @@ public class BoardViewActivity extends AppCompatActivity {
|
|||||||
i.putExtra("idBoard", idBoard);
|
i.putExtra("idBoard", idBoard);
|
||||||
i.putExtra("barTitle", boardTitle);
|
i.putExtra("barTitle", boardTitle);
|
||||||
i.putExtra("barColor", boardColor);
|
i.putExtra("barColor", boardColor);
|
||||||
startActivity(i);
|
startActivityForResult(i, WLISTS_REQUEST);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -112,7 +115,6 @@ public class BoardViewActivity extends AppCompatActivity {
|
|||||||
divider2.setBackgroundColor(boardColor);
|
divider2.setBackgroundColor(boardColor);
|
||||||
divider3.setBackgroundColor(boardColor);
|
divider3.setBackgroundColor(boardColor);
|
||||||
|
|
||||||
|
|
||||||
ArrayList<String> labelsTitle = new ArrayList<>();
|
ArrayList<String> labelsTitle = new ArrayList<>();
|
||||||
for (int i=0; i<board.getLabels().size(); i++){
|
for (int i=0; i<board.getLabels().size(); i++){
|
||||||
labelsTitle.add(board.getLabels().get(i).getName());
|
labelsTitle.add(board.getLabels().get(i).getName());
|
||||||
@ -123,8 +125,7 @@ public class BoardViewActivity extends AppCompatActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFailure(Call<Board> call, Throwable t) {
|
public void onFailure(@NotNull Call<Board> call, @NotNull Throwable t) {
|
||||||
//boardTitle.setText(t.toString());
|
|
||||||
//TODO
|
//TODO
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -187,9 +188,20 @@ public class BoardViewActivity extends AppCompatActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFailure(Call<User> call, Throwable t) {
|
public void onFailure(@NotNull Call<User> call, @NotNull Throwable t) {
|
||||||
//TODO
|
//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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,7 @@
|
|||||||
package it.unisannio.ding.ids.wedroid.app.view;
|
package it.unisannio.ding.ids.wedroid.app.view;
|
||||||
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.graphics.drawable.Drawable;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.widget.Button;
|
|
||||||
|
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
@ -18,7 +16,6 @@ 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.data.entity.WList;
|
import it.unisannio.ding.ids.wedroid.app.data.entity.WList;
|
||||||
import it.unisannio.ding.ids.wedroid.app.util.PreferenceReader;
|
|
||||||
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;
|
import it.unisannio.ding.ids.wedroid.app.viewModel.WListsListViewModel;
|
||||||
@ -26,8 +23,10 @@ import it.unisannio.ding.ids.wedroid.app.viewModel.WListsListViewModel;
|
|||||||
public class WListsListActivity extends AppCompatActivity {
|
public class WListsListActivity extends AppCompatActivity {
|
||||||
|
|
||||||
Toolbar myToolbar;
|
Toolbar myToolbar;
|
||||||
String boardTitle;
|
|
||||||
int barColor;
|
int barColor;
|
||||||
|
WListsListViewModel viewModel;
|
||||||
|
RecyclerView recyclerView;
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||||
@ -35,24 +34,27 @@ public class WListsListActivity extends AppCompatActivity {
|
|||||||
setContentView(R.layout.activity_wlists_view);
|
setContentView(R.layout.activity_wlists_view);
|
||||||
myToolbar = findViewById(R.id.my_toolbar);
|
myToolbar = findViewById(R.id.my_toolbar);
|
||||||
setSupportActionBar(myToolbar);
|
setSupportActionBar(myToolbar);
|
||||||
Intent i = getIntent();
|
|
||||||
|
|
||||||
boardTitle = i.getStringExtra("barTitle");
|
Intent i = getIntent();
|
||||||
|
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);
|
||||||
|
|
||||||
myToolbar.setBackgroundColor(barColor);
|
myToolbar.setBackgroundColor(barColor);
|
||||||
|
|
||||||
PreferenceReader reader =new SharedPreferenceHelper(this);
|
recyclerView = findViewById(R.id.recyclerviewWList);
|
||||||
|
initializeUi();
|
||||||
|
}
|
||||||
|
|
||||||
RecyclerView recyclerView = findViewById(R.id.recyclerviewWList);
|
private void initializeUi() {
|
||||||
final WListsAdapter adapter = new WListsAdapter(this);
|
final WListsAdapter adapter = new WListsAdapter(this);
|
||||||
recyclerView.setAdapter(adapter);
|
recyclerView.setAdapter(adapter);
|
||||||
recyclerView.setLayoutManager(new LinearLayoutManager(this,
|
recyclerView.setLayoutManager(new LinearLayoutManager(this,
|
||||||
LinearLayoutManager.HORIZONTAL, false));
|
LinearLayoutManager.HORIZONTAL, false));
|
||||||
//linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
|
|
||||||
//recyclerView.setHasFixedSize(true);
|
//recyclerView.setHasFixedSize(true);
|
||||||
|
|
||||||
WListsListViewModel viewModel = new ViewModelProvider(this).get(WListsListViewModel.class);
|
viewModel = new ViewModelProvider(this).get(WListsListViewModel.class);
|
||||||
|
|
||||||
viewModel.getAllWLists().observe(this, new Observer<List<WList>>() {
|
viewModel.getAllWLists().observe(this, new Observer<List<WList>>() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -34,6 +34,13 @@ public class WListsListViewModel extends AndroidViewModel {
|
|||||||
return allWLists;
|
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() {
|
public void refresh() {
|
||||||
wListRepository.synchronize();
|
wListRepository.synchronize();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user