Browse Source

Simple text mockup of pieces map

pull/517/head
Phillip Dykman 5 years ago
parent
commit
02ab41cffc
  1. 2
      app/src/main/java/org/transdroid/core/gui/DetailsFragment.java
  2. 24
      app/src/main/java/org/transdroid/core/gui/lists/DetailsAdapter.java
  3. 14
      app/src/main/java/org/transdroid/daemon/Qbittorrent/QbittorrentAdapter.java
  4. 27
      app/src/main/java/org/transdroid/daemon/TorrentDetails.java

2
app/src/main/java/org/transdroid/core/gui/DetailsFragment.java

@ -203,6 +203,8 @@ public class DetailsFragment extends Fragment implements OnTrackersUpdatedListen @@ -203,6 +203,8 @@ public class DetailsFragment extends Fragment implements OnTrackersUpdatedListen
.updateTrackers(SimpleListItemAdapter.SimpleStringItem.wrapStringsList(newTorrentDetails.getTrackers()));
((DetailsAdapter) detailsList.getAdapter())
.updateErrors(SimpleListItemAdapter.SimpleStringItem.wrapStringsList(newTorrentDetails.getErrors()));
((DetailsAdapter) detailsList.getAdapter())
.updatePieces(newTorrentDetails.getPieces());
}
/**

24
app/src/main/java/org/transdroid/core/gui/lists/DetailsAdapter.java

@ -29,6 +29,7 @@ import android.text.util.Linkify; @@ -29,6 +29,7 @@ import android.text.util.Linkify;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
/**
* List adapter that holds a header view showing torrent details and show the list list contained by the torrent.
@ -38,6 +39,8 @@ public class DetailsAdapter extends MergeAdapter { @@ -38,6 +39,8 @@ public class DetailsAdapter extends MergeAdapter {
private ViewHolderAdapter torrentDetailsViewAdapter = null;
private TorrentDetailsView torrentDetailsView = null;
private ViewHolderAdapter piecesMapViewAdapter = null;
private TextView piecesMapView = null;
private ViewHolderAdapter trackersSeparatorAdapter = null;
private SimpleListItemAdapter trackersAdapter = null;
private ViewHolderAdapter errorsSeparatorAdapter = null;
@ -56,6 +59,13 @@ public class DetailsAdapter extends MergeAdapter { @@ -56,6 +59,13 @@ public class DetailsAdapter extends MergeAdapter {
torrentDetailsViewAdapter.setViewVisibility(View.GONE);
addAdapter(torrentDetailsViewAdapter);
// Pieces map
piecesMapView = new TextView(context);
piecesMapViewAdapter = new ViewHolderAdapter(piecesMapView);
piecesMapViewAdapter.setViewEnabled(true);
piecesMapViewAdapter.setViewVisibility(View.VISIBLE);
addAdapter(piecesMapViewAdapter);
// Tracker errors
errorsSeparatorAdapter = new ViewHolderAdapter(FilterSeparatorView_.build(context).setText(
context.getString(R.string.status_errors)));
@ -137,6 +147,20 @@ public class DetailsAdapter extends MergeAdapter { @@ -137,6 +147,20 @@ public class DetailsAdapter extends MergeAdapter {
}
}
public void updatePieces(List<Integer> pieces) {
if (pieces == null || pieces.isEmpty()) {
//errorsAdapter.update(new ArrayList<SimpleListItemAdapter.SimpleStringItem>());
//errorsSeparatorAdapter.setViewVisibility(View.GONE);
} else {
String piecesText = "";
for (int piece : pieces) {
piecesText += piece;
}
piecesMapView.setText(piecesText.substring(0,40));
//errorsSeparatorAdapter.setViewVisibility(View.VISIBLE);
}
}
/**
* Clear currently visible torrent, including header and shown lists
*/

14
app/src/main/java/org/transdroid/daemon/Qbittorrent/QbittorrentAdapter.java

