1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-10 12:09:27 +01:00

Add overflow menu to blacklist and whitelist all installed applications

Fixes #679
This commit is contained in:
Daniele Gobbetti 2018-06-18 21:29:07 +02:00
parent 3f06a8c2a6
commit d55d551943
4 changed files with 47 additions and 0 deletions

View File

@ -22,6 +22,8 @@ import android.support.v4.app.NavUtils;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.SearchView;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import org.slf4j.Logger;
@ -64,12 +66,25 @@ public class AppBlacklistActivity extends AbstractGBActivity {
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.app_blacklist_menu, menu);
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
NavUtils.navigateUpFromSameTask(this);
return true;
case R.id.blacklist_all_notif:
appBlacklistAdapter.blacklistAllNotif();
return true;
case R.id.whitelist_all_notif:
appBlacklistAdapter.whitelistAllNotif();
return true;
}
return super.onOptionsItemSelected(item);
}

View File

@ -32,8 +32,10 @@ import android.widget.TextView;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
import java.util.IdentityHashMap;
import java.util.List;
import java.util.Set;
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
import nodomain.freeyourgadget.gadgetbridge.R;
@ -127,6 +129,22 @@ public class AppBlacklistAdapter extends RecyclerView.Adapter<AppBlacklistAdapte
}
public void blacklistAllNotif() {
Set<String> apps_blacklist = new HashSet<>();
List<ApplicationInfo> allApps = mPm.getInstalledApplications(PackageManager.GET_META_DATA);
for (ApplicationInfo ai : allApps) {
apps_blacklist.add(ai.packageName);
}
GBApplication.setAppsNotifBlackList(apps_blacklist);
notifyDataSetChanged();
}
public void whitelistAllNotif() {
Set<String> apps_blacklist = new HashSet<>();
GBApplication.setAppsNotifBlackList(apps_blacklist);
notifyDataSetChanged();
}
@Override
public int getItemCount() {
return applicationInfoList.size();

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/blacklist_all_notif"
android:title="@string/blacklist_all_for_notifications">
</item>
<item
android:id="@+id/whitelist_all_notif"
android:title="@string/whitelist_all_for_notifications" />
</menu>

View File

@ -46,6 +46,9 @@
<!-- Strings related to AppBlacklist -->
<string name="title_activity_appblacklist">Notification blacklist</string>
<string name="blacklist_all_for_notifications">Blacklist all for notifications</string>
<string name="whitelist_all_for_notifications">Whitelist all for notifications</string>
<!-- Strings related to CalBlacklist -->
<string name="title_activity_calblacklist">Blacklisted Calendars</string>