added swipe to remove
added remove on removebutton-click added fancy remove animation :)
This commit is contained in:
parent
3e6165f638
commit
746ec62e2f
@ -12,7 +12,6 @@ import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.ListView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
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.MainActivity;
|
||||
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 {
|
||||
|
||||
@ -98,6 +102,7 @@ public class FlurFragment extends Fragment implements AddButtonDialogSingle.AddB
|
||||
|
||||
@Override
|
||||
public void onSwiped(@NonNull @NotNull RecyclerView.ViewHolder viewHolder, int direction) {
|
||||
listAdapter.remove(viewHolder.getAdapterPosition());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -107,7 +112,8 @@ public class FlurFragment extends Fragment implements AddButtonDialogSingle.AddB
|
||||
|
||||
@Override
|
||||
public boolean isItemViewSwipeEnabled() {
|
||||
return false;
|
||||
return true;
|
||||
|
||||
}
|
||||
});
|
||||
h.attachToRecyclerView(listView);
|
||||
@ -140,7 +146,7 @@ public class FlurFragment extends Fragment implements AddButtonDialogSingle.AddB
|
||||
openDialog3();
|
||||
} else if (i == 3) {
|
||||
listAdapter.add(new ListItemSpace(3));
|
||||
listAdapter.notifyDataSetChanged();
|
||||
|
||||
}
|
||||
|
||||
dialogInterface.dismiss();
|
||||
@ -176,20 +182,20 @@ public class FlurFragment extends Fragment implements AddButtonDialogSingle.AddB
|
||||
public void applyTextsSingle(String name, String command, String button) {
|
||||
//items.add(new ListItemSingle(0,name,command,button));
|
||||
listAdapter.add(new ListItemSingle(list_item_type,name,command,button));
|
||||
listAdapter.notifyDataSetChanged();
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
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.notifyDataSetChanged();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyTextsHeadline(String headline) {
|
||||
listAdapter.add(new ListItemHeadline(list_item_type,headline));
|
||||
listAdapter.notifyDataSetChanged();
|
||||
|
||||
|
||||
}
|
||||
}
|
@ -1,12 +1,11 @@
|
||||
package de.jg_cody.Teraplex.ui.rooms;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.Button;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
@ -31,7 +30,6 @@ public class ListAdapter extends RecyclerView.Adapter<ListAdapter.ListItemViewHo
|
||||
private ArrayList<ListItem> objects;
|
||||
|
||||
public ListAdapter(Context context, ArrayList<ListItem> objects) {
|
||||
//super(context, resource, objects);
|
||||
this.context = context;
|
||||
this.inflater = LayoutInflater.from(context);
|
||||
this.objects = objects;
|
||||
@ -60,6 +58,18 @@ public class ListAdapter extends RecyclerView.Adapter<ListAdapter.ListItemViewHo
|
||||
|
||||
public void add(ListItem 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) {
|
||||
@ -92,6 +102,13 @@ public class ListAdapter extends RecyclerView.Adapter<ListAdapter.ListItemViewHo
|
||||
|
||||
public void bindView(View view, ListItem item) {
|
||||
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()) {
|
||||
case SINGLEBUTTON:
|
||||
{
|
||||
|
@ -20,7 +20,7 @@
|
||||
app:backgroundTint="@null" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/image_remove3"
|
||||
android:id="@+id/image_remove"
|
||||
android:layout_width="40dp"
|
||||
android:layout_height="40dp"
|
||||
android:layout_gravity="center"
|
||||
|
@ -12,7 +12,7 @@
|
||||
android:layout_weight="1" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/image_remove2"
|
||||
android:id="@+id/image_remove"
|
||||
android:layout_width="40dp"
|
||||
android:layout_height="40dp"
|
||||
android:layout_gravity="center"
|
||||
|
Loading…
Reference in New Issue
Block a user