Skip to content

Commit

Permalink
Merge pull request #20 from DSteve595/upload_ratio
Browse files Browse the repository at this point in the history
Upload ratio
  • Loading branch information
DSteve595 committed Aug 5, 2014
2 parents b3230d0 + 0e6d2d6 commit 0ed2f96
Show file tree
Hide file tree
Showing 9 changed files with 171 additions and 189 deletions.
2 changes: 1 addition & 1 deletion app/app.iml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
<orderEntry type="library" exported="" name="support-v4-20.0.0" level="project" />
<orderEntry type="library" exported="" name="commons-io-2.4" level="project" />
<orderEntry type="library" exported="" name="picasso-2.3.3" level="project" />
<orderEntry type="library" exported="" name="httpmime-4.3.4" level="project" />
<orderEntry type="library" exported="" name="httpmime-4.3.5" level="project" />
<orderEntry type="library" exported="" name="eventbus-2.2.1" level="project" />
<orderEntry type="library" exported="" name="mediarouter-0.1.2" level="project" />
<orderEntry type="library" exported="" name="retrofit-1.6.1" level="project" />
Expand Down
20 changes: 13 additions & 7 deletions app/src/main/java/com/stevenschoen/putionew/PutioFileLayout.java
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
package com.stevenschoen.putionew;

import android.content.Context;
import android.content.res.Resources;
import android.os.Parcel;
import android.os.Parcelable;

import com.stevenschoen.putionew.model.files.PutioFileData;

