improved stability

This commit is contained in:
daniel oeh 2012-07-23 20:41:43 +02:00
parent dcddf476bf
commit f910b057bc
9 changed files with 88 additions and 91 deletions

View File

@ -45,7 +45,8 @@ public class DownloadObserver extends AsyncTask<Void, Void, Void> {
@Override
protected void onCancelled() {
if (AppConfig.DEBUG) Log.d(TAG, "Task was cancelled.");
if (AppConfig.DEBUG)
Log.d(TAG, "Task was cancelled.");
statusList.clear();
for (DownloadObserver.Callback callback : observer) {
callback.onFinish();
@ -54,7 +55,8 @@ public class DownloadObserver extends AsyncTask<Void, Void, Void> {
@Override
protected void onPostExecute(Void result) {
if (AppConfig.DEBUG) Log.d(TAG, "Background task has finished");
if (AppConfig.DEBUG)
Log.d(TAG, "Background task has finished");
statusList.clear();
for (DownloadObserver.Callback callback : observer) {
callback.onFinish();
@ -62,7 +64,8 @@ public class DownloadObserver extends AsyncTask<Void, Void, Void> {
}
protected Void doInBackground(Void... params) {
if (AppConfig.DEBUG) Log.d(TAG, "Background Task started.");
if (AppConfig.DEBUG)
Log.d(TAG, "Background Task started.");
while (downloadsLeft() && !isCancelled()) {
refreshStatuslist();
publishProgress();
@ -72,7 +75,8 @@ public class DownloadObserver extends AsyncTask<Void, Void, Void> {
Log.w(TAG, "Thread was interrupted while waiting.");
}
}
if (AppConfig.DEBUG) Log.d(TAG, "Background Task finished.");
if (AppConfig.DEBUG)
Log.d(TAG, "Background Task finished.");
return null;
}
@ -144,13 +148,17 @@ public class DownloadObserver extends AsyncTask<Void, Void, Void> {
/** Request a cursor with all running Feedfile downloads */
private Cursor getDownloadCursor() {
// Collect download ids
int numDownloads = requester.getNumberOfDownloads();
long ids[] = new long[numDownloads];
for (int i = 0; i < numDownloads; i++) {
ids[i] = requester.getDownloadAt(i).getDownloadId();
ArrayList<Long> ids = new ArrayList<Long>();
for (FeedFile download : requester.getDownloads()) {
ids.add(download.getDownloadId());
}
DownloadManager.Query query = new DownloadManager.Query();
query.setFilterById(ids);
long[] pIds = new long[ids.size()];
for (int x = 0; x < ids.size(); x++) {
pIds[x] = ids.get(x);
}
query.setFilterById(pIds);
DownloadManager manager = (DownloadManager) context
.getSystemService(Context.DOWNLOAD_SERVICE);

View File

@ -4,6 +4,7 @@ import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import de.danoeh.antennapod.AppConfig;
import de.danoeh.antennapod.activity.MediaplayerActivity;
@ -36,27 +37,27 @@ public class FeedManager {
private static FeedManager singleton;
private ArrayList<Feed> feeds;
private List<Feed> feeds;
private ArrayList<FeedCategory> categories;
/** Contains all items where 'read' is false */
private ArrayList<FeedItem> unreadItems;
private List<FeedItem> unreadItems;
/** Contains completed Download status entries */
private ArrayList<DownloadStatus> downloadLog;
/** Contains the queue of items to be played. */
private ArrayList<FeedItem> queue;
private List<FeedItem> queue;
private DownloadRequester requester;
private FeedManager() {
feeds = new ArrayList<Feed>();
feeds = Collections.synchronizedList(new ArrayList<Feed>());
categories = new ArrayList<FeedCategory>();
unreadItems = new ArrayList<FeedItem>();
unreadItems = Collections.synchronizedList(new ArrayList<FeedItem>());
requester = DownloadRequester.getInstance();
downloadLog = new ArrayList<DownloadStatus>();
queue = new ArrayList<FeedItem>();
queue = Collections.synchronizedList(new ArrayList<FeedItem>());
}
public static FeedManager getInstance() {
@ -740,11 +741,11 @@ public class FeedManager {
cursor.close();
}
public ArrayList<Feed> getFeeds() {
public List<Feed> getFeeds() {
return feeds;
}
public ArrayList<FeedItem> getUnreadItems() {
public List<FeedItem> getUnreadItems() {
return unreadItems;
}
@ -752,7 +753,7 @@ public class FeedManager {
return downloadLog;
}
public ArrayList<FeedItem> getQueue() {
public List<FeedItem> getQueue() {
return queue;
}

View File

@ -11,6 +11,7 @@ import de.danoeh.antennapod.AppConfig;
import de.danoeh.antennapod.R;
import android.os.AsyncTask;
import android.os.Bundle;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.view.View;
import android.view.ViewGroup;
@ -54,12 +55,11 @@ public class FeedlistFragment extends SherlockListFragment implements
pActivity = null;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (AppConfig.DEBUG) Log.d(TAG, "Creating");
if (AppConfig.DEBUG)
Log.d(TAG, "Creating");
manager = FeedManager.getInstance();
fla = new FeedlistAdapter(pActivity, 0, manager.getFeeds());
setListAdapter(fla);
@ -82,7 +82,9 @@ public class FeedlistFragment extends SherlockListFragment implements
public boolean onItemLongClick(AdapterView<?> parent, View view,
int position, long id) {
Feed selection = fla.getItem(position);
if (AppConfig.DEBUG) Log.d(TAG, "Selected Feed with title " + selection.getTitle());
if (AppConfig.DEBUG)
Log.d(TAG,
"Selected Feed with title " + selection.getTitle());
if (selection != null) {
if (mActionMode != null) {
mActionMode.finish();
@ -102,6 +104,7 @@ public class FeedlistFragment extends SherlockListFragment implements
@Override
public void onResume() {
super.onResume();
if (AppConfig.DEBUG) Log.d(TAG, "Resuming");
IntentFilter filter = new IntentFilter();
filter.addAction(DownloadService.ACTION_DOWNLOAD_HANDLED);
filter.addAction(DownloadService.ACTION_FEED_SYNC_COMPLETED);
@ -124,8 +127,16 @@ public class FeedlistFragment extends SherlockListFragment implements
private BroadcastReceiver contentUpdate = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if (AppConfig.DEBUG) Log.d(TAG, "Received contentUpdate Intent.");
fla.notifyDataSetChanged();
if (AppConfig.DEBUG)
Log.d(TAG, "Received contentUpdate Intent.");
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
fla.notifyDataSetChanged();
}
});
}
};
@ -150,6 +161,7 @@ public class FeedlistFragment extends SherlockListFragment implements
return FeedMenuHandler.onPrepareOptionsMenu(menu, selectedFeed);
}
@SuppressLint("NewApi")
@Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
if (FeedMenuHandler.onOptionsItemClicked(getSherlockActivity(), item,
@ -166,7 +178,8 @@ public class FeedlistFragment extends SherlockListFragment implements
}
};
if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.GINGERBREAD_MR1) {
remover.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, selectedFeed);
remover.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR,
selectedFeed);
} else {
remover.execute(selectedFeed);
}
@ -183,5 +196,5 @@ public class FeedlistFragment extends SherlockListFragment implements
selectedFeed = null;
fla.setSelectedItemIndex(FeedlistAdapter.SELECTION_NONE);
}
}

View File

@ -1,6 +1,7 @@
package de.danoeh.antennapod.fragment;
import java.util.ArrayList;
import java.util.List;
import android.content.BroadcastReceiver;
import android.content.Context;
@ -43,7 +44,7 @@ public class ItemlistFragment extends SherlockListFragment implements
protected DownloadRequester requester;
/** The feed which the activity displays */
protected ArrayList<FeedItem> items;
protected List<FeedItem> items;
/**
* This is only not null if the fragment displays the items of a specific
* feed
@ -56,7 +57,7 @@ public class ItemlistFragment extends SherlockListFragment implements
/** Argument for FeeditemlistAdapter */
protected boolean showFeedtitle;
public ItemlistFragment(ArrayList<FeedItem> items, boolean showFeedtitle) {
public ItemlistFragment(List<FeedItem> items, boolean showFeedtitle) {
super();
this.items = items;
this.showFeedtitle = showFeedtitle;
@ -102,26 +103,37 @@ public class ItemlistFragment extends SherlockListFragment implements
onButActionClicked, showFeedtitle);
setListAdapter(fila);
}
@Override
public void onPause() {
super.onPause();
getActivity().unregisterReceiver(contentUpdate);
if (mActionMode != null) {
mActionMode.finish();
}
}
@Override
public void onDestroy() {
super.onDestroy();
getActivity().unregisterReceiver(contentUpdate);
}
@Override
public void onResume() {
super.onResume();
fila.notifyDataSetChanged();
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
fila.notifyDataSetChanged();
}
});
updateProgressBarVisibility();
IntentFilter filter = new IntentFilter();
filter.addAction(DownloadService.ACTION_DOWNLOAD_HANDLED);
filter.addAction(DownloadRequester.ACTION_DOWNLOAD_QUEUED);
filter.addAction(FeedManager.ACTION_QUEUE_UPDATE);
filter.addAction(FeedManager.ACTION_UNREAD_ITEMS_UPDATE);
getActivity().registerReceiver(contentUpdate, filter);
}
@ -140,9 +152,17 @@ public class ItemlistFragment extends SherlockListFragment implements
private BroadcastReceiver contentUpdate = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if (AppConfig.DEBUG) Log.d(TAG, "Received contentUpdate Intent.");
fila.notifyDataSetChanged();
updateProgressBarVisibility();
if (AppConfig.DEBUG)
Log.d(TAG, "Received contentUpdate Intent.");
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
fila.notifyDataSetChanged();
updateProgressBarVisibility();
}
});
}
};

