Changes in ItemlistFragment + improved application startup time
This commit is contained in:
parent
b283eae1b9
commit
3e0937df7d
|
@ -16,7 +16,7 @@ import de.podfetcher.R;
|
|||
import de.podfetcher.asynctask.FeedRemover;
|
||||
import de.podfetcher.feed.Feed;
|
||||
import de.podfetcher.feed.FeedManager;
|
||||
import de.podfetcher.fragment.FeedItemlistFragment;
|
||||
import de.podfetcher.fragment.ItemlistFragment;
|
||||
import de.podfetcher.fragment.FeedlistFragment;
|
||||
import de.podfetcher.util.FeedMenuHandler;
|
||||
|
||||
|
@ -28,7 +28,7 @@ public class FeedItemlistActivity extends SherlockFragmentActivity {
|
|||
|
||||
/** The feed which the activity displays */
|
||||
private Feed feed;
|
||||
private FeedItemlistFragment filf;
|
||||
private ItemlistFragment filf;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
|
@ -44,7 +44,8 @@ public class FeedItemlistActivity extends SherlockFragmentActivity {
|
|||
|
||||
FragmentManager fragmentManager = getSupportFragmentManager();
|
||||
FragmentTransaction fT = fragmentManager.beginTransaction();
|
||||
filf = new FeedItemlistFragment(feed.getItems());
|
||||
|
||||
filf = ItemlistFragment.newInstance(feed.getId());
|
||||
fT.add(R.id.feeditemlistFragment, filf);
|
||||
fT.commit();
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ import de.podfetcher.feed.Feed;
|
|||
import de.podfetcher.feed.FeedItem;
|
||||
import de.podfetcher.feed.FeedManager;
|
||||
import de.podfetcher.feed.FeedMedia;
|
||||
import de.podfetcher.fragment.FeedItemlistFragment;
|
||||
import de.podfetcher.fragment.ItemlistFragment;
|
||||
import de.podfetcher.fragment.FeedlistFragment;
|
||||
import de.podfetcher.service.PlaybackService;
|
||||
import de.podfetcher.storage.DownloadRequester;
|
||||
|
@ -62,7 +62,7 @@ public class ItemviewActivity extends SherlockActivity {
|
|||
/** Extracts FeedItem object the activity is supposed to display */
|
||||
private void extractFeeditem() {
|
||||
long itemId = getIntent().getLongExtra(
|
||||
FeedItemlistFragment.EXTRA_SELECTED_FEEDITEM, -1);
|
||||
ItemlistFragment.EXTRA_SELECTED_FEEDITEM, -1);
|
||||
long feedId = getIntent().getLongExtra(
|
||||
FeedlistFragment.EXTRA_SELECTED_FEED, -1);
|
||||
if (itemId == -1 || feedId == -1) {
|
||||
|
|
|
@ -18,7 +18,7 @@ import com.actionbarsherlock.view.MenuItem;
|
|||
|
||||
import de.podfetcher.R;
|
||||
import de.podfetcher.feed.FeedManager;
|
||||
import de.podfetcher.fragment.FeedItemlistFragment;
|
||||
import de.podfetcher.fragment.ItemlistFragment;
|
||||
import de.podfetcher.fragment.FeedlistFragment;
|
||||
import de.podfetcher.fragment.QueueFragment;
|
||||
import de.podfetcher.fragment.UnreadItemlistFragment;
|
||||
|
@ -29,7 +29,7 @@ public class PodfetcherActivity extends SherlockFragmentActivity {
|
|||
private FeedManager manager;
|
||||
|
||||
private FeedlistFragment feedlist;
|
||||
FeedItemlistFragment unreadList;
|
||||
ItemlistFragment unreadList;
|
||||
|
||||
|
||||
@Override
|
||||
|
|
|
@ -11,6 +11,7 @@ import de.podfetcher.storage.*;
|
|||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.database.Cursor;
|
||||
import android.os.Debug;
|
||||
import android.util.Log;
|
||||
|
||||
/**
|
||||
|
@ -349,14 +350,16 @@ public class FeedManager {
|
|||
public void updateArrays(Context context) {
|
||||
feeds.clear();
|
||||
categories.clear();
|
||||
extractFeedlistFromCursor(context);
|
||||
extractDownloadLogFromCursor(context);
|
||||
extractQueueFromCursor(context);
|
||||
}
|
||||
|
||||
private void extractFeedlistFromCursor(Context context) {
|
||||
PodDBAdapter adapter = new PodDBAdapter(context);
|
||||
adapter.open();
|
||||
extractFeedlistFromCursor(context, adapter);
|
||||
extractDownloadLogFromCursor(context, adapter);
|
||||
extractQueueFromCursor(context, adapter);
|
||||
adapter.close();
|
||||
}
|
||||
|
||||
private void extractFeedlistFromCursor(Context context, PodDBAdapter adapter) {
|
||||
|
||||
Cursor feedlistCursor = adapter.getAllFeedsCursor();
|
||||
if (feedlistCursor.moveToFirst()) {
|
||||
do {
|
||||
|
@ -385,19 +388,17 @@ public class FeedManager {
|
|||
// Get FeedItem-Object
|
||||
Cursor itemlistCursor = adapter.getAllItemsOfFeedCursor(feed);
|
||||
feed.setItems(extractFeedItemsFromCursor(context, feed,
|
||||
itemlistCursor));
|
||||
itemlistCursor, adapter));
|
||||
|
||||
feeds.add(feed);
|
||||
} while (feedlistCursor.moveToNext());
|
||||
}
|
||||
adapter.close();
|
||||
|
||||
}
|
||||
|
||||
private ArrayList<FeedItem> extractFeedItemsFromCursor(Context context,
|
||||
Feed feed, Cursor itemlistCursor) {
|
||||
Feed feed, Cursor itemlistCursor, PodDBAdapter adapter) {
|
||||
ArrayList<FeedItem> items = new ArrayList<FeedItem>();
|
||||
PodDBAdapter adapter = new PodDBAdapter(context);
|
||||
adapter.open();
|
||||
if (itemlistCursor.moveToFirst()) {
|
||||
do {
|
||||
FeedItem item = new FeedItem();
|
||||
|
@ -429,13 +430,10 @@ public class FeedManager {
|
|||
items.add(item);
|
||||
} while (itemlistCursor.moveToNext());
|
||||
}
|
||||
adapter.close();
|
||||
return items;
|
||||
}
|
||||
|
||||
private void extractDownloadLogFromCursor(Context context) {
|
||||
PodDBAdapter adapter = new PodDBAdapter(context);
|
||||
adapter.open();
|
||||
private void extractDownloadLogFromCursor(Context context, PodDBAdapter adapter) {
|
||||
Cursor logCursor = adapter.getDownloadLogCursor();
|
||||
if (logCursor.moveToFirst()) {
|
||||
do {
|
||||
|
@ -468,13 +466,10 @@ public class FeedManager {
|
|||
}
|
||||
|
||||
} while (logCursor.moveToNext());
|
||||
}
|
||||
adapter.close();
|
||||
}
|
||||
}
|
||||
|
||||
private void extractQueueFromCursor(Context context) {
|
||||
PodDBAdapter adapter = new PodDBAdapter(context);
|
||||
adapter.open();
|
||||
private void extractQueueFromCursor(Context context, PodDBAdapter adapter) {
|
||||
Cursor cursor = adapter.getQueueCursor();
|
||||
if (cursor.moveToFirst()) {
|
||||
do {
|
||||
|
@ -487,7 +482,6 @@ public class FeedManager {
|
|||
queue.add(index, item);
|
||||
} while (cursor.moveToNext());
|
||||
}
|
||||
adapter.close();
|
||||
}
|
||||
|
||||
public ArrayList<Feed> getFeeds() {
|
||||
|
|
|
@ -23,8 +23,9 @@ import de.podfetcher.feed.FeedManager;
|
|||
import de.podfetcher.storage.DownloadRequester;
|
||||
import de.podfetcher.util.FeedItemMenuHandler;
|
||||
|
||||
public class FeedItemlistFragment extends SherlockListFragment {
|
||||
|
||||
/** Displays a list of FeedItems. */
|
||||
public class ItemlistFragment extends SherlockListFragment {
|
||||
|
||||
@Override
|
||||
public void onViewCreated(View view, Bundle savedInstanceState) {
|
||||
this.getListView().setItemsCanFocus(true);
|
||||
|
@ -32,7 +33,7 @@ public class FeedItemlistFragment extends SherlockListFragment {
|
|||
|
||||
private static final String TAG = "FeedItemlistFragment";
|
||||
public static final String EXTRA_SELECTED_FEEDITEM = "extra.de.podfetcher.activity.selected_feeditem";
|
||||
|
||||
public static final String ARGUMENT_FEED_ID = "argument.de.podfetcher.feed_id";
|
||||
protected FeedItemlistAdapter fila;
|
||||
protected FeedManager manager;
|
||||
protected DownloadRequester requester;
|
||||
|
@ -43,16 +44,31 @@ public class FeedItemlistFragment extends SherlockListFragment {
|
|||
protected FeedItem selectedItem;
|
||||
protected ActionMode mActionMode;
|
||||
|
||||
public FeedItemlistFragment(ArrayList<FeedItem> items) {
|
||||
public ItemlistFragment(ArrayList<FeedItem> items) {
|
||||
super();
|
||||
this.items = items;
|
||||
manager = FeedManager.getInstance();
|
||||
requester = DownloadRequester.getInstance();
|
||||
}
|
||||
|
||||
public ItemlistFragment() {
|
||||
}
|
||||
|
||||
public static ItemlistFragment newInstance(long feedId) {
|
||||
ItemlistFragment i = new ItemlistFragment();
|
||||
Bundle b = new Bundle();
|
||||
b.putLong(ARGUMENT_FEED_ID, feedId);
|
||||
i.setArguments(b);
|
||||
return i;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
if (items == null) {
|
||||
long feedId = getArguments().getLong(ARGUMENT_FEED_ID);
|
||||
items = FeedManager.getInstance().getFeed(feedId).getItems();
|
||||
}
|
||||
fila = new FeedItemlistAdapter(getActivity(), 0, items,
|
||||
onButActionClicked);
|
||||
setListAdapter(fila);
|
|
@ -2,7 +2,7 @@ package de.podfetcher.fragment;
|
|||
|
||||
import de.podfetcher.feed.FeedManager;
|
||||
|
||||
public class QueueFragment extends FeedItemlistFragment {
|
||||
public class QueueFragment extends ItemlistFragment {
|
||||
|
||||
public QueueFragment() {
|
||||
super(FeedManager.getInstance().getQueue());
|
||||
|
|
|
@ -3,7 +3,7 @@ package de.podfetcher.fragment;
|
|||
import de.podfetcher.feed.FeedManager;
|
||||
|
||||
/** Contains all unread items. */
|
||||
public class UnreadItemlistFragment extends FeedItemlistFragment {
|
||||
public class UnreadItemlistFragment extends ItemlistFragment {
|
||||
|
||||
public UnreadItemlistFragment() {
|
||||
super(FeedManager.getInstance().getUnreadItems());
|
||||
|
|
|
@ -21,7 +21,7 @@ import android.util.Log;
|
|||
* Implements methods for accessing the database
|
||||
* */
|
||||
public class PodDBAdapter {
|
||||
|
||||
private static final String TAG = "PodDBAdapter";
|
||||
private static final int DATABASE_VERSION = 1;
|
||||
private static final String DATABASE_NAME = "Podfetcher.db";
|
||||
|
||||
|
@ -124,6 +124,7 @@ public class PodDBAdapter {
|
|||
|
||||
public PodDBAdapter open() {
|
||||
if (db == null || !db.isOpen() || db.isReadOnly()) {
|
||||
Log.d(TAG, "Opening DB");
|
||||
try {
|
||||
db = helper.getWritableDatabase();
|
||||
} catch (SQLException ex) {
|
||||
|
@ -135,6 +136,7 @@ public class PodDBAdapter {
|
|||
}
|
||||
|
||||
public void close() {
|
||||
Log.d(TAG, "Closing DB");
|
||||
db.close();
|
||||
}
|
||||
|
||||
|
@ -457,7 +459,6 @@ public class PodDBAdapter {
|
|||
* */
|
||||
public final FeedMedia getFeedMedia(final long rowIndex,
|
||||
final FeedItem owner) throws SQLException {
|
||||
open();
|
||||
Cursor cursor = db.query(TABLE_NAME_FEED_MEDIA, null, KEY_ID + "=?",
|
||||
new String[] { String.valueOf(rowIndex) }, null, null, null);
|
||||
if ((cursor.getCount() == 0) || !cursor.moveToFirst()) {
|
||||
|
@ -471,7 +472,6 @@ public class PodDBAdapter {
|
|||
.getColumnIndex(KEY_FILE_URL)), cursor.getString(cursor
|
||||
.getColumnIndex(KEY_DOWNLOAD_URL)), cursor.getInt(cursor
|
||||
.getColumnIndex(KEY_DOWNLOADED)) > 0);
|
||||
close();
|
||||
return media;
|
||||
}
|
||||
|
||||
|
@ -483,7 +483,6 @@ public class PodDBAdapter {
|
|||
* @return The found object
|
||||
* */
|
||||
public final FeedImage getFeedImage(final long id) throws SQLException {
|
||||
open();
|
||||
Cursor cursor = this.getImageOfFeedCursor(id);
|
||||
if ((cursor.getCount() == 0) || !cursor.moveToFirst()) {
|
||||
throw new SQLException("No FeedImage found at index: " + id);
|
||||
|
@ -493,7 +492,6 @@ public class PodDBAdapter {
|
|||
.getColumnIndex(KEY_FILE_URL)), cursor.getString(cursor
|
||||
.getColumnIndex(KEY_DOWNLOAD_URL)), cursor.getInt(cursor
|
||||
.getColumnIndex(KEY_DOWNLOADED)) > 0);
|
||||
close();
|
||||
return image;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue