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

pushing #13

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
7 changes: 1 addition & 6 deletions src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -16,12 +16,7 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".ListViewActivity"
android:windowSoftInputMode="adjustPan" />
<activity android:name=".NetworkActivity" />
<activity android:name=".JSONActivity" />
<activity android:name=".NotificationActivity" />

<activity
android:name=".PaceCalculatorActivity"
android:label="@string/title_activity_pace_calculator"
235 changes: 235 additions & 0 deletions src/main/java/nyc/c4q/DBAdapter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,235 @@
package nyc.c4q;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.widget.Toast;

import java.util.ArrayList;

/**
* Created by c4q-madelyntavarez on 8/30/15.
*/
public class DBAdapter {
DBHelper dbHelper;

public DBAdapter(Context context){
dbHelper = new DBHelper(context);
}
public long insertMemberData(int id, String name, String city, String state, int month, int day, int year) {
SQLiteDatabase db = dbHelper.getWritableDatabase();
ContentValues contentValues = new ContentValues();

contentValues.put(DBHelper.FOREIGNID,id);
contentValues.put(DBHelper.NAME, name);
contentValues.put(DBHelper.CITY, city);
contentValues.put(DBHelper.MONTH,month);
contentValues.put(DBHelper.DAY,day);
contentValues.put(DBHelper.YEAR,year);
contentValues.put(DBHelper.STATE, state);

long id1 = db.insert(DBHelper.TABLE_NAME, null, contentValues);

return id1;
}

public long insertBookData(int id, String title, String author, String isbn, String isbn13, String publisher, int pushlisherYear, boolean isCheckedOut,
int checkedOutBy, int checkoutYear, int checkOutMonth, int checkOutDay, int dueDateYear, int dueDateMonth, int
dueDateDay){
SQLiteDatabase db = dbHelper.getWritableDatabase();
ContentValues contentValues = new ContentValues();

contentValues.put(DBHelper.FOREIGNID,id);
contentValues.put(DBHelper.TITLE,title);
contentValues.put(DBHelper.AUTHOR,author);
contentValues.put(DBHelper.ISBN,isbn);
contentValues.put(DBHelper.ISBN13,isbn13);
contentValues.put(DBHelper.PUBLISHER,publisher);
contentValues.put(DBHelper.PUBLISHERYEAR,pushlisherYear);
contentValues.put(DBHelper.ISCHECKEDOUT,isCheckedOut);
contentValues.put(DBHelper.CHECKEDOUTBY,checkedOutBy);
contentValues.put(DBHelper.CHECKOUTYEAR,checkoutYear);
contentValues.put(DBHelper.CHECKOUTMONTH,checkOutMonth);
contentValues.put(DBHelper.CHECKOUTDAY,checkOutDay);
contentValues.put(DBHelper.DUEYEAR,dueDateYear);
contentValues.put(DBHelper.DUEMONTH,dueDateMonth);
contentValues.put(DBHelper.DUEDAY,dueDateDay);

long id2=db.insert(DBHelper.TABLE_NAME_2,null,contentValues);
return id2;
}
public String getDataForMember(String name) {
SQLiteDatabase dbs = dbHelper.getWritableDatabase();
String[] columns = {DBHelper.UID, DBHelper.NAME, DBHelper.CITY, DBHelper.STATE, DBHelper.MONTH,DBHelper.DAY,DBHelper.YEAR,DBHelper.FOREIGNID};
Cursor cursor = dbs.query(DBHelper.TABLE_NAME, columns, DBHelper.NAME + " = '" + name + "'", null, null, null, null);

StringBuffer buffer = new StringBuffer();
while (cursor.moveToNext()) {
int index1=cursor.getColumnIndex(DBHelper.FOREIGNID);
int index2 = cursor.getColumnIndex(DBHelper.NAME);
int index3 = cursor.getColumnIndex(DBHelper.CITY);
int index4= cursor.getColumnIndex(DBHelper.STATE);
int index5=cursor.getColumnIndex(DBHelper.MONTH);
int index6=cursor.getColumnIndex(DBHelper.DAY);
int index7=cursor.getColumnIndex(DBHelper.YEAR);
int userID=cursor.getInt(index1);
String userName = cursor.getString(index2);
String userCityAndState = cursor.getString(index3)+", " +cursor.getString(index4);
String dob=cursor.getInt(index5)+"/"+cursor.getInt(index6)+"/"+cursor.getInt(index7);

buffer.append("id: "+userID+"\n name: "+userName + "\n dob: " + dob + "\n location: "+userCityAndState);

}
return buffer.toString();
}

public String getBookInfo(String ISBN){

SQLiteDatabase dbs = dbHelper.getWritableDatabase();
String[] columns = {DBHelper.UID, DBHelper.TITLE, DBHelper.ISBN, DBHelper.ISBN13, DBHelper.PUBLISHER,DBHelper.PUBLISHERYEAR,DBHelper.ISCHECKEDOUT, DBHelper.CHECKOUTYEAR,DBHelper.CHECKOUTMONTH,
DBHelper.CHECKOUTDAY,DBHelper.DUEYEAR,DBHelper.DUEMONTH,DBHelper.DUEYEAR,DBHelper.FOREIGNID};

Cursor cursor = dbs.query(DBHelper.TABLE_NAME, columns, DBHelper.ISBN + " = '" + ISBN + "'", null, null, null, null);

StringBuffer buffer = new StringBuffer();
while (cursor.moveToNext()) {
int index1=cursor.getColumnIndex(DBHelper.FOREIGNID);
int index2 = cursor.getColumnIndex(DBHelper.TITLE);
int index17=cursor.getColumnIndex(DBHelper.AUTHOR);
int index3 = cursor.getColumnIndex(DBHelper.ISBN);
int index4= cursor.getColumnIndex(DBHelper.ISBN13);
int index5=cursor.getColumnIndex(DBHelper.PUBLISHER);
int index6=cursor.getColumnIndex(DBHelper.PUBLISHERYEAR);

int userID=cursor.getInt(index1);
String title = cursor.getString(index2);
String author=cursor.getString(index17);
long isbn=cursor.getLong(index3);
long isbn13=cursor.getLong(index4);
String publisher=cursor.getString(index5);
long publicationYear=cursor.getLong(index6);

buffer.append("id: "+userID+"\n title: "+title + "\n author: " + author + "\n isbn: "+isbn+"\n" +
"isbn13: "+isbn13+"\n publisher: "+publisher+"\n publication year: "+publicationYear);

}
return buffer.toString();
}

public ArrayList<String> getCurrentlyCheckedOut(String name){
int UID = 0;
SQLiteDatabase dbs = dbHelper.getWritableDatabase();
String[] columns = {DBHelper.UID, DBHelper.NAME, DBHelper.CITY, DBHelper.STATE, DBHelper.MONTH,DBHelper.DAY,DBHelper.YEAR,DBHelper.FOREIGNID};

Cursor cursor = dbs.query(DBHelper.TABLE_NAME, columns, DBHelper.NAME + " = '" + name + "'", null, null, null, null);
StringBuffer buffer = new StringBuffer();
while (cursor.moveToNext()) {
int index1=cursor.getColumnIndex(DBHelper.FOREIGNID);
UID=cursor.getInt(index1);
}

SQLiteDatabase dbs1 = dbHelper.getWritableDatabase();
String[] columns1 = {DBHelper.UID, DBHelper.TITLE, DBHelper.ISBN, DBHelper.ISBN13, DBHelper.PUBLISHER,DBHelper.PUBLISHERYEAR,DBHelper.ISCHECKEDOUT, DBHelper.CHECKOUTYEAR,DBHelper.CHECKOUTMONTH,
DBHelper.CHECKOUTDAY,DBHelper.DUEYEAR,DBHelper.DUEMONTH,DBHelper.DUEYEAR};

Cursor cursor1 = dbs1.query(DBHelper.TABLE_NAME_2, columns1, DBHelper.CHECKEDOUTBY + " = '" + UID + "'", null, null, null, null);

StringBuffer buffer1 = new StringBuffer();


ArrayList<String> arrayList=new ArrayList<>();
while (cursor1.moveToNext()) {
int index1=cursor1.getColumnIndex(DBHelper.UID);
int index2 = cursor1.getColumnIndex(DBHelper.TITLE);
int index17=cursor1.getColumnIndex(DBHelper.AUTHOR);
int index3 = cursor1.getColumnIndex(DBHelper.ISBN);
int index4= cursor1.getColumnIndex(DBHelper.ISBN13);
int index5=cursor1.getColumnIndex(DBHelper.PUBLISHER);
int index6=cursor1.getColumnIndex(DBHelper.PUBLISHERYEAR);
int index7=cursor1.getColumnIndex(DBHelper.ISCHECKEDOUT);
int index8=cursor1.getColumnIndex(DBHelper.CHECKEDOUTBY);
int index9=cursor1.getColumnIndex(DBHelper.CHECKOUTYEAR);
int index10=cursor1.getColumnIndex(DBHelper.CHECKOUTMONTH);
int index11=cursor1.getColumnIndex(DBHelper.CHECKOUTDAY);
int index12=cursor1.getColumnIndex(DBHelper.DUEYEAR);
int index13=cursor1.getColumnIndex(DBHelper.DUEMONTH);
int index14= cursor1.getColumnIndex(DBHelper.DUEDAY);

String title = cursor1.getString(index2);
String author=cursor1.getString(index17);
String checkOutDate=cursor1.getInt(index10)+"/"+cursor1.getInt(index11)+"/"+cursor1.getInt(index9);
String dueDate=cursor1.getInt(index13)+"/"+cursor1.getInt(index14)+"/"+cursor1.getInt(index12);

String all="name: "+name+"title: "+title + "\n author: " + author + "\n checkout date: "+checkOutDate+"\n" +
"Due Date: "+dueDate;

arrayList.add(all);
}


return arrayList;
}

static class DBHelper extends SQLiteOpenHelper {
private static final String DATABASE_NAME = "LibraryDatabase";
private static String TABLE_NAME = "LibraryBooks";
private static String TABLE_NAME_2 = "LibraryMembers";
private static int DATABASE_VERSION = 1;
private static final String UID = "_id";
private Context context;
private static final String CITY = "City";
private static final String STATE = "State";
private static final String DROP_TABLE = "DROP TABLE IF EXISTS " + TABLE_NAME;
private static final String NAME = "Name";
private static final String MONTH="Month";
private static final String DAY="Day";
private static final String YEAR="Year";
private static final String TITLE="Title";
private static final String ISBN="ISBN";
private static final String AUTHOR="Author";
private static final String ISBN13="ISBN13";
private static final String PUBLISHER="Publisher";
private static final String ISCHECKEDOUT="IsCheckedOut";
private static final String PUBLISHERYEAR="PublisherYear";
private static final String CHECKEDOUTBY="CheckedOutBy";
private static final String CHECKOUTYEAR="CheckoutYear";
private static final String CHECKOUTMONTH="CheckoutMonth";
private static final String CHECKOUTDAY="CheckoutDay";
private static final String DUEYEAR="DueYear";
private static final String DUEMONTH="DueMonth";
private static final String DUEDAY="DueDay";
private static final String FOREIGNID="ForeignID";
private static final String CREATE_MEMBER_TABLE = "Create table " + TABLE_NAME + " (" + UID + " INTEGER PRIMARY KEY AUTOINCREMENT, " + NAME
+ " VARCHAR(255), " + CITY + " VARCHAR (255), "+STATE + " VARCHAR (255), "+ MONTH + " INTEGER, " + DAY + " INTEGER, " + YEAR + " LONG, " + FOREIGNID + " INTEGER);";

private static final String CREATE_BOOK_TABLE = "Create table "+ TABLE_NAME_2+" ("+ UID+" INTEGER PRIMARY KEY AUTOINCREMENT, " + TITLE + " VARCHAR (255), "+ ISBN + " VARCHAR (255), "+ ISBN13 + " VARCHAR (255), "+
PUBLISHER + " VARCHAR (255), "+ PUBLISHERYEAR + " INTEGER, " + ISCHECKEDOUT+ " INTEGER, " + CHECKEDOUTBY + " INTEGER, " + CHECKOUTYEAR + " INTEGER, " + CHECKOUTMONTH + " INTEGER, " + CHECKOUTDAY + " INTEGER, " +
DUEYEAR + " INTEGER, " + DUEMONTH + " INTEGER, " + DUEDAY + " INTEGER, "+ FOREIGNID + " INTEGER);";

public DBHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
this.context = context;
Toast.makeText(context,"Constructor Called",Toast.LENGTH_LONG).show();
}

@Override
public void onCreate(SQLiteDatabase db) {
Toast.makeText(context, "OnCreate Was Called", Toast.LENGTH_LONG).show();

db.execSQL(CREATE_MEMBER_TABLE);
db.execSQL(CREATE_BOOK_TABLE);
}

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
Toast.makeText(context, "ONUPGRADE Was Called",Toast.LENGTH_LONG).show();
db.execSQL(DROP_TABLE);
onCreate(db);


}
}
}