View File

@ -30,23 +30,6 @@ public class QueueFragment extends ItemlistFragment {
return true;
}
@Override
public void onPause() {
super.onPause();
try {
getActivity().unregisterReceiver(queueUpdate);
} catch (IllegalArgumentException e) {
}
}
@Override
public void onResume() {
super.onResume();
getActivity().registerReceiver(queueUpdate,
new IntentFilter(FeedManager.ACTION_QUEUE_UPDATE));
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -73,15 +56,6 @@ public class QueueFragment extends ItemlistFragment {
return handled;
}
private BroadcastReceiver queueUpdate = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
fila.notifyDataSetChanged();
}
};
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
super.onCreateOptionsMenu(menu, inflater);

View File

@ -20,38 +20,12 @@ public class UnreadItemlistFragment extends ItemlistFragment {
}
@Override
public void onPause() {
super.onPause();
try {
getActivity().unregisterReceiver(unreadItemsUpdate);
} catch (IllegalArgumentException e) {
}
}
@Override
public void onResume() {
super.onResume();
getActivity().registerReceiver(unreadItemsUpdate,
new IntentFilter(FeedManager.ACTION_UNREAD_ITEMS_UPDATE));
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setHasOptionsMenu(true);
}
private BroadcastReceiver unreadItemsUpdate = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
fila.notifyDataSetChanged();
}
};
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
super.onCreateOptionsMenu(menu, inflater);

