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.ViewGroup;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
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.DownloadStatus;
|
||||
import de.danoeh.antennapod.core.service.download.Downloader;
|
||||
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 {
|
||||
|
||||
private final ItemAccess itemAccess;
|
||||
private final Context context;
|
||||
|
||||
public DownloadlistAdapter(Context context,
|
||||
ItemAccess itemAccess) {
|
||||
public DownloadlistAdapter(Context context, ItemAccess itemAccess) {
|
||||
super();
|
||||
this.context = context;
|
||||
this.itemAccess = itemAccess;
|
||||
|
@ -47,47 +49,44 @@ public class DownloadlistAdapter extends BaseAdapter {
|
|||
Holder holder;
|
||||
Downloader downloader = getItem(position);
|
||||
DownloadRequest request = downloader.getDownloadRequest();
|
||||
// Inflate layout
|
||||
if (convertView == null) {
|
||||
holder = new Holder();
|
||||
LayoutInflater inflater = (LayoutInflater) context
|
||||
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
convertView = inflater.inflate(R.layout.downloadlist_item, parent, false);
|
||||
holder.title = convertView.findViewById(R.id.txtvTitle);
|
||||
holder.downloaded = convertView
|
||||
.findViewById(R.id.txtvDownloaded);
|
||||
holder.percent = convertView
|
||||
.findViewById(R.id.txtvPercent);
|
||||
holder.progbar = convertView
|
||||
.findViewById(R.id.progProgress);
|
||||
holder.butSecondary = convertView
|
||||
.findViewById(R.id.butSecondaryAction);
|
||||
|
||||
holder.status = convertView.findViewById(R.id.txtvStatus);
|
||||
holder.secondaryActionButton = convertView.findViewById(R.id.secondaryActionButton);
|
||||
holder.secondaryActionIcon = convertView.findViewById(R.id.secondaryActionIcon);
|
||||
holder.secondaryActionProgress = convertView.findViewById(R.id.secondaryActionProgress);
|
||||
convertView.setTag(holder);
|
||||
} else {
|
||||
holder = (Holder) convertView.getTag();
|
||||
}
|
||||
|
||||
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 strDownloaded = Converter.byteToString(request.getSoFar());
|
||||
if (request.getSize() != DownloadStatus.SIZE_UNKNOWN) {
|
||||
strDownloaded += " / " + Converter.byteToString(request.getSize());
|
||||
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);
|
||||
String status = "";
|
||||
if (request.getFeedfileType() == Feed.FEEDFILETYPE_FEED) {
|
||||
status += context.getString(R.string.download_type_feed);
|
||||
} else if (request.getFeedfileType() == FeedMedia.FEEDFILETYPE_FEEDMEDIA) {
|
||||
status += context.getString(R.string.download_type_media);
|
||||
}
|
||||
|
||||
holder.downloaded.setText(strDownloaded);
|
||||
|
||||
holder.butSecondary.setFocusable(false);
|
||||
holder.butSecondary.setTag(downloader);
|
||||
holder.butSecondary.setOnClickListener(butSecondaryListener);
|
||||
status += " · ";
|
||||
if (request.getSoFar() <= 0) {
|
||||
status += context.getString(R.string.download_queued);
|
||||
} else {
|
||||
status += Converter.byteToString(request.getSoFar());
|
||||
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;
|
||||
}
|
||||
|
@ -102,10 +101,10 @@ public class DownloadlistAdapter extends BaseAdapter {
|
|||
|
||||
static class Holder {
|
||||
TextView title;
|
||||
TextView downloaded;
|
||||
TextView percent;
|
||||
ProgressBar progbar;
|
||||
ImageButton butSecondary;
|
||||
TextView status;
|
||||
View secondaryActionButton;
|
||||
ImageView secondaryActionIcon;
|
||||
CircularProgressBar secondaryActionProgress;
|
||||
}
|
||||
|
||||
public interface ItemAccess {
|
||||
|
|
|
@ -104,11 +104,12 @@ public class RunningDownloadsFragment extends ListFragment {
|
|||
DownloadRequest downloadRequest = downloader.getDownloadRequest();
|
||||
DownloadRequester.getInstance().cancelDownload(getActivity(), downloadRequest.getSource());
|
||||
|
||||
if(downloadRequest.getFeedfileType() == FeedMedia.FEEDFILETYPE_FEEDMEDIA &&
|
||||
UserPreferences.isEnableAutodownload()) {
|
||||
if (downloadRequest.getFeedfileType() == FeedMedia.FEEDFILETYPE_FEEDMEDIA
|
||||
&& UserPreferences.isEnableAutodownload()) {
|
||||
FeedMedia media = DBReader.getFeedMedia(downloadRequest.getFeedfileId());
|
||||
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 {
|
||||
Toast.makeText(getActivity(), R.string.download_canceled_msg, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
|
|
@ -1,90 +1,39 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
tools:background="@android:color/darker_gray">
|
||||
android:gravity="center_vertical"
|
||||
android:baselineAligned="false"
|
||||
android:descendantFocusability="blocksDescendants">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="@dimen/listitem_threeline_verticalpadding"
|
||||
android:layout_marginRight="@dimen/listitem_threeline_textrightpadding"
|
||||
android:layout_marginEnd="@dimen/listitem_threeline_textrightpadding"
|
||||
android:layout_marginTop="@dimen/listitem_threeline_verticalpadding"
|
||||
android:layout_marginLeft="16dp"
|
||||
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"
|
||||
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_marginBottom="@dimen/listitem_threeline_verticalpadding"
|
||||
android:layout_marginLeft="@dimen/listitem_threeline_horizontalpadding"
|
||||
android:layout_marginRight="@dimen/listitem_threeline_horizontalpadding">
|
||||
|
||||
tools:text="@sample/episodes.json/data/title"
|
||||
android:ellipsize="end"/>
|
||||
<TextView
|
||||
android:id="@+id/txtvDownloaded"
|
||||
android:id="@+id/txtvStatus"
|
||||
style="@style/AntennaPod.TextView.ListItemSecondaryTitle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentLeft="true"
|
||||
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>
|
||||
|
||||
tools:text="Media file · 10MB / 20MB"/>
|
||||
</LinearLayout>
|
||||
|
||||
<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" />
|
||||
<include layout="@layout/secondary_action"/>
|
||||
</LinearLayout>
|
||||
|
|
|
@ -102,6 +102,7 @@
|
|||
<string name="feed_volume_reduction_light">Light</string>
|
||||
<string name="feed_volume_reduction_heavy">Heavy</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_always">Always</string>
|
||||
<string name="feed_auto_download_never">Never</string>
|
||||
|
|
Loading…
Reference in New Issue