Commit 4e17dac0 authored by Daniel Wolf's avatar Daniel Wolf
Browse files

Do not create an entry if an entry with the same name already exists

parent 0419cef3
......@@ -144,6 +144,10 @@ public class DatabaseHelper extends com.frostnerd.utils.database.DatabaseHelper
super.close();
}
public boolean dnsEntryExists(String name){
return select(DNSEntry.class, WhereCondition.equal("name", name)).size() != 0;
}
public boolean dnsRuleExists(@NonNull String host){
return this.rowExists(DNSRule.class, WhereCondition.equal(findColumn(DNSRule.class, "host"), host));
}
......
......@@ -15,6 +15,7 @@ import android.widget.Button;
import android.widget.EditText;
import com.frostnerd.dnschanger.R;
import com.frostnerd.dnschanger.database.DatabaseHelper;
import com.frostnerd.dnschanger.database.entities.DNSEntry;
import com.frostnerd.dnschanger.database.entities.IPPortPair;
import com.frostnerd.dnschanger.util.PreferencesAccessor;
......@@ -119,7 +120,7 @@ public class DNSCreationDialog extends UtilityDialog {
@Override
public void onClick(View v) {
if (isConfigurationValid()) {
listener.onCreationFinished(ed_name.getText().toString(), dns1, dns2, dns1V6, dns2V6);
listener.onCreationFinished(ed_name.getText().toString().trim(), dns1, dns2, dns1V6, dns2V6);
dismiss();
} else {
vibrator.vibrate(300);
......@@ -204,6 +205,8 @@ public class DNSCreationDialog extends UtilityDialog {
@Override
public void afterTextChanged(Editable s) {
if(s.toString().trim().equals("")) met_name.setIndicatorState(MaterialEditText.IndicatorState.INCORRECT);
else if(DatabaseHelper.getInstance(getContext()).dnsEntryExists(s.toString().trim())) met_name.setIndicatorState(MaterialEditText.IndicatorState.INCORRECT);
else met_name.setIndicatorState(MaterialEditText.IndicatorState.CORRECT);
}
});
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment