Improved custom dns server manage

This commit is contained in:
PeratX 2017-05-04 21:21:46 +08:00
parent 8ab3c0ad9a
commit 7dcb8b2643
28 changed files with 54 additions and 28 deletions

View File

@ -33,7 +33,7 @@ import java.util.List;
/**
* Daedalus Project
*
* @author iTXTech
* @author iTX Technologies
* @link https://itxtech.org
* <p>
* This program is free software: you can redistribute it and/or modify

View File

@ -16,7 +16,7 @@ import org.itxtech.daedalus.fragment.DnsServerConfigFragment;
/**
* Daedalus Project
*
* @author iTXTech
* @author iTX Technologies
* @link https://itxtech.org
* <p>
* This program is free software: you can redistribute it and/or modify

View File

@ -29,7 +29,7 @@ import org.itxtech.daedalus.fragment.*;
/**
* Daedalus Project
*
* @author iTXTech
* @author iTX Technologies
* @link https://itxtech.org
* <p>
* This program is free software: you can redistribute it and/or modify

View File

@ -20,7 +20,7 @@ import java.util.Locale;
/**
* Daedalus Project
*
* @author iTXTech
* @author iTX Technologies
* @link https://itxtech.org
* <p>
* This program is free software: you can redistribute it and/or modify

View File

@ -20,7 +20,7 @@ import org.itxtech.daedalus.util.DnsServer;
/**
* Daedalus Project
*
* @author iTXTech
* @author iTX Technologies
* @link https://itxtech.org
* <p>
* This program is free software: you can redistribute it and/or modify

View File

@ -4,6 +4,7 @@ import android.app.Fragment;
import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.helper.ItemTouchHelper;
@ -19,7 +20,7 @@ import org.itxtech.daedalus.util.CustomDnsServer;
/**
* Daedalus Project
*
* @author iTXTech
* @author iTX Technologies
* @link https://itxtech.org
* <p>
* This program is free software: you can redistribute it and/or modify
@ -29,10 +30,11 @@ import org.itxtech.daedalus.util.CustomDnsServer;
*/
public class DnsServersFragment extends Fragment {
private DnsServersFragment.DnsServerAdapter adapter;
private CustomDnsServer server = null;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_dns_servers, container, false);
final View view = inflater.inflate(R.layout.fragment_dns_servers, container, false);
RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.recyclerView_dns_servers);
LinearLayoutManager manager = new LinearLayoutManager(getActivity());
recyclerView.setLayoutManager(manager);
@ -52,8 +54,11 @@ public class DnsServersFragment extends Fragment {
@Override
public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) {
int position = viewHolder.getAdapterPosition();
adapter.notifyItemRemoved(position);
server = Daedalus.configurations.getCustomDnsServers().get(position);
Daedalus.configurations.getCustomDnsServers().remove(position);
Snackbar.make(view, R.string.action_removed, Snackbar.LENGTH_LONG)
.setAction(R.string.action_undo, new SnackbarClickListener(position)).show();
adapter.notifyItemRemoved(position);
}
});
itemTouchHelper.attachToRecyclerView(recyclerView);
@ -69,12 +74,27 @@ public class DnsServersFragment extends Fragment {
return view;
}
private class SnackbarClickListener implements View.OnClickListener {
private final int position;
private SnackbarClickListener(int position) {
this.position = position;
}
@Override
public void onClick(View v) {
Daedalus.configurations.getCustomDnsServers().add(position, server);
adapter.notifyItemInserted(position);
}
}
@Override
public void onDestroyView() {
super.onDestroyView();
Daedalus.configurations.save();
adapter = null;
server = null;
}
@Override
@ -100,7 +120,7 @@ public class DnsServersFragment extends Fragment {
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_dns_servers, parent, false);
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.card_server, parent, false);
return new ViewHolder(view);
}
}

View File

