Skip to content
This repository has been archived by the owner on Apr 20, 2019. It is now read-only.

Anna_FinalAssessment #7

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ dependencies {
// 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') {
Expand Down
87 changes: 87 additions & 0 deletions src/main/java/nyc/c4q/Books.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package nyc.c4q;

import com.j256.ormlite.field.DatabaseField;
import com.j256.ormlite.table.DatabaseTable;

@DatabaseTable
public class Books {
@DatabaseField(generatedId = true)
private int id = 1;
@DatabaseField
private String title;
@DatabaseField
private String author;
@DatabaseField
private long isbn;
@DatabaseField
private long isbn13;
@DatabaseField
private String publisher;
@DatabaseField
private int publishyear;

public Books(String title, String author, String isbn, String isbn13, String publisher, int publishyear) {
this.title = title;
this.author = author;
this.isbn = isbn;
this.isbn13 = isbn13;
this.publisher = publisher;
this.publishyear = publishyear;
}

public int getId() {
return id;
}

public void setId(int id) {
this.id = id;
}

public String getTitle() {
return title;
}

public void setTitle(String title) {
this.title = title;
}

public String getAuthor() {
return author;
}

public void setAuthor(String author) {
this.author = author;
}

public long getIsbn() {
return isbn;
}

public void setIsbn(long isbn) {
this.isbn = isbn;
}

public long getIsbn13() {
return isbn13;
}

public void setIsbn13(long isbn13) {
this.isbn13 = isbn13;
}

public String getPublisher() {
return publisher;
}

public void setPublisher(String publisher) {
this.publisher = publisher;
}

public int getPublishyear() {
return publishyear;
}

public void setPublishyear(int publishyear) {
this.publishyear = publishyear;
}
}
33 changes: 33 additions & 0 deletions src/main/java/nyc/c4q/CustomAdapter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package nyc.c4q;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

/**
* Created on 8/30/15.
*/
class CustomAdapter extends ArrayAdapter<Person> {

CustomAdapter(Context context, Person[] PEOPLE) {
super(context, R.layout.listitem_member, PEOPLE);
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater personInflater = LayoutInflater.from(getContext());
View customView = personInflater.inflate(R.layout.listitem_member, parent, false);

Person name = getItem(position);
TextView personName = (TextView) customView.findViewById(R.id.text_name);
Person house = getItem(position);
TextView personHouse = (TextView)customView.findViewById(R.id.text_house);

personName.setText((CharSequence) name);
personHouse.setText((CharSequence) house);
return convertView;
}
}
81 changes: 81 additions & 0 deletions src/main/java/nyc/c4q/DatabaseHelper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package nyc.c4q;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.os.Build;

import com.j256.ormlite.android.apptools.OrmLiteSqliteOpenHelper;
import com.j256.ormlite.dao.Dao;
import com.j256.ormlite.support.ConnectionSource;
import com.j256.ormlite.table.TableUtils;

import java.sql.SQLException;
import java.util.List;

public class DatabaseHelper extends OrmLiteSqliteOpenHelper {

private static final String MYDB = "mydb.db";
private static final int VERSION = 1;
private static DatabaseHelper mHelper;

private DatabaseHelper getInstance(Context context) {
if (mHelper == null) {
mHelper = new DatabaseHelper(context.getApplicationContext());
return mHelper;
}
return mHelper;
}

public DatabaseHelper(Context context) {
super(context, MYDB, null, VERSION);
}

@Override
public void onCreate(SQLiteDatabase database, ConnectionSource connectionSource) {
try {
TableUtils.createTable(connectionSource, Books.class);
TableUtils.createTable(connectionSource, Members.class);
} catch (SQLException e) {
throw new RuntimeException(e);
}
}

@Override
public void onUpgrade(SQLiteDatabase database, ConnectionSource connectionSource, int oldVersion, int newVersion) {
try {
TableUtils.dropTable(connectionSource, Books.class, true);
TableUtils.dropTable(connectionSource, Members.class, true);
onCreate(database, connectionSource);
} catch (SQLException e) {
throw new RuntimeException(e);
}
}

public void insertMemberRow(int id, String name, int dob_month, int dob_day, int dob_year, String city, String state) {
Members member = new Members( name, dob_month, dob_day, dob_year, city, state);
try {
getDao(Members.class).create(member);
} catch (SQLException e) {
e.printStackTrace();
}
}

public void insertBookRow(int id, String title, String author, String isbn, String isbn13, String publisher, int publishyear) {
Books book = new Books( title, author, isbn, isbn13, publisher, publishyear);
try {
getDao(Books.class).create(book);
} catch (SQLException e) {
e.printStackTrace();
}
}

public List<Books> loadBookData() throws SQLException {
List<Books> isbn = getDao(Books.class).queryForAll();
return isbn;
}

public List<Members> loadMemberData() throws SQLException {
List<Members> name = getDao(Members.class).queryForAll();
return name;
}
}
73 changes: 73 additions & 0 deletions src/main/java/nyc/c4q/FragmentCalculator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package nyc.c4q;

import android.os.Bundle;
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 on 8/30/15.
*/
public class FragmentCalculator extends Fragment {

EditText distance, time_min, time_sec, pace_min, pace_sec;
Button calculate;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_pace_calculator, container, false);

distance = (EditText)view.findViewById(R.id.input_distance);
time_min = (EditText)view.findViewById(R.id.input_time_min);
time_sec = (EditText)view.findViewById(R.id.input_time_sec);
pace_min = (EditText)view.findViewById(R.id.input_pace_min);
pace_sec = (EditText)view.findViewById(R.id.input_pace_sec);
calculate = (Button)view.findViewById(R.id.button_calculate);

calculate.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

double distan = Integer.parseInt(FragmentCalculator.this.distance.getText().toString());
int numTimeMin = Integer.parseInt(time_min.getText().toString());
int numTimeSec = (int) (Integer.parseInt(time_sec.getText().toString()) * 0.01);
int numPaceMin = Integer.parseInt(pace_min.getText().toString());
int numPaceSec = (int) (Integer.parseInt(pace_sec.getText().toString()) * 0.01);

double time = numTimeMin + numTimeSec;
double pace = numPaceMin + numPaceSec;

if (time >1 && pace >1) {
FragmentCalculator.this.distance.setText(time / pace + "");
}
else if (time >1 && distan>1){
pace_min.setText((int)time/distan+"");
pace_sec.setText(((time/distan)-(int)(time/distan))+"");
}
else if (pace >1 && distan>1){
time_min.setText((int)pace*distan+"");
time_sec.setText((pace*distan)-(int)pace*distan+"");
}
else if (time==0||pace==0||distan==0||time==1||pace==1||distan==1){
distance.setText("");
time_min.setText("");
time_sec.setText("");
pace_min.setText("");
pace_sec.setText("");
}
else {
distance.setText("");
time_min.setText("");
time_sec.setText("");
pace_min.setText("");
pace_sec.setText("");
}
}
});


