diff options
author | Daniel Oeh <daniel@danielpc.(none)> | 2012-04-11 13:24:12 +0200 |
---|---|---|
committer | Daniel Oeh <daniel@danielpc.(none)> | 2012-04-11 13:24:12 +0200 |
commit | d2468c58624b9db6f16e39cc857214b32ef76ebd (patch) | |
tree | f404d97356d89eafb7a810edbc84c452697d2905 | |
parent | b1d9a536e015f0f8f47afae036b1d36ee2ed130a (diff) | |
download | AntennaPod-d2468c58624b9db6f16e39cc857214b32ef76ebd.zip |
Added SherlockActionBar library, Fixed Bugs in DBAdapter
-rw-r--r-- | AndroidManifest.xml | 2 | ||||
-rw-r--r-- | project.properties | 2 | ||||
-rw-r--r-- | res/menu/feedlist.xml | 15 | ||||
-rw-r--r-- | src/de/podfetcher/PodcastApp.java | 7 | ||||
-rw-r--r-- | src/de/podfetcher/activity/FeedlistActivity.java | 41 | ||||
-rw-r--r-- | src/de/podfetcher/activity/PodfetcherActivity.java | 45 | ||||
-rw-r--r-- | src/de/podfetcher/storage/PodDBAdapter.java | 28 |
7 files changed, 79 insertions, 61 deletions
diff --git a/AndroidManifest.xml b/AndroidManifest.xml index b7859cf1e..e0581aded 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -13,7 +13,7 @@ <application android:icon="@drawable/ic_launcher" android:label="@string/app_name" - android:theme="@style/Theme.GreenDroid" + android:theme="@style/Theme.Sherlock" android:name=".PodcastApp"> <activity android:label="@string/app_name" diff --git a/project.properties b/project.properties index a84a31943..62be9be8e 100644 --- a/project.properties +++ b/project.properties @@ -9,4 +9,4 @@ # Project target. target=android-14 -android.library.reference.1=/home/daniel/src/android/actionbarsherlock/library/ +android.library.reference.1=../actionbarsherlock/library/ diff --git a/res/menu/feedlist.xml b/res/menu/feedlist.xml new file mode 100644 index 000000000..1c6eedcd2 --- /dev/null +++ b/res/menu/feedlist.xml @@ -0,0 +1,15 @@ +<?xml version="1.0" encoding="utf-8"?> +<menu xmlns:android="http://schemas.android.com/apk/res/android"> + <item + android:id="@+id/add_feed" + android:title="Add Feed" + android:icon="@android:drawable/ic_menu_add" + android:showAsAction="ifRoom"> + </item> + <item + android:id="@+id/all_feed_refresh" + android:title="Refresh" + android:icon="@android:drawable/ic_menu_rotate" + android:showAsAction="ifRoom"> + </item> +</menu> diff --git a/src/de/podfetcher/PodcastApp.java b/src/de/podfetcher/PodcastApp.java index 2587cf93f..0d60c4b37 100644 --- a/src/de/podfetcher/PodcastApp.java +++ b/src/de/podfetcher/PodcastApp.java @@ -2,9 +2,8 @@ package de.podfetcher; import de.podfetcher.activity.PodfetcherActivity; import android.app.Application; -import greendroid.app.GDApplication; -public class PodcastApp extends GDApplication { +public class PodcastApp extends Application { private static PodcastApp singleton; @@ -12,10 +11,6 @@ public class PodcastApp extends GDApplication { return singleton; } - public Class<?> getHomeActivityClass() { - return PodfetcherActivity.class; - } - @Override public void onCreate() { super.onCreate(); diff --git a/src/de/podfetcher/activity/FeedlistActivity.java b/src/de/podfetcher/activity/FeedlistActivity.java index 3bf8defb8..bf9411b60 100644 --- a/src/de/podfetcher/activity/FeedlistActivity.java +++ b/src/de/podfetcher/activity/FeedlistActivity.java @@ -5,18 +5,19 @@ import de.podfetcher.feed.FeedManager; import de.podfetcher.gui.FeedlistAdapter; import de.podfetcher.service.FeedSyncService; import de.podfetcher.storage.DownloadRequester; -import greendroid.app.GDListActivity; import android.os.Bundle; import android.view.View; -import greendroid.widget.ActionBarItem.Type; -import greendroid.widget.ActionBarItem; import android.content.Intent; import android.content.IntentFilter; import android.content.BroadcastReceiver; import android.content.Context; +import com.actionbarsherlock.app.SherlockListActivity; +import com.actionbarsherlock.view.Menu; +import com.actionbarsherlock.view.MenuInflater; +import com.actionbarsherlock.view.MenuItem; -public class FeedlistActivity extends GDListActivity { +public class FeedlistActivity extends SherlockListActivity { private FeedManager manager; private FeedlistAdapter fla; @@ -29,9 +30,24 @@ public class FeedlistActivity extends GDListActivity { fla = new FeedlistAdapter(this, R.layout.feedlist_item, 0, manager.getFeeds()); setListAdapter(fla); - addActionBarItem(Type.Add, R.id.action_bar_add); - addActionBarItem(Type.Refresh, R.id.action_bar_refresh); - + } + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + MenuInflater inflater = getSupportMenuInflater(); + inflater.inflate(R.menu.feedlist, menu); + return true; + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + switch(item.getItemId()) { + case R.id.add_feed: + startActivity(new Intent(this, AddFeedActivity.class)); + return true; + default: + return super.onOptionsItemSelected(item); + } } @Override @@ -50,17 +66,6 @@ public class FeedlistActivity extends GDListActivity { unregisterReceiver(contentUpdate); } - @Override - public boolean onHandleActionBarItemClick(ActionBarItem item, int position) { - switch(item.getItemId()) { - case R.id.action_bar_add: - startActivity(new Intent(this, AddFeedActivity.class)); - return true; - default: - return super.onHandleActionBarItemClick(item, position); - } - } - private BroadcastReceiver contentUpdate = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { diff --git a/src/de/podfetcher/activity/PodfetcherActivity.java b/src/de/podfetcher/activity/PodfetcherActivity.java index 5483f007b..1c943656e 100644 --- a/src/de/podfetcher/activity/PodfetcherActivity.java +++ b/src/de/podfetcher/activity/PodfetcherActivity.java @@ -7,51 +7,38 @@ import org.xml.sax.SAXException; import de.podfetcher.R; import de.podfetcher.feed.*; import de.podfetcher.storage.DownloadRequester; -import greendroid.app.GDListActivity; -import greendroid.widget.ItemAdapter; -import greendroid.widget.item.TextItem; -import greendroid.widget.item.Item; -import greendroid.widget.ActionBar; -import greendroid.widget.ActionBar.Type; -import greendroid.app.ActionBarActivity; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.ListView; +import android.widget.ArrayAdapter; import android.os.Bundle; import android.content.Intent; +import com.actionbarsherlock.app.SherlockListActivity; -public class PodfetcherActivity extends GDListActivity { + - public PodfetcherActivity() { - super(ActionBar.Type.Normal); - } +public class PodfetcherActivity extends SherlockListActivity { + private final String[] ITEMS = {"Feeds", "Settings"}; + @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - + // Add navigation menu - ItemAdapter adapter = new ItemAdapter(this); - adapter.add(createListItem(R.string.feeds_label, FeedlistActivity.class)); - adapter.add(new TextItem("Settings")); - - setListAdapter(adapter); - - + setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, ITEMS)); } - private TextItem createListItem(int id, Class<?> _class) { - final TextItem item = new TextItem(getString(id)); - item.setTag(_class); - return item; - } - @Override protected void onListItemClick(ListView l, View v, int position, long id) { - final TextItem item = (TextItem) l.getAdapter().getItem(position); - Intent intent = new Intent(PodfetcherActivity.this, (Class<?>) item.getTag()); - intent.putExtra(ActionBarActivity.GD_ACTION_BAR_TITLE, item.text); - startActivity(intent); + final String selection = (String) l.getAdapter().getItem(position); + + if(selection.equals(ITEMS[0])) { + Intent intent = new Intent(PodfetcherActivity.this, FeedlistActivity.class); + startActivity(intent); + } else if(selection.equals(ITEMS[1])){ + + } } } diff --git a/src/de/podfetcher/storage/PodDBAdapter.java b/src/de/podfetcher/storage/PodDBAdapter.java index 9728a6887..76af8e07f 100644 --- a/src/de/podfetcher/storage/PodDBAdapter.java +++ b/src/de/podfetcher/storage/PodDBAdapter.java @@ -90,10 +90,12 @@ public class PodDBAdapter { } public PodDBAdapter open() { - try { - db = helper.getWritableDatabase(); - } catch (SQLException ex) { - db = helper.getReadableDatabase(); + if(db == null || !db.isOpen() || db.isReadOnly()) { + try { + db = helper.getWritableDatabase(); + } catch (SQLException ex) { + db = helper.getReadableDatabase(); + } } return this; } @@ -105,8 +107,7 @@ public class PodDBAdapter { /** Inserts or updates a feed entry * @return the id of the entry * */ - public long setFeed(Feed feed) { - open(); + public long setFeed(Feed feed) { ContentValues values = new ContentValues(); values.put(KEY_TITLE, feed.getTitle()); values.put(KEY_LINK, feed.getLink()); @@ -128,6 +129,7 @@ public class PodDBAdapter { } values.put(KEY_DOWNLOAD_URL, feed.getDownload_url()); + open(); if(feed.getId() == 0) { // Create new entry Log.d(this.toString(), "Inserting new Feed into db"); @@ -144,6 +146,7 @@ public class PodDBAdapter { * @return the id of the entry * */ public long setCategory(FeedCategory category) { + open(); ContentValues values = new ContentValues(); values.put(KEY_NAME, category.getName()); if(category.getId() == 0) { @@ -152,6 +155,7 @@ public class PodDBAdapter { db.update(TABLE_NAME_FEED_CATEGORIES, values, KEY_ID+"=?", new String[]{String.valueOf(category.getId())}); } + close(); return category.getId(); } @@ -160,6 +164,7 @@ public class PodDBAdapter { * @return the id of the entry * */ public long setImage(FeedImage image) { + open(); ContentValues values = new ContentValues(); values.put(KEY_TITLE, image.getTitle()); values.put(KEY_DOWNLOAD_URL, image.getDownload_url()); @@ -171,6 +176,7 @@ public class PodDBAdapter { } else { db.update(TABLE_NAME_FEED_IMAGES, values, KEY_ID+"=?", new String[]{String.valueOf(image.getId())}); } + close(); return image.getId(); } @@ -179,6 +185,7 @@ public class PodDBAdapter { * @return the id of the entry */ public long setMedia(FeedMedia media) { + open(); ContentValues values = new ContentValues(); values.put(KEY_LENGTH, media.getLength()); values.put(KEY_POSITION, media.getPosition()); @@ -193,6 +200,7 @@ public class PodDBAdapter { } else { db.update(TABLE_NAME_FEED_MEDIA, values, KEY_ID+"=?", new String[]{String.valueOf(media.getId())}); } + close(); return media.getId(); } @@ -217,6 +225,14 @@ public class PodDBAdapter { } values.put(KEY_FEED, item.getFeed().getId()); values.put(KEY_READ, (item.isRead()) ? 1 : 0); + + open(); + if(item.getId() == 0) { + item.setId(db.insert(TABLE_NAME_FEED_ITEMS, null, values)); + } else { + db.update(TABLE_NAME_FEED_ITEMS, values, KEY_ID+"=?", new String[]{String.valueOf(item.getId())}); + } + close(); return item.getId(); } |