Merge pull request #1020 from mfietz/feature/queue-information

Queue shows number of episodes and total duration
This commit is contained in:
Tom Hennen 2015-07-20 20:10:18 -04:00
commit d1ef7f63ff
3 changed files with 59 additions and 7 deletions

View File

@ -47,6 +47,7 @@ import de.danoeh.antennapod.core.storage.DBTasks;
import de.danoeh.antennapod.core.storage.DBWriter;
import de.danoeh.antennapod.core.storage.DownloadRequestException;
import de.danoeh.antennapod.core.storage.DownloadRequester;
import de.danoeh.antennapod.core.util.Converter;
import de.danoeh.antennapod.core.util.LongList;
import de.danoeh.antennapod.core.util.QueueSorter;
import de.danoeh.antennapod.core.util.gui.FeedItemUndoToken;
@ -66,6 +67,7 @@ public class QueueFragment extends Fragment {
EventDistributor.DOWNLOAD_QUEUED |
EventDistributor.PLAYER_STATUS_UPDATE;
private TextView infoBar;
private DragSortListView listView;
private QueueListAdapter listAdapter;
private TextView txtvEmpty;
@ -363,6 +365,7 @@ public class QueueFragment extends Fragment {
((MainActivity) getActivity()).getSupportActionBar().setTitle(R.string.queue_label);
View root = inflater.inflate(R.layout.queue_fragment, container, false);
infoBar = (TextView) root.findViewById(R.id.info_bar);
listView = (DragSortListView) root.findViewById(android.R.id.list);
txtvEmpty = (TextView) root.findViewById(android.R.id.empty);
progLoading = (ProgressBar) root.findViewById(R.id.progLoading);
@ -469,6 +472,20 @@ public class QueueFragment extends Fragment {
// we need to refresh the options menu because it sometimes
// needs data that may have just been loaded.
getActivity().supportInvalidateOptionsMenu();
// refresh information bar
String info = queue.size() + getString(R.string.episodes_suffix);
if(queue.size() > 0) {
int duration = 0;
for(FeedItem item : queue) {
if(item.getMedia() != null) {
duration += item.getMedia().getDuration();
}
}
info += " \u2022 ";
info += Converter.getDurationStringLocalized(getActivity(), duration);
}
infoBar.setText(info);
}
private DownloadObserver.Callback downloadObserverCallback = new DownloadObserver.Callback() {

View File

@ -1,18 +1,33 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:dslv="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/info_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:gravity="center"
android:textSize="12sp"
android:text="42 episodes \u2022 5 hours 17 minutes"/>
<View
android:id="@+id/divider"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_below="@id/info_bar"
android:background="?android:attr/listDivider"/>
<com.mobeta.android.dslv.DragSortListView
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_height="wrap_content"
android:clipToPadding="false"
android:paddingBottom="@dimen/list_vertical_padding"
android:paddingTop="@dimen/list_vertical_padding"
android:scrollbarStyle="outsideOverlay"
android:layout_below="@+id/divider"
dslv:collapsed_height="2dp"
dslv:drag_enabled="true"
dslv:drag_handle_id="@id/drag_handle"
@ -31,7 +46,7 @@
android:id="@id/android:empty"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_centerInParent="true"
android:gravity="center"
android:text="@string/no_items_label" />
@ -39,12 +54,13 @@
android:id="@+id/progLoading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_centerInParent="true"
android:indeterminateOnly="true"
android:visibility="gone" />
<LinearLayout
android:id="@+id/undobar"
android:layout_alignParentBottom="true"
style="@style/UndoBar">
<TextView
@ -57,4 +73,4 @@
</LinearLayout>
</FrameLayout>
</RelativeLayout>

View File

@ -1,7 +1,10 @@
package de.danoeh.antennapod.core.util;
import android.content.Context;
import android.util.Log;
import de.danoeh.antennapod.core.R;
/** Provides methods for converting various units. */
public final class Converter {
/** Class shall not be instantiated. */
@ -100,4 +103,20 @@ public final class Converter {
Integer.valueOf(parts[1]) * 1000 * 60;
}
/** Converts milliseconds to a localized string containing hours and minutes */
public static String getDurationStringLocalized(Context context, int duration) {
int h = duration / HOURS_MIL;
int rest = duration - h * HOURS_MIL;
int m = rest / MINUTES_MIL;
String result = "";
if(h > 0) {
String hours = context.getString(R.string.time_unit_hours);
result += h + " " + hours + " ";
}
String minutes = context.getString(R.string.time_unit_minutes);
result += m + " " + minutes;
return result;
}
}