Browse Source

Merge branch 'master' into switch-to-work-manager

pull/649/head
Eric Kok 1 year ago committed by GitHub
parent
commit
9b293ecbca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 27
      app/build.gradle
  2. 6
      app/src/main/java/org/transdroid/daemon/Label.java
  3. 11
      app/src/main/java/org/transdroid/daemon/adapters/bitComet/BitCometAdapter.java
  4. 20
      app/src/main/java/org/transdroid/daemon/adapters/qBittorrent/QBittorrentAdapter.java

27
app/build.gradle

@ -1,11 +1,11 @@ @@ -1,11 +1,11 @@
apply plugin: 'com.android.application'
android {
compileSdkVersion 31
compileSdkVersion 33
defaultConfig {
minSdkVersion 15
targetSdkVersion 31
minSdkVersion 21
targetSdkVersion 33
versionCode 242
versionName '2.5.22'
@ -80,26 +80,27 @@ android { @@ -80,26 +80,27 @@ android {
dependencies {
// Android support
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.preference:preference:1.1.1'
implementation 'androidx.appcompat:appcompat:1.5.1'
implementation 'androidx.preference:preference:1.2.0'
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'
implementation 'com.google.android.material:material:1.3.0'
implementation 'com.google.android.material:material:1.7.0'
// Other
implementation 'org.androidannotations:androidannotations-api:4.7.0'
implementation 'org.androidannotations:ormlite-api:4.7.0'
implementation 'com.j256.ormlite:ormlite-core:5.1'
implementation 'com.j256.ormlite:ormlite-android:5.1'
implementation 'org.androidannotations:androidannotations-api:4.8.0'
implementation 'org.androidannotations:ormlite-api:4.8.0'
implementation 'com.j256.ormlite:ormlite-android:6.1'
implementation 'com.nostra13.universalimageloader:universal-image-loader:1.9.5'
implementation 'com.getbase:floatingactionbutton:1.10.1'
implementation 'com.nispok:snackbar:2.11.0'
implementation 'org.apache.openjpa:openjpa-lib:3.1.1'
implementation 'org.apache.openjpa:openjpa-lib:3.2.2'
implementation 'net.iharder:base64:2.3.9'
implementation('com.github.afollestad.material-dialogs:core:0.9.6.0@aar') {
transitive = true
}
implementation 'androidx.work:work-runtime:2.7.1'
implementation "androidx.lifecycle:lifecycle-viewmodel:2.5.1"
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.5.1"
annotationProcessor 'org.androidannotations:androidannotations:4.7.0'
annotationProcessor 'org.androidannotations:ormlite:4.7.0'
annotationProcessor 'org.androidannotations:androidannotations:4.8.0'
annotationProcessor 'org.androidannotations:ormlite:4.8.0'
}

6
app/src/main/java/org/transdroid/daemon/Label.java

@ -69,6 +69,12 @@ public final class Label implements Parcelable, Comparable<Label> { @@ -69,6 +69,12 @@ public final class Label implements Parcelable, Comparable<Label> {
return name.compareTo(another.getName());
}
@Override
public boolean equals(Object another) {
// compare names
return name.equals(((Label) another).getName());
}
@Override
public int describeContents() {
return 0;

11
app/src/main/java/org/transdroid/daemon/adapters/bitComet/BitCometAdapter.java

@ -136,6 +136,8 @@ public class BitCometAdapter implements IDaemonAdapter { @@ -136,6 +136,8 @@ public class BitCometAdapter implements IDaemonAdapter {
return new RetrieveTaskSuccessResult((RetrieveTask) task, parseXmlTorrents(xmlResult),
null);
}
} catch (DaemonException e) {
throw e;
} catch (Exception e) {
// it's probably an old client, parse HTML instead
String htmlResult = makeRequest(log, "/panel/task_list");
@ -243,7 +245,7 @@ public class BitCometAdapter implements IDaemonAdapter { @@ -243,7 +245,7 @@ public class BitCometAdapter implements IDaemonAdapter {
task.getMethod() + " is not supported by " + getType()));
}
} catch (DaemonException e) {
return new DaemonTaskFailureResult(task, new DaemonException(ExceptionType.ParsingFailed, e.toString()));
return new DaemonTaskFailureResult(task, e);
}
}
@ -290,6 +292,10 @@ public class BitCometAdapter implements IDaemonAdapter { @@ -290,6 +292,10 @@ public class BitCometAdapter implements IDaemonAdapter {
// Make the request
HttpResponse response = httpclient.execute(new HttpGet(buildWebUIUrl(url)));
int statusCode = response.getStatusLine().getStatusCode();
if (statusCode == 401 || statusCode == 403) {
throw new DaemonException(ExceptionType.AuthenticationFailure, "Response code " + statusCode);
}
HttpEntity entity = response.getEntity();
if (entity != null) {
@ -309,6 +315,9 @@ public class BitCometAdapter implements IDaemonAdapter { @@ -309,6 +315,9 @@ public class BitCometAdapter implements IDaemonAdapter {
throw new DaemonException(ExceptionType.ConnectionError, e.toString());
} catch (Exception e) {
log.d(LOG_NAME, "Error: " + e.toString());
if (e instanceof DaemonException) {
throw (DaemonException) e;
}
throw new DaemonException(ExceptionType.ConnectionError, e.toString());
}

20
app/src/main/java/org/transdroid/daemon/adapters/qBittorrent/QBittorrentAdapter.java

@ -94,6 +94,8 @@ public class QBittorrentAdapter implements IDaemonAdapter { @@ -94,6 +94,8 @@ public class QBittorrentAdapter implements IDaemonAdapter {
private int qbLowPriority = 1;
private int qbNormalPriority = 2;
private int qbHighPriority = 7;
// a cache of all labels on the server
private List<Label> labelList;
public QBittorrentAdapter(DaemonSettings settings) {
this.settings = settings;
@ -245,7 +247,7 @@ public class QBittorrentAdapter implements IDaemonAdapter { @@ -245,7 +247,7 @@ public class QBittorrentAdapter implements IDaemonAdapter {
if (allLabelsResult == null) {
allLabelsResult = new JSONArray();
}
final List<Label> labelList = parseJsonLabels(allLabelsResult, allTorrentsResult);
labelList = parseJsonLabels(allLabelsResult, allTorrentsResult);
return new RetrieveTaskSuccessResult((RetrieveTask) task, torrentsList, labelList);
case GetTorrentDetails:
@ -446,6 +448,20 @@ public class QBittorrentAdapter implements IDaemonAdapter { @@ -446,6 +448,20 @@ public class QBittorrentAdapter implements IDaemonAdapter {
case SetLabel:
SetLabelTask labelTask = (SetLabelTask) task;
String newLabel = labelTask.getNewLabel();
if (version >= 30200) {
if (!labelList.contains(new Label(newLabel, 0))) {
// create new label on server side
if (version >= 40100) {
path = "/api/v2/torrents/createCategory";
} else {
path = "/command/addCategory";
}
makeRequest(log, path,
new BasicNameValuePair("category", newLabel));
}
}
if (version >= 40100) {
path = "/api/v2/torrents/setCategory";
} else {
@ -453,7 +469,7 @@ public class QBittorrentAdapter implements IDaemonAdapter { @@ -453,7 +469,7 @@ public class QBittorrentAdapter implements IDaemonAdapter {
}
makeRequest(log, path,
new BasicNameValuePair("hashes", task.getTargetTorrent().getUniqueID()),
new BasicNameValuePair("category", labelTask.getNewLabel()));
new BasicNameValuePair("category", newLabel));
return new DaemonTaskSuccessResult(task);
case SetDownloadLocation:

Loading…
Cancel
Save