Browse Source

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

pull/649/head
Eric Kok 5 months 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 @@
apply plugin: 'com.android.application' apply plugin: 'com.android.application'
android { android {
compileSdkVersion 31 compileSdkVersion 33
defaultConfig { defaultConfig {
minSdkVersion 15 minSdkVersion 21
targetSdkVersion 31 targetSdkVersion 33
versionCode 242 versionCode 242
versionName '2.5.22' versionName '2.5.22'
@ -80,26 +80,27 @@ android {
dependencies { dependencies {
// Android support // Android support
implementation 'androidx.appcompat:appcompat:1.2.0' implementation 'androidx.appcompat:appcompat:1.5.1'
implementation 'androidx.preference:preference:1.1.1' implementation 'androidx.preference:preference:1.2.0'
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.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 // Other
implementation 'org.androidannotations:androidannotations-api:4.7.0' implementation 'org.androidannotations:androidannotations-api:4.8.0'
implementation 'org.androidannotations:ormlite-api:4.7.0' implementation 'org.androidannotations:ormlite-api:4.8.0'
implementation 'com.j256.ormlite:ormlite-core:5.1' implementation 'com.j256.ormlite:ormlite-android:6.1'
implementation 'com.j256.ormlite:ormlite-android:5.1'
implementation 'com.nostra13.universalimageloader:universal-image-loader:1.9.5' implementation 'com.nostra13.universalimageloader:universal-image-loader:1.9.5'
implementation 'com.getbase:floatingactionbutton:1.10.1' implementation 'com.getbase:floatingactionbutton:1.10.1'
implementation 'com.nispok:snackbar:2.11.0' 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 'net.iharder:base64:2.3.9'
implementation('com.github.afollestad.material-dialogs:core:0.9.6.0@aar') { implementation('com.github.afollestad.material-dialogs:core:0.9.6.0@aar') {
transitive = true transitive = true
} }
implementation 'androidx.work:work-runtime:2.7.1' 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:androidannotations:4.8.0'
annotationProcessor 'org.androidannotations:ormlite:4.7.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> {
return name.compareTo(another.getName()); return name.compareTo(another.getName());
} }
@Override
public boolean equals(Object another) {
// compare names
return name.equals(((Label) another).getName());
}
@Override @Override
public int describeContents() { public int describeContents() {
return 0; return 0;

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

@ -136,6 +136,8 @@ public class BitCometAdapter implements IDaemonAdapter {
return new RetrieveTaskSuccessResult((RetrieveTask) task, parseXmlTorrents(xmlResult), return new RetrieveTaskSuccessResult((RetrieveTask) task, parseXmlTorrents(xmlResult),
null); null);
} }
} catch (DaemonException e) {
throw e;
} catch (Exception e) { } catch (Exception e) {
// it's probably an old client, parse HTML instead // it's probably an old client, parse HTML instead
String htmlResult = makeRequest(log, "/panel/task_list"); String htmlResult = makeRequest(log, "/panel/task_list");
@ -243,7 +245,7 @@ public class BitCometAdapter implements IDaemonAdapter {
task.getMethod() + " is not supported by " + getType())); task.getMethod() + " is not supported by " + getType()));
} }
} catch (DaemonException e) { } 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 {
// Make the request // Make the request
HttpResponse response = httpclient.execute(new HttpGet(buildWebUIUrl(url))); 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(); HttpEntity entity = response.getEntity();
if (entity != null) { if (entity != null) {
@ -309,6 +315,9 @@ public class BitCometAdapter implements IDaemonAdapter {
throw new DaemonException(ExceptionType.ConnectionError, e.toString()); throw new DaemonException(ExceptionType.ConnectionError, e.toString());
} catch (Exception e) { } catch (Exception e) {
log.d(LOG_NAME, "Error: " + e.toString()); log.d(LOG_NAME, "Error: " + e.toString());
if (e instanceof DaemonException) {
throw (DaemonException) e;
}
throw new DaemonException(ExceptionType.ConnectionError, e.toString()); 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 {
private int qbLowPriority = 1; private int qbLowPriority = 1;
private int qbNormalPriority = 2; private int qbNormalPriority = 2;
private int qbHighPriority = 7; private int qbHighPriority = 7;
// a cache of all labels on the server
private List<Label> labelList;
public QBittorrentAdapter(DaemonSettings settings) { public QBittorrentAdapter(DaemonSettings settings) {
this.settings = settings; this.settings = settings;
@ -245,7 +247,7 @@ public class QBittorrentAdapter implements IDaemonAdapter {
if (allLabelsResult == null) { if (allLabelsResult == null) {
allLabelsResult = new JSONArray(); allLabelsResult = new JSONArray();
} }
final List<Label> labelList = parseJsonLabels(allLabelsResult, allTorrentsResult); labelList = parseJsonLabels(allLabelsResult, allTorrentsResult);
return new RetrieveTaskSuccessResult((RetrieveTask) task, torrentsList, labelList); return new RetrieveTaskSuccessResult((RetrieveTask) task, torrentsList, labelList);
case GetTorrentDetails: case GetTorrentDetails:
@ -446,6 +448,20 @@ public class QBittorrentAdapter implements IDaemonAdapter {
case SetLabel: case SetLabel:
SetLabelTask labelTask = (SetLabelTask) task; 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) { if (version >= 40100) {
path = "/api/v2/torrents/setCategory"; path = "/api/v2/torrents/setCategory";
} else { } else {
@ -453,7 +469,7 @@ public class QBittorrentAdapter implements IDaemonAdapter {
} }
makeRequest(log, path, makeRequest(log, path,
new BasicNameValuePair("hashes", task.getTargetTorrent().getUniqueID()), new BasicNameValuePair("hashes", task.getTargetTorrent().getUniqueID()),
new BasicNameValuePair("category", labelTask.getNewLabel())); new BasicNameValuePair("category", newLabel));
return new DaemonTaskSuccessResult(task); return new DaemonTaskSuccessResult(task);
case SetDownloadLocation: case SetDownloadLocation:

Loading…
Cancel
Save