Skip to content
This repository has been archived by the owner on May 7, 2023. It is now read-only.

Commit

Permalink
Update jlibtorrent and change download start behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
se-bastiaan committed Aug 29, 2017
1 parent bafe499 commit 85fc078
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 33 deletions.
6 changes: 5 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -16,6 +19,7 @@ buildscript {
allprojects {
repositories {
jcenter()
maven { url "https://maven.google.com" }
}
}

Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -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
25 changes: 4 additions & 21 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -58,7 +41,7 @@ android {
}

ext {
libtorrentVersion = '1.2.0.6'
libtorrentVersion = '1.2.0.12'
}

dependencies {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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;
}

Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 85fc078

Please sign in to comment.