From d035d1f8144eb0b9946abf36a17ebcc10485017b Mon Sep 17 00:00:00 2001 From: PeratX <1215714524@qq.com> Date: Mon, 1 May 2017 11:20:22 +0800 Subject: [PATCH] Added support for swipe to delete server --- .../daedalus/fragment/DnsServersFragment.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/app/src/main/java/org/itxtech/daedalus/fragment/DnsServersFragment.java b/app/src/main/java/org/itxtech/daedalus/fragment/DnsServersFragment.java index c30c700..99664ed 100644 --- a/app/src/main/java/org/itxtech/daedalus/fragment/DnsServersFragment.java +++ b/app/src/main/java/org/itxtech/daedalus/fragment/DnsServersFragment.java @@ -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() {