Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

filter-by-accounts #32

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@

Overview
---
This is a free application that allows you to configure the blocking of unwanted calls and SMS
This is a fork of free application that allows you to configure the blocking of unwanted calls and SMS
in convenient way. It does not contain ads, supports light and dark interface themes and is
supported by devices with Android 2.3 and up.
supported by devices with Android 2.3 and up. As original Blacklist is not maintained anymore, I'll take care of it's fork.
Forked version will introduce online sources syncing, and online repositories for blocking and sharing public blacklists
using CardDAV servers, or even gists. I've also added contacts group support.

Features
---
Expand Down Expand Up @@ -69,8 +71,17 @@ separately. You can adjust the level of visual and audio information about the e
You can set the light or dark theme of the application interface. Here, you can also export and
import application data, for example, to transfer them from one device to another.

### License:

### Fork License:
Copyright (C) 2019 Dmitrij Rysanow <[email protected]>
Licensed under the Apache License, Version 2.0 (the "License"); you may not
use this file except in compliance with the License. You may obtain a copy of
the License at http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
License for the specific language governing permissions and limitations under
the License.
### Original License:
Copyright (C) 2017 Anton Kaliturin <[email protected]>
Licensed under the Apache License, Version 2.0 (the "License"); you may not
use this file except in compliance with the License. You may obtain a copy of
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
android:versionCode="18"
android:versionName="1.2.12">

<uses-permission
android:name="android.permission.GET_ACCOUNTS"
android:maxSdkVersion="22" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_CONTACTS" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import android.support.v4.util.LongSparseArray;
import android.support.v4.view.MenuItemCompat;
import android.support.v7.widget.SearchView;
import android.util.Pair;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
Expand All @@ -53,20 +54,28 @@
import com.kaliturin.blacklist.utils.ProgressDialogHolder;
import com.kaliturin.blacklist.utils.Utils;

import java.util.HashMap;
import java.util.List;

/**
* Fragment for representation the list of contacts to choose
* which one is adding to the black/white list
*/
public class AddContactsFragment extends Fragment implements FragmentArguments {
private static final HashMap<String, String> ACCOUNT_TYPES = new HashMap<String, String>() {{
put("com.google", "Google");
put("at.bitfire.davdroid.address_book", "DAVDroid");
put("com.deependhulla.opensync.address_book", "Open Sync");
}};
private ContactsCursorAdapter cursorAdapter = null;
private ButtonsBar snackBar = null;
private ContactSourceType sourceType = null;
private int contactType = 0;
private boolean singleNumberMode = false;
private LongSparseArray<ContactNumber> singleContactNumbers = new LongSparseArray<>();

private String accountType = null;
private String accountName = null;
private String itemsFilter = null;
public AddContactsFragment() {
// Required empty public constructor
}
Expand Down Expand Up @@ -157,7 +166,7 @@ public void onClick(View row) {
listView.setEmptyView(textEmptyView);

// init and run the loader of contacts
getLoaderManager().initLoader(0, null, newLoaderCallbacks(null));
getLoaderManager().initLoader(0, null, newLoaderCallbacks(null, null, null));
}

@Override
Expand All @@ -173,6 +182,19 @@ public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
Utils.setMenuIconTint(getContext(), itemSearch, R.attr.colorAccent);
itemSearch.setVisible(true);

MenuItem findByAccount = menu.findItem(R.id.action_filter_group);
Utils.setMenuIconTint(getContext(), findByAccount, R.attr.colorAccent);
findByAccount.setVisible(true);
findByAccount.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem menuItem) {
if (menuItem.getTitle() == getResources().getString(R.string.Filter_by_group)) {
showAccountsFilterDialog();
return true;
}
return false;
}
});
// get the view from search menu item
SearchView searchView = (SearchView) MenuItemCompat.getActionView(itemSearch);
searchView.setQueryHint(getString(R.string.Search_action));
Expand All @@ -185,7 +207,8 @@ public boolean onQueryTextSubmit(String query) {

@Override
public boolean onQueryTextChange(String newText) {
reloadItems(newText);
itemsFilter = newText;
reloadItems();
return true;
}
});
Expand All @@ -201,14 +224,46 @@ public boolean onMenuItemActionExpand(MenuItem item) {

@Override
public boolean onMenuItemActionCollapse(MenuItem item) {
reloadItems(null);
reloadItems();
return true;
}
});

