Added support for swipe to delete server

This commit is contained in:
PeratX 2017-05-01 11:20:22 +08:00
parent fa69502441
commit d035d1f814

View File

@ -6,6 +6,7 @@ import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.helper.ItemTouchHelper;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -36,6 +37,25 @@ public class DnsServersFragment extends Fragment {
recyclerView.setLayoutManager(manager);
adapter = new DnsServerAdapter();
recyclerView.setAdapter(adapter);
ItemTouchHelper itemTouchHelper = new ItemTouchHelper(new ItemTouchHelper.Callback() {
@Override
public int getMovementFlags(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
return makeMovementFlags(0, ItemTouchHelper.START | ItemTouchHelper.END);
}
@Override
public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) {
return false;
}
@Override
public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) {
int position = viewHolder.getAdapterPosition();
adapter.notifyItemRemoved(position);
Daedalus.configurations.getCustomDnsServers().remove(position);
}
});
itemTouchHelper.attachToRecyclerView(recyclerView);
FloatingActionButton fab = (FloatingActionButton) view.findViewById(R.id.fab_add_server);
fab.setOnClickListener(new View.OnClickListener() {