diff options
-rw-r--r-- | AndroidManifest.xml | 1 | ||||
-rw-r--r-- | res/layout/playbackhistory_activity.xml | 8 | ||||
-rw-r--r-- | res/menu/podfetcher.xml | 3 | ||||
-rw-r--r-- | res/values/ids.xml | 1 | ||||
-rw-r--r-- | res/values/strings.xml | 4 | ||||
-rw-r--r-- | src/de/danoeh/antennapod/activity/MainActivity.java | 3 | ||||
-rw-r--r-- | src/de/danoeh/antennapod/activity/PlaybackHistoryActivity.java | 57 | ||||
-rw-r--r-- | src/de/danoeh/antennapod/feed/FeedManager.java | 27 | ||||
-rw-r--r-- | src/de/danoeh/antennapod/fragment/PlaybackHistoryFragment.java | 47 |
9 files changed, 150 insertions, 1 deletions
diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 814272d53..fa689839a 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -225,6 +225,7 @@ android:screenOrientation="landscape" android:theme="@style/VideoplayerTheme" > </activity> + <activity android:label="@string/playback_history_label" android:name=".activity.PlaybackHistoryActivity"></activity> </application> </manifest>
\ No newline at end of file diff --git a/res/layout/playbackhistory_activity.xml b/res/layout/playbackhistory_activity.xml new file mode 100644 index 000000000..eefa914ea --- /dev/null +++ b/res/layout/playbackhistory_activity.xml @@ -0,0 +1,8 @@ +<?xml version="1.0" encoding="utf-8"?> +<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:id="@+id/playbackhistory_fragment" + android:layout_width="match_parent" + android:layout_height="match_parent" > + + +</FrameLayout>
\ No newline at end of file diff --git a/res/menu/podfetcher.xml b/res/menu/podfetcher.xml index afe422539..226f07954 100644 --- a/res/menu/podfetcher.xml +++ b/res/menu/podfetcher.xml @@ -12,7 +12,8 @@ <item android:id="@id/search_item" android:icon="@drawable/action_search" android:title="@string/search_label" android:showAsAction="ifRoom|collapseActionView"></item><item android:id="@+id/show_player" android:title="@string/show_player_label" android:icon="@drawable/av_play" android:showAsAction="collapseActionView"></item> <item android:id="@+id/opml_import" android:title="@string/opml_import_label" android:showAsAction="collapseActionView"></item> - <item android:id="@+id/opml_export" android:title="@string/opml_export_label"></item><item android:id="@+id/show_downloads" android:title="@string/downloads_label" android:icon="@drawable/av_download" android:showAsAction="collapseActionView"> + <item android:id="@+id/opml_export" android:title="@string/opml_export_label"></item><item android:id="@+id/show_playback_history" android:title="@string/playback_history_label" android:showAsAction="collapseActionView"></item><item android:id="@+id/show_downloads" android:title="@string/downloads_label" android:icon="@drawable/av_download" android:showAsAction="collapseActionView"> </item><item android:id="@+id/show_preferences" android:title="@string/settings_label" android:icon="@drawable/action_settings" android:showAsAction="collapseActionView"></item> + </menu> diff --git a/res/values/ids.xml b/res/values/ids.xml index 6ae686ee5..c3219b553 100644 --- a/res/values/ids.xml +++ b/res/values/ids.xml @@ -10,5 +10,6 @@ <item type="id" name="search_item"/> <item name="enqueue_all_item" type="id"/> <item name="download_all_item" type="id"/> + <item type="id" name="clear_history_item"/> </resources>
\ No newline at end of file diff --git a/res/values/strings.xml b/res/values/strings.xml index ff7b189d7..8e0adef7c 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -10,7 +10,11 @@ <string name="downloads_label">Downloads</string> <string name="cancel_download_label">Cancel Download</string> <string name="download_log_label">Download log</string> + <string name="playback_history_label">Playback history</string> + <!-- Playback history --> + <string name="clear_history_label">Clear history</string> + <!-- Other --> <string name="confirm_label">Confirm</string> <string name="cancel_label">Cancel</string> diff --git a/src/de/danoeh/antennapod/activity/MainActivity.java b/src/de/danoeh/antennapod/activity/MainActivity.java index 77544af47..b5f89b882 100644 --- a/src/de/danoeh/antennapod/activity/MainActivity.java +++ b/src/de/danoeh/antennapod/activity/MainActivity.java @@ -127,6 +127,9 @@ public class MainActivity extends SherlockFragmentActivity { case R.id.search_item: onSearchRequested(); return true; + case R.id.show_playback_history: + startActivity(new Intent(this, PlaybackHistoryActivity.class)); + return true; default: return super.onOptionsItemSelected(item); } diff --git a/src/de/danoeh/antennapod/activity/PlaybackHistoryActivity.java b/src/de/danoeh/antennapod/activity/PlaybackHistoryActivity.java new file mode 100644 index 000000000..82cff51de --- /dev/null +++ b/src/de/danoeh/antennapod/activity/PlaybackHistoryActivity.java @@ -0,0 +1,57 @@ +package de.danoeh.antennapod.activity; + +import android.content.Intent; +import android.os.Bundle; +import android.support.v4.app.FragmentTransaction; +import android.util.Log; + +import com.actionbarsherlock.app.SherlockFragmentActivity; +import com.actionbarsherlock.view.Menu; +import com.actionbarsherlock.view.MenuItem; + +import de.danoeh.antennapod.AppConfig; +import de.danoeh.antennapod.R; +import de.danoeh.antennapod.feed.FeedManager; +import de.danoeh.antennapod.fragment.PlaybackHistoryFragment; + +public class PlaybackHistoryActivity extends SherlockFragmentActivity { + private static final String TAG = "PlaybackHistoryActivity"; + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + menu.add(Menu.NONE, R.id.clear_history_item, Menu.NONE, + R.string.clear_history_label).setShowAsAction( + MenuItem.SHOW_AS_ACTION_IF_ROOM); + return true; + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()) { + case android.R.id.home: + Intent intent = new Intent(this, MainActivity.class); + intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP + | Intent.FLAG_ACTIVITY_NEW_TASK); + startActivity(intent); + return true; + case R.id.clear_history_item: + FeedManager.getInstance().clearPlaybackHistory(this); + return true; + } + return super.onOptionsItemSelected(item); + } + + @Override + protected void onCreate(Bundle arg0) { + super.onCreate(arg0); + if (AppConfig.DEBUG) + Log.d(TAG, "Activity created"); + getSupportActionBar().setDisplayHomeAsUpEnabled(true); + setContentView(R.layout.playbackhistory_activity); + + FragmentTransaction fT = getSupportFragmentManager().beginTransaction(); + fT.replace(R.id.playbackhistory_fragment, new PlaybackHistoryFragment()); + fT.commit(); + } + +} diff --git a/src/de/danoeh/antennapod/feed/FeedManager.java b/src/de/danoeh/antennapod/feed/FeedManager.java index dde2c9323..04dc3b2a9 100644 --- a/src/de/danoeh/antennapod/feed/FeedManager.java +++ b/src/de/danoeh/antennapod/feed/FeedManager.java @@ -325,6 +325,33 @@ public class FeedManager { } } + public void clearPlaybackHistory(final Context context) { + if (!playbackHistory.isEmpty()) { + if (AppConfig.DEBUG) + Log.d(TAG, "Clearing playback history."); + final FeedItem[] items = playbackHistory + .toArray(new FeedItem[playbackHistory.size()]); + playbackHistory.clear(); + sendPlaybackHistoryUpdateBroadcast(context); + dbExec.execute(new Runnable() { + + @Override + public void run() { + PodDBAdapter adapter = new PodDBAdapter(context); + adapter.open(); + for (FeedItem item : items) { + if (item.getMedia() != null + && item.getMedia().getPlaybackCompletionDate() != null) { + item.getMedia().setPlaybackCompletionDate(null); + adapter.setMedia(item.getMedia()); + } + } + adapter.close(); + } + }); + } + } + public void addItemToPlaybackHistory(Context context, FeedItem item) { if (item.getMedia() != null && item.getMedia().getPlaybackCompletionDate() != null) { diff --git a/src/de/danoeh/antennapod/fragment/PlaybackHistoryFragment.java b/src/de/danoeh/antennapod/fragment/PlaybackHistoryFragment.java new file mode 100644 index 000000000..a2826c977 --- /dev/null +++ b/src/de/danoeh/antennapod/fragment/PlaybackHistoryFragment.java @@ -0,0 +1,47 @@ +package de.danoeh.antennapod.fragment; + +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.content.IntentFilter; +import android.os.Bundle; +import android.util.Log; +import de.danoeh.antennapod.AppConfig; +import de.danoeh.antennapod.feed.FeedManager; + +public class PlaybackHistoryFragment extends ItemlistFragment { + private static final String TAG = "PlaybackHistoryFragment"; + + public PlaybackHistoryFragment() { + super(FeedManager.getInstance().getPlaybackHistory(), true); + } + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + getActivity().registerReceiver(historyUpdate, + new IntentFilter(FeedManager.ACTION_PLAYBACK_HISTORY_UPDATE)); + } + + @Override + public void onDestroy() { + super.onDestroy(); + try { + getActivity().unregisterReceiver(historyUpdate); + } catch (IllegalArgumentException e) { + // ignore + } + } + + private BroadcastReceiver historyUpdate = new BroadcastReceiver() { + + @Override + public void onReceive(Context context, Intent intent) { + if (AppConfig.DEBUG) + Log.d(TAG, "Received content update"); + fila.notifyDataSetChanged(); + } + + }; + +} |