У меня есть СoordinatorLayout
в который вложен appbarlayout. За ним располагается recyclerview, в котором реализовано удаление пунктов свайпами в право/лево.
Реализовано с помощью SwipeableRecyclerViewTouchListener.
И всё казалось бы отлично, если бы это не работало так плохо. Карточка из ресайкл удаляется если только провести от края до края экрана и очень аккуратно, в то же время, если создать отдельный layout и внести туда ресвью, работает всё отлично.
Осознание того, что проблема кроется в том, что свайпы не хотят дружить со скрывающимся эпбаром есть, но как эту проблему можно решить? Помогите, пожалуйста.
Сам фрагмент:
public class TimeList extends Fragment implements View.OnClickListener {
static private List<Double> time; //список со временем
private List<String> scr;
public List<Integer> numb;
private RecyclerView rv; // опредеяем ресайклевью
private RecyclerView.LayoutManager mLayoutManager; // не надо, но пусть будет
static RVAdapter adapter1;
static SQLHelper sqlHelper;
static SQLiteDatabase db;
//Button delete;
FloatingActionButton delete;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View w = inflater.inflate(R.layout.activity_list, container, false);
rv = (RecyclerView) w.findViewById(R.id.rv);
mLayoutManager = new LinearLayoutManager(getActivity());
rv.setLayoutManager(mLayoutManager);
rv.setHasFixedSize(true);
sqlHelper= new SQLHelper(getActivity());
db=sqlHelper.getWritableDatabase();
initializeData();
initializeAdapter();
delete = (FloatingActionButton) w.findViewById(R.id.delete);
delete.setOnClickListener(this);
SwipeableRecyclerViewTouchListener swipeTouchListener =
new SwipeableRecyclerViewTouchListener(rv,
new SwipeableRecyclerViewTouchListener.SwipeListener() {
@Override
public boolean canSwipe(int position) {
return true;
}
@Override
public boolean canSwipeLeft(int position) {
return true;
}
@Override
public boolean canSwipeRight(int position) {
return true;
}
@Override
public void onDismissedBySwipeLeft(RecyclerView
recyclerView, int[] reverseSortedPositions) {
for (int position : reverseSortedPositions) {
time.remove(position);
scr.remove(position);
adapter1.notifyItemRemoved(position);
}
adapter1.notifyDataSetChanged();
}
@Override
public void onDismissedBySwipeRight(RecyclerView
recyclerView, int[] reverseSortedPositions) {
for (int position : reverseSortedPositions) {
time.remove(position);
scr.remove(position);
adapter1.notifyItemRemoved(position);
}
adapter1.notifyDataSetChanged();
}
});
swipeTouchListener.setEnabled(true);
rv.addOnItemTouchListener(swipeTouchListener);
return w;
}
private void initializeData() {
/**
* инициализируем данные
*/
time = new ArrayList<>();
scr = new ArrayList<>();
numb = new ArrayList<>();
}
private void initializeAdapter() {
adapter1 = new RVAdapter(time, scr, numb);
rv.setAdapter(adapter1);
}
public static void addTime(double t, String scr) {
ContentValues contentValues = new ContentValues();
contentValues.put(FeedReaderContract.FeedEntry.COLUMN_NAME_TIME, t);
contentValues.put(FeedReaderContract.FeedEntry.COLUMN_NAME_SCRAMBLE, scr);
db.insert(FeedReaderContract.FeedEntry.TABLE_NAME, null, contentValues);
adapter1.add(t, scr);
}
@Override
public void onClick(View v) {
switch (v.getId()){
case R.id.delete:
int size = time.size();
time.clear();
scr.clear();
numb.clear();
adapter1.notifyItemRangeRemoved(0, size);
break;
}
}
static List<Double> getList() {
return time;
}
}
RecyclerView.Adapter:
public class RVAdapter extends
RecyclerView.Adapter<RVAdapter.TimeViewHolder> {
public static class TimeViewHolder extends RecyclerView.ViewHolder {
/**
* Класс, в котором определяем отдельные элементе в строке ресайклвью
* но это не точно
*/
CardView cv; //
public TextView ftime; // время в карточке
public TextView fdata; // дата сборки
public TextView fnumber;
public TimeViewHolder(View itemView) {
super(itemView);
cv = (CardView) itemView.findViewById(R.id.cv);
ftime = (TextView) itemView.findViewById(R.id.ftime);
fdata = (TextView) itemView.findViewById(R.id.fdata);
fnumber = (TextView) itemView.findViewById(R.id.fnumber);
}
}
List<Double> time; // список со временем
List<String> scramble;
List<Integer> numb;
int position = 0;
RVAdapter(List<Double> time1, List <String> scramble1,List<Integer> numb) {
/**
* конструктор
*/
this.time = time1;
this.scramble = scramble1;
this.numb = numb;
}
@Override
public void onAttachedToRecyclerView(RecyclerView recyclerView) {
super.onAttachedToRecyclerView(recyclerView);
}
@Override
public TimeViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
View v =
LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.item_card,
viewGroup, false);
TimeViewHolder pvh = new TimeViewHolder(v);
return pvh;
}
@Override
public void onBindViewHolder(TimeViewHolder timeViewHolder, int i) {
timeViewHolder.ftime.setText("" + time.get(i));
timeViewHolder.fdata.setText("" + scramble.get(i));
timeViewHolder.fnumber.setText("" + numb.get(i) +".");
}
public void add(double t, String s) {
time.add(0, t);
scramble.add(0, s);
numb.add(0, Timer.countOfSolves);
super.notifyDataSetChanged();
}
@Override
public int getItemCount() {
return time.size();
}
public void clear() {
time.remove(0);
scramble.remove(0);
notifyItemRemoved(0);
}
}
activity_list:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#EEEEEE"
android:fitsSystemWindows="true">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="300dp"
android:background="@drawable/img1"
android:fitsSystemWindows="true">
<android.support.design.widget.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:layout_scrollInterpolator=
"@android:anim/decelerate_interpolator"
app:toolbarId="@+id/toolbar">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"/>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="4dp"
android:background="#E0E0E0"
android:elevation="1dp"
app:layout_behavior="android.support.design.widget.AppBarLayout$ScrollingViewBehavior">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#EEEEEE"
android:elevation="1dp"
android:orientation="horizontal"
android:paddingBottom="50dp">
<android.support.v7.widget.RecyclerView
android:id="@+id/rv"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:background="@null">
</android.support.v7.widget.RecyclerView>
</RelativeLayout>
</android.support.v4.widget.NestedScrollView>
<android.support.design.widget.FloatingActionButton
android:id="@+id/delete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="16dp"
android:background="@drawable/del"
android:clickable="true"
android:src="@android:drawable/ic_input_add"
app:fabSize="mini"
app:layout_anchor="@id/appbar"
app:layout_anchorGravity="bottom|right|end" />
</android.support.design.widget.CoordinatorLayout>