Added SherlockActionBar library, Fixed Bugs in DBAdapter

This commit is contained in:
Daniel Oeh 2012-04-11 13:24:12 +02:00
parent b1d9a536e0
commit d2468c5862
7 changed files with 79 additions and 61 deletions

View File

@ -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"

View File

@ -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/

15
res/menu/feedlist.xml Normal file
View File

@ -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>

View File

@ -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();

View File

@ -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) {

View File

@ -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])){
}
}
}

View File

@ -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();
}