-
Notifications
You must be signed in to change notification settings - Fork 0
Kamila/add friends button #196
Changes from 24 commits
a1e7c63
101ab77
93f1119
a19cbf1
8a28e12
ef9d279
b70cf33
d86ec70
4e1a569
20170bb
4a1b034
5960d85
5ad51b5
7cc6845
938fd65
38fe5c7
70ec5da
e9ceadd
e0f63c0
961f87b
b2ce075
2fe0be5
b3ac589
34e3579
0fffe05
e2c4361
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,6 +42,20 @@ class UsersRepo @Inject constructor() { | |
} | ||
|
||
|
||
/** | ||
* Update a subfield of user's field | ||
* @param userID the id of the user which is being updated | ||
* @param newVal (Boolean) the new value of the field that is being updated | ||
* @param fieldName the field name of the field that is being updated | ||
* @param subFieldName the field name of the field that is being updated | ||
*/ | ||
fun updateFieldSubFieldBoolean(userID: String, newVal: Boolean, fieldName: String, subFieldName: String) { | ||
dbRef.child(userID) | ||
.child(fieldName) | ||
.child(subFieldName) | ||
.setValue(newVal) | ||
} | ||
|
||
/** | ||
* This function creates a new user account in the database | ||
* @param email the email of the new user | ||
|
@@ -50,17 +64,48 @@ class UsersRepo @Inject constructor() { | |
* @param callback function to be called when the the user has been created | ||
*/ | ||
fun createUser(email: String, username: String, handle: String, callback: (String) -> Unit) { | ||
var newUser = User(handle, username, "", email, 0, 0, 0, 0 | ||
) | ||
|
||
var newUser = User(handle, username, "", email, 0, 0, 0, 0) | ||
val newId = Util.createNewId() | ||
|
||
dbRef.child(newId).setValue(newUser) | ||
.addOnSuccessListener { | ||
callback(email) | ||
} | ||
} | ||
|
||
/** | ||
* Search for users by its any field in Firebase Realtime Database | ||
* @param field user fields used for a search | ||
* @param searchInput search text inputed by user | ||
* @param callback function to call with found users by username | ||
* | ||
* Comment about \uf8ff: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suggest putting this comment right below line 89 so that when people read the code, it's easier for them to find the explanation. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done! |
||
* The \uf8ff character used in the query above is a very high code point in the Unicode range. | ||
* Because it is after most regular characters in Unicode, the query matches all values that start with a inputUsername. | ||
*/ | ||
fun searchByField(field: String, searchInput: String, callback:(ArrayList<User>) -> Unit) { | ||
val queryUsers = dbRef | ||
.orderByChild(field) | ||
.startAt(searchInput) | ||
.endAt(searchInput+"\uf8ff") | ||
|
||
val users: ArrayList<User> = ArrayList() | ||
queryUsers.addValueEventListener(object : ValueEventListener { | ||
override fun onDataChange(dataSnapshot: DataSnapshot) { | ||
users.clear() | ||
for (snapshot in dataSnapshot.children) { | ||
val userProfile:User? = snapshot.getValue(User::class.java) | ||
if (userProfile != null) { | ||
users.add(userProfile) | ||
} | ||
} | ||
return callback(users) | ||
} | ||
override fun onCancelled(error: DatabaseError) { | ||
Log.w(ContentValues.TAG, "searchByField:onCancelled", error.toException()) | ||
} | ||
}) | ||
} | ||
|
||
/** | ||
* This functions fetches the data of the given user from the database | ||
* @param email the of the user | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,5 +9,6 @@ data class User( | |
var totalGames: Int = 0, | ||
var bestScore: Int = 0, | ||
var correctSongs: Int = 0, | ||
var ranking: Int = 0 | ||
) : Serializable {} | ||
var ranking: Int = 0, | ||
var uid: String = "" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why do we need an uid if the handle is already unique for each user? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was not sure whether the handle is correct. I saved the uid since the user is stored by it. We can discuss it next meeting. |
||
) : Serializable {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe explain in a comment why this test is commented
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done!