Differential D12229 Diff 32204 src/org/kde/kdeconnect/Plugins/NotificationsPlugin/NotificationFilterActivity.java
Changeset View
Changeset View
Standalone View
Standalone View
src/org/kde/kdeconnect/Plugins/NotificationsPlugin/NotificationFilterActivity.java
Show First 20 Lines • Show All 90 Lines • ▼ Show 20 Line(s) | 48 | public class NotificationFilterActivity extends AppCompatActivity { | |||
---|---|---|---|---|---|
91 | } | 91 | } | ||
92 | 92 | | |||
93 | @Override | 93 | @Override | ||
94 | protected void onCreate(Bundle savedInstanceState) { | 94 | protected void onCreate(Bundle savedInstanceState) { | ||
95 | super.onCreate(savedInstanceState); | 95 | super.onCreate(savedInstanceState); | ||
96 | setContentView(R.layout.activity_notification_filter); | 96 | setContentView(R.layout.activity_notification_filter); | ||
97 | appDatabase = new AppDatabase(NotificationFilterActivity.this, false); | 97 | appDatabase = new AppDatabase(NotificationFilterActivity.this, false); | ||
98 | 98 | | |||
99 | new Thread(new Runnable() { | 99 | new Thread(() -> { | ||
100 | @Override | | |||
101 | public void run() { | | |||
102 | 100 | | |||
103 | PackageManager packageManager = getPackageManager(); | 101 | PackageManager packageManager = getPackageManager(); | ||
104 | List<ApplicationInfo> appList = packageManager.getInstalledApplications(0); | 102 | List<ApplicationInfo> appList = packageManager.getInstalledApplications(0); | ||
105 | int count = appList.size(); | 103 | int count = appList.size(); | ||
106 | 104 | | |||
107 | apps = new AppListInfo[count]; | 105 | apps = new AppListInfo[count]; | ||
108 | for (int i = 0; i < count; i++) { | 106 | for (int i = 0; i < count; i++) { | ||
109 | ApplicationInfo appInfo = appList.get(i); | 107 | ApplicationInfo appInfo = appList.get(i); | ||
110 | apps[i] = new AppListInfo(); | 108 | apps[i] = new AppListInfo(); | ||
111 | apps[i].pkg = appInfo.packageName; | 109 | apps[i].pkg = appInfo.packageName; | ||
112 | apps[i].name = appInfo.loadLabel(packageManager).toString(); | 110 | apps[i].name = appInfo.loadLabel(packageManager).toString(); | ||
113 | apps[i].icon = resizeIcon(appInfo.loadIcon(packageManager), 48); | 111 | apps[i].icon = resizeIcon(appInfo.loadIcon(packageManager), 48); | ||
114 | apps[i].isEnabled = appDatabase.isEnabled(appInfo.packageName); | 112 | apps[i].isEnabled = appDatabase.isEnabled(appInfo.packageName); | ||
115 | } | 113 | } | ||
116 | 114 | | |||
117 | Arrays.sort(apps, new Comparator<AppListInfo>() { | 115 | Arrays.sort(apps, (lhs, rhs) -> StringsHelper.compare(lhs.name, rhs.name)); | ||
118 | @Override | | |||
119 | public int compare(AppListInfo lhs, AppListInfo rhs) { | | |||
120 | return StringsHelper.compare(lhs.name, rhs.name); | | |||
121 | } | | |||
122 | }); | | |||
123 | 116 | | |||
124 | runOnUiThread(new Runnable() { | 117 | runOnUiThread(this::displayAppList); | ||
125 | @Override | | |||
126 | public void run() { | | |||
127 | displayAppList(); | | |||
128 | } | | |||
129 | }); | | |||
130 | } | | |||
131 | }).start(); | 118 | }).start(); | ||
132 | 119 | | |||
133 | } | 120 | } | ||
134 | 121 | | |||
135 | private void displayAppList() { | 122 | private void displayAppList() { | ||
136 | 123 | | |||
137 | final ListView listView = (ListView) findViewById(R.id.lvFilterApps); | 124 | final ListView listView = (ListView) findViewById(R.id.lvFilterApps); | ||
138 | AppListAdapter adapter = new AppListAdapter(); | 125 | AppListAdapter adapter = new AppListAdapter(); | ||
139 | listView.setAdapter(adapter); | 126 | listView.setAdapter(adapter); | ||
140 | listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE); | 127 | listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE); | ||
141 | listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { | 128 | listView.setOnItemClickListener((adapterView, view, i, l) -> { | ||
142 | @Override | | |||
143 | public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) { | | |||
144 | boolean checked = listView.isItemChecked(i); | 129 | boolean checked = listView.isItemChecked(i); | ||
145 | appDatabase.setEnabled(apps[i].pkg, checked); | 130 | appDatabase.setEnabled(apps[i].pkg, checked); | ||
146 | apps[i].isEnabled = checked; | 131 | apps[i].isEnabled = checked; | ||
147 | } | | |||
148 | }); | 132 | }); | ||
149 | 133 | | |||
150 | for (int i = 0; i < apps.length; i++) { | 134 | for (int i = 0; i < apps.length; i++) { | ||
151 | listView.setItemChecked(i, apps[i].isEnabled); | 135 | listView.setItemChecked(i, apps[i].isEnabled); | ||
152 | } | 136 | } | ||
153 | 137 | | |||
154 | listView.setVisibility(View.VISIBLE); | 138 | listView.setVisibility(View.VISIBLE); | ||
155 | findViewById(R.id.spinner).setVisibility(View.GONE); | 139 | findViewById(R.id.spinner).setVisibility(View.GONE); | ||
Show All 31 Lines |