Add feature remove list
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Umberto Furno 2020-01-06 01:57:44 +01:00
parent fdd558a613
commit 9f9675f091
3 changed files with 85 additions and 17 deletions

View File

@ -1,16 +1,23 @@
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.content.res.ColorStateList;
import android.os.Bundle; import android.os.Bundle;
import android.view.View;
import android.widget.Toast;
import androidx.annotation.NonNull;
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.lifecycle.Observer; import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider; import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.ItemTouchHelper;
import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
@ -26,7 +33,8 @@ public class WListsListActivity extends AppCompatActivity {
int barColor; int barColor;
WListsListViewModel viewModel; WListsListViewModel viewModel;
RecyclerView recyclerView; RecyclerView recyclerView;
//SwipeRefreshLayout swipeRefreshLayout;
SharedPreferenceHelper sp;
@Override @Override
protected void onCreate(@Nullable Bundle savedInstanceState) { protected void onCreate(@Nullable Bundle savedInstanceState) {
@ -34,6 +42,8 @@ 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);
//swipeRefreshLayout = findViewById(R.id.pullToRefresh);
sp = new SharedPreferenceHelper(this);
Intent i = getIntent(); Intent i = getIntent();
String boardTitle = i.getStringExtra("barTitle"); String boardTitle = i.getStringExtra("barTitle");
@ -44,10 +54,19 @@ public class WListsListActivity extends AppCompatActivity {
myToolbar.setBackgroundColor(barColor); myToolbar.setBackgroundColor(barColor);
recyclerView = findViewById(R.id.recyclerviewWList); recyclerView = findViewById(R.id.recyclerviewWList);
initializeUi(); 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() { private void initializeUi(final String idBoard) {
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,
@ -62,5 +81,37 @@ public class WListsListActivity extends AppCompatActivity {
adapter.setWLists(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);
} }
} }

View File

@ -35,7 +35,7 @@ import retrofit2.Response;
public class WListsAdapter extends RecyclerView.Adapter<WListsAdapter.WListViewHolder> { public class WListsAdapter extends RecyclerView.Adapter<WListsAdapter.WListViewHolder> {
private final LayoutInflater mInflater; private final LayoutInflater mInflater;
private List<WList> mWLists; // Cached copy of words private List<WList> mWLists; // Cached copy of lists
private Context mContext; private Context mContext;
private ServicesFactory service; private ServicesFactory service;
private SharedPreferenceHelper sp; private SharedPreferenceHelper sp;
@ -119,7 +119,8 @@ public class WListsAdapter extends RecyclerView.Adapter<WListsAdapter.WListViewH
private void showInputDialog(final String current) { private void showInputDialog(final String current) {
LayoutInflater layoutInflater = LayoutInflater.from(mContext); LayoutInflater layoutInflater = LayoutInflater.from(mContext);
@SuppressLint("InflateParams") View promptView = layoutInflater.inflate(R.layout.alert_new_card, null); @SuppressLint("InflateParams") View promptView = layoutInflater.inflate(
R.layout.alert_new_card, null);
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(mContext); AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(mContext);
alertDialogBuilder.setView(promptView); alertDialogBuilder.setView(promptView);
@ -130,9 +131,11 @@ public class WListsAdapter extends RecyclerView.Adapter<WListsAdapter.WListViewH
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()).enqueue(new Callback<List<Swimlane>>() { service.getSwimlanesService().getAllSwimlanes(sp.getBoardId())
.enqueue(new Callback<List<Swimlane>>() {
@Override @Override
public void onResponse(@NotNull Call<List<Swimlane>> call, @NotNull Response<List<Swimlane>> response) { public void onResponse(@NotNull Call<List<Swimlane>> call,
@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()){
@ -155,7 +158,7 @@ public class WListsAdapter extends RecyclerView.Adapter<WListsAdapter.WListViewH
Toast.makeText(mContext, "card posted" , Toast.makeText(mContext, "card posted" ,
Toast.LENGTH_LONG).show(); Toast.LENGTH_LONG).show();
else else
Toast.makeText(mContext, "card unposted" , Toast.makeText(mContext, "card doesn't posted" ,
Toast.LENGTH_LONG).show(); Toast.LENGTH_LONG).show();
} }
@Override @Override

View File

@ -13,21 +13,35 @@
android:background="?attr/colorPrimary" android:background="?attr/colorPrimary"
android:elevation="4dp" android:elevation="4dp"
android:theme="@style/ThemeOverlay.AppCompat.ActionBar" android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" app:layout_constraintTop_toTopOf="parent"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" /> app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerviewWList"
android:layout_width="0dp" <androidx.recyclerview.widget.RecyclerView
android:layout_height="0dp" android:id="@+id/recyclerviewWList"
android:background="@android:color/white" 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_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent" app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/my_toolbar" app:srcCompat="@android:drawable/ic_popup_sync" />
tools:listitem="@layout/wlist_recyclerview_item" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>