summaryrefslogtreecommitdiff
path: root/src/de/danoeh/antennapod/activity
diff options
context:
space:
mode:
Diffstat (limited to 'src/de/danoeh/antennapod/activity')
-rw-r--r--src/de/danoeh/antennapod/activity/AboutActivity.java4
-rw-r--r--src/de/danoeh/antennapod/activity/AddFeedActivity.java28
-rw-r--r--src/de/danoeh/antennapod/activity/AudioplayerActivity.java12
-rw-r--r--src/de/danoeh/antennapod/activity/DirectoryChooserActivity.java11
-rw-r--r--src/de/danoeh/antennapod/activity/DownloadActivity.java451
-rw-r--r--src/de/danoeh/antennapod/activity/DownloadLogActivity.java76
-rw-r--r--src/de/danoeh/antennapod/activity/FeedInfoActivity.java104
-rw-r--r--src/de/danoeh/antennapod/activity/FeedItemlistActivity.java312
-rw-r--r--src/de/danoeh/antennapod/activity/FlattrAuthActivity.java9
-rw-r--r--src/de/danoeh/antennapod/activity/ItemviewActivity.java129
-rw-r--r--src/de/danoeh/antennapod/activity/MainActivity.java62
-rw-r--r--src/de/danoeh/antennapod/activity/MediaplayerActivity.java19
-rw-r--r--src/de/danoeh/antennapod/activity/MiroGuideCategoryActivity.java13
-rw-r--r--src/de/danoeh/antennapod/activity/MiroGuideChannelViewActivity.java309
-rw-r--r--src/de/danoeh/antennapod/activity/MiroGuideMainActivity.java277
-rw-r--r--src/de/danoeh/antennapod/activity/MiroGuideSearchActivity.java126
-rw-r--r--src/de/danoeh/antennapod/activity/OnlineFeedViewActivity.java47
-rw-r--r--src/de/danoeh/antennapod/activity/OpmlFeedChooserActivity.java219
-rw-r--r--src/de/danoeh/antennapod/activity/OpmlImportBaseActivity.java5
-rw-r--r--src/de/danoeh/antennapod/activity/OpmlImportFromPathActivity.java5
-rw-r--r--src/de/danoeh/antennapod/activity/OrganizeQueueActivity.java112
-rw-r--r--src/de/danoeh/antennapod/activity/PlaybackHistoryActivity.java18
-rw-r--r--src/de/danoeh/antennapod/activity/PreferenceActivity.java689
-rw-r--r--src/de/danoeh/antennapod/activity/SearchActivity.java332
-rw-r--r--src/de/danoeh/antennapod/activity/StorageErrorActivity.java5
-rw-r--r--src/de/danoeh/antennapod/activity/VideoplayerActivity.java7
26 files changed, 1809 insertions, 1572 deletions
diff --git a/src/de/danoeh/antennapod/activity/AboutActivity.java b/src/de/danoeh/antennapod/activity/AboutActivity.java
index e3265d1eb..27fdbe241 100644
--- a/src/de/danoeh/antennapod/activity/AboutActivity.java
+++ b/src/de/danoeh/antennapod/activity/AboutActivity.java
@@ -1,15 +1,15 @@
package de.danoeh.antennapod.activity;
import android.os.Bundle;
+import android.support.v7.app.ActionBarActivity;
import android.webkit.WebView;
import android.webkit.WebViewClient;
-import com.actionbarsherlock.app.SherlockActivity;
import de.danoeh.antennapod.R;
/** Displays the 'about' screen */
-public class AboutActivity extends SherlockActivity {
+public class AboutActivity extends ActionBarActivity {
private WebView webview;
diff --git a/src/de/danoeh/antennapod/activity/AddFeedActivity.java b/src/de/danoeh/antennapod/activity/AddFeedActivity.java
index 39434fa87..4085fc8d2 100644
--- a/src/de/danoeh/antennapod/activity/AddFeedActivity.java
+++ b/src/de/danoeh/antennapod/activity/AddFeedActivity.java
@@ -2,6 +2,11 @@ package de.danoeh.antennapod.activity;
import java.util.Date;
+import android.support.v7.app.ActionBarActivity;
+import android.view.Menu;
+import android.view.MenuItem;
+import org.apache.commons.lang3.StringUtils;
+
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;
@@ -13,10 +18,6 @@ import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
-import com.actionbarsherlock.app.SherlockActivity;
-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.Feed;
@@ -29,7 +30,7 @@ import de.danoeh.antennapod.util.StorageUtils;
import de.danoeh.antennapod.util.URLChecker;
/** Activity for adding a Feed */
-public class AddFeedActivity extends SherlockActivity {
+public class AddFeedActivity extends ActionBarActivity {
private static final String TAG = "AddFeedActivity";
private DownloadRequester requester;
@@ -44,6 +45,9 @@ public class AddFeedActivity extends SherlockActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
+ if (AppConfig.DEBUG)
+ Log.d(TAG, "Was started with Intent " + getIntent().getAction()
+ + " and Data " + getIntent().getDataString());
setTheme(UserPreferences.getTheme());
super.onCreate(savedInstanceState);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
@@ -54,6 +58,10 @@ public class AddFeedActivity extends SherlockActivity {
progDialog = new ProgressDialog(this);
etxtFeedurl = (EditText) findViewById(R.id.etxtFeedurl);
+ if (StringUtils.equals(getIntent().getAction(), Intent.ACTION_VIEW)) {
+ etxtFeedurl.setText(getIntent().getDataString());
+ }
+
butBrowseMiroGuide = (Button) findViewById(R.id.butBrowseMiroguide);
butOpmlImport = (Button) findViewById(R.id.butOpmlImport);
butConfirm = (Button) findViewById(R.id.butConfirm);
@@ -101,7 +109,7 @@ public class AddFeedActivity extends SherlockActivity {
if (intent.getAction() != null
&& intent.getAction().equals(Intent.ACTION_SEND)) {
if (AppConfig.DEBUG)
- Log.d(TAG, "Was started with ACTION_SEND intent");
+ Log.d(TAG, "Resuming with ACTION_SEND intent");
String text = intent.getStringExtra(Intent.EXTRA_TEXT);
if (text != null) {
etxtFeedurl.setText(text);
@@ -152,7 +160,7 @@ public class AddFeedActivity extends SherlockActivity {
}
@Override
- public void onConnectionFailure(int reason) {
+ public void onConnectionFailure(DownloadError reason) {
handleDownloadError(reason);
}
});
@@ -168,11 +176,11 @@ public class AddFeedActivity extends SherlockActivity {
progDialog.setMessage(getString(R.string.loading_label));
}
- private void handleDownloadError(int reason) {
+ private void handleDownloadError(DownloadError reason) {
final AlertDialog errorDialog = new AlertDialog.Builder(this).create();
errorDialog.setTitle(R.string.error_label);
errorDialog.setMessage(getString(R.string.error_msg_prefix) + " "
- + DownloadError.getErrorString(this, reason));
+ + reason.getErrorString(this));
errorDialog.setButton(getString(android.R.string.ok),
new DialogInterface.OnClickListener() {
@Override
@@ -191,6 +199,8 @@ public class AddFeedActivity extends SherlockActivity {
return true;
}
+
+
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
diff --git a/src/de/danoeh/antennapod/activity/AudioplayerActivity.java b/src/de/danoeh/antennapod/activity/AudioplayerActivity.java
index f43f29db3..cf82d936d 100644
--- a/src/de/danoeh/antennapod/activity/AudioplayerActivity.java
+++ b/src/de/danoeh/antennapod/activity/AudioplayerActivity.java
@@ -7,9 +7,11 @@ import android.content.res.TypedArray;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
+import android.support.v4.app.ListFragment;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
+import android.view.Window;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ImageButton;
@@ -17,9 +19,6 @@ import android.widget.ImageView.ScaleType;
import android.widget.ListView;
import android.widget.TextView;
-import com.actionbarsherlock.app.SherlockListFragment;
-import com.actionbarsherlock.view.Window;
-
import de.danoeh.antennapod.AppConfig;
import de.danoeh.antennapod.R;
import de.danoeh.antennapod.adapter.ChapterListAdapter;
@@ -49,7 +48,7 @@ public class AudioplayerActivity extends MediaplayerActivity {
private CoverFragment coverFragment;
private ItemDescriptionFragment descriptionFragment;
- private SherlockListFragment chapterFragment;
+ private ListFragment chapterFragment;
private Fragment currentlyShownFragment;
private int currentlyShownPosition = -1;
@@ -250,8 +249,7 @@ public class AudioplayerActivity extends MediaplayerActivity {
/**
* Changes the currently displayed fragment.
*
- * @param Must
- * be POS_COVER, POS_DESCR, or POS_CHAPTERS
+ * @param pos Must be POS_COVER, POS_DESCR, or POS_CHAPTERS
* */
private void switchToFragment(int pos) {
if (AppConfig.DEBUG)
@@ -282,7 +280,7 @@ public class AudioplayerActivity extends MediaplayerActivity {
break;
case POS_CHAPTERS:
if (chapterFragment == null) {
- chapterFragment = new SherlockListFragment() {
+ chapterFragment = new ListFragment() {
@Override
public void onListItemClick(ListView l, View v,
diff --git a/src/de/danoeh/antennapod/activity/DirectoryChooserActivity.java b/src/de/danoeh/antennapod/activity/DirectoryChooserActivity.java
index 54c4f0589..984491174 100644
--- a/src/de/danoeh/antennapod/activity/DirectoryChooserActivity.java
+++ b/src/de/danoeh/antennapod/activity/DirectoryChooserActivity.java
@@ -12,7 +12,11 @@ import android.content.Intent;
import android.os.Bundle;
import android.os.Environment;
import android.os.FileObserver;
+import android.support.v7.app.ActionBarActivity;
import android.util.Log;
+import android.view.Menu;
+import android.view.MenuInflater;
+import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
@@ -24,11 +28,6 @@ import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
-import com.actionbarsherlock.app.SherlockActivity;
-import com.actionbarsherlock.view.Menu;
-import com.actionbarsherlock.view.MenuInflater;
-import com.actionbarsherlock.view.MenuItem;
-
import de.danoeh.antennapod.AppConfig;
import de.danoeh.antennapod.R;
import de.danoeh.antennapod.preferences.UserPreferences;
@@ -37,7 +36,7 @@ import de.danoeh.antennapod.preferences.UserPreferences;
* Let's the user choose a directory on the storage device. The selected folder
* will be sent back to the starting activity as an activity result.
*/
-public class DirectoryChooserActivity extends SherlockActivity {
+public class DirectoryChooserActivity extends ActionBarActivity {
private static final String TAG = "DirectoryChooserActivity";
private static final String CREATE_DIRECTORY_NAME = "AntennaPod";
diff --git a/src/de/danoeh/antennapod/activity/DownloadActivity.java b/src/de/danoeh/antennapod/activity/DownloadActivity.java
index 10ebb1285..40c75d336 100644
--- a/src/de/danoeh/antennapod/activity/DownloadActivity.java
+++ b/src/de/danoeh/antennapod/activity/DownloadActivity.java
@@ -11,21 +11,23 @@ import android.content.res.TypedArray;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.IBinder;
+import android.support.v4.view.MenuItemCompat;
+import android.support.v7.app.ActionBarActivity;
+import android.support.v7.view.ActionMode;
import android.util.Log;
+import android.view.Menu;
+import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemLongClickListener;
-import com.actionbarsherlock.app.SherlockListActivity;
-import com.actionbarsherlock.view.ActionMode;
-import com.actionbarsherlock.view.Menu;
-import com.actionbarsherlock.view.MenuItem;
+import android.widget.ListView;
import de.danoeh.antennapod.AppConfig;
import de.danoeh.antennapod.R;
import de.danoeh.antennapod.adapter.DownloadlistAdapter;
-import de.danoeh.antennapod.asynctask.DownloadStatus;
import de.danoeh.antennapod.preferences.UserPreferences;
+import de.danoeh.antennapod.service.download.DownloadRequest;
import de.danoeh.antennapod.service.download.DownloadService;
import de.danoeh.antennapod.storage.DownloadRequester;
@@ -33,221 +35,228 @@ import de.danoeh.antennapod.storage.DownloadRequester;
* Shows all running downloads in a list. The list objects are DownloadStatus
* objects created by a DownloadObserver.
*/
-public class DownloadActivity extends SherlockListActivity implements
- ActionMode.Callback {
-
- private static final String TAG = "DownloadActivity";
- private static final int MENU_SHOW_LOG = 0;
- private static final int MENU_CANCEL_ALL_DOWNLOADS = 1;
- private DownloadlistAdapter dla;
- private DownloadRequester requester;
-
- private ActionMode mActionMode;
- private DownloadStatus selectedDownload;
-
- private DownloadService downloadService = null;
- boolean mIsBound;
-
- private AsyncTask<Void, Void, Void> contentRefresher;
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- setTheme(UserPreferences.getTheme());
- super.onCreate(savedInstanceState);
- if (AppConfig.DEBUG)
- Log.d(TAG, "Creating Activity");
- requester = DownloadRequester.getInstance();
- getSupportActionBar().setDisplayHomeAsUpEnabled(true);
- }
-
- @Override
- protected void onPause() {
- super.onPause();
- unbindService(mConnection);
- unregisterReceiver(contentChanged);
- }
-
- @Override
- protected void onResume() {
- super.onResume();
- registerReceiver(contentChanged, new IntentFilter(
- DownloadService.ACTION_DOWNLOADS_CONTENT_CHANGED));
- bindService(new Intent(this, DownloadService.class), mConnection, 0);
- startContentRefresher();
- if (dla != null) {
- dla.notifyDataSetChanged();
- }
- }
-
- @Override
- protected void onStop() {
- super.onStop();
- if (AppConfig.DEBUG)
- Log.d(TAG, "Stopping Activity");
- stopContentRefresher();
- }
-
- private ServiceConnection mConnection = new ServiceConnection() {
- public void onServiceDisconnected(ComponentName className) {
- downloadService = null;
- mIsBound = false;
- Log.i(TAG, "Closed connection with DownloadService.");
- }
-
- public void onServiceConnected(ComponentName name, IBinder service) {
- downloadService = ((DownloadService.LocalBinder) service)
- .getService();
- mIsBound = true;
- if (AppConfig.DEBUG)
- Log.d(TAG, "Connection to service established");
- dla = new DownloadlistAdapter(DownloadActivity.this, 0,
- downloadService.getDownloads());
- setListAdapter(dla);
- dla.notifyDataSetChanged();
- }
- };
-
- @SuppressLint("NewApi")
- private void startContentRefresher() {
- if (contentRefresher != null) {
- contentRefresher.cancel(true);
- }
- contentRefresher = new AsyncTask<Void, Void, Void>() {
- private final int WAITING_INTERVALL = 1000;
-
- @Override
- protected void onProgressUpdate(Void... values) {
- super.onProgressUpdate(values);
- if (dla != null) {
- if (AppConfig.DEBUG)
- Log.d(TAG, "Refreshing content automatically");
- dla.notifyDataSetChanged();
- }
- }
-
- @Override
- protected Void doInBackground(Void... params) {
- while (!isCancelled()) {
- try {
- Thread.sleep(WAITING_INTERVALL);
- publishProgress();
- } catch (InterruptedException e) {
- return null;
- }
- }
- return null;
- }
- };
- if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.GINGERBREAD_MR1) {
- contentRefresher.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
- } else {
- contentRefresher.execute();
- }
- }
-
- private void stopContentRefresher() {
- if (contentRefresher != null) {
- contentRefresher.cancel(true);
- }
- }
-
- @Override
- protected void onPostCreate(Bundle savedInstanceState) {
- super.onPostCreate(savedInstanceState);
- getListView().setOnItemLongClickListener(new OnItemLongClickListener() {
-
- @Override
- public boolean onItemLongClick(AdapterView<?> arg0, View view,
- int position, long id) {
- DownloadStatus selection = dla.getItem(position).getStatus();
- if (selection != null && mActionMode != null) {
- mActionMode.finish();
- }
- dla.setSelectedItemIndex(position);
- selectedDownload = selection;
- mActionMode = startActionMode(DownloadActivity.this);
- return true;
- }
-
- });
- }
-
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- menu.add(Menu.NONE, MENU_SHOW_LOG, Menu.NONE,
- R.string.show_download_log).setShowAsAction(
- MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
- menu.add(Menu.NONE, MENU_CANCEL_ALL_DOWNLOADS, Menu.NONE,
- R.string.cancel_all_downloads_label).setShowAsAction(
- MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
- 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);
- break;
- case MENU_SHOW_LOG:
- startActivity(new Intent(this, DownloadLogActivity.class));
- break;
- case MENU_CANCEL_ALL_DOWNLOADS:
- requester.cancelAllDownloads(this);
- break;
- }
- return true;
- }
-
- @Override
- public boolean onCreateActionMode(ActionMode mode, Menu menu) {
- if (!selectedDownload.isDone()) {
- TypedArray drawables = obtainStyledAttributes(new int[] { R.attr.navigation_cancel });
- menu.add(Menu.NONE, R.id.cancel_download_item, Menu.NONE,
- R.string.cancel_download_label).setIcon(
- drawables.getDrawable(0));
- }
- return true;
- }
-
- @Override
- public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
- return false;
- }
-
- @Override
- public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
- boolean handled = false;
- switch (item.getItemId()) {
- case R.id.cancel_download_item:
- requester.cancelDownload(this, selectedDownload.getFeedFile());
- handled = true;
- break;
- }
- mActionMode.finish();
- return handled;
- }
-
- @Override
- public void onDestroyActionMode(ActionMode mode) {
- mActionMode = null;
- selectedDownload = null;
- dla.setSelectedItemIndex(DownloadlistAdapter.SELECTION_NONE);
- }
-
- private BroadcastReceiver contentChanged = new BroadcastReceiver() {
-
- @Override
- public void onReceive(Context context, Intent intent) {
- if (dla != null) {
- if (AppConfig.DEBUG)
- Log.d(TAG, "Refreshing content");
- dla.notifyDataSetChanged();
- }
- }
- };
+public class DownloadActivity extends ActionBarActivity implements
+ ActionMode.Callback {
+
+ private static final String TAG = "DownloadActivity";
+ private static final int MENU_SHOW_LOG = 0;
+ private static final int MENU_CANCEL_ALL_DOWNLOADS = 1;
+ private DownloadlistAdapter dla;
+ private DownloadRequester requester;
+
+ private ActionMode mActionMode;
+ private DownloadRequest selectedDownload;
+
+ private DownloadService downloadService = null;
+ boolean mIsBound;
+
+ private AsyncTask<Void, Void, Void> contentRefresher;
+
+ private ListView listview;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ setTheme(UserPreferences.getTheme());
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.listview_activity);
+
+ listview = (ListView) findViewById(R.id.listview);
+
+ if (AppConfig.DEBUG)
+ Log.d(TAG, "Creating Activity");
+ requester = DownloadRequester.getInstance();
+ getSupportActionBar().setDisplayHomeAsUpEnabled(true);
+ }
+
+ @Override
+ protected void onPause() {
+ super.onPause();
+ unbindService(mConnection);
+ unregisterReceiver(contentChanged);
+ }
+
+ @Override
+ protected void onResume() {
+ super.onResume();
+ registerReceiver(contentChanged, new IntentFilter(
+ DownloadService.ACTION_DOWNLOADS_CONTENT_CHANGED));
+ bindService(new Intent(this, DownloadService.class), mConnection, 0);
+ startContentRefresher();
+ if (dla != null) {
+ dla.notifyDataSetChanged();
+ }
+ }
+
+ @Override
+ protected void onStop() {
+ super.onStop();
+ if (AppConfig.DEBUG)
+ Log.d(TAG, "Stopping Activity");
+ stopContentRefresher();
+ }
+
+ private ServiceConnection mConnection = new ServiceConnection() {
+ public void onServiceDisconnected(ComponentName className) {
+ downloadService = null;
+ mIsBound = false;
+ Log.i(TAG, "Closed connection with DownloadService.");
+ }
+
+ public void onServiceConnected(ComponentName name, IBinder service) {
+ downloadService = ((DownloadService.LocalBinder) service)
+ .getService();
+ mIsBound = true;
+ if (AppConfig.DEBUG)
+ Log.d(TAG, "Connection to service established");
+ dla = new DownloadlistAdapter(DownloadActivity.this, 0,
+ downloadService.getDownloads());
+ listview.setAdapter(dla);
+ dla.notifyDataSetChanged();
+ }
+ };
+
+ @SuppressLint("NewApi")
+ private void startContentRefresher() {
+ if (contentRefresher != null) {
+ contentRefresher.cancel(true);
+ }
+ contentRefresher = new AsyncTask<Void, Void, Void>() {
+ private final int WAITING_INTERVALL = 1000;
+
+ @Override
+ protected void onProgressUpdate(Void... values) {
+ super.onProgressUpdate(values);
+ if (dla != null) {
+ if (AppConfig.DEBUG)
+ Log.d(TAG, "Refreshing content automatically");
+ dla.notifyDataSetChanged();
+ }
+ }
+
+ @Override
+ protected Void doInBackground(Void... params) {
+ while (!isCancelled()) {
+ try {
+ Thread.sleep(WAITING_INTERVALL);
+ publishProgress();
+ } catch (InterruptedException e) {
+ return null;
+ }
+ }
+ return null;
+ }
+ };
+ if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.GINGERBREAD_MR1) {
+ contentRefresher.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
+ } else {
+ contentRefresher.execute();
+ }
+ }
+
+ private void stopContentRefresher() {
+ if (contentRefresher != null) {
+ contentRefresher.cancel(true);
+ }
+ }
+
+ @Override
+ protected void onPostCreate(Bundle savedInstanceState) {
+ super.onPostCreate(savedInstanceState);
+ listview.setOnItemLongClickListener(new OnItemLongClickListener() {
+
+ @Override
+ public boolean onItemLongClick(AdapterView<?> arg0, View view,
+ int position, long id) {
+ DownloadRequest selection = dla.getItem(position)
+ .getDownloadRequest();
+ if (selection != null && mActionMode != null) {
+ mActionMode.finish();
+ }
+ dla.setSelectedItemIndex(position);
+ selectedDownload = selection;
+ mActionMode = startSupportActionMode(DownloadActivity.this);
+ return true;
+ }
+
+ });
+ }
+
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ MenuItemCompat.setShowAsAction(menu.add(Menu.NONE, MENU_SHOW_LOG, Menu.NONE,
+ R.string.show_download_log),
+ MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
+ MenuItemCompat.setShowAsAction(menu.add(Menu.NONE, MENU_CANCEL_ALL_DOWNLOADS, Menu.NONE,
+ R.string.cancel_all_downloads_label),
+ MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
+ 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);
+ break;
+ case MENU_SHOW_LOG:
+ startActivity(new Intent(this, DownloadLogActivity.class));
+ break;
+ case MENU_CANCEL_ALL_DOWNLOADS:
+ requester.cancelAllDownloads(this);
+ break;
+ }
+ return true;
+ }
+
+ @Override
+ public boolean onCreateActionMode(ActionMode mode, Menu menu) {
+ if (selectedDownload != null) {
+ TypedArray drawables = obtainStyledAttributes(new int[]{R.attr.navigation_cancel});
+ menu.add(Menu.NONE, R.id.cancel_download_item, Menu.NONE,
+ R.string.cancel_download_label).setIcon(
+ drawables.getDrawable(0));
+ }
+ return true;
+ }
+
+ @Override
+ public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
+ return false;
+ }
+
+ @Override
+ public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
+ boolean handled = false;
+ switch (item.getItemId()) {
+ case R.id.cancel_download_item:
+ requester.cancelDownload(this, selectedDownload.getSource());
+ handled = true;
+ break;
+ }
+ mActionMode.finish();
+ return handled;
+ }
+
+ @Override
+ public void onDestroyActionMode(ActionMode mode) {
+ mActionMode = null;
+ selectedDownload = null;
+ dla.setSelectedItemIndex(DownloadlistAdapter.SELECTION_NONE);
+ }
+
+ private BroadcastReceiver contentChanged = new BroadcastReceiver() {
+
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ if (dla != null) {
+ if (AppConfig.DEBUG)
+ Log.d(TAG, "Refreshing content");
+ dla.notifyDataSetChanged();
+ }
+ }
+ };
}
diff --git a/src/de/danoeh/antennapod/activity/DownloadLogActivity.java b/src/de/danoeh/antennapod/activity/DownloadLogActivity.java
index 232a7ba1d..5e48371b8 100644
--- a/src/de/danoeh/antennapod/activity/DownloadLogActivity.java
+++ b/src/de/danoeh/antennapod/activity/DownloadLogActivity.java
@@ -1,35 +1,47 @@
package de.danoeh.antennapod.activity;
+import android.os.AsyncTask;
import android.os.Bundle;
-import com.actionbarsherlock.app.SherlockListActivity;
-import com.actionbarsherlock.view.Menu;
-import com.actionbarsherlock.view.MenuItem;
+import android.support.v7.app.ActionBarActivity;
+import android.util.Log;
+import android.view.Menu;
+import android.view.MenuItem;
+import android.widget.ListView;
+import de.danoeh.antennapod.R;
import de.danoeh.antennapod.adapter.DownloadLogAdapter;
import de.danoeh.antennapod.feed.EventDistributor;
-import de.danoeh.antennapod.feed.FeedManager;
import de.danoeh.antennapod.preferences.UserPreferences;
+import de.danoeh.antennapod.service.download.DownloadStatus;
+import de.danoeh.antennapod.storage.DBReader;
+
+import java.util.List;
/**
- * Displays completed and failed downloads in a list. The data comes from the
- * FeedManager.
+ * Displays completed and failed downloads in a list.
*/
-public class DownloadLogActivity extends SherlockListActivity {
+public class DownloadLogActivity extends ActionBarActivity {
private static final String TAG = "DownloadLogActivity";
- DownloadLogAdapter dla;
- FeedManager manager;
+ private List<DownloadStatus> downloadLog;
+ private DownloadLogAdapter dla;
+
+ private ListView listview;
@Override
protected void onCreate(Bundle savedInstanceState) {
setTheme(UserPreferences.getTheme());
super.onCreate(savedInstanceState);
- manager = FeedManager.getInstance();
+ setContentView(R.layout.listview_activity);
+ getSupportActionBar().setDisplayHomeAsUpEnabled(true);
+
- dla = new DownloadLogAdapter(this);
- getSupportActionBar().setDisplayHomeAsUpEnabled(true);
- setListAdapter(dla);
+ listview = (ListView) findViewById(R.id.listview);
+
+ dla = new DownloadLogAdapter(this, itemAccess);
+ listview.setAdapter(dla);
+ loadData();
}
@Override
@@ -62,12 +74,48 @@ public class DownloadLogActivity extends SherlockListActivity {
return true;
}
+ private void loadData() {
+ AsyncTask<Void, Void, List<DownloadStatus>> loadTask = new AsyncTask<Void, Void, List<DownloadStatus>>() {
+ @Override
+ protected List<DownloadStatus> doInBackground(Void... voids) {
+ return DBReader.getDownloadLog(DownloadLogActivity.this);
+ }
+
+ @Override
+ protected void onPostExecute(List<DownloadStatus> downloadStatuses) {
+ super.onPostExecute(downloadStatuses);
+ if (downloadStatuses != null) {
+ downloadLog = downloadStatuses;
+ if (dla != null) {
+ dla.notifyDataSetChanged();
+ }
+ } else {
+ Log.e(TAG, "Could not load download log");
+ }
+ }
+ };
+ loadTask.execute();
+ }
+
+ private DownloadLogAdapter.ItemAccess itemAccess = new DownloadLogAdapter.ItemAccess() {
+
+ @Override
+ public int getCount() {
+ return (downloadLog != null) ? downloadLog.size() : 0;
+ }
+
+ @Override
+ public DownloadStatus getItem(int position) {
+ return (downloadLog != null) ? downloadLog.get(position) : null;
+ }
+ };
+
private EventDistributor.EventListener contentUpdate = new EventDistributor.EventListener() {
@Override
public void update(EventDistributor eventDistributor, Integer arg) {
if ((arg & EventDistributor.DOWNLOADLOG_UPDATE) != 0) {
- dla.notifyDataSetChanged();
+ loadData();
}
}
};
diff --git a/src/de/danoeh/antennapod/activity/FeedInfoActivity.java b/src/de/danoeh/antennapod/activity/FeedInfoActivity.java
index c57a5794b..4a8a2f1f8 100644
--- a/src/de/danoeh/antennapod/activity/FeedInfoActivity.java
+++ b/src/de/danoeh/antennapod/activity/FeedInfoActivity.java
@@ -1,28 +1,28 @@
package de.danoeh.antennapod.activity;
+import android.os.AsyncTask;
import android.os.Bundle;
+import android.support.v7.app.ActionBarActivity;
import android.util.Log;
+import android.view.Menu;
+import android.view.MenuInflater;
+import android.view.MenuItem;
import android.widget.ImageView;
import android.widget.TextView;
-import com.actionbarsherlock.app.SherlockActivity;
-import com.actionbarsherlock.view.Menu;
-import com.actionbarsherlock.view.MenuInflater;
-import com.actionbarsherlock.view.MenuItem;
-
import de.danoeh.antennapod.AppConfig;
import de.danoeh.antennapod.R;
import de.danoeh.antennapod.asynctask.ImageLoader;
import de.danoeh.antennapod.dialog.DownloadRequestErrorDialogCreator;
import de.danoeh.antennapod.feed.Feed;
-import de.danoeh.antennapod.feed.FeedManager;
import de.danoeh.antennapod.preferences.UserPreferences;
+import de.danoeh.antennapod.storage.DBReader;
import de.danoeh.antennapod.storage.DownloadRequestException;
import de.danoeh.antennapod.util.LangUtils;
import de.danoeh.antennapod.util.menuhandler.FeedMenuHandler;
/** Displays information about a feed. */
-public class FeedInfoActivity extends SherlockActivity {
+public class FeedInfoActivity extends ActionBarActivity {
private static final String TAG = "FeedInfoActivity";
public static final String EXTRA_FEED_ID = "de.danoeh.antennapod.extra.feedId";
@@ -42,47 +42,66 @@ public class FeedInfoActivity extends SherlockActivity {
setContentView(R.layout.feedinfo);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
long feedId = getIntent().getLongExtra(EXTRA_FEED_ID, -1);
- FeedManager manager = FeedManager.getInstance();
- feed = manager.getFeed(feedId);
- if (feed != null) {
- if (AppConfig.DEBUG)
- Log.d(TAG, "Language is " + feed.getLanguage());
- if (AppConfig.DEBUG)
- Log.d(TAG, "Author is " + feed.getAuthor());
- imgvCover = (ImageView) findViewById(R.id.imgvCover);
- txtvTitle = (TextView) findViewById(R.id.txtvTitle);
- txtvDescription = (TextView) findViewById(R.id.txtvDescription);
- txtvLanguage = (TextView) findViewById(R.id.txtvLanguage);
- txtvAuthor = (TextView) findViewById(R.id.txtvAuthor);
- imgvCover.post(new Runnable() {
-
- @Override
- public void run() {
- ImageLoader.getInstance().loadThumbnailBitmap(
- feed.getImage(), imgvCover);
- }
- });
+
+ AsyncTask<Long, Void, Feed> loadTask = new AsyncTask<Long, Void, Feed>() {
- txtvTitle.setText(feed.getTitle());
- txtvDescription.setText(feed.getDescription());
- if (feed.getAuthor() != null) {
- txtvAuthor.setText(feed.getAuthor());
+ @Override
+ protected Feed doInBackground(Long... params) {
+ return DBReader.getFeed(FeedInfoActivity.this, params[0]);
}
- if (feed.getLanguage() != null) {
- txtvLanguage.setText(LangUtils.getLanguageString(feed
- .getLanguage()));
- }
- } else {
- Log.e(TAG, "Activity was started with invalid arguments");
- }
+ @Override
+ protected void onPostExecute(Feed result) {
+ super.onPostExecute(result);
+ if (result != null) {
+ feed = result;
+ if (feed != null) {
+ if (AppConfig.DEBUG)
+ Log.d(TAG, "Language is " + feed.getLanguage());
+ if (AppConfig.DEBUG)
+ Log.d(TAG, "Author is " + feed.getAuthor());
+ imgvCover = (ImageView) findViewById(R.id.imgvCover);
+ txtvTitle = (TextView) findViewById(R.id.txtvTitle);
+ txtvDescription = (TextView) findViewById(R.id.txtvDescription);
+ txtvLanguage = (TextView) findViewById(R.id.txtvLanguage);
+ txtvAuthor = (TextView) findViewById(R.id.txtvAuthor);
+ imgvCover.post(new Runnable() {
+
+ @Override
+ public void run() {
+ ImageLoader.getInstance().loadThumbnailBitmap(
+ feed.getImage(), imgvCover);
+ }
+ });
+
+ txtvTitle.setText(feed.getTitle());
+ txtvDescription.setText(feed.getDescription());
+ if (feed.getAuthor() != null) {
+ txtvAuthor.setText(feed.getAuthor());
+ }
+ if (feed.getLanguage() != null) {
+ txtvLanguage.setText(LangUtils
+ .getLanguageString(feed.getLanguage()));
+ }
+ supportInvalidateOptionsMenu();
+ }
+ } else {
+ Log.e(TAG, "Activity was started with invalid arguments");
+ }
+ }
+ };
+ loadTask.execute(feedId);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
- MenuInflater inflater = new MenuInflater(this);
- inflater.inflate(R.menu.feedinfo, menu);
- return true;
+ if (feed != null) {
+ MenuInflater inflater = new MenuInflater(this);
+ inflater.inflate(R.menu.feedinfo, menu);
+ return true;
+ } else {
+ return false;
+ }
}
@Override
@@ -105,7 +124,8 @@ public class FeedInfoActivity extends SherlockActivity {
return FeedMenuHandler.onOptionsItemClicked(this, item, feed);
} catch (DownloadRequestException e) {
e.printStackTrace();
- DownloadRequestErrorDialogCreator.newRequestErrorDialog(this, e.getMessage());
+ DownloadRequestErrorDialogCreator.newRequestErrorDialog(this,
+ e.getMessage());
}
return super.onOptionsItemSelected(item);
}
diff --git a/src/de/danoeh/antennapod/activity/FeedItemlistActivity.java b/src/de/danoeh/antennapod/activity/FeedItemlistActivity.java
index fdca48e8a..ee4e39b9d 100644
--- a/src/de/danoeh/antennapod/activity/FeedItemlistActivity.java
+++ b/src/de/danoeh/antennapod/activity/FeedItemlistActivity.java
@@ -1,151 +1,213 @@
package de.danoeh.antennapod.activity;
import android.annotation.SuppressLint;
+import android.app.SearchManager;
+import android.app.SearchableInfo;
+import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.res.TypedArray;
+import android.media.AudioManager;
+import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
+import android.support.v4.view.MenuItemCompat;
+import android.support.v7.app.ActionBarActivity;
+import android.support.v7.widget.SearchView;
import android.util.Log;
-import com.actionbarsherlock.app.SherlockFragmentActivity;
-import com.actionbarsherlock.view.Menu;
-import com.actionbarsherlock.view.MenuInflater;
-import com.actionbarsherlock.view.MenuItem;
-import com.actionbarsherlock.view.Window;
-
+import android.view.Menu;
+import android.view.MenuInflater;
+import android.view.MenuItem;
+import android.view.Window;
+import de.danoeh.antennapod.AppConfig;
import de.danoeh.antennapod.R;
import de.danoeh.antennapod.asynctask.FeedRemover;
import de.danoeh.antennapod.dialog.ConfirmationDialog;
import de.danoeh.antennapod.dialog.DownloadRequestErrorDialogCreator;
import de.danoeh.antennapod.feed.Feed;
-import de.danoeh.antennapod.feed.FeedManager;
import de.danoeh.antennapod.fragment.ExternalPlayerFragment;
import de.danoeh.antennapod.fragment.FeedlistFragment;
import de.danoeh.antennapod.fragment.ItemlistFragment;
import de.danoeh.antennapod.preferences.UserPreferences;
+import de.danoeh.antennapod.storage.DBReader;
import de.danoeh.antennapod.storage.DownloadRequestException;
import de.danoeh.antennapod.util.StorageUtils;
import de.danoeh.antennapod.util.menuhandler.FeedMenuHandler;
-/** Displays a List of FeedItems */
-public class FeedItemlistActivity extends SherlockFragmentActivity {
- private static final String TAG = "FeedItemlistActivity";
-
- private FeedManager manager;
-
- /** The feed which the activity displays */
- private Feed feed;
- private ItemlistFragment filf;
- private ExternalPlayerFragment externalPlayerFragment;
-
- @Override
- public void onCreate(Bundle savedInstanceState) {
- setTheme(UserPreferences.getTheme());
- super.onCreate(savedInstanceState);
- StorageUtils.checkStorageAvailability(this);
- requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
-
- getSupportActionBar().setDisplayHomeAsUpEnabled(true);
- setContentView(R.layout.feeditemlist_activity);
-
- manager = FeedManager.getInstance();
- long feedId = getIntent().getLongExtra(
- FeedlistFragment.EXTRA_SELECTED_FEED, -1);
- if (feedId == -1)
- Log.e(TAG, "Received invalid feed selection.");
-
- feed = manager.getFeed(feedId);
- setTitle(feed.getTitle());
-
- FragmentManager fragmentManager = getSupportFragmentManager();
- FragmentTransaction fT = fragmentManager.beginTransaction();
-
- filf = ItemlistFragment.newInstance(feed.getId());
- fT.replace(R.id.feeditemlistFragment, filf);
-
- externalPlayerFragment = new ExternalPlayerFragment();
- fT.replace(R.id.playerFragment, externalPlayerFragment);
- fT.commit();
-
- }
-
- @Override
- protected void onResume() {
- super.onResume();
- StorageUtils.checkStorageAvailability(this);
- }
-
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- TypedArray drawables = obtainStyledAttributes(new int[] { R.attr.action_search });
- menu.add(Menu.NONE, R.id.search_item, Menu.NONE, R.string.search_label)
- .setIcon(drawables.getDrawable(0))
- .setShowAsAction(MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
- return FeedMenuHandler
- .onCreateOptionsMenu(new MenuInflater(this), menu);
- }
-
- @Override
- public boolean onPrepareOptionsMenu(Menu menu) {
- return FeedMenuHandler.onPrepareOptionsMenu(menu, feed);
- }
-
- @SuppressLint("NewApi")
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- try {
- if (FeedMenuHandler.onOptionsItemClicked(this, item, feed)) {
- filf.getListAdapter().notifyDataSetChanged();
- } else {
- switch (item.getItemId()) {
- case R.id.remove_item:
- final FeedRemover remover = new FeedRemover(
- FeedItemlistActivity.this, feed) {
- @Override
- protected void onPostExecute(Void result) {
- super.onPostExecute(result);
- finish();
- }
- };
- ConfirmationDialog conDialog = new ConfirmationDialog(this,
- R.string.remove_feed_label,
- R.string.feed_delete_confirmation_msg) {
-
- @Override
- public void onConfirmButtonPressed(
- DialogInterface dialog) {
- dialog.dismiss();
- remover.executeAsync();
- }
- };
- conDialog.createNewDialog().show();
- break;
- case R.id.search_item:
- onSearchRequested();
- break;
- case android.R.id.home:
- Intent intent = new Intent(this, MainActivity.class);
- intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
- startActivity(intent);
- break;
- }
- }
- } catch (DownloadRequestException e) {
- e.printStackTrace();
- DownloadRequestErrorDialogCreator.newRequestErrorDialog(this,
- e.getMessage());
- }
- return true;
- }
-
- @Override
- public boolean onSearchRequested() {
- Bundle bundle = new Bundle();
- bundle.putLong(SearchActivity.EXTRA_FEED_ID, feed.getId());
- startSearch(null, false, bundle, false);
- return true;
- }
+/**
+ * Displays a List of FeedItems
+ */
+public class FeedItemlistActivity extends ActionBarActivity {
+ private static final String TAG = "FeedItemlistActivity";
+
+ /**
+ * The feed which the activity displays
+ */
+ private Feed feed;
+ private ItemlistFragment filf;
+ private ExternalPlayerFragment externalPlayerFragment;
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ setTheme(UserPreferences.getTheme());
+ super.onCreate(savedInstanceState);
+ StorageUtils.checkStorageAvailability(this);
+ requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
+
+ getSupportActionBar().setDisplayHomeAsUpEnabled(true);
+ setContentView(R.layout.feeditemlist_activity);
+ setVolumeControlStream(AudioManager.STREAM_MUSIC);
+
+ long feedId = getIntent().getLongExtra(
+ FeedlistFragment.EXTRA_SELECTED_FEED, -1);
+ if (feedId == -1) {
+ Log.e(TAG, "Received invalid feed selection.");
+ } else {
+ loadData(feedId);
+ }
+
+ }
+
+ private void loadData(long id) {
+ AsyncTask<Long, Void, Feed> loadTask = new AsyncTask<Long, Void, Feed>() {
+
+ @Override
+ protected Feed doInBackground(Long... longs) {
+ if (AppConfig.DEBUG)
+ Log.d(TAG, "Loading feed data in background");
+ return DBReader.getFeed(FeedItemlistActivity.this, longs[0]);
+ }
+
+ @Override
+ protected void onPostExecute(Feed result) {
+ super.onPostExecute(result);
+ if (result != null) {
+ if (AppConfig.DEBUG) Log.d(TAG, "Finished loading feed data");
+ feed = result;
+ setTitle(feed.getTitle());
+
+ FragmentManager fragmentManager = getSupportFragmentManager();
+ FragmentTransaction fT = fragmentManager.beginTransaction();
+
+ filf = ItemlistFragment.newInstance(feed.getId());
+ fT.replace(R.id.feeditemlistFragment, filf);
+
+ externalPlayerFragment = new ExternalPlayerFragment();
+ fT.replace(R.id.playerFragment, externalPlayerFragment);
+ fT.commit();
+ supportInvalidateOptionsMenu();
+ } else {
+ Log.e(TAG, "Error: Feed was null");
+ }
+ }
+ };
+ loadTask.execute(id);
+ }
+
+ @Override
+ protected void onResume() {
+ super.onResume();
+ StorageUtils.checkStorageAvailability(this);
+ }
+
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ if (feed != null) {
+ TypedArray drawables = obtainStyledAttributes(new int[]{R.attr.action_search});
+ MenuItemCompat.setShowAsAction(menu.add(Menu.NONE, R.id.search_item, Menu.NONE, R.string.search_label)
+ .setIcon(drawables.getDrawable(0)),
+ MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
+ MenuItemCompat.setActionView(menu.findItem(R.id.search_item), new SearchView(this));
+
+ SearchManager searchManager =
+ (SearchManager) getSystemService(Context.SEARCH_SERVICE);
+ SearchView searchView = (SearchView) MenuItemCompat.getActionView(menu.findItem(R.id.search_item));
+ searchView.setIconifiedByDefault(true);
+
+ searchView.setSearchableInfo(
+ searchManager.getSearchableInfo(getComponentName()));
+ return FeedMenuHandler
+ .onCreateOptionsMenu(new MenuInflater(this), menu);
+ } else {
+ return false;
+ }
+ }
+
+ @Override
+ public boolean onPrepareOptionsMenu(Menu menu) {
+ return FeedMenuHandler.onPrepareOptionsMenu(menu, feed);
+ }
+
+ @SuppressLint("NewApi")
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ try {
+ if (FeedMenuHandler.onOptionsItemClicked(this, item, feed)) {
+ filf.getListAdapter().notifyDataSetChanged();
+ } else {
+ switch (item.getItemId()) {
+ case R.id.remove_item:
+ final FeedRemover remover = new FeedRemover(
+ FeedItemlistActivity.this, feed) {
+ @Override
+ protected void onPostExecute(Void result) {
+ super.onPostExecute(result);
+ finish();
+ }
+ };
+ ConfirmationDialog conDialog = new ConfirmationDialog(this,
+ R.string.remove_feed_label,
+ R.string.feed_delete_confirmation_msg) {
+
+ @Override
+ public void onConfirmButtonPressed(
+ DialogInterface dialog) {
+ dialog.dismiss();
+ remover.executeAsync();
+ }
+ };
+ conDialog.createNewDialog().show();
+ break;
+ case android.R.id.home:
+ Intent intent = new Intent(this, MainActivity.class);
+ intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
+ startActivity(intent);
+ break;
+ }
+ }
+ } catch (DownloadRequestException e) {
+ e.printStackTrace();
+ DownloadRequestErrorDialogCreator.newRequestErrorDialog(this,
+ e.getMessage());
+ }
+ return true;
+ }
+
+ @Override
+ public boolean onSearchRequested() {
+ if (feed != null) {
+ Bundle bundle = new Bundle();
+ bundle.putLong(SearchActivity.EXTRA_FEED_ID, feed.getId());
+ startSearch(null, false, bundle, false);
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ @Override
+ public void startActivity(Intent intent) {
+ if (intent.getAction() != null &&
+ intent.getAction().equals(Intent.ACTION_SEARCH)) {
+ addSearchInformation(intent);
+ }
+ super.startActivity(intent);
+ }
+
+ private void addSearchInformation(Intent startIntent) {
+ startIntent.putExtra(SearchActivity.EXTRA_FEED_ID, feed.getId());
+ }
}
diff --git a/src/de/danoeh/antennapod/activity/FlattrAuthActivity.java b/src/de/danoeh/antennapod/activity/FlattrAuthActivity.java
index 75e513816..2ab95e287 100644
--- a/src/de/danoeh/antennapod/activity/FlattrAuthActivity.java
+++ b/src/de/danoeh/antennapod/activity/FlattrAuthActivity.java
@@ -1,6 +1,9 @@
package de.danoeh.antennapod.activity;
+import android.support.v7.app.ActionBarActivity;
+import android.view.Menu;
+import android.view.MenuItem;
import org.shredzone.flattr4j.exception.FlattrException;
import android.content.Intent;
@@ -12,10 +15,6 @@ import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
-import com.actionbarsherlock.app.SherlockActivity;
-import com.actionbarsherlock.view.Menu;
-import com.actionbarsherlock.view.MenuItem;
-
import de.danoeh.antennapod.AppConfig;
import de.danoeh.antennapod.R;
import de.danoeh.antennapod.preferences.UserPreferences;
@@ -23,7 +22,7 @@ import de.danoeh.antennapod.util.flattr.FlattrUtils;
/** Guides the user through the authentication process */
-public class FlattrAuthActivity extends SherlockActivity {
+public class FlattrAuthActivity extends ActionBarActivity {
private static final String TAG = "FlattrAuthActivity";
private TextView txtvExplanation;
diff --git a/src/de/danoeh/antennapod/activity/ItemviewActivity.java b/src/de/danoeh/antennapod/activity/ItemviewActivity.java
index 5ead667dc..c2833760d 100644
--- a/src/de/danoeh/antennapod/activity/ItemviewActivity.java
+++ b/src/de/danoeh/antennapod/activity/ItemviewActivity.java
@@ -1,55 +1,60 @@
package de.danoeh.antennapod.activity;
-import java.text.DateFormat;
-
+import android.media.AudioManager;
+import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
+import android.support.v7.app.ActionBarActivity;
import android.text.format.DateUtils;
import android.util.Log;
+import android.view.Menu;
+import android.view.MenuInflater;
+import android.view.MenuItem;
+import android.view.Window;
import android.widget.TextView;
-import com.actionbarsherlock.app.SherlockFragmentActivity;
-import com.actionbarsherlock.view.Menu;
-import com.actionbarsherlock.view.MenuInflater;
-import com.actionbarsherlock.view.MenuItem;
-import com.actionbarsherlock.view.Window;
-
import de.danoeh.antennapod.AppConfig;
import de.danoeh.antennapod.R;
import de.danoeh.antennapod.dialog.DownloadRequestErrorDialogCreator;
-import de.danoeh.antennapod.feed.Feed;
+import de.danoeh.antennapod.feed.EventDistributor;
import de.danoeh.antennapod.feed.FeedItem;
-import de.danoeh.antennapod.feed.FeedManager;
-import de.danoeh.antennapod.fragment.FeedlistFragment;
import de.danoeh.antennapod.fragment.ItemDescriptionFragment;
import de.danoeh.antennapod.fragment.ItemlistFragment;
import de.danoeh.antennapod.preferences.UserPreferences;
+import de.danoeh.antennapod.storage.DBReader;
import de.danoeh.antennapod.storage.DownloadRequestException;
+import de.danoeh.antennapod.util.QueueAccess;
import de.danoeh.antennapod.util.StorageUtils;
import de.danoeh.antennapod.util.menuhandler.FeedItemMenuHandler;
+import java.text.DateFormat;
+
/** Displays a single FeedItem and provides various actions */
-public class ItemviewActivity extends SherlockFragmentActivity {
+public class ItemviewActivity extends ActionBarActivity {
private static final String TAG = "ItemviewActivity";
- private FeedManager manager;
- private FeedItem item;
+ private static final int EVENTS = EventDistributor.DOWNLOAD_HANDLED | EventDistributor.DOWNLOAD_QUEUED;
- // Widgets
- private TextView txtvTitle;
- private TextView txtvPublished;
+ private FeedItem item;
@Override
public void onCreate(Bundle savedInstanceState) {
setTheme(UserPreferences.getTheme());
super.onCreate(savedInstanceState);
StorageUtils.checkStorageAvailability(this);
- manager = FeedManager.getInstance();
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
getSupportActionBar().setDisplayShowTitleEnabled(false);
- extractFeeditem();
- populateUI();
+ EventDistributor.getInstance().register(contentUpdate);
+ setVolumeControlStream(AudioManager.STREAM_MUSIC);
+
+ long itemId = getIntent().getLongExtra(
+ ItemlistFragment.EXTRA_SELECTED_FEEDITEM, -1);
+ if (itemId == -1) {
+ Log.e(TAG, "Received invalid selection of either feeditem or feed.");
+ } else {
+ loadData(itemId);
+ }
}
@Override
@@ -62,32 +67,43 @@ public class ItemviewActivity extends SherlockFragmentActivity {
@Override
public void onStop() {
super.onStop();
+ EventDistributor.getInstance().unregister(contentUpdate);
if (AppConfig.DEBUG)
Log.d(TAG, "Stopping Activity");
}
- /** Extracts FeedItem object the activity is supposed to display */
- private void extractFeeditem() {
- long itemId = getIntent().getLongExtra(
- ItemlistFragment.EXTRA_SELECTED_FEEDITEM, -1);
- long feedId = getIntent().getLongExtra(
- FeedlistFragment.EXTRA_SELECTED_FEED, -1);
- if (itemId == -1 || feedId == -1) {
- Log.e(TAG, "Received invalid selection of either feeditem or feed.");
- }
- Feed feed = manager.getFeed(feedId);
- item = manager.getFeedItem(itemId, feed);
- if (AppConfig.DEBUG)
- Log.d(TAG, "Title of item is " + item.getTitle());
- if (AppConfig.DEBUG)
- Log.d(TAG, "Title of feed is " + item.getFeed().getTitle());
- }
+ private void loadData(long itemId) {
+ AsyncTask<Long, Void, FeedItem> loadTask = new AsyncTask<Long, Void, FeedItem>() {
+
+ @Override
+ protected FeedItem doInBackground(Long... longs) {
+ return DBReader.getFeedItem(ItemviewActivity.this, longs[0]);
+ }
+
+ @Override
+ protected void onPostExecute(FeedItem feedItem) {
+ super.onPostExecute(feedItem);
+ if (feedItem != null && feedItem.getFeed() != null) {
+ item = feedItem;
+ populateUI();
+ supportInvalidateOptionsMenu();
+ } else {
+ if (feedItem == null) {
+ Log.e(TAG, "Error: FeedItem was null");
+ } else if (feedItem.getFeed() == null) {
+ Log.e(TAG, "Error: Feed was null");
+ }
+ }
+ }
+ };
+ loadTask.execute(itemId);
+ }
private void populateUI() {
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
setContentView(R.layout.feeditemview);
- txtvTitle = (TextView) findViewById(R.id.txtvItemname);
- txtvPublished = (TextView) findViewById(R.id.txtvPublished);
+ TextView txtvTitle = (TextView) findViewById(R.id.txtvItemname);
+ TextView txtvPublished = (TextView) findViewById(R.id.txtvPublished);
setTitle(item.getFeed().getTitle());
txtvPublished.setText(DateUtils.formatSameDayTime(item.getPubDate()
@@ -106,9 +122,13 @@ public class ItemviewActivity extends SherlockFragmentActivity {
@Override
public boolean onCreateOptionsMenu(Menu menu) {
- MenuInflater inflater = getSupportMenuInflater();
- inflater.inflate(R.menu.feeditem, menu);
- return true;
+ if (item != null) {
+ MenuInflater inflater = getMenuInflater();
+ inflater.inflate(R.menu.feeditem, menu);
+ return true;
+ } else {
+ return false;
+ }
}
@Override
@@ -134,13 +154,28 @@ public class ItemviewActivity extends SherlockFragmentActivity {
@Override
public boolean onPrepareOptionsMenu(final Menu menu) {
return FeedItemMenuHandler.onPrepareMenu(
- new FeedItemMenuHandler.MenuInterface() {
+ new FeedItemMenuHandler.MenuInterface() {
- @Override
- public void setItemVisibility(int id, boolean visible) {
- menu.findItem(id).setVisible(visible);
- }
- }, item, true);
+ @Override
+ public void setItemVisibility(int id, boolean visible) {
+ menu.findItem(id).setVisible(visible);
+ }
+ }, item, true, QueueAccess.NotInQueueAccess());
}
+ private EventDistributor.EventListener contentUpdate = new EventDistributor.EventListener() {
+
+ @Override
+ public void update(EventDistributor eventDistributor, Integer arg) {
+ if ((EVENTS & arg) != 0) {
+ if (AppConfig.DEBUG)
+ Log.d(TAG, "Received contentUpdate Intent.");
+ if (item != null) {
+ loadData(item.getId());
+ }
+ }
+ }
+ };
+
+
}
diff --git a/src/de/danoeh/antennapod/activity/MainActivity.java b/src/de/danoeh/antennapod/activity/MainActivity.java
index 410617b23..447a436cf 100644
--- a/src/de/danoeh/antennapod/activity/MainActivity.java
+++ b/src/de/danoeh/antennapod/activity/MainActivity.java
@@ -2,44 +2,47 @@ package de.danoeh.antennapod.activity;
import java.util.ArrayList;
+import android.app.SearchManager;
+import android.app.SearchableInfo;
import android.content.Context;
import android.content.Intent;
+import android.media.AudioManager;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.app.FragmentTransaction;
+import android.support.v4.view.MenuItemCompat;
import android.support.v4.view.ViewPager;
+import android.support.v7.app.ActionBar;
+import android.support.v7.app.ActionBarActivity;
+import android.support.v7.widget.SearchView;
import android.util.Log;
-import com.actionbarsherlock.app.ActionBar;
-import com.actionbarsherlock.app.ActionBar.Tab;
-import com.actionbarsherlock.app.SherlockFragmentActivity;
-import com.actionbarsherlock.view.Menu;
-import com.actionbarsherlock.view.MenuInflater;
-import com.actionbarsherlock.view.MenuItem;
-import com.actionbarsherlock.view.Window;
-
+import android.view.Menu;
+import android.view.MenuInflater;
+import android.view.MenuItem;
+import android.view.Window;
import de.danoeh.antennapod.AppConfig;
import de.danoeh.antennapod.R;
import de.danoeh.antennapod.feed.EventDistributor;
-import de.danoeh.antennapod.feed.FeedManager;
import de.danoeh.antennapod.fragment.EpisodesFragment;
import de.danoeh.antennapod.fragment.ExternalPlayerFragment;
import de.danoeh.antennapod.fragment.FeedlistFragment;
import de.danoeh.antennapod.preferences.UserPreferences;
import de.danoeh.antennapod.service.PlaybackService;
import de.danoeh.antennapod.service.download.DownloadService;
+import de.danoeh.antennapod.storage.DBReader;
+import de.danoeh.antennapod.storage.DBTasks;
import de.danoeh.antennapod.storage.DownloadRequester;
import de.danoeh.antennapod.util.StorageUtils;
/** The activity that is shown when the user launches the app. */
-public class MainActivity extends SherlockFragmentActivity {
+public class MainActivity extends ActionBarActivity {
private static final String TAG = "MainActivity";
private static final int EVENTS = EventDistributor.DOWNLOAD_HANDLED
| EventDistributor.DOWNLOAD_QUEUED;
- private FeedManager manager;
private ViewPager viewpager;
private TabsAdapter pagerAdapter;
private ExternalPlayerFragment externalPlayerFragment;
@@ -51,20 +54,20 @@ public class MainActivity extends SherlockFragmentActivity {
setTheme(UserPreferences.getTheme());
super.onCreate(savedInstanceState);
StorageUtils.checkStorageAvailability(this);
- manager = FeedManager.getInstance();
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
setContentView(R.layout.main);
+ setVolumeControlStream(AudioManager.STREAM_MUSIC);
- getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
+ getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
viewpager = (ViewPager) findViewById(R.id.viewpager);
pagerAdapter = new TabsAdapter(this, viewpager);
viewpager.setAdapter(pagerAdapter);
- Tab feedsTab = getSupportActionBar().newTab();
+ ActionBar.Tab feedsTab = getSupportActionBar().newTab();
feedsTab.setText(R.string.podcasts_label);
- Tab episodesTab = getSupportActionBar().newTab();
+ ActionBar.Tab episodesTab = getSupportActionBar().newTab();
episodesTab.setText(R.string.episodes_label);
pagerAdapter.addTab(feedsTab, FeedlistFragment.class, null);
@@ -80,7 +83,7 @@ public class MainActivity extends SherlockFragmentActivity {
if (!appLaunched && getIntent().getAction() != null
&& getIntent().getAction().equals(Intent.ACTION_MAIN)) {
appLaunched = true;
- if (manager.getUnreadItemsSize(true) > 0) {
+ if (DBReader.getNumberOfUnreadItems(this) > 0) {
// select 'episodes' tab
getSupportActionBar().setSelectedNavigationItem(1);
}
@@ -142,7 +145,7 @@ public class MainActivity extends SherlockFragmentActivity {
startActivity(new Intent(this, AddFeedActivity.class));
return true;
case R.id.all_feed_refresh:
- manager.refreshAllFeeds(this);
+ DBTasks.refreshAllFeeds(this, null);
return true;
case R.id.show_downloads:
startActivity(new Intent(this, DownloadActivity.class));
@@ -153,9 +156,6 @@ public class MainActivity extends SherlockFragmentActivity {
case R.id.show_player:
startActivity(PlaybackService.getPlayerActivityIntent(this));
return true;
- case R.id.search_item:
- onSearchRequested();
- return true;
case R.id.show_playback_history:
startActivity(new Intent(this, PlaybackHistoryActivity.class));
return true;
@@ -173,9 +173,6 @@ public class MainActivity extends SherlockFragmentActivity {
} else {
refreshAll.setVisible(true);
}
-
- boolean hasFeeds = manager.getFeedsSize() > 0;
- menu.findItem(R.id.all_feed_refresh).setVisible(hasFeeds);
return true;
}
@@ -183,7 +180,18 @@ public class MainActivity extends SherlockFragmentActivity {
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = new MenuInflater(this);
inflater.inflate(R.menu.main, menu);
- return true;
+
+ SearchManager searchManager =
+ (SearchManager) getSystemService(Context.SEARCH_SERVICE);
+ SearchView searchView = (SearchView) MenuItemCompat.getActionView(menu.findItem(R.id.search_item));
+ searchView.setIconifiedByDefault(true);
+
+ SearchableInfo info = searchManager.getSearchableInfo(getComponentName());
+ searchView.setSearchableInfo(
+ searchManager.getSearchableInfo(getComponentName()));
+
+
+ return true;
}
public static class TabsAdapter extends FragmentPagerAdapter implements
@@ -248,7 +256,7 @@ public class MainActivity extends SherlockFragmentActivity {
}
@Override
- public void onTabSelected(Tab tab, FragmentTransaction ft) {
+ public void onTabSelected(ActionBar.Tab tab, FragmentTransaction ft) {
Object tag = tab.getTag();
for (int i = 0; i < mTabs.size(); i++) {
if (mTabs.get(i) == tag) {
@@ -258,12 +266,12 @@ public class MainActivity extends SherlockFragmentActivity {
}
@Override
- public void onTabUnselected(Tab tab, FragmentTransaction ft) {
+ public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction ft) {
}
@Override
- public void onTabReselected(Tab tab, FragmentTransaction ft) {
+ public void onTabReselected(ActionBar.Tab tab, FragmentTransaction ft) {
}
}
diff --git a/src/de/danoeh/antennapod/activity/MediaplayerActivity.java b/src/de/danoeh/antennapod/activity/MediaplayerActivity.java
index 9fa9fbf52..af244f2ed 100644
--- a/src/de/danoeh/antennapod/activity/MediaplayerActivity.java
+++ b/src/de/danoeh/antennapod/activity/MediaplayerActivity.java
@@ -4,24 +4,23 @@ import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.PixelFormat;
+import android.media.AudioManager;
import android.net.Uri;
import android.os.Bundle;
+import android.support.v7.app.ActionBarActivity;
import android.util.Log;
+import android.view.Menu;
+import android.view.MenuInflater;
+import android.view.MenuItem;
import android.widget.ImageButton;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TextView;
-import com.actionbarsherlock.app.SherlockFragmentActivity;
-import com.actionbarsherlock.view.Menu;
-import com.actionbarsherlock.view.MenuInflater;
-import com.actionbarsherlock.view.MenuItem;
-
import de.danoeh.antennapod.AppConfig;
import de.danoeh.antennapod.R;
import de.danoeh.antennapod.asynctask.FlattrClickWorker;
import de.danoeh.antennapod.dialog.TimeDialog;
-import de.danoeh.antennapod.feed.FeedManager;
import de.danoeh.antennapod.preferences.UserPreferences;
import de.danoeh.antennapod.service.PlaybackService;
import de.danoeh.antennapod.util.Converter;
@@ -35,12 +34,10 @@ import de.danoeh.antennapod.util.playback.PlaybackController;
* Provides general features which are both needed for playing audio and video
* files.
*/
-public abstract class MediaplayerActivity extends SherlockFragmentActivity
+public abstract class MediaplayerActivity extends ActionBarActivity
implements OnSeekBarChangeListener {
private static final String TAG = "MediaplayerActivity";
- protected FeedManager manager;
-
protected PlaybackController controller;
protected TextView txtvPosition;
@@ -156,9 +153,9 @@ public abstract class MediaplayerActivity extends SherlockFragmentActivity
if (AppConfig.DEBUG)
Log.d(TAG, "Creating Activity");
StorageUtils.checkStorageAvailability(this);
+ setVolumeControlStream(AudioManager.STREAM_MUSIC);
- orientation = getResources().getConfiguration().orientation;
- manager = FeedManager.getInstance();
+ orientation = getResources().getConfiguration().orientation;
getWindow().setFormat(PixelFormat.TRANSPARENT);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
diff --git a/src/de/danoeh/antennapod/activity/MiroGuideCategoryActivity.java b/src/de/danoeh/antennapod/activity/MiroGuideCategoryActivity.java
index bb50944cc..c039e96f8 100644
--- a/src/de/danoeh/antennapod/activity/MiroGuideCategoryActivity.java
+++ b/src/de/danoeh/antennapod/activity/MiroGuideCategoryActivity.java
@@ -5,13 +5,11 @@ import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.view.ViewPager;
+import android.support.v7.app.ActionBarActivity;
import android.util.Log;
-import com.actionbarsherlock.app.SherlockFragmentActivity;
-import com.actionbarsherlock.view.Menu;
-import com.actionbarsherlock.view.MenuItem;
-import com.viewpagerindicator.TabPageIndicator;
-
+import android.view.Menu;
+import android.view.MenuItem;
import de.danoeh.antennapod.R;
import de.danoeh.antennapod.fragment.MiroGuideChannellistFragment;
import de.danoeh.antennapod.preferences.UserPreferences;
@@ -21,14 +19,13 @@ import de.danoeh.antennapod.preferences.UserPreferences;
* activity uses MiroGuideChannelListFragments for these lists. If the user
* selects a channel, the MiroGuideChannelViewActivity is started.
*/
-public class MiroGuideCategoryActivity extends SherlockFragmentActivity {
+public class MiroGuideCategoryActivity extends ActionBarActivity {
private static final String TAG = "MiroGuideCategoryActivity";
public static String EXTRA_CATEGORY = "category";
private ViewPager viewpager;
private CategoryPagerAdapter pagerAdapter;
- private TabPageIndicator tabs;
private String category;
@@ -40,14 +37,12 @@ public class MiroGuideCategoryActivity extends SherlockFragmentActivity {
setContentView(R.layout.miroguide_category);
viewpager = (ViewPager) findViewById(R.id.viewpager);
- tabs = (TabPageIndicator) findViewById(R.id.tabs);
category = getIntent().getStringExtra(EXTRA_CATEGORY);
if (category != null) {
getSupportActionBar().setTitle(category);
pagerAdapter = new CategoryPagerAdapter(getSupportFragmentManager());
viewpager.setAdapter(pagerAdapter);
- tabs.setViewPager(viewpager);
} else {
Log.e(TAG, "Activity was started with invalid arguments");
}
diff --git a/src/de/danoeh/antennapod/activity/MiroGuideChannelViewActivity.java b/src/de/danoeh/antennapod/activity/MiroGuideChannelViewActivity.java
index f9fe912cd..d4b4597f2 100644
--- a/src/de/danoeh/antennapod/activity/MiroGuideChannelViewActivity.java
+++ b/src/de/danoeh/antennapod/activity/MiroGuideChannelViewActivity.java
@@ -1,13 +1,18 @@
package de.danoeh.antennapod.activity;
import java.util.Date;
+import java.util.List;
import android.annotation.SuppressLint;
import android.content.Intent;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
+import android.support.v7.app.ActionBarActivity;
import android.util.Log;
+import android.view.Menu;
+import android.view.MenuInflater;
+import android.view.MenuItem;
import android.view.View;
import android.widget.ListView;
import android.widget.ProgressBar;
@@ -15,21 +20,16 @@ import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
-import com.actionbarsherlock.app.SherlockActivity;
-import com.actionbarsherlock.view.Menu;
-import com.actionbarsherlock.view.MenuInflater;
-import com.actionbarsherlock.view.MenuItem;
-
import de.danoeh.antennapod.AppConfig;
import de.danoeh.antennapod.R;
import de.danoeh.antennapod.adapter.MiroGuideItemlistAdapter;
import de.danoeh.antennapod.dialog.DownloadRequestErrorDialogCreator;
import de.danoeh.antennapod.feed.Feed;
-import de.danoeh.antennapod.feed.FeedManager;
import de.danoeh.antennapod.miroguide.conn.MiroGuideException;
import de.danoeh.antennapod.miroguide.conn.MiroGuideService;
import de.danoeh.antennapod.miroguide.model.MiroGuideChannel;
import de.danoeh.antennapod.preferences.UserPreferences;
+import de.danoeh.antennapod.storage.DBReader;
import de.danoeh.antennapod.storage.DownloadRequestException;
import de.danoeh.antennapod.storage.DownloadRequester;
@@ -37,147 +37,164 @@ import de.danoeh.antennapod.storage.DownloadRequester;
* Displays information about one channel and lets the user add this channel to
* his library.
*/
-public class MiroGuideChannelViewActivity extends SherlockActivity {
+public class MiroGuideChannelViewActivity extends ActionBarActivity {
private static final String TAG = "MiroGuideChannelViewActivity";
- public static final String EXTRA_CHANNEL_ID = "id";
- public static final String EXTRA_CHANNEL_URL = "url";
-
- private RelativeLayout layoutContent;
- private ProgressBar progLoading;
- private TextView txtvTitle;
- private TextView txtVDescription;
- private ListView listEntries;
-
- private long channelId;
- private String channelUrl;
- private MiroGuideChannel channel;
-
- @Override
- protected void onPause() {
- super.onPause();
- channelLoader.cancel(true);
- }
-
- @SuppressLint("NewApi")
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- setTheme(UserPreferences.getTheme());
- super.onCreate(savedInstanceState);
- getSupportActionBar().setDisplayHomeAsUpEnabled(true);
- setContentView(R.layout.miroguide_channelview);
-
- layoutContent = (RelativeLayout) findViewById(R.id.layout_content);
- progLoading = (ProgressBar) findViewById(R.id.progLoading);
- txtvTitle = (TextView) findViewById(R.id.txtvTitle);
- txtVDescription = (TextView) findViewById(R.id.txtvDescription);
- listEntries = (ListView) findViewById(R.id.itemlist);
-
- channelId = getIntent().getLongExtra(EXTRA_CHANNEL_ID, -1);
- channelUrl = getIntent().getStringExtra(EXTRA_CHANNEL_URL);
-
- if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.GINGERBREAD_MR1) {
- channelLoader.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
- } else {
- channelLoader.execute();
- }
-
- }
-
- /** Is used to load channel information asynchronously. */
- private AsyncTask<Void, Void, Void> channelLoader = new AsyncTask<Void, Void, Void>() {
- private static final String TAG = "ChannelLoader";
- private Exception exception;
-
- @Override
- protected Void doInBackground(Void... params) {
- if (AppConfig.DEBUG)
- Log.d(TAG, "Starting background task");
- MiroGuideService service = new MiroGuideService();
- try {
- channel = service.getChannel(channelId);
- } catch (MiroGuideException e) {
- e.printStackTrace();
- exception = e;
- }
- return null;
- }
-
- @SuppressLint("NewApi")
- @Override
- protected void onPostExecute(Void result) {
- if (AppConfig.DEBUG)
- Log.d(TAG, "Loading finished");
- if (exception == null) {
- txtvTitle.setText(channel.getName());
- txtVDescription.setText(channel.getDescription());
-
- MiroGuideItemlistAdapter listAdapter = new MiroGuideItemlistAdapter(
- MiroGuideChannelViewActivity.this, 0,
- channel.getItems());
- listEntries.setAdapter(listAdapter);
- progLoading.setVisibility(View.GONE);
- layoutContent.setVisibility(View.VISIBLE);
- supportInvalidateOptionsMenu();
- } else {
- finish();
- }
- }
-
- };
-
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- MenuInflater inflater = new MenuInflater(this);
- inflater.inflate(R.menu.channelview, menu);
- return true;
- }
-
- @Override
- public boolean onPrepareOptionsMenu(Menu menu) {
- boolean channelLoaded = channel != null;
- boolean beingDownloaded = channelLoaded
- && DownloadRequester.getInstance().isDownloadingFile(
- channel.getDownloadUrl());
- boolean notAdded = channelLoaded
- && !((FeedManager.getInstance().feedExists(
- channel.getDownloadUrl()) || beingDownloaded));
- menu.findItem(R.id.add_feed).setVisible(notAdded);
- menu.findItem(R.id.visit_website_item).setVisible(
- channelLoaded && channel.getWebsiteUrl() != null);
- return true;
- }
-
- @SuppressLint("NewApi")
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- switch (item.getItemId()) {
- case android.R.id.home:
- finish();
- return true;
- case R.id.visit_website_item:
- Uri uri = Uri.parse(channel.getWebsiteUrl());
- startActivity(new Intent(Intent.ACTION_VIEW, uri));
- return true;
- case R.id.add_feed:
- try {
- DownloadRequester.getInstance().downloadFeed(
- this,
- new Feed(channel.getDownloadUrl(), new Date(), channel
- .getName()));
- } catch (DownloadRequestException e) {
- e.printStackTrace();
- DownloadRequestErrorDialogCreator.newRequestErrorDialog(this,
- e.getMessage());
- }
- Toast toast = Toast.makeText(this, R.string.miro_feed_added,
- Toast.LENGTH_LONG);
- toast.show();
- supportInvalidateOptionsMenu();
- return true;
- default:
- return false;
- }
- }
+ public static final String EXTRA_CHANNEL_ID = "id";
+ public static final String EXTRA_CHANNEL_URL = "url";
+
+ private RelativeLayout layoutContent;
+ private ProgressBar progLoading;
+ private TextView txtvTitle;
+ private TextView txtVDescription;
+ private ListView listEntries;
+
+ private long channelId;
+ private String channelUrl;
+ private MiroGuideChannel channel;
+ private volatile List<Feed> feeds;
+
+ @Override
+ protected void onPause() {
+ super.onPause();
+ channelLoader.cancel(true);
+ }
+
+ @SuppressLint("NewApi")
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ setTheme(UserPreferences.getTheme());
+ super.onCreate(savedInstanceState);
+ getSupportActionBar().setDisplayHomeAsUpEnabled(true);
+ setContentView(R.layout.miroguide_channelview);
+
+ layoutContent = (RelativeLayout) findViewById(R.id.layout_content);
+ progLoading = (ProgressBar) findViewById(R.id.progLoading);
+ txtvTitle = (TextView) findViewById(R.id.txtvTitle);
+ txtVDescription = (TextView) findViewById(R.id.txtvDescription);
+ listEntries = (ListView) findViewById(R.id.itemlist);
+
+ channelId = getIntent().getLongExtra(EXTRA_CHANNEL_ID, -1);
+ channelUrl = getIntent().getStringExtra(EXTRA_CHANNEL_URL);
+
+ if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.GINGERBREAD_MR1) {
+ channelLoader.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
+ } else {
+ channelLoader.execute();
+ }
+
+ }
+
+ /**
+ * Is used to load channel information asynchronously.
+ */
+ private AsyncTask<Void, Void, Void> channelLoader = new AsyncTask<Void, Void, Void>() {
+ private static final String TAG = "ChannelLoader";
+ private Exception exception;
+
+ @Override
+ protected Void doInBackground(Void... params) {
+ if (AppConfig.DEBUG)
+ Log.d(TAG, "Starting background task");
+ feeds = DBReader.getFeedList(MiroGuideChannelViewActivity.this);
+ MiroGuideService service = new MiroGuideService();
+ try {
+ channel = service.getChannel(channelId);
+ } catch (MiroGuideException e) {
+ e.printStackTrace();
+ exception = e;
+ }
+ return null;
+ }
+
+ @SuppressLint("NewApi")
+ @Override
+ protected void onPostExecute(Void result) {
+ if (AppConfig.DEBUG)
+ Log.d(TAG, "Loading finished");
+ if (exception == null) {
+ txtvTitle.setText(channel.getName());
+ txtVDescription.setText(channel.getDescription());
+
+ MiroGuideItemlistAdapter listAdapter = new MiroGuideItemlistAdapter(
+ MiroGuideChannelViewActivity.this, 0,
+ channel.getItems());
+ listEntries.setAdapter(listAdapter);
+ progLoading.setVisibility(View.GONE);
+ layoutContent.setVisibility(View.VISIBLE);
+ supportInvalidateOptionsMenu();
+ } else {
+ finish();
+ }
+ }
+
+ };
+
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ MenuInflater inflater = new MenuInflater(this);
+ inflater.inflate(R.menu.channelview, menu);
+ return true;
+ }
+
+ @Override
+ public boolean onPrepareOptionsMenu(Menu menu) {
+ boolean channelLoaded = channel != null;
+ boolean beingDownloaded = channelLoaded
+ && DownloadRequester.getInstance().isDownloadingFile(
+ channel.getDownloadUrl());
+ boolean notAdded = channelLoaded
+ && !((feedExists(
+ channel.getDownloadUrl()) || beingDownloaded));
+ menu.findItem(R.id.add_feed).setVisible(notAdded);
+ menu.findItem(R.id.visit_website_item).setVisible(
+ channelLoaded && channel.getWebsiteUrl() != null);
+ return true;
+ }
+
+ @SuppressLint("NewApi")
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ switch (item.getItemId()) {
+ case android.R.id.home:
+ finish();
+ return true;
+ case R.id.visit_website_item:
+ Uri uri = Uri.parse(channel.getWebsiteUrl());
+ startActivity(new Intent(Intent.ACTION_VIEW, uri));
+ return true;
+ case R.id.add_feed:
+ try {
+ DownloadRequester.getInstance().downloadFeed(
+ this,
+ new Feed(channel.getDownloadUrl(), new Date(), channel
+ .getName()));
+ } catch (DownloadRequestException e) {
+ e.printStackTrace();
+ DownloadRequestErrorDialogCreator.newRequestErrorDialog(this,
+ e.getMessage());
+ }
+ Toast toast = Toast.makeText(this, R.string.miro_feed_added,
+ Toast.LENGTH_LONG);
+ toast.show();
+ supportInvalidateOptionsMenu();
+ return true;
+ default:
+ return false;
+ }
+ }
+
+ private boolean feedExists(String downloadUrl) {
+ if (feeds == null) {
+ return false;
+ }
+
+ for (Feed feed : feeds) {
+ if (feed.getDownload_url().equals(downloadUrl)) {
+ return true;
+ }
+ }
+ return false;
+ }
}
diff --git a/src/de/danoeh/antennapod/activity/MiroGuideMainActivity.java b/src/de/danoeh/antennapod/activity/MiroGuideMainActivity.java
index 8b33ef1da..40306e4da 100644
--- a/src/de/danoeh/antennapod/activity/MiroGuideMainActivity.java
+++ b/src/de/danoeh/antennapod/activity/MiroGuideMainActivity.java
@@ -1,19 +1,24 @@
package de.danoeh.antennapod.activity;
import android.annotation.SuppressLint;
+import android.app.SearchManager;
+import android.app.SearchableInfo;
+import android.content.Context;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
+import android.support.v4.view.MenuItemCompat;
+import android.support.v7.app.ActionBarActivity;
+import android.support.v7.widget.SearchView;
import android.util.Log;
+import android.view.Menu;
+import android.view.MenuItem;
import android.view.View;
+import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
-import com.actionbarsherlock.app.SherlockListActivity;
-import com.actionbarsherlock.view.Menu;
-import com.actionbarsherlock.view.MenuItem;
-
import de.danoeh.antennapod.AppConfig;
import de.danoeh.antennapod.R;
import de.danoeh.antennapod.miroguide.conn.MiroGuideException;
@@ -24,132 +29,140 @@ import de.danoeh.antennapod.preferences.UserPreferences;
* Shows a list of available categories and offers a search button. If the user
* selects a category, the MiroGuideCategoryActivity is started.
*/
-public class MiroGuideMainActivity extends SherlockListActivity {
- private static final String TAG = "MiroGuideMainActivity";
-
- private static String[] categories;
- private ArrayAdapter<String> listAdapter;
-
- private TextView txtvStatus;
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- setTheme(UserPreferences.getTheme());
- super.onCreate(savedInstanceState);
- getSupportActionBar().setDisplayHomeAsUpEnabled(true);
- setContentView(R.layout.miroguide_categorylist);
-
- txtvStatus = (TextView) findViewById(android.R.id.empty);
- }
-
- @Override
- protected void onPause() {
- super.onPause();
- }
-
- @Override
- protected void onResume() {
- super.onResume();
- if (categories != null) {
- createAdapter();
- } else {
- loadCategories();
- }
- }
-
- @Override
- protected void onListItemClick(ListView l, View v, int position, long id) {
- super.onListItemClick(l, v, position, id);
- String selection = listAdapter.getItem(position);
- Intent launchIntent = new Intent(this, MiroGuideCategoryActivity.class);
- launchIntent.putExtra(MiroGuideCategoryActivity.EXTRA_CATEGORY,
- selection);
- startActivity(launchIntent);
- }
-
- private void createAdapter() {
- if (categories != null) {
- listAdapter = new ArrayAdapter<String>(this,
- android.R.layout.simple_list_item_1, categories);
- txtvStatus.setText(R.string.no_items_label);
- setListAdapter(listAdapter);
- }
- }
-
- /**
- * Launches an AsyncTask to load the available categories in the background.
- */
- @SuppressLint("NewApi")
- private void loadCategories() {
- AsyncTask<Void, Void, Void> listLoader = new AsyncTask<Void, Void, Void>() {
-
- private String[] c;
- private MiroGuideException exception;
-
- @Override
- protected void onPostExecute(Void result) {
- if (exception == null) {
- if (AppConfig.DEBUG)
- Log.d(TAG, "Successfully loaded categories");
- categories = c;
- createAdapter();
- } else {
- Log.e(TAG, "Error happened while trying to load categories");
- txtvStatus.setText(exception.getMessage());
- }
- }
-
- @Override
- protected void onPreExecute() {
- txtvStatus.setText(R.string.loading_categories_label);
- }
-
- @Override
- protected Void doInBackground(Void... params) {
- MiroGuideService service = new MiroGuideService();
- try {
- c = service.getCategories();
- } catch (MiroGuideException e) {
- e.printStackTrace();
- exception = e;
- } finally {
- service.close();
- }
- return null;
- }
-
- };
-
- if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.GINGERBREAD_MR1) {
- listLoader.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
- } else {
- listLoader.execute();
- }
- }
-
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- menu.add(Menu.NONE, R.id.search_item, Menu.NONE, R.string.search_label)
- .setIcon(
- obtainStyledAttributes(
- new int[] { R.attr.action_search })
- .getDrawable(0))
- .setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
- return true;
- }
-
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- switch (item.getItemId()) {
- case android.R.id.home:
- finish();
- return true;
- case R.id.search_item:
- onSearchRequested();
- return true;
- default:
- return false;
- }
- }
-
+public class MiroGuideMainActivity extends ActionBarActivity implements AdapterView.OnItemClickListener {
+ private static final String TAG = "MiroGuideMainActivity";
+
+ private static String[] categories;
+ private ArrayAdapter<String> listAdapter;
+
+ private TextView txtvStatus;
+ private ListView listView;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ setTheme(UserPreferences.getTheme());
+ super.onCreate(savedInstanceState);
+ getSupportActionBar().setDisplayHomeAsUpEnabled(true);
+ setContentView(R.layout.miroguide_categorylist);
+
+ txtvStatus = (TextView) findViewById(android.R.id.empty);
+ listView = (ListView) findViewById(android.R.id.list);
+ listView.setOnItemClickListener(this);
+ listView.setEmptyView(txtvStatus);
+ }
+
+ @Override
+ protected void onPause() {
+ super.onPause();
+ }
+
+ @Override
+ protected void onResume() {
+ super.onResume();
+ if (categories != null) {
+ createAdapter();
+ } else {
+ loadCategories();
+ }
+ }
+
+ private void createAdapter() {
+ if (categories != null) {
+ listAdapter = new ArrayAdapter<String>(this,
+ android.R.layout.simple_list_item_1, categories);
+ txtvStatus.setText(R.string.no_items_label);
+ listView.setAdapter(listAdapter);
+ }
+ }
+
+ /**
+ * Launches an AsyncTask to load the available categories in the background.
+ */
+ @SuppressLint("NewApi")
+ private void loadCategories() {
+ AsyncTask<Void, Void, Void> listLoader = new AsyncTask<Void, Void, Void>() {
+
+ private String[] c;
+ private MiroGuideException exception;
+
+ @Override
+ protected void onPostExecute(Void result) {
+ if (exception == null) {
+ if (AppConfig.DEBUG)
+ Log.d(TAG, "Successfully loaded categories");
+ categories = c;
+ createAdapter();
+ } else {
+ Log.e(TAG, "Error happened while trying to load categories");
+ txtvStatus.setText(exception.getMessage());
+ }
+ }
+
+ @Override
+ protected void onPreExecute() {
+ txtvStatus.setText(R.string.loading_categories_label);
+ }
+
+ @Override
+ protected Void doInBackground(Void... params) {
+ MiroGuideService service = new MiroGuideService();
+ try {
+ c = service.getCategories();
+ } catch (MiroGuideException e) {
+ e.printStackTrace();
+ exception = e;
+ } finally {
+ service.close();
+ }
+ return null;
+ }
+
+ };
+
+ if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.GINGERBREAD_MR1) {
+ listLoader.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
+ } else {
+ listLoader.execute();
+ }
+ }
+
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ MenuItemCompat.setShowAsAction(menu.add(Menu.NONE, R.id.search_item, Menu.NONE, R.string.search_label)
+ .setIcon(
+ obtainStyledAttributes(
+ new int[]{R.attr.action_search})
+ .getDrawable(0)),
+ MenuItem.SHOW_AS_ACTION_IF_ROOM);
+ MenuItemCompat.setActionView(menu.findItem(R.id.search_item), new SearchView(this));
+
+ SearchManager searchManager =
+ (SearchManager) getSystemService(Context.SEARCH_SERVICE);
+ SearchView searchView = (SearchView) MenuItemCompat.getActionView(menu.findItem(R.id.search_item));
+ searchView.setIconifiedByDefault(true);
+ searchView.setSearchableInfo(
+ searchManager.getSearchableInfo(getComponentName()));
+
+ return true;
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ switch (item.getItemId()) {
+ case android.R.id.home:
+ finish();
+ return true;
+ default:
+ return false;
+ }
+ }
+
+ @Override
+ public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
+ String selection = listAdapter.getItem(position);
+ Intent launchIntent = new Intent(this, MiroGuideCategoryActivity.class);
+ launchIntent.putExtra(MiroGuideCategoryActivity.EXTRA_CATEGORY,
+ selection);
+ startActivity(launchIntent);
+ }
}
diff --git a/src/de/danoeh/antennapod/activity/MiroGuideSearchActivity.java b/src/de/danoeh/antennapod/activity/MiroGuideSearchActivity.java
index a30777fb1..4ea0b1699 100644
--- a/src/de/danoeh/antennapod/activity/MiroGuideSearchActivity.java
+++ b/src/de/danoeh/antennapod/activity/MiroGuideSearchActivity.java
@@ -4,12 +4,12 @@ import android.app.SearchManager;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentTransaction;
+import android.support.v4.view.MenuItemCompat;
+import android.support.v7.app.ActionBarActivity;
import android.util.Log;
-import com.actionbarsherlock.app.SherlockFragmentActivity;
-import com.actionbarsherlock.view.Menu;
-import com.actionbarsherlock.view.MenuItem;
-
+import android.view.Menu;
+import android.view.MenuItem;
import de.danoeh.antennapod.AppConfig;
import de.danoeh.antennapod.R;
import de.danoeh.antennapod.fragment.MiroGuideChannellistFragment;
@@ -19,72 +19,72 @@ import de.danoeh.antennapod.preferences.UserPreferences;
* Displays results when a search for miroguide channels has been performed. It
* uses a MiroGuideChannelListFragment to display the results.
*/
-public class MiroGuideSearchActivity extends SherlockFragmentActivity {
- private static final String TAG = "MiroGuideSearchActivity";
+public class MiroGuideSearchActivity extends ActionBarActivity {
+ private static final String TAG = "MiroGuideSearchActivity";
- private MiroGuideChannellistFragment listFragment;
+ private MiroGuideChannellistFragment listFragment;
- @Override
- protected void onCreate(Bundle arg0) {
- setTheme(UserPreferences.getTheme());
- super.onCreate(arg0);
- getSupportActionBar().setDisplayHomeAsUpEnabled(true);
- setContentView(R.layout.miroguidesearch);
- }
+ @Override
+ protected void onCreate(Bundle arg0) {
+ setTheme(UserPreferences.getTheme());
+ super.onCreate(arg0);
+ getSupportActionBar().setDisplayHomeAsUpEnabled(true);
+ setContentView(R.layout.miroguidesearch);
+ }
- @Override
- protected void onResume() {
- super.onResume();
- Intent intent = getIntent();
- if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
- String query = intent.getStringExtra(SearchManager.QUERY);
- getSupportActionBar()
- .setSubtitle(
- getString(R.string.search_term_label) + "\""
- + query + "\"");
- handleSearchRequest(query);
- }
- }
+ @Override
+ protected void onResume() {
+ super.onResume();
+ Intent intent = getIntent();
+ if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
+ String query = intent.getStringExtra(SearchManager.QUERY);
+ getSupportActionBar()
+ .setSubtitle(
+ getString(R.string.search_term_label) + "\""
+ + query + "\"");
+ handleSearchRequest(query);
+ }
+ }
- private void handleSearchRequest(String query) {
- if (AppConfig.DEBUG)
- Log.d(TAG, "Performing search");
- FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
- listFragment = MiroGuideChannellistFragment.newInstance("name", query,
- "name");
- ft.replace(R.id.channellistFragment, listFragment);
- ft.commit();
- }
+ private void handleSearchRequest(String query) {
+ if (AppConfig.DEBUG)
+ Log.d(TAG, "Performing search");
+ FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
+ listFragment = MiroGuideChannellistFragment.newInstance("name", query,
+ "name");
+ ft.replace(R.id.channellistFragment, listFragment);
+ ft.commit();
+ }
- @Override
- protected void onNewIntent(Intent intent) {
- setIntent(intent);
- }
+ @Override
+ protected void onNewIntent(Intent intent) {
+ setIntent(intent);
+ }
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- menu.add(Menu.NONE, R.id.search_item, Menu.NONE, R.string.search_label)
- .setIcon(
- obtainStyledAttributes(
- new int[] { R.attr.action_search })
- .getDrawable(0))
- .setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ MenuItemCompat.setShowAsAction(menu.add(Menu.NONE, R.id.search_item, Menu.NONE, R.string.search_label)
+ .setIcon(
+ obtainStyledAttributes(
+ new int[]{R.attr.action_search})
+ .getDrawable(0)),
+ MenuItem.SHOW_AS_ACTION_IF_ROOM);
- return true;
- }
+ return true;
+ }
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- switch (item.getItemId()) {
- case android.R.id.home:
- finish();
- return true;
- case R.id.search_item:
- onSearchRequested();
- return true;
- default:
- return false;
- }
- }
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ switch (item.getItemId()) {
+ case android.R.id.home:
+ finish();
+ return true;
+ case R.id.search_item:
+ onSearchRequested();
+ return true;
+ default:
+ return false;
+ }
+ }
}
diff --git a/src/de/danoeh/antennapod/activity/OnlineFeedViewActivity.java b/src/de/danoeh/antennapod/activity/OnlineFeedViewActivity.java
index d6ff537a3..cb1c66cab 100644
--- a/src/de/danoeh/antennapod/activity/OnlineFeedViewActivity.java
+++ b/src/de/danoeh/antennapod/activity/OnlineFeedViewActivity.java
@@ -6,6 +6,7 @@ import java.util.Date;
import javax.xml.parsers.ParserConfigurationException;
+import android.support.v7.app.ActionBarActivity;
import org.xml.sax.SAXException;
import android.app.AlertDialog;
@@ -17,13 +18,12 @@ import android.view.Gravity;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
-import com.actionbarsherlock.app.SherlockFragmentActivity;
-
import de.danoeh.antennapod.AppConfig;
import de.danoeh.antennapod.R;
-import de.danoeh.antennapod.asynctask.DownloadStatus;
import de.danoeh.antennapod.feed.Feed;
import de.danoeh.antennapod.preferences.UserPreferences;
+import de.danoeh.antennapod.service.download.DownloadRequest;
+import de.danoeh.antennapod.service.download.DownloadStatus;
import de.danoeh.antennapod.service.download.Downloader;
import de.danoeh.antennapod.service.download.DownloaderCallback;
import de.danoeh.antennapod.service.download.HttpDownloader;
@@ -42,10 +42,10 @@ import de.danoeh.antennapod.util.URLChecker;
* If the feed cannot be downloaded or parsed, an error dialog will be displayed
* and the activity will finish as soon as the error dialog is closed.
*/
-public abstract class OnlineFeedViewActivity extends SherlockFragmentActivity {
+public abstract class OnlineFeedViewActivity extends ActionBarActivity {
private static final String TAG = "OnlineFeedViewActivity";
private static final String ARG_FEEDURL = "arg.feedurl";
-
+
public static final int RESULT_ERROR = 2;
private Feed feed;
@@ -70,7 +70,7 @@ public abstract class OnlineFeedViewActivity extends SherlockFragmentActivity {
@Override
protected void onStop() {
super.onStop();
- if (downloader != null && downloader.getStatus().isDone() == false) {
+ if (downloader != null && !downloader.isFinished()) {
downloader.cancel();
}
}
@@ -82,15 +82,14 @@ public abstract class OnlineFeedViewActivity extends SherlockFragmentActivity {
@Override
public void run() {
- DownloadStatus status = downloader.getStatus();
+ DownloadStatus status = downloader.getResult();
if (status != null) {
if (!status.isCancelled()) {
if (status.isSuccessful()) {
parseFeed();
} else {
- String errorMsg = DownloadError.getErrorString(
- OnlineFeedViewActivity.this,
- status.getReason());
+ String errorMsg = status.getReason().getErrorString(
+ OnlineFeedViewActivity.this);
if (errorMsg != null
&& status.getReasonDetailed() != null) {
errorMsg += " ("
@@ -119,10 +118,13 @@ public abstract class OnlineFeedViewActivity extends SherlockFragmentActivity {
FileNameGenerator.generateFileName(feed.getDownload_url()))
.toString();
feed.setFile_url(fileUrl);
- DownloadStatus status = new DownloadStatus(feed, "OnlineFeed");
+ DownloadRequest request = new DownloadRequest(feed.getFile_url(),
+ feed.getDownload_url(), "OnlineFeed", 0, Feed.FEEDFILETYPE_FEED);
+ /* TODO update
HttpDownloader httpDownloader = new HttpDownloader(downloaderCallback,
- status);
+ request);
httpDownloader.start();
+ */
}
/** Displays a progress indicator. */
@@ -187,9 +189,9 @@ public abstract class OnlineFeedViewActivity extends SherlockFragmentActivity {
}
});
} else {
- final String errorMsg = DownloadError.getErrorString(
- OnlineFeedViewActivity.this,
- DownloadError.ERROR_PARSER_EXCEPTION)
+ final String errorMsg =
+ DownloadError.ERROR_PARSER_EXCEPTION.getErrorString(
+ OnlineFeedViewActivity.this)
+ " (" + reasonDetailed + ")";
runOnUiThread(new Runnable() {
@@ -217,13 +219,14 @@ public abstract class OnlineFeedViewActivity extends SherlockFragmentActivity {
} else {
builder.setMessage(R.string.error_msg_prefix);
}
- builder.setNeutralButton(android.R.string.ok, new DialogInterface.OnClickListener() {
-
- @Override
- public void onClick(DialogInterface dialog, int which) {
- dialog.cancel();
- }
- });
+ builder.setNeutralButton(android.R.string.ok,
+ new DialogInterface.OnClickListener() {
+
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ dialog.cancel();
+ }
+ });
builder.setOnCancelListener(new OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
diff --git a/src/de/danoeh/antennapod/activity/OpmlFeedChooserActivity.java b/src/de/danoeh/antennapod/activity/OpmlFeedChooserActivity.java
index 9ba355baf..2ec42e9ef 100644
--- a/src/de/danoeh/antennapod/activity/OpmlFeedChooserActivity.java
+++ b/src/de/danoeh/antennapod/activity/OpmlFeedChooserActivity.java
@@ -5,17 +5,17 @@ import java.util.List;
import android.content.Intent;
import android.os.Bundle;
+import android.support.v4.view.MenuItemCompat;
+import android.support.v7.app.ActionBarActivity;
import android.util.SparseBooleanArray;
+import android.view.Menu;
+import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
-import com.actionbarsherlock.app.SherlockActivity;
-import com.actionbarsherlock.view.Menu;
-import com.actionbarsherlock.view.MenuItem;
-
import de.danoeh.antennapod.R;
import de.danoeh.antennapod.opml.OpmlElement;
import de.danoeh.antennapod.preferences.UserPreferences;
@@ -24,110 +24,111 @@ import de.danoeh.antennapod.preferences.UserPreferences;
* Displays the feeds that the OPML-Importer has read and lets the user choose
* which feeds he wants to import.
*/
-public class OpmlFeedChooserActivity extends SherlockActivity {
- private static final String TAG = "OpmlFeedChooserActivity";
-
- public static final String EXTRA_SELECTED_ITEMS = "de.danoeh.antennapod.selectedItems";
-
- private Button butConfirm;
- private Button butCancel;
- private ListView feedlist;
- private ArrayAdapter<String> listAdapter;
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- setTheme(UserPreferences.getTheme());
- super.onCreate(savedInstanceState);
-
- setContentView(R.layout.opml_selection);
- butConfirm = (Button) findViewById(R.id.butConfirm);
- butCancel = (Button) findViewById(R.id.butCancel);
- feedlist = (ListView) findViewById(R.id.feedlist);
-
- feedlist.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
- listAdapter = new ArrayAdapter<String>(this,
- android.R.layout.simple_list_item_multiple_choice,
- getTitleList());
-
- feedlist.setAdapter(listAdapter);
-
- butCancel.setOnClickListener(new OnClickListener() {
- @Override
- public void onClick(View v) {
- setResult(RESULT_CANCELED);
- finish();
- }
- });
-
- butConfirm.setOnClickListener(new OnClickListener() {
-
- @Override
- public void onClick(View v) {
- Intent intent = new Intent();
- SparseBooleanArray checked = feedlist.getCheckedItemPositions();
-
- int checkedCount = 0;
- // Get number of checked items
- for (int i = 0; i < checked.size(); i++) {
- if (checked.valueAt(i)) {
- checkedCount++;
- }
- }
- int[] selection = new int[checkedCount];
- for (int i = 0, collected = 0; collected < checkedCount; i++) {
- if (checked.valueAt(i)) {
- selection[collected] = checked.keyAt(i);
- collected++;
- }
- }
- intent.putExtra(EXTRA_SELECTED_ITEMS, selection);
- setResult(RESULT_OK, intent);
- finish();
- }
- });
-
- }
-
- private List<String> getTitleList() {
- List<String> result = new ArrayList<String>();
- if (OpmlImportHolder.getReadElements() != null) {
- for (OpmlElement element : OpmlImportHolder.getReadElements()) {
- result.add(element.getText());
- }
-
- }
- return result;
- }
-
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- menu.add(Menu.NONE, R.id.select_all_item, Menu.NONE,
- R.string.select_all_label).setShowAsAction(
- MenuItem.SHOW_AS_ACTION_IF_ROOM);
- menu.add(Menu.NONE, R.id.deselect_all_item, Menu.NONE,
- R.string.deselect_all_label).setShowAsAction(
- MenuItem.SHOW_AS_ACTION_IF_ROOM);
- return true;
- }
-
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- switch (item.getItemId()) {
- case R.id.select_all_item:
- selectAllItems(true);
- return true;
- case R.id.deselect_all_item:
- selectAllItems(false);
- return true;
- default:
- return false;
- }
- }
-
- private void selectAllItems(boolean b) {
- for (int i = 0; i < feedlist.getCount(); i++) {
- feedlist.setItemChecked(i, b);
- }
- }
+public class OpmlFeedChooserActivity extends ActionBarActivity {
+ private static final String TAG = "OpmlFeedChooserActivity";
+
+ public static final String EXTRA_SELECTED_ITEMS = "de.danoeh.antennapod.selectedItems";
+
+ private Button butConfirm;
+ private Button butCancel;
+ private ListView feedlist;
+ private ArrayAdapter<String> listAdapter;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ setTheme(UserPreferences.getTheme());
+ super.onCreate(savedInstanceState);
+
+ setContentView(R.layout.opml_selection);
+ butConfirm = (Button) findViewById(R.id.butConfirm);
+ butCancel = (Button) findViewById(R.id.butCancel);
+ feedlist = (ListView) findViewById(R.id.feedlist);
+
+ feedlist.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
+ listAdapter = new ArrayAdapter<String>(this,
+ android.R.layout.simple_list_item_multiple_choice,
+ getTitleList());
+
+ feedlist.setAdapter(listAdapter);
+
+ butCancel.setOnClickListener(new OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ setResult(RESULT_CANCELED);
+ finish();
+ }
+ });
+
+ butConfirm.setOnClickListener(new OnClickListener() {
+
+ @Override
+ public void onClick(View v) {
+ Intent intent = new Intent();
+ SparseBooleanArray checked = feedlist.getCheckedItemPositions();
+
+ int checkedCount = 0;
+ // Get number of checked items
+ for (int i = 0; i < checked.size(); i++) {
+ if (checked.valueAt(i)) {
+ checkedCount++;
+ }
+ }
+ int[] selection = new int[checkedCount];
+ for (int i = 0, collected = 0; collected < checkedCount; i++) {
+ if (checked.valueAt(i)) {
+ selection[collected] = checked.keyAt(i);
+ collected++;
+ }
+ }
+ intent.putExtra(EXTRA_SELECTED_ITEMS, selection);
+ setResult(RESULT_OK, intent);
+ finish();
+ }
+ });
+
+ }
+
+ private List<String> getTitleList() {
+ List<String> result = new ArrayList<String>();
+ if (OpmlImportHolder.getReadElements() != null) {
+ for (OpmlElement element : OpmlImportHolder.getReadElements()) {
+ result.add(element.getText());
+ }
+
+ }
+ return result;
+ }
+
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ MenuItemCompat.setShowAsAction(menu.add(Menu.NONE, R.id.select_all_item, Menu.NONE,
+ R.string.select_all_label),
+ MenuItem.SHOW_AS_ACTION_IF_ROOM);
+
+ MenuItemCompat.setShowAsAction(menu.add(Menu.NONE, R.id.deselect_all_item, Menu.NONE,
+ R.string.deselect_all_label),
+ MenuItem.SHOW_AS_ACTION_IF_ROOM);
+ return true;
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ switch (item.getItemId()) {
+ case R.id.select_all_item:
+ selectAllItems(true);
+ return true;
+ case R.id.deselect_all_item:
+ selectAllItems(false);
+ return true;
+ default:
+ return false;
+ }
+ }
+
+ private void selectAllItems(boolean b) {
+ for (int i = 0; i < feedlist.getCount(); i++) {
+ feedlist.setItemChecked(i, b);
+ }
+ }
}
diff --git a/src/de/danoeh/antennapod/activity/OpmlImportBaseActivity.java b/src/de/danoeh/antennapod/activity/OpmlImportBaseActivity.java
index f887fdd94..905183aa2 100644
--- a/src/de/danoeh/antennapod/activity/OpmlImportBaseActivity.java
+++ b/src/de/danoeh/antennapod/activity/OpmlImportBaseActivity.java
@@ -4,10 +4,9 @@ import java.io.Reader;
import java.util.ArrayList;
import android.content.Intent;
+import android.support.v7.app.ActionBarActivity;
import android.util.Log;
-import com.actionbarsherlock.app.SherlockActivity;
-
import de.danoeh.antennapod.AppConfig;
import de.danoeh.antennapod.asynctask.OpmlFeedQueuer;
import de.danoeh.antennapod.asynctask.OpmlImportWorker;
@@ -16,7 +15,7 @@ import de.danoeh.antennapod.opml.OpmlElement;
/**
* Base activity for Opml Import - e.g. with code what to do afterwards
* */
-public class OpmlImportBaseActivity extends SherlockActivity {
+public class OpmlImportBaseActivity extends ActionBarActivity {
private static final String TAG = "OpmlImportBaseActivity";
private OpmlImportWorker importWorker;
diff --git a/src/de/danoeh/antennapod/activity/OpmlImportFromPathActivity.java b/src/de/danoeh/antennapod/activity/OpmlImportFromPathActivity.java
index b38e0c443..259689abf 100644
--- a/src/de/danoeh/antennapod/activity/OpmlImportFromPathActivity.java
+++ b/src/de/danoeh/antennapod/activity/OpmlImportFromPathActivity.java
@@ -9,15 +9,14 @@ import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.util.Log;
+import android.view.Menu;
+import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
-import com.actionbarsherlock.view.Menu;
-import com.actionbarsherlock.view.MenuItem;
-
import de.danoeh.antennapod.AppConfig;
import de.danoeh.antennapod.R;
import de.danoeh.antennapod.preferences.UserPreferences;
diff --git a/src/de/danoeh/antennapod/activity/OrganizeQueueActivity.java b/src/de/danoeh/antennapod/activity/OrganizeQueueActivity.java
index 7269f7549..e376b08b8 100644
--- a/src/de/danoeh/antennapod/activity/OrganizeQueueActivity.java
+++ b/src/de/danoeh/antennapod/activity/OrganizeQueueActivity.java
@@ -1,10 +1,13 @@
package de.danoeh.antennapod.activity;
import android.content.Context;
-import android.content.res.TypedArray;
+import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Parcel;
import android.os.Parcelable;
+import android.support.v7.app.ActionBarActivity;
+import android.view.*;
+import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@@ -12,28 +15,32 @@ import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
-import com.actionbarsherlock.app.SherlockListActivity;
-import com.actionbarsherlock.view.Menu;
-import com.actionbarsherlock.view.MenuItem;
import com.mobeta.android.dslv.DragSortListView;
-
import de.danoeh.antennapod.R;
import de.danoeh.antennapod.asynctask.ImageLoader;
import de.danoeh.antennapod.feed.EventDistributor;
import de.danoeh.antennapod.feed.FeedItem;
-import de.danoeh.antennapod.feed.FeedManager;
import de.danoeh.antennapod.preferences.UserPreferences;
+import de.danoeh.antennapod.storage.DBReader;
+import de.danoeh.antennapod.storage.DBTasks;
+import de.danoeh.antennapod.storage.DBWriter;
import de.danoeh.antennapod.util.UndoBarController;
-public class OrganizeQueueActivity extends SherlockListActivity implements
+import java.util.List;
+
+public class OrganizeQueueActivity extends ActionBarActivity implements
UndoBarController.UndoListener {
private static final String TAG = "OrganizeQueueActivity";
private static final int MENU_ID_ACCEPT = 2;
+ private List<FeedItem> queue;
+
private OrganizeAdapter adapter;
private UndoBarController undoBarController;
+ private DragSortListView listView;
+
@Override
protected void onCreate(Bundle savedInstanceState) {
setTheme(UserPreferences.getTheme());
@@ -41,17 +48,42 @@ public class OrganizeQueueActivity extends SherlockListActivity implements
setContentView(R.layout.organize_queue);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
- DragSortListView listView = (DragSortListView) getListView();
+ listView = (DragSortListView) findViewById(android.R.id.list);
listView.setDropListener(dropListener);
listView.setRemoveListener(removeListener);
+ listView.setEmptyView(findViewById(android.R.id.empty));
- adapter = new OrganizeAdapter(this);
- setListAdapter(adapter);
-
+ loadData();
undoBarController = new UndoBarController(findViewById(R.id.undobar),
this);
}
+ private void loadData() {
+ AsyncTask<Void, Void, List<FeedItem>> loadTask = new AsyncTask<Void, Void, List<FeedItem>>() {
+
+ @Override
+ protected List<FeedItem> doInBackground(Void... voids) {
+ return DBReader.getQueue(OrganizeQueueActivity.this);
+ }
+
+ @Override
+ protected void onPostExecute(List<FeedItem> feedItems) {
+ super.onPostExecute(feedItems);
+ if (feedItems != null) {
+ queue = feedItems;
+ if (adapter == null) {
+ adapter = new OrganizeAdapter(OrganizeQueueActivity.this);
+ listView.setAdapter(adapter);
+ }
+ adapter.notifyDataSetChanged();
+ } else {
+ Log.e(TAG, "Queue was null");
+ }
+ }
+ };
+ loadTask.execute();
+ }
+
@Override
protected void onPause() {
super.onPause();
@@ -61,8 +93,7 @@ public class OrganizeQueueActivity extends SherlockListActivity implements
@Override
protected void onStop() {
super.onStop();
- FeedManager.getInstance().autodownloadUndownloadedItems(
- getApplicationContext());
+ DBTasks.autodownloadUndownloadedItems(getApplicationContext());
}
@Override
@@ -76,9 +107,7 @@ public class OrganizeQueueActivity extends SherlockListActivity implements
@Override
public void update(EventDistributor eventDistributor, Integer arg) {
if (((EventDistributor.QUEUE_UPDATE | EventDistributor.FEED_LIST_UPDATE) & arg) != 0) {
- if (adapter != null) {
- adapter.notifyDataSetChanged();
- }
+ loadData();
}
}
};
@@ -87,9 +116,10 @@ public class OrganizeQueueActivity extends SherlockListActivity implements
@Override
public void drop(int from, int to) {
- FeedManager manager = FeedManager.getInstance();
- manager.moveQueueItem(OrganizeQueueActivity.this, from, to, false);
- adapter.notifyDataSetChanged();
+ final FeedItem item = queue.remove(from);
+ queue.add(to, item);
+ adapter.notifyDataSetChanged();
+ DBWriter.moveQueueItem(OrganizeQueueActivity.this, from, to, true);
}
};
@@ -97,9 +127,8 @@ public class OrganizeQueueActivity extends SherlockListActivity implements
@Override
public void remove(int which) {
- FeedManager manager = FeedManager.getInstance();
- FeedItem item = (FeedItem) getListAdapter().getItem(which);
- manager.removeQueueItem(OrganizeQueueActivity.this, item, false);
+ FeedItem item = (FeedItem) listView.getAdapter().getItem(which);
+ DBWriter.removeQueueItem(OrganizeQueueActivity.this, item.getId(), true);
undoBarController.showUndoBar(false,
getString(R.string.removed_from_queue), new UndoToken(item,
which));
@@ -127,22 +156,20 @@ public class OrganizeQueueActivity extends SherlockListActivity implements
public void onUndo(Parcelable token) {
// Perform the undo
UndoToken undoToken = (UndoToken) token;
- FeedItem feedItem = undoToken.getFeedItem();
- int position = undoToken.getPosition();
-
- FeedManager manager = FeedManager.getInstance();
- manager.addQueueItemAt(OrganizeQueueActivity.this, feedItem, position,
- false);
+ if (token != null) {
+ long itemId = undoToken.getFeedItemId();
+ int position = undoToken.getPosition();
+ DBWriter.addQueueItemAt(OrganizeQueueActivity.this, itemId, position, false);
+ }
}
private static class OrganizeAdapter extends BaseAdapter {
- private Context context;
- private FeedManager manager = FeedManager.getInstance();
+ private OrganizeQueueActivity organizeQueueActivity;
- public OrganizeAdapter(Context context) {
+ public OrganizeAdapter(OrganizeQueueActivity organizeQueueActivity) {
super();
- this.context = context;
+ this.organizeQueueActivity = organizeQueueActivity;
}
@Override
@@ -152,7 +179,7 @@ public class OrganizeQueueActivity extends SherlockListActivity implements
if (convertView == null) {
holder = new Holder();
- LayoutInflater inflater = (LayoutInflater) context
+ LayoutInflater inflater = (LayoutInflater) organizeQueueActivity
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(
R.layout.organize_queue_listitem, null);
@@ -189,13 +216,20 @@ public class OrganizeQueueActivity extends SherlockListActivity implements
@Override
public int getCount() {
- int queueSize = manager.getQueueSize(true);
- return queueSize;
+ if (organizeQueueActivity.queue != null) {
+ return organizeQueueActivity.queue.size();
+ } else {
+ return 0;
+ }
}
@Override
public FeedItem getItem(int position) {
- return manager.getQueueItemAtIndex(position, true);
+ if (organizeQueueActivity.queue != null) {
+ return organizeQueueActivity.queue.get(position);
+ } else {
+ return null;
+ }
}
@Override
@@ -211,7 +245,6 @@ public class OrganizeQueueActivity extends SherlockListActivity implements
private int position;
public UndoToken(FeedItem item, int position) {
- FeedManager manager = FeedManager.getInstance();
this.itemId = item.getId();
this.feedId = item.getFeed().getId();
this.position = position;
@@ -243,9 +276,8 @@ public class OrganizeQueueActivity extends SherlockListActivity implements
out.writeInt(position);
}
- public FeedItem getFeedItem() {
- FeedManager manager = FeedManager.getInstance();
- return manager.getFeedItem(itemId, feedId);
+ public long getFeedItemId() {
+ return itemId;
}
public int getPosition() {
diff --git a/src/de/danoeh/antennapod/activity/PlaybackHistoryActivity.java b/src/de/danoeh/antennapod/activity/PlaybackHistoryActivity.java
index 1a5a2cac9..f329581e5 100644
--- a/src/de/danoeh/antennapod/activity/PlaybackHistoryActivity.java
+++ b/src/de/danoeh/antennapod/activity/PlaybackHistoryActivity.java
@@ -3,25 +3,25 @@ package de.danoeh.antennapod.activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentTransaction;
+import android.support.v4.view.MenuItemCompat;
+import android.support.v7.app.ActionBarActivity;
import android.util.Log;
-import com.actionbarsherlock.app.SherlockFragmentActivity;
-import com.actionbarsherlock.view.Menu;
-import com.actionbarsherlock.view.MenuItem;
-
+import android.view.Menu;
+import android.view.MenuItem;
import de.danoeh.antennapod.AppConfig;
import de.danoeh.antennapod.R;
-import de.danoeh.antennapod.feed.FeedManager;
import de.danoeh.antennapod.fragment.PlaybackHistoryFragment;
import de.danoeh.antennapod.preferences.UserPreferences;
+import de.danoeh.antennapod.storage.DBWriter;
-public class PlaybackHistoryActivity extends SherlockFragmentActivity {
+public class PlaybackHistoryActivity extends ActionBarActivity {
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(
+ MenuItemCompat.setShowAsAction(menu.add(Menu.NONE, R.id.clear_history_item, Menu.NONE,
+ R.string.clear_history_label),
MenuItem.SHOW_AS_ACTION_IF_ROOM);
return true;
}
@@ -36,7 +36,7 @@ public class PlaybackHistoryActivity extends SherlockFragmentActivity {
startActivity(intent);
return true;
case R.id.clear_history_item:
- FeedManager.getInstance().clearPlaybackHistory(this);
+ DBWriter.clearPlaybackHistory(this);
return true;
}
return super.onOptionsItemSelected(item);
diff --git a/src/de/danoeh/antennapod/activity/PreferenceActivity.java b/src/de/danoeh/antennapod/activity/PreferenceActivity.java
index 9fcf57ac2..880724c28 100644
--- a/src/de/danoeh/antennapod/activity/PreferenceActivity.java
+++ b/src/de/danoeh/antennapod/activity/PreferenceActivity.java
@@ -19,369 +19,358 @@ import android.preference.Preference.OnPreferenceClickListener;
import android.preference.PreferenceScreen;
import android.util.Log;
-import com.actionbarsherlock.app.SherlockPreferenceActivity;
-import com.actionbarsherlock.view.Menu;
-import com.actionbarsherlock.view.MenuItem;
-
+import android.view.Menu;
+import android.view.MenuItem;
import de.danoeh.antennapod.AppConfig;
import de.danoeh.antennapod.R;
import de.danoeh.antennapod.asynctask.FlattrClickWorker;
import de.danoeh.antennapod.asynctask.OpmlExportWorker;
-import de.danoeh.antennapod.feed.FeedManager;
import de.danoeh.antennapod.preferences.UserPreferences;
import de.danoeh.antennapod.util.flattr.FlattrUtils;
-/** The main preference activity */
-public class PreferenceActivity extends SherlockPreferenceActivity {
- private static final String TAG = "PreferenceActivity";
+/**
+ * The main preference activity
+ */
+public class PreferenceActivity extends android.preference.PreferenceActivity {
+ private static final String TAG = "PreferenceActivity";
+
+ private static final String PREF_FLATTR_THIS_APP = "prefFlattrThisApp";
+ private static final String PREF_FLATTR_AUTH = "pref_flattr_authenticate";
+ private static final String PREF_FLATTR_REVOKE = "prefRevokeAccess";
+ private static final String PREF_OPML_EXPORT = "prefOpmlExport";
+ private static final String PREF_ABOUT = "prefAbout";
+ private static final String PREF_CHOOSE_DATA_DIR = "prefChooseDataDir";
+ private static final String AUTO_DL_PREF_SCREEN = "prefAutoDownloadSettings";
- private static final String PREF_FLATTR_THIS_APP = "prefFlattrThisApp";
- private static final String PREF_FLATTR_AUTH = "pref_flattr_authenticate";
- private static final String PREF_FLATTR_REVOKE = "prefRevokeAccess";
- private static final String PREF_OPML_EXPORT = "prefOpmlExport";
- private static final String PREF_ABOUT = "prefAbout";
- private static final String PREF_CHOOSE_DATA_DIR = "prefChooseDataDir";
- private static final String AUTO_DL_PREF_SCREEN = "prefAutoDownloadSettings";
+ private CheckBoxPreference[] selectedNetworks;
- private CheckBoxPreference[] selectedNetworks;
+ @SuppressWarnings("deprecation")
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ setTheme(UserPreferences.getTheme());
+ super.onCreate(savedInstanceState);
- @SuppressWarnings("deprecation")
- @Override
- public void onCreate(Bundle savedInstanceState) {
- setTheme(UserPreferences.getTheme());
- super.onCreate(savedInstanceState);
+ if (android.os.Build.VERSION.SDK_INT >= 11) {
+ getActionBar().setDisplayHomeAsUpEnabled(true);
+ }
- getSupportActionBar().setDisplayHomeAsUpEnabled(true);
addPreferencesFromResource(R.xml.preferences);
findPreference(PREF_FLATTR_THIS_APP).setOnPreferenceClickListener(
new OnPreferenceClickListener() {
- @Override
- public boolean onPreferenceClick(Preference preference) {
- new FlattrClickWorker(PreferenceActivity.this,
- FlattrUtils.APP_URL).executeAsync();
-
- return true;
- }
- });
-
- findPreference(PREF_FLATTR_REVOKE).setOnPreferenceClickListener(
- new OnPreferenceClickListener() {
-
- @Override
- public boolean onPreferenceClick(Preference preference) {
- FlattrUtils.revokeAccessToken(PreferenceActivity.this);
- checkItemVisibility();
- return true;
- }
-
- });
-
- findPreference(PREF_ABOUT).setOnPreferenceClickListener(
- new OnPreferenceClickListener() {
-
- @Override
- public boolean onPreferenceClick(Preference preference) {
- PreferenceActivity.this.startActivity(new Intent(
- PreferenceActivity.this, AboutActivity.class));
- return true;
- }
-
- });
-
- findPreference(PREF_OPML_EXPORT).setOnPreferenceClickListener(
- new OnPreferenceClickListener() {
-
- @Override
- public boolean onPreferenceClick(Preference preference) {
- if (FeedManager.getInstance().getFeedsSize() > 0) {
- new OpmlExportWorker(PreferenceActivity.this)
- .executeAsync();
- }
- return true;
- }
- });
-
- findPreference(PREF_CHOOSE_DATA_DIR).setOnPreferenceClickListener(
- new OnPreferenceClickListener() {
-
- @Override
- public boolean onPreferenceClick(Preference preference) {
- startActivityForResult(
- new Intent(PreferenceActivity.this,
- DirectoryChooserActivity.class),
- DirectoryChooserActivity.RESULT_CODE_DIR_SELECTED);
- return true;
- }
- });
- findPreference(UserPreferences.PREF_THEME)
- .setOnPreferenceChangeListener(
- new OnPreferenceChangeListener() {
-
- @Override
- public boolean onPreferenceChange(
- Preference preference, Object newValue) {
- Intent i = getIntent();
- i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK
- | Intent.FLAG_ACTIVITY_NEW_TASK);
- finish();
- startActivity(i);
- return true;
- }
- });
- findPreference(UserPreferences.PREF_ENABLE_AUTODL_WIFI_FILTER)
- .setOnPreferenceChangeListener(
- new OnPreferenceChangeListener() {
-
- @Override
- public boolean onPreferenceChange(
- Preference preference, Object newValue) {
- if (newValue instanceof Boolean) {
- setSelectedNetworksEnabled((Boolean) newValue);
- return true;
- } else {
- return false;
- }
- }
- });
- findPreference(UserPreferences.PREF_EPISODE_CACHE_SIZE)
- .setOnPreferenceChangeListener(
- new OnPreferenceChangeListener() {
-
- @Override
- public boolean onPreferenceChange(
- Preference preference, Object newValue) {
- if (newValue instanceof String) {
- setEpisodeCacheSizeText(Integer
- .valueOf((String) newValue));
- }
- return true;
- }
- });
- findPreference(UserPreferences.PREF_ENABLE_AUTODL)
- .setOnPreferenceClickListener(new OnPreferenceClickListener() {
-
- @Override
- public boolean onPreferenceClick(Preference preference) {
- checkItemVisibility();
- return true;
- }
- });
- buildUpdateIntervalPreference();
- buildAutodownloadSelectedNetworsPreference();
- setSelectedNetworksEnabled(UserPreferences
- .isEnableAutodownloadWifiFilter());
-
- }
-
- private void buildUpdateIntervalPreference() {
- ListPreference pref = (ListPreference) findPreference(UserPreferences.PREF_UPDATE_INTERVAL);
- String[] values = getResources().getStringArray(
- R.array.update_intervall_values);
- String[] entries = new String[values.length];
- for (int x = 0; x < values.length; x++) {
- Integer v = Integer.parseInt(values[x]);
- switch (v) {
- case 0:
- entries[x] = getString(R.string.pref_update_interval_hours_manual);
- break;
- case 1:
- entries[x] = v
- + " "
- + getString(R.string.pref_update_interval_hours_singular);
- break;
- default:
- entries[x] = v + " "
- + getString(R.string.pref_update_interval_hours_plural);
- break;
-
- }
- }
- pref.setEntries(entries);
-
- }
-
- private void setSelectedNetworksEnabled(boolean b) {
- if (selectedNetworks != null) {
- for (Preference p : selectedNetworks) {
- p.setEnabled(b);
- }
- }
- }
-
- @Override
- protected void onResume() {
- super.onResume();
- checkItemVisibility();
- setEpisodeCacheSizeText(UserPreferences.getEpisodeCacheSize());
- setDataFolderText();
- }
-
- @SuppressWarnings("deprecation")
- private void checkItemVisibility() {
-
- boolean hasFlattrToken = FlattrUtils.hasToken();
-
- findPreference(PREF_FLATTR_AUTH).setEnabled(!hasFlattrToken);
- findPreference(PREF_FLATTR_REVOKE).setEnabled(hasFlattrToken);
-
- findPreference(UserPreferences.PREF_ENABLE_AUTODL_WIFI_FILTER)
- .setEnabled(UserPreferences.isEnableAutodownload());
- setSelectedNetworksEnabled(UserPreferences.isEnableAutodownload()
- && UserPreferences.isEnableAutodownloadWifiFilter());
-
- }
-
- private void setEpisodeCacheSizeText(int cacheSize) {
- String s;
- if (cacheSize == getResources().getInteger(
- R.integer.episode_cache_size_unlimited)) {
- s = getString(R.string.pref_episode_cache_unlimited);
- } else {
- s = Integer.toString(cacheSize)
- + getString(R.string.episodes_suffix);
- }
- findPreference(UserPreferences.PREF_EPISODE_CACHE_SIZE).setSummary(s);
- }
-
- private void setDataFolderText() {
- File f = UserPreferences.getDataFolder(this, null);
- if (f != null) {
- findPreference(PREF_CHOOSE_DATA_DIR)
- .setSummary(f.getAbsolutePath());
- }
- }
-
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- 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);
- startActivity(intent);
- break;
- default:
- return false;
- }
- return true;
- }
-
- @Override
- protected void onApplyThemeResource(Theme theme, int resid, boolean first) {
- theme.applyStyle(UserPreferences.getTheme(), true);
- }
-
- @Override
- protected void onActivityResult(int requestCode, int resultCode, Intent data) {
- super.onActivityResult(requestCode, resultCode, data);
- if (resultCode == DirectoryChooserActivity.RESULT_CODE_DIR_SELECTED) {
- String dir = data
- .getStringExtra(DirectoryChooserActivity.RESULT_SELECTED_DIR);
- if (AppConfig.DEBUG)
- Log.d(TAG, "Setting data folder");
- UserPreferences.setDataFolder(dir);
- }
- }
-
- private void buildAutodownloadSelectedNetworsPreference() {
- if (selectedNetworks != null) {
- clearAutodownloadSelectedNetworsPreference();
- }
- // get configured networks
- WifiManager wifiservice = (WifiManager) getSystemService(Context.WIFI_SERVICE);
- List<WifiConfiguration> networks = wifiservice.getConfiguredNetworks();
-
- if (networks != null) {
- selectedNetworks = new CheckBoxPreference[networks.size()];
- List<String> prefValues = Arrays.asList(UserPreferences
- .getAutodownloadSelectedNetworks());
- PreferenceScreen prefScreen = (PreferenceScreen) findPreference(AUTO_DL_PREF_SCREEN);
- OnPreferenceClickListener clickListener = new OnPreferenceClickListener() {
-
- @Override
- public boolean onPreferenceClick(Preference preference) {
- if (preference instanceof CheckBoxPreference) {
- String key = preference.getKey();
- ArrayList<String> prefValuesList = new ArrayList<String>(
- Arrays.asList(UserPreferences
- .getAutodownloadSelectedNetworks()));
- boolean newValue = ((CheckBoxPreference) preference)
- .isChecked();
- if (AppConfig.DEBUG)
- Log.d(TAG, "Selected network " + key
- + ". New state: " + newValue);
-
- int index = prefValuesList.indexOf(key);
- if (index >= 0 && newValue == false) {
- // remove network
- prefValuesList.remove(index);
- } else if (index < 0 && newValue == true) {
- prefValuesList.add(key);
- }
-
- UserPreferences.setAutodownloadSelectedNetworks(
- PreferenceActivity.this, prefValuesList
- .toArray(new String[prefValuesList
- .size()]));
- return true;
- } else {
- return false;
- }
- }
- };
- // create preference for each known network. attach listener and set
- // value
- for (int i = 0; i < networks.size(); i++) {
- WifiConfiguration config = networks.get(i);
-
- CheckBoxPreference pref = new CheckBoxPreference(this);
- String key = Integer.toString(config.networkId);
- pref.setTitle(config.SSID);
- pref.setKey(key);
- pref.setOnPreferenceClickListener(clickListener);
- pref.setPersistent(false);
- pref.setChecked(prefValues.contains(key));
- selectedNetworks[i] = pref;
- prefScreen.addPreference(pref);
- }
- } else {
- Log.e(TAG, "Couldn't get list of configure Wi-Fi networks");
- }
- }
-
- private void clearAutodownloadSelectedNetworsPreference() {
- if (selectedNetworks != null) {
- PreferenceScreen prefScreen = (PreferenceScreen) findPreference(AUTO_DL_PREF_SCREEN);
-
- for (int i = 0; i < selectedNetworks.length; i++) {
- if (selectedNetworks[i] != null) {
- prefScreen.removePreference(selectedNetworks[i]);
- }
- }
- }
- }
-
- @SuppressWarnings("deprecation")
- @Override
- public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen,
- Preference preference) {
- super.onPreferenceTreeClick(preferenceScreen, preference);
- if (preference != null)
- if (preference instanceof PreferenceScreen)
- if (((PreferenceScreen) preference).getDialog() != null)
- ((PreferenceScreen) preference)
- .getDialog()
- .getWindow()
- .getDecorView()
- .setBackgroundDrawable(
- this.getWindow().getDecorView()
- .getBackground().getConstantState()
- .newDrawable());
- return false;
- }
+ @Override
+ public boolean onPreferenceClick(Preference preference) {
+ new FlattrClickWorker(PreferenceActivity.this,
+ FlattrUtils.APP_URL).executeAsync();
+
+ return true;
+ }
+ });
+
+ findPreference(PREF_FLATTR_REVOKE).setOnPreferenceClickListener(
+ new OnPreferenceClickListener() {
+
+ @Override
+ public boolean onPreferenceClick(Preference preference) {
+ FlattrUtils.revokeAccessToken(PreferenceActivity.this);
+ checkItemVisibility();
+ return true;
+ }
+
+ });
+
+ findPreference(PREF_ABOUT).setOnPreferenceClickListener(
+ new OnPreferenceClickListener() {
+
+ @Override
+ public boolean onPreferenceClick(Preference preference) {
+ PreferenceActivity.this.startActivity(new Intent(
+ PreferenceActivity.this, AboutActivity.class));
+ return true;
+ }
+
+ });
+
+ findPreference(PREF_OPML_EXPORT).setOnPreferenceClickListener(
+ new OnPreferenceClickListener() {
+
+ @Override
+ public boolean onPreferenceClick(Preference preference) {
+ new OpmlExportWorker(PreferenceActivity.this)
+ .executeAsync();
+
+ return true;
+ }
+ });
+
+ findPreference(PREF_CHOOSE_DATA_DIR).setOnPreferenceClickListener(
+ new OnPreferenceClickListener() {
+
+ @Override
+ public boolean onPreferenceClick(Preference preference) {
+ startActivityForResult(
+ new Intent(PreferenceActivity.this,
+ DirectoryChooserActivity.class),
+ DirectoryChooserActivity.RESULT_CODE_DIR_SELECTED);
+ return true;
+ }
+ });
+ findPreference(UserPreferences.PREF_THEME)
+ .setOnPreferenceChangeListener(
+ new OnPreferenceChangeListener() {
+
+ @Override
+ public boolean onPreferenceChange(
+ Preference preference, Object newValue) {
+ Intent i = getIntent();
+ i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK
+ | Intent.FLAG_ACTIVITY_NEW_TASK);
+ finish();
+ startActivity(i);
+ return true;
+ }
+ });
+ findPreference(UserPreferences.PREF_ENABLE_AUTODL_WIFI_FILTER)
+ .setOnPreferenceChangeListener(
+ new OnPreferenceChangeListener() {
+
+ @Override
+ public boolean onPreferenceChange(
+ Preference preference, Object newValue) {
+ if (newValue instanceof Boolean) {
+ setSelectedNetworksEnabled((Boolean) newValue);
+ return true;
+ } else {
+ return false;
+ }
+ }
+ });
+ findPreference(UserPreferences.PREF_EPISODE_CACHE_SIZE)
+ .setOnPreferenceChangeListener(
+ new OnPreferenceChangeListener() {
+
+
+ @Override
+ public boolean onPreferenceChange(Preference preference, Object o) {
+ checkItemVisibility();
+ return true;
+ }
+ });
+ buildUpdateIntervalPreference();
+ buildAutodownloadSelectedNetworsPreference();
+ setSelectedNetworksEnabled(UserPreferences
+ .isEnableAutodownloadWifiFilter());
+
+ }
+
+ private void buildUpdateIntervalPreference() {
+ ListPreference pref = (ListPreference) findPreference(UserPreferences.PREF_UPDATE_INTERVAL);
+ String[] values = getResources().getStringArray(
+ R.array.update_intervall_values);
+ String[] entries = new String[values.length];
+ for (int x = 0; x < values.length; x++) {
+ Integer v = Integer.parseInt(values[x]);
+ switch (v) {
+ case 0:
+ entries[x] = getString(R.string.pref_update_interval_hours_manual);
+ break;
+ case 1:
+ entries[x] = v
+ + " "
+ + getString(R.string.pref_update_interval_hours_singular);
+ break;
+ default:
+ entries[x] = v + " "
+ + getString(R.string.pref_update_interval_hours_plural);
+ break;
+
+ }
+ }
+ pref.setEntries(entries);
+
+ }
+
+ private void setSelectedNetworksEnabled(boolean b) {
+ if (selectedNetworks != null) {
+ for (Preference p : selectedNetworks) {
+ p.setEnabled(b);
+ }
+ }
+ }
+
+ @Override
+ protected void onResume() {
+ super.onResume();
+ checkItemVisibility();
+ setEpisodeCacheSizeText(UserPreferences.getEpisodeCacheSize());
+ setDataFolderText();
+ }
+
+ @SuppressWarnings("deprecation")
+ private void checkItemVisibility() {
+
+ boolean hasFlattrToken = FlattrUtils.hasToken();
+
+ findPreference(PREF_FLATTR_AUTH).setEnabled(!hasFlattrToken);
+ findPreference(PREF_FLATTR_REVOKE).setEnabled(hasFlattrToken);
+
+ findPreference(UserPreferences.PREF_ENABLE_AUTODL_WIFI_FILTER)
+ .setEnabled(UserPreferences.isEnableAutodownload());
+ setSelectedNetworksEnabled(UserPreferences.isEnableAutodownload()
+ && UserPreferences.isEnableAutodownloadWifiFilter());
+
+ }
+
+ private void setEpisodeCacheSizeText(int cacheSize) {
+ String s;
+ if (cacheSize == getResources().getInteger(
+ R.integer.episode_cache_size_unlimited)) {
+ s = getString(R.string.pref_episode_cache_unlimited);
+ } else {
+ s = Integer.toString(cacheSize)
+ + getString(R.string.episodes_suffix);
+ }
+ findPreference(UserPreferences.PREF_EPISODE_CACHE_SIZE).setSummary(s);
+ }
+
+ private void setDataFolderText() {
+ File f = UserPreferences.getDataFolder(this, null);
+ if (f != null) {
+ findPreference(PREF_CHOOSE_DATA_DIR)
+ .setSummary(f.getAbsolutePath());
+ }
+ }
+
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ 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);
+ startActivity(intent);
+ break;
+ default:
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ protected void onApplyThemeResource(Theme theme, int resid, boolean first) {
+ theme.applyStyle(UserPreferences.getTheme(), true);
+ }
+
+ @Override
+ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
+ super.onActivityResult(requestCode, resultCode, data);
+ if (resultCode == DirectoryChooserActivity.RESULT_CODE_DIR_SELECTED) {
+ String dir = data
+ .getStringExtra(DirectoryChooserActivity.RESULT_SELECTED_DIR);
+ if (AppConfig.DEBUG)
+ Log.d(TAG, "Setting data folder");
+ UserPreferences.setDataFolder(dir);
+ }
+ }
+
+ private void buildAutodownloadSelectedNetworsPreference() {
+ if (selectedNetworks != null) {
+ clearAutodownloadSelectedNetworsPreference();
+ }
+ // get configured networks
+ WifiManager wifiservice = (WifiManager) getSystemService(Context.WIFI_SERVICE);
+ List<WifiConfiguration> networks = wifiservice.getConfiguredNetworks();
+
+ if (networks != null) {
+ selectedNetworks = new CheckBoxPreference[networks.size()];
+ List<String> prefValues = Arrays.asList(UserPreferences
+ .getAutodownloadSelectedNetworks());
+ PreferenceScreen prefScreen = (PreferenceScreen) findPreference(AUTO_DL_PREF_SCREEN);
+ OnPreferenceClickListener clickListener = new OnPreferenceClickListener() {
+
+ @Override
+ public boolean onPreferenceClick(Preference preference) {
+ if (preference instanceof CheckBoxPreference) {
+ String key = preference.getKey();
+ ArrayList<String> prefValuesList = new ArrayList<String>(
+ Arrays.asList(UserPreferences
+ .getAutodownloadSelectedNetworks()));
+ boolean newValue = ((CheckBoxPreference) preference)
+ .isChecked();
+ if (AppConfig.DEBUG)
+ Log.d(TAG, "Selected network " + key
+ + ". New state: " + newValue);
+
+ int index = prefValuesList.indexOf(key);
+ if (index >= 0 && newValue == false) {
+ // remove network
+ prefValuesList.remove(index);
+ } else if (index < 0 && newValue == true) {
+ prefValuesList.add(key);
+ }
+
+ UserPreferences.setAutodownloadSelectedNetworks(
+ PreferenceActivity.this, prefValuesList
+ .toArray(new String[prefValuesList
+ .size()]));
+ return true;
+ } else {
+ return false;
+ }
+ }
+ };
+ // create preference for each known network. attach listener and set
+ // value
+ for (int i = 0; i < networks.size(); i++) {
+ WifiConfiguration config = networks.get(i);
+
+ CheckBoxPreference pref = new CheckBoxPreference(this);
+ String key = Integer.toString(config.networkId);
+ pref.setTitle(config.SSID);
+ pref.setKey(key);
+ pref.setOnPreferenceClickListener(clickListener);
+ pref.setPersistent(false);
+ pref.setChecked(prefValues.contains(key));
+ selectedNetworks[i] = pref;
+ prefScreen.addPreference(pref);
+ }
+ } else {
+ Log.e(TAG, "Couldn't get list of configure Wi-Fi networks");
+ }
+ }
+
+ private void clearAutodownloadSelectedNetworsPreference() {
+ if (selectedNetworks != null) {
+ PreferenceScreen prefScreen = (PreferenceScreen) findPreference(AUTO_DL_PREF_SCREEN);
+
+ for (int i = 0; i < selectedNetworks.length; i++) {
+ if (selectedNetworks[i] != null) {
+ prefScreen.removePreference(selectedNetworks[i]);
+ }
+ }
+ }
+ }
+
+ @SuppressWarnings("deprecation")
+ @Override
+ public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen,
+ Preference preference) {
+ super.onPreferenceTreeClick(preferenceScreen, preference);
+ if (preference != null)
+ if (preference instanceof PreferenceScreen)
+ if (((PreferenceScreen) preference).getDialog() != null)
+ ((PreferenceScreen) preference)
+ .getDialog()
+ .getWindow()
+ .getDecorView()
+ .setBackgroundDrawable(
+ this.getWindow().getDecorView()
+ .getBackground().getConstantState()
+ .newDrawable());
+ return false;
+ }
}
diff --git a/src/de/danoeh/antennapod/activity/SearchActivity.java b/src/de/danoeh/antennapod/activity/SearchActivity.java
index 152710112..257ae86ae 100644
--- a/src/de/danoeh/antennapod/activity/SearchActivity.java
+++ b/src/de/danoeh/antennapod/activity/SearchActivity.java
@@ -1,185 +1,195 @@
package de.danoeh.antennapod.activity;
import java.util.ArrayList;
+import java.util.List;
import android.annotation.SuppressLint;
import android.app.SearchManager;
import android.content.Intent;
import android.os.Bundle;
+import android.support.v4.view.MenuItemCompat;
+import android.support.v7.app.ActionBarActivity;
import android.util.Log;
+import android.view.Menu;
+import android.view.MenuItem;
import android.view.View;
+import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.TextView;
-import com.actionbarsherlock.app.SherlockListActivity;
-import com.actionbarsherlock.view.Menu;
-import com.actionbarsherlock.view.MenuItem;
-
import de.danoeh.antennapod.AppConfig;
import de.danoeh.antennapod.R;
import de.danoeh.antennapod.adapter.SearchlistAdapter;
import de.danoeh.antennapod.feed.Feed;
import de.danoeh.antennapod.feed.FeedItem;
-import de.danoeh.antennapod.feed.FeedManager;
-import de.danoeh.antennapod.feed.FeedSearcher;
+import de.danoeh.antennapod.storage.FeedSearcher;
import de.danoeh.antennapod.feed.SearchResult;
import de.danoeh.antennapod.fragment.FeedlistFragment;
import de.danoeh.antennapod.fragment.ItemlistFragment;
import de.danoeh.antennapod.preferences.UserPreferences;
-/** Displays the results when the user searches for FeedItems or Feeds. */
-public class SearchActivity extends SherlockListActivity {
- private static final String TAG = "SearchActivity";
-
- public static final String EXTRA_FEED_ID = "de.danoeh.antennapod.searchactivity.extra.feedId";
-
- private SearchlistAdapter searchAdapter;
- private ArrayList<SearchResult> content;
-
- /** Feed that is being searched or null if the search is global. */
- private Feed selectedFeed;
-
- private TextView txtvStatus;
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- setTheme(UserPreferences.getTheme());
- super.onCreate(savedInstanceState);
-
- getSupportActionBar().setDisplayHomeAsUpEnabled(true);
- setContentView(R.layout.searchlist);
- txtvStatus = (TextView) findViewById(android.R.id.empty);
- }
-
- @Override
- protected void onNewIntent(Intent intent) {
- setIntent(intent);
- }
-
- @Override
- protected void onResume() {
- super.onResume();
- Intent intent = getIntent();
- if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
- Bundle extra = intent.getBundleExtra(SearchManager.APP_DATA);
- if (extra != null) {
- if (AppConfig.DEBUG)
- Log.d(TAG, "Found bundle extra");
- long feedId = extra.getLong(EXTRA_FEED_ID);
- selectedFeed = FeedManager.getInstance().getFeed(feedId);
- }
- if (AppConfig.DEBUG)
- Log.d(TAG, "Starting search");
- String query = intent.getStringExtra(SearchManager.QUERY);
- getSupportActionBar()
- .setSubtitle(
- getString(R.string.search_term_label) + "\""
- + query + "\"");
- handleSearchRequest(query);
- }
- }
-
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- menu.add(Menu.NONE, R.id.search_item, Menu.NONE, R.string.search_label)
- .setIcon(
- obtainStyledAttributes(
- new int[] { R.attr.action_search })
- .getDrawable(0))
- .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);
- startActivity(intent);
- return true;
- case R.id.search_item:
- onSearchRequested();
- return true;
- default:
- return false;
- }
- }
-
- @Override
- public boolean onSearchRequested() {
- Bundle extra = null;
- if (selectedFeed != null) {
- extra = new Bundle();
- extra.putLong(EXTRA_FEED_ID, selectedFeed.getId());
- }
- startSearch(null, false, extra, false);
- return true;
- }
-
- @Override
- protected void onListItemClick(ListView l, View v, int position, long id) {
- super.onListItemClick(l, v, position, id);
- SearchResult selection = searchAdapter.getItem(position);
- if (selection.getComponent().getClass() == Feed.class) {
- Feed feed = (Feed) selection.getComponent();
- Intent launchIntent = new Intent(this, FeedItemlistActivity.class);
- launchIntent.putExtra(FeedlistFragment.EXTRA_SELECTED_FEED,
- feed.getId());
- startActivity(launchIntent);
-
- } else if (selection.getComponent().getClass() == FeedItem.class) {
- FeedItem item = (FeedItem) selection.getComponent();
- Intent launchIntent = new Intent(this, ItemviewActivity.class);
- launchIntent.putExtra(FeedlistFragment.EXTRA_SELECTED_FEED, item
- .getFeed().getId());
- launchIntent.putExtra(ItemlistFragment.EXTRA_SELECTED_FEEDITEM,
- item.getId());
- startActivity(launchIntent);
- }
- }
-
- @SuppressLint({ "NewApi", "NewApi" })
- private void handleSearchRequest(final String query) {
- if (searchAdapter != null) {
- searchAdapter.clear();
- searchAdapter.notifyDataSetChanged();
- }
- txtvStatus.setText(R.string.search_status_searching);
-
- Thread thread = new Thread() {
-
- @Override
- public void run() {
- Log.d(TAG, "Starting background work");
- final ArrayList<SearchResult> result = FeedSearcher
- .performSearch(SearchActivity.this, query, selectedFeed);
- if (SearchActivity.this != null) {
- SearchActivity.this.runOnUiThread(new Runnable() {
-
- @Override
- public void run() {
- if (AppConfig.DEBUG)
- Log.d(TAG, "Background work finished");
- if (AppConfig.DEBUG)
- Log.d(TAG, "Found " + result.size()
- + " results");
- content = result;
-
- searchAdapter = new SearchlistAdapter(
- SearchActivity.this, 0, content);
- getListView().setAdapter(searchAdapter);
- searchAdapter.notifyDataSetChanged();
- if (content.isEmpty()) {
- txtvStatus
- .setText(R.string.search_status_no_results);
- }
- }
- });
- }
- }
- };
- thread.start();
-
- }
+/**
+ * Displays the results when the user searches for FeedItems or Feeds.
+ */
+public class SearchActivity extends ActionBarActivity implements AdapterView.OnItemClickListener {
+ private static final String TAG = "SearchActivity";
+
+ public static final String EXTRA_FEED_ID = "de.danoeh.antennapod.searchactivity.extra.feedId";
+
+ private SearchlistAdapter searchAdapter;
+
+ /**
+ * ID of the feed that is being searched or null if the search is global.
+ */
+ private long feedID;
+
+ private ListView listView;
+ private TextView txtvStatus;
+
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ setTheme(UserPreferences.getTheme());
+ super.onCreate(savedInstanceState);
+
+ getSupportActionBar().setDisplayHomeAsUpEnabled(true);
+ setContentView(R.layout.searchlist);
+ listView = (ListView) findViewById(android.R.id.list);
+ txtvStatus = (TextView) findViewById(android.R.id.empty);
+
+ listView.setOnItemClickListener(this);
+ searchAdapter = new SearchlistAdapter(this, 0, new ArrayList<SearchResult>());
+ listView.setAdapter(searchAdapter);
+ listView.setEmptyView(txtvStatus);
+ }
+
+ @Override
+ protected void onNewIntent(Intent intent) {
+ setIntent(intent);
+ }
+
+ @Override
+ protected void onResume() {
+ super.onResume();
+ Intent intent = getIntent();
+ if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
+ if (intent.hasExtra(SearchActivity.EXTRA_FEED_ID)) {
+ if (AppConfig.DEBUG)
+ Log.d(TAG, "Found bundle extra");
+ feedID = intent.getLongExtra(SearchActivity.EXTRA_FEED_ID, 0);
+ }
+ if (AppConfig.DEBUG)
+ Log.d(TAG, "Starting search");
+ String query = intent.getStringExtra(SearchManager.QUERY);
+ getSupportActionBar()
+ .setSubtitle(
+ getString(R.string.search_term_label) + "\""
+ + query + "\"");
+ handleSearchRequest(query);
+ }
+ }
+
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ MenuItemCompat.setShowAsAction(menu.add(Menu.NONE, R.id.search_item, Menu.NONE, R.string.search_label)
+ .setIcon(
+ obtainStyledAttributes(
+ new int[]{R.attr.action_search})
+ .getDrawable(0)),
+ (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);
+ startActivity(intent);
+ return true;
+ case R.id.search_item:
+ onSearchRequested();
+ return true;
+ default:
+ return false;
+ }
+ }
+
+ @Override
+ public boolean onSearchRequested() {
+ Bundle extra = null;
+ if (feedID != 0) {
+ extra = new Bundle();
+ extra.putLong(EXTRA_FEED_ID, feedID);
+ }
+ startSearch(null, false, extra, false);
+ return true;
+ }
+
+ @SuppressLint({"NewApi", "NewApi"})
+ private void handleSearchRequest(final String query) {
+ if (searchAdapter != null) {
+ searchAdapter.clear();
+ searchAdapter.notifyDataSetChanged();
+ }
+ txtvStatus.setText(R.string.search_status_searching);
+
+ Thread thread = new Thread() {
+
+ @Override
+ public void run() {
+ Log.d(TAG, "Starting background work");
+ final List<SearchResult> result = FeedSearcher
+ .performSearch(SearchActivity.this, query, feedID);
+ if (SearchActivity.this != null) {
+ SearchActivity.this.runOnUiThread(new Runnable() {
+
+ @Override
+ public void run() {
+ if (AppConfig.DEBUG)
+ Log.d(TAG, "Background work finished");
+ if (AppConfig.DEBUG)
+ Log.d(TAG, "Found " + result.size()
+ + " results");
+
+ searchAdapter.clear();
+ searchAdapter.addAll(result);
+ searchAdapter.notifyDataSetChanged();
+ txtvStatus
+ .setText(R.string.search_status_no_results);
+ if (!searchAdapter.isEmpty()) {
+ txtvStatus.setVisibility(View.GONE);
+ } else {
+ txtvStatus.setVisibility(View.VISIBLE);
+ }
+ }
+ });
+ }
+ }
+ };
+ thread.start();
+
+ }
+
+ @Override
+ public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
+ SearchResult selection = searchAdapter.getItem(position);
+ if (selection.getComponent().getClass() == Feed.class) {
+ Feed feed = (Feed) selection.getComponent();
+ Intent launchIntent = new Intent(this, FeedItemlistActivity.class);
+ launchIntent.putExtra(FeedlistFragment.EXTRA_SELECTED_FEED,
+ feed.getId());
+ startActivity(launchIntent);
+
+ } else if (selection.getComponent().getClass() == FeedItem.class) {
+ FeedItem item = (FeedItem) selection.getComponent();
+ Intent launchIntent = new Intent(this, ItemviewActivity.class);
+ launchIntent.putExtra(FeedlistFragment.EXTRA_SELECTED_FEED, item
+ .getFeed().getId());
+ launchIntent.putExtra(ItemlistFragment.EXTRA_SELECTED_FEEDITEM,
+ item.getId());
+ startActivity(launchIntent);
+ }
+ }
}
diff --git a/src/de/danoeh/antennapod/activity/StorageErrorActivity.java b/src/de/danoeh/antennapod/activity/StorageErrorActivity.java
index 4d9184dcf..33277ebc9 100644
--- a/src/de/danoeh/antennapod/activity/StorageErrorActivity.java
+++ b/src/de/danoeh/antennapod/activity/StorageErrorActivity.java
@@ -5,17 +5,16 @@ import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
+import android.support.v7.app.ActionBarActivity;
import android.util.Log;
-import com.actionbarsherlock.app.SherlockActivity;
-
import de.danoeh.antennapod.AppConfig;
import de.danoeh.antennapod.R;
import de.danoeh.antennapod.preferences.UserPreferences;
import de.danoeh.antennapod.util.StorageUtils;
/** Is show if there is now external storage available. */
-public class StorageErrorActivity extends SherlockActivity {
+public class StorageErrorActivity extends ActionBarActivity {
private static final String TAG = "StorageErrorActivity";
@Override
diff --git a/src/de/danoeh/antennapod/activity/VideoplayerActivity.java b/src/de/danoeh/antennapod/activity/VideoplayerActivity.java
index b3567e417..01841f099 100644
--- a/src/de/danoeh/antennapod/activity/VideoplayerActivity.java
+++ b/src/de/danoeh/antennapod/activity/VideoplayerActivity.java
@@ -5,18 +5,13 @@ import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
-import android.view.MotionEvent;
-import android.view.SurfaceHolder;
-import android.view.View;
-import android.view.WindowManager;
+import android.view.*;
import android.view.animation.AnimationUtils;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.SeekBar;
import android.widget.VideoView;
-import com.actionbarsherlock.view.Window;
-
import de.danoeh.antennapod.AppConfig;
import de.danoeh.antennapod.R;
import de.danoeh.antennapod.feed.MediaType;