Now you can't modify the custom server when it is in using

This commit is contained in:
PeratX 2017-05-13 14:53:36 +08:00
parent 62791ed5f9
commit be7ab36d13
4 changed files with 27 additions and 3 deletions

View File

@ -10,6 +10,7 @@ import android.support.v4.graphics.drawable.DrawableCompat;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import org.itxtech.daedalus.Daedalus;
import org.itxtech.daedalus.R;
import org.itxtech.daedalus.fragment.DnsServerConfigFragment;
@ -55,4 +56,11 @@ public class DnsServerConfigActivity extends AppCompatActivity {
fragmentTransaction.replace(R.id.id_config, fragment);
fragmentTransaction.commit();
}
@Override
protected void onDestroy() {
super.onDestroy();
Daedalus.configurations.save();
}
}

View File

@ -16,6 +16,7 @@ import org.itxtech.daedalus.Daedalus;
import org.itxtech.daedalus.R;
import org.itxtech.daedalus.activity.DnsServerConfigActivity;
import org.itxtech.daedalus.util.CustomDnsServer;
import org.itxtech.daedalus.util.DnsServerHelper;
/**
* Daedalus Project
@ -43,6 +44,11 @@ public class DnsServersFragment extends Fragment {
ItemTouchHelper itemTouchHelper = new ItemTouchHelper(new ItemTouchHelper.Callback() {
@Override
public int getMovementFlags(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
if (viewHolder instanceof ViewHolder) {
if (DnsServerHelper.isInUsing(Daedalus.configurations.getCustomDnsServers().get(((ViewHolder) viewHolder).getIndex()))) {
return 0;
}
}
return makeMovementFlags(0, ItemTouchHelper.START | ItemTouchHelper.END);
}
@ -141,10 +147,16 @@ public class DnsServersFragment extends Fragment {
this.index = index;
}
int getIndex() {
return index;
}
@Override
public void onClick(View v) {
Daedalus.getInstance().startActivity(new Intent(Daedalus.getInstance(), DnsServerConfigActivity.class)
.putExtra(DnsServerConfigActivity.LAUNCH_ACTION_CUSTOM_DNS_SERVER_ID, index));
if (!DnsServerHelper.isInUsing(Daedalus.configurations.getCustomDnsServers().get(index))) {
Daedalus.getInstance().startActivity(new Intent(Daedalus.getInstance(), DnsServerConfigActivity.class)
.putExtra(DnsServerConfigActivity.LAUNCH_ACTION_CUSTOM_DNS_SERVER_ID, index));
}
}
}
}

View File

@ -30,7 +30,7 @@ public class Configurations {
private int totalId;
public int getNextId() {
int getNextId() {
if (totalId < CUSTOM_DNS_ID_START) {
totalId = CUSTOM_DNS_ID_START;
}

View File

@ -146,4 +146,8 @@ public class DnsServerHelper {
}
return Daedalus.DNS_SERVERS.get(0).getStringDescription(context);
}
public static boolean isInUsing(CustomDnsServer server) {
return Daedalus.getInstance().isServiceActivated() && (server.getId().equals(getPrimary()) || server.getId().equals(getSecondary()));
}
}