Skip to content

Commit ed860a9

Browse files
author
isayan
committed
support sort by
1 parent d533804 commit ed860a9

File tree

9 files changed

+68
-16
lines changed

9 files changed

+68
-16
lines changed

Readme-ja.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,14 @@ Disallow Application と Allow Application の2つのモードがあります
5858
画面上部の検索アイコン(![Menu](images/Search.png))から、アプリケーションを絞り込めます。
5959
アプリケーション名に指定したキーワードを含む、アプリケーションのみが表示されます。
6060

61+
プリケーションリストは、画面上部のメニューアイコン(![メニュー](images / Menu.png))からソートできます。
62+
63+
* アプリ名で並べ替え
64+
* アプリケーション名でアプリケーションリストを並べ替えます。
65+
66+
* パッケージ名で並べ替え
67+
* パッケージ名でアプリケーションリストを並べ替えます。
68+
6169
### About
6270
アプリケーションバージョンを表示します。
6371

Readme.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,19 @@ The default is **Disallow Application** selected.
5353

5454
### Settings Search
5555

56-
![Menu Settings](images/Menu-Settings-Search.png)
56+
![Menu Settings](images/Menu-Settings-Search.png) / ![Menu Settings](images/Menu-Settings-SortBy.png)
5757

5858
You can narrow down the applications from the search icon.(![Menu](images/Search.png))
5959
Only applications that contain the keyword specified in the application name are displayed.
6060

61+
The application list can be sorted from the menu icon (![Menu](images/Menu.png)) at the top of the screen.
62+
63+
* sort by app name
64+
* Sort application list by application name
65+
66+
* sort by package name
67+
* Sort application list by package name
68+
6169
### About
6270
Display application version
6371

