Updated running downloads list
This commit is contained in:
parent
24a51062e0
commit
7ec9b00e8b
|
@ -5,23 +5,25 @@ import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.BaseAdapter;
|
import android.widget.BaseAdapter;
|
||||||
import android.widget.ImageButton;
|
import android.widget.ImageView;
|
||||||
import android.widget.ProgressBar;
|
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import de.danoeh.antennapod.R;
|
import de.danoeh.antennapod.R;
|
||||||
|
import de.danoeh.antennapod.core.feed.Feed;
|
||||||
|
import de.danoeh.antennapod.core.feed.FeedMedia;
|
||||||
import de.danoeh.antennapod.core.service.download.DownloadRequest;
|
import de.danoeh.antennapod.core.service.download.DownloadRequest;
|
||||||
import de.danoeh.antennapod.core.service.download.DownloadStatus;
|
import de.danoeh.antennapod.core.service.download.DownloadStatus;
|
||||||
import de.danoeh.antennapod.core.service.download.Downloader;
|
import de.danoeh.antennapod.core.service.download.Downloader;
|
||||||
import de.danoeh.antennapod.core.util.Converter;
|
import de.danoeh.antennapod.core.util.Converter;
|
||||||
|
import de.danoeh.antennapod.core.util.ThemeUtils;
|
||||||
|
import de.danoeh.antennapod.view.CircularProgressBar;
|
||||||
|
|
||||||
public class DownloadlistAdapter extends BaseAdapter {
|
public class DownloadlistAdapter extends BaseAdapter {
|
||||||
|
|
||||||
private final ItemAccess itemAccess;
|
private final ItemAccess itemAccess;
|
||||||
private final Context context;
|
private final Context context;
|
||||||
|
|
||||||
public DownloadlistAdapter(Context context,
|
public DownloadlistAdapter(Context context, ItemAccess itemAccess) {
|
||||||
ItemAccess itemAccess) {
|
|
||||||
super();
|
super();
|
||||||
this.context = context;
|
this.context = context;
|
||||||
this.itemAccess = itemAccess;
|
this.itemAccess = itemAccess;
|
||||||
|
@ -47,47 +49,44 @@ public class DownloadlistAdapter extends BaseAdapter {
|
||||||
Holder holder;
|
Holder holder;
|
||||||
Downloader downloader = getItem(position);
|
Downloader downloader = getItem(position);
|
||||||
DownloadRequest request = downloader.getDownloadRequest();
|
DownloadRequest request = downloader.getDownloadRequest();
|
||||||
// Inflate layout
|
|
||||||
if (convertView == null) {
|
if (convertView == null) {
|
||||||
holder = new Holder();
|
holder = new Holder();
|
||||||
LayoutInflater inflater = (LayoutInflater) context
|
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||||
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
|
||||||
convertView = inflater.inflate(R.layout.downloadlist_item, parent, false);
|
convertView = inflater.inflate(R.layout.downloadlist_item, parent, false);
|
||||||
holder.title = convertView.findViewById(R.id.txtvTitle);
|
holder.title = convertView.findViewById(R.id.txtvTitle);
|
||||||
holder.downloaded = convertView
|
holder.status = convertView.findViewById(R.id.txtvStatus);
|
||||||
.findViewById(R.id.txtvDownloaded);
|
holder.secondaryActionButton = convertView.findViewById(R.id.secondaryActionButton);
|
||||||
holder.percent = convertView
|
holder.secondaryActionIcon = convertView.findViewById(R.id.secondaryActionIcon);
|
||||||
.findViewById(R.id.txtvPercent);
|
holder.secondaryActionProgress = convertView.findViewById(R.id.secondaryActionProgress);
|
||||||
holder.progbar = convertView
|
|
||||||
.findViewById(R.id.progProgress);
|
|
||||||
holder.butSecondary = convertView
|
|
||||||
.findViewById(R.id.butSecondaryAction);
|
|
||||||
|
|
||||||
convertView.setTag(holder);
|
convertView.setTag(holder);
|
||||||
} else {
|
} else {
|
||||||
holder = (Holder) convertView.getTag();
|
holder = (Holder) convertView.getTag();
|
||||||
}
|
}
|
||||||
|
|
||||||
holder.title.setText(request.getTitle());
|
holder.title.setText(request.getTitle());
|
||||||
|
holder.secondaryActionIcon.setImageResource(ThemeUtils.getDrawableFromAttr(context, R.attr.navigation_cancel));
|
||||||
|
holder.secondaryActionButton.setTag(downloader);
|
||||||
|
holder.secondaryActionButton.setOnClickListener(butSecondaryListener);
|
||||||
|
holder.secondaryActionProgress.setPercentage(0, request);
|
||||||
|
|
||||||
holder.progbar.setIndeterminate(request.getSoFar() <= 0);
|
String status = "";
|
||||||
|
if (request.getFeedfileType() == Feed.FEEDFILETYPE_FEED) {
|
||||||
String strDownloaded = Converter.byteToString(request.getSoFar());
|
status += context.getString(R.string.download_type_feed);
|
||||||
if (request.getSize() != DownloadStatus.SIZE_UNKNOWN) {
|
} else if (request.getFeedfileType() == FeedMedia.FEEDFILETYPE_FEEDMEDIA) {
|
||||||
strDownloaded += " / " + Converter.byteToString(request.getSize());
|
status += context.getString(R.string.download_type_media);
|
||||||
holder.percent.setText(request.getProgressPercent() + "%");
|
|
||||||
holder.progbar.setProgress(request.getProgressPercent());
|
|
||||||
holder.percent.setVisibility(View.VISIBLE);
|
|
||||||
} else {
|
|
||||||
holder.progbar.setProgress(0);
|
|
||||||
holder.percent.setVisibility(View.INVISIBLE);
|
|
||||||
}
|
}
|
||||||
|
status += " · ";
|
||||||
holder.downloaded.setText(strDownloaded);
|
if (request.getSoFar() <= 0) {
|
||||||
|
status += context.getString(R.string.download_queued);
|
||||||
holder.butSecondary.setFocusable(false);
|
} else {
|
||||||
holder.butSecondary.setTag(downloader);
|
status += Converter.byteToString(request.getSoFar());
|
||||||
holder.butSecondary.setOnClickListener(butSecondaryListener);
|
if (request.getSize() != DownloadStatus.SIZE_UNKNOWN) {
|
||||||
|
status += " / " + Converter.byteToString(request.getSize());
|
||||||
|
holder.secondaryActionProgress.setPercentage(
|
||||||
|
0.01f * Math.max(1, request.getProgressPercent()), request);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
holder.status.setText(status);
|
||||||
|
|
||||||
return convertView;
|
return convertView;
|
||||||
}
|
}
|
||||||
|
@ -102,10 +101,10 @@ public class DownloadlistAdapter extends BaseAdapter {
|
||||||
|
|
||||||
static class Holder {
|
static class Holder {
|
||||||
TextView title;
|
TextView title;
|
||||||
TextView downloaded;
|
TextView status;
|
||||||
TextView percent;
|
View secondaryActionButton;
|
||||||
ProgressBar progbar;
|
ImageView secondaryActionIcon;
|
||||||
ImageButton butSecondary;
|
CircularProgressBar secondaryActionProgress;
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface ItemAccess {
|
public interface ItemAccess {
|
||||||
|
|
|
@ -104,11 +104,12 @@ public class RunningDownloadsFragment extends ListFragment {
|
||||||
DownloadRequest downloadRequest = downloader.getDownloadRequest();
|
DownloadRequest downloadRequest = downloader.getDownloadRequest();
|
||||||
DownloadRequester.getInstance().cancelDownload(getActivity(), downloadRequest.getSource());
|
DownloadRequester.getInstance().cancelDownload(getActivity(), downloadRequest.getSource());
|
||||||
|
|
||||||
if(downloadRequest.getFeedfileType() == FeedMedia.FEEDFILETYPE_FEEDMEDIA &&
|
if (downloadRequest.getFeedfileType() == FeedMedia.FEEDFILETYPE_FEEDMEDIA
|
||||||
UserPreferences.isEnableAutodownload()) {
|
&& UserPreferences.isEnableAutodownload()) {
|
||||||
FeedMedia media = DBReader.getFeedMedia(downloadRequest.getFeedfileId());
|
FeedMedia media = DBReader.getFeedMedia(downloadRequest.getFeedfileId());
|
||||||
DBWriter.setFeedItemAutoDownload(media.getItem(), false);
|
DBWriter.setFeedItemAutoDownload(media.getItem(), false);
|
||||||
Toast.makeText(getActivity(), R.string.download_canceled_autodownload_enabled_msg, Toast.LENGTH_SHORT).show();
|
Toast.makeText(getActivity(), R.string.download_canceled_autodownload_enabled_msg,
|
||||||
|
Toast.LENGTH_SHORT).show();
|
||||||
} else {
|
} else {
|
||||||
Toast.makeText(getActivity(), R.string.download_canceled_msg, Toast.LENGTH_SHORT).show();
|
Toast.makeText(getActivity(), R.string.download_canceled_msg, Toast.LENGTH_SHORT).show();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,90 +1,39 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<LinearLayout
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:layout_width="match_parent"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_height="wrap_content"
|
android:id="@+id/container"
|
||||||
android:orientation="horizontal"
|
android:layout_width="match_parent"
|
||||||
tools:background="@android:color/darker_gray">
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="horizontal"
|
||||||
|
android:gravity="center_vertical"
|
||||||
|
android:baselineAligned="false"
|
||||||
|
android:descendantFocusability="blocksDescendants">
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_weight="1"
|
|
||||||
android:orientation="vertical">
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/txtvTitle"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginLeft="@dimen/listitem_threeline_horizontalpadding"
|
|
||||||
android:layout_marginStart="@dimen/listitem_threeline_horizontalpadding"
|
|
||||||
android:layout_marginTop="@dimen/listitem_threeline_verticalpadding"
|
|
||||||
android:ellipsize="end"
|
|
||||||
android:lines="1"
|
|
||||||
android:textColor="?android:attr/textColorPrimary"
|
|
||||||
android:textSize="16sp"
|
|
||||||
tools:text="Download item title"
|
|
||||||
tools:background="@android:color/holo_green_dark" />
|
|
||||||
|
|
||||||
<ProgressBar
|
|
||||||
android:id="@+id/progProgress"
|
|
||||||
style="?android:attr/progressBarStyleHorizontal"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="16dp"
|
|
||||||
android:layout_marginBottom="4dp"
|
|
||||||
android:layout_marginLeft="@dimen/listitem_threeline_horizontalpadding"
|
|
||||||
android:layout_marginRight="@dimen/listitem_threeline_horizontalpadding"
|
|
||||||
android:layout_marginTop="4dp"
|
|
||||||
tools:background="@android:color/holo_blue_light" />
|
|
||||||
|
|
||||||
<RelativeLayout
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginBottom="@dimen/listitem_threeline_verticalpadding"
|
android:layout_marginBottom="@dimen/listitem_threeline_verticalpadding"
|
||||||
android:layout_marginLeft="@dimen/listitem_threeline_horizontalpadding"
|
android:layout_marginRight="@dimen/listitem_threeline_textrightpadding"
|
||||||
android:layout_marginRight="@dimen/listitem_threeline_horizontalpadding">
|
android:layout_marginEnd="@dimen/listitem_threeline_textrightpadding"
|
||||||
|
android:layout_marginTop="@dimen/listitem_threeline_verticalpadding"
|
||||||
<TextView
|
android:layout_marginLeft="16dp"
|
||||||
android:id="@+id/txtvDownloaded"
|
android:layout_marginStart="16dp"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:orientation="vertical">
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/txtvTitle"
|
||||||
|
style="@style/AntennaPod.TextView.ListItemPrimaryTitle"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
tools:text="@sample/episodes.json/data/title"
|
||||||
|
android:ellipsize="end"/>
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/txtvStatus"
|
||||||
|
style="@style/AntennaPod.TextView.ListItemSecondaryTitle"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_alignParentLeft="true"
|
tools:text="Media file · 10MB / 20MB"/>
|
||||||
android:layout_alignParentStart="true"
|
|
||||||
android:ellipsize="end"
|
|
||||||
android:lines="1"
|
|
||||||
android:textColor="?android:attr/textColorPrimary"
|
|
||||||
android:textSize="@dimen/text_size_small"
|
|
||||||
tools:text="21 MB / 42 MB"
|
|
||||||
tools:background="@android:color/holo_green_dark" />
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/txtvPercent"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_alignParentRight="true"
|
|
||||||
android:layout_alignParentEnd="true"
|
|
||||||
android:ellipsize="end"
|
|
||||||
android:lines="1"
|
|
||||||
android:textColor="?android:attr/textColorPrimary"
|
|
||||||
android:textSize="@dimen/text_size_small"
|
|
||||||
tools:text="50%"
|
|
||||||
tools:background="@android:color/holo_green_dark" />
|
|
||||||
</RelativeLayout>
|
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
<include layout="@layout/secondary_action"/>
|
||||||
<include layout="@layout/vertical_list_divider"/>
|
|
||||||
|
|
||||||
<ImageButton
|
|
||||||
android:id="@+id/butSecondaryAction"
|
|
||||||
android:layout_width="@dimen/listview_secondary_button_width"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
android:background="?attr/selectableItemBackground"
|
|
||||||
android:clickable="false"
|
|
||||||
android:contentDescription="@string/cancel_download_label"
|
|
||||||
android:focusable="false"
|
|
||||||
android:focusableInTouchMode="false"
|
|
||||||
android:src="?attr/navigation_cancel"
|
|
||||||
tools:src="@drawable/ic_cancel_white_24dp"
|
|
||||||
tools:background="@android:color/holo_green_dark" />
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
|
@ -102,6 +102,7 @@
|
||||||
<string name="feed_volume_reduction_light">Light</string>
|
<string name="feed_volume_reduction_light">Light</string>
|
||||||
<string name="feed_volume_reduction_heavy">Heavy</string>
|
<string name="feed_volume_reduction_heavy">Heavy</string>
|
||||||
<string name="parallel_downloads_suffix">\u0020parallel downloads</string>
|
<string name="parallel_downloads_suffix">\u0020parallel downloads</string>
|
||||||
|
<string name="download_queued">Download queued</string>
|
||||||
<string name="feed_auto_download_global">Global default</string>
|
<string name="feed_auto_download_global">Global default</string>
|
||||||
<string name="feed_auto_download_always">Always</string>
|
<string name="feed_auto_download_always">Always</string>
|
||||||
<string name="feed_auto_download_never">Never</string>
|
<string name="feed_auto_download_never">Never</string>
|
||||||
|
|
Loading…
Reference in New Issue