195 changes: 195 additions & 0 deletions src/main/java/nyc/c4q/ExampleFragment.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
package nyc.c4q;


import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import java.util.ArrayList;

/**
* A simple {@link Fragment} subclass.
*/
public class ExampleFragment extends android.support.v4.app.Fragment {
EditText distanceText;
EditText timeMin;
EditText timeSec;
EditText paceMin;
EditText paceSec;
Button calculate;
ArrayList<Integer> integerArrayList;
int distanceInput;
int timeMinInput ;
int timeSecInput ;
int paceMinInput ;
int paceSecInput ;

public ExampleFragment() {
// Required empty public constructor
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view= inflater.inflate(R.layout.fragment_pace_calculator,null);
distanceText= (EditText) view.findViewById(R.id.input_distance);
timeMin=(EditText) view.findViewById(R.id.input_time_min);
timeSec= (EditText) view.findViewById(R.id.input_time_sec);
paceMin=(EditText) view.findViewById(R.id.input_pace_min);
paceSec=(EditText) view.findViewById(R.id.input_pace_sec);
calculate=(Button) view.findViewById(R.id.button_calculate);
try{
String distanceInputString = distanceText.getText().toString();
String timeMinInputString = timeMin.getText().toString();
String timeSecInputString = timeSec.getText().toString();
String paceMinInputString =paceMin.getText().toString();
String paceSecInputString = paceSec.getText().toString();

timeMinInput= Integer.parseInt(timeMinInputString);
timeSecInput= Integer.parseInt(timeSecInputString);
paceMinInput= Integer.parseInt(paceMinInputString);
paceSecInput= Integer.parseInt(paceSecInputString);
distanceInput= Integer.parseInt(distanceInputString);


String totalTimeString=timeMinInput+"."+timeSecInput;
double totalTime= Double.parseDouble(totalTimeString);

String totalPaceString=paceMinInput+"."+paceSecInput;
double totalPace= Double.parseDouble(totalPaceString);

integerArrayList=new ArrayList<>();
integerArrayList.add(timeMinInput);
integerArrayList.add(timeSecInput);
integerArrayList.add(paceMinInput);
integerArrayList.add(paceSecInput);
integerArrayList.add(distanceInput);
}catch(NumberFormatException ex){ // handle your exception
Toast.makeText(getActivity(),"Invalid Input",Toast.LENGTH_LONG).show();
}




calculate.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int numNull = 0;
int numWithInput = 0;
if(integerArrayList!=null) {
for (Integer input : integerArrayList) {
if (input == null) {
numNull++;
}
if (input != null) {
numWithInput++;
}
}

if (numWithInput == 0 || numWithInput == 1 || numWithInput == 5) {
}

if (numNull > 3) {
}
}

if (distanceText.getText() != null && timeMin.getText() != null && paceMin != null) {
}

if (distanceText.getText() != null && timeMin.getText() != null && paceSec.getText() != null) {
}

if (distanceText.getText() != null && timeSec.getText() != null && paceSec.getText() != null) {
}

if (distanceText.getText() != null && timeSec.getText() != null && paceMin.getText() != null) {
}

if (distanceText.getText() != null) {
if (timeMin.getText() != null || timeSec.getText() != null) {
calculatePace(timeMinInput, timeSecInput, distanceInput);
}
if (paceMin.getText() != null || timeSec.getText() != null) {
calculateTime(paceMinInput, paceSecInput, distanceInput);
}
}
if(distanceText.getText()==null) {
if (timeMin.getText() != null || timeSec.getText() != null) {
if (paceMin.getText() != null || paceSec.getText() != null) {
calculateDistance(timeMinInput, timeSecInput, paceMinInput, paceSecInput);
}
}
}

}
});

