Skip to content
This repository has been archived by the owner on Sep 1, 2022. It is now read-only.

Commit

Permalink
Merge branch 'release/1.2.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
Amab committed Nov 26, 2014
2 parents 2c711a4 + 5876df7 commit 6d98acc
Show file tree
Hide file tree
Showing 21 changed files with 346 additions and 382 deletions.
4 changes: 2 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="es.ugr.swad.swadroid"
android:installLocation="auto"
android:versionCode="66"
android:versionName="1.2.1" >
android:versionCode="67"
android:versionName="1.2.2" >

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ public void handleDecode(Result rawResult, Bitmap barcode) {

if (u != null) {
ImageFactory.displayImage(getApplicationContext(), u.getUserPhoto(), image, true, true,
R.raw.usr_bl, R.raw.usr_bl, R.raw.usr_bl);
R.drawable.usr_bl, R.drawable.usr_bl, R.drawable.usr_bl);
}

// Show appropriate icon
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/es/ugr/swad/swadroid/SWADMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,8 @@ public void onCreate(Bundle icicle) {
lastVersion = Preferences.getLastVersion();
currentVersion = getPackageManager().getPackageInfo(getPackageName(), 0).versionCode;
dbHelper.initializeDB();
//lastVersion = 64;
//currentVersion = 65;
//lastVersion = 67;
//currentVersion = 68;

//If this is the first run, show configuration dialog
if (lastVersion == 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@ public class DataBaseHelper {
* Table name for events
*/
public static final String DB_TABLE_EVENTS_ATTENDANCES = "events_attendances";
/**
* Table name for relationship between events and courses
*/
public static final String DB_TABLE_EVENTS_COURSES = "events_courses";
/**
* Table name for groups
*/
Expand Down Expand Up @@ -252,6 +256,9 @@ private Pair<String, String> selectParamsPairTable(String table) {
} else if (table.equals(DataBaseHelper.DB_TABLE_GROUPS_GROUPTYPES)) {
firstParam = "grpTypCod";
secondParam = "grpCod";
} else if (table.equals(DataBaseHelper.DB_TABLE_EVENTS_COURSES)) {
firstParam = "eventCode";
secondParam = "crsCod";
} else {
Log.e("selectParamsPairTable", "Table " + table + " not exists");
}
Expand Down Expand Up @@ -292,7 +299,8 @@ private <T extends Model> T createObjectByTable(String table, Entity ent) {
table.equals(DataBaseHelper.DB_TABLE_TEST_QUESTION_ANSWERS) ||
table.equals(DataBaseHelper.DB_TABLE_USERS_COURSES) ||
table.equals(DataBaseHelper.DB_TABLE_GROUPS_COURSES) ||
table.equals(DataBaseHelper.DB_TABLE_GROUPS_GROUPTYPES)) {
table.equals(DataBaseHelper.DB_TABLE_GROUPS_GROUPTYPES) ||
table.equals(DataBaseHelper.DB_TABLE_EVENTS_COURSES)) {

params = selectParamsPairTable(table);

Expand Down Expand Up @@ -641,6 +649,37 @@ public Cursor getUsersEventCursor(int eventCode) {
+ " ON U.userCode = A.userCode WHERE eventCode ='" + eventCode + "'", null);
}

/**
* Gets the list of events related to the selected course
*
* @param crsCod Course code to be referenced
* @return A list of Event
*/
public List<Event> getEventsCourse(long crsCod) {
List<Event> result = new ArrayList<Event>();
List<Entity> rows = db.getEntityList(DataBaseHelper.DB_TABLE_EVENTS_COURSES, "crsCod = '" + crsCod + "'");

if (rows != null) {
for (Entity ent : rows) {
result.add((Event) getRow(DataBaseHelper.DB_TABLE_EVENTS_ATTENDANCES, "id", ent.getValue("eventCode")));
}
}

return result;
}

/**
* Gets the list of users related to the selected event
*
* @param crsCod Course code to be referenced
* @return A Cursor with a list of events related to the selected course
*/
public Cursor getEventsCourseCursor(long crsCod) {
return db.rawQuery("SELECT * FROM " + DB_TABLE_EVENTS_ATTENDANCES + " AS E"
+ " INNER JOIN " + DB_TABLE_EVENTS_COURSES + " AS C"
+ " ON E.id = C.eventCode WHERE C.crsCod ='" + crsCod + "'", null);
}

/**
* Gets the number of users related to the selected event
*
Expand Down Expand Up @@ -1253,6 +1292,7 @@ public void insertAttendance(long userCode, long eventCode, boolean present) {
} else {
ent = rows.get(0);
}

ent.setValue("userCode", userCode);
ent.setValue("eventCode", eventCode);
ent.setValue("present", Utils.parseBoolInt(present));
Expand All @@ -1276,6 +1316,7 @@ public void insertEvent(Event event) {
} else {
ent = rows.get(0);
}

ent.setValue("id", event.getId());
ent.setValue("hidden", Utils.parseBoolInt(event.isHidden()));
ent.setValue("userSurname1", crypto.encrypt(event.getUserSurname1()));
Expand All @@ -1291,6 +1332,29 @@ public void insertEvent(Event event) {
ent.save();
}

/**
* Inserts a new record in database for the relationship between an attendance event and a course,
* or updates it if already exists
*
* @param eventCode Event code
* @param crsCod Course code
*/
public void insertEventCourse(long eventCode, long crsCod) {
Entity ent;
String where = "eventCode = " + eventCode + " AND crsCod = " + crsCod;
List<Entity> rows = db.getEntityList(DataBaseHelper.DB_TABLE_EVENTS_COURSES, where);

if (rows.isEmpty()) {
ent = new Entity(DataBaseHelper.DB_TABLE_EVENTS_COURSES);
} else {
ent = rows.get(0);
}

ent.setValue("eventCode", eventCode);
ent.setValue("crsCod", crsCod);
ent.save();
}

/**
* Updates a course in database
*
Expand Down Expand Up @@ -1988,8 +2052,30 @@ public void emptyTable(String table) {
* @param table Table to be deleted
*/
public void deleteTable(String table) {
db.deleteTable(table);
Log.d(TAG, "Deleted table " + table);
if(isTableExisting(table)) {
db.deleteTable(table);
Log.d(TAG, "Deleted table " + table);
} else {
Log.e(TAG, "Table " + table + " doesn't exists. Can't be deleted");
}
}

/**
* Checks if a table exists in database
* @param tableName Name of the table to be checked
* @return true is table exists
* false otherwise
*/
public boolean isTableExisting(String tableName) {
Cursor cursor = db.rawQuery("select DISTINCT tbl_name from sqlite_master where tbl_name = '"+tableName+"'", null);
if(cursor!=null) {
if(cursor.getCount()>0) {
cursor.close();
return true;
}
cursor.close();
}
return false;
}

/**
Expand Down Expand Up @@ -2111,6 +2197,13 @@ public void upgradeDB(Context context) {
deleteTable(DB_TABLE_ROLLCALL);
}

/* version 18-19
* deleted old event data
* */
if (dbVersion == 19) {
emptyTable(DB_TABLE_EVENTS_ATTENDANCES);
}

Log.i(TAG, "Database upgraded");

compactDB();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public static ImageLoader init(Context ctx, boolean cacheMemory, boolean cacheDi

builder.cacheInMemory(cacheMemory);
builder.cacheOnDisk(cacheDisk);
builder.resetViewBeforeLoading(true);

if(imageEmpty == -1) {
builder.showImageForEmptyUri(imageLoading);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ protected void onCreate(Bundle savedInstanceState) {
//userPhotoView.setImageURI(Uri.parse(userPhoto));
//new DownloadImageTask(userPhotoView).execute(userPhoto);
ImageFactory.displayImage(getApplicationContext(), userPhoto, userPhotoView, true, true,
R.raw.usr_bl, R.raw.usr_bl, R.raw.usr_bl);
R.drawable.usr_bl, R.drawable.usr_bl, R.drawable.usr_bl);
} else {
Log.d(TAG, "No connection or no photo " + userPhoto);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,21 @@ public boolean onOptionsItemSelected(MenuItem item) {
}
}

private void swipeItem(int position) {
int notSeenChildrenCount = adapter.getChildrenCount(NOT_SEEN_GROUP_ID);
long childId;

if(position <= notSeenChildrenCount) {
childId = adapter.getChildId(NOT_SEEN_GROUP_ID, position - 1);

//Set notification as seen locally
dbHelper.updateNotification(childId, "seenLocal", Utils.parseBoolString(true));
sendReadedNotifications();

refreshScreen();
}
}

/*
* @Override public void setContentView(int layoutResID) { View v =
* getLayoutInflater().inflate(layoutResID, refreshLayout, false);
Expand All @@ -627,49 +642,52 @@ private void initSwipeOptions() {
refreshLayout.setOnRefreshListener(this);
setAppearance();
// disableSwipe();


list.setOnScrollListener(new AbsListView.OnScrollListener() {
@Override
public void onScrollStateChanged(AbsListView absListView, int scrollState) {
}

@Override
public void onScroll(AbsListView absListView, int firstVisibleItem,
int visibleItemCount, int totalItemCount) {

boolean enable = false;
if(list != null && list.getChildCount() > 0){
// check if the first item of the list is visible
boolean firstItemVisible = list.getFirstVisiblePosition() == 0;
// check if the top of the first item is visible
boolean topOfFirstItemVisible = list.getChildAt(0).getTop() == 0;
// enabling or disabling the refresh layout
enable = firstItemVisible && topOfFirstItemVisible;
}
refreshLayout.setEnabled(enable);
}
});
/*
* Create a ListView-specific touch listener. ListViews are given special treatment because
* by default they handle touches for their list items... i.e. they're in charge of drawing
* the pressed state (the list selector), handling list item clicks, etc.
*
* Requires Android 3.1 (HONEYCOMB_MR1) or newer
*/
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR1) {
/*if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR1) {
SwipeListViewTouchListener touchListener =
new SwipeListViewTouchListener(
list,
new SwipeListViewTouchListener.OnSwipeCallback() {
@Override
public void onSwipeLeft(ListView listView, int [] reverseSortedPositions) {
int notSeenChildrenCount = adapter.getChildrenCount(NOT_SEEN_GROUP_ID);
long childId;

if(reverseSortedPositions[0] <= notSeenChildrenCount) {
childId = adapter.getChildId(NOT_SEEN_GROUP_ID, reverseSortedPositions[0]-1);

//Set notification as seen locally
dbHelper.updateNotification(childId, "seenLocal", Utils.parseBoolString(true));
sendReadedNotifications();

refreshScreen();
}
if(reverseSortedPositions.length > 0) {
swipeItem(reverseSortedPositions[0]);
}
}
@Override
public void onSwipeRight(ListView listView, int [] reverseSortedPositions) {
int notSeenChildrenCount = adapter.getChildrenCount(NOT_SEEN_GROUP_ID);
long childId;

if(reverseSortedPositions[0] <= notSeenChildrenCount) {
childId = adapter.getChildId(NOT_SEEN_GROUP_ID, reverseSortedPositions[0]-1);

//Set notification as seen locally
dbHelper.updateNotification(childId, "seenLocal", Utils.parseBoolString(true));
sendReadedNotifications();

refreshScreen();
}
if(reverseSortedPositions.length > 0) {
swipeItem(reverseSortedPositions[0]);
}
}
@Override
Expand Down Expand Up @@ -712,7 +730,7 @@ public void onScroll(AbsListView absListView, int firstVisibleItem,
refreshLayout.setEnabled(enable);
}
});
}
}*/
}

@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
Expand Down Expand Up @@ -803,8 +821,9 @@ public void setChildGroupData() {
list.setAdapter(adapter);
list.setOnChildClickListener(clickListener);

//Expand the not seen notifications group
//Expand the groups
list.expandGroup(NOT_SEEN_GROUP_ID);
list.expandGroup(SEEN_GROUP_ID);
} else {
Log.d(TAG, "[setChildGroupData] Notifications table is empty");

Expand Down
Loading

0 comments on commit 6d98acc

Please sign in to comment.