and more fixes

* fix content length reading
* use float overflow. Expensive, double is used instead
* fix invalid cast after click the mission body
* use a list for maximum attemps (downloads)
* minor clean up (DownloadManager.java)
* dont pass SharedPreferences instace to DownloadManager
* use a switch instead of checkbox for cross_network_downloads
* notify media scanner after deleting a finished download
This commit is contained in:
kapodamy 2018-11-24 00:14:37 -03:00
parent 3357fc0f17
commit 6d4e97a877
12 changed files with 111 additions and 52 deletions

View file

@ -183,6 +183,7 @@ public class MissionAdapter extends RecyclerView.Adapter<ViewHolder> {
return mIterator.getSpecialAtItem(position);
}
@SuppressLint("DefaultLocale")
private void updateProgress(ViewHolderItem h) {
if (h == null || h.item == null || h.item.mission instanceof FinishedMission) return;
@ -216,14 +217,15 @@ public class MissionAdapter extends RecyclerView.Adapter<ViewHolder> {
progress = Float.NaN;
h.progress.setProgress(0f);
} else {
progress = (float) mission.done / mission.length;
progress = (float) ((double) mission.done / mission.length);
if (mission.urls.length > 1 && mission.current < mission.urls.length) {
progress = (progress / mission.urls.length) + ((float) mission.current / mission.urls.length);
}
}
if (hasError) {
if (Float.isNaN(progress) || Float.isInfinite(progress)) h.progress.setProgress(1f);
if (Float.isNaN(progress) || Float.isInfinite(progress))
h.progress.setProgress(1f);
h.status.setText(R.string.msg_error);
} else if (Float.isNaN(progress) || Float.isInfinite(progress)) {
h.status.setText("--.-%");
@ -275,7 +277,7 @@ public class MissionAdapter extends RecyclerView.Adapter<ViewHolder> {
if (deltaTime > 1000 && deltaDone > 0) {
float speed = (float) deltaDone / deltaTime;
float speed = (float) ((double) deltaDone / deltaTime);
String speedStr = Utility.formatSpeed(speed * 1000);
String sizeStr = Utility.formatBytes(length);
@ -497,7 +499,7 @@ public class MissionAdapter extends RecyclerView.Adapter<ViewHolder> {
mIterator.start();
mIterator.end();
for (ViewHolderItem item: mPendingDownloadsItems) {
for (ViewHolderItem item : mPendingDownloadsItems) {
item.lastTimeStamp = -1;
}
@ -592,11 +594,9 @@ public class MissionAdapter extends RecyclerView.Adapter<ViewHolder> {
checksum = menu.findItem(R.id.checksum);
itemView.setOnClickListener((v) -> {
if (((DownloadMission) item.mission).isFinished())
if (item.mission instanceof FinishedMission)
viewWithFileProvider(item.mission.getDownloadedFile());
});
//h.itemView.setOnClickListener(v -> showDetail(h));
}
private void showPopupMenu() {

View file

@ -1,7 +1,9 @@
package us.shandian.giga.ui.common;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.support.design.widget.Snackbar;
@ -11,6 +13,7 @@ import org.schabi.newpipe.R;
import java.util.ArrayList;
import us.shandian.giga.get.FinishedMission;
import us.shandian.giga.get.Mission;
import us.shandian.giga.service.DownloadManager;
import us.shandian.giga.service.DownloadManager.MissionIterator;
@ -120,6 +123,10 @@ public class Deleter {
mIterator.unHide(mission);
mDownloadManager.deleteMission(mission);
if (mission instanceof FinishedMission) {
mContext.sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.fromFile(mission.getDownloadedFile())));
}
break;
}
@ -167,4 +174,4 @@ public class Deleter {
bundle.putStringArray(BUNDLE_NAMES, names);
bundle.putStringArray(BUNDLE_LOCATIONS, locations);
}
}
}