added swipe to remove

added remove on removebutton-click
added fancy remove animation :)
This commit is contained in:
JG-Cody 2021-06-28 22:02:38 +02:00
parent 3e6165f638
commit 746ec62e2f
4 changed files with 35 additions and 12 deletions

View File

@ -12,7 +12,6 @@ import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.ListView;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi; import androidx.annotation.RequiresApi;
@ -36,7 +35,12 @@ import de.jg_cody.Teraplex.AddHeadlineDialog;
import de.jg_cody.Teraplex.Cricketer; import de.jg_cody.Teraplex.Cricketer;
import de.jg_cody.Teraplex.MainActivity; import de.jg_cody.Teraplex.MainActivity;
import de.jg_cody.Teraplex.R; import de.jg_cody.Teraplex.R;
import de.jg_cody.Teraplex.ui.rooms.*; import de.jg_cody.Teraplex.ui.rooms.ListAdapter;
import de.jg_cody.Teraplex.ui.rooms.ListItem;
import de.jg_cody.Teraplex.ui.rooms.ListItemDouble;
import de.jg_cody.Teraplex.ui.rooms.ListItemHeadline;
import de.jg_cody.Teraplex.ui.rooms.ListItemSingle;
import de.jg_cody.Teraplex.ui.rooms.ListItemSpace;
public class FlurFragment extends Fragment implements AddButtonDialogSingle.AddButtonDialogListenerSingle, AddButtonsDialogDouble.AddButtonsDialogListenerDouble, AddHeadlineDialog.AddHeadlineDialogListener { public class FlurFragment extends Fragment implements AddButtonDialogSingle.AddButtonDialogListenerSingle, AddButtonsDialogDouble.AddButtonsDialogListenerDouble, AddHeadlineDialog.AddHeadlineDialogListener {
@ -98,6 +102,7 @@ public class FlurFragment extends Fragment implements AddButtonDialogSingle.AddB
@Override @Override
public void onSwiped(@NonNull @NotNull RecyclerView.ViewHolder viewHolder, int direction) { public void onSwiped(@NonNull @NotNull RecyclerView.ViewHolder viewHolder, int direction) {
listAdapter.remove(viewHolder.getAdapterPosition());
} }
@Override @Override
@ -107,7 +112,8 @@ public class FlurFragment extends Fragment implements AddButtonDialogSingle.AddB
@Override @Override
public boolean isItemViewSwipeEnabled() { public boolean isItemViewSwipeEnabled() {
return false; return true;
} }
}); });
h.attachToRecyclerView(listView); h.attachToRecyclerView(listView);
@ -140,7 +146,7 @@ public class FlurFragment extends Fragment implements AddButtonDialogSingle.AddB
openDialog3(); openDialog3();
} else if (i == 3) { } else if (i == 3) {
listAdapter.add(new ListItemSpace(3)); listAdapter.add(new ListItemSpace(3));
listAdapter.notifyDataSetChanged();
} }
dialogInterface.dismiss(); dialogInterface.dismiss();
@ -176,20 +182,20 @@ public class FlurFragment extends Fragment implements AddButtonDialogSingle.AddB
public void applyTextsSingle(String name, String command, String button) { public void applyTextsSingle(String name, String command, String button) {
//items.add(new ListItemSingle(0,name,command,button)); //items.add(new ListItemSingle(0,name,command,button));
listAdapter.add(new ListItemSingle(list_item_type,name,command,button)); listAdapter.add(new ListItemSingle(list_item_type,name,command,button));
listAdapter.notifyDataSetChanged();
} }
@Override @Override
public void applyTextsDouble(String name, String command1, String command2, String button1, String button2) { public void applyTextsDouble(String name, String command1, String command2, String button1, String button2) {
listAdapter.add(new ListItemDouble(list_item_type,name, command1, command2, button1, button2)); listAdapter.add(new ListItemDouble(list_item_type,name, command1, command2, button1, button2));
listAdapter.notifyDataSetChanged();
} }
@Override @Override
public void applyTextsHeadline(String headline) { public void applyTextsHeadline(String headline) {
listAdapter.add(new ListItemHeadline(list_item_type,headline)); listAdapter.add(new ListItemHeadline(list_item_type,headline));
listAdapter.notifyDataSetChanged();
} }
} }

View File

@ -1,12 +1,11 @@
package de.jg_cody.Teraplex.ui.rooms; package de.jg_cody.Teraplex.ui.rooms;
import android.annotation.SuppressLint;
import android.content.Context; import android.content.Context;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button; import android.widget.Button;
import android.widget.ImageView;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
@ -31,7 +30,6 @@ public class ListAdapter extends RecyclerView.Adapter<ListAdapter.ListItemViewHo
private ArrayList<ListItem> objects; private ArrayList<ListItem> objects;
public ListAdapter(Context context, ArrayList<ListItem> objects) { public ListAdapter(Context context, ArrayList<ListItem> objects) {
//super(context, resource, objects);
this.context = context; this.context = context;
this.inflater = LayoutInflater.from(context); this.inflater = LayoutInflater.from(context);
this.objects = objects; this.objects = objects;
@ -60,6 +58,18 @@ public class ListAdapter extends RecyclerView.Adapter<ListAdapter.ListItemViewHo
public void add(ListItem item) { public void add(ListItem item) {
objects.add(item); objects.add(item);
notifyDataSetChanged();
}
public void remove(ListItem item) {
int position = objects.indexOf(item);
objects.remove(item);
notifyItemRemoved(position);
}
public void remove(int position) {
objects.remove(position);
notifyItemRemoved(position);
} }
public void swap(int idx1, int idx2) { public void swap(int idx1, int idx2) {
@ -92,6 +102,13 @@ public class ListAdapter extends RecyclerView.Adapter<ListAdapter.ListItemViewHo
public void bindView(View view, ListItem item) { public void bindView(View view, ListItem item) {
String[] strings = item.getStrings(); String[] strings = item.getStrings();
ImageView Remove = view.findViewById(R.id.image_remove);
Remove.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
remove(item);
}
});
switch(item.getType()) { switch(item.getType()) {
case SINGLEBUTTON: case SINGLEBUTTON:
{ {

View File

@ -20,7 +20,7 @@
app:backgroundTint="@null" /> app:backgroundTint="@null" />
<ImageView <ImageView
android:id="@+id/image_remove3" android:id="@+id/image_remove"
android:layout_width="40dp" android:layout_width="40dp"
android:layout_height="40dp" android:layout_height="40dp"
android:layout_gravity="center" android:layout_gravity="center"

View File

@ -12,7 +12,7 @@
android:layout_weight="1" /> android:layout_weight="1" />
<ImageView <ImageView
android:id="@+id/image_remove2" android:id="@+id/image_remove"
android:layout_width="40dp" android:layout_width="40dp"
android:layout_height="40dp" android:layout_height="40dp"
android:layout_gravity="center" android:layout_gravity="center"