Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
shalzz committed Feb 27, 2016
2 parents 16625d5 + 02bb4f8 commit 675970c
Show file tree
Hide file tree
Showing 40 changed files with 966 additions and 572 deletions.
2 changes: 0 additions & 2 deletions attendance/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ android {

dependencies {
useLibrary 'org.apache.http.legacy'
compile fileTree(dir: 'libs', include: ['*.jar'])

// google support libraries
compile 'com.google.android.gms:play-services-analytics:8.+'
Expand All @@ -73,7 +72,6 @@ android {
compile 'com.android.support:design:23.1.+'
compile 'com.android.support:support-v4:23.1.+'
compile 'com.android.support:appcompat-v7:23.1.+'
compile 'com.android.support:support-v13:23.1.+'
compile 'com.android.support:preference-v14:23.1.+'

// 3rd party library projects
Expand Down
Binary file removed attendance/libs/MMAdMobAdapter_1_7_0.jar
Binary file not shown.
Binary file removed attendance/libs/MMSDK.jar
Binary file not shown.
7 changes: 3 additions & 4 deletions attendance/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.shalzz.attendance"
android:versionCode="243"
android:versionName="2.4.3" >
android:versionCode="250"
android:versionName="2.5.0" >

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
Expand Down Expand Up @@ -82,7 +82,7 @@
<activity
android:name=".activity.SplashActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
android:theme="@style/AppTheme.Launcher" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
Expand All @@ -97,7 +97,6 @@

<activity
android:name=".activity.MainActivity"
android:label="Attendance"
android:theme="@style/DrawerActivityTheme">
<intent-filter>
<action android:name="android.intent.action.MANAGE_NETWORK_USAGE" />
Expand Down
151 changes: 57 additions & 94 deletions attendance/src/main/java/com/shalzz/attendance/DatabaseHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.support.v4.content.AsyncTaskLoader;

import com.shalzz.attendance.model.ListFooterModel;
import com.shalzz.attendance.model.PeriodModel;
Expand All @@ -48,7 +49,7 @@ public class DatabaseHandler extends SQLiteOpenHelper {
/**
* Database Version
*/
private static final int DATABASE_VERSION = 7;
private static final int DATABASE_VERSION = 8;

/**
* Database Name
Expand Down Expand Up @@ -171,6 +172,7 @@ public void onCreate(SQLiteDatabase db) {
public void onConfigure(SQLiteDatabase db) {
super.onConfigure(db);
db.setForeignKeyConstraintsEnabled(true);
db.enableWriteAheadLogging();
}

/**
Expand Down Expand Up @@ -216,8 +218,6 @@ public void addSubject(SubjectModel subject, long timestamp) {
dates.put(KEY_DAYS_ABSENT, DateHelper.formatToTechnicalFormat(date));
db.insert(TABLE_DAYS_ABSENT, null, dates);
}

db.close(); // Closing database connection
}

/**
Expand All @@ -242,12 +242,8 @@ public int updateSubject(SubjectModel subject, long timestamp) {
db.insertWithOnConflict(TABLE_DAYS_ABSENT, null, dates, SQLiteDatabase.CONFLICT_IGNORE);
}

// updating row
int rows_affected = db.update(TABLE_ATTENDANCE, values, KEY_ID + " = ?",
return db.update(TABLE_ATTENDANCE, values, KEY_ID + " = ?",
new String[] { String.valueOf(subject.getID()) });
db.close();

return rows_affected;
}

/**
Expand All @@ -268,100 +264,64 @@ public void addOrUpdateSubject(SubjectModel subject, long timestamp) {
updateSubject(subject, timestamp);
}
cursor.close();
db.close(); // Closing database connection
}

/**
* Get All Subjects
* @return subjectList
*/
public List<SubjectModel> getAllSubjects() {
public List<SubjectModel> getAllSubjects(AsyncTaskLoader callback, String filter) {
List<SubjectModel> subjectList = new ArrayList<>();
// Select All Query
String selectQuery = "SELECT * FROM " + TABLE_ATTENDANCE + ";";

SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.rawQuery(selectQuery, null);

// looping through all rows and adding to list
if (cursor.moveToFirst()) {
do {

SubjectModel subject = new SubjectModel();
subject.setID(cursor.getInt(cursor.getColumnIndexOrThrow(KEY_ID)));
subject.setName(cursor.getString(cursor.getColumnIndexOrThrow(KEY_NAME)));
subject.setClassesHeld(cursor.getFloat(cursor.getColumnIndexOrThrow(KEY_CLASSES_HELD)));
subject.setClassesAttended(cursor.getFloat(cursor.getColumnIndexOrThrow(KEY_CLASSES_ATTENDED)));

String datesQuery = "SELECT " + KEY_DAYS_ABSENT + " FROM " + TABLE_DAYS_ABSENT +
" WHERE " + KEY_ID + " = " + subject.getID() + ";";

Cursor dateCursor = db.rawQuery(datesQuery, null);
ArrayList<Date> dates = new ArrayList<>();
if (dateCursor.moveToFirst()) {
do {
Date date = DateHelper.parseDate(dateCursor.getString(0));
dates.add(date);
} while (dateCursor.moveToNext());
}
dateCursor.close();
Date dateArray[] = new Date[dates.size()];
subject.setAbsentDates(dates.toArray(dateArray));

subjectList.add(subject);
} while (cursor.moveToNext());
Cursor cursor;

if (filter != null) {
cursor = db.query(TABLE_ATTENDANCE, new String[]{KEY_ID, KEY_NAME, KEY_CLASSES_HELD,
KEY_CLASSES_ATTENDED, KEY_DAYS_ABSENT}, KEY_NAME + " LIKE '%" +
filter + "%'",
null, null, null, KEY_NAME, null);
} else {
cursor = db.query(TABLE_ATTENDANCE, new String[]{KEY_ID, KEY_NAME, KEY_CLASSES_HELD,
KEY_CLASSES_ATTENDED, KEY_DAYS_ABSENT}, null,
null, null, null, KEY_NAME, null);
}

db.close();
cursor.close();

return subjectList;
}

/**
* Get All Subjects ordered alphabetically.
* @return subjectList
*/
public List<SubjectModel> getAllOrderedSubjects() {
List<SubjectModel> subjectList = new ArrayList<>();
// Select All Query
String selectQuery = "SELECT * FROM " + TABLE_ATTENDANCE + " ORDER BY " + KEY_NAME + ";";

SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.rawQuery(selectQuery, null);

// looping through all rows and adding to list
if (cursor.moveToFirst()) {
do {

SubjectModel subject = new SubjectModel();
subject.setID(cursor.getInt(cursor.getColumnIndexOrThrow(KEY_ID)));
subject.setName(cursor.getString(cursor.getColumnIndexOrThrow(KEY_NAME)));
subject.setClassesHeld(cursor.getFloat(cursor.getColumnIndexOrThrow(KEY_CLASSES_HELD)));
subject.setClassesAttended(cursor.getFloat(cursor.getColumnIndexOrThrow(KEY_CLASSES_ATTENDED)));

String datesQuery = "SELECT " + KEY_DAYS_ABSENT + " FROM " + TABLE_DAYS_ABSENT +
" WHERE " + KEY_ID + " = " + subject.getID() + ";";

Cursor dateCursor = db.rawQuery(datesQuery, null);
ArrayList<Date> dates = new ArrayList<>();
if (dateCursor.moveToFirst()) {
do {
Date date = DateHelper.parseDate(dateCursor.getString(0));
dates.add(date);
} while (dateCursor.moveToNext());
}
dateCursor.close();
Date dateArray[] = new Date[dates.size()];
subject.setAbsentDates(dates.toArray(dateArray));

subjectList.add(subject);
} while (cursor.moveToNext());
if (cursor != null && cursor.moveToFirst()) {
try {
do {
// Check isLoadInBackgroundCanceled() to cancel out early
if(callback != null && callback.isLoadInBackgroundCanceled()) {
break;
}

SubjectModel subject = new SubjectModel();
subject.setID(cursor.getInt(cursor.getColumnIndexOrThrow(KEY_ID)));
subject.setName(cursor.getString(cursor.getColumnIndexOrThrow(KEY_NAME)));
subject.setClassesHeld(cursor.getFloat(cursor.getColumnIndexOrThrow(KEY_CLASSES_HELD)));
subject.setClassesAttended(cursor.getFloat(cursor.getColumnIndexOrThrow(KEY_CLASSES_ATTENDED)));

String datesQuery = "SELECT " + KEY_DAYS_ABSENT + " FROM " + TABLE_DAYS_ABSENT +
" WHERE " + KEY_ID + " = " + subject.getID() + ";";

Cursor dateCursor = db.rawQuery(datesQuery, null);
ArrayList<Date> dates = new ArrayList<>();
if (dateCursor.moveToFirst()) {
do {
Date date = DateHelper.parseDate(dateCursor.getString(0));
dates.add(date);
} while (dateCursor.moveToNext());
}
dateCursor.close();
Date dateArray[] = new Date[dates.size()];
subject.setAbsentDates(dates.toArray(dateArray));

subjectList.add(subject);
} while (cursor.moveToNext());
} finally {
cursor.close();
}
}

db.close();
cursor.close();

return subjectList;
}

Expand Down Expand Up @@ -592,7 +552,7 @@ public void addOrUpdatePeriod(PeriodModel period, long timestamp) {
db.close(); // Closing database connection
}

public ArrayList<PeriodModel> getAllPeriods(String dayName) {
public ArrayList<PeriodModel> getAllPeriods(String dayName, AsyncTaskLoader callback) {
SQLiteDatabase db = this.getReadableDatabase();

Cursor cursor = db.query(TABLE_TIMETABLE, null, KEY_DAY + "=?",
Expand All @@ -601,16 +561,19 @@ public ArrayList<PeriodModel> getAllPeriods(String dayName) {
ArrayList<PeriodModel> periods = new ArrayList<>();
if (cursor.moveToFirst()) {
do {
// Check isLoadInBackgroundCanceled() to cancel out early
if(callback != null && callback.isLoadInBackgroundCanceled()) {
break;
}
PeriodModel period = new PeriodModel();
period.setId(cursor.getInt(cursor.getColumnIndexOrThrow(KEY_ID)));
period.setDay(cursor.getString(cursor.getColumnIndexOrThrow(KEY_DAY)));
period.setSubjectName(cursor.getString(cursor.getColumnIndexOrThrow(KEY_SUBJECT_NAME)));
period.setTeacher(cursor.getString(cursor.getColumnIndexOrThrow(KEY_TEACHER)));
period.setRoom(cursor.getString(cursor.getColumnIndexOrThrow(KEY_ROOM)));
period.setBatch(cursor.getString(cursor.getColumnIndexOrThrow(KEY_BATCH)));
String start = cursor.getString(cursor.getColumnIndexOrThrow(KEY_START));
String end = cursor.getString(cursor.getColumnIndexOrThrow(KEY_END));
period.setTime(start,end);
period.setStart(cursor.getString(cursor.getColumnIndexOrThrow(KEY_START)));
period.setEnd(cursor.getString(cursor.getColumnIndexOrThrow(KEY_END)));
periods.add(period);
} while (cursor.moveToNext());
}
Expand Down
Loading

0 comments on commit 675970c

Please sign in to comment.