@ -33,7 +33,7 @@ import java.util.Set;
/**
* Daedalus Project
*
* @author iTXTech
* @author iTX Technologies
* @link https://itxtech.org
* <p>
* This program is free software: you can redistribute it and/or modify

View File

@ -25,7 +25,7 @@ import java.util.Date;
/**
* Daedalus Project
*
* @author iTXTech
* @author iTX Technologies
* @link https://itxtech.org
* <p>
* This program is free software: you can redistribute it and/or modify

View File

@ -21,7 +21,7 @@ import org.itxtech.daedalus.util.DnsServerHelper;
/**
* Daedalus Project
*
* @author iTXTech
* @author iTX Technologies
* @link https://itxtech.org
* <p>
* This program is free software: you can redistribute it and/or modify

View File

@ -16,7 +16,7 @@ import org.itxtech.daedalus.util.DnsServerHelper;
/**
* Daedalus Project
*
* @author iTXTech
* @author iTX Technologies
* @link https://itxtech.org
* <p>
* This program is free software: you can redistribute it and/or modify

View File

@ -6,7 +6,7 @@ import org.itxtech.daedalus.service.DaedalusVpnService;
/**
* Daedalus Project
*
* @author iTXTech
* @author iTX Technologies
* @link https://itxtech.org
* <p>
* This program is free software: you can redistribute it and/or modify

View File

@ -24,7 +24,7 @@ import java.util.LinkedList;
/**
* Daedalus Project
*
* @author iTXTech
* @author iTX Technologies
* @link https://itxtech.org
* <p>
* This program is free software: you can redistribute it and/or modify

View File

@ -32,7 +32,7 @@ import java.util.Queue;
/**
* Daedalus Project
*
* @author iTXTech
* @author iTX Technologies
* @link https://itxtech.org
* <p>
* This program is free software: you can redistribute it and/or modify

View File

@ -12,7 +12,7 @@ import org.itxtech.daedalus.util.DnsServerHelper;
/**
* Daedalus Project
*
* @author iTXTech
* @author iTX Technologies
* @link https://itxtech.org
* <p>
* This program is free software: you can redistribute it and/or modify

View File

@ -12,7 +12,7 @@ import java.lang.reflect.Method;
/**
* Daedalus Project
*
* @author iTXTech
* @author iTX Technologies
* @link https://itxtech.org
* <p>
* This program is free software: you can redistribute it and/or modify

View File

@ -27,7 +27,7 @@ import java.net.Inet4Address;
/**
* Daedalus Project
*
* @author iTXTech
* @author iTX Technologies
* @link https://itxtech.org
* <p>
* This program is free software: you can redistribute it and/or modify

View File

@ -13,7 +13,7 @@ import java.util.ArrayList;
/**
* Daedalus Project
*
* @author iTXTech
* @author iTX Technologies
* @link https://itxtech.org
* <p>
* This program is free software: you can redistribute it and/or modify

View File

@ -5,7 +5,7 @@ import org.itxtech.daedalus.Daedalus;
/**
* Daedalus Project
*
* @author iTXTech
* @author iTX Technologies
* @link https://itxtech.org
* <p>
* This program is free software: you can redistribute it and/or modify

View File

@ -5,7 +5,7 @@ import android.content.Context;
/**
* Daedalus Project
*
* @author iTXTech
* @author iTX Technologies
* @link https://itxtech.org
* <p>
* This program is free software: you can redistribute it and/or modify

View File

@ -10,7 +10,7 @@ import java.util.HashMap;
/**
* Daedalus Project
*
* @author iTXTech
* @author iTX Technologies
* @link https://itxtech.org
* <p>
* This program is free software: you can redistribute it and/or modify

View File

@ -7,7 +7,7 @@ import java.util.ArrayList;
/**
* Daedalus Project
*
* @author iTXTech
* @author iTX Technologies
* @link https://itxtech.org
* <p>
* This program is free software: you can redistribute it and/or modify

View File

@ -11,7 +11,7 @@ import java.util.HashMap;
/**
* Daedalus Project
*
* @author iTXTech
* @author iTX Technologies
* @link https://itxtech.org
* <p>
* This program is free software: you can redistribute it and/or modify

View File

@ -15,7 +15,7 @@ import org.itxtech.daedalus.R;
/**
* Daedalus Project
*
* @author iTXTech & MrFuFuFu
* @author iTX Technologies & MrFuFuFu
* @link https://itxtech.org
* <p>
* This program is free software: you can redistribute it and/or modify

View File

@ -9,7 +9,7 @@ import android.util.AttributeSet;
/**
* Daedalus Project
*
* @author iTXTech
* @author iTX Technologies
* @link https://itxtech.org
* <p>
* This program is free software: you can redistribute it and/or modify

View File

@ -21,7 +21,7 @@
</android.support.design.widget.AppBarLayout>
<RelativeLayout
<android.support.design.widget.CoordinatorLayout
android:id="@+id/id_content"
android:layout_width="match_parent"
android:layout_height="match_parent"

View File

@ -4,6 +4,8 @@
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:clickable="true"
android:foreground="?attr/selectableItemBackground"
app:cardCornerRadius="10dp"
app:cardPreventCornerOverlap="true"
app:cardUseCompatPadding="true">

View File

@ -64,4 +64,6 @@
<string name="apply">应用</string>
<string name="notice_fill_in_all">请填写所有配置项。</string>
<string name="settings_dns_over_tcp">DNS over TCP</string>
<string name="action_removed">已移除。</string>
<string name="action_undo">撤销</string>
</resources>

View File

@ -64,4 +64,6 @@
<string name="apply">Apply</string>
<string name="notice_fill_in_all">Please fill in all configuration items.</string>
<string name="settings_dns_over_tcp">DNS over TCP</string>
<string name="action_removed">Removed.</string>
<string name="action_undo">Undo</string>
</resources>