android_app/app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ android {
66
applicationId "tun.proxy"
77
minSdkVersion 21
88
targetSdkVersion 27
9-
versionCode 100010
9+
versionCode 100011
1010
versionName VERSION_NAME
1111
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
1212
externalNativeBuild {

android_app/app/src/main/java/tun/proxy/MyApplication.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ public void onCreate() {
4343

4444
public enum VPNMode {DISALLOW, ALLOW};
4545

46+
public enum AppSortBy {APPNAME, PKGNAME};
47+
4648
// public final String vpn_mode_key[] = {VPNMode.DISALLOW.name(), VPNMode.ALLOW.name()};
4749

4850
private final String pref_key[] = {"vpn_disallowed_application", "vpn_allowed_application"};

android_app/app/src/main/java/tun/proxy/SimplePreferenceFragment.java

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public void onCreate(Bundle savedInstanceState) {
3939
@Override
4040
public boolean onPreferenceChange(Preference preference, Object value) {
4141
if (preference instanceof ListPreference) {
42-
ListPreference listPreference = (ListPreference) preference;
42+
final ListPreference listPreference = (ListPreference) preference;
4343
int index = listPreference.findIndexOfValue((String) value);
4444

4545
PreferenceScreen disallow = (PreferenceScreen) findPreference(VPN_DISALLOWED_APPLICATION_LIST);
@@ -102,11 +102,12 @@ private void transitionFragment(PreferenceFragment nextPreferenceFragment) {
102102

103103
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
104104
public static class PackageListPreferenceFragment extends PreferenceFragment implements SearchView.OnQueryTextListener, SearchView.OnCloseListener {
105-
private MyApplication.VPNMode mode;
105+
private MyApplication.VPNMode mode = MyApplication.VPNMode.DISALLOW;
106+
private MyApplication.AppSortBy appSortBy = MyApplication.AppSortBy.APPNAME;
106107
private PreferenceScreen mRootPreferenceScreen;
107108

108109
public static PackageListPreferenceFragment newInstance(MyApplication.VPNMode mode) {
109-
PackageListPreferenceFragment fragment = new PackageListPreferenceFragment();
110+
final PackageListPreferenceFragment fragment = new PackageListPreferenceFragment();
110111
fragment.mode = mode;
111112
return fragment;
112113
}
@@ -123,14 +124,18 @@ public void onCreate(Bundle savedInstanceState) {
123124
private SearchView searchView;
124125

125126
protected void filter(String filter) {
127+
this.filter(filter, this.appSortBy);
128+
}
129+
130+
protected void filter(String filter, final MyApplication.AppSortBy sortBy) {
126131
if (filter == null) {
127132
filter = searchFilter;
128133
}
129134
else {
130135
searchFilter = filter;
131136
}
132137
removeAllPreferenceScreen();
133-
buildPackagesPreferences(filter);
138+
buildPackagesPreferences(filter, sortBy);
134139
loadSelectedPackage();
135140
}
136141

@@ -140,7 +145,7 @@ public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
140145
// Menuの設定
141146
inflater.inflate(R.menu.menu_search, menu);
142147

143-
MenuItem menuItem = menu.findItem(R.id.search_menu_item);
148+
final MenuItem menuItem = menu.findItem(R.id.menu_search_item);
144149

145150
this.searchView = (SearchView)menuItem.getActionView();
146151
this.searchView.setOnQueryTextListener(this);
@@ -164,16 +169,23 @@ private void removeAllPreferenceScreen() {
164169
mRootPreferenceScreen.removeAll();
165170
}
166171

167-
private void buildPackagesPreferences(String filter) {
172+
private void buildPackagesPreferences(String filter, final MyApplication.AppSortBy sortBy) {
168173
final Context context = MyApplication.getInstance().getApplicationContext();
169174
final PackageManager pm = context.getPackageManager();
170175
final List<PackageInfo> installedPackages = pm.getInstalledPackages(PackageManager.GET_META_DATA);
171176
Collections.sort(installedPackages, new Comparator<PackageInfo>() {
172177
@Override
173178
public int compare(PackageInfo o1, PackageInfo o2) {
174-
String t1 = o1.applicationInfo.loadLabel(pm).toString();
175-
String t2 = o2.applicationInfo.loadLabel(pm).toString();
176-
return t1.compareTo(t2);
179+
if (sortBy == MyApplication.AppSortBy.APPNAME) {
180+
String t1 = o1.applicationInfo.loadLabel(pm).toString();
181+
String t2 = o2.applicationInfo.loadLabel(pm).toString();
182+
return t1.compareTo(t2);
183+
}
184+
else {
185+
String t1 = o1.packageName;
186+
String t2 = o2.packageName;
187+
return t1.compareTo(t2);
188+
}
177189
}
178190
});
179191
for (final PackageInfo pi : installedPackages) {
@@ -234,9 +246,20 @@ private void storeSelectedPackageSet(final Set<String> set) {
234246
@Override
235247
public boolean onOptionsItemSelected(MenuItem item) {
236248
int id = item.getItemId();
237-
if (id == android.R.id.home) {
238-
startActivity(new Intent(getActivity(), SimplePreferenceActivity.class));
239-
return true;
249+
switch (id) {
250+
case android.R.id.home:
251+
startActivity(new Intent(getActivity(), SimplePreferenceActivity.class));
252+
return true;
253+
case R.id.menu_sort_app_name:
254+
item.setChecked(!item.isChecked());
255+
this.appSortBy = MyApplication.AppSortBy.APPNAME;
256+
filter(null, this.appSortBy);
257+
break;
258+
case R.id.menu_sort_pkg_name:
259+
item.setChecked(!item.isChecked());
260+
this.appSortBy = MyApplication.AppSortBy.PKGNAME;
261+
filter(null, this.appSortBy);
262+
break;
240263
}
241264
return super.onOptionsItemSelected(item);
242265
}

android_app/app/src/main/res/menu/menu_search.xml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,21 @@
22
<menu
33
xmlns:android="http://schemas.android.com/apk/res/android"
44
xmlns:app="http://schemas.android.com/apk/res-auto">
5-
<item android:id="@+id/search_menu_item"
5+
<item android:id="@+id/menu_search_item"
66
android:title="@string/search"
77
android:icon="@android:drawable/ic_menu_search"
88
app:showAsAction="always"
99
android:orderInCategory="100"
1010
app:actionViewClass="android.widget.SearchView" />
11+
<group android:checkableBehavior="single">
12+
<item
13+
android:id="@+id/menu_sort_app_name"
14+
android:checked="true"
15+
android:title="sort by app name"
16+
app:showAsAction="never" />
17+
<item
18+
android:id="@+id/menu_sort_pkg_name"
19+
android:title="sort by package name"
20+
app:showAsAction="never" />
21+
</group>
1122
</menu>

android_app/gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ org.gradle.jvmargs=-Xmx1536m
1313
# org.gradle.parallel=true
1414

1515
APP_NAME=TunProxy
16-
VERSION_NAME=1.1.0
16+
VERSION_NAME=1.1.1
1717

1818
productKeyStore=../androidkeystore.jks
1919
productKeyAlias=key0

images/Menu-Settings-SoertBy.png

115 KB
Loading

images/Menu-Settings-app.png

-124 KB
Loading

0 commit comments

Comments
 (0)