public class PutioFileLayout implements Parcelable {
public String name;
public String description;
public int iconRes;
public String iconUrl;

public PutioFileLayout(String name, String description, int iconRes, String iconUrl) {
super();
this.name = name;
this.description = description;
this.iconRes = iconRes;
this.iconUrl = iconUrl;
}
public PutioFileLayout(Resources resources, PutioFileData data) {
name = data.name;
description = resources.getString(R.string.size_is, PutioUtils.humanReadableByteCount(
data.size, false));
Integer iconResource = PutioFileData.contentTypes.get(data.contentType);
if (iconResource == null) iconResource = R.drawable.ic_putio_file;
iconRes = iconResource;
iconUrl = data.icon;
}

@Override
public int describeContents() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,24 @@
import android.os.Parcel;
import android.os.Parcelable;

import com.stevenschoen.putionew.model.transfers.PutioTransferData;

public class PutioTransferLayout implements Parcelable {
public String name;
public long downSpeed;
public long upSpeed;
public String ratio;
public int percentDone;
public String status;

public PutioTransferLayout() {
super();
}

public PutioTransferLayout(String name, long downSpeed, long upSpeed, int percentDone, String status) {
super();
this.name = name;
this.downSpeed = downSpeed;
this.upSpeed = upSpeed;
this.percentDone = percentDone;
this.status = status;
}
public PutioTransferLayout(PutioTransferData data) {
name = data.name;
downSpeed = data.downSpeed;
upSpeed = data.upSpeed;
ratio = data.currentRatio;
percentDone = data.percentDone;
status = data.status;
}

@Override
public int describeContents() {
Expand All @@ -33,12 +32,10 @@ public PutioTransferLayout(Parcel in) {
}

private void readFromParcel(Parcel in) {
// We just need to read back each
// field in the order that it was
// written to the parcel
this.name = in.readString();
this.downSpeed = in.readLong();
this.upSpeed = in.readLong();
this.ratio = in.readString();
this.percentDone = in.readInt();
this.status = in.readString();
}
Expand All @@ -48,6 +45,7 @@ public void writeToParcel(Parcel out, int flags) {
out.writeString(this.name);
out.writeLong(this.downSpeed);
out.writeLong(this.upSpeed);
out.writeString(this.ratio);
out.writeInt(this.percentDone);
out.writeString(this.status);
}
Expand Down
110 changes: 60 additions & 50 deletions app/src/main/java/com/stevenschoen/putionew/TransfersAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,16 @@ public View getView(int position, View convertView, ViewGroup parent) {
holder.textDownUnit = (TextView) row.findViewById(R.id.text_transfer_downUnit);
holder.textUpValue = (TextView) row.findViewById(R.id.text_transfer_upValue);
holder.textUpUnit = (TextView) row.findViewById(R.id.text_transfer_upUnit);
holder.textRatio = (TextView) row.findViewById(R.id.text_transfer_ratio);
holder.textPercent = (TextView) row.findViewById(R.id.text_transfer_percent);
holder.imgStatusIcon = (ImageView) row.findViewById(R.id.img_transfer_icon);
holder.statusLoading = (ProgressBar) row.findViewById(R.id.transfer_statusLoading);

holder.greenBar = row.findViewById(R.id.transfer_greenbar);
holder.textMessage = (TextView) row.findViewById(R.id.text_transfer_message);
holder.speedHolder = row.findViewById(R.id.transfer_speedHolder);
holder.downHolder = row.findViewById(R.id.holder_transfer_down);
holder.upHolder = row.findViewById(R.id.holder_transfer_up);
holder.ratioHolder = row.findViewById(R.id.holder_transfer_ratio);

row.setTag(holder);
} else {
Expand All @@ -59,61 +62,65 @@ public View getView(int position, View convertView, ViewGroup parent) {

holder.textName.setText(transfer.name);

String[] downStrings = PutioUtils.humanReadableByteCountArray(data.get(position).downSpeed, false);
String[] downStrings = PutioUtils.humanReadableByteCountArray(transfer.downSpeed, false);
holder.textDownValue.setText(downStrings[0]);
holder.textDownUnit.setText(downStrings[1] + "/sec");
String[] upStrings = PutioUtils.humanReadableByteCountArray(data.get(position).upSpeed, false);
String[] upStrings = PutioUtils.humanReadableByteCountArray(transfer.upSpeed, false);
holder.textUpValue.setText(upStrings[0]);
holder.textUpUnit.setText(upStrings[1] + "/sec");

int percentInt = data.get(position).percentDone;
int percentInt = transfer.percentDone;
String percentString = Integer.toString(percentInt);

if (data.get(position).status.equals("COMPLETED")) {
holder.imgStatusIcon.setImageResource(R.drawable.ic_transfer_done);
holder.imgStatusIcon.setVisibility(View.VISIBLE);
holder.statusLoading.setVisibility(View.INVISIBLE);
holder.textMessage.setVisibility(View.GONE);
holder.speedHolder.setVisibility(View.VISIBLE);
holder.textPercent.setText(percentString + "%");
holder.greenBar.setBackgroundColor(Color.parseColor("#2000FF00"));
holder.greenBar.setPivotX(0);
holder.greenBar.setScaleX(1f);
holder.textPercent.setTextColor(context.getResources().getColor(R.color.putio_green));
} else if (data.get(position).status.equals("SEEDING")) {
holder.imgStatusIcon.setImageResource(R.drawable.ic_transfer_done);
holder.imgStatusIcon.setVisibility(View.VISIBLE);
holder.statusLoading.setVisibility(View.INVISIBLE);
holder.textMessage.setVisibility(View.GONE);
holder.speedHolder.setVisibility(View.VISIBLE);
holder.textPercent.setText(percentString + "%");
holder.greenBar.setBackgroundColor(Color.parseColor("#2000FF00"));
holder.greenBar.setPivotX(0);
holder.greenBar.setScaleX(1f);
holder.textPercent.setTextColor(context.getResources().getColor(R.color.putio_green));
} else if (data.get(position).status.equals("ERROR")) {
holder.imgStatusIcon.setImageResource(R.drawable.ic_transfer_failed);
holder.imgStatusIcon.setVisibility(View.VISIBLE);
holder.statusLoading.setVisibility(View.INVISIBLE);
holder.textMessage.setText(context.getString(R.string.transferfailed));
holder.textMessage.setVisibility(View.VISIBLE);
holder.speedHolder.setVisibility(View.GONE);
holder.textPercent.setText(":(");
holder.greenBar.setBackgroundColor(context.getResources().getColor(R.color.putio_error));
holder.greenBar.setPivotX(0);
holder.greenBar.setScaleX(1f);
holder.textPercent.setTextColor(Color.RED);
} else {
holder.imgStatusIcon.setVisibility(View.INVISIBLE);
holder.statusLoading.setVisibility(View.VISIBLE);
holder.textMessage.setVisibility(View.GONE);
holder.speedHolder.setVisibility(View.VISIBLE);
holder.textPercent.setText(percentString + "%");
holder.greenBar.setBackgroundColor(Color.parseColor("#2000FF00"));
holder.greenBar.setPivotX(0);
holder.greenBar.setScaleX((float) data.get(position).percentDone / 100);
holder.textPercent.setTextColor(Color.BLACK);
}
switch (transfer.status) {
case "COMPLETED":
case "SEEDING":
holder.imgStatusIcon.setImageResource(R.drawable.ic_transfer_done);
holder.imgStatusIcon.setVisibility(View.VISIBLE);
holder.statusLoading.setVisibility(View.INVISIBLE);
holder.textMessage.setVisibility(View.GONE);
holder.downHolder.setVisibility(View.GONE);
holder.upHolder.setVisibility(View.VISIBLE);
if (Float.valueOf(transfer.ratio) != 0) {
holder.textRatio.setText(getContext().getString(R.string.ratio_is, transfer.ratio));
holder.ratioHolder.setVisibility(View.VISIBLE);
} else {
holder.ratioHolder.setVisibility(View.GONE);
}
holder.textPercent.setText(percentString + "%");
holder.greenBar.setBackgroundColor(Color.parseColor("#2000FF00"));
holder.greenBar.setPivotX(0);
holder.greenBar.setScaleX(1f);
holder.textPercent.setTextColor(context.getResources().getColor(R.color.putio_green));
break;
case "ERROR":
holder.imgStatusIcon.setImageResource(R.drawable.ic_transfer_failed);
holder.imgStatusIcon.setVisibility(View.VISIBLE);
holder.statusLoading.setVisibility(View.INVISIBLE);
holder.textMessage.setText(context.getString(R.string.transferfailed));
holder.textMessage.setVisibility(View.VISIBLE);
holder.downHolder.setVisibility(View.GONE);
holder.upHolder.setVisibility(View.GONE);
holder.ratioHolder.setVisibility(View.GONE);
holder.textPercent.setText(":(");
holder.greenBar.setBackgroundColor(context.getResources().getColor(R.color.putio_error));
holder.greenBar.setPivotX(0);
holder.greenBar.setScaleX(1f);
holder.textPercent.setTextColor(Color.RED);
break;
default:
holder.imgStatusIcon.setVisibility(View.INVISIBLE);
holder.statusLoading.setVisibility(View.VISIBLE);
holder.textMessage.setVisibility(View.GONE);
holder.downHolder.setVisibility(View.VISIBLE);
holder.upHolder.setVisibility(View.VISIBLE);
holder.ratioHolder.setVisibility(View.GONE);
holder.textPercent.setText(percentString + "%");
holder.greenBar.setBackgroundColor(Color.parseColor("#2000FF00"));
holder.greenBar.setPivotX(0);
holder.greenBar.setScaleX((float) data.get(position).percentDone / 100);
holder.textPercent.setTextColor(Color.BLACK);
}

return row;
}
Expand All @@ -124,12 +131,15 @@ static class TransferHolder {
TextView textDownUnit;
TextView textUpValue;
TextView textUpUnit;
TextView textRatio;
TextView textPercent;
ImageView imgStatusIcon;
ProgressBar statusLoading;

View greenBar;
TextView textMessage;
View speedHolder;
View downHolder;
View upHolder;
View ratioHolder;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -475,15 +475,7 @@ private void populateList(final List<PutioFileData> files, int newId, int parent
fileLayouts.clear();
if (isAdded()) {
for (PutioFileData file : files) {
Integer iconResource = PutioFileData.contentTypes.get(file.contentType);
if (iconResource == null) iconResource = R.drawable.ic_putio_file;
fileLayouts.add(new PutioFileLayout(
file.name,
getString(R.string.size_is, PutioUtils.humanReadableByteCount(
file.size, false)),
iconResource,
file.icon
));
fileLayouts.add(new PutioFileLayout(getResources(), file));
}
}
adapter.notifyDataSetChanged();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,48 +240,12 @@ public void updateTransfers(List<PutioTransferData> transfers) {
setViewMode(VIEWMODE_LIST);
}

// final ArrayList<PutioTransferLayout> transferLayoutsTemp = new ArrayList<PutioTransferLayout>();
// for (int i = 0; i < transfers.length; i++) {
// if (isAdded()) {
// transferLayoutsTemp.add(new PutioTransferLayout(
// transfers[i].name,
// transfers[i].downSpeed,
// transfers[i].upSpeed,
// transfers[i].percentDone,
// transfers[i].status));
// }
// }
//
// int index = listview.getFirstVisiblePosition();
// View v = listview.getChildAt(0);
// int top = (v == null) ? 0 : v.getTop();
//
// listview.setSelectionFromTop(index, top);
//
// while (transferLayouts.size() > transferLayoutsTemp.size()) {
// transferLayouts.remove(transferLayouts.size() - 1);
// }
//
// for (int i = 0; i < transferLayoutsTemp.size(); i++) {
// if (transferLayouts.size() <= i) {
// transferLayouts.add(transferLayoutsTemp.get(i));
// } else {
// transferLayouts.set(i, transferLayoutsTemp.get(i));
// }
// adapter.notifyDataSetChanged();
// }

transfersData = transfers;

if (isAdded()) {
transferLayouts.clear();
for (PutioTransferData transfer : transfers) {
transferLayouts.add(new PutioTransferLayout(
transfer.name,
transfer.downSpeed,
transfer.upSpeed,
transfer.percentDone,
transfer.status));
transferLayouts.add(new PutioTransferLayout(transfer));
}
adapter.notifyDataSetChanged();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,34 +11,15 @@ public class PutioTransferData implements Parcelable {
public String estimatedTime;
public String createdTime;
public boolean extract;
public String currentRatio;
public long downSpeed;
public long upSpeed;
public int percentDone;
public String status;
public String statusMessage;
public int saveParentId;

public PutioTransferData(int id, int fileId, long size, String name,
String estimatedTime, String createdTime, boolean extract,
long downSpeed, long upSpeed, int percentDone, String status,
String statusMessage, int saveParentId) {
super();
this.id = id;
this.fileId = fileId;
this.size = size;
this.name = name;
this.estimatedTime = estimatedTime;
this.createdTime = createdTime;
this.extract = extract;
this.downSpeed = downSpeed;
this.upSpeed = upSpeed;
this.percentDone = percentDone;
this.status = status;
this.statusMessage = statusMessage;
this.saveParentId = saveParentId;
}

@Override
@Override
public int describeContents() {
return 0;
}
Expand All @@ -48,16 +29,14 @@ public PutioTransferData(Parcel in) {
}

private void readFromParcel(Parcel in) {
// We just need to read back each
// field in the order that it was
// written to the parcel
this.id = in.readInt();
this.fileId = in.readInt();
this.size = in.readLong();
this.name = in.readString();
this.estimatedTime = in.readString();
this.createdTime = in.readString();
this.extract = (Boolean) in.readValue(ClassLoader.getSystemClassLoader());
this.currentRatio = in.readString();
this.downSpeed = in.readLong();
this.upSpeed = in.readLong();
this.percentDone = in.readInt();
Expand All @@ -75,6 +54,7 @@ public void writeToParcel(Parcel out, int flags) {
out.writeString(this.estimatedTime);
out.writeString(this.createdTime);
out.writeValue(this.extract);
out.writeString(this.currentRatio);
out.writeLong(this.downSpeed);
out.writeLong(this.upSpeed);
out.writeInt(this.percentDone);
Expand Down
Loading

0 comments on commit 0ed2f96

Please sign in to comment.