From 85fc0785ecce91a50b573fa5d7172c0c31b04882 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Se=CC=81bastiaan?= Date: Tue, 29 Aug 2017 14:02:10 +0200 Subject: [PATCH] Update jlibtorrent and change download start behaviour --- build.gradle | 6 ++++- gradle/wrapper/gradle-wrapper.properties | 4 +-- library/build.gradle | 25 +++---------------- .../se_bastiaan/torrentstream/Torrent.java | 3 ++- .../torrentstream/TorrentOptions.java | 7 ++++++ .../torrentstream/TorrentStream.java | 8 ++++-- .../listeners/TorrentAddedAlertListener.java | 10 ++++---- .../torrentstreamer/sample/MainActivity.java | 3 ++- 8 files changed, 33 insertions(+), 33 deletions(-) diff --git a/build.gradle b/build.gradle index 32ed3fc..e16f197 100644 --- a/build.gradle +++ b/build.gradle @@ -3,9 +3,12 @@ buildscript { repositories { jcenter() + maven { url "https://maven.google.com" } } + dependencies { - classpath 'com.android.tools.build:gradle:2.3.0' + classpath 'com.android.tools.build:gradle:3.0.0-beta3' + classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.1' classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5' // NOTE: Do not place your application dependencies here; they belong @@ -16,6 +19,7 @@ buildscript { allprojects { repositories { jcenter() + maven { url "https://maven.google.com" } } } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index afd2655..b166153 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Sun Mar 26 22:21:22 CEST 2017 +#Tue Aug 29 13:27:24 CEST 2017 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip diff --git a/library/build.gradle b/library/build.gradle index 1a6a7ee..a0bfd8c 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -14,35 +14,18 @@ * limitations under the License. */ -buildscript { - repositories { - jcenter() - } - - - - dependencies { - classpath 'com.android.tools.build:gradle:2.3.0' - classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.0' - classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5' - - // NOTE: Do not place your application dependencies here; they belong - // in the individual module build.gradle files - } -} - apply plugin: 'com.android.library' apply plugin: 'com.github.dcendents.android-maven' group='com.github.se_bastiaan' android { - compileSdkVersion 25 - buildToolsVersion "25.0.2" + compileSdkVersion 26 + buildToolsVersion "26.0.0" defaultConfig { minSdkVersion 15 - targetSdkVersion 25 + targetSdkVersion 26 } buildTypes { @@ -58,7 +41,7 @@ android { } ext { - libtorrentVersion = '1.2.0.6' + libtorrentVersion = '1.2.0.12' } dependencies { diff --git a/library/src/main/java/com/github/se_bastiaan/torrentstream/Torrent.java b/library/src/main/java/com/github/se_bastiaan/torrentstream/Torrent.java index 653f5a4..08162cb 100644 --- a/library/src/main/java/com/github/se_bastiaan/torrentstream/Torrent.java +++ b/library/src/main/java/com/github/se_bastiaan/torrentstream/Torrent.java @@ -19,6 +19,7 @@ import com.frostwire.jlibtorrent.AlertListener; import com.frostwire.jlibtorrent.FileStorage; import com.frostwire.jlibtorrent.Priority; +import com.frostwire.jlibtorrent.TorrentFlags; import com.frostwire.jlibtorrent.TorrentHandle; import com.frostwire.jlibtorrent.TorrentInfo; import com.frostwire.jlibtorrent.TorrentStatus; @@ -402,7 +403,7 @@ private void startSequentialMode() { resetPriorities(); if (hasPieces == null) { - torrentHandle.setSequentialDownload(true); + torrentHandle.setFlags(torrentHandle.flags().and_(TorrentFlags.SEQUENTIAL_DOWNLOAD)); } else { for (int i = firstPieceIndex + piecesToPrepare; i < firstPieceIndex + piecesToPrepare + SEQUENTIAL_CONCURRENT_PIECES_COUNT; i++) { torrentHandle.piecePriority(i, Priority.SEVEN); diff --git a/library/src/main/java/com/github/se_bastiaan/torrentstream/TorrentOptions.java b/library/src/main/java/com/github/se_bastiaan/torrentstream/TorrentOptions.java index e83cfd9..9c9e1f2 100644 --- a/library/src/main/java/com/github/se_bastiaan/torrentstream/TorrentOptions.java +++ b/library/src/main/java/com/github/se_bastiaan/torrentstream/TorrentOptions.java @@ -32,6 +32,7 @@ public final class TorrentOptions { protected Integer listeningPort = -1; protected Boolean removeFiles = false; protected Boolean anonymousMode = false; + protected Boolean autoDownload = true; protected Long prepareSize = 15 * 1024L * 1024L; private TorrentOptions() { @@ -51,6 +52,7 @@ private TorrentOptions(TorrentOptions torrentOptions) { this.listeningPort = torrentOptions.listeningPort; this.removeFiles = torrentOptions.removeFiles; this.anonymousMode = torrentOptions.anonymousMode; + this.autoDownload = torrentOptions.autoDownload; this.prepareSize = torrentOptions.prepareSize; } @@ -135,6 +137,11 @@ public Builder anonymousMode(Boolean enable) { return this; } + public Builder autoDownload(Boolean enable) { + torrentOptions.autoDownload = enable; + return this; + } + public TorrentOptions build() { return torrentOptions; } diff --git a/library/src/main/java/com/github/se_bastiaan/torrentstream/TorrentStream.java b/library/src/main/java/com/github/se_bastiaan/torrentstream/TorrentStream.java index a59bee0..e58fa7a 100644 --- a/library/src/main/java/com/github/se_bastiaan/torrentstream/TorrentStream.java +++ b/library/src/main/java/com/github/se_bastiaan/torrentstream/TorrentStream.java @@ -26,7 +26,7 @@ import com.frostwire.jlibtorrent.SettingsPack; import com.frostwire.jlibtorrent.TorrentHandle; import com.frostwire.jlibtorrent.TorrentInfo; -import com.frostwire.jlibtorrent.alerts.TorrentAddedAlert; +import com.frostwire.jlibtorrent.alerts.AddTorrentAlert; import com.frostwire.jlibtorrent.swig.settings_pack; import com.github.se_bastiaan.torrentstream.exceptions.DirectoryModifyException; import com.github.se_bastiaan.torrentstream.exceptions.NotInitializedException; @@ -77,7 +77,7 @@ public void stats(int totalDhtNodes) { private final TorrentAddedAlertListener torrentAddedAlertListener = new TorrentAddedAlertListener() { @Override - public void torrentAdded(TorrentAddedAlert alert) { + public void torrentAdded(AddTorrentAlert alert) { InternalTorrentListener listener = new InternalTorrentListener(); TorrentHandle th = torrentSession.find(alert.handle().infoHash()); currentTorrent = new Torrent(th, listener, torrentOptions.prepareSize); @@ -521,6 +521,10 @@ public void onStreamStopped() { @Override public void onStreamPrepared(final Torrent torrent) { + if (torrentOptions.autoDownload) { + torrent.startDownload(); + } + for (final TorrentListener listener : listeners) { ThreadUtils.runOnUiThread(new Runnable() { @Override diff --git a/library/src/main/java/com/github/se_bastiaan/torrentstream/listeners/TorrentAddedAlertListener.java b/library/src/main/java/com/github/se_bastiaan/torrentstream/listeners/TorrentAddedAlertListener.java index 156bc3e..7819bc6 100644 --- a/library/src/main/java/com/github/se_bastiaan/torrentstream/listeners/TorrentAddedAlertListener.java +++ b/library/src/main/java/com/github/se_bastiaan/torrentstream/listeners/TorrentAddedAlertListener.java @@ -17,26 +17,26 @@ package com.github.se_bastiaan.torrentstream.listeners; import com.frostwire.jlibtorrent.AlertListener; +import com.frostwire.jlibtorrent.alerts.AddTorrentAlert; import com.frostwire.jlibtorrent.alerts.Alert; import com.frostwire.jlibtorrent.alerts.AlertType; -import com.frostwire.jlibtorrent.alerts.TorrentAddedAlert; public abstract class TorrentAddedAlertListener implements AlertListener { @Override public int[] types() { - return new int[]{AlertType.TORRENT_ADDED.swig()}; + return new int[]{AlertType.ADD_TORRENT.swig()}; } @Override public void alert(Alert alert) { switch (alert.type()) { - case TORRENT_ADDED: - torrentAdded((TorrentAddedAlert) alert); + case ADD_TORRENT: + torrentAdded((AddTorrentAlert) alert); break; default: break; } } - public abstract void torrentAdded(TorrentAddedAlert alert); + public abstract void torrentAdded(AddTorrentAlert alert); } diff --git a/sample/src/main/java/com/github/se_bastiaan/torrentstreamer/sample/MainActivity.java b/sample/src/main/java/com/github/se_bastiaan/torrentstreamer/sample/MainActivity.java index b6b37d5..9506ff1 100644 --- a/sample/src/main/java/com/github/se_bastiaan/torrentstreamer/sample/MainActivity.java +++ b/sample/src/main/java/com/github/se_bastiaan/torrentstreamer/sample/MainActivity.java @@ -108,7 +108,8 @@ protected void onResume() { @Override public void onStreamPrepared(Torrent torrent) { Log.d(TORRENT, "OnStreamPrepared"); - torrent.startDownload(); + // If you set TorrentOptions#autoDownload(false) then this is probably the place to call + // torrent.startDownload(); } @Override