diff options
18 files changed, 569 insertions, 62 deletions
diff --git a/res/drawable-hdpi/ic_action_overflow.png b/res/drawable-hdpi/ic_action_overflow.png Binary files differnew file mode 100644 index 000000000..002fc4bfb --- /dev/null +++ b/res/drawable-hdpi/ic_action_overflow.png diff --git a/res/drawable-hdpi/ic_action_overflow_dark.png b/res/drawable-hdpi/ic_action_overflow_dark.png Binary files differnew file mode 100644 index 000000000..c8792cbe2 --- /dev/null +++ b/res/drawable-hdpi/ic_action_overflow_dark.png diff --git a/res/drawable-mdpi/ic_action_overflow.png b/res/drawable-mdpi/ic_action_overflow.png Binary files differnew file mode 100644 index 000000000..6f0fb23f4 --- /dev/null +++ b/res/drawable-mdpi/ic_action_overflow.png diff --git a/res/drawable-mdpi/ic_action_overflow_dark.png b/res/drawable-mdpi/ic_action_overflow_dark.png Binary files differnew file mode 100644 index 000000000..b4a4a221f --- /dev/null +++ b/res/drawable-mdpi/ic_action_overflow_dark.png diff --git a/res/drawable-xhdpi/ic_action_overflow.png b/res/drawable-xhdpi/ic_action_overflow.png Binary files differnew file mode 100644 index 000000000..7ba4e10ea --- /dev/null +++ b/res/drawable-xhdpi/ic_action_overflow.png diff --git a/res/drawable-xhdpi/ic_action_overflow_dark.png b/res/drawable-xhdpi/ic_action_overflow_dark.png Binary files differnew file mode 100644 index 000000000..5d8af5d63 --- /dev/null +++ b/res/drawable-xhdpi/ic_action_overflow_dark.png diff --git a/res/drawable-xxhdpi/ic_action_overflow.png b/res/drawable-xxhdpi/ic_action_overflow.png Binary files differnew file mode 100644 index 000000000..5a603b6bc --- /dev/null +++ b/res/drawable-xxhdpi/ic_action_overflow.png diff --git a/res/drawable-xxhdpi/ic_action_overflow_dark.png b/res/drawable-xxhdpi/ic_action_overflow_dark.png Binary files differnew file mode 100644 index 000000000..e22049b1e --- /dev/null +++ b/res/drawable-xxhdpi/ic_action_overflow_dark.png diff --git a/res/layout/feeditem_dialog.xml b/res/layout/feeditem_dialog.xml new file mode 100644 index 000000000..3b7c02b72 --- /dev/null +++ b/res/layout/feeditem_dialog.xml @@ -0,0 +1,52 @@ +<?xml version="1.0" encoding="utf-8"?> + +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:tools="http://schemas.android.com/tools" + android:orientation="vertical" + android:layout_width="match_parent" + android:layout_height="match_parent"> + + <LinearLayout + android:id="@+id/header" + android:orientation="horizontal" + android:layout_width="match_parent" + android:layout_height="wrap_content"> + + <ImageButton + android:layout_width="0dp" + android:layout_height="48dp" + android:layout_weight="1" + android:id="@+id/butAction1" + android:background="?attr/borderless_button" + tools:ignore="ContentDescription"/> + + <ImageButton + android:layout_width="0dp" + android:layout_height="48dp" + android:layout_weight="1" + android:id="@+id/butAction2" + android:background="?attr/borderless_button" + tools:ignore="ContentDescription"/> + + <ImageButton + android:layout_width="0dp" + android:layout_height="48dp" + android:layout_weight="1" + android:id="@+id/butMoreActions" + android:background="?attr/borderless_button" + android:src="?attr/ic_action_overflow" + android:contentDescription="@string/butAction_label"/> + </LinearLayout> + + <View + android:layout_width="match_parent" + android:layout_height="3dp" + android:background="@color/bright_blue"/> + + <WebView + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:id="@+id/webview"/> + + +</LinearLayout>
\ No newline at end of file diff --git a/res/menu/feeditem_dialog.xml b/res/menu/feeditem_dialog.xml new file mode 100644 index 000000000..f33b7502a --- /dev/null +++ b/res/menu/feeditem_dialog.xml @@ -0,0 +1,48 @@ +<?xml version="1.0" encoding="utf-8"?> +<menu xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:custom="http://schemas.android.com/apk/res-auto"> + + <item + android:id="@id/skip_episode_item" + android:title="@string/skip_episode_label" + custom:showAsAction="collapseActionView"> + </item> + + <item + android:id="@+id/mark_read_item" + custom:showAsAction="collapseActionView" + android:title="@string/mark_read_label"> + </item> + <item + android:id="@+id/mark_unread_item" + custom:showAsAction="collapseActionView" + android:title="@string/mark_unread_label"> + </item> + <item + android:id="@+id/add_to_queue_item" + custom:showAsAction="collapseActionView" + android:title="@string/add_to_queue_label"> + </item> + <item + android:id="@+id/remove_from_queue_item" + custom:showAsAction="collapseActionView" + android:title="@string/remove_from_queue_label"> + </item> + <item + android:id="@+id/share_link_item" + custom:showAsAction="collapseActionView" + android:title="@string/share_link_label"> + </item> + <item + android:id="@+id/visit_website_item" + android:icon="?attr/location_web_site" + custom:showAsAction="ifRoom|collapseActionView" + android:title="@string/visit_website_label"> + </item> + <item + android:id="@+id/support_item" + custom:showAsAction="collapseActionView" + android:title="@string/support_label"> + </item> + +</menu>
\ No newline at end of file diff --git a/res/values/attrs.xml b/res/values/attrs.xml index 36afb6d7b..751134a50 100644 --- a/res/values/attrs.xml +++ b/res/values/attrs.xml @@ -1,40 +1,41 @@ <?xml version="1.0" encoding="utf-8"?> <resources> - <attr name="action_about" format="reference" /> - <attr name="action_search" format="reference" /> - <attr name="action_settings" format="reference" /> - <attr name="action_stream" format="reference" /> - <attr name="av_download" format="reference" /> - <attr name="av_fast_forward" format="reference" /> - <attr name="av_pause" format="reference" /> - <attr name="av_play" format="reference" /> - <attr name="av_rewind" format="reference" /> - <attr name="content_discard" format="reference" /> - <attr name="content_new" format="reference" /> - <attr name="default_cover" format="reference" /> - <attr name="device_access_time" format="reference" /> - <attr name="location_web_site" format="reference" /> - <attr name="navigation_accept" format="reference" /> - <attr name="navigation_cancel" format="reference" /> - <attr name="navigation_expand" format="reference" /> - <attr name="navigation_collapse" format="reference" /> - <attr name="navigation_refresh" format="reference" /> - <attr name="navigation_up" format="reference" /> - <attr name="navigation_shownotes" format="reference" /> - <attr name="navigation_chapters" format="reference" /> - <attr name="social_share" format="reference" /> - <attr name="stat_playlist" format="reference" /> - <attr name="type_audio" format="reference" /> - <attr name="type_video" format="reference" /> - <attr name="borderless_button" format="reference" /> - <attr name="spinner_button" format="reference" /> - <attr name="overlay_drawable" format="reference" /> - <attr name="dragview_background" format="reference" /> - <attr name="dragview_float_background" format="reference" /> + <attr name="action_about" format="reference"/> + <attr name="action_search" format="reference"/> + <attr name="action_settings" format="reference"/> + <attr name="action_stream" format="reference"/> + <attr name="av_download" format="reference"/> + <attr name="av_fast_forward" format="reference"/> + <attr name="av_pause" format="reference"/> + <attr name="av_play" format="reference"/> + <attr name="av_rewind" format="reference"/> + <attr name="content_discard" format="reference"/> + <attr name="content_new" format="reference"/> + <attr name="default_cover" format="reference"/> + <attr name="device_access_time" format="reference"/> + <attr name="location_web_site" format="reference"/> + <attr name="navigation_accept" format="reference"/> + <attr name="navigation_cancel" format="reference"/> + <attr name="navigation_expand" format="reference"/> + <attr name="navigation_collapse" format="reference"/> + <attr name="navigation_refresh" format="reference"/> + <attr name="navigation_up" format="reference"/> + <attr name="navigation_shownotes" format="reference"/> + <attr name="navigation_chapters" format="reference"/> + <attr name="social_share" format="reference"/> + <attr name="stat_playlist" format="reference"/> + <attr name="type_audio" format="reference"/> + <attr name="type_video" format="reference"/> + <attr name="borderless_button" format="reference"/> + <attr name="spinner_button" format="reference"/> + <attr name="overlay_drawable" format="reference"/> + <attr name="dragview_background" format="reference"/> + <attr name="dragview_float_background" format="reference"/> + <attr name="ic_action_overflow" format="reference"/> <!-- Used in itemdescription --> - <attr name="non_transparent_background" format="reference" /> - <attr name="overlay_background" format="color" /> + <attr name="non_transparent_background" format="reference"/> + <attr name="overlay_background" format="color"/> <attr name="nav_drawer_background" format="color"/> <attr name="nav_drawer_toggle" format="reference"/> diff --git a/res/values/styles.xml b/res/values/styles.xml index e29329c78..f169b6301 100644 --- a/res/values/styles.xml +++ b/res/values/styles.xml @@ -37,6 +37,7 @@ <item name="attr/dragview_float_background">@color/white</item> <item name="attr/nav_drawer_background">@color/white</item> <item name="attr/nav_drawer_toggle">@drawable/ic_drawer</item> + <item name="attr/ic_action_overflow">@drawable/ic_action_overflow</item> </style> <style name="Theme.AntennaPod.Dark" parent="@style/Theme.AppCompat"> @@ -75,41 +76,45 @@ <item name="attr/dragview_float_background">@color/black</item> <item name="attr/nav_drawer_background">#3B3B3B</item> <item name="attr/nav_drawer_toggle">@drawable/ic_drawer_dark</item> + <item name="attr/ic_action_overflow">@drawable/ic_action_overflow_dark</item> + </style> <style name="UndoBar"> - <item name="android:layout_width">match_parent</item> - <item name="android:layout_height">48dp</item> - <item name="android:layout_gravity">bottom</item> - <item name="android:layout_marginLeft">8dp</item> - <item name="android:layout_marginRight">8dp</item> - <item name="android:layout_marginBottom">16dp</item> - <item name="android:orientation">horizontal</item> - <item name="android:background">@drawable/undobar</item> - <item name="android:clickable">true</item> - <item name="android:divider">@drawable/undobar_divider</item> + <item name="android:layout_width">match_parent</item> + <item name="android:layout_height">48dp</item> + <item name="android:layout_gravity">bottom</item> + <item name="android:layout_marginLeft">8dp</item> + <item name="android:layout_marginRight">8dp</item> + <item name="android:layout_marginBottom">16dp</item> + <item name="android:orientation">horizontal</item> + <item name="android:background">@drawable/undobar</item> + <item name="android:clickable">true</item> + <item name="android:divider">@drawable/undobar_divider</item> </style> + <style name="UndoBarMessage"> - <item name="android:layout_width">0dp</item> - <item name="android:layout_weight">1</item> - <item name="android:layout_height">wrap_content</item> - <item name="android:layout_marginLeft">16dp</item> - <item name="android:layout_gravity">center_vertical</item> - <item name="android:layout_marginRight">16dp</item> - <item name="android:textAppearance">?android:textAppearanceMedium</item> - <item name="android:textColor">#fff</item> + <item name="android:layout_width">0dp</item> + <item name="android:layout_weight">1</item> + <item name="android:layout_height">wrap_content</item> + <item name="android:layout_marginLeft">16dp</item> + <item name="android:layout_gravity">center_vertical</item> + <item name="android:layout_marginRight">16dp</item> + <item name="android:textAppearance">?android:textAppearanceMedium</item> + <item name="android:textColor">#fff</item> </style> + <style name="UndoBarButton"> - <item name="android:layout_width">wrap_content</item> - <item name="android:layout_height">match_parent</item> - <item name="android:paddingLeft">16dp</item> - <item name="android:paddingRight">16dp</item> - <item name="android:background">@drawable/undobar_button</item> - <item name="android:drawableLeft">@drawable/ic_undobar_undo</item> - <item name="android:drawablePadding">12dp</item> - <item name="android:textAppearance">?android:textAppearanceSmall</item> - <item name="android:textStyle">bold</item> - <item name="android:textColor">#fff</item> - <item name="android:text">@string/undo</item> + <item name="android:layout_width">wrap_content</item> + <item name="android:layout_height">match_parent</item> + <item name="android:paddingLeft">16dp</item> + <item name="android:paddingRight">16dp</item> + <item name="android:background">@drawable/undobar_button</item> + <item name="android:drawableLeft">@drawable/ic_undobar_undo</item> + <item name="android:drawablePadding">12dp</item> + <item name="android:textAppearance">?android:textAppearanceSmall</item> + <item name="android:textStyle">bold</item> + <item name="android:textColor">#fff</item> + <item name="android:text">@string/undo</item> </style> </resources> diff --git a/src/de/danoeh/antennapod/adapter/DefaultActionButtonCallback.java b/src/de/danoeh/antennapod/adapter/DefaultActionButtonCallback.java index 7c023d2c2..3acd587af 100644 --- a/src/de/danoeh/antennapod/adapter/DefaultActionButtonCallback.java +++ b/src/de/danoeh/antennapod/adapter/DefaultActionButtonCallback.java @@ -26,6 +26,10 @@ public class DefaultActionButtonCallback implements ActionButtonCallback { @Override public void onActionButtonPressed(final FeedItem item) { final FeedMedia media = item.getMedia(); + if (media == null) { + return; + } + boolean isDownloading = DownloadRequester.getInstance().isDownloadingFile(media); if (!isDownloading && !media.isDownloaded()) { try { diff --git a/src/de/danoeh/antennapod/dialog/FeedItemDialog.java b/src/de/danoeh/antennapod/dialog/FeedItemDialog.java new file mode 100644 index 000000000..62c274858 --- /dev/null +++ b/src/de/danoeh/antennapod/dialog/FeedItemDialog.java @@ -0,0 +1,306 @@ +package de.danoeh.antennapod.dialog; + +import android.app.Dialog; +import android.content.ActivityNotFoundException; +import android.content.Context; +import android.content.Intent; +import android.content.res.TypedArray; +import android.net.Uri; +import android.os.AsyncTask; +import android.os.Build; +import android.os.Bundle; +import android.support.v7.widget.PopupMenu; +import android.util.Log; +import android.util.TypedValue; +import android.view.MenuItem; +import android.view.View; +import android.webkit.WebSettings; +import android.webkit.WebView; +import android.webkit.WebViewClient; +import android.widget.ImageButton; +import android.widget.Toast; +import de.danoeh.antennapod.BuildConfig; +import de.danoeh.antennapod.R; +import de.danoeh.antennapod.adapter.DefaultActionButtonCallback; +import de.danoeh.antennapod.feed.FeedItem; +import de.danoeh.antennapod.feed.FeedMedia; +import de.danoeh.antennapod.preferences.UserPreferences; +import de.danoeh.antennapod.storage.DBTasks; +import de.danoeh.antennapod.storage.DBWriter; +import de.danoeh.antennapod.storage.DownloadRequestException; +import de.danoeh.antennapod.storage.DownloadRequester; +import de.danoeh.antennapod.util.QueueAccess; +import de.danoeh.antennapod.util.ShownotesProvider; +import de.danoeh.antennapod.util.menuhandler.FeedItemMenuHandler; +import org.apache.commons.lang3.StringEscapeUtils; + +import java.util.Collection; +import java.util.concurrent.Callable; + +/** + * Shows information about a specific FeedItem and provides actions like playing, downloading, etc. + */ +public class FeedItemDialog extends Dialog { + private static final String TAG = "FeedItemDialog"; + + private FeedItem item; + private QueueAccess queue; + + private View header; + private WebView webvDescription; + private ImageButton butAction1; + private ImageButton butAction2; + private ImageButton butMore; + private PopupMenu popupMenu; + + public FeedItemDialog(Context context, FeedItem item, QueueAccess queue) { + super(context); + if (item == null) throw new IllegalArgumentException("item = null"); + if (queue == null) throw new IllegalArgumentException("queue = null"); + this.item = item; + this.queue = queue; + } + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.feeditem_dialog); + + header = findViewById(R.id.header); + webvDescription = (WebView) findViewById(R.id.webview); + butAction1 = (ImageButton) findViewById(R.id.butAction1); + butAction2 = (ImageButton) findViewById(R.id.butAction2); + butMore = (ImageButton) findViewById(R.id.butMoreActions); + popupMenu = new PopupMenu(getContext(), butMore); + + webvDescription.setWebViewClient(new WebViewClient()); + setTitle(item.getTitle()); + + if (UserPreferences.getTheme() == R.style.Theme_AntennaPod_Dark) { + if (Build.VERSION.SDK_INT >= 11 + && Build.VERSION.SDK_INT <= Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) { + webvDescription.setLayerType(View.LAYER_TYPE_SOFTWARE, null); + } + webvDescription.setBackgroundColor(getContext().getResources().getColor( + R.color.black)); + } + webvDescription.getSettings().setUseWideViewPort(false); + webvDescription.getSettings().setLayoutAlgorithm( + WebSettings.LayoutAlgorithm.NARROW_COLUMNS); + webvDescription.getSettings().setLoadWithOverviewMode(true); + webvDescription.setWebViewClient(new WebViewClient() { + + @Override + public boolean shouldOverrideUrlLoading(WebView view, String url) { + Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); + try { + getContext().startActivity(intent); + } catch (ActivityNotFoundException e) { + e.printStackTrace(); + return false; + } + return true; + } + }); + + loadDescriptionWebview(item); + + butAction1.setOnClickListener(new View.OnClickListener() { + DefaultActionButtonCallback actionButtonCallback = new DefaultActionButtonCallback(getContext()); + + @Override + + public void onClick(View v) { + FeedMedia media = item.getMedia(); + if (media == null) { + return; + } + actionButtonCallback.onActionButtonPressed(item); + + } + } + ); + + butAction2.setOnClickListener(new View.OnClickListener() + + { + @Override + public void onClick(View v) { + FeedMedia media = item.getMedia(); + if (media == null) { + return; + } + + if (!media.isDownloaded()) { + DBTasks.playMedia(getContext(), media, true, true, true); + dismiss(); + } else { + DBWriter.deleteFeedMediaOfItem(getContext(), media.getId()); + } + } + } + ); + + butMore.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + popupMenu.getMenu().clear(); + popupMenu.inflate(R.menu.feeditem_dialog); + FeedItemMenuHandler.onPrepareMenu(popupMenuInterface, item, true, queue); + popupMenu.show(); + } + } + ); + + popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { + @Override + public boolean onMenuItemClick(MenuItem menuItem) { + + try { + return FeedItemMenuHandler.onMenuItemClicked(getContext(), menuItem.getItemId(), item); + } catch (DownloadRequestException e) { + e.printStackTrace(); + Toast.makeText(getContext(), e.getMessage(), Toast.LENGTH_LONG).show(); + return true; + } + } + } + ); + + updateMenuAppearance(); + } + + private final FeedItemMenuHandler.MenuInterface popupMenuInterface = new FeedItemMenuHandler.MenuInterface() { + @Override + public void setItemVisibility(int id, boolean visible) { + MenuItem item = popupMenu.getMenu().findItem(id); + if (item != null) { + item.setVisible(visible); + } + } + }; + + public void updateMenuAppearance() { + if (item == null || queue == null) { + Log.w(TAG, "UpdateMenuAppearance called while item or queue was null"); + return; + } + FeedMedia media = item.getMedia(); + if (media == null) { + header.setVisibility(View.GONE); + } else { + header.setVisibility(View.VISIBLE); + boolean isDownloading = DownloadRequester.getInstance().isDownloadingFile(media); + TypedArray drawables = getContext().obtainStyledAttributes(new int[]{R.attr.av_play, + R.attr.av_download, R.attr.action_stream, R.attr.content_discard, R.attr.navigation_cancel}); + + if (!media.isDownloaded()) { + butAction2.setImageDrawable(drawables.getDrawable(2)); + butAction2.setContentDescription(getContext().getString(R.string.stream_label)); + } else { + butAction2.setImageDrawable(drawables.getDrawable(3)); + butAction2.setContentDescription(getContext().getString(R.string.remove_episode_lable)); + } + + if (isDownloading) { + butAction1.setImageDrawable(drawables.getDrawable(4)); + butAction1.setContentDescription(getContext().getString(R.string.cancel_download_label)); + } else if (media.isDownloaded()) { + butAction1.setImageDrawable(drawables.getDrawable(0)); + butAction1.setContentDescription(getContext().getString(R.string.play_label)); + } else { + butAction1.setImageDrawable(drawables.getDrawable(1)); + butAction1.setContentDescription(getContext().getString(R.string.download_label)); + } + + drawables.recycle(); + } + } + + + private void loadDescriptionWebview(final ShownotesProvider shownotesProvider) { + AsyncTask<Void, Void, Void> loadTask = new AsyncTask<Void, Void, Void>() { + String data; + + + private String applyWebviewStyle(String textColor, String data) { + final String WEBVIEW_STYLE = "<html><head><style type=\"text/css\"> * { color: %s; font-family: Helvetica; line-height: 1.3em; font-size: 11pt; } a { font-style: normal; text-decoration: none; font-weight: normal; color: #00A8DF; } img { display: block; margin: 10 auto; max-width: %s; height: auto; } body { margin: %dpx %dpx %dpx %dpx; }</style></head><body>%s</body></html>"; + final int pageMargin = (int) TypedValue.applyDimension( + TypedValue.COMPLEX_UNIT_DIP, 8, getContext().getResources() + .getDisplayMetrics() + ); + return String.format(WEBVIEW_STYLE, textColor, "100%", pageMargin, + pageMargin, pageMargin, pageMargin, data); + } + + + @Override + protected void onPostExecute(Void result) { + super.onPostExecute(result); + // /webvDescription.loadData(url, "text/html", "utf-8"); + if (FeedItemDialog.this.isShowing() && webvDescription != null) { + webvDescription.loadDataWithBaseURL(null, data, "text/html", + "utf-8", "about:blank"); + if (BuildConfig.DEBUG) + Log.d(TAG, "Webview loaded"); + } + } + + + @Override + protected Void doInBackground(Void... params) { + if (BuildConfig.DEBUG) + Log.d(TAG, "Loading Webview"); + try { + Callable<String> shownotesLoadTask = shownotesProvider.loadShownotes(); + final String shownotes = shownotesLoadTask.call(); + + data = StringEscapeUtils.unescapeHtml4(shownotes); + TypedArray res = getContext() + .getTheme() + .obtainStyledAttributes( + new int[]{android.R.attr.textColorPrimary}); + int colorResource = res.getColor(0, 0); + String colorString = String.format("#%06X", + 0xFFFFFF & colorResource); + Log.i(TAG, "text color: " + colorString); + res.recycle(); + data = applyWebviewStyle(colorString, data); + + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } + + }; + loadTask.execute(); + } + + public void setItem(FeedItem item) { + if (item == null) throw new IllegalArgumentException("item = null"); + this.item = item; + } + + public void setItemFromCollection(Collection<FeedItem> items) { + for (FeedItem item : items) { + if (item.getId() == this.item.getId()) { + setItem(item); + break; + } + } + } + + public void setQueue(QueueAccess queue) { + if (queue == null) throw new IllegalArgumentException("queue = null"); + this.queue = queue; + } + + public FeedItem getItem() { + return item; + } + + public QueueAccess getQueue() { + return queue; + } +} diff --git a/src/de/danoeh/antennapod/fragment/ItemlistFragment.java b/src/de/danoeh/antennapod/fragment/ItemlistFragment.java index dce64aa5e..de3d48d55 100644 --- a/src/de/danoeh/antennapod/fragment/ItemlistFragment.java +++ b/src/de/danoeh/antennapod/fragment/ItemlistFragment.java @@ -23,6 +23,7 @@ import de.danoeh.antennapod.adapter.DefaultActionButtonCallback; import de.danoeh.antennapod.adapter.InternalFeedItemlistAdapter; import de.danoeh.antennapod.asynctask.DownloadObserver; import de.danoeh.antennapod.asynctask.ImageLoader; +import de.danoeh.antennapod.dialog.FeedItemDialog; import de.danoeh.antennapod.feed.EventDistributor; import de.danoeh.antennapod.feed.Feed; import de.danoeh.antennapod.feed.FeedItem; @@ -65,6 +66,8 @@ public class ItemlistFragment extends ListFragment { private DownloadObserver downloadObserver; private List<Downloader> downloaderList; + private FeedItemDialog feedItemDialog; + /** * Creates new ItemlistFragment which shows the Feeditems of a specific @@ -122,6 +125,7 @@ public class ItemlistFragment extends ListFragment { if (downloadObserver != null) { downloadObserver.onPause(); } + feedItemDialog = null; } @Override @@ -149,12 +153,16 @@ public class ItemlistFragment extends ListFragment { @Override public void onListItemClick(ListView l, View v, int position, long id) { FeedItem selection = adapter.getItem(position - l.getHeaderViewsCount()); + /* Intent showItem = new Intent(getActivity(), ItemviewActivity.class); showItem.putExtra(FeedlistFragment.EXTRA_SELECTED_FEED, selection .getFeed().getId()); showItem.putExtra(EXTRA_SELECTED_FEEDITEM, selection.getId()); startActivity(showItem); + */ + feedItemDialog = new FeedItemDialog(activity.get(), selection, queue); + feedItemDialog.show(); } private EventDistributor.EventListener contentUpdate = new EventDistributor.EventListener() { @@ -200,6 +208,13 @@ public class ItemlistFragment extends ListFragment { setListShown(true); adapter.notifyDataSetChanged(); + if (feedItemDialog != null && feedItemDialog.isShowing()) { + feedItemDialog.setItemFromCollection(feed.getItems()); + feedItemDialog.setQueue(queue); + feedItemDialog.updateMenuAppearance(); + } + + } private DownloadObserver.Callback downloadObserverCallback = new DownloadObserver.Callback() { @@ -208,6 +223,9 @@ public class ItemlistFragment extends ListFragment { if (adapter != null) { adapter.notifyDataSetChanged(); } + if (feedItemDialog != null && feedItemDialog.isShowing()) { + feedItemDialog.updateMenuAppearance(); + } } @Override diff --git a/src/de/danoeh/antennapod/fragment/NewEpisodesFragment.java b/src/de/danoeh/antennapod/fragment/NewEpisodesFragment.java index 3377dc565..c2dccd820 100644 --- a/src/de/danoeh/antennapod/fragment/NewEpisodesFragment.java +++ b/src/de/danoeh/antennapod/fragment/NewEpisodesFragment.java @@ -9,6 +9,7 @@ import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.widget.AdapterView; import android.widget.ProgressBar; import android.widget.TextView; import com.mobeta.android.dslv.DragSortListView; @@ -17,6 +18,7 @@ import de.danoeh.antennapod.activity.MainActivity; import de.danoeh.antennapod.adapter.DefaultActionButtonCallback; import de.danoeh.antennapod.adapter.NewEpisodesListAdapter; import de.danoeh.antennapod.asynctask.DownloadObserver; +import de.danoeh.antennapod.dialog.FeedItemDialog; import de.danoeh.antennapod.feed.EventDistributor; import de.danoeh.antennapod.feed.FeedItem; import de.danoeh.antennapod.feed.FeedMedia; @@ -56,6 +58,8 @@ public class NewEpisodesFragment extends Fragment { private DownloadObserver downloadObserver = null; + private FeedItemDialog feedItemDialog; + @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -101,6 +105,7 @@ public class NewEpisodesFragment extends Fragment { if (downloadObserver != null) { downloadObserver.onPause(); } + feedItemDialog = null; } @Override @@ -111,6 +116,18 @@ public class NewEpisodesFragment extends Fragment { txtvEmpty = (TextView) root.findViewById(android.R.id.empty); progLoading = (ProgressBar) root.findViewById(R.id.progLoading); + listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { + @Override + public void onItemClick(AdapterView<?> parent, View view, int position, long id) { + FeedItem item = (FeedItem) listAdapter.getItem(position - listView.getHeaderViewsCount()); + if (item != null) { + feedItemDialog = new FeedItemDialog(activity.get(), item, queueAccess); + feedItemDialog.show(); + } + + } + }); + if (!itemsLoaded) { progLoading.setVisibility(View.VISIBLE); txtvEmpty.setVisibility(View.GONE); @@ -133,6 +150,12 @@ public class NewEpisodesFragment extends Fragment { downloadObserver = new DownloadObserver(activity.get(), new Handler(), downloadObserverCallback); downloadObserver.onResume(); } + if (feedItemDialog != null && feedItemDialog.isShowing()) { + feedItemDialog.setQueue(queueAccess); + feedItemDialog.setItemFromCollection(unreadItems); + feedItemDialog.setItemFromCollection(recentItems); + feedItemDialog.updateMenuAppearance(); + } listAdapter.notifyDataSetChanged(); } @@ -142,6 +165,9 @@ public class NewEpisodesFragment extends Fragment { if (listAdapter != null) { listAdapter.notifyDataSetChanged(); } + if (feedItemDialog != null && feedItemDialog.isShowing()) { + feedItemDialog.updateMenuAppearance(); + } } @Override diff --git a/src/de/danoeh/antennapod/fragment/PlaybackHistoryFragment.java b/src/de/danoeh/antennapod/fragment/PlaybackHistoryFragment.java index a8627f12e..c28208d37 100644 --- a/src/de/danoeh/antennapod/fragment/PlaybackHistoryFragment.java +++ b/src/de/danoeh/antennapod/fragment/PlaybackHistoryFragment.java @@ -7,10 +7,12 @@ import android.os.Bundle; import android.os.Handler; import android.support.v4.app.ListFragment; import android.view.View; +import android.widget.ListView; import de.danoeh.antennapod.adapter.ActionButtonCallback; import de.danoeh.antennapod.adapter.DefaultActionButtonCallback; import de.danoeh.antennapod.adapter.InternalFeedItemlistAdapter; import de.danoeh.antennapod.asynctask.DownloadObserver; +import de.danoeh.antennapod.dialog.FeedItemDialog; import de.danoeh.antennapod.feed.EventDistributor; import de.danoeh.antennapod.feed.FeedItem; import de.danoeh.antennapod.feed.FeedMedia; @@ -36,6 +38,8 @@ public class PlaybackHistoryFragment extends ListFragment { private DownloadObserver downloadObserver; private List<Downloader> downloaderList; + private FeedItemDialog feedItemDialog; + @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -67,6 +71,7 @@ public class PlaybackHistoryFragment extends ListFragment { if (downloadObserver != null) { downloadObserver.onPause(); } + feedItemDialog = null; } @Override @@ -91,6 +96,16 @@ public class PlaybackHistoryFragment extends ListFragment { } } + @Override + public void onListItemClick(ListView l, View v, int position, long id) { + super.onListItemClick(l, v, position, id); + FeedItem item = adapter.getItem(position - l.getHeaderViewsCount()); + if (item != null) { + feedItemDialog = new FeedItemDialog(activity.get(), item, queue); + feedItemDialog.show(); + } + } + private EventDistributor.EventListener contentUpdate = new EventDistributor.EventListener() { @Override @@ -110,6 +125,11 @@ public class PlaybackHistoryFragment extends ListFragment { } setListShown(true); adapter.notifyDataSetChanged(); + if (feedItemDialog != null && feedItemDialog.isShowing()) { + feedItemDialog.setItemFromCollection(playbackHistory); + feedItemDialog.setQueue(queue); + feedItemDialog.updateMenuAppearance(); + } } private DownloadObserver.Callback downloadObserverCallback = new DownloadObserver.Callback() { @@ -118,6 +138,9 @@ public class PlaybackHistoryFragment extends ListFragment { if (adapter != null) { adapter.notifyDataSetChanged(); } + if (feedItemDialog != null && feedItemDialog.isShowing()) { + feedItemDialog.updateMenuAppearance(); + } } @Override diff --git a/src/de/danoeh/antennapod/fragment/QueueFragment.java b/src/de/danoeh/antennapod/fragment/QueueFragment.java index e88c7e178..093151d98 100644 --- a/src/de/danoeh/antennapod/fragment/QueueFragment.java +++ b/src/de/danoeh/antennapod/fragment/QueueFragment.java @@ -11,6 +11,7 @@ import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.widget.AdapterView; import android.widget.ProgressBar; import android.widget.TextView; import com.mobeta.android.dslv.DragSortListView; @@ -19,12 +20,14 @@ import de.danoeh.antennapod.activity.MainActivity; import de.danoeh.antennapod.adapter.DefaultActionButtonCallback; import de.danoeh.antennapod.adapter.QueueListAdapter; import de.danoeh.antennapod.asynctask.DownloadObserver; +import de.danoeh.antennapod.dialog.FeedItemDialog; import de.danoeh.antennapod.feed.EventDistributor; import de.danoeh.antennapod.feed.FeedItem; import de.danoeh.antennapod.feed.FeedMedia; import de.danoeh.antennapod.service.download.Downloader; import de.danoeh.antennapod.storage.DBReader; import de.danoeh.antennapod.storage.DBWriter; +import de.danoeh.antennapod.util.QueueAccess; import de.danoeh.antennapod.util.UndoBarController; import de.danoeh.antennapod.util.gui.FeedItemUndoToken; @@ -56,6 +59,8 @@ public class QueueFragment extends Fragment { private DownloadObserver downloadObserver = null; + private FeedItemDialog feedItemDialog; + /** * Download observer updates won't result in an upate of the list adapter if this is true. */ @@ -108,6 +113,7 @@ public class QueueFragment extends Fragment { if (downloadObserver != null) { downloadObserver.onPause(); } + feedItemDialog = null; } @Override @@ -119,6 +125,16 @@ public class QueueFragment extends Fragment { progLoading = (ProgressBar) root.findViewById(R.id.progLoading); listView.setEmptyView(txtvEmpty); + listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { + @Override + public void onItemClick(AdapterView<?> parent, View view, int position, long id) { + FeedItem item = (FeedItem) listAdapter.getItem(position - listView.getHeaderViewsCount()); + if (item != null) { + feedItemDialog = new FeedItemDialog(activity.get(), item, QueueAccess.ItemListAccess(queue)); + feedItemDialog.show(); + } + } + }); listView.setRemoveListener(new DragSortListView.RemoveListener() { @Override @@ -192,6 +208,11 @@ public class QueueFragment extends Fragment { downloadObserver.onResume(); } listAdapter.notifyDataSetChanged(); + if (feedItemDialog != null && feedItemDialog.isShowing()) { + feedItemDialog.setQueue(QueueAccess.ItemListAccess(queue)); + feedItemDialog.setItemFromCollection(queue); + feedItemDialog.updateMenuAppearance(); + } } private DownloadObserver.Callback downloadObserverCallback = new DownloadObserver.Callback() { @@ -200,6 +221,9 @@ public class QueueFragment extends Fragment { if (listAdapter != null && !blockDownloadObserverUpdate) { listAdapter.notifyDataSetChanged(); } + if (feedItemDialog != null && feedItemDialog.isShowing()) { + feedItemDialog.updateMenuAppearance(); + } } @Override |