@@ -38,37 +38,41 @@ public final class ProxyUtils {
38
38
private static boolean sI2PHelperBound ;
39
39
private static boolean sI2PProxyInitialized ;
40
40
41
- @ Inject UserPreferences mUserPreferences ;
42
- @ Inject DeveloperPreferences mDeveloperPreferences ;
43
- @ Inject I2PAndroidHelper mI2PHelper ;
41
+ private final UserPreferences userPreferences ;
42
+ private final DeveloperPreferences developerPreferences ;
43
+ private final I2PAndroidHelper i2PAndroidHelper ;
44
44
45
45
@ Inject
46
- public ProxyUtils () {
47
- BrowserApp .getAppComponent ().inject (this );
46
+ public ProxyUtils (UserPreferences userPreferences ,
47
+ DeveloperPreferences developerPreferences ,
48
+ I2PAndroidHelper i2PAndroidHelper ) {
49
+ this .userPreferences = userPreferences ;
50
+ this .developerPreferences = developerPreferences ;
51
+ this .i2PAndroidHelper = i2PAndroidHelper ;
48
52
}
49
53
50
54
/*
51
55
* If Orbot/Tor or I2P is installed, prompt the user if they want to enable
52
56
* proxying for this session
53
57
*/
54
58
public void checkForProxy (@ NonNull final Activity activity ) {
55
- final ProxyChoice currentProxyChoice = mUserPreferences .getProxyChoice ();
59
+ final ProxyChoice currentProxyChoice = userPreferences .getProxyChoice ();
56
60
57
61
final boolean orbotInstalled = OrbotHelper .isOrbotInstalled (activity );
58
- boolean orbotChecked = mDeveloperPreferences .getCheckedForTor ();
62
+ boolean orbotChecked = developerPreferences .getCheckedForTor ();
59
63
boolean orbot = orbotInstalled && !orbotChecked ;
60
64
61
- boolean i2pInstalled = mI2PHelper .isI2PAndroidInstalled ();
62
- boolean i2pChecked = mDeveloperPreferences .getCheckedForI2P ();
65
+ boolean i2pInstalled = i2PAndroidHelper .isI2PAndroidInstalled ();
66
+ boolean i2pChecked = developerPreferences .getCheckedForI2P ();
63
67
boolean i2p = i2pInstalled && !i2pChecked ;
64
68
65
69
// Do only once per install
66
70
if (currentProxyChoice != ProxyChoice .NONE && (orbot || i2p )) {
67
71
if (orbot ) {
68
- mDeveloperPreferences .setCheckedForTor (true );
72
+ developerPreferences .setCheckedForTor (true );
69
73
}
70
74
if (i2p ) {
71
- mDeveloperPreferences .setCheckedForI2P (true );
75
+ developerPreferences .setCheckedForI2P (true );
72
76
}
73
77
AlertDialog .Builder builder = new AlertDialog .Builder (activity );
74
78
@@ -80,27 +84,27 @@ public void checkForProxy(@NonNull final Activity activity) {
80
84
list .add (new Pair <>(proxyChoice , proxyChoices [proxyChoice .getValue ()]));
81
85
}
82
86
builder .setTitle (activity .getResources ().getString (R .string .http_proxy ));
83
- AlertDialogExtensionsKt .withSingleChoiceItems (builder , list , mUserPreferences .getProxyChoice (), newProxyChoice -> {
84
- mUserPreferences .setProxyChoice (newProxyChoice );
87
+ AlertDialogExtensionsKt .withSingleChoiceItems (builder , list , userPreferences .getProxyChoice (), newProxyChoice -> {
88
+ userPreferences .setProxyChoice (newProxyChoice );
85
89
return Unit .INSTANCE ;
86
90
});
87
91
builder .setPositiveButton (activity .getResources ().getString (R .string .action_ok ),
88
92
(dialog , which ) -> {
89
- if (mUserPreferences .getProxyChoice () != ProxyChoice .NONE ) {
93
+ if (userPreferences .getProxyChoice () != ProxyChoice .NONE ) {
90
94
initializeProxy (activity );
91
95
}
92
96
});
93
97
} else {
94
98
DialogInterface .OnClickListener dialogClickListener = (dialog , which ) -> {
95
99
switch (which ) {
96
100
case DialogInterface .BUTTON_POSITIVE :
97
- mUserPreferences .setProxyChoice (orbotInstalled
101
+ userPreferences .setProxyChoice (orbotInstalled
98
102
? ProxyChoice .ORBOT
99
103
: ProxyChoice .I2P );
100
104
initializeProxy (activity );
101
105
break ;
102
106
case DialogInterface .BUTTON_NEGATIVE :
103
- mUserPreferences .setProxyChoice (ProxyChoice .NONE );
107
+ userPreferences .setProxyChoice (ProxyChoice .NONE );
104
108
break ;
105
109
}
106
110
};
@@ -121,7 +125,7 @@ private void initializeProxy(@NonNull Activity activity) {
121
125
String host ;
122
126
int port ;
123
127
124
- switch (mUserPreferences .getProxyChoice ()) {
128
+ switch (userPreferences .getProxyChoice ()) {
125
129
case NONE :
126
130
// We shouldn't be here
127
131
return ;
@@ -134,16 +138,16 @@ private void initializeProxy(@NonNull Activity activity) {
134
138
break ;
135
139
case I2P :
136
140
sI2PProxyInitialized = true ;
137
- if (sI2PHelperBound && !mI2PHelper .isI2PAndroidRunning ()) {
138
- mI2PHelper .requestI2PAndroidStart (activity );
141
+ if (sI2PHelperBound && !i2PAndroidHelper .isI2PAndroidRunning ()) {
142
+ i2PAndroidHelper .requestI2PAndroidStart (activity );
139
143
}
140
144
host = "localhost" ;
141
145
port = 4444 ;
142
146
break ;
143
147
default :
144
148
case MANUAL :
145
- host = mUserPreferences .getProxyHost ();
146
- port = mUserPreferences .getProxyPort ();
149
+ host = userPreferences .getProxyHost ();
150
+ port = userPreferences .getProxyPort ();
147
151
break ;
148
152
}
149
153
@@ -156,11 +160,11 @@ private void initializeProxy(@NonNull Activity activity) {
156
160
}
157
161
158
162
public boolean isProxyReady (@ NonNull Activity activity ) {
159
- if (mUserPreferences .getProxyChoice () == ProxyChoice .I2P ) {
160
- if (!mI2PHelper .isI2PAndroidRunning ()) {
163
+ if (userPreferences .getProxyChoice () == ProxyChoice .I2P ) {
164
+ if (!i2PAndroidHelper .isI2PAndroidRunning ()) {
161
165
ActivityExtensions .snackbar (activity , R .string .i2p_not_running );
162
166
return false ;
163
- } else if (!mI2PHelper .areTunnelsActive ()) {
167
+ } else if (!i2PAndroidHelper .areTunnelsActive ()) {
164
168
ActivityExtensions .snackbar (activity , R .string .i2p_tunnels_not_ready );
165
169
return false ;
166
170
}
@@ -170,7 +174,7 @@ public boolean isProxyReady(@NonNull Activity activity) {
170
174
}
171
175
172
176
public void updateProxySettings (@ NonNull Activity activity ) {
173
- if (mUserPreferences .getProxyChoice () != ProxyChoice .NONE ) {
177
+ if (userPreferences .getProxyChoice () != ProxyChoice .NONE ) {
174
178
initializeProxy (activity );
175
179
} else {
176
180
try {
@@ -184,17 +188,17 @@ public void updateProxySettings(@NonNull Activity activity) {
184
188
}
185
189
186
190
public void onStop () {
187
- mI2PHelper .unbind ();
191
+ i2PAndroidHelper .unbind ();
188
192
sI2PHelperBound = false ;
189
193
}
190
194
191
195
public void onStart (final Activity activity ) {
192
- if (mUserPreferences .getProxyChoice () == ProxyChoice .I2P ) {
196
+ if (userPreferences .getProxyChoice () == ProxyChoice .I2P ) {
193
197
// Try to bind to I2P Android
194
- mI2PHelper .bind (() -> {
198
+ i2PAndroidHelper .bind (() -> {
195
199
sI2PHelperBound = true ;
196
- if (sI2PProxyInitialized && !mI2PHelper .isI2PAndroidRunning ())
197
- mI2PHelper .requestI2PAndroidStart (activity );
200
+ if (sI2PProxyInitialized && !i2PAndroidHelper .isI2PAndroidRunning ())
201
+ i2PAndroidHelper .requestI2PAndroidStart (activity );
198
202
});
199
203
}
200
204
}
0 commit comments