diff options
author | Martin Fietz <martin.fietz@gmail.com> | 2018-01-14 17:47:43 +0100 |
---|---|---|
committer | Martin Fietz <martin.fietz@gmail.com> | 2018-01-14 17:47:43 +0100 |
commit | 332943effb89dcfb7aa05d85e7019abb70c965d6 (patch) | |
tree | eb459ac920efd0d2fbb871200af7feef87552f5d /app/src | |
parent | 7257a6c76e002e39eef8d1f28c70b654e9954d4e (diff) | |
download | AntennaPod-332943effb89dcfb7aa05d85e7019abb70c965d6.zip |
Replace anonymous type with lambda
Diffstat (limited to 'app/src')
3 files changed, 113 insertions, 125 deletions
diff --git a/app/src/androidTest/java/de/test/antennapod/util/service/download/NanoHTTPD.java b/app/src/androidTest/java/de/test/antennapod/util/service/download/NanoHTTPD.java index 28ff6694e..da79ec615 100644 --- a/app/src/androidTest/java/de/test/antennapod/util/service/download/NanoHTTPD.java +++ b/app/src/androidTest/java/de/test/antennapod/util/service/download/NanoHTTPD.java @@ -168,44 +168,38 @@ public abstract class NanoHTTPD { myServerSocket = new ServerSocket(); myServerSocket.bind((hostname != null) ? new InetSocketAddress(hostname, myPort) : new InetSocketAddress(myPort)); - myThread = new Thread(new Runnable() { - @Override - public void run() { - do { - try { - final Socket finalAccept = myServerSocket.accept(); - registerConnection(finalAccept); - finalAccept.setSoTimeout(SOCKET_READ_TIMEOUT); - final InputStream inputStream = finalAccept.getInputStream(); - asyncRunner.exec(new Runnable() { - @Override - public void run() { - OutputStream outputStream = null; - try { - outputStream = finalAccept.getOutputStream(); - TempFileManager tempFileManager = tempFileManagerFactory.create(); - HTTPSession session = new HTTPSession(tempFileManager, inputStream, outputStream, finalAccept.getInetAddress()); - while (!finalAccept.isClosed()) { - session.execute(); - } - } catch (Exception e) { - // When the socket is closed by the client, we throw our own SocketException - // to break the "keep alive" loop above. - if (!(e instanceof SocketException && "NanoHttpd Shutdown".equals(e.getMessage()))) { - e.printStackTrace(); - } - } finally { - safeClose(outputStream); - safeClose(inputStream); - safeClose(finalAccept); - unRegisterConnection(finalAccept); - } + myThread = new Thread(() -> { + do { + try { + final Socket finalAccept = myServerSocket.accept(); + registerConnection(finalAccept); + finalAccept.setSoTimeout(SOCKET_READ_TIMEOUT); + final InputStream inputStream = finalAccept.getInputStream(); + asyncRunner.exec(() -> { + OutputStream outputStream = null; + try { + outputStream = finalAccept.getOutputStream(); + TempFileManager tempFileManager = tempFileManagerFactory.create(); + HTTPSession session = new HTTPSession(tempFileManager, inputStream, outputStream, finalAccept.getInetAddress()); + while (!finalAccept.isClosed()) { + session.execute(); } - }); - } catch (IOException e) { - } - } while (!myServerSocket.isClosed()); - } + } catch (Exception e) { + // When the socket is closed by the client, we throw our own SocketException + // to break the "keep alive" loop above. + if (!(e instanceof SocketException && "NanoHttpd Shutdown".equals(e.getMessage()))) { + e.printStackTrace(); + } + } finally { + safeClose(outputStream); + safeClose(inputStream); + safeClose(finalAccept); + unRegisterConnection(finalAccept); + } + }); + } catch (IOException e) { + } + } while (!myServerSocket.isClosed()); }); myThread.setDaemon(true); myThread.setName("NanoHttpd Main Listener"); diff --git a/app/src/main/java/de/danoeh/antennapod/activity/AboutActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/AboutActivity.java index 1b42b274c..041053a25 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/AboutActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/AboutActivity.java @@ -75,53 +75,50 @@ public class AboutActivity extends AppCompatActivity { } private void loadAsset(String filename) { - subscription = Observable.create(new Observable.OnSubscribe<String>() { - @Override - public void call(Subscriber<? super String> subscriber) { - InputStream input = null; - try { - TypedArray res = AboutActivity.this.getTheme().obtainStyledAttributes( - new int[] { android.R.attr.textColorPrimary }); - int colorResource = res.getColor(0, 0); - String colorString = String.format("#%06X", 0xFFFFFF & colorResource); - res.recycle(); - input = getAssets().open(filename); - String webViewData = IOUtils.toString(input, Charset.defaultCharset()); - if(!webViewData.startsWith("<!DOCTYPE html>")) { - //webViewData = webViewData.replace("\n\n", "</p><p>"); - webViewData = webViewData.replace("%", "%"); - webViewData = - "<!DOCTYPE html>" + - "<html>" + - "<head>" + - " <meta http-equiv=\"Content-Type\" content=\"text/html;charset=UTF-8\">" + - " <style type=\"text/css\">" + - " @font-face {" + - " font-family: 'Roboto-Light';" + - " src: url('file:///android_asset/Roboto-Light.ttf');" + - " }" + - " * {" + - " color: %s;" + - " font-family: roboto-Light;" + - " font-size: 8pt;" + - " }" + - " </style>" + - "</head><body><p>" + webViewData + "</p></body></html>"; - webViewData = webViewData.replace("\n", "<br/>"); - depth++; - } else { - depth = 0; - } - webViewData = String.format(webViewData, colorString); - subscriber.onNext(webViewData); - } catch (IOException e) { - subscriber.onError(e); - } finally { - IOUtils.closeQuietly(input); - } - subscriber.onCompleted(); - } - }) + subscription = Observable.create((Observable.OnSubscribe<String>) subscriber -> { + InputStream input = null; + try { + TypedArray res = AboutActivity.this.getTheme().obtainStyledAttributes( + new int[] { android.R.attr.textColorPrimary }); + int colorResource = res.getColor(0, 0); + String colorString = String.format("#%06X", 0xFFFFFF & colorResource); + res.recycle(); + input = getAssets().open(filename); + String webViewData = IOUtils.toString(input, Charset.defaultCharset()); + if(!webViewData.startsWith("<!DOCTYPE html>")) { + //webViewData = webViewData.replace("\n\n", "</p><p>"); + webViewData = webViewData.replace("%", "%"); + webViewData = + "<!DOCTYPE html>" + + "<html>" + + "<head>" + + " <meta http-equiv=\"Content-Type\" content=\"text/html;charset=UTF-8\">" + + " <style type=\"text/css\">" + + " @font-face {" + + " font-family: 'Roboto-Light';" + + " src: url('file:///android_asset/Roboto-Light.ttf');" + + " }" + + " * {" + + " color: %s;" + + " font-family: roboto-Light;" + + " font-size: 8pt;" + + " }" + + " </style>" + + "</head><body><p>" + webViewData + "</p></body></html>"; + webViewData = webViewData.replace("\n", "<br/>"); + depth++; + } else { + depth = 0; + } + webViewData = String.format(webViewData, colorString); + subscriber.onNext(webViewData); + } catch (IOException e) { + subscriber.onError(e); + } finally { + IOUtils.closeQuietly(input); + } + subscriber.onCompleted(); + }) .subscribeOn(Schedulers.newThread()) .observeOn(AndroidSchedulers.mainThread()) .subscribe( diff --git a/app/src/main/java/de/danoeh/antennapod/dialog/ProxyDialog.java b/app/src/main/java/de/danoeh/antennapod/dialog/ProxyDialog.java index 0bd75b5b0..53d200991 100644 --- a/app/src/main/java/de/danoeh/antennapod/dialog/ProxyDialog.java +++ b/app/src/main/java/de/danoeh/antennapod/dialog/ProxyDialog.java @@ -243,47 +243,44 @@ public class ProxyDialog { txtvMessage.setTextColor(textColorPrimary); txtvMessage.setText("{fa-circle-o-notch spin} " + checking); txtvMessage.setVisibility(View.VISIBLE); - subscription = Observable.create(new Observable.OnSubscribe<Response>() { - @Override - public void call(Subscriber<? super Response> subscriber) { - String type = (String) spType.getSelectedItem(); - String host = etHost.getText().toString(); - String port = etPort.getText().toString(); - String username = etUsername.getText().toString(); - String password = etPassword.getText().toString(); - int portValue = 8080; - if(!TextUtils.isEmpty(port)) { - portValue = Integer.valueOf(port); - } - SocketAddress address = InetSocketAddress.createUnresolved(host, portValue); - Proxy.Type proxyType = Proxy.Type.valueOf(type.toUpperCase()); - Proxy proxy = new Proxy(proxyType, address); - OkHttpClient.Builder builder = AntennapodHttpClient.newBuilder() - .connectTimeout(10, TimeUnit.SECONDS) - .proxy(proxy); - builder.interceptors().clear(); - OkHttpClient client = builder.build(); - if(!TextUtils.isEmpty(username)) { - String credentials = Credentials.basic(username, password); - client.interceptors().add(chain -> { - Request request = chain.request().newBuilder() - .header("Proxy-Authorization", credentials).build(); - return chain.proceed(request); - }); - } - Request request = new Request.Builder() - .url("http://www.google.com") - .head() - .build(); - try { - Response response = client.newCall(request).execute(); - subscriber.onNext(response); - } catch(IOException e) { - subscriber.onError(e); - } - subscriber.onCompleted(); - } - }) + subscription = Observable.create((Observable.OnSubscribe<Response>) subscriber -> { + String type = (String) spType.getSelectedItem(); + String host = etHost.getText().toString(); + String port = etPort.getText().toString(); + String username = etUsername.getText().toString(); + String password = etPassword.getText().toString(); + int portValue = 8080; + if(!TextUtils.isEmpty(port)) { + portValue = Integer.valueOf(port); + } + SocketAddress address = InetSocketAddress.createUnresolved(host, portValue); + Proxy.Type proxyType = Proxy.Type.valueOf(type.toUpperCase()); + Proxy proxy = new Proxy(proxyType, address); + OkHttpClient.Builder builder = AntennapodHttpClient.newBuilder() + .connectTimeout(10, TimeUnit.SECONDS) + .proxy(proxy); + builder.interceptors().clear(); + OkHttpClient client = builder.build(); + if(!TextUtils.isEmpty(username)) { + String credentials = Credentials.basic(username, password); + client.interceptors().add(chain -> { + Request request = chain.request().newBuilder() + .header("Proxy-Authorization", credentials).build(); + return chain.proceed(request); + }); + } + Request request = new Request.Builder() + .url("http://www.google.com") + .head() + .build(); + try { + Response response = client.newCall(request).execute(); + subscriber.onNext(response); + } catch(IOException e) { + subscriber.onError(e); + } + subscriber.onCompleted(); + }) .subscribeOn(Schedulers.newThread()) .observeOn(AndroidSchedulers.mainThread()) .subscribe( |