View File

@ -420,6 +420,12 @@ public class DownloadService extends Service {
reason, successful));
sendDownloadHandledIntent(downloadId, statusId, hasImage, imageId);
queryDownloads();
try {
Thread.sleep(100);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/** Delete files that aren't needed anymore */

View File

@ -1,6 +1,7 @@
package de.danoeh.antennapod.storage;
import java.util.ArrayList;
import java.util.List;
import de.danoeh.antennapod.AppConfig;
import de.danoeh.antennapod.asynctask.DownloadStatus;
@ -397,7 +398,7 @@ public class PodDBAdapter {
return status.getId();
}
public void setQueue(ArrayList<FeedItem> queue) {
public void setQueue(List<FeedItem> queue) {
ContentValues values = new ContentValues();
db.delete(TABLE_NAME_QUEUE, null, null);
for (int i = 0; i < queue.size(); i++) {

View File

@ -21,7 +21,7 @@ public final class URLChecker {
* @param url The url which is going to be prepared
* @return The prepared url
* */
public static String prepareURL(final String url) {
public static String prepareURL(String url) {
StringBuilder builder = new StringBuilder();
if (!url.startsWith("http")) {
@ -29,7 +29,7 @@ public final class URLChecker {
if (AppConfig.DEBUG) Log.d(TAG, "Missing http; appending");
} else if (url.startsWith("https")) {
if (AppConfig.DEBUG) Log.d(TAG, "Replacing https with http");
url.replaceFirst("https", "http");
url = url.replaceFirst("https", "http");
}
builder.append(url);