Skip to content

Commit

Permalink
Rename
Browse files Browse the repository at this point in the history
  • Loading branch information
HMBSbige committed Nov 6, 2019
1 parent 8b94271 commit eb6ee9d
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 134 deletions.
67 changes: 3 additions & 64 deletions app/src/main/java/com/github/shadowsocks/Shadowsocks.java
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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();


Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand All @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down
102 changes: 32 additions & 70 deletions app/src/main/java/com/github/shadowsocks/ShadowsocksSettings.java
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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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) -> {
Expand All @@ -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);
Expand Down Expand Up @@ -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
Expand All @@ -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));
Expand Down

0 comments on commit eb6ee9d

Please sign in to comment.