Skip to content

Commit 322adc7

Browse files
committed
Merge pull request OpnTec#25 from fashiontec/dob_field
Added Date of birth to person
2 parents 2922716 + dea20a5 commit 322adc7

File tree

9 files changed

+232
-146
lines changed

9 files changed

+232
-146
lines changed

Diff for: app/src/main/java/org/fashiontec/bodyapps/db/DBContract.java

+6-3
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,24 @@ public static abstract class Person {
2222
public static final String COLUMN_NAME_EMAIL = "email";
2323
public static final String COLUMN_NAME_NAME = "name";
2424
public static final String COLUMN_NAME_GENDER = "gender";
25+
public static final String COLUMN_NAME_DOB = "dob";
2526

2627
public static final String SQL_CREATE_ENTRIES = "CREATE TABLE "
2728
+ Person.TABLE_NAME + " ("
2829
+ Person.COLUMN_NAME_ID + " INTEGER PRIMARY KEY autoincrement" + COMMA_SEP
2930
+ Person.COLUMN_NAME_EMAIL + TEXT_TYPE + COMMA_SEP
3031
+ Person.COLUMN_NAME_NAME + TEXT_TYPE + COMMA_SEP
31-
+ Person.COLUMN_NAME_GENDER + NUMBER_TYPE
32-
+ ")";
32+
+ Person.COLUMN_NAME_GENDER + NUMBER_TYPE+ COMMA_SEP
33+
+Person.COLUMN_NAME_DOB + NUMBER_TYPE
34+
+ ")";
3335
public static final String SQL_DELETE_ENTRIES = "DROP TABLE IF EXISTS "
3436
+ Person.TABLE_NAME;
3537

3638
public static final String[] allColumns = {
3739
Person.COLUMN_NAME_EMAIL,
3840
Person.COLUMN_NAME_NAME,
39-
Person.COLUMN_NAME_GENDER };
41+
Person.COLUMN_NAME_GENDER,
42+
Person.COLUMN_NAME_DOB};
4043

4144

4245
}

Diff for: app/src/main/java/org/fashiontec/bodyapps/db/DatabaseHandler.java

+39-39
Original file line numberDiff line numberDiff line change
@@ -11,47 +11,47 @@
1111
import android.util.Log;
1212

1313
/**
14-
*Creates all the tables in DB and handles DB.
14+
* Creates all the tables in DB and handles DB.
1515
*/
16-
public class DatabaseHandler extends SQLiteOpenHelper{
17-
public static final int DATABASE_VERSION = 6;
16+
public class DatabaseHandler extends SQLiteOpenHelper {
17+
public static final int DATABASE_VERSION = 7;
1818
public static final String DATABASE_NAME = "BodyApp.db";
1919
public static DatabaseHandler dbHandler;
20-
21-
22-
private DatabaseHandler(Context context) {
23-
super(context, DATABASE_NAME, null, DATABASE_VERSION);
24-
}
25-
26-
@Override
27-
public void onCreate(SQLiteDatabase db) {
28-
Log.d("SQLite", "Creating Databases");
29-
db.execSQL(DBContract.User.SQL_CREATE_ENTRIES);
30-
Log.d("table", "Created user");
31-
db.execSQL(DBContract.Person.SQL_CREATE_ENTRIES);
32-
Log.d("table", "Created person");
33-
db.execSQL(DBContract.Measurement.SQL_CREATE_ENTRIES);
34-
Log.d("table", "Created measurement");
35-
db.execSQL(DBContract.Delete.SQL_CREATE_ENTRIES);
36-
Log.d("table", "Created delete");
37-
38-
}
39-
40-
@Override
41-
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
42-
db.execSQL(DBContract.User.SQL_DELETE_ENTRIES);
43-
db.execSQL(DBContract.Person.SQL_DELETE_ENTRIES);
44-
db.execSQL(DBContract.Measurement.SQL_DELETE_ENTRIES);
45-
db.execSQL(DBContract.Delete.SQL_DELETE_ENTRIES);
46-
onCreate(db);
47-
48-
}
49-
50-
public static DatabaseHandler getInstance (Context context){
51-
if(dbHandler==null){
52-
dbHandler=new DatabaseHandler(context);
53-
}
54-
return dbHandler;
55-
}
20+
21+
22+
private DatabaseHandler(Context context) {
23+
super(context, DATABASE_NAME, null, DATABASE_VERSION);
24+
}
25+
26+
@Override
27+
public void onCreate(SQLiteDatabase db) {
28+
Log.d("SQLite", "Creating Databases");
29+
db.execSQL(DBContract.User.SQL_CREATE_ENTRIES);
30+
Log.d("table", "Created user");
31+
db.execSQL(DBContract.Person.SQL_CREATE_ENTRIES);
32+
Log.d("table", "Created person");
33+
db.execSQL(DBContract.Measurement.SQL_CREATE_ENTRIES);
34+
Log.d("table", "Created measurement");
35+
db.execSQL(DBContract.Delete.SQL_CREATE_ENTRIES);
36+
Log.d("table", "Created delete");
37+
38+
}
39+
40+
@Override
41+
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
42+
db.execSQL(DBContract.User.SQL_DELETE_ENTRIES);
43+
db.execSQL(DBContract.Person.SQL_DELETE_ENTRIES);
44+
db.execSQL(DBContract.Measurement.SQL_DELETE_ENTRIES);
45+
db.execSQL(DBContract.Delete.SQL_DELETE_ENTRIES);
46+
onCreate(db);
47+
48+
}
49+
50+
public static DatabaseHandler getInstance(Context context) {
51+
if (dbHandler == null) {
52+
dbHandler = new DatabaseHandler(context);
53+
}
54+
return dbHandler;
55+
}
5656