return view;
}

public void calculatePace(int timeMin, int timeSec, int distance) {

String actualTimeString=timeMin+"."+timeSec;

double actualTimeWithSeconds= Double.parseDouble(actualTimeString);

double pace= distance/actualTimeWithSeconds;

String paceString= String.valueOf(pace);

if(paceString.contains(".")) {
String[] splitPace = paceString.split(".");
paceMin.setText(splitPace[0]);
paceMin.setText(splitPace[1]);
} else{
paceMin.setText(String.valueOf(pace));
}
}

public void calculateDistance(int timeMin, int timeSec, int paceMin, int paceSec){
try {
String totalTimeString=timeMin+"."+timeSec;

double totalTime=Double.parseDouble(totalTimeString);

String totalPaceString=paceMin+"."+paceSec;

double totalPace=Double.parseDouble(totalPaceString);

double distance= totalTime/totalPace;


distanceText.setText(String.valueOf(distance));



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

}

public void calculateTime(int paceMin, int paceSec, int distance){
String paceString=paceMin+"."+paceSec;
double totalPace=Double.parseDouble(paceString.trim());

double time= distance/totalPace;

String timeString=String.valueOf(time);

if (timeString.contains(".")) {
String[] splitting = timeString.split(".");
timeMin.setText(splitting[0]);
timeSec.setText(splitting[1]);
}
else{
timeMin.setText(timeString);
}

}
}
112 changes: 112 additions & 0 deletions src/main/java/nyc/c4q/LibraryActivity.java
Original file line number Diff line number Diff line change
@@ -4,18 +4,38 @@
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

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

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;


