diff options
Diffstat (limited to 'main/src')
-rw-r--r-- | main/src/main/java/de/blinkt/openvpn/fragments/Settings_Allowed_Apps.java | 39 | ||||
-rw-r--r-- | main/src/main/res/layout/allowed_vpn_apps.xml | 2 |
2 files changed, 31 insertions, 10 deletions
diff --git a/main/src/main/java/de/blinkt/openvpn/fragments/Settings_Allowed_Apps.java b/main/src/main/java/de/blinkt/openvpn/fragments/Settings_Allowed_Apps.java index c6c7996c..74d1c88d 100644 --- a/main/src/main/java/de/blinkt/openvpn/fragments/Settings_Allowed_Apps.java +++ b/main/src/main/java/de/blinkt/openvpn/fragments/Settings_Allowed_Apps.java @@ -6,8 +6,8 @@ package de.blinkt.openvpn.fragments; import android.Manifest; +import android.app.Activity; import android.app.Fragment; -import android.app.SearchManager; import android.content.Context; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; @@ -30,7 +30,6 @@ import android.widget.SearchView; import android.widget.Switch; import android.widget.TextView; -import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Vector; @@ -109,7 +108,7 @@ public class Settings_Allowed_Apps extends Fragment implements AdapterView.OnIte class PackageAdapter extends BaseAdapter implements Filterable { - private final List<ApplicationInfo> mPackages; + private Vector<ApplicationInfo> mPackages; private final LayoutInflater mInflater; private final PackageManager mPm; private ItemFilter mFilter = new ItemFilter(); @@ -128,10 +127,6 @@ public class Settings_Allowed_Apps extends Fragment implements AdapterView.OnIte int count = mPackages.size(); final Vector<ApplicationInfo> nlist = new Vector<>(count); - String filterableString ; - - - for (int i = 0; i < count; i++) { ApplicationInfo pInfo = mPackages.get(i); CharSequence appName = pInfo.loadLabel(mPm); @@ -165,9 +160,15 @@ public class Settings_Allowed_Apps extends Fragment implements AdapterView.OnIte PackageAdapter(Context c, VpnProfile vp) { mPm = c.getPackageManager(); mProfile = vp; - List<ApplicationInfo> installedPackages = mPm.getInstalledApplications(PackageManager.GET_META_DATA); mInflater = LayoutInflater.from(c); + mPackages = new Vector<>(); + mFilteredData = mPackages; + } + + private void populateList(Activity c) { + List<ApplicationInfo> installedPackages = mPm.getInstalledApplications(PackageManager.GET_META_DATA); + // Remove apps not using Internet int androidSystemUid = 0; @@ -194,6 +195,12 @@ public class Settings_Allowed_Apps extends Fragment implements AdapterView.OnIte Collections.sort(apps, new ApplicationInfo.DisplayNameComparator(mPm)); mPackages = apps; mFilteredData = apps; + c.runOnUiThread(new Runnable() { + @Override + public void run() { + notifyDataSetChanged(); + } + }); } @Override @@ -271,14 +278,18 @@ public class Settings_Allowed_Apps extends Fragment implements AdapterView.OnIte @Override public boolean onQueryTextChange(String newText) { mListView.setFilterText(newText); - mListView.setTextFilterEnabled(true); + if (TextUtils.isEmpty(newText)) + mListView.setTextFilterEnabled(false); + else + mListView.setTextFilterEnabled(true); + return true; } }); searchView.setOnCloseListener(new SearchView.OnCloseListener() { @Override public boolean onClose() { - mListView.setTextFilterEnabled(false); + mListView.clearTextFilter(); return false; } }); @@ -311,6 +322,14 @@ public class Settings_Allowed_Apps extends Fragment implements AdapterView.OnIte mListView.setAdapter(mListAdapter); mListView.setOnItemClickListener(this); + mListView.setEmptyView(v.findViewById(R.id.loading_container)); + + new Thread(new Runnable() { + @Override + public void run() { + mListAdapter.populateList(getActivity()); + } + }).start(); return v; } diff --git a/main/src/main/res/layout/allowed_vpn_apps.xml b/main/src/main/res/layout/allowed_vpn_apps.xml index ff015fca..463e0d03 100644 --- a/main/src/main/res/layout/allowed_vpn_apps.xml +++ b/main/src/main/res/layout/allowed_vpn_apps.xml @@ -38,6 +38,7 @@ </RelativeLayout> <ListView + android:visibility="gone" android:id="@android:id/list" android:drawSelectorOnTop="false" android:layout_width="match_parent" @@ -46,6 +47,7 @@ android:scrollbarStyle="outsideOverlay" /> + <LinearLayout android:id="@+id/loading_container" android:orientation="vertical" |