Browse Source

Merged patch from Alexey Rogovoy with label-related fixes.

pull/11/head
Eric Kok 13 years ago
parent
commit
f6f1b47119
  1. 6
      android/AndroidManifest.xml
  2. 2
      android/project.properties
  3. 8
      android/res/layout/dialog_new_label.xml
  4. 9
      android/res/layout/list_item_label.xml
  5. 3
      android/src/org/transdroid/gui/SetLabelDialog.java
  6. 3
      android/src/org/transdroid/gui/TorrentProgressBar.java
  7. 22
      android/src/org/transdroid/gui/TorrentsFragment.java
  8. 2
      lib/src/org/transdroid/daemon/Bitflu/BitfluAdapter.java
  9. 2
      lib/src/org/transdroid/daemon/BuffaloNas/BuffaloNasAdapter.java
  10. 2
      lib/src/org/transdroid/daemon/DLinkRouterBT/DLinkRouterBTAdapter.java
  11. 2
      lib/src/org/transdroid/daemon/Deluge/DelugeAdapter.java
  12. 2
      lib/src/org/transdroid/daemon/Ktorrent/KtorrentAdapter.java
  13. 79
      lib/src/org/transdroid/daemon/Label.java
  14. 2
      lib/src/org/transdroid/daemon/Qbittorrent/QbittorrentAdapter.java
  15. 2
      lib/src/org/transdroid/daemon/Rtorrent/RtorrentAdapter.java
  16. 2
      lib/src/org/transdroid/daemon/Tfb4rt/Tfb4rtAdapter.java
  17. 2
      lib/src/org/transdroid/daemon/Transmission/TransmissionAdapter.java
  18. 25
      lib/src/org/transdroid/daemon/Utorrent/UtorrentAdapter.java
  19. 2
      lib/src/org/transdroid/daemon/Vuze/VuzeAdapter.java
  20. 8
      lib/src/org/transdroid/daemon/task/RetrieveTaskSuccessResult.java

6
android/AndroidManifest.xml

@ -18,11 +18,11 @@ @@ -18,11 +18,11 @@
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.transdroid"
android:versionName="1.1.5"
android:versionCode="146"
android:versionName="1.1.6"
android:versionCode="147"
android:installLocation="auto">
<uses-sdk android:minSdkVersion="4" android:targetSdkVersion="14" />
<uses-sdk android:minSdkVersion="4" android:targetSdkVersion="13" />
<supports-screens smallScreens="true" normalScreens="true" largeScreens="true" xlargeScreens="true" android:anyDensity="true" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />

2
android/project.properties

@ -10,6 +10,6 @@ @@ -10,6 +10,6 @@
# Indicates whether an apk should be generated for each density.
split.density=false
# Project target.
target=android-14
target=android-13
apk-configurations=
android.library.reference.1=../external/JakeWharton-ActionBarSherlock/library

8
android/res/layout/dialog_new_label.xml

@ -11,7 +11,7 @@ @@ -11,7 +11,7 @@
android:layout_height="wrap_content"
android:orientation="vertical"
android:minHeight="54dip"
android:background="#80000000">
android:background="#80000000">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
@ -49,13 +49,15 @@ @@ -49,13 +49,15 @@
android:layout_height="wrap_content"
android:layout_margin="10dip">
<EditText
<EditText
android:id="@+id/new_label"
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="1"
android:maxLines="1"
android:inputType="textShortMessage" />
android:inputType="textShortMessage"
android:textColor="#999999"
/>
<Button
android:id="@+id/set_button"

9
android/res/layout/list_item_label.xml

@ -13,14 +13,11 @@ @@ -13,14 +13,11 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/text1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLargeInverse"
android:gravity="center_vertical"
android:paddingLeft="6dip"
android:minHeight="?android:attr/listPreferredItemHeight"
android:textColor="#000"
/>
android:paddingLeft="3dip"
android:textAppearance="?android:attr/textAppearanceMediumInverse"
android:textColor="#000" />

3
android/src/org/transdroid/gui/SetLabelDialog.java