5757
}

Diff for: app/src/main/java/org/fashiontec/bodyapps/main/CreateActivity.java

+41-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import android.app.Activity;
99
import android.app.AlertDialog;
10+
import android.app.DatePickerDialog;
1011
import android.content.Context;
1112
import android.content.DialogInterface;
1213
import android.content.Intent;
@@ -16,6 +17,7 @@
1617
import android.view.View.OnClickListener;
1718
import android.widget.ArrayAdapter;
1819
import android.widget.Button;
20+
import android.widget.DatePicker;
1921
import android.widget.Spinner;
2022
import android.widget.TextView;
2123

@@ -25,20 +27,24 @@
2527
import org.fashiontec.bodyapps.models.Person;
2628

2729
import java.text.SimpleDateFormat;
30+
import java.util.Calendar;
2831
import java.util.Date;
2932
import java.util.UUID;
3033

3134
public class CreateActivity extends Activity {
3235
private Button btnCreate;
36+
private Button btnDoB;
3337
private Spinner spnUnits;
3438
private Spinner spnGender;
3539
private TextView txtEmail;
3640
private TextView txtName;
41+
private TextView txtDoB;
3742
private Person person;
3843
private Measurement measurement;
3944
Context context;
4045
private static AlertDialog alertDialog;
4146
static final String TAG = CreateActivity.class.getName();
47+
static final Calendar myCalendar = Calendar.getInstance();
4248

4349
@Override
4450
protected void onCreate(Bundle savedInstanceState) {
@@ -66,7 +72,40 @@ public void onClick(View v) {
6672
android.R.layout.simple_spinner_item);
6773
spnGender.setAdapter(genderAdapter);
6874
context = this;
75+
txtDoB = (TextView) findViewById(R.id.create_txt_dob);
76+
updateLabel();
77+
final DatePickerDialog.OnDateSetListener date = new DatePickerDialog.OnDateSetListener() {
6978

79+
@Override
80+
public void onDateSet(DatePicker view, int year, int monthOfYear,
81+
int dayOfMonth) {
82+
// TODO Auto-generated method stub
83+
myCalendar.set(Calendar.YEAR, year);
84+
myCalendar.set(Calendar.MONTH, monthOfYear);
85+
myCalendar.set(Calendar.DAY_OF_MONTH, dayOfMonth);
86+
updateLabel();
87+
}
88+
89+
};
90+
91+
btnDoB = (Button) findViewById(R.id.create_btn_dob);
92+
btnDoB.setOnClickListener(new OnClickListener() {
93+
@Override
94+
public void onClick(View view) {
95+
new DatePickerDialog(CreateActivity.this, date, myCalendar
96+
.get(Calendar.YEAR), myCalendar.get(Calendar.MONTH),
97+
myCalendar.get(Calendar.DAY_OF_MONTH)
98+
).show();
99+
}
100+
});
101+
102+
}
103+
104+
private void updateLabel() {
105+
106+
String myFormat = "MM/dd/yyyy";
107+
SimpleDateFormat sdf = new SimpleDateFormat(myFormat);
108+
txtDoB.setText(sdf.format(myCalendar.getTime()));
70109
}
71110

72111
public boolean setData() {
@@ -89,7 +128,8 @@ public boolean setData() {
89128
}
90129

91130
private void setMeasurement(String name, String email) {
92-
person = new Person(email, name, spnGender.getSelectedItemPosition());
131+
Date bdate = myCalendar.getTime();
132+
person = new Person(email, name, spnGender.getSelectedItemPosition(), bdate.getTime());
93133
// adds the person to DB and gets his ID
94134
int personID = PersonManager.getInstance(this.getApplicationContext()).getPerson(person);
95135
if (personID == -1) {

Diff for: app/src/main/java/org/fashiontec/bodyapps/main/SavedActivity.java

-7
Original file line numberDiff line numberDiff line change
@@ -302,13 +302,6 @@ public void onResume() {
302302
if (measurementsList.size() != 0) {
303303
shownID = measurementsList.get(shownIndex).getID();
304304
}
305-
}
306-
307-
@Override
308-
public void onActivityCreated(Bundle savedInstanceState) {
309-
310-
super.onActivityCreated(savedInstanceState);
311-
312305
View viewSaved = getActivity().findViewById(R.id.mesurements);
313306
dualPane = viewSaved != null
314307
&& viewSaved.getVisibility() == View.VISIBLE;

0 commit comments

Comments
 (0)