super.onCreateOptionsMenu(menu, inflater);
}

private void showAccountsFilterDialog() {
ContactsAccessHelper dao = ContactsAccessHelper.getInstance(getContext());

final List<Pair<String, String>> accounts = dao.getAccounts();

DialogBuilder dialog = new DialogBuilder(getContext());
dialog.setTitle(R.string.Filter_by_group);
dialog.addItem(R.string.All, new View.OnClickListener() {
@Override
public void onClick(View view) {
applyAccountFilter(null, null);
}
});
for (final Pair<String, String> pair: accounts) {
String name = ACCOUNT_TYPES.get(pair.first);
dialog.addItem(name + " " + pair.second, new View.OnClickListener() {
@Override
public void onClick(View view) {
applyAccountFilter(pair.first, pair.second);
}
});
}
dialog.show();
}

private void applyAccountFilter(String accountType, String accountName) {
// assign accountType and accountName
this.accountType = accountType;
this.accountName = accountName;
// refresh the list
reloadItems();
}
//-------------------------------------------------------------------

// Opens menu dialog with list of contact's numbers to choose
Expand Down Expand Up @@ -260,38 +315,42 @@ public boolean dismissSnackBar() {
}

// Reloads items
private void reloadItems(String itemsFilter) {
private void reloadItems() {
singleContactNumbers.clear();
dismissSnackBar();
if (isAdded()) {
getLoaderManager().restartLoader(0, null, newLoaderCallbacks(itemsFilter));
getLoaderManager().restartLoader(0, null, newLoaderCallbacks(itemsFilter, accountType, accountName));
}
}

// Creates new contacts loader
private ContactsLoaderCallbacks newLoaderCallbacks(String itemsFilter) {
return new ContactsLoaderCallbacks(getContext(), sourceType, cursorAdapter, itemsFilter);
private ContactsLoaderCallbacks newLoaderCallbacks(String itemsFilter, String accountType, String accountName) {
return new ContactsLoaderCallbacks(getContext(), sourceType, cursorAdapter, itemsFilter, accountType, accountName);
}

//-------------------------------------------------------------------

// Contact items loader
private static class ContactsLoader extends CursorLoader {
private ContactSourceType sourceType;
private String itemsFilter;

private String accountType;
private String accountName;
ContactsLoader(Context context,
ContactSourceType sourceType,
String itemsFilter) {
String itemsFilter,
String accountType,
String accountName) {
super(context);
this.sourceType = sourceType;
this.itemsFilter = itemsFilter;
this.accountType = accountType;
this.accountName = accountName;
}

@Override
public Cursor loadInBackground() {
ContactsAccessHelper dao = ContactsAccessHelper.getInstance(getContext());
return dao.getContacts(getContext(), sourceType, itemsFilter);
return dao.getContacts(getContext(), sourceType, itemsFilter, accountType, accountName);
}
}

Expand All @@ -302,21 +361,29 @@ private static class ContactsLoaderCallbacks implements LoaderManager.LoaderCall
private ContactSourceType sourceType;
private ContactsCursorAdapter cursorAdapter;
private String itemsFilter;
private String accountType;
private String accountName;

ContactsLoaderCallbacks(Context context,
ContactSourceType sourceType,
ContactsCursorAdapter cursorAdapter,
String itemsFilter) {
String itemsFilter,
String accountType,
String accountName) {
this.context = context;
this.sourceType = sourceType;
this.cursorAdapter = cursorAdapter;
this.itemsFilter = itemsFilter;
this.accountType = accountType;
this.accountName = accountName;
}

@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
progress.show(context, 0, R.string.Loading_);
return new ContactsLoader(context, sourceType, itemsFilter);
//TODO: investigate how to assign group to filter
int groupId = 0;
return new ContactsLoader(context, sourceType, itemsFilter, accountType, accountName);
}

@Override
Expand Down
Loading