Lots and lots

master
Evan Leybourn 2010-05-29 20:43:52 +10:00
parent 173c88f2c4
commit bdbc9677a8
32 changed files with 810 additions and 244 deletions

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.eleybourn.bookcatalogue"
android:versionCode="15" android:versionName="1.11">
android:versionName="2.0" android:versionCode="16">
<application android:label="@string/app_name" android:icon="@drawable/logo_bc">
<activity android:name=".BookCatalogue"
android:label="@string/app_name">
@ -16,7 +16,7 @@
<meta-data android:name="android.app.searchable" android:resource="@xml/searchable" />
</activity>
<activity android:name=".BookEdit" android:label="@string/edit_title"></activity>
<activity android:name=".BookEdit"></activity>
<activity android:name=".BookISBNSearch" android:label="@string/title_isbn_search"></activity>
<activity android:name=".Bookshelf" android:label="@string/title_manage_bs"></activity>
@ -32,4 +32,5 @@
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
<uses-permission android:name="android.permission.READ_CONTACTS"></uses-permission>
</manifest>

15
README
View File

@ -41,11 +41,16 @@ Features include;
case. e.g. "The murder on the links" becomes "The Murder on the Links"
* Using ISBN or Barcode scanning will also download a thumbnail (if available)
New in v1.11
* There is a new tabbed "edit" interface which allows you to 1) edit,
2) make notes and 3) loan a book
* The comments tab also has a notes field where you can add any information you
want (Requested by Luke).
New in v2.0
* There is a new tabbed "edit" interface to simplify editing books.
* The new comments tab also includes a notes field where you can add personal
notes for any book (Requested by Luke).
* The new loaned books tab allows you to record books loaned to friends. This
will lookup your phone contacts to pre-populate the list (Requested by Luke)
* Scanned books that already exist in the database (based on ISBN) will no
longer be added (Identified by Colin)
* After adding a book, the main view will now scroll to a appropriate location.
* Searching has been made significantly faster.
New in v1.10
* Fixed a crash on the phone (SQL Exception)

Binary file not shown.

Binary file not shown.

View File