return view;
}
}
39 changes: 39 additions & 0 deletions src/main/java/nyc/c4q/LibraryActivity.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
package nyc.c4q;

import android.app.Activity;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;

import com.google.gson.JsonArray;

import org.json.JSONException;
import org.json.JSONObject;


public class LibraryActivity extends Activity {

public EditText inputParameter;
private DatabaseHelper mHelper;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -18,6 +25,38 @@ protected void onCreate(Bundle savedInstanceState) {
inputParameter = (EditText) findViewById(R.id.input_parameter);
}

private class MyDatabaseTask extends AsyncTask<Void, Void, Void> {
@Override
protected Void doInBackground(Void... params) {
mHelper = DatabaseHelper.getInstance(getApplicationContext());
if (mHelper.fetchAllBooks() == null) {
JsonArray bookArray = new JsonArray();
for (int i =0; i<bookArray.size();i++){
JSONObject jsonObject = bookArray.getJsonObject(i);
try {
String title = jsonObject.getString("title");
String author = jsonObject.getString("author");
long isbn = jsonObject.getLong("isbn");
long isbn13 = jsonObject.getLong("isbn13");
String publisher = jsonObject.getString("publisher");
int publishyear = jsonObject.getInt("publishyear");

} catch (JSONException e) {
e.printStackTrace();
}


}
}
return null;
}

@Override
protected void onPostExecute(Void aVoid) {
super.onPostExecute(aVoid);
}
}

public void checkOut(int memberId, int bookId) {
// TODO This method is called when the member with the given ID checks
// out the book with the given ID. Update the system accordingly.
Expand Down
Loading