Added support for swipe to delete server
This commit is contained in:
parent
fa69502441
commit
d035d1f814
@ -6,6 +6,7 @@ import android.os.Bundle;
|
|||||||
import android.support.design.widget.FloatingActionButton;
|
import android.support.design.widget.FloatingActionButton;
|
||||||
import android.support.v7.widget.LinearLayoutManager;
|
import android.support.v7.widget.LinearLayoutManager;
|
||||||
import android.support.v7.widget.RecyclerView;
|
import android.support.v7.widget.RecyclerView;
|
||||||
|
import android.support.v7.widget.helper.ItemTouchHelper;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
@ -36,6 +37,25 @@ public class DnsServersFragment extends Fragment {
|
|||||||
recyclerView.setLayoutManager(manager);
|
recyclerView.setLayoutManager(manager);
|
||||||
adapter = new DnsServerAdapter();
|
adapter = new DnsServerAdapter();
|
||||||
recyclerView.setAdapter(adapter);
|
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);
|
FloatingActionButton fab = (FloatingActionButton) view.findViewById(R.id.fab_add_server);
|
||||||
fab.setOnClickListener(new View.OnClickListener() {
|
fab.setOnClickListener(new View.OnClickListener() {
|
||||||
|
Loading…
Reference in New Issue
Block a user