@ -44,8 +44,8 @@ public final class R {
public static final int bookshelf=0x7f060013;
public static final int bookshelf_img=0x7f060003;
public static final int bookshelf_label=0x7f060004;
public static final int bookshelf_name=0x7f06001b;
public static final int bookshelf_num=0x7f06001c;
public static final int bookshelf_name=0x7f060020;
public static final int bookshelf_num=0x7f060021;
public static final int cancel=0x7f060016;
public static final int confirm=0x7f060015;
public static final int date_published=0x7f060012;
@ -55,45 +55,52 @@ public final class R {
public static final int import_img=0x7f060007;
public static final int import_label=0x7f060008;
public static final int isbn=0x7f06000e;
public static final int notes=0x7f060019;
public static final int line=0x7f060019;
public static final int loan_to=0x7f06001a;
public static final int loan_to_who=0x7f06001b;
public static final int loaned_to=0x7f060017;
public static final int notes=0x7f06001e;
public static final int pages=0x7f060014;
public static final int publisher=0x7f060011;
public static final int rating=0x7f060018;
public static final int read=0x7f060017;
public static final int row_author=0x7f060022;
public static final int row_bookshelf=0x7f060024;
public static final int row_family=0x7f06001d;
public static final int row_given=0x7f06001e;
public static final int rating=0x7f06001d;
public static final int read=0x7f06001c;
public static final int row_author=0x7f060027;
public static final int row_bookshelf=0x7f060029;
public static final int row_family=0x7f060022;
public static final int row_given=0x7f060023;
public static final int row_img=0x7f06000b;
public static final int row_publisher=0x7f060023;
public static final int row_series=0x7f060020;
public static final int row_series_num=0x7f060021;
public static final int row_title=0x7f06001f;
public static final int search=0x7f06001a;
public static final int row_publisher=0x7f060028;
public static final int row_series=0x7f060025;
public static final int row_series_num=0x7f060026;
public static final int row_title=0x7f060024;
public static final int search=0x7f06001f;
public static final int series=0x7f06000f;
public static final int series_num=0x7f060010;
public static final int spinnerTarget=0x7f060025;
public static final int spinnerTarget=0x7f06002a;
public static final int title=0x7f06000d;
public static final int url=0x7f06000a;
public static final int version=0x7f060002;
public static final int version_label=0x7f060001;
public static final int who=0x7f060018;
}
public static final class layout {
public static final int administration=0x7f030000;
public static final int edit_book=0x7f030001;
public static final int edit_book_notes=0x7f030002;
public static final int edit_bookshelf=0x7f030003;
public static final int isbn_search=0x7f030004;
public static final int list_authors=0x7f030005;
public static final int list_books=0x7f030006;
public static final int list_bookshelves=0x7f030007;
public static final int main=0x7f030008;
public static final int row_authors=0x7f030009;
public static final int row_authors_books=0x7f03000a;
public static final int row_books=0x7f03000b;
public static final int row_bookshelf=0x7f03000c;
public static final int spinner_frontpage=0x7f03000d;
public static final int tabhost=0x7f03000e;
public static final int edit_book_loan=0x7f030002;
public static final int edit_book_loaned=0x7f030003;
public static final int edit_book_notes=0x7f030004;
public static final int edit_bookshelf=0x7f030005;
public static final int isbn_search=0x7f030006;
public static final int list_authors=0x7f030007;
public static final int list_books=0x7f030008;
public static final int list_bookshelves=0x7f030009;
public static final int main=0x7f03000a;
public static final int row_authors=0x7f03000b;
public static final int row_authors_books=0x7f03000c;
public static final int row_books=0x7f03000d;
public static final int row_bookshelf=0x7f03000e;
public static final int spinner_frontpage=0x7f03000f;
public static final int tabhost=0x7f030010;
}
public static final class string {
public static final int administration_label=0x7f050036;
@ -127,6 +134,8 @@ public final class R {
public static final int install_scan_title=0x7f050039;
public static final int isbn=0x7f050006;
public static final int isbn_found=0x7f050024;
public static final int loan_to=0x7f050045;
public static final int loaned_to=0x7f050043;
public static final int menu_administration=0x7f050037;
public static final int menu_bookshelf=0x7f05001e;
public static final int menu_delete=0x7f050003;
@ -139,6 +148,8 @@ public final class R {
public static final int menu_sort_by_author_collapsed=0x7f050013;
public static final int menu_sort_by_author_expanded=0x7f050011;
public static final int menu_sort_by_title=0x7f050012;
public static final int name=0x7f050047;
public static final int nobody=0x7f050044;
public static final int nobooks=0x7f05000f;
public static final int nobookshelves=0x7f05001b;
public static final int notes=0x7f050042;
@ -147,6 +158,7 @@ public final class R {
public static final int rating=0x7f050009;
public static final int read=0x7f05000b;
public static final int results_found=0x7f050035;
public static final int returned=0x7f050046;
public static final int search=0x7f050018;
public static final int search_hint=0x7f05002a;
public static final int search_label=0x7f050029;

60
res/layout/edit_book_loan.xml Executable file
View File

@ -0,0 +1,60 @@
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:padding="10sp">
<TextView android:id="@+id/loaned_to"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/loaned_to"
/>
<TextView android:id="@+id/who"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/nobody"
android:paddingBottom = "5sp"
/>
<TextView android:id="@+id/line"
android:layout_width="fill_parent"
android:layout_height="2sp"
android:layout_weight="1"
android:background = "#CCCCCC"
/>
<TextView android:id="@+id/loan_to"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/loan_to"
android:paddingTop = "5sp"
/>
<AutoCompleteTextView android:id="@+id/loan_to_who"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="@string/name"
android:inputType="textCapWords"
android:completionThreshold="2"
/>
<Button android:id="@+id/confirm"
android:text="@string/confirm_add"
android:width="150sp"
android:layout_width="wrap_content"
android:layout_height="fill_parent" />
</LinearLayout>
</ScrollView>

44
res/layout/edit_book_loaned.xml Executable file
View File

@ -0,0 +1,44 @@
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:padding="10sp">
<TextView android:id="@+id/loaned_to"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/loaned_to"
/>
<TextView android:id="@+id/who"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/nobody"
android:paddingBottom = "5sp"
/>
<TextView android:id="@+id/line"
android:layout_width="fill_parent"
android:layout_height="2sp"
android:layout_weight="1"
android:background = "#CCCCCC"
/>
<Button android:id="@+id/confirm"
android:paddingTop = "5sp"
android:text="@string/returned"
android:width="150sp"
android:layout_width="wrap_content"
android:layout_height="fill_parent" />
</LinearLayout>
</ScrollView>

View File

@ -20,8 +20,8 @@
<string name="menu_sort_by_author_expanded">Expand All</string>
<string name="menu_sort_by_title">Sort By Title</string>
<string name="menu_sort_by_author_collapsed">Collapse All</string>
<string name="sort_title">Book Catalogue (by Title)</string>
<string name="edit_title">Book Catalogue (Edit Book)</string>
<string name="sort_title">Book Catalogue: by Title</string>
<string name="edit_title">Book Catalogue: Edit Book</string>
<string name="menu_insert_isbn">Add by ISBN</string>
<string name="menu_insert_barcode">Add by Barcode</string>
<string name="search">Search</string>
@ -37,9 +37,9 @@
<string name="bookshelf_label">Bookshelf: </string>
<string name="all_books">All Books</string>
<string name="isbn_found">ISBN Scanned. Searching Internet.</string>
<string name="title_isbn_search">Book Catalogue (ISBN Search)</string>
<string name="title_manage_bs">Book Catalogue (Manage Bookshelves)</string>
<string name="title_edit_bs">Book Catalogue (Edit Bookshelf)</string>
<string name="title_isbn_search">Book Catalogue: ISBN Search</string>
<string name="title_manage_bs">Book Catalogue: Manage Bookshelves</string>
<string name="title_edit_bs">Book Catalogue: Edit Bookshelf</string>
<string name="book_exists">The book you are trying to add already exists. Skipping.</string>
<string name="search_label">Search for Books</string>
<string name="search_hint">Search Author or Title</string>
@ -67,4 +67,9 @@
<string name="edit_book_friends">Loan Book</string>
<string name="unknown_error">An unknown error occured</string>
<string name="notes">Notes</string>
<string name="loaned_to">This book has been loaned to:</string>
<string name="nobody">Nobody</string>
<string name="loan_to">Loan book to:</string>
<string name="returned">Returned</string>
<string name="name">Name</string>
</resources>

View File

@ -89,6 +89,7 @@ public class BookCatalogue extends ExpandableListActivity {
private boolean expanded = false;
private static boolean shown = false;
private String justAdded = "";
/** Called when the activity is first created. */
@Override
@ -172,29 +173,29 @@ public class BookCatalogue extends ExpandableListActivity {
mBookshelfNumView.setText("(" + numBooks + ")");
}
private void fillDataAuthor() {
Intent intent = getIntent();
// base the layout and the query on the sort order
int layout = R.layout.row_authors;
int layout_child = R.layout.row_authors_books;
// Get all of the rows from the database and create the item list
Cursor BooksCursor = null;
private void fillDataAuthor() {
Intent intent = getIntent();
// base the layout and the query on the sort order
int layout = R.layout.row_authors;
int layout_child = R.layout.row_authors_books;
// Get all of the rows from the database and create the item list
Cursor BooksCursor = null;
if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
String query = intent.getStringExtra(SearchManager.QUERY);
BooksCursor = mDbHelper.searchAuthors(query, bookshelf);
numAuthors = BooksCursor.getCount();
Toast.makeText(this, numAuthors + " " + this.getResources().getString(R.string.results_found), Toast.LENGTH_LONG).show();
numAuthors = BooksCursor.getCount();
Toast.makeText(this, numAuthors + " " + this.getResources().getString(R.string.results_found), Toast.LENGTH_LONG).show();
this.setTitle(R.string.search_title);
} else {
BooksCursor = mDbHelper.fetchAllAuthors(bookshelf);
numAuthors = BooksCursor.getCount();
numAuthors = BooksCursor.getCount();
this.setTitle(R.string.app_name);
}
mGroupIdColumnIndex = BooksCursor.getColumnIndexOrThrow("_id");
startManagingCursor(BooksCursor);
// Create an array to specify the fields we want to display in the list
mGroupIdColumnIndex = BooksCursor.getColumnIndexOrThrow("_id");
startManagingCursor(BooksCursor);
// Create an array to specify the fields we want to display in the list
String[] from = new String[]{CatalogueDBAdapter.KEY_FAMILY_NAME, CatalogueDBAdapter.KEY_GIVEN_NAMES};
String[] exp_from = new String[]{CatalogueDBAdapter.KEY_TITLE, CatalogueDBAdapter.KEY_SERIES, CatalogueDBAdapter.KEY_SERIES_NUM};
@ -457,29 +458,33 @@ public class BookCatalogue extends ExpandableListActivity {
}
/*
* add / remove items from the current group arraylist
* add / remove items from the current group arrayList
*/
public void addToCurrentGroup(int pos) {
addToCurrentGroup(pos, false);
}
/*
* add / remove items from the current group arraylist
*/
public void addToCurrentGroup(int pos, boolean force) {
int index = currentGroup.indexOf(pos);
if (index == -1) {
//it does not exist (so is not open), so add to the list
currentGroup.add(pos);
} else {
//it does exist (so is open), so remove from the list
currentGroup.remove(index);
if (force == true) {
currentGroup.add(pos);
}
}
}
/**
* add / remove items from the current group arrayList
*
* @param pos The position to add or remove
* @param force If force is true, then it will be always be added, even if it already exists - but moved to the end
*/
public void addToCurrentGroup(int pos, boolean force) {
int index = currentGroup.indexOf(pos);
if (index == -1) {
//it does not exist (so is not open), so add to the list
currentGroup.add(pos);
} else {
//it does exist (so is open), so remove from the list
currentGroup.remove(index);
if (force == true) {
currentGroup.add(pos);
}
}
}
/*
* Expand all Author Groups
*/
@ -522,7 +527,7 @@ public class BookCatalogue extends ExpandableListActivity {
ExpandableListView.ExpandableListContextMenuInfo info = (ExpandableListView.ExpandableListContextMenuInfo) menuInfo;
try {
// Only delete titles, not authors
if (ExpandableListView.getPackedPositionType(info.packedPosition) == 1) {
if (ExpandableListView.getPackedPositionType(info.packedPosition) == 1 || sort == 1) {
MenuItem delete = menu.add(0, DELETE_ID, 0, R.string.menu_delete);
delete.setIcon(android.R.drawable.ic_menu_delete);
MenuItem edit_book = menu.add(0, EDIT_BOOK, 0, R.string.edit_book);
@ -666,32 +671,49 @@ public class BookCatalogue extends ExpandableListActivity {
}
return result;
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
super.onActivityResult(requestCode, resultCode, intent);
switch(requestCode) {
case ACTIVITY_SCAN:
try {
String contents = intent.getStringExtra("SCAN_RESULT");
Toast.makeText(this, R.string.isbn_found, Toast.LENGTH_LONG).show();
Intent i = new Intent(this, BookISBNSearch.class);
i.putExtra("isbn", contents);
startActivityForResult(i, ACTIVITY_ISBN);
} catch (NullPointerException e) {
// This is not a scan result, but a normal return
fillData();
}
break;
case ACTIVITY_CREATE:
case ACTIVITY_EDIT:
case ACTIVITY_SORT:
case ACTIVITY_ISBN:
case ACTIVITY_ADMIN:
fillData();
break;
}
}
/**
* Called when an activity launched exits, giving you the requestCode you started it with,
* the resultCode it returned, and any additional data from it.
*/
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
super.onActivityResult(requestCode, resultCode, intent);
switch(requestCode) {
case ACTIVITY_SCAN:
try {
String contents = intent.getStringExtra("SCAN_RESULT");
Toast.makeText(this, R.string.isbn_found, Toast.LENGTH_LONG).show();
Intent i = new Intent(this, BookISBNSearch.class);
i.putExtra("isbn", contents);
startActivityForResult(i, ACTIVITY_ISBN);
} catch (NullPointerException e) {
// This is not a scan result, but a normal return
fillData();
}
break;
case ACTIVITY_CREATE:
case ACTIVITY_EDIT:
case ACTIVITY_SORT:
case ACTIVITY_ISBN:
case ACTIVITY_ADMIN:
try {
if (sort == 1) {
justAdded = intent.getStringExtra(BookEditFields.ADDED_TITLE);
int position = mDbHelper.fetchBookPositionByTitle(justAdded, bookshelf);
addToCurrentGroup(position, true);
} else {
justAdded = intent.getStringExtra(BookEditFields.ADDED_AUTHOR);
int position = mDbHelper.fetchAuthorPositionByName(justAdded, bookshelf);
addToCurrentGroup(position, true);
}
} catch (Exception e) {
//do nothing
}
fillData();
break;
}
}
}

View File

@ -91,4 +91,14 @@ public class BookEdit extends TabActivity {
tabHost.setCurrentTab(currentTab);
}
/**
* This is a straight passthrough
*/
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
super.onActivityResult(requestCode, resultCode, intent);
setResult(resultCode, intent);
finish();
}
}

View File

@ -24,6 +24,7 @@ import java.io.File;
import java.util.ArrayList;
import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.graphics.BitmapFactory;
import android.os.Bundle;
@ -58,6 +59,11 @@ public class BookEditFields extends Activity {
private Float rating = Float.parseFloat("0");
private boolean read = false;
private String notes = "";
private String added_title = "";
private String added_author = "";
public static String ADDED_TITLE = "ADDED_TITLE";
public static String ADDED_AUTHOR = "ADDED_AUTHOR";
protected void getRowId() {
/* Get any information from the extras bundle */
@ -150,8 +156,15 @@ public class BookEditFields extends Activity {
mConfirmButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
saveState();
setResult(RESULT_OK);
finish();
Intent i = new Intent();
i.putExtra(ADDED_TITLE, added_title);
i.putExtra(ADDED_AUTHOR, added_author);
if (getParent() == null) {
setResult(RESULT_OK, i);
} else {
getParent().setResult(RESULT_OK, i);
}
getParent().finish();
}
});
@ -176,9 +189,11 @@ public class BookEditFields extends Activity {
// From the database (edit)
Cursor book = mDbHelper.fetchBook(mRowId);
startManagingCursor(book);
String title = book.getString(book.getColumnIndexOrThrow(CatalogueDBAdapter.KEY_TITLE));
getParent().setTitle(this.getResources().getString(R.string.app_name) + ": " + title);
mAuthorText.setText(book.getString(book.getColumnIndexOrThrow(CatalogueDBAdapter.KEY_AUTHOR)));
mTitleText.setText(book.getString(book.getColumnIndexOrThrow(CatalogueDBAdapter.KEY_TITLE)));
mTitleText.setText(title);
mIsbnText.setText(book.getString(book.getColumnIndexOrThrow(CatalogueDBAdapter.KEY_ISBN)));
mPublisherText.setText(book.getString(book.getColumnIndexOrThrow(CatalogueDBAdapter.KEY_PUBLISHER)));
String[] date = book.getString(book.getColumnIndexOrThrow(CatalogueDBAdapter.KEY_DATE_PUBLISHED)).split("-");
@ -198,6 +213,7 @@ public class BookEditFields extends Activity {
read = (book.getInt(book.getColumnIndex(CatalogueDBAdapter.KEY_READ))==0 ? false:true);
notes = book.getString(book.getColumnIndexOrThrow(CatalogueDBAdapter.KEY_NOTES));
} else if (extras != null) {
getParent().setTitle(this.getResources().getString(R.string.app_name) + ": " + this.getResources().getString(R.string.menu_insert));
// From the ISBN Search (add)
String[] book = extras.getStringArray("book");
mAuthorText.setText(book[0]);
@ -225,6 +241,7 @@ public class BookEditFields extends Activity {
mImageView.setImageBitmap(BitmapFactory.decodeFile(tmpThumbFilename));
} else {
// Manual Add
getParent().setTitle(this.getResources().getString(R.string.app_name) + ": " + this.getResources().getString(R.string.menu_insert));
mConfirmButton.setText(R.string.confirm_add);
}
}
@ -249,10 +266,19 @@ public class BookEditFields extends Activity {
super.onResume();
populateFields();
}
/**
* This will save a book into the database, by either updating or created a book.
* Minor modifications will be made to the strings:
* Titles will be rewords so a, the, an will be moved to the end of the string
* Date published will be converted from a date to a string
*
* It will also ensure the book doesn't already exist (isbn search) if you are creating a book.
* Thumbnails will also be saved to the correct location
*/
private void saveState() {
String author = mAuthorText.getText().toString();
/* Move "The, A, An" to the end of the string */
String title = mTitleText.getText().toString();
String[] title_words = title.split(" ");
@ -270,7 +296,7 @@ public class BookEditFields extends Activity {
} catch (Exception e) {
//do nothing. Title stays the same
}
String isbn = mIsbnText.getText().toString();
String publisher = mPublisherText.getText().toString();
int yyyy = mDate_publishedText.getYear();
@ -286,7 +312,7 @@ public class BookEditFields extends Activity {
} catch (NumberFormatException e) {
pages = 0;
}
if (mRowId == null || mRowId == 0) {
/* Check if the book currently exists */
if (!isbn.equals("")) {
@ -297,7 +323,7 @@ public class BookEditFields extends Activity {
return;
}
}
long id = mDbHelper.createBook(author, title, isbn, publisher, date_published, rating, bookshelf, read, series, pages, series_num, notes);
if (id > 0) {
mRowId = id;
@ -310,6 +336,9 @@ public class BookEditFields extends Activity {
} else {
mDbHelper.updateBook(mRowId, author, title, isbn, publisher, date_published, rating, bookshelf, read, series, pages, series_num, notes);
}
/* These are global variables that will be sent via intent back to the list view */
added_author = author;
added_title = title;
return;
}

View File

@ -20,24 +20,150 @@
package com.eleybourn.bookcatalogue;
//import android.R;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
import java.util.ArrayList;
/*
* A book catalogue application that integrates with Google Books.
import android.app.Activity;
import android.database.Cursor;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
/**
* This class is called by the BookEdit activity and displays the Loaned Tab
*
* Users can select a book and, from this activity, select a friend to "loan" the book to.
* This will then be saved in the database for reference.
*/
public class BookEditLoaned extends Activity {
/* mRowId contains the id of the book */
private Long mRowId;
private CatalogueDBAdapter mDbHelper;
/** Called when the activity is first created. */
/**
* getRowId will extract the book id from either the saved bundle (from pausing the activity)
* or from the passed extras Bundle.
*
* @param savedInstanceState The saved bundle (from pausing). Can be null.
*/
protected void getRowId(Bundle savedInstanceState) {
/* Get any information from the extras bundle */
mRowId = savedInstanceState != null ? savedInstanceState.getLong(CatalogueDBAdapter.KEY_ROWID) : null;
if (mRowId == null) {
Bundle extras = getIntent().getExtras();
mRowId = extras != null ? extras.getLong(CatalogueDBAdapter.KEY_ROWID) : null;
}
}
/**
* Return a list of friends from your contact list.
* This is for the autoComplete textView
*
* @return an ArrayList of names
*/
protected ArrayList<String> getFriends() {
ArrayList<String> friend_list = new ArrayList<String>();
Cursor contactsCursor = getContentResolver().query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null);
while (contactsCursor.moveToNext()) {
String name = contactsCursor.getString(contactsCursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
friend_list.add(name);
}
return friend_list;
}
/**
* Called when the activity is first created. This function will check whether a book has been loaned
* and display the appropriate page as required.
*
* @param savedInstanceState The saved bundle (from pausing). Can be null.
*/
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView textview = new TextView(this);
textview.setText("This is the loaned tab");
setContentView(textview);
mDbHelper = new CatalogueDBAdapter(this);
mDbHelper.open();
getRowId(savedInstanceState);
if (mRowId == null || mRowId == 0) {
/* This activity must have a row id, i.e. you can't loan a book you haven't created yet */
Toast.makeText(this, R.string.unknown_error, Toast.LENGTH_LONG).show();
finish();
return;
}
Cursor book = mDbHelper.fetchBook(mRowId);
startManagingCursor(book);
String title = book.getString(book.getColumnIndexOrThrow(CatalogueDBAdapter.KEY_TITLE));
getParent().setTitle(this.getResources().getString(R.string.app_name) + ": " + title);
String user = mDbHelper.fetchLoanByBook(mRowId);
if (user == null) {
loanTo();
} else {
loaned(user);
}
}
/**
* Display the loan to page. It is slightly different to the existing loan page
*/
private void loanTo() {
setContentView(R.layout.edit_book_loan);
ArrayAdapter<String> series_adapter = new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line, getFriends());
AutoCompleteTextView mUserText = (AutoCompleteTextView) findViewById(R.id.loan_to_who);
mUserText.setAdapter(series_adapter);
Button mConfirmButton = (Button) findViewById(R.id.confirm);
mConfirmButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
String friend = saveLoan();
setResult(RESULT_OK);
loaned(friend);
}
});
}
/**
* Display the existing loan page. It is slightly different to the loan to page
*
* @param user The user the book was loaned to
*/
private void loaned(String user) {
setContentView(R.layout.edit_book_loaned);
TextView mWhoText = (TextView) findViewById(R.id.who);
mWhoText.setText(user);
Button mConfirmButton = (Button) findViewById(R.id.confirm);
mConfirmButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
removeLoan();
setResult(RESULT_OK);
loanTo();
}
});
}
/**
* Save the user and book combination as a loan in the database
*
* @return the user
*/
private String saveLoan() {
AutoCompleteTextView mUserText = (AutoCompleteTextView) findViewById(R.id.loan_to_who);
String friend = mUserText.getText().toString();
mDbHelper.createLoan(mRowId, friend);
return friend;
}
/**
* Delete the user and book combination as a loan from the database
*/
private void removeLoan() {
mDbHelper.deleteLoan(mRowId);
return;
}
}

View File

@ -109,6 +109,8 @@ public class BookEditNotes extends Activity {
// From the database (edit)
Cursor book = mDbHelper.fetchBook(mRowId);
startManagingCursor(book);
String title = book.getString(book.getColumnIndexOrThrow(CatalogueDBAdapter.KEY_TITLE));
getParent().setTitle(this.getResources().getString(R.string.app_name) + ": " + title);
mRatingText.setRating(book.getFloat(book.getColumnIndexOrThrow(CatalogueDBAdapter.KEY_RATING)));
mReadText.setChecked((book.getInt(book.getColumnIndex(CatalogueDBAdapter.KEY_READ))==0? false:true) );

View File

@ -42,6 +42,7 @@ import org.xml.sax.SAXException;
import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.os.Environment;
import android.view.View;
@ -50,7 +51,8 @@ import android.widget.EditText;
import android.widget.Toast;
public class BookISBNSearch extends Activity {
private static final int CREATE_BOOK = 0;
private EditText mIsbnText;
private CatalogueDBAdapter mDbHelper;
@ -83,7 +85,25 @@ public class BookISBNSearch extends Activity {
}
}
/**
* This function takes the isbn and search google books (and soon amazon)
* to extract the details of the book. The details will then get sent to the
* BookEdit activity
*
* @param isbn The ISBN to search
*/
protected void go(String isbn) {
// If the book already exists, do not continue
if (!isbn.equals("")) {
Cursor book = mDbHelper.fetchBookByISBN(isbn);
int rows = book.getCount();
if (rows != 0) {
Toast.makeText(this, R.string.book_exists, Toast.LENGTH_LONG).show();
finish();
return;
}
}
/* Delete any hanging around thumbs */
try {
String tmpThumbFilename = Environment.getExternalStorageDirectory() + "/" + CatalogueDBAdapter.LOCATION + "/tmp.jpg";
@ -121,8 +141,6 @@ public class BookISBNSearch extends Activity {
book[8] = properCase(book[8]); // series
}
createBook(book);
setResult(RESULT_OK);
finish();
}
@Override
@ -382,7 +400,16 @@ public class BookISBNSearch extends Activity {
private void createBook(String[] book) {
Intent i = new Intent(this, BookEdit.class);
i.putExtra("book", book);
startActivity(i);
startActivityForResult(i, CREATE_BOOK);
}
/**
* This is a straight passthrough
*/
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
super.onActivityResult(requestCode, resultCode, intent);
setResult(resultCode, intent);
finish();
}
}

View File

@ -24,15 +24,17 @@ import java.io.File;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.CursorIndexOutOfBoundsException;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.os.Environment;
import android.util.Log;
/**
* Book Catalogue database access helper class. Defines the basic CRUD operations
* for the catalogue (based on the Notepad tutorial) example, and gives the
* ability to list all notes as well as retrieve or modify a specific book.
* for the catalogue (based on the Notepad tutorial), and gives the
* ability to list all books as well as retrieve or modify a specific book.
*/
public class CatalogueDBAdapter {
@ -53,6 +55,8 @@ public class CatalogueDBAdapter {
public static final String LOCATION = "bookCatalogue";
public static final String KEY_SERIES_NUM = "series_num";
public static final String KEY_NOTES = "notes";
public static final String KEY_BOOK = "book";
public static final String KEY_LOANED_TO = "loaned_to";
private DatabaseHelper mDbHelper;
private SQLiteDatabase mDb;
@ -62,11 +66,10 @@ public class CatalogueDBAdapter {
private static final String DATABASE_TABLE_BOOKS = "books";
private static final String DATABASE_TABLE_AUTHORS = "authors";
private static final String DATABASE_TABLE_BOOKSHELF = "bookshelf";
private static final String DATABASE_TABLE_LOAN = "loan";
public static String message = "";
/**
* Database creation sql statement
*/
/* Database creation sql statement */
private static final String DATABASE_CREATE_AUTHORS =
"create table " + DATABASE_TABLE_AUTHORS +
" (_id integer primary key autoincrement, " +
@ -101,23 +104,64 @@ public class CatalogueDBAdapter {
KEY_NOTES + " text " +
")";
private final Context mCtx;
private static final int DATABASE_VERSION = 20;
private static final String DATABASE_CREATE_LOAN =
"create table " + DATABASE_TABLE_LOAN +
" (_id integer primary key autoincrement, " +
KEY_BOOK + " integer REFERENCES " + DATABASE_TABLE_BOOKS + " ON DELETE SET NULL ON UPDATE SET NULL, " +
KEY_LOANED_TO + " text " +
")";
private static final String DATABASE_CREATE_INDICES =
"CREATE INDEX IF NOT EXISTS authors_given_names ON "+DATABASE_TABLE_AUTHORS+" ("+KEY_GIVEN_NAMES+");" +
"CREATE INDEX IF NOT EXISTS authors_family_name ON "+DATABASE_TABLE_AUTHORS+" ("+KEY_FAMILY_NAME+");" +
"CREATE INDEX IF NOT EXISTS bookshelf_bookshelf ON "+DATABASE_TABLE_BOOKSHELF+" ("+KEY_BOOKSHELF+");" +
"CREATE INDEX IF NOT EXISTS books_author ON "+DATABASE_TABLE_BOOKS+" ("+KEY_AUTHOR+");" +
"CREATE INDEX IF NOT EXISTS books_title ON "+DATABASE_TABLE_BOOKS+" ("+KEY_TITLE+");" +
"CREATE INDEX IF NOT EXISTS books_isbn ON "+DATABASE_TABLE_BOOKS+" ("+KEY_ISBN+");" +
"CREATE INDEX IF NOT EXISTS books_bookshelf ON "+DATABASE_TABLE_BOOKS+" ("+KEY_BOOKSHELF+");" +
"CREATE INDEX IF NOT EXISTS books_series ON "+DATABASE_TABLE_BOOKS+" ("+KEY_SERIES+");" +
"CREATE INDEX IF NOT EXISTS books_publisher ON "+DATABASE_TABLE_BOOKS+" ("+KEY_PUBLISHER+");" +
"CREATE UNIQUE INDEX IF NOT EXISTS loan_book_loaned_to ON "+DATABASE_TABLE_LOAN+" ("+KEY_BOOK+");"
;
private final Context mCtx;
private static final int DATABASE_VERSION = 23;
/**
* This is a specific version of the SQLiteOpenHelper class. It handles onCreate and onUpgrade events
*
* @author evan
*/
private static class DatabaseHelper extends SQLiteOpenHelper {
DatabaseHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
/**
* This function is called when the database is first created
*
* @param db The database to be created
*/
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(DATABASE_CREATE_AUTHORS);
db.execSQL(DATABASE_CREATE_BOOKSHELF);
db.execSQL(DATABASE_CREATE_BOOKS);
db.execSQL(DATABASE_CREATE_BOOKSHELF_DATA);
db.execSQL(DATABASE_CREATE_LOAN);
db.execSQL(DATABASE_CREATE_INDICES);
new File(Environment.getExternalStorageDirectory() + "/" + LOCATION + "/").mkdirs();
}
/**
* This function is called each time the database is upgraded. The function will run all
* upgrade scripts between the oldVersion and the newVersion.
*
* @see DATABASE_VERSION
* @param db The database to be upgraded
* @param oldVersion The current version number of the database
* @param newVersion The new version number of the database
*/
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
//Log.w(TAG, "Upgrading database from version " + oldVersion + " to " + newVersion + ", existing data will be saved");
@ -149,8 +193,8 @@ public class CatalogueDBAdapter {
if (curVersion == 16) {
//do nothing except increment
curVersion++;
message += "* This message will now appear whenever you upgrade\n";
message += "* Various SQL bugs have been resolved\n";
message += "* This message will now appear whenever you upgrade\n\n";
message += "* Various SQL bugs have been resolved\n\n";
}
if (curVersion == 17) {
//do nothing except increment
@ -161,101 +205,300 @@ public class CatalogueDBAdapter {
curVersion++;
}
if (curVersion == 19) {
//do nothing except increment
curVersion++;
message += "* There is a new tabbed 'edit' interface which allows you to 1) edit, 2) make notes and 3) loan a book\n";
message += "* The comments tab also has a notes field where you can add any information you want (Requested by Luke).\n";
db.execSQL("ALTER TABLE " + DATABASE_TABLE_BOOKS + " ADD " + KEY_NOTES + " text");
db.execSQL("UPDATE " + DATABASE_TABLE_BOOKS + " SET " + KEY_NOTES + " = ''");
curVersion++;
}
if (curVersion == 20) {
curVersion++;
db.execSQL(DATABASE_CREATE_LOAN);
db.execSQL(DATABASE_CREATE_INDICES);
}
if (curVersion == 21) {
//do nothing
curVersion++;
}
if (curVersion == 22) {
curVersion++;
message += "* There is a new tabbed 'edit' interface to simplify editing books.\n\n";
message += "* The new comments tab also includes a notes field where you can add personal notes for any book (Requested by Luke).\n\n";
message += "* The new loaned books tab allows you to record books loaned to friends. This will lookup your phone contacts to pre-populate the list (Requested by Luke)\n\n";
message += "* Scanned books that already exist in the database (based on ISBN) will no longer be added (Identified by Colin)\n\n";
message += "* After adding a book, the main view will now scroll to a appropriate location. \n\n";
message += "* Searching has been made significantly faster.\n\n";
}
}
}
/**
* Constructor - takes the context to allow the database to be
* opened/created
*
* @param ctx the Context within which to work
*/
public CatalogueDBAdapter(Context ctx) {
this.mCtx = ctx;
}
/**
* Open the notes database. If it cannot be opened, try to create a new
* instance of the database. If it cannot be created, throw an exception to
* signal the failure
*
* @return this (self reference, allowing this to be chained in an
* initialization call)
* @throws SQLException if the database could be neither opened or created
*/
public CatalogueDBAdapter open() throws SQLException {
/* Create the bookCatalogue directory if it does not exist */
new File(Environment.getExternalStorageDirectory() + "/" + LOCATION + "/").mkdirs();
mDbHelper = new DatabaseHelper(mCtx);
mDb = mDbHelper.getWritableDatabase();
return this;
}
public void close() {
mDbHelper.close();
}
/*
* This will return the author id based on the name.
* The name can be in either "family, given" or "given family" format.
*/
public String[] processAuthorName(String name) {
String[] author = {"", ""};
String family = "";
String given = "";
String names[];
int commaIndex = name.indexOf(",");
if (commaIndex > 0) {
family = name.substring(0, commaIndex);
given = name.substring(commaIndex+1);
} else {
names = name.split(" ");
int flen = 1;
if (names.length > 2) {
String sname = names[names.length-2];
/* e.g. Ursula Le Guin or Marianne De Pierres */
if (sname.matches("[LlDd]e")) {
family = names[names.length-2] + " ";
flen = 2;
}
}
family += names[names.length-1];
for (int i=0; i<names.length-flen; i++) {
given += names[i] + " ";
}
}
family = family.trim();
/**
* Constructor - takes the context to allow the database to be
* opened/created
*
* @param ctx the Context within which to work
*/
public CatalogueDBAdapter(Context ctx) {
this.mCtx = ctx;
}
/**
* Open the books database. If it cannot be opened, try to create a new
* instance of the database. If it cannot be created, throw an exception to
* signal the failure
*
* @return this (self reference, allowing this to be chained in an initialisation call)
* @throws SQLException if the database could be neither opened or created
*/
public CatalogueDBAdapter open() throws SQLException {
/* Create the bookCatalogue directory if it does not exist */
new File(Environment.getExternalStorageDirectory() + "/" + LOCATION + "/").mkdirs();
mDbHelper = new DatabaseHelper(mCtx);
mDb = mDbHelper.getWritableDatabase();
return this;
}
/**
* Generic function to close the database
*/
public void close() {
mDbHelper.close();
}
/**
* This will return the parsed author name based on a String.
* The name can be in either "family, given" or "given family" format.
*
* @param name a String containing the name e.g. "Isaac Asimov" or "Asimov, Isaac"
* @return a String array containing the family and given names. e.g. ['Asimov', 'Isaac']
*/
public String[] processAuthorName(String name) {
String[] author = {"", ""};
String family = "";
String given = "";
String names[];
int commaIndex = name.indexOf(",");
if (commaIndex > 0) {
family = name.substring(0, commaIndex);
given = name.substring(commaIndex+1);
} else {
names = name.split(" ");
int flen = 1;
if (names.length > 2) {
String sname = names[names.length-2];
/* e.g. Ursula Le Guin or Marianne De Pierres */
if (sname.matches("[LlDd]e")) {
family = names[names.length-2] + " ";
flen = 2;
}
}
family += names[names.length-1];
for (int i=0; i<names.length-flen; i++) {
given += names[i] + " ";
}
}
family = family.trim();
given = given.trim();
author[0] = family;
author[1] = given;
return author;
}
/*
* This will return the author id based on the name.
* The name can be in either "family, given" or "given family" format.
*/
public Cursor getBookshelfByName(String name) {
String sql = "";
author[0] = family;
author[1] = given;
return author;
}
/**
* A helper function to get a single int value (from the first row) from a cursor
*
* @param results The Cursor the extract from
* @param index The index, or column, to extract from
* @return
*/
private int getIntValue(Cursor results, int index) {
int value = 0;
try {
if (results != null) {
results.moveToFirst();
value = results.getInt(index);
}
} catch (CursorIndexOutOfBoundsException e) {
value = 0;
}
return value;
}
/**
* A helper function to get a single string value (from the first row) from a cursor
*
* @param results The Cursor the extract from
* @param index The index, or column, to extract from
* @return
*/
private String getStringValue(Cursor results, int index) {
String value = null;
try {
if (results != null) {
results.moveToFirst();
value = results.getString(index);
}
} catch (CursorIndexOutOfBoundsException e) {
value = null;
}
return value;
}
/**
* Return the position of an author in a list of all authors (within a bookshelf)
*
* @param author The author to search for
* @param bookshelf The bookshelf to search within
* @return The position of the author
*/
public int fetchAuthorPositionByName(String name, String bookshelf) {
String where = "";
String[] names = processAuthorName(name);
if (bookshelf.equals("All Books")) {
// do nothing
} else {
where += " AND a." + KEY_ROWID + " IN (SELECT " + KEY_AUTHOR + " FROM " +
DATABASE_TABLE_BOOKS + " b, " + DATABASE_TABLE_BOOKSHELF + " bs WHERE bs." + KEY_ROWID + "=b." + KEY_BOOKSHELF +
" AND bs." + KEY_BOOKSHELF + "='" + encodeString(bookshelf) + "') ";
}
String sql = "SELECT count(*) as count FROM " + DATABASE_TABLE_AUTHORS + " a " +
"WHERE a." + KEY_FAMILY_NAME + "<'" + encodeString(names[0]) + "' " +
"OR (a." + KEY_FAMILY_NAME + "='" + encodeString(names[0]) + "' AND a." + KEY_GIVEN_NAMES + "<'" + encodeString(names[1]) + "')" +
where;
Log.e("BC", sql);
Cursor results = mDb.rawQuery(sql, null);
int pos = getIntValue(results, 0);
Log.e("BC", pos + " foo");
return pos;
}
/**
* Return the position of a book in a list of all books (within a bookshelf)
*
* @param title The book title to search for
* @param bookshelf The bookshelf to search within
* @return The position of the book
*/
public int fetchBookPositionByTitle(String title, String bookshelf) {
String where = "";
if (bookshelf.equals("All Books")) {
// do nothing
} else {
where += " AND bs." + KEY_BOOKSHELF + "='" + encodeString(bookshelf) + "'";
}
String sql = "SELECT count(*) as count FROM " + DATABASE_TABLE_BOOKS + " b, " + DATABASE_TABLE_BOOKSHELF + " bs " +
"WHERE bs._id=b." + KEY_BOOKSHELF + " AND b.title < '" + encodeString(title) + "'" + where;
Log.e("BC", sql);
Cursor results = mDb.rawQuery(sql, null);
int pos = getIntValue(results, 0);
Log.e("BC", pos + " foo");
return pos;
}
/**
* This will return the author id based on the name.
* The name can be in either "family, given" or "given family" format.
*
* @param name The bookshelf name to search for
* @return A cursor containing all bookshelves with the given name
*/
public Cursor fetchBookshelfByName(String name) {
String sql = "";
sql = KEY_BOOKSHELF + "='" + encodeString(name) + "'";
return mDb.query(DATABASE_TABLE_BOOKSHELF, new String[] {"_id", KEY_BOOKSHELF}, sql, null, null, null, null);
}
/**
* This will return the borrower for a given book, if any
*
* @param mRowId The book id to search for
* @return Who the book is loaned to, can be blank.
*/
public String fetchLoanByBook(Long mRowId) {
String sql = "";
sql = KEY_BOOK + "=" + mRowId + "";
Cursor results = mDb.query(DATABASE_TABLE_LOAN, new String[] {KEY_BOOK, KEY_LOANED_TO}, sql, null, null, null, null);
String user = getStringValue(results, 1);
return user;
}
/**
* This function will create a new author in the database
*
* @param family_name A string containing the family name
* @param given_names A string containing the given names
* @return the ID of the author
*/
public long createAuthor(String family_name, String given_names) {
ContentValues initialValues = new ContentValues();
initialValues.put(KEY_FAMILY_NAME, family_name);
initialValues.put(KEY_GIVEN_NAMES, given_names);
return mDb.insert(DATABASE_TABLE_AUTHORS, null, initialValues);
}
/**
* This function will create a new loan in the database
*
* @param book The id of the book
* @param friend A string containing the friend you are loaning to
* @return the ID of the loan
*/
public long createLoan(long book, String friend) {
ContentValues initialValues = new ContentValues();
initialValues.put(KEY_BOOK, book);
initialValues.put(KEY_LOANED_TO, friend);
return mDb.insert(DATABASE_TABLE_LOAN, null, initialValues);
}
/**
* Delete the book with the given rowId
*
* @param rowId id of book to delete
* @return true if deleted, false otherwise
*/
public boolean deleteBook(long rowId) {
boolean success;
success = mDb.delete(DATABASE_TABLE_BOOKS, KEY_ROWID + "=" + rowId, null) > 0;
deleteAuthors();
return success;
}
/**
* Delete the loan with the given rowId
*
* @param rowId id of note to delete
* @return true if deleted, false otherwise
*/
public boolean deleteLoan(long rowId) {
boolean success;
success = mDb.delete(DATABASE_TABLE_LOAN, KEY_BOOK+ "=" + rowId, null) > 0;
return success;
}
sql = KEY_BOOKSHELF + "='" + encodeString(name) + "'";
return mDb.query(DATABASE_TABLE_BOOKSHELF, new String[] {"_id", KEY_BOOKSHELF}, sql, null, null, null, null);
}
/*
* This will return the author id based on the name.
* The name can be in either "family, given" or "given family" format.
@ -263,7 +506,7 @@ public class CatalogueDBAdapter {
public Cursor getAuthorByName(String name) {
String[] names = processAuthorName(name);
String sql = "";
sql = KEY_FAMILY_NAME + "='" + encodeString(names[0]) + "' AND " + KEY_GIVEN_NAMES + "='" + encodeString(names[1]) + "'";
return mDb.query(DATABASE_TABLE_AUTHORS, new String[] {"_id", KEY_FAMILY_NAME, KEY_GIVEN_NAMES}, sql, null, null, null, null);
}
@ -288,13 +531,6 @@ public class CatalogueDBAdapter {
}
public long createAuthor(String family_name, String given_names) {
ContentValues initialValues = new ContentValues();
initialValues.put(KEY_FAMILY_NAME, family_name);
initialValues.put(KEY_GIVEN_NAMES, given_names);
return mDb.insert(DATABASE_TABLE_AUTHORS, null, initialValues);
}
/**
* Create a new note using the title and body provided. If the note is
@ -319,12 +555,12 @@ public class CatalogueDBAdapter {
int bookshelf_id=1;
if (bookshelf != "") {
Cursor bookshelfId = getBookshelfByName(bookshelf);
Cursor bookshelfId = fetchBookshelfByName(bookshelf);
int bRows = bookshelfId.getCount();
if (bRows == 0) {
createBookshelf(bookshelf);
bookshelfId.close();
bookshelfId = getBookshelfByName(bookshelf);
bookshelfId = fetchBookshelfByName(bookshelf);
}
bookshelfId.moveToFirst();
bookshelf_id = bookshelfId.getInt(0);
@ -347,19 +583,6 @@ public class CatalogueDBAdapter {
return mDb.insert(DATABASE_TABLE_BOOKS, null, initialValues);
}
/**
* Delete the book with the given rowId
*
* @param rowId id of note to delete
* @return true if deleted, false otherwise
*/
public boolean deleteBook(long rowId) {
boolean success;
success = mDb.delete(DATABASE_TABLE_BOOKS, KEY_ROWID + "=" + rowId, null) > 0;
deleteAuthors();
return success;
}
/**
@ -683,12 +906,12 @@ public class CatalogueDBAdapter {
int bookshelf_id=1;
if (bookshelf != "") {
Cursor bookshelfId = getBookshelfByName(bookshelf);
Cursor bookshelfId = fetchBookshelfByName(bookshelf);
int bRows = bookshelfId.getCount();
if (bRows == 0) {
createBookshelf(bookshelf);
bookshelfId.close();
bookshelfId = getBookshelfByName(bookshelf);
bookshelfId = fetchBookshelfByName(bookshelf);
}
bookshelfId.moveToFirst();
bookshelf_id = bookshelfId.getInt(0);