@ -204,7 +204,8 @@ public class QbittorrentAdapter implements IDaemonAdapter { @@ -204,7 +204,8 @@ public class QbittorrentAdapter implements IDaemonAdapter {
String mhash = task.getTargetTorrent().getUniqueID();
JSONArray messages =
new JSONArray(makeRequest(log, (version >= 30200 ? "/query/propertiesTrackers/" : "/json/propertiesTrackers/") + mhash));
return new GetTorrentDetailsTaskSuccessResult((GetTorrentDetailsTask) task, parseJsonTorrentDetails(messages));
JSONArray pieces = new JSONArray(makeRequest(log, "/query/getPieceStates/" + mhash));
return new GetTorrentDetailsTaskSuccessResult((GetTorrentDetailsTask) task, parseJsonTorrentDetails(messages, pieces));
case GetFileList:
@ -439,7 +440,7 @@ public class QbittorrentAdapter implements IDaemonAdapter { @@ -439,7 +440,7 @@ public class QbittorrentAdapter implements IDaemonAdapter {
return (settings.getSsl() ? "https://" : "http://") + settings.getAddress() + ":" + settings.getPort() + proxyFolder + path;
}
private TorrentDetails parseJsonTorrentDetails(JSONArray messages) throws JSONException {
private TorrentDetails parseJsonTorrentDetails(JSONArray messages, JSONArray pieceStates) throws JSONException {
ArrayList<String> trackers = new ArrayList<>();
ArrayList<String> errors = new ArrayList<>();
@ -455,8 +456,15 @@ public class QbittorrentAdapter implements IDaemonAdapter { @@ -455,8 +456,15 @@ public class QbittorrentAdapter implements IDaemonAdapter {
}
}
ArrayList<Integer> pieces = new ArrayList<>();
if (pieceStates.length() > 0) {
for (int i = 0; i < pieceStates.length(); i++) {
pieces.add(pieceStates.getInt(i));
}
}
// Return the list
return new TorrentDetails(trackers, errors);
return new TorrentDetails(trackers, errors, pieces);
}

27
app/src/main/java/org/transdroid/daemon/TorrentDetails.java

@ -18,6 +18,7 @@ @@ -18,6 +18,7 @@
package org.transdroid.daemon;
import java.util.List;
import java.util.ArrayList;
import android.os.Parcel;
import android.os.Parcelable;
@ -32,15 +33,29 @@ public final class TorrentDetails implements Parcelable { @@ -32,15 +33,29 @@ public final class TorrentDetails implements Parcelable {
private final List<String> trackers;
private final List<String> errors;
private final List<Integer> pieces;
public TorrentDetails(List<String> trackers, List<String> errors) {
this.trackers = trackers;
this.errors = errors;
this.pieces = null;
}
public TorrentDetails(List<String> trackers, List<String> errors, List<Integer> pieces) {
this.trackers = trackers;
this.errors = errors;
this.pieces = pieces;
}
private TorrentDetails(Parcel in) {
this.trackers = in.createStringArrayList();
this.errors = in.createStringArrayList();
int[] piecesarray = in.createIntArray();
this.pieces = new ArrayList<Integer>(piecesarray.length);
for (int i : piecesarray) {
this.pieces.add(i);
}
}
public List<String> getTrackers() {
@ -77,6 +92,10 @@ public final class TorrentDetails implements Parcelable { @@ -77,6 +92,10 @@ public final class TorrentDetails implements Parcelable {
return errorsText;
}
public List<Integer> getPieces() {
return this.pieces;
}
public static final Parcelable.Creator<TorrentDetails> CREATOR = new Parcelable.Creator<TorrentDetails>() {
public TorrentDetails createFromParcel(Parcel in) {
return new TorrentDetails(in);
@ -96,6 +115,14 @@ public final class TorrentDetails implements Parcelable { @@ -96,6 +115,14 @@ public final class TorrentDetails implements Parcelable {
public void writeToParcel(Parcel dest, int flags) {
dest.writeStringList(trackers);
dest.writeStringList(errors);
int[] piecesarray = new int[this.pieces.size()];
for(int i = 0; i < this.pieces.size(); i++) {
if (this.pieces.get(i) != null) {
piecesarray[i] = this.pieces.get(i);
}
}
dest.writeIntArray(piecesarray);
}
}

Loading…
Cancel
Save