forked from HMBSbige/ShadowsocksR-Android
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
35 additions
and
134 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,4 @@ | ||
package com.github.shadowsocks; | ||
/* | ||
* Shadowsocks - A shadowsocks client for Android | ||
* Copyright (C) 2014 <[email protected]> | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
* | ||
* ___====-_ _-====___ | ||
* _--^^^#####// \\#####^^^--_ | ||
* _-^##########// ( ) \\##########^-_ | ||
* -############// |\^^/| \\############- | ||
* _/############// (@::@) \\############\_ | ||
* /#############(( \\// ))#############\ | ||
* -###############\\ (oo) //###############- | ||
* -#################\\ / VV \ //#################- | ||
* -###################\\/ \//###################- | ||
* _#/|##########/\######( /\ )######/\##########|\#_ | ||
* |/ |#/\#/\#/\/ \#/\##\ | | /##/\#/ \/\#/\#/\#| \| | ||
* ` |/ V V ` V \#\| | | |/#/ V ' V V \| ' | ||
* ` ` ` ` / | | | | \ ' ' ' ' | ||
* ( | | | | ) | ||
* __\ | | | | /__ | ||
* (vvv(VVV)(VVV)vvv) | ||
* | ||
* HERE BE DRAGONS | ||
* | ||
*/ | ||
|
||
import android.app.ProgressDialog; | ||
import android.app.backup.BackupManager; | ||
|
@@ -68,7 +30,6 @@ | |
import com.github.jorgecastilloprz.FABProgressCircle; | ||
import com.github.shadowsocks.aidl.IShadowsocksServiceCallback; | ||
import com.github.shadowsocks.database.Profile; | ||
import com.github.shadowsocks.database.SSRSub; | ||
import com.github.shadowsocks.job.SSRSubUpdateJob; | ||
import com.github.shadowsocks.network.request.RequestCallback; | ||
import com.github.shadowsocks.network.request.RequestHelper; | ||
|
@@ -94,7 +55,6 @@ public class Shadowsocks extends AppCompatActivity { | |
private ProgressDialog progressDialog; | ||
private int state = Constants.State.STOPPED; | ||
private ServiceBoundContext mServiceBoundContext; | ||
private boolean isDestroyed; | ||
private boolean isTestConnect; | ||
private View stat; | ||
private TextView connectionTestText; | ||
|
@@ -215,10 +175,6 @@ public void attachService() { | |
mServiceBoundContext.attachService(callback); | ||
} | ||
|
||
public void detachService() { | ||
mServiceBoundContext.detachService(); | ||
} | ||
|
||
private void changeSwitch(boolean checked) { | ||
serviceStarted = checked; | ||
int resId = checked ? R.drawable.ic_start_connected : R.drawable.ic_start_idle; | ||
|
@@ -298,11 +254,6 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { | |
|
||
updateTraffic(0, 0, 0, 0); | ||
|
||
// ssr sub handler | ||
SSRSub first = ShadowsocksApplication.Companion.getApp().getSsrSubManager().getFirstSSRSub(); | ||
// if (first == null) { | ||
// ShadowsocksApplication.app.ssrSubManager.createDefault(); | ||
// } | ||
SSRSubUpdateJob.Companion.schedule(); | ||
|
||
|
||
|
@@ -405,6 +356,7 @@ private void updateState(boolean resetConnectionTest) { | |
int state = mServiceBoundContext.getBgService().getState(); | ||
switch (state) { | ||
case Constants.State.CONNECTING: | ||
case Constants.State.STOPPING: | ||
fab.setBackgroundTintList(greyTint); | ||
serviceStarted = false; | ||
fab.setImageResource(R.drawable.ic_start_busy); | ||
|
@@ -424,14 +376,6 @@ private void updateState(boolean resetConnectionTest) { | |
connectionTestText.setText(getString(R.string.connection_test_pending)); | ||
} | ||
break; | ||
case Constants.State.STOPPING: | ||
fab.setBackgroundTintList(greyTint); | ||
serviceStarted = false; | ||
fab.setImageResource(R.drawable.ic_start_busy); | ||
preferences.setEnabled(false); | ||
fabProgressCircle.show(); | ||
stat.setVisibility(View.GONE); | ||
break; | ||
default: | ||
fab.setBackgroundTintList(greyTint); | ||
serviceStarted = false; | ||
|
@@ -449,7 +393,7 @@ private void updateState(boolean resetConnectionTest) { | |
|
||
private boolean updateCurrentProfile() { | ||
// Check if current profile changed | ||
if (preferences.profile == null || ShadowsocksApplication.Companion.getApp().profileId() != preferences.profile.getId()) { | ||
if (preferences.currentProfile == null || ShadowsocksApplication.Companion.getApp().profileId() != preferences.currentProfile.getId()) { | ||
// updated | ||
Profile profile = ShadowsocksApplication.Companion.getApp().currentProfile(); | ||
if (profile == null) { | ||
|
@@ -504,17 +448,12 @@ protected void onStop() { | |
|
||
@Override | ||
public boolean isDestroyed() { | ||
if (Build.VERSION.SDK_INT >= 17) { | ||
return super.isDestroyed(); | ||
} else { | ||
return isDestroyed; | ||
} | ||
return super.isDestroyed(); | ||
} | ||
|
||
@Override | ||
protected void onDestroy() { | ||
super.onDestroy(); | ||
isDestroyed = true; | ||
mServiceBoundContext.detachService(); | ||
new BackupManager(this).dataChanged(); | ||
handler.removeCallbacksAndMessages(null); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,4 @@ | ||
package com.github.shadowsocks; | ||
/* | ||
* Shadowsocks - A shadowsocks client for Android | ||
* Copyright (C) 2014 <[email protected]> | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
* | ||
* ___====-_ _-====___ | ||
* _--^^^#####// \\#####^^^--_ | ||
* _-^##########// ( ) \\##########^-_ | ||
* -############// |\^^/| \\############- | ||
* _/############// (@::@) \\############\_ | ||
* /#############(( \\// ))#############\ | ||
* -###############\\ (oo) //###############- | ||
* -#################\\ / VV \ //#################- | ||
* -###################\\/ \//###################- | ||
* _#/|##########/\######( /\ )######/\##########|\#_ | ||
* |/ |#/\#/\#/\/ \#/\##\ | | /##/\#/ \/\#/\#/\#| \| | ||
* ` |/ V V ` V \#\| | | |/#/ V ' V V \| ' | ||
* ` ` ` ` / | | | | \ ' ' ' ' | ||
* ( | | | | ) | ||
* __\ | | | | /__ | ||
* (vvv(VVV)(VVV)vvv) | ||
* | ||
* HERE BE DRAGONS | ||
* | ||
*/ | ||
|
||
import android.app.ProgressDialog; | ||
import android.content.Intent; | ||
|
@@ -95,7 +57,7 @@ public class ShadowsocksSettings extends PreferenceFragment implements SharedPre | |
private static final String[] FEATURE_PREFS = { | ||
Constants.Key.route, Constants.Key.proxyApps, | ||
Constants.Key.udpdns, Constants.Key.ipv6}; | ||
public Profile profile; | ||
public Profile currentProfile; | ||
private Shadowsocks activity; | ||
private SwitchPreference isProxyApps; | ||
|
||
|
@@ -169,59 +131,59 @@ public void onCreate(@Nullable Bundle savedInstanceState) { | |
activity = (Shadowsocks) getActivity(); | ||
|
||
findPreference(Constants.Key.group_name).setOnPreferenceChangeListener((preference, value) -> { | ||
profile.setUrl_group((String) value); | ||
return ShadowsocksApplication.Companion.getApp().getProfileManager().updateProfile(profile); | ||
currentProfile.setUrl_group((String) value); | ||
return ShadowsocksApplication.Companion.getApp().getProfileManager().updateProfile(currentProfile); | ||
}); | ||
findPreference(Constants.Key.name).setOnPreferenceChangeListener((preference, value) -> { | ||
profile.setName((String) value); | ||
return ShadowsocksApplication.Companion.getApp().getProfileManager().updateProfile(profile); | ||
currentProfile.setName((String) value); | ||
return ShadowsocksApplication.Companion.getApp().getProfileManager().updateProfile(currentProfile); | ||
}); | ||
findPreference(Constants.Key.host).setOnPreferenceClickListener(preference -> { | ||
LayoutInflater li = LayoutInflater.from(activity); | ||
final View myView = li.inflate(R.layout.layout_edittext, null); | ||
final EditText HostEditText = myView.findViewById(R.id.editTextInput); | ||
HostEditText.setText(profile.getHost()); | ||
HostEditText.setText(currentProfile.getHost()); | ||
new AlertDialog.Builder(activity) | ||
.setView(myView) | ||
.setTitle(getString(R.string.proxy)) | ||
.setPositiveButton(android.R.string.ok, (dialog, which) -> { | ||
profile.setHost(HostEditText.getText().toString()); | ||
ShadowsocksApplication.Companion.getApp().getProfileManager().updateProfile(profile); | ||
currentProfile.setHost(HostEditText.getText().toString()); | ||
ShadowsocksApplication.Companion.getApp().getProfileManager().updateProfile(currentProfile); | ||
}) | ||
.setNegativeButton(android.R.string.no, (dialog, which) -> setProfile(profile)).create().show(); | ||
.setNegativeButton(android.R.string.no, (dialog, which) -> setProfile(currentProfile)).create().show(); | ||
return true; | ||
}); | ||
findPreference(Constants.Key.remotePort).setOnPreferenceChangeListener((preference, value) -> { | ||
profile.setRemotePort((int) value); | ||
return ShadowsocksApplication.Companion.getApp().getProfileManager().updateProfile(profile); | ||
currentProfile.setRemotePort((int) value); | ||
return ShadowsocksApplication.Companion.getApp().getProfileManager().updateProfile(currentProfile); | ||
}); | ||
findPreference(Constants.Key.localPort).setOnPreferenceChangeListener((preference, value) -> { | ||
profile.setLocalPort((int) value); | ||
return ShadowsocksApplication.Companion.getApp().getProfileManager().updateProfile(profile); | ||
currentProfile.setLocalPort((int) value); | ||
return ShadowsocksApplication.Companion.getApp().getProfileManager().updateProfile(currentProfile); | ||
}); | ||
findPreference(Constants.Key.password).setOnPreferenceChangeListener((preference, value) -> { | ||
profile.setPassword((String) value); | ||
return ShadowsocksApplication.Companion.getApp().getProfileManager().updateProfile(profile); | ||
currentProfile.setPassword((String) value); | ||
return ShadowsocksApplication.Companion.getApp().getProfileManager().updateProfile(currentProfile); | ||
}); | ||
findPreference(Constants.Key.method).setOnPreferenceChangeListener((preference, value) -> { | ||
profile.setMethod((String) value); | ||
return ShadowsocksApplication.Companion.getApp().getProfileManager().updateProfile(profile); | ||
currentProfile.setMethod((String) value); | ||
return ShadowsocksApplication.Companion.getApp().getProfileManager().updateProfile(currentProfile); | ||
}); | ||
findPreference(Constants.Key.protocol).setOnPreferenceChangeListener((preference, value) -> { | ||
profile.setProtocol((String) value); | ||
return ShadowsocksApplication.Companion.getApp().getProfileManager().updateProfile(profile); | ||
currentProfile.setProtocol((String) value); | ||
return ShadowsocksApplication.Companion.getApp().getProfileManager().updateProfile(currentProfile); | ||
}); | ||
findPreference(Constants.Key.protocol_param).setOnPreferenceChangeListener((preference, value) -> { | ||
profile.setProtocol_param((String) value); | ||
return ShadowsocksApplication.Companion.getApp().getProfileManager().updateProfile(profile); | ||
currentProfile.setProtocol_param((String) value); | ||
return ShadowsocksApplication.Companion.getApp().getProfileManager().updateProfile(currentProfile); | ||
}); | ||
findPreference(Constants.Key.obfs).setOnPreferenceChangeListener((preference, value) -> { | ||
profile.setObfs((String) value); | ||
return ShadowsocksApplication.Companion.getApp().getProfileManager().updateProfile(profile); | ||
currentProfile.setObfs((String) value); | ||
return ShadowsocksApplication.Companion.getApp().getProfileManager().updateProfile(currentProfile); | ||
}); | ||
findPreference(Constants.Key.obfs_param).setOnPreferenceChangeListener((preference, value) -> { | ||
profile.setObfs_param((String) value); | ||
return ShadowsocksApplication.Companion.getApp().getProfileManager().updateProfile(profile); | ||
currentProfile.setObfs_param((String) value); | ||
return ShadowsocksApplication.Companion.getApp().getProfileManager().updateProfile(currentProfile); | ||
}); | ||
|
||
findPreference(Constants.Key.route).setOnPreferenceChangeListener((preference, value) -> { | ||
|
@@ -235,14 +197,14 @@ public void onCreate(@Nullable Bundle savedInstanceState) { | |
.setTitle(getString(R.string.acl_file)) | ||
.setPositiveButton(android.R.string.ok, (dialog, which) -> { | ||
if (TextUtils.isEmpty(AclUrlEditText.getText().toString())) { | ||
setProfile(profile); | ||
setProfile(currentProfile); | ||
} else { | ||
getPreferenceManager().getSharedPreferences().edit().putString(Constants.Key.aclurl, AclUrlEditText.getText().toString()).apply(); | ||
downloadAcl(AclUrlEditText.getText().toString()); | ||
ShadowsocksApplication.Companion.getApp().getProfileManager().updateAllProfileByString(Constants.Key.route, (String) value); | ||
} | ||
}) | ||
.setNegativeButton(android.R.string.no, (dialog, which) -> setProfile(profile)) | ||
.setNegativeButton(android.R.string.no, (dialog, which) -> setProfile(currentProfile)) | ||
.create().show(); | ||
} else { | ||
ShadowsocksApplication.Companion.getApp().getProfileManager().updateAllProfileByString(Constants.Key.route, (String) value); | ||
|
@@ -488,20 +450,20 @@ public void downloadAcl(final String url) { | |
public void refreshProfile() { | ||
Profile profile = ShadowsocksApplication.Companion.getApp().currentProfile(); | ||
if (profile != null) { | ||
this.profile = profile; | ||
this.currentProfile = profile; | ||
} else { | ||
Profile first = ShadowsocksApplication.Companion.getApp().getProfileManager().getFirstProfile(); | ||
if (first != null) { | ||
ShadowsocksApplication.Companion.getApp().profileId(first.getId()); | ||
this.profile = first; | ||
this.currentProfile = first; | ||
} else { | ||
Profile defaultProfile = ShadowsocksApplication.Companion.getApp().getProfileManager().createDefault(); | ||
ShadowsocksApplication.Companion.getApp().profileId(defaultProfile.getId()); | ||
this.profile = defaultProfile; | ||
this.currentProfile = defaultProfile; | ||
} | ||
} | ||
|
||
isProxyApps.setChecked(this.profile.getProxyApps()); | ||
isProxyApps.setChecked(this.currentProfile.getProxyApps()); | ||
} | ||
|
||
@Override | ||
|
@@ -528,7 +490,7 @@ public void setEnabled(boolean enabled) { | |
} | ||
|
||
public void setProfile(Profile profile) { | ||
this.profile = profile; | ||
this.currentProfile = profile; | ||
List<String> list = new ArrayList<>(); | ||
list.addAll(Arrays.asList(PROXY_PREFS)); | ||
list.addAll(Arrays.asList(FEATURE_PREFS)); | ||
|