diff --git a/build.gradle b/build.gradle
index 7c6b66b..e3f21bb 100644
--- a/build.gradle
+++ b/build.gradle
@@ -32,11 +32,9 @@ dependencies {
repositories {
mavenCentral()
}
-
// Espresso
- androidTestCompile('com.android.support.test.espresso:espresso-core:2.0')
- androidTestCompile('com.android.support.test:testing-support-lib:0.1')
-
+ androidTestCompile 'com.android.support.test.espresso:espresso-core:2.0'
+ androidTestCompile 'com.android.support.test:testing-support-lib:0.1'
// Robolectric
testCompile 'junit:junit:4.12'
testCompile 'org.hamcrest:hamcrest-core:1.1'
@@ -44,15 +42,13 @@ dependencies {
testCompile 'org.hamcrest:hamcrest-integration:1.1'
// https://github.com/robolectric/robolectric/issues/1369
compile 'com.android.support:support-v4:22.1.1'
-
// why is this 'compile' over 'testCompile'? Man... so weird.
// relevant: https://github.com/square/assertj-android/issues/129
compile 'com.squareup.assertj:assertj-android:1.0.0'
-
// better version of Java's HttpURLConnection
compile 'com.squareup.okhttp:okhttp:2.4.0'
compile 'com.google.code.gson:gson:2.3.1'
-
+ compile 'com.j256.ormlite:ormlite-android:4.48'
// TODO: requires special build of robolectric right now. working on this...
testCompile('org.robolectric:robolectric:2.4') {
exclude module: 'classworlds'
@@ -71,5 +67,4 @@ dependencies {
exclude module: 'wagon-http-lightweight'
exclude module: 'wagon-provider-api'
}
-
}
diff --git a/src/main/AndroidManifest.xml b/src/main/AndroidManifest.xml
index f96e9d3..a590e83 100644
--- a/src/main/AndroidManifest.xml
+++ b/src/main/AndroidManifest.xml
@@ -16,9 +16,6 @@
-
diff --git a/src/main/java/nyc/c4q/LibraryActivity.java b/src/main/java/nyc/c4q/LibraryActivity.java
index ca2a050..5e49cee 100644
--- a/src/main/java/nyc/c4q/LibraryActivity.java
+++ b/src/main/java/nyc/c4q/LibraryActivity.java
@@ -1,21 +1,108 @@
package nyc.c4q;
import android.app.Activity;
+import android.content.Context;
+import android.os.AsyncTask;
import android.os.Bundle;
+import android.util.Log;
import android.view.View;
import android.widget.EditText;
+import android.widget.TextView;
+import android.widget.Toast;
+
+import com.google.gson.Gson;
+import com.google.gson.JsonArray;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonParser;
+
+import java.io.BufferedReader;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.sql.SQLException;
+import java.util.ArrayList;
+
+import nyc.c4q.db.Book;
+import nyc.c4q.db.DatabaseHelper;
+import nyc.c4q.db.Member;
public class LibraryActivity extends Activity {
public EditText inputParameter;
+ DatabaseHelper dbHelper;
+ TextView displayInfo;
+ Context context;
+ Member member = null;
+ Book book = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_library);
+ context = this;
inputParameter = (EditText) findViewById(R.id.input_parameter);
+ dbHelper = DatabaseHelper.getInstance(this);
+ displayInfo = (TextView) findViewById(R.id.text_display);
+
+ new dbInitialize().execute();
+ }
+
+ private class dbInitialize extends AsyncTask{
+
+ @Override
+ protected Void doInBackground(Void... voids) {
+
+ //BOOKS
+ Reader reader = null;
+ InputStream stream = context.getResources()
+ .openRawResource(R.raw.books);
+ reader = new BufferedReader(new InputStreamReader(stream), 8092);
+
+ // parse json
+ JsonParser parser = new JsonParser();
+ JsonArray jsonArray = (JsonArray)parser.parse(reader);
+ ArrayList books = new ArrayList<>();
+ for(JsonElement jsonElement : jsonArray){
+ books.add(new Gson().fromJson(jsonElement, Book.class));
+ }
+ Log.d("BOOKS", "Parsed");
+
+ //MEMBERS
+ Reader memReader = null;
+ InputStream memStream = context.getResources()
+ .openRawResource(R.raw.members);
+ memReader = new BufferedReader(new InputStreamReader(memStream), 8092);
+
+ // parse json
+ JsonParser memParser = new JsonParser();
+ JsonArray memJsonArray = (JsonArray)memParser.parse(memReader);
+ ArrayList members = new ArrayList<>();
+ for(JsonElement jsonElement : memJsonArray){
+ members.add(new Gson().fromJson(jsonElement, Member.class));
+ }
+ Log.d("MEMBERS", "Parsed");
+
+ //Insert Into DB
+ for(Book book: books) {
+ try {
+ dbHelper.insertRow(book);
+ } catch (SQLException e) {
+ e.printStackTrace();
+ }
+ }
+ for(Member member: members){
+ try {
+ dbHelper.insertRow(member);
+ } catch (SQLException e) {
+ e.printStackTrace();
+ }
+ }
+ Log.d("DATABASE", "LOADED");
+
+ return null;
+ }
}
public void checkOut(int memberId, int bookId) {
@@ -34,15 +121,51 @@ public boolean checkIn(int memberId, int bookId) {
}
public void button_getMember_onClick(View view) {
- String name = inputParameter.getText().toString();
+ displayInfo.setText("");
+ final String name = inputParameter.getText().toString();
// TODO Display member information for the member with the given name.
+
+
+ try {
+ member = dbHelper.loadSpecificMember(name);
+ } catch (SQLException e) {
+ e.printStackTrace();
+ Toast.makeText(context,"SQLException error",Toast.LENGTH_SHORT).show();
+ }
+
+ if(member != null){
+ Log.d("MEMBER", member.getId() + "");
+ displayInfo.setText(member.toString());
+ }else{
+ Toast.makeText(context,"Member not found",Toast.LENGTH_SHORT).show();
+ }
+
+ inputParameter.setText("");
}
public void button_getBook_onClick(View view) {
+ displayInfo.setText("");
String isbn = inputParameter.getText().toString();
// TODO Display book information for the book with the given ISBN.
+
+
+
+ try {
+ book = dbHelper.loadSpecificBook(isbn);
+ } catch (SQLException e) {
+ e.printStackTrace();
+ }
+
+ if(book != null){
+ Log.d("BOOK", book.getId() + "");
+ displayInfo.setText(book.toString());
+ }else{
+ Toast.makeText(context,"Book not found",Toast.LENGTH_SHORT).show();
+ }
+
+ inputParameter.setText("");
}
public void button_getCheckedOut_onClick(View view) {
diff --git a/src/main/java/nyc/c4q/ListActivity.java b/src/main/java/nyc/c4q/ListActivity.java
index 08894ac..af22544 100644
--- a/src/main/java/nyc/c4q/ListActivity.java
+++ b/src/main/java/nyc/c4q/ListActivity.java
@@ -1,15 +1,27 @@
package nyc.c4q;
import android.app.Activity;
+import android.content.SharedPreferences;
import android.os.Bundle;
-import android.view.Menu;
-import android.view.MenuItem;
+import android.view.View;
+import android.widget.Button;
import android.widget.ListView;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+
public class ListActivity extends Activity {
public ListView list;
+ private ArrayList people;
+ private Button lastFirstButton, showColorButton;
+ private boolean doShowColor, displayLastFirst;
+ private static final String S_PREF = "s pref";
+ private static final String SHOW_COLOR = "show color";
+ private static final String DISPLAY_LAST_FIRST = "last name first";
+ private RosterListAdapter rosterListAdapter;
public static final Person[] PEOPLE = {
new Person("Hannah", "Abbott", House.Hufflepuff),
@@ -46,8 +58,135 @@ public class ListActivity extends Activity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_list);
+ SharedPreferences sharedPreferences = getSharedPreferences(S_PREF,MODE_PRIVATE);
+ doShowColor = sharedPreferences.getBoolean(SHOW_COLOR, true);
+ displayLastFirst = sharedPreferences.getBoolean(DISPLAY_LAST_FIRST, true);
list = (ListView) findViewById(R.id.list);
+ lastFirstButton = (Button) findViewById(R.id.button_name);
+ showColorButton = (Button) findViewById(R.id.button_color);
+ people = new ArrayList<>();
+
+ for(int i = 0; i < PEOPLE.length; i++){
+ people.add(PEOPLE[i]);
+ }
+ rosterListAdapter = new RosterListAdapter(people, doShowColor, displayLastFirst);
+ list.setAdapter(rosterListAdapter);
+ sortData();
+
+ if(!displayLastFirst){
+ lastFirstButton.setText("First Last");
+ }
+ lastFirstButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ if (lastFirstButton.getText().toString().equals("Last, First")) {
+ lastFirstButton.setText("First Last");
+ setDisplayLastFirst(false);
+ sortData();
+ } else {
+ lastFirstButton.setText("Last, First");
+ setDisplayLastFirst(true);
+ sortData();
+ }
+ }
+ });
+
+ if(!doShowColor){
+ showColorButton.setText("Hide Color");
+ }
+ showColorButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ if (showColorButton.getText().toString().equals("Show Color")) {
+ showColorButton.setText("Hide Color");
+ setShowColor(false);
+ rosterListAdapter.setDisplayColor(doShowColor);
+ } else {
+ showColorButton.setText("Show Color");
+ setShowColor(true);
+ rosterListAdapter.setDisplayColor(doShowColor);
+ }
+ }
+ });
+ }
+
+ private void setShowColor(boolean bool){
+ doShowColor = bool;
+ SharedPreferences sharedPreferences = getSharedPreferences(S_PREF, MODE_PRIVATE);
+ SharedPreferences.Editor editor = sharedPreferences.edit();
+ editor.putBoolean(SHOW_COLOR, bool);
+ editor.commit();
+ }
+
+ private void setDisplayLastFirst(boolean bool){
+ displayLastFirst = bool;
+ SharedPreferences sharedPreferences = getSharedPreferences(S_PREF, MODE_PRIVATE);
+ SharedPreferences.Editor editor = sharedPreferences.edit();
+ editor.putBoolean(DISPLAY_LAST_FIRST, bool);
+ editor.commit();
+ }
+
+ private void sortData() {
+ if(displayLastFirst)
+ sortByLastName();
+ else
+ sortByFirstName();
+
+ rosterListAdapter.setDisplayLastNameFirst(displayLastFirst);
+ }
+
+
+
+ private class lastNameComparator implements Comparator{
+
+ @Override
+ public int compare(Person person, Person t1) {
+ int length = person.lastName.length();
+ if (t1.lastName.length() <= person.lastName.length()) {
+ length = t1.lastName.length();
+ }
+ for (int i = 0; i < length; i++) {
+ int personChar = (int) person.lastName.toLowerCase().charAt(i);
+ int t1Char = (int) t1.lastName.toLowerCase().charAt(i);
+
+ if (personChar > t1Char)
+ return 1;
+ else if (personChar < t1Char)
+ return -1;
+ }
+ return 0;
+ }
}
+ private class firstNameComparator implements Comparator{
+
+ @Override
+ public int compare(Person person, Person t1) {
+ int length = person.firstName.length();
+ if (t1.firstName.length() <= person.firstName.length()) {
+ length = t1.firstName.length();
+ }
+ for (int i = 0; i < length; i++) {
+ int personChar = (int) person.firstName.toLowerCase().charAt(i);
+ int t1Char = (int) t1.firstName.toLowerCase().charAt(i);
+
+ if (personChar > t1Char)
+ return 1;
+ else if (personChar < t1Char)
+ return -1;
+ }
+ return 0;
+ }
+ }
+
+ private void sortByLastName() {
+ Collections.sort(people, new lastNameComparator());
+ }
+
+ private void sortByFirstName() {
+ Collections.sort(people, new firstNameComparator());
+ }
+
+
}
diff --git a/src/main/java/nyc/c4q/PaceCalculatorActivity.java b/src/main/java/nyc/c4q/PaceCalculatorActivity.java
index 5c0616e..9cd00cd 100644
--- a/src/main/java/nyc/c4q/PaceCalculatorActivity.java
+++ b/src/main/java/nyc/c4q/PaceCalculatorActivity.java
@@ -2,6 +2,8 @@
import android.support.v4.app.FragmentActivity;
import android.os.Bundle;
+import android.support.v4.app.FragmentManager;
+import android.support.v4.app.FragmentTransaction;
public class PaceCalculatorActivity extends FragmentActivity {
@@ -9,6 +11,12 @@ public class PaceCalculatorActivity extends FragmentActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_pace_calculator);
+
+ FragmentManager fm = getSupportFragmentManager();
+ FragmentTransaction ft = fm.beginTransaction();
+ ft.replace(R.id.activity_pace_calculator,new PaceCalculatorFragment());
+ ft.commit();
+
}
}
diff --git a/src/main/java/nyc/c4q/PaceCalculatorFragment.java b/src/main/java/nyc/c4q/PaceCalculatorFragment.java
new file mode 100644
index 0000000..1eabe97
--- /dev/null
+++ b/src/main/java/nyc/c4q/PaceCalculatorFragment.java
@@ -0,0 +1,113 @@
+package nyc.c4q;
+
+import android.os.Bundle;
+import android.support.annotation.Nullable;
+import android.support.v4.app.Fragment;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.Button;
+import android.widget.EditText;
+
+/**
+ * Created by c4q-anthonyf on 8/30/15.
+ */
+public class PaceCalculatorFragment extends Fragment {
+
+ EditText distanceET, timeMinET, timeSecET, paceMinET, paceSecET;
+ Button calculateButton;
+
+ double timeMin, timeSec, paceMin, paceSec, distance;
+
+
+ @Nullable
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
+ View root = inflater.inflate(R.layout.fragment_pace_calculator, container, false);
+
+ distanceET = (EditText) root.findViewById(R.id.input_distance);
+ timeMinET = (EditText) root.findViewById(R.id.input_time_min);
+ timeSecET = (EditText) root.findViewById(R.id.input_time_sec);
+ paceMinET = (EditText) root.findViewById(R.id.input_pace_min);
+ paceSecET = (EditText) root.findViewById(R.id.input_pace_sec);
+
+ distance = timeMin = timeSec = paceMin = paceSec = 0;
+
+ calculateButton = (Button) root.findViewById(R.id.button_calculate);
+ calculateButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ retrieveDataFromViews();
+ if(distance == 0
+ && (timeMin > 0 || timeSec > 0)
+ && (paceMin > 0 || paceSec > 0)){
+ distance = ((timeMin * 60) + timeSec)/((paceMin * 60) + paceSec);
+ distanceET.setText(distance + "");
+ }else if(paceMin == 0
+ && paceSec == 0
+ && distance > 0
+ && (timeMin > 0 || timeSec > 0)){
+ paceSec = ((timeMin * 60) + timeSec)/distance;
+ paceMin = paceSec/60;
+ paceSec = paceSec - ((int)paceMin * 60);
+
+ paceMinET.setText(paceMin + "");
+ paceSecET.setText(paceSec + "");
+ }else if(timeMin == 0 && timeSec == 0
+ && distance > 0
+ && (paceMin > 0 || paceSec > 0)){
+ timeSec = ((paceMin * 60) + paceSec) * distance;
+ timeMin = timeSec/60;
+ timeSec = timeSec - ((int)timeMin * 60);
+
+ timeMinET.setText(timeMin + "");
+ timeSecET.setText(timeSec + "");
+ }
+ }
+ });
+
+
+ return root;
+
+ }
+
+ private void retrieveDataFromViews() {
+ if(!distanceET.getText().toString().isEmpty()) {
+ try {
+ distance = Double.parseDouble(distanceET.getText().toString());
+ }catch(NumberFormatException e){
+ distance = 0;
+ }
+ }
+ if(!timeMinET.getText().toString().isEmpty()) {
+ try{
+ timeMin = Integer.parseInt(timeMinET.getText().toString());
+ }catch(NumberFormatException e){
+ timeMin = 0;
+ }
+ }
+ if(!timeSecET.getText().toString().isEmpty()) {
+ try {
+ timeSec = Integer.parseInt(timeSecET.getText().toString());
+ }catch(NumberFormatException e){
+ timeSec = 0;
+ }
+ }
+ if(!paceMinET.getText().toString().isEmpty()) {
+ try{
+ paceMin = Integer.parseInt(paceMinET.getText().toString());
+ }catch(NumberFormatException e){
+ paceMin = 0;
+ }
+ }
+ if(!paceSecET.getText().toString().isEmpty()) {
+ try{
+ paceSec = Integer.parseInt(paceSecET.getText().toString());
+ }catch(NumberFormatException e){
+ paceSec = 0;
+ }
+ }
+ }
+
+
+}
diff --git a/src/main/java/nyc/c4q/RosterListAdapter.java b/src/main/java/nyc/c4q/RosterListAdapter.java
new file mode 100644
index 0000000..2e32ac3
--- /dev/null
+++ b/src/main/java/nyc/c4q/RosterListAdapter.java
@@ -0,0 +1,99 @@
+package nyc.c4q;
+
+import android.content.Context;
+import android.graphics.drawable.ColorDrawable;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.BaseAdapter;
+import android.widget.TextView;
+
+import java.util.ArrayList;
+import java.util.Map;
+import java.util.TreeMap;
+import java.util.zip.CheckedOutputStream;
+
+
+/**
+ * Created by c4q-anthonyf on 8/30/15.
+ */
+public class RosterListAdapter extends BaseAdapter{
+
+ private ArrayList roster;
+ private boolean displayLastNameFirst;
+ private boolean doDisplayColor;
+ final Map HOUSE_COLORS;
+
+ public RosterListAdapter(ArrayList roster, boolean doDisplayColor, boolean displayLastNameFirst){
+ this.roster = roster;
+ this.doDisplayColor = doDisplayColor;
+ this.displayLastNameFirst = displayLastNameFirst;
+ HOUSE_COLORS = new TreeMap<>();
+ HOUSE_COLORS.put("Gryffindor", R.color.gryffindor_red);
+ HOUSE_COLORS.put("Ravenclaw", R.color.ravenclaw_blue);
+ HOUSE_COLORS.put("Hufflepuff", R.color.hufflepuff_yellow);
+ HOUSE_COLORS.put("Slytherin", R.color.slytherin_green);
+ }
+
+ @Override
+ public int getCount() {
+ return roster.size();
+ }
+
+ @Override
+ public Object getItem(int i) {
+ return null;
+ }
+
+ @Override
+ public long getItemId(int i) {
+ return 0;
+ }
+
+ static class ViewHolder {
+ TextView personNameTV, houseTV;
+ }
+
+ @Override
+ public View getView(int i, View view, ViewGroup viewGroup) {
+ ViewHolder v;
+ if(view == null) {
+ view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.listitem_member, viewGroup, false);
+ v = new ViewHolder();
+ v.houseTV = (TextView) view.findViewById(R.id.text_house);
+ v.personNameTV = (TextView) view.findViewById(R.id.text_name);
+ view.setTag(v);
+ }else{
+ v = (ViewHolder) view.getTag();
+ }
+
+ Person person = roster.get(i);
+
+ if(displayLastNameFirst)
+ v.personNameTV.setText(person.lastName + ", " + person.firstName);
+ else
+ v.personNameTV.setText(person.firstName + " " + person.lastName);
+ v.houseTV.setText(person.house + "");
+
+
+ if(doDisplayColor)
+ view.setBackgroundResource(HOUSE_COLORS.get(person.house + ""));
+ else
+ view.setBackgroundResource(0);
+
+ return view;
+ }
+
+ public void setDisplayLastNameFirst(boolean lastNameFirst){
+ displayLastNameFirst = lastNameFirst;
+
+ notifyDataSetChanged();
+ }
+
+ public void setDisplayColor(boolean showColor){
+ doDisplayColor = showColor;
+
+ notifyDataSetChanged();
+ }
+
+}
diff --git a/src/main/java/nyc/c4q/Unit3AssessmentActivity.java b/src/main/java/nyc/c4q/Unit3AssessmentActivity.java
index 8223094..312d92f 100644
--- a/src/main/java/nyc/c4q/Unit3AssessmentActivity.java
+++ b/src/main/java/nyc/c4q/Unit3AssessmentActivity.java
@@ -1,6 +1,8 @@
package nyc.c4q;
import android.app.Activity;
+import android.app.FragmentManager;
+import android.app.FragmentTransaction;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
diff --git a/src/main/java/nyc/c4q/db/Book.java b/src/main/java/nyc/c4q/db/Book.java
new file mode 100644
index 0000000..46b729a
--- /dev/null
+++ b/src/main/java/nyc/c4q/db/Book.java
@@ -0,0 +1,345 @@
+package nyc.c4q.db;
+
+import com.google.gson.annotations.Expose;
+import com.j256.ormlite.field.DatabaseField;
+import com.j256.ormlite.table.DatabaseTable;
+
+@DatabaseTable
+public class Book {
+
+ public static final String ID = "ID";
+ public static final String TITLE = "TITLE";
+ public static final String AUTHOR = "AUTHOR";
+ public static final String ISBN = "ISBN";
+ public static final String ISBN13 = "ISBN13";
+ @Expose
+ @DatabaseField(columnName = ID)
+ public Integer id;
+ @Expose
+ @DatabaseField(columnName = TITLE)
+ public String title;
+ @Expose
+ @DatabaseField(columnName = AUTHOR)
+ public String author;
+ @Expose
+ @DatabaseField(columnName = ISBN)
+ public String isbn;
+ @Expose
+ @DatabaseField(columnName = ISBN13)
+ public String isbn13;
+ @Expose
+ @DatabaseField
+ public String publisher;
+ @Expose
+ @DatabaseField
+ public Integer publishyear;
+ @Expose
+ @DatabaseField
+ public Boolean checkedout;
+ @Expose
+ @DatabaseField
+ public Integer checkedoutby;
+ @Expose
+ @DatabaseField
+ public Integer checkoutdateyear;
+ @Expose
+ @DatabaseField
+ public Integer checkoutdatemonth;
+ @Expose
+ @DatabaseField
+ public Integer checkoutdateday;
+ @Expose
+ @DatabaseField
+ public Integer duedateyear;
+ @Expose
+ @DatabaseField
+ public Integer duedatemonth;
+ @Expose
+ @DatabaseField
+ public Integer duedateday;
+
+ public Book(){
+
+ }
+
+ /**
+ *
+ * @return
+ * The id
+ */
+ public Integer getId() {
+ return id;
+ }
+
+ /**
+ *
+ * @param id
+ * The id
+ */
+ public void setId(Integer id) {
+ this.id = id;
+ }
+
+ /**
+ *
+ * @return
+ * The title
+ */
+ public String getTitle() {
+ return title;
+ }
+
+ /**
+ *
+ * @param title
+ * The title
+ */
+ public void setTitle(String title) {
+ this.title = title;
+ }
+
+ /**
+ *
+ * @return
+ * The author
+ */
+ public String getAuthor() {
+ return author;
+ }
+
+ /**
+ *
+ * @param author
+ * The author
+ */
+ public void setAuthor(String author) {
+ this.author = author;
+ }
+
+ /**
+ *
+ * @return
+ * The isbn
+ */
+ public String getIsbn() {
+ return isbn;
+ }
+
+ /**
+ *
+ * @param isbn
+ * The isbn
+ */
+ public void setIsbn(String isbn) {
+ this.isbn = isbn;
+ }
+
+ /**
+ *
+ * @return
+ * The isbn13
+ */
+ public String getIsbn13() {
+ return isbn13;
+ }
+
+ /**
+ *
+ * @param isbn13
+ * The isbn13
+ */
+ public void setIsbn13(String isbn13) {
+ this.isbn13 = isbn13;
+ }
+
+ /**
+ *
+ * @return
+ * The publisher
+ */
+ public String getPublisher() {
+ return publisher;
+ }
+
+ /**
+ *
+ * @param publisher
+ * The publisher
+ */
+ public void setPublisher(String publisher) {
+ this.publisher = publisher;
+ }
+
+ /**
+ *
+ * @return
+ * The publishyear
+ */
+ public Integer getPublishyear() {
+ return publishyear;
+ }
+
+ /**
+ *
+ * @param publishyear
+ * The publishyear
+ */
+ public void setPublishyear(Integer publishyear) {
+ this.publishyear = publishyear;
+ }
+
+ /**
+ *
+ * @return
+ * The checkedout
+ */
+ public Boolean getCheckedout() {
+ return checkedout;
+ }
+
+ /**
+ *
+ * @param checkedout
+ * The checkedout
+ */
+ public void setCheckedout(Boolean checkedout) {
+ this.checkedout = checkedout;
+ }
+
+ /**
+ *
+ * @return
+ * The checkedoutby
+ */
+ public Integer getCheckedoutby() {
+ return checkedoutby;
+ }
+
+ /**
+ *
+ * @param checkedoutby
+ * The checkedoutby
+ */
+ public void setCheckedoutby(Integer checkedoutby) {
+ this.checkedoutby = checkedoutby;
+ }
+
+ /**
+ *
+ * @return
+ * The checkoutdateyear
+ */
+ public Integer getCheckoutdateyear() {
+ return checkoutdateyear;
+ }
+
+ /**
+ *
+ * @param checkoutdateyear
+ * The checkoutdateyear
+ */
+ public void setCheckoutdateyear(Integer checkoutdateyear) {
+ this.checkoutdateyear = checkoutdateyear;
+ }
+
+ /**
+ *
+ * @return
+ * The checkoutdatemonth
+ */
+ public Integer getCheckoutdatemonth() {
+ return checkoutdatemonth;
+ }
+
+ /**
+ *
+ * @param checkoutdatemonth
+ * The checkoutdatemonth
+ */
+ public void setCheckoutdatemonth(Integer checkoutdatemonth) {
+ this.checkoutdatemonth = checkoutdatemonth;
+ }
+
+ /**
+ *
+ * @return
+ * The checkoutdateday
+ */
+ public Integer getCheckoutdateday() {
+ return checkoutdateday;
+ }
+
+ /**
+ *
+ * @param checkoutdateday
+ * The checkoutdateday
+ */
+ public void setCheckoutdateday(Integer checkoutdateday) {
+ this.checkoutdateday = checkoutdateday;
+ }
+
+ /**
+ *
+ * @return
+ * The duedateyear
+ */
+ public Integer getDuedateyear() {
+ return duedateyear;
+ }
+
+ /**
+ *
+ * @param duedateyear
+ * The duedateyear
+ */
+ public void setDuedateyear(Integer duedateyear) {
+ this.duedateyear = duedateyear;
+ }
+
+ /**
+ *
+ * @return
+ * The duedatemonth
+ */
+ public Integer getDuedatemonth() {
+ return duedatemonth;
+ }
+
+ /**
+ *
+ * @param duedatemonth
+ * The duedatemonth
+ */
+ public void setDuedatemonth(Integer duedatemonth) {
+ this.duedatemonth = duedatemonth;
+ }
+
+ /**
+ *
+ * @return
+ * The duedateday
+ */
+ public Integer getDuedateday() {
+ return duedateday;
+ }
+
+ /**
+ *
+ * @param duedateday
+ * The duedateday
+ */
+ public void setDuedateday(Integer duedateday) {
+ this.duedateday = duedateday;
+ }
+
+ @Override
+ public String toString() {
+ return "id: " + id +
+ "\ntitle: " + title +
+ "\nauthor: " + author +
+ "\nisbn: " + isbn +
+ "\nisbn13: " + isbn13 +
+ "\npublisher: " + publisher +
+ "\npublication year: " + publishyear;
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/nyc/c4q/db/DatabaseHelper.java b/src/main/java/nyc/c4q/db/DatabaseHelper.java
new file mode 100644
index 0000000..3fa693f
--- /dev/null
+++ b/src/main/java/nyc/c4q/db/DatabaseHelper.java
@@ -0,0 +1,81 @@
+package nyc.c4q.db;
+
+import android.content.Context;
+import android.database.sqlite.SQLiteDatabase;
+
+import com.j256.ormlite.android.apptools.OrmLiteSqliteOpenHelper;
+import com.j256.ormlite.support.ConnectionSource;
+import com.j256.ormlite.table.TableUtils;
+
+import java.sql.SQLException;
+
+/**
+ * Created by c4q-anthonyf on 8/30/15.
+ */
+public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
+
+ private final static int VERSION = 1;
+ private final static String MYDB = "MyDb";
+
+ private static DatabaseHelper mHelper;
+
+ public DatabaseHelper(Context context) {
+ super(context, MYDB, null, VERSION);
+ }
+
+ public static synchronized DatabaseHelper getInstance(Context context){
+
+ if(mHelper == null){
+ mHelper = new DatabaseHelper(context.getApplicationContext());
+ }
+
+ return mHelper;
+
+ }
+
+ @Override
+ public void onCreate(SQLiteDatabase database, ConnectionSource connectionSource) {
+
+ try {
+ TableUtils.createTable(connectionSource, Book.class);
+ TableUtils.createTable(connectionSource, Member.class);
+ } catch (SQLException e) {
+ e.printStackTrace();
+ }
+ }
+
+ @Override
+ public void onUpgrade(SQLiteDatabase database, ConnectionSource connectionSource, int oldVersion, int newVersion) {
+ try {
+ TableUtils.dropTable(connectionSource, Book.class, true);
+ TableUtils.dropTable(connectionSource, Member.class, true);
+ onCreate(database, connectionSource);
+ } catch (SQLException e) {
+ e.printStackTrace();
+ }
+ }
+
+ public Member loadSpecificMember(String name) throws SQLException, java.sql.SQLException {
+ return getDao(Member.class)
+ .queryBuilder()
+ .where().eq("NAME", name)
+ .queryForFirst();
+ }
+
+ public Book loadSpecificBook(String isbn) throws SQLException, java.sql.SQLException {
+ return getDao(Book.class)
+ .queryBuilder()
+ .where().eq("ISBN", isbn)
+ .queryForFirst();
+ }
+
+ public void insertRow(Book book) throws SQLException {
+ getDao(Book.class).create(book);
+ }
+
+ public void insertRow(Member member) throws SQLException {
+ getDao(Member.class).create(member);
+ }
+
+}
+
diff --git a/src/main/java/nyc/c4q/db/Member.java b/src/main/java/nyc/c4q/db/Member.java
new file mode 100644
index 0000000..2263db0
--- /dev/null
+++ b/src/main/java/nyc/c4q/db/Member.java
@@ -0,0 +1,175 @@
+package nyc.c4q.db;
+
+import com.google.gson.annotations.Expose;
+import com.google.gson.annotations.SerializedName;
+import com.j256.ormlite.field.DatabaseField;
+import com.j256.ormlite.table.DatabaseTable;
+
+@DatabaseTable
+public class Member {
+
+ public static final String NAME = "NAME";
+
+ @Expose
+ @DatabaseField
+ public Integer id;
+ @Expose
+ @DatabaseField(columnName = NAME)
+ public String name;
+ @SerializedName("dob_month")
+ @Expose
+ @DatabaseField
+ public Integer dobMonth;
+ @SerializedName("dob_day")
+ @Expose
+ @DatabaseField
+ public Integer dobDay;
+ @SerializedName("dob_year")
+ @Expose
+ @DatabaseField
+ public Integer dobYear;
+ @Expose
+ @DatabaseField
+ public String city;
+ @Expose
+ @DatabaseField
+ public String state;
+
+ public Member(){
+
+ }
+
+ /**
+ *
+ * @return
+ * The id
+ */
+ public Integer getId() {
+ return id;
+ }
+
+ /**
+ *
+ * @param id
+ * The id
+ */
+ public void setId(Integer id) {
+ this.id = id;
+ }
+
+ /**
+ *
+ * @return
+ * The name
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ *
+ * @param name
+ * The name
+ */
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ /**
+ *
+ * @return
+ * The dobMonth
+ */
+ public Integer getDobMonth() {
+ return dobMonth;
+ }
+
+ /**
+ *
+ * @param dobMonth
+ * The dob_month
+ */
+ public void setDobMonth(Integer dobMonth) {
+ this.dobMonth = dobMonth;
+ }
+
+ /**
+ *
+ * @return
+ * The dobDay
+ */
+ public Integer getDobDay() {
+ return dobDay;
+ }
+
+ /**
+ *
+ * @param dobDay
+ * The dob_day
+ */
+ public void setDobDay(Integer dobDay) {
+ this.dobDay = dobDay;
+ }
+
+ /**
+ *
+ * @return
+ * The dobYear
+ */
+ public Integer getDobYear() {
+ return dobYear;
+ }
+
+ /**
+ *
+ * @param dobYear
+ * The dob_year
+ */
+ public void setDobYear(Integer dobYear) {
+ this.dobYear = dobYear;
+ }
+
+ /**
+ *
+ * @return
+ * The city
+ */
+ public String getCity() {
+ return city;
+ }
+
+ /**
+ *
+ * @param city
+ * The city
+ */
+ public void setCity(String city) {
+ this.city = city;
+ }
+
+ /**
+ *
+ * @return
+ * The state
+ */
+ public String getState() {
+ return state;
+ }
+
+ /**
+ *
+ * @param state
+ * The state
+ */
+ public void setState(String state) {
+ this.state = state;
+ }
+
+ @Override
+ public String toString() {
+ return "id: " + id +
+ "\nname: " + name +
+ "\ndob: " + dobDay+"/"+dobMonth+"/"+dobYear +
+ "\nlocation: " + city + ", " + state;
+ }
+}
\ No newline at end of file
diff --git a/src/main/res/raw/books.json b/src/main/res/raw/books.json
index 8cc9673..79b378e 100644
--- a/src/main/res/raw/books.json
+++ b/src/main/res/raw/books.json
@@ -838,7 +838,7 @@
"isbn": "0439554934",
"isbn13": "9780439554930",
"publisher": "Scholastic",
- "publishyear": 2003.
+ "publishyear": 2003,
"checkedout": true,
"checkedoutby": 38,
"checkoutdateyear": 2015,