Browse Source

Another attempt to fix the localized qBittorrent issues as referenced in #115 and hopefully fixes #142. Who would think of localizing JSON?

pull/148/merge
Eric Kok 11 years ago
parent
commit
e4b5bc4dc1
  1. 2
      core/src/org/transdroid/core/gui/settings/RssfeedSettingsActivity.java
  2. 2
      core/src/org/transdroid/core/gui/settings/ServerSettingsActivity.java
  3. 2
      core/src/org/transdroid/core/gui/settings/WebsearchSettingsActivity.java
  4. 40
      lib/src/org/transdroid/daemon/Qbittorrent/QbittorrentAdapter.java

2
core/src/org/transdroid/core/gui/settings/RssfeedSettingsActivity.java

@ -20,7 +20,7 @@ import org.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.OptionsItem; import org.androidannotations.annotations.OptionsItem;
import org.androidannotations.annotations.OptionsMenu; import org.androidannotations.annotations.OptionsMenu;
import org.transdroid.core.R; import org.transdroid.core.R;
import org.transdroid.core.app.settings.ApplicationSettings_; import org.transdroid.core.app.settings.*;
import android.annotation.TargetApi; import android.annotation.TargetApi;
import android.app.AlertDialog; import android.app.AlertDialog;

2
core/src/org/transdroid/core/gui/settings/ServerSettingsActivity.java

@ -20,7 +20,7 @@ import org.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.OptionsItem; import org.androidannotations.annotations.OptionsItem;
import org.androidannotations.annotations.OptionsMenu; import org.androidannotations.annotations.OptionsMenu;
import org.transdroid.core.R; import org.transdroid.core.R;
import org.transdroid.core.app.settings.ApplicationSettings_; import org.transdroid.core.app.settings.*;
import org.transdroid.daemon.Daemon; import org.transdroid.daemon.Daemon;
import android.annotation.TargetApi; import android.annotation.TargetApi;

2
core/src/org/transdroid/core/gui/settings/WebsearchSettingsActivity.java

@ -20,7 +20,7 @@ import org.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.OptionsItem; import org.androidannotations.annotations.OptionsItem;
import org.androidannotations.annotations.OptionsMenu; import org.androidannotations.annotations.OptionsMenu;
import org.transdroid.core.R; import org.transdroid.core.R;
import org.transdroid.core.app.settings.ApplicationSettings_; import org.transdroid.core.app.settings.*;
import android.annotation.TargetApi; import android.annotation.TargetApi;
import android.app.AlertDialog; import android.app.AlertDialog;

40
lib/src/org/transdroid/daemon/Qbittorrent/QbittorrentAdapter.java

@ -399,9 +399,7 @@ public class QbittorrentAdapter implements IDaemonAdapter {
private double parseRatio(String string) { private double parseRatio(String string) {
// Ratio is given in "1.5" string format // Ratio is given in "1.5" string format
try { try {
// FIXME Hack for issue #115: Strip the possible . and , separators in a hopefully reliable fashion, for now return Double.parseDouble(normalizeNumber(string));
string = string.replace(",", ".");
return Double.parseDouble(string);
} catch (Exception e) { } catch (Exception e) {
return 0D; return 0D;
} }
@ -412,20 +410,14 @@ public class QbittorrentAdapter implements IDaemonAdapter {
if (string.equals("Unknown")) if (string.equals("Unknown"))
return -1; return -1;
// Sizes are given in "1,023.3 MiB"-like string format // Sizes are given in "1,023.3 MiB"-like string format
// FIXME Hack for issue #115: Strip the possible . and , separators in a hopefully reliable fashion, for now
String[] parts = string.split(" "); String[] parts = string.split(" ");
String part1 = "";
if (parts[0].length() >= 3)
part1 = parts[0].substring(0, parts[0].length() - 3);
String part2 = parts[0].substring(parts[0].length() - 3);
parts[0] = part1.replace("Ê", "").replace(" ", "").replace(",", "").replace(".", "") + part2.replace(",", ".");
// Returns size in B-based long
double number; double number;
try { try {
number = Double.parseDouble(parts[0]); number = Double.parseDouble(normalizeNumber(parts[0]));
} catch (Exception e) { } catch (Exception e) {
return -1L; return -1L;
} }
// Returns size in B-based long
if (parts[1].equals("TiB")) { if (parts[1].equals("TiB")) {
return (long) (number * 1024L * 1024L * 1024L * 1024L); return (long) (number * 1024L * 1024L * 1024L * 1024L);
} else if (parts[1].equals("GiB")) { } else if (parts[1].equals("GiB")) {
@ -453,19 +445,35 @@ public class QbittorrentAdapter implements IDaemonAdapter {
// See https://github.com/qbittorrent/qBittorrent/wiki/WebUI-API-Documentation // See https://github.com/qbittorrent/qBittorrent/wiki/WebUI-API-Documentation
if (speed.equals("Unknown")) if (speed.equals("Unknown"))
return -1; return -1;
// Speeds are in "21.9 KiB/s"-like string format // Sizes are given in "1,023.3 KiB/s"-like string format
// Returns speed in B/s-based integer
String[] parts = speed.split(" "); String[] parts = speed.split(" ");
double number;
try {
number = Double.parseDouble(normalizeNumber(parts[0]));
} catch (Exception e) {
return -1;
}
// Returns size in B-based int
if (parts[1].equals("GiB/s")) { if (parts[1].equals("GiB/s")) {
return (int) (Double.parseDouble(parts[0]) * 1024 * 1024 * 1024); return (int) (number * 1024 * 1024 * 1024);
} else if (parts[1].equals("MiB/s")) { } else if (parts[1].equals("MiB/s")) {
return (int) (Double.parseDouble(parts[0]) * 1024 * 1024); return (int) (number * 1024 * 1024);
} else if (parts[1].equals("KiB/s")) { } else if (parts[1].equals("KiB/s")) {
return (int) (Double.parseDouble(parts[0]) * 1024); return (int) (number * 1024);
} }
return (int) (Double.parseDouble(parts[0])); return (int) (Double.parseDouble(parts[0]));
} }
private String normalizeNumber(String in) {
// FIXME Hack for issue #115: Strip the possible . and , separators in a hopefully reliable fashion, for now
if (in.length() >= 3) {
String part1 = in.substring(0, in.length() - 3);
String part2 = in.substring(in.length() - 3);
return part1.replace("Ê", "").replace(" ", "").replace(",", "").replace(".", "") + part2.replace(",", ".");
}
return in.replace(",", ".");
}
private TorrentStatus parseStatus(String state) { private TorrentStatus parseStatus(String state) {
// Status is given as a descriptive string // Status is given as a descriptive string
if (state.equals("downloading")) { if (state.equals("downloading")) {

Loading…
Cancel
Save