Skip to content

Commit 3f71ddb

Browse files
committed
proxy test: small refactor
1 parent 09b2ce2 commit 3f71ddb

1 file changed

Lines changed: 13 additions & 9 deletions

File tree

common/src/main/java/com/liskovsoft/smartyoutubetv2/common/proxy/WebProxyDialog.java

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
import android.widget.EditText;
1010
import android.widget.RadioGroup;
1111
import android.widget.TextView;
12+
13+
import androidx.annotation.NonNull;
1214
import androidx.annotation.RequiresApi;
1315
import androidx.appcompat.app.AlertDialog;
1416
import com.liskovsoft.sharedutils.helpers.Helpers;
@@ -37,7 +39,7 @@ public class WebProxyDialog {
3739
public WebProxyDialog(Context context) {
3840
mContext = context;
3941
mProxyManager = new ProxyManager(mContext);
40-
mProxyTestHandler = new Handler(Looper.myLooper());
42+
mProxyTestHandler = new Handler(Looper.getMainLooper());
4143
mUrlTests = new ArrayList<>();
4244
}
4345

@@ -128,25 +130,27 @@ protected void testProxyConnections() {
128130

129131
for (String urlString: testUrls) {
130132
int serialNo = ++ mNumTests;
131-
Request request = new Request.Builder().url(urlString).build();
133+
Request request = new Request.Builder().url(urlString).head().build();
132134
appendStatusMessage(R.string.proxy_test_start, serialNo, urlString);
133135
Call call = okHttpClient.newCall(request);
134136
call.enqueue(new Callback() {
135137
@Override
136-
public void onFailure(Call call, IOException e) {
138+
public void onFailure(@NonNull Call call, @NonNull IOException e) {
137139
if (call.isCanceled())
138140
mProxyTestHandler.post(() -> appendStatusMessage(R.string.proxy_test_cancelled, serialNo));
139141
else
140142
mProxyTestHandler.post(() -> appendStatusMessage(R.string.proxy_test_error, serialNo, e));
141143
}
142144

143145
@Override
144-
public void onResponse(Call call, Response response) {
145-
String protocol = response.protocol().toString().toUpperCase();
146-
int code = response.code();
147-
String status = response.message();
148-
mProxyTestHandler.post(() -> appendStatusMessage(R.string.proxy_test_status,
149-
serialNo, protocol, code, status.isEmpty() ? "OK" : status));
146+
public void onResponse(@NonNull Call call, @NonNull Response response) {
147+
try (Response ignored = response) {
148+
String protocol = response.protocol().toString().toUpperCase();
149+
int code = response.code();
150+
String status = response.message();
151+
mProxyTestHandler.post(() -> appendStatusMessage(R.string.proxy_test_status,
152+
serialNo, protocol, code, status.isEmpty() ? "OK" : status));
153+
}
150154
}
151155
});
152156
mUrlTests.add(call);

0 commit comments

Comments
 (0)