@ -58,6 +58,7 @@ public class SetLabelDialog extends Dialog { @@ -58,6 +58,7 @@ public class SetLabelDialog extends Dialog {
existingLabelsList = (ListView) findViewById(R.id.labels);
newLabelText = (EditText) findViewById(R.id.new_label);
okButton = (Button) findViewById(R.id.set_button);
newLabelText.setText(currentLabel);
// Set content and attach listeners
existingLabelsList.setAdapter(new ArrayAdapter<String>(context, R.layout.list_item_label, existingLabels));
@ -69,7 +70,7 @@ public class SetLabelDialog extends Dialog { @@ -69,7 +70,7 @@ public class SetLabelDialog extends Dialog {
// Update the available existing labels and empty the text box
this.currentLabel = currentLabel;
existingLabelsList.setAdapter(new ArrayAdapter<String>(context, R.layout.list_item_label, existingLabels));
newLabelText.setText("");
newLabelText.setText(currentLabel);
}
private OnItemClickListener onLabelSelected = new OnItemClickListener() {

3
android/src/org/transdroid/gui/TorrentProgressBar.java

@ -46,14 +46,17 @@ public class TorrentProgressBar extends View { @@ -46,14 +46,17 @@ public class TorrentProgressBar extends View {
public void setProgress(int progress) {
this.progress = progress;
this.invalidate();
}
public void setActive(boolean isActive) {
this.isActive = isActive;
this.invalidate();
}
public void setError(boolean isError) {
this.isError = isError;
this.invalidate();
}
public TorrentProgressBar(Context context) {

22
android/src/org/transdroid/gui/TorrentsFragment.java

@ -33,6 +33,7 @@ import org.transdroid.daemon.Torrent; @@ -33,6 +33,7 @@ import org.transdroid.daemon.Torrent;
import org.transdroid.daemon.TorrentStatus;
import org.transdroid.daemon.TorrentsComparator;
import org.transdroid.daemon.TorrentsSortBy;
import org.transdroid.daemon.Label;
import org.transdroid.daemon.task.AddByFileTask;
import org.transdroid.daemon.task.AddByMagnetUrlTask;
import org.transdroid.daemon.task.AddByUrlTask;
@ -207,7 +208,8 @@ public class TorrentsFragment extends Fragment implements IDaemonCallback, OnTou @@ -207,7 +208,8 @@ public class TorrentsFragment extends Fragment implements IDaemonCallback, OnTou
protected boolean ignoreFirstListNavigation = true;
private List<Torrent> allTorrents;
private List<Label> allLabels;
private TaskQueue queue;
private boolean inProgress = false;
@ -1384,12 +1386,12 @@ public class TorrentsFragment extends Fragment implements IDaemonCallback, OnTou @@ -1384,12 +1386,12 @@ public class TorrentsFragment extends Fragment implements IDaemonCallback, OnTou
}
public void updateTorrentList() {
if (daemon != null) {
if (daemon != null) {
queue.enqueue(RetrieveTask.create(daemon));
if (Daemon.supportsStats(daemon.getType())) {
queue.enqueue(GetStatsTask.create(daemon));
}
}
}
}
private void addTorrentByUrl(String url, String title) {
@ -1402,7 +1404,6 @@ public class TorrentsFragment extends Fragment implements IDaemonCallback, OnTou @@ -1402,7 +1404,6 @@ public class TorrentsFragment extends Fragment implements IDaemonCallback, OnTou
queue.enqueue(AddByUrlTask.create(daemon, url, title));
queue.enqueue(RetrieveTask.create(daemon));
}
private void addTorrentByMagnetUrl(String url) {
@ -1661,6 +1662,9 @@ public class TorrentsFragment extends Fragment implements IDaemonCallback, OnTou @@ -1661,6 +1662,9 @@ public class TorrentsFragment extends Fragment implements IDaemonCallback, OnTou
// Sort the new list of torrents
allTorrents = ((RetrieveTaskSuccessResult) result).getTorrents();
Collections.sort(allTorrents, new TorrentsComparator(daemon, sortSetting, sortReversed));
// Sort the new list of labels
allLabels = ((RetrieveTaskSuccessResult) result).getLabels();
// Show refreshed totals for this daemon
updateStatusText(null);
@ -1922,6 +1926,16 @@ public class TorrentsFragment extends Fragment implements IDaemonCallback, OnTou @@ -1922,6 +1926,16 @@ public class TorrentsFragment extends Fragment implements IDaemonCallback, OnTou
availableLabels.add(showAll);
// Gather the used labels from the torrents
if (allLabels!=null){
for (Label lab : allLabels) {
String name = lab.getName();
// Start a new label if this name wasn't encountered yet
if (!availableLabels.contains(name)) {
availableLabels.add(name);
}
}
}
for (Torrent tor : allTorrents) {
// Force a label name (use 'unlabeled' if none is provided)

2
lib/src/org/transdroid/daemon/Bitflu/BitfluAdapter.java

@ -95,7 +95,7 @@ public class BitfluAdapter implements IDaemonAdapter { @@ -95,7 +95,7 @@ public class BitfluAdapter implements IDaemonAdapter {
case Retrieve:
// Request all torrents from server
JSONObject result = makeBitfluRequest(RPC_TORRENT_LIST);
return new RetrieveTaskSuccessResult((RetrieveTask) task, parseJsonRetrieveTorrents(result.getJSONArray(JSON_ROOT)));
return new RetrieveTaskSuccessResult((RetrieveTask) task, parseJsonRetrieveTorrents(result.getJSONArray(JSON_ROOT)),null);
case GetStats:
return new GetStatsTaskSuccessResult((GetStatsTask) task, false, -1);
case Pause:

2
lib/src/org/transdroid/daemon/BuffaloNas/BuffaloNasAdapter.java

@ -88,7 +88,7 @@ public class BuffaloNasAdapter implements IDaemonAdapter { @@ -88,7 +88,7 @@ public class BuffaloNasAdapter implements IDaemonAdapter {
// Request all torrents from server
JSONObject result = new JSONObject(makeRequest("/api/torrents-get"));
return new RetrieveTaskSuccessResult((RetrieveTask) task, parseJsonTorrents(result));
return new RetrieveTaskSuccessResult((RetrieveTask) task, parseJsonTorrents(result),null);
case GetFileList:

2
lib/src/org/transdroid/daemon/DLinkRouterBT/DLinkRouterBTAdapter.java

@ -124,7 +124,7 @@ public class DLinkRouterBTAdapter implements IDaemonAdapter { @@ -124,7 +124,7 @@ public class DLinkRouterBTAdapter implements IDaemonAdapter {
// Request all torrents from server
JSONObject result = makeRequest(API_GET);
return new RetrieveTaskSuccessResult((RetrieveTask) task, parseJsonRetrieveTorrents(result));
return new RetrieveTaskSuccessResult((RetrieveTask) task, parseJsonRetrieveTorrents(result),null);
case GetFileList:

2
lib/src/org/transdroid/daemon/Deluge/DelugeAdapter.java

@ -220,7 +220,7 @@ public class DelugeAdapter implements IDaemonAdapter { @@ -220,7 +220,7 @@ public class DelugeAdapter implements IDaemonAdapter {
// params.put(-1); // cache_id
JSONObject result = makeRequest(buildRequest(RPC_METHOD_GET, params));
return new RetrieveTaskSuccessResult((RetrieveTask) task, parseJsonRetrieveTorrents(result.getJSONObject(RPC_RESULT)));
return new RetrieveTaskSuccessResult((RetrieveTask) task, parseJsonRetrieveTorrents(result.getJSONObject(RPC_RESULT)),null);
case GetTorrentDetails:

2
lib/src/org/transdroid/daemon/Ktorrent/KtorrentAdapter.java

@ -106,7 +106,7 @@ public class KtorrentAdapter implements IDaemonAdapter { @@ -106,7 +106,7 @@ public class KtorrentAdapter implements IDaemonAdapter {
case Retrieve:
// Request all torrents from server
return new RetrieveTaskSuccessResult((RetrieveTask) task, makeStatsRequest());
return new RetrieveTaskSuccessResult((RetrieveTask) task, makeStatsRequest(),null);
case GetFileList:

79
lib/src/org/transdroid/daemon/Label.java

@ -0,0 +1,79 @@ @@ -0,0 +1,79 @@
/*
* This file is part of Transdroid <http://www.transdroid.org>
*
* Transdroid is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Transdroid is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Transdroid. If not, see <http://www.gnu.org/licenses/>.
*
*/
package org.transdroid.daemon;
import android.os.Parcel;
import android.os.Parcelable;
/**
* Represents a label on a server daemon.
*
* @author Lexa
*
*/
public final class Label implements Parcelable, Comparable<Label> {
final private String name;
final private int count;
public String getName() { return name; }
public int getCount() { return count; }
private Label(Parcel in) {
this.name = in.readString();
this.count = in.readInt();
}
public Label(String name, int count) {
this.name = name;
this.count = count;
}
@Override
public String toString() {
return name;//+"("+String.valueOf(count)+")";
}
@Override
public int compareTo(Label another) {
// Compare Label objects on their name (used for sorting only!)
return name.compareTo(another.getName());
}
public static final Parcelable.Creator<Label> CREATOR = new Parcelable.Creator<Label>() {
public Label createFromParcel(Parcel in) {
return new Label(in);
}
public Label[] newArray(int size) {
return new Label[size];
}
};
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(name);
dest.writeInt(count);
}
}

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

@ -94,7 +94,7 @@ public class QbittorrentAdapter implements IDaemonAdapter { @@ -94,7 +94,7 @@ public class QbittorrentAdapter implements IDaemonAdapter {
// Request all torrents from server
JSONArray result = new JSONArray(makeRequest("/json/events"));
return new RetrieveTaskSuccessResult((RetrieveTask) task, parseJsonTorrents(result));
return new RetrieveTaskSuccessResult((RetrieveTask) task, parseJsonTorrents(result),null);
case GetTorrentDetails:

2
lib/src/org/transdroid/daemon/Rtorrent/RtorrentAdapter.java

@ -86,7 +86,7 @@ public class RtorrentAdapter implements IDaemonAdapter { @@ -86,7 +86,7 @@ public class RtorrentAdapter implements IDaemonAdapter {
case Retrieve:
Object result = makeRtorrentCall("d.multicall", new String[] { "main", "d.get_hash=", "d.get_name=", "d.get_state=", "d.get_down_rate=", "d.get_up_rate=", "d.get_peers_connected=", "d.get_peers_not_connected=", "d.get_peers_accounted=", "d.get_bytes_done=", "d.get_up_total=", "d.get_size_bytes=", "d.get_creation_date=", "d.get_left_bytes=", "d.get_complete=", "d.is_active=", "d.is_hash_checking=", "d.get_base_path=", "d.get_base_filename=", "d.get_message=" });
return new RetrieveTaskSuccessResult((RetrieveTask) task, onTorrentsRetrieved(result));
return new RetrieveTaskSuccessResult((RetrieveTask) task, onTorrentsRetrieved(result),null);
case GetTorrentDetails:

2
lib/src/org/transdroid/daemon/Tfb4rt/Tfb4rtAdapter.java

@ -90,7 +90,7 @@ public class Tfb4rtAdapter implements IDaemonAdapter { @@ -90,7 +90,7 @@ public class Tfb4rtAdapter implements IDaemonAdapter {
case Retrieve:
// Request all torrents from server
return new RetrieveTaskSuccessResult((RetrieveTask) task, makeStatsRequest());
return new RetrieveTaskSuccessResult((RetrieveTask) task, makeStatsRequest(),null);
case AddByFile:

2
lib/src/org/transdroid/daemon/Transmission/TransmissionAdapter.java

@ -149,7 +149,7 @@ public class TransmissionAdapter implements IDaemonAdapter { @@ -149,7 +149,7 @@ public class TransmissionAdapter implements IDaemonAdapter {
request.put("fields", fields);
JSONObject result = makeRequest(buildRequestObject("torrent-get", request));
return new RetrieveTaskSuccessResult((RetrieveTask) task, parseJsonRetrieveTorrents(result.getJSONObject("arguments")));
return new RetrieveTaskSuccessResult((RetrieveTask) task, parseJsonRetrieveTorrents(result.getJSONObject("arguments")),null);
case GetStats:

25
lib/src/org/transdroid/daemon/Utorrent/UtorrentAdapter.java

@ -45,6 +45,7 @@ import org.transdroid.daemon.Torrent; @@ -45,6 +45,7 @@ import org.transdroid.daemon.Torrent;
import org.transdroid.daemon.TorrentDetails;
import org.transdroid.daemon.TorrentFile;
import org.transdroid.daemon.TorrentStatus;
import org.transdroid.daemon.Label;
import org.transdroid.daemon.task.AddByFileTask;
import org.transdroid.daemon.task.AddByMagnetUrlTask;
import org.transdroid.daemon.task.AddByUrlTask;
@ -103,7 +104,7 @@ public class UtorrentAdapter implements IDaemonAdapter { @@ -103,7 +104,7 @@ public class UtorrentAdapter implements IDaemonAdapter {
// Request all torrents from server
JSONObject result = makeUtorrentRequest("&list=1");
return new RetrieveTaskSuccessResult((RetrieveTask) task, parseJsonRetrieveTorrents(result.getJSONArray("torrents")));
return new RetrieveTaskSuccessResult((RetrieveTask) task, parseJsonRetrieveTorrents(result.getJSONArray("torrents")),parseJsonRetrieveGetLabels(result.getJSONArray("label")));
case GetTorrentDetails:
@ -246,7 +247,7 @@ public class UtorrentAdapter implements IDaemonAdapter { @@ -246,7 +247,7 @@ public class UtorrentAdapter implements IDaemonAdapter {
makeUtorrentRequest("&action=setprops" + RPC_URL_HASH + trackersTask.getTargetTorrent().getUniqueID() +
"&s=trackers&v=" + URLEncoder.encode(newTrackersText, "UTF-8"));
return new DaemonTaskSuccessResult(task);
default:
return new DaemonTaskFailureResult(task, new DaemonException(ExceptionType.MethodUnsupported, task.getMethod() + " is not supported by " + getType()));
}
@ -263,6 +264,26 @@ public class UtorrentAdapter implements IDaemonAdapter { @@ -263,6 +264,26 @@ public class UtorrentAdapter implements IDaemonAdapter {
}
}
private static final int NAME_IDX = 0;
private static final int COUNT_IDX = 1;
private ArrayList<Label> parseJsonRetrieveGetLabels(JSONArray lresults) throws JSONException {
// Parse response
ArrayList<Label> labels = new ArrayList<Label>();
for (int i = 0; i < lresults.length(); i++) {
JSONArray lab = lresults.getJSONArray(i);
String name = lab.getString(NAME_IDX);
int count = lab.getInt(COUNT_IDX);
labels.add(new Label(
name,
count
));
}
return labels;
}
private JSONObject makeUtorrentRequest(String addToUrl) throws DaemonException {
try {

2
lib/src/org/transdroid/daemon/Vuze/VuzeAdapter.java

@ -88,7 +88,7 @@ public class VuzeAdapter implements IDaemonAdapter { @@ -88,7 +88,7 @@ public class VuzeAdapter implements IDaemonAdapter {
case Retrieve:
Object result = makeVuzeCall(DaemonMethod.Retrieve, "getDownloads");
return new RetrieveTaskSuccessResult((RetrieveTask) task, onTorrentsRetrieved(result));
return new RetrieveTaskSuccessResult((RetrieveTask) task, onTorrentsRetrieved(result),null);
case GetFileList:

8
lib/src/org/transdroid/daemon/task/RetrieveTaskSuccessResult.java

@ -20,6 +20,7 @@ @@ -20,6 +20,7 @@
import java.util.List;
import org.transdroid.daemon.Torrent;
import org.transdroid.daemon.Label;
/**
* The result of a successfully executed RetrieveTask on the daemon.
@ -30,14 +31,19 @@ import org.transdroid.daemon.Torrent; @@ -30,14 +31,19 @@ import org.transdroid.daemon.Torrent;
public class RetrieveTaskSuccessResult extends DaemonTaskSuccessResult {
private List<Torrent> torrents;
private List<Label> labels;
public RetrieveTaskSuccessResult(RetrieveTask executedTask, List<Torrent> torrents) {
public RetrieveTaskSuccessResult(RetrieveTask executedTask, List<Torrent> torrents, List<Label> labels) {
super(executedTask);
this.torrents = torrents;
this.labels = labels;
}
public List<Torrent> getTorrents() {
return torrents;
}
public List<Label> getLabels() {
return labels;
}
}

Loading…
Cancel
Save