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