diff --git a/res/layout/activity_notification_filter.xml b/res/layout/activity_notification_filter.xml --- a/res/layout/activity_notification_filter.xml +++ b/res/layout/activity_notification_filter.xml @@ -9,7 +9,7 @@ android:id="@+id/tFilter" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:paddingBottom="5dp" + android:paddingBottom="16dp" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" diff --git a/res/values/strings.xml b/res/values/strings.xml --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -237,5 +237,6 @@ You will need to confirm the command on the desktop There are no commands registered You can add new commands in the KDE Connect System Settings + All diff --git a/src/org/kde/kdeconnect/Plugins/NotificationsPlugin/NotificationFilterActivity.java b/src/org/kde/kdeconnect/Plugins/NotificationsPlugin/NotificationFilterActivity.java --- a/src/org/kde/kdeconnect/Plugins/NotificationsPlugin/NotificationFilterActivity.java +++ b/src/org/kde/kdeconnect/Plugins/NotificationsPlugin/NotificationFilterActivity.java @@ -15,8 +15,8 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program. If not, see . -*/ + * along with this program. If not, see . + */ package org.kde.kdeconnect.Plugins.NotificationsPlugin; @@ -48,8 +48,10 @@ public class NotificationFilterActivity extends AppCompatActivity { private AppDatabase appDatabase; + private ListView listView; static class AppListInfo { + String pkg; String name; Drawable icon; @@ -62,28 +64,33 @@ @Override public int getCount() { - return apps.length; + return apps.length + 1; } @Override public AppListInfo getItem(int position) { - return apps[position]; + return apps[position - 1]; } @Override public long getItemId(int position) { - return position; + return position - 1; } public View getView(int position, View view, ViewGroup parent) { if (view == null) { LayoutInflater inflater = getLayoutInflater(); view = inflater.inflate(android.R.layout.simple_list_item_multiple_choice, null, true); } CheckedTextView checkedTextView = (CheckedTextView) view; - checkedTextView.setText(apps[position].name); - checkedTextView.setCompoundDrawablesWithIntrinsicBounds(apps[position].icon, null, null, null); - checkedTextView.setCompoundDrawablePadding((int) (8 * getResources().getDisplayMetrics().density)); + if (position == 0) { + checkedTextView.setText(R.string.all); + checkedTextView.setCompoundDrawablesWithIntrinsicBounds(null, null, null, null); + } else { + checkedTextView.setText(apps[position - 1].name); + checkedTextView.setCompoundDrawablesWithIntrinsicBounds(apps[position - 1].icon, null, null, null); + checkedTextView.setCompoundDrawablePadding((int) (8 * getResources().getDisplayMetrics().density)); + } return view; } @@ -134,21 +141,26 @@ private void displayAppList() { - final ListView listView = (ListView) findViewById(R.id.lvFilterApps); + listView = (ListView) findViewById(R.id.lvFilterApps); AppListAdapter adapter = new AppListAdapter(); listView.setAdapter(adapter); listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView adapterView, View view, int i, long l) { - boolean checked = listView.isItemChecked(i); - appDatabase.setEnabled(apps[i].pkg, checked); - apps[i].isEnabled = checked; + + if (i == 0) { + setAllAppsEnabled(listView.isItemChecked(0)); + } else { + boolean checked = listView.isItemChecked(i); + appDatabase.setEnabled(apps[i - 1].pkg, checked); + apps[i - 1].isEnabled = checked; + } } }); for (int i = 0; i < apps.length; i++) { - listView.setItemChecked(i, apps[i].isEnabled); + listView.setItemChecked(i + 1, apps[i].isEnabled); } listView.setVisibility(View.VISIBLE); @@ -181,6 +193,21 @@ return new BitmapDrawable(res, bitmap); + } + + private void setAllAppsEnabled(final boolean enabled) { + for (int i = 0; i < apps.length; i++) { + listView.setItemChecked(i, enabled); + } + + new Thread(new Runnable() { + @Override + public void run() { + for (AppListInfo app : apps) { + appDatabase.setEnabled(app.pkg, enabled); + } + } + }).start(); } }