老毛子代码写的还真是精致,在昨天把中文XML资源撸出来后,发现里面的代码写的还是挺有意思的,可读性很强。
今天继续研究设置代理的业务逻辑。
通过猜测,我们可知道ProxyListActivity.java就是设置代理的界面了,那么里面肯定有设置代理的代码,
public boolean onFragmentCreate() {
super.onFragmentCreate();
SharedConfig.loadProxyList(); // 这句是重点!!!!!
currentConnectionState = ConnectionsManager.getInstance(currentAccount).getConnectionState();
NotificationCenter.getGlobalInstance().addObserver(this, NotificationCenter.proxySettingsChanged);
NotificationCenter.getGlobalInstance().addObserver(this, NotificationCenter.proxyCheckDone);
NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.didUpdateConnectionState);
final SharedPreferences preferences = MessagesController.getGlobalMainSettings();
useProxySettings = preferences.getBoolean("proxy_enabled", false) && !SharedConfig.proxyList.isEmpty();
useProxyForCalls = preferences.getBoolean("proxy_enabled_calls", false);
updateRows(true);
return true;
}
通过上句我们发现了一个很有意思的类:SharedConfig, 通过名字我们可以猜测应该是共享的通用配置,就是多个账户公用信息。而每个账户也会有自己单独的信息,比如ConnectionManager等。
所以我们去看看 SharedConfig.loadProxyList(); 到底如何加载数据,并且看看这个公用配置里面有什么。
里面有个简单实体类:ProxyInfo,我们简单看一眼,大概也就知道什么意思。
public ProxyInfo(St