Don't create blacklist duplicates

This commit is contained in:
xynngh 2020-08-07 13:38:49 +04:00
parent d44121607f
commit a95ce13628
2 changed files with 14 additions and 1 deletions

View File

@ -222,7 +222,13 @@ public class EditBlacklistItemActivity extends AppCompatActivity {
} }
} else { } else {
if (TextUtils.isEmpty(name) && TextUtils.isEmpty(pattern)) { if (TextUtils.isEmpty(name) && TextUtils.isEmpty(pattern)) {
LOG.warn("save() not creating a new item because fields are empty"); LOG.info("save() not creating a new item because fields are empty");
return;
}
if (blacklistDao.findByNameAndPattern(name, pattern) != null) {
LOG.info("save() not creating a new item because" +
" an item with the same name and pattern exists");
return; return;
} }

View File

@ -51,6 +51,13 @@ public class BlacklistDao {
.orderAsc(BlacklistItemDao.Properties.Pattern)); .orderAsc(BlacklistItemDao.Properties.Pattern));
} }
public BlacklistItem findByNameAndPattern(String name, String pattern) {
return first(getBlacklistItemDao().queryBuilder()
.where(BlacklistItemDao.Properties.Name.eq(name))
.where(BlacklistItemDao.Properties.Pattern.eq(pattern))
.orderAsc(BlacklistItemDao.Properties.Pattern));
}
public void save(BlacklistItem blacklistItem) { public void save(BlacklistItem blacklistItem) {
getBlacklistItemDao().save(blacklistItem); getBlacklistItemDao().save(blacklistItem);
} }