Skip to content

Commit

Permalink
support Clear all selection
Browse files Browse the repository at this point in the history
  • Loading branch information
isayan committed Jan 19, 2020
1 parent 11b1b68 commit 18cdd25
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 29 deletions.
2 changes: 1 addition & 1 deletion android_app/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ android {
applicationId "tun.proxy"
minSdkVersion 21
targetSdkVersion 27
versionCode 100014
versionCode 100015
versionName VERSION_NAME
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
externalNativeBuild {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package tun.proxy;

import android.app.AlertDialog;
import android.annotation.TargetApi;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
Expand Down Expand Up @@ -29,6 +31,7 @@ public class SimplePreferenceFragment extends PreferenceFragment
public static final String VPN_CONNECTION_MODE = "vpn_connection_mode";
public static final String VPN_DISALLOWED_APPLICATION_LIST = "vpn_disallowed_application_list";
public static final String VPN_ALLOWED_APPLICATION_LIST = "vpn_allowed_application_list";
public static final String VPN_CLEAR_ALL_SELECTION = "vpn_clear_all_selection";

@Override
public void onCreate(Bundle savedInstanceState) {
Expand All @@ -40,8 +43,10 @@ public void onCreate(Bundle savedInstanceState) {
final ListPreference prefPackage = (ListPreference) this.findPreference(VPN_CONNECTION_MODE);
final PreferenceScreen prefDisallow = (PreferenceScreen) findPreference(VPN_DISALLOWED_APPLICATION_LIST);
final PreferenceScreen prefAllow = (PreferenceScreen) findPreference(VPN_ALLOWED_APPLICATION_LIST);
final PreferenceScreen clearAllSelection = (PreferenceScreen) findPreference(VPN_CLEAR_ALL_SELECTION);
prefDisallow.setOnPreferenceClickListener(this);
prefAllow.setOnPreferenceClickListener(this);
clearAllSelection.setOnPreferenceClickListener(this);

prefPackage.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
Expand All @@ -63,6 +68,18 @@ public boolean onPreferenceChange(Preference preference, Object value) {
prefDisallow.setEnabled(MyApplication.VPNMode.DISALLOW.name().equals(prefPackage.getValue()));
prefAllow.setEnabled(MyApplication.VPNMode.ALLOW.name().equals(prefPackage.getValue()));

updateMenuItem();

}

private void updateMenuItem() {
final PreferenceScreen prefDisallow = (PreferenceScreen) findPreference(VPN_DISALLOWED_APPLICATION_LIST);
final PreferenceScreen prefAllow = (PreferenceScreen) findPreference(VPN_ALLOWED_APPLICATION_LIST);

int countDisallow = MyApplication.getInstance().loadVPNApplication(MyApplication.VPNMode.DISALLOW).size();
int countAllow = MyApplication.getInstance().loadVPNApplication(MyApplication.VPNMode.ALLOW).size();
prefDisallow.setTitle(getString(R.string.pref_disallowed_application_list) + String.format(" (%d)",countDisallow));
prefAllow.setTitle(getString(R.string.pref_allowed_application_list) + String.format(" (%d)",countAllow));
}

@Override
Expand All @@ -87,10 +104,29 @@ public boolean onPreferenceClick(Preference preference) {
case VPN_ALLOWED_APPLICATION_LIST:
transitionFragment(PackageListPreferenceFragment.newInstance(MyApplication.VPNMode.ALLOW));
break;
case VPN_CLEAR_ALL_SELECTION:
new AlertDialog.Builder(getActivity())
.setTitle(getString(R.string.title_activity_settings))
.setMessage(getString(R.string.pref_dialog_clear_all_application_msg))
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Set set = new HashSet();
MyApplication.getInstance().storeVPNApplication(MyApplication.VPNMode.ALLOW, set);
MyApplication.getInstance().storeVPNApplication(MyApplication.VPNMode.DISALLOW, set);
updateMenuItem();
}
})
.setNegativeButton("Cancel", null)
.show();

break;
}
return false;
}



private void transitionFragment(PreferenceFragment nextPreferenceFragment) {
// replaceによるFragmentの切り替えと、addToBackStackで戻るボタンを押した時に前のFragmentに戻るようにする
getFragmentManager()
Expand Down
23 changes: 9 additions & 14 deletions android_app/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
<string name="title_show_about">About</string>
<string name="title_activity_settings">Settings</string>


<!-- Category -->
<string name="search">Search</string>

<!-- Category -->
<string name="pref_header_allowed_application_list">Allowed application list</string>
<string name="pref_header_disallowed_application_list">Disallowed application list</string>
<string name="pref_dialog_clear_all_application_msg">Clear all selections of Allowed / Disallowed application list</string>

<string name="pref_vpn_connection_mode">Allowed / Disallowed Application</string>
<string-array name="pref_vpn_connection_name">
Expand All @@ -33,23 +33,18 @@

<string name="pref_allowed_application_list">allowed application list</string>

<string-array name="pref_allowed_application_name">
</string-array>
<string-array name="pref_allowed_application_value">
</string-array>
<string-array name="pref_allowed_application_name"> </string-array>
<string-array name="pref_allowed_application_value"></string-array>

<string name="pref_disallowed_application_list">disallowed application list</string>
<string-array name="pref_disallowed_application_name">
</string-array>
<string-array name="pref_disallowed_application_value">
</string-array>

<string-array name="pref_disallowed_application_name"></string-array>
<string-array name="pref_disallowed_application_value"></string-array>

<string name="pref_trusted_ca_list">trusted CA list</string>
<string-array name="pref_trusted_ca_name">
</string-array>

<string-array name="pref_trusted_ca_value">
</string-array>
<string-array name="pref_trusted_ca_name"></string-array>
<string-array name="pref_trusted_ca_value"></string-array>


</resources>
30 changes: 17 additions & 13 deletions android_app/app/src/main/res/xml/preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,23 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

<!--
<MultiSelectListPreference
android:key="vpn_allowed_application"
android:title="@string/pref_header_allowed_package_list"
android:entries="@array/pref_allowed_application_name"
android:entryValues="@array/pref_allowed_application_value" />
<MultiSelectListPreference
android:key="vpn_disallowed_application"
android:title="@string/pref_header_disallowed_package_list"
android:entries="@array/pref_disallowed_application_name"
android:entryValues="@array/pref_disallowed_application_value" />
-->
<PreferenceScreen
android:key="vpn_clear_all_selection"
android:title="Clear all selection" />

<!--
<MultiSelectListPreference
android:key="vpn_allowed_application"
android:title="@string/pref_header_allowed_package_list"
android:entries="@array/pref_allowed_application_name"
android:entryValues="@array/pref_allowed_application_value" />
<MultiSelectListPreference
android:key="vpn_disallowed_application"
android:title="@string/pref_header_disallowed_package_list"
android:entries="@array/pref_disallowed_application_name"
android:entryValues="@array/pref_disallowed_application_value" />
-->
</PreferenceCategory>
<!--
<PreferenceCategory
Expand Down
2 changes: 1 addition & 1 deletion android_app/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ org.gradle.jvmargs=-Xmx1536m
# org.gradle.parallel=true

APP_NAME=TunProxy
VERSION_NAME=1.1.4
VERSION_NAME=1.1.5

productKeyStore=../androidkeystore.jks
productKeyAlias=key0
Expand Down

0 comments on commit 18cdd25

Please sign in to comment.