public class LibraryActivity extends Activity {

public EditText inputParameter;
DBAdapter dbAdapter;
public TextView textDisplay;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_library);
dbAdapter = new DBAdapter(this);

inputParameter = (EditText) findViewById(R.id.input_parameter);
textDisplay=(TextView) findViewById(R.id.text_display);



loadBookJSONFromAsset(R.raw.books);
loadMemberJSONFromAsset(R.raw.members);


}

public void checkOut(int memberId, int bookId) {
@@ -36,21 +56,113 @@ public boolean checkIn(int memberId, int bookId) {
public void button_getMember_onClick(View view) {
String name = inputParameter.getText().toString();

textDisplay.setText(dbAdapter.getDataForMember(name));

// TODO Display member information for the member with the given name.
}

public void button_getBook_onClick(View view) {
String isbn = inputParameter.getText().toString();

textDisplay.setText(dbAdapter.getBookInfo(isbn));

// TODO Display book information for the book with the given ISBN.
}

public void button_getCheckedOut_onClick(View view) {
String name = inputParameter.getText().toString();

ArrayList<String> checkedOutList=new ArrayList<>();

checkedOutList.addAll(dbAdapter.getCurrentlyCheckedOut(name));

// TODO Display a list of books that the member with the given name
// currently has checked out, ordered by due date, with the
// earliest due first.
}

public void loadMemberJSONFromAsset(int fileName) {
String json = null;
try {
InputStream is = getResources().openRawResource(fileName);
int size = is.available();
byte[] buffer = new byte[size];
is.read(buffer);
is.close();
json = new String(buffer, "UTF-8");

} catch (IOException ex) {
ex.printStackTrace();
}
sendMemberInfo(json);
}
public void loadBookJSONFromAsset(int fileName) {
String json = null;
try {
InputStream is = getResources().openRawResource(fileName);
int size = is.available();
byte[] buffer = new byte[size];
is.read(buffer);
is.close();
json = new String(buffer, "UTF-8");

} catch (IOException ex) {
ex.printStackTrace();
}
sendMemberInfo(json);
}

public void sendMemberInfo(String json){

try {
JSONArray obj = new JSONArray(json);

for(int i=0;i<obj.length();i++) {
JSONObject jsonObject = obj.getJSONObject(0);
int id = jsonObject.getInt("id");
String name = jsonObject.getString("name");
int birthMonth = jsonObject.getInt("dob_month");
int birthDay = jsonObject.getInt("dob_day");
int birthYear = jsonObject.getInt("dob_year");
String city = jsonObject.getString("city");
String state = jsonObject.getString("state");
dbAdapter.insertMemberData(id,name,city,state,birthMonth,birthDay,birthYear);
}

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

public void sendBookInfoToDB(String json){
try {
JSONArray obj = new JSONArray(json);

for(int i=0;i<obj.length();i++) {
JSONObject jsonObject = obj.getJSONObject(0);
int id = jsonObject.getInt("id");
String title = jsonObject.getString("title");
String author=jsonObject.getString("author");
String isbn=jsonObject.getString("isbn");
String isbn13=jsonObject.getString("isbn13");
String publisher=jsonObject.getString("publisher");
int publishYear= jsonObject.getInt("publishyear");
boolean checkout=jsonObject.getBoolean("checkedout");
int checkoutby=jsonObject.getInt("checkoutby");
int chheckoutYear=jsonObject.getInt("checkoutdateyear");
int checkoutdatemonth=jsonObject.getInt("checkoutdatemonth");
int checkoutdateday=jsonObject.getInt("checkoutdateday");
int dueDateYear=jsonObject.getInt("duedateyear");
int dueDateMonth=jsonObject.getInt("duedatemonth");
int dueDateDay=jsonObject.getInt("duedateday");

dbAdapter.insertBookData(id,title,author,isbn,isbn13,publisher,publishYear,checkout,checkoutby,chheckoutYear,checkoutdatemonth,checkoutdateday
,dueDateYear,dueDateMonth,dueDateDay);
}

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

}
}
49 changes: 45 additions & 4 deletions src/main/java/nyc/c4q/ListActivity.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
package nyc.c4q;

import android.app.Activity;
import android.content.Context;
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.Arrays;


public class ListActivity extends Activity {

public ListView list;
int numOfButtonToggles;
int numofColorToggles;
Button nameChange;
Button colorChange;
ArrayList<Person> peopleList;

public static final Person[] PEOPLE = {
new Person("Hannah", "Abbott", House.Hufflepuff),
@@ -41,13 +51,44 @@ public class ListActivity extends Activity {
new Person("Ginny", "Weasley", House.Gryffindor),
new Person("Ron", "Weasley", House.Gryffindor)
};

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_list);

list = (ListView) findViewById(R.id.list);
}
nameChange=(Button) findViewById(R.id.button_name);
colorChange=(Button) findViewById(R.id.button_color);
peopleList= new ArrayList<>(Arrays.asList(PEOPLE));

SharedPreferences sharedPreferences=getSharedPreferences("Info", Context.MODE_PRIVATE);

numOfButtonToggles=sharedPreferences.getInt("numForName",0);
numofColorToggles=sharedPreferences.getInt("numForColor",0);
TestListAdapter testListAdapter = new TestListAdapter(this, peopleList, numOfButtonToggles, numofColorToggles);


list.setAdapter(testListAdapter);



nameChange.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
numOfButtonToggles++;
TestListAdapter testListAdapter = new TestListAdapter(ListActivity.this, peopleList, numOfButtonToggles, numofColorToggles);
list.setAdapter(testListAdapter);
}
});

colorChange.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
numofColorToggles++;
TestListAdapter testListAdapter = new TestListAdapter(ListActivity.this, peopleList, numOfButtonToggles, numofColorToggles);
list.setAdapter(testListAdapter);
}
});

}
}
13 changes: 11 additions & 2 deletions src/main/java/nyc/c4q/PaceCalculatorActivity.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
package nyc.c4q;

import android.support.v4.app.FragmentActivity;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;

public class PaceCalculatorActivity extends FragmentActivity {


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_pace_calculator);

android.support.v4.app.FragmentManager fragmentManager = getSupportFragmentManager();

android.support.v4.app.FragmentTransaction ft = fragmentManager.beginTransaction();

ExampleFragment fragment = new ExampleFragment();
ft.add(R.id.activity_pace_calculator, fragment);
ft.commit();
}

}
}
112 changes: 112 additions & 0 deletions src/main/java/nyc/c4q/TestListAdapter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
package nyc.c4q;

import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.util.Log;
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.Collections;
import java.util.Comparator;

/**
* Created by c4q-madelyntavarez on 8/30/15.
*/
public class TestListAdapter extends BaseAdapter {

ArrayList<Person> persons;
Context context;
LayoutInflater layoutInflater;
int numOfButtonToggles;
int numOfColorToggles;

public TestListAdapter(Context context,ArrayList<Person> persons,int numOfButtonToggles, int numOfColorToggles) {
this.persons = persons;
this.numOfButtonToggles=numOfButtonToggles;
this.context = context;
this.numOfColorToggles=numOfColorToggles;
layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}

@Override
public int getCount() {
return persons.size();
}

@Override
public Object getItem(int position) {
return position;
}

@Override
public long getItemId(int position) {
return position;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {

View view=layoutInflater.inflate(R.layout.listitem_member,null);

TextView house=(TextView) view.findViewById(R.id.text_house);
TextView name=(TextView) view.findViewById(R.id.text_name);

if(numOfButtonToggles % 2==0){
name.setText(persons.get(position).lastName + ", " + persons.get(position).firstName);
house.setText(persons.get(position).house.toString());
Collections.sort(persons, new Comparator<Person>() {
public int compare(Person result1, Person result2) {
return result1.lastName.compareTo(result2.lastName);
}
});

}
else{
name.setText(persons.get(position).firstName + " " + persons.get(position).lastName);
house.setText(persons.get(position).house.toString());

Collections.sort(persons, new Comparator<Person>() {
public int compare(Person result1, Person result2) {
return result1.firstName.compareTo(result2.firstName);
}
});
}

House houseForColor=persons.get(position).house;
String color=houseForColor.toString();
if(numOfColorToggles%2==0){
name.setBackgroundColor(Color.TRANSPARENT);
}
else{
if (color.equals("Gryffindor")) {
name.setBackgroundColor(context.getResources().getColor(R.color.gryffindor_red));
Log.d("COLOR", color);
}
if (color.equals("Ravenclaw")) {
name.setBackgroundColor(context.getResources().getColor(R.color.ravenclaw_blue));
Log.d("COLOR", color);
}
if (color.equals("Hufflepuff")) {
name.setBackgroundColor(context.getResources().getColor(R.color.hufflepuff_yellow));
Log.d("COLOR", color);
}
if (color.equals("Slytherin")) {
name.setBackgroundColor(context.getResources().getColor(R.color.slytherin_green));
Log.d("COLOR", color);
}
}

SharedPreferences sharedPreferences=context.getSharedPreferences("Info",Context.MODE_PRIVATE);
SharedPreferences.Editor editor=sharedPreferences.edit();
editor.putInt("numForName",numOfButtonToggles);
editor.putInt("numForColor",numOfColorToggles);
editor.commit();

return view;
}
}
14 changes: 12 additions & 2 deletions src/main/res/layout/activity_pace_calculator.xml
Original file line number Diff line number Diff line change
@@ -4,5 +4,15 @@
android:id="@+id/activity_pace_calculator"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="nyc.c4q.PaceCalculatorActivity"
/>
tools:context="nyc.c4q.PaceCalculatorActivity">

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="@+id/linearWithin">
</LinearLayout>



</FrameLayout>
2 changes: 1 addition & 1 deletion src/main/res/raw/books.json
Original file line number Diff line number Diff line change
@@ -838,7 +838,7 @@
"isbn": "0439554934",
"isbn13": "9780439554930",
"publisher": "Scholastic",
"publishyear": 2003.
"publishyear": 2003,
"checkedout": true,
"checkedoutby": 38,
"checkoutdateyear": 2015,
3 changes: 3 additions & 0 deletions src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -24,4 +24,7 @@
<string name="show_color">Show Color</string>
<string name="hide_color">Hide Color</string>

<!-- TODO: Remove or change this placeholder text -->
<string name="hello_blank_fragment">Hello blank fragment</string>

</resources>