mirror of
https://gitlab.com/xynngh/YetAnotherCallBlocker.git
synced 2025-04-22 22:37:21 +02:00
Add "Select all" blacklist action
This commit is contained in:
parent
a9532d5ba6
commit
e06dd5fb97
@ -105,7 +105,11 @@ public class BlacklistActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
|
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
|
||||||
if (item.getItemId() == R.id.menu_delete) {
|
if (item.getItemId() == R.id.menu_select_all) {
|
||||||
|
selectionTracker.setItemsSelected(blacklistDataSourceFactory
|
||||||
|
.getCurrentDataSource().getAllIds(), true);
|
||||||
|
return true;
|
||||||
|
} else if (item.getItemId() == R.id.menu_delete) {
|
||||||
new AlertDialog.Builder(BlacklistActivity.this)
|
new AlertDialog.Builder(BlacklistActivity.this)
|
||||||
.setTitle(R.string.are_you_sure)
|
.setTitle(R.string.are_you_sure)
|
||||||
.setMessage(R.string.blacklist_delete_confirmation)
|
.setMessage(R.string.blacklist_delete_confirmation)
|
||||||
|
@ -8,6 +8,7 @@ import org.greenrobot.greendao.query.QueryBuilder;
|
|||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import dummydomain.yetanothercallblocker.data.db.BlacklistDao;
|
import dummydomain.yetanothercallblocker.data.db.BlacklistDao;
|
||||||
@ -26,6 +27,10 @@ public class BlacklistDataSource extends PositionalDataSource<BlacklistItem> {
|
|||||||
this.blacklistDao = blacklistDao;
|
this.blacklistDao = blacklistDao;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public BlacklistDataSource getCurrentDataSource() {
|
||||||
|
return ds;
|
||||||
|
}
|
||||||
|
|
||||||
public void invalidate() {
|
public void invalidate() {
|
||||||
LOG.debug("invalidate()");
|
LOG.debug("invalidate()");
|
||||||
|
|
||||||
@ -48,6 +53,27 @@ public class BlacklistDataSource extends PositionalDataSource<BlacklistItem> {
|
|||||||
this.blacklistDao = blacklistDao;
|
this.blacklistDao = blacklistDao;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The iterable must be iterated through
|
||||||
|
* or the underlying cursor won't be closed.
|
||||||
|
*
|
||||||
|
* @return an iterable containing ids of all items this DS would load
|
||||||
|
*/
|
||||||
|
public Iterable<Long> getAllIds() {
|
||||||
|
Iterator<BlacklistItem> iterator = newQueryBuilder().listIterator();
|
||||||
|
return () -> new Iterator<Long>() {
|
||||||
|
@Override
|
||||||
|
public boolean hasNext() {
|
||||||
|
return iterator.hasNext();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Long next() {
|
||||||
|
return iterator.next().getId();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void loadInitial(@NonNull LoadInitialParams params,
|
public void loadInitial(@NonNull LoadInitialParams params,
|
||||||
@NonNull LoadInitialCallback<BlacklistItem> callback) {
|
@NonNull LoadInitialCallback<BlacklistItem> callback) {
|
||||||
@ -60,7 +86,7 @@ public class BlacklistDataSource extends PositionalDataSource<BlacklistItem> {
|
|||||||
Integer totalCount = null;
|
Integer totalCount = null;
|
||||||
|
|
||||||
if (items.isEmpty()) {
|
if (items.isEmpty()) {
|
||||||
totalCount = (int) blacklistDao.countAll();
|
totalCount = (int) countAll();
|
||||||
if (totalCount > 0) {
|
if (totalCount > 0) {
|
||||||
LOG.debug("loadInitial() initial range is empty: totalCount={}, offset={}",
|
LOG.debug("loadInitial() initial range is empty: totalCount={}, offset={}",
|
||||||
totalCount, offset);
|
totalCount, offset);
|
||||||
@ -78,7 +104,7 @@ public class BlacklistDataSource extends PositionalDataSource<BlacklistItem> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (params.placeholdersEnabled) {
|
if (params.placeholdersEnabled) {
|
||||||
if (totalCount == null) totalCount = (int) blacklistDao.countAll();
|
if (totalCount == null) totalCount = (int) countAll();
|
||||||
|
|
||||||
callback.onResult(items, offset, totalCount);
|
callback.onResult(items, offset, totalCount);
|
||||||
} else {
|
} else {
|
||||||
@ -103,11 +129,19 @@ public class BlacklistDataSource extends PositionalDataSource<BlacklistItem> {
|
|||||||
return blacklistDao.detach(items); // for DiffUtil to work
|
return blacklistDao.detach(items); // for DiffUtil to work
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private long countAll() {
|
||||||
|
return newQueryBuilder().count();
|
||||||
|
}
|
||||||
|
|
||||||
private QueryBuilder<BlacklistItem> getQueryBuilder() {
|
private QueryBuilder<BlacklistItem> getQueryBuilder() {
|
||||||
if (queryBuilder == null) {
|
if (queryBuilder == null) {
|
||||||
queryBuilder = blacklistDao.getDefaultQueryBuilder();
|
queryBuilder = newQueryBuilder();
|
||||||
}
|
}
|
||||||
return queryBuilder;
|
return queryBuilder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private QueryBuilder<BlacklistItem> newQueryBuilder() {
|
||||||
|
return blacklistDao.getDefaultQueryBuilder();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -82,10 +82,6 @@ public class BlacklistDao {
|
|||||||
getBlacklistItemDao().deleteByKeyInTx(keys);
|
getBlacklistItemDao().deleteByKeyInTx(keys);
|
||||||
}
|
}
|
||||||
|
|
||||||
public long countAll() {
|
|
||||||
return getBlacklistItemDao().queryBuilder().count();
|
|
||||||
}
|
|
||||||
|
|
||||||
public long countValid() {
|
public long countValid() {
|
||||||
return getBlacklistItemDao().queryBuilder()
|
return getBlacklistItemDao().queryBuilder()
|
||||||
.where(BlacklistItemDao.Properties.Invalid.notEq(true)).count();
|
.where(BlacklistItemDao.Properties.Invalid.notEq(true)).count();
|
||||||
|
9
app/src/main/res/drawable/ic_select_all_24dp.xml
Normal file
9
app/src/main/res/drawable/ic_select_all_24dp.xml
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="24dp"
|
||||||
|
android:height="24dp"
|
||||||
|
android:viewportWidth="24"
|
||||||
|
android:viewportHeight="24">
|
||||||
|
<path
|
||||||
|
android:fillColor="#FFFFFFFF"
|
||||||
|
android:pathData="M3,5h2L5,3c-1.1,0 -2,0.9 -2,2zM3,13h2v-2L3,11v2zM7,21h2v-2L7,19v2zM3,9h2L5,7L3,7v2zM13,3h-2v2h2L13,3zM19,3v2h2c0,-1.1 -0.9,-2 -2,-2zM5,21v-2L3,19c0,1.1 0.9,2 2,2zM3,17h2v-2L3,15v2zM9,3L7,3v2h2L9,3zM11,21h2v-2h-2v2zM19,13h2v-2h-2v2zM19,21c1.1,0 2,-0.9 2,-2h-2v2zM19,9h2L21,7h-2v2zM19,17h2v-2h-2v2zM15,21h2v-2h-2v2zM15,5h2L17,3h-2v2zM7,17h10L17,7L7,7v10zM9,9h6v6L9,15L9,9z" />
|
||||||
|
</vector>
|
@ -2,6 +2,12 @@
|
|||||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||||
|
|
||||||
|
<item
|
||||||
|
android:id="@+id/menu_select_all"
|
||||||
|
android:icon="@drawable/ic_select_all_24dp"
|
||||||
|
android:title="@string/blacklist_select_all"
|
||||||
|
app:showAsAction="ifRoom" />
|
||||||
|
|
||||||
<item
|
<item
|
||||||
android:id="@+id/menu_delete"
|
android:id="@+id/menu_delete"
|
||||||
android:icon="@drawable/ic_delete_24dp"
|
android:icon="@drawable/ic_delete_24dp"
|
||||||
|
@ -141,6 +141,7 @@
|
|||||||
<string name="blacklist_item_date_no_info">нет информации</string>
|
<string name="blacklist_item_date_no_info">нет информации</string>
|
||||||
<string name="blacklist_item_no_calls">Никогда не звонил</string>
|
<string name="blacklist_item_no_calls">Никогда не звонил</string>
|
||||||
<string name="blacklist_add">Добавить</string>
|
<string name="blacklist_add">Добавить</string>
|
||||||
|
<string name="blacklist_select_all">Выделить все</string>
|
||||||
<string name="blacklist_delete">Удалить</string>
|
<string name="blacklist_delete">Удалить</string>
|
||||||
<string name="blacklist_delete_confirmation">Удалить выбранные элементы?</string>
|
<string name="blacklist_delete_confirmation">Удалить выбранные элементы?</string>
|
||||||
<string name="blacklist_export">Экспортировать</string>
|
<string name="blacklist_export">Экспортировать</string>
|
||||||
|
@ -158,6 +158,7 @@
|
|||||||
<string name="blacklist_item_date_no_info">no info</string>
|
<string name="blacklist_item_date_no_info">no info</string>
|
||||||
<string name="blacklist_item_no_calls">Never called</string>
|
<string name="blacklist_item_no_calls">Never called</string>
|
||||||
<string name="blacklist_add">Add</string>
|
<string name="blacklist_add">Add</string>
|
||||||
|
<string name="blacklist_select_all">Select all</string>
|
||||||
<string name="blacklist_delete">Delete</string>
|
<string name="blacklist_delete">Delete</string>
|
||||||
<string name="blacklist_delete_confirmation">Delete the selected items?</string>
|
<string name="blacklist_delete_confirmation">Delete the selected items?</string>
|
||||||
<string name="blacklist_export">Export</string>
|
<string name="blacklist_export">Export</string>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user