-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #308 from fga-gpp-mds/feature/267
Feature/267
- Loading branch information
Showing
44 changed files
with
1,922 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 0 additions & 1 deletion
1
project/app/src/main/java/com/nexte/nexte/Entities/Challenge/ChallengeMocker.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
package com.nexte.nexte.Entities.Challenge | ||
|
||
import java.util.* | ||
|
||
object ChallengeMocker { | ||
|
15 changes: 10 additions & 5 deletions
15
project/app/src/main/java/com/nexte/nexte/Entities/Comment/Comment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
project/app/src/main/java/com/nexte/nexte/Entities/Comment/CommentAdapter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.nexte.nexte.Entities.Comment | ||
|
||
/** | ||
* Interface to allow Comment Entity to assume different values according | ||
* to Realm | ||
*/ | ||
interface CommentAdapter { | ||
fun getAll(): List<Comment> | ||
fun get(identifier: String): Comment? | ||
fun updateOrInsert(challenge: Comment): Comment? | ||
fun delete(identifier: String): Comment? | ||
} |
78 changes: 78 additions & 0 deletions
78
project/app/src/main/java/com/nexte/nexte/Entities/Comment/CommentAdapterRealm.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package com.nexte.nexte.Entities.Comment | ||
import io.realm.Realm | ||
import io.realm.kotlin.where | ||
|
||
/** | ||
* Class to allow adaptations of data and sending to Realm. | ||
* */ | ||
class CommentAdapterRealm : CommentAdapter { | ||
|
||
var realm: Realm = Realm.getDefaultInstance() | ||
|
||
override fun get(identifier: String): Comment? { | ||
val commentRealm = realm.where<CommentRealm>().equalTo("id", identifier).findFirst() | ||
return convertCommentRealmToComment(commentRealm!!) | ||
} | ||
|
||
override fun getAll(): List<Comment> { | ||
val commentRealmResults = realm.where<CommentRealm>().findAll() | ||
return convertListCommentRealmToCommentList(commentRealmResults) | ||
|
||
} | ||
|
||
override fun updateOrInsert(comment: Comment): Comment? { | ||
convertCommentToCommentRealm(comment)?.let { | ||
realm.beginTransaction() | ||
realm.insertOrUpdate(it) | ||
realm.commitTransaction() | ||
return comment | ||
} | ||
|
||
return null | ||
} | ||
|
||
override fun delete(identifier: String): Comment? { | ||
|
||
return null | ||
} | ||
|
||
private fun convertCommentRealmToComment(commentRealm: CommentRealm) : Comment { | ||
|
||
val commentId = commentRealm.id | ||
|
||
val userId = commentRealm.userId | ||
|
||
val comment = commentRealm.comment | ||
|
||
val date = commentRealm.date | ||
|
||
val comments = Comment(id = commentId, userId = userId, comment = comment, date = date) | ||
return comments | ||
} | ||
|
||
private fun convertListCommentRealmToCommentList(commentRealm: List<CommentRealm>) : List<Comment> { | ||
val comments: MutableList<Comment> = mutableListOf() | ||
for(commentRealm in commentRealm) { | ||
convertCommentRealmToComment(commentRealm)?.let { | ||
comments.add(it) | ||
} | ||
} | ||
|
||
return comments.toList() | ||
} | ||
|
||
private fun convertCommentToCommentRealm(comment: Comment): CommentRealm { | ||
|
||
val id = comment.id | ||
|
||
val userId = comment.userId | ||
|
||
val comments = comment.comment | ||
|
||
val date = comment.date | ||
|
||
val commentRealm = CommentRealm(id = id, userId = userId, comment = comments, date = date) | ||
return commentRealm | ||
} | ||
|
||
} |
54 changes: 52 additions & 2 deletions
54
project/app/src/main/java/com/nexte/nexte/Entities/Comment/CommentManager.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,57 @@ | ||
package com.nexte.nexte.Entities.Comment | ||
|
||
class CommentManager { | ||
fun createInitialMocker() { | ||
/** | ||
* Class define according to scene requests which kind of response will be displayed: | ||
* data from remote repository or from data storage. | ||
* @param commentAdapter hold information from CommentAdapterRealm | ||
* */ | ||
class CommentManager(private val commentAdapter: CommentAdapter = CommentAdapterRealm()) { | ||
fun get(identifier: String): Comment? { | ||
return commentAdapter.get(identifier) | ||
} | ||
|
||
fun getAll(): List<Comment> { | ||
return commentAdapter.getAll() | ||
} | ||
|
||
fun update(comment: Comment): Comment? { | ||
return commentAdapter.updateOrInsert(comment) | ||
} | ||
|
||
fun updateMany(comments: List<Comment>): List<Comment> { | ||
val newComments: MutableList<Comment> = mutableListOf() | ||
for (comment in comments) { | ||
val updatedComment = commentAdapter.updateOrInsert(comment) | ||
updatedComment?.let { | ||
newComments.add(it) | ||
} | ||
} | ||
return newComments.toList() | ||
} | ||
|
||
fun delete(identifier: String): Comment? { | ||
return commentAdapter.delete(identifier) | ||
} | ||
|
||
fun createInitialMocker(): List<Comment> { | ||
|
||
val commentsInMocker = CommentMocker.allComments | ||
val insertedComments: MutableList<Comment> = mutableListOf() | ||
|
||
for (comment in commentsInMocker) { | ||
|
||
val insertedComment = commentAdapter.updateOrInsert(comment) | ||
insertedComment?.let { | ||
insertedComments.add(it) | ||
} | ||
} | ||
return insertedComments.toList() | ||
} | ||
|
||
fun createCommentsIds(amount: Int): List<String>{ | ||
return CommentMocker.generateComments(amount = amount) | ||
} | ||
|
||
|
||
|
||
} |
147 changes: 147 additions & 0 deletions
147
project/app/src/main/java/com/nexte/nexte/Entities/Comment/CommentMocker.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
package com.nexte.nexte.Entities.Comment | ||
import com.nexte.nexte.Entities.User.User | ||
import com.nexte.nexte.Entities.User.UserAdapter | ||
import com.nexte.nexte.Entities.User.UserManager | ||
import java.util.* | ||
|
||
|
||
/** | ||
* Singleton responsible for mock comment data | ||
*/ | ||
object CommentMocker{ | ||
|
||
/** | ||
* @property commentTextMocks contains a list of mock comments | ||
*/ | ||
private val commentTextMocks = listOf("Que jogo sensacional! " + | ||
"Muita coisa ruim aconteceu mas eu sei que muita coisa ainda " + | ||
"vai acontecer e por isso torço muito para que muita coisa" + | ||
" continue acontecendo porque no final é tudo o que importa," + | ||
" não é mesmo? Eu sei meu amigo." + | ||
" As coisas mudam e tudo tem que mudar. A vida é assim!!!", | ||
"Tá na hora da revanche!" + | ||
" As coisas mudam e tudo tem que mudar. A vida é assim!!!", | ||
"Você é muito pato", | ||
"Arregou! Torço muito para que muita coisa continue" + | ||
" acontecendo porque no final é tudo o que importa, não é mesmo?" + | ||
" Eu sei meu amigo. As coisas mudam" + | ||
" e tudo tem que mudar. A vida é assim!!!", | ||
"Eu Não imaginava esse placar. ", | ||
"Eu também acho isso. Eu sei meu amigo." + | ||
" As coisas mudam e tudo tem que mudar. A vida é assim!!!", | ||
"Mais seriedade", | ||
"Não vou mais jogar contigo.", | ||
"Cala a boca!") | ||
var commentsId = 0 | ||
var userAdapter: UserAdapter? = null | ||
var commentAdapter: CommentAdapter? = null | ||
var allComments = mutableListOf<Comment>() | ||
|
||
/** | ||
* Function to generate random numbers | ||
*/ | ||
private fun randomNumber(from: Int, to: Int): Int{ | ||
val random = Random() | ||
println("BOUND: " + (to - from)) | ||
|
||
val bound = to - from | ||
|
||
if (bound > 0){ | ||
return random.nextInt(bound) + from | ||
}else{ | ||
return from | ||
} | ||
} | ||
|
||
/** | ||
* Function to generate random dates for all comments | ||
*/ | ||
private fun generateRandomDate(): Date { | ||
val year = randomNumber(2013, 2018) | ||
val dayOfYear = randomNumber(1, 30) | ||
val monthOfYear = randomNumber(1, 12) | ||
val date = Date(year, monthOfYear, dayOfYear) | ||
return date | ||
} | ||
|
||
/** | ||
* Function to generate comments Ids | ||
*/ | ||
private fun getCommentIds(amount: Int): List<String>{ | ||
|
||
val commentsIds = mutableListOf<String>() | ||
for(counter in 0..amount - 1){ | ||
commentsIds.add(commentsId++.toString()) | ||
} | ||
|
||
return commentsIds.toList() | ||
} | ||
|
||
/** | ||
* Function to generate users Ids | ||
*/ | ||
private fun getUsersIds(usersAmount: Int) : List<String> { | ||
var users = listOf<User>() | ||
|
||
if(userAdapter == null){ | ||
users = UserManager().getAll() | ||
}else{ | ||
users = UserManager(userAdapter = userAdapter!!).getAll() | ||
} | ||
|
||
val usersIds = mutableListOf<String>() | ||
|
||
println(users.size) | ||
println(usersAmount) | ||
for (counter in 0..usersAmount - 1){ | ||
println(counter) | ||
usersIds.add(users[counter].id) | ||
} | ||
|
||
return usersIds | ||
} | ||
|
||
/** | ||
* Function to generate a date for a comment | ||
*/ | ||
private fun getDates(amount: Int): List<Date>{ | ||
val dates = mutableListOf<Date>() | ||
|
||
for (counter in 0..amount - 1){ | ||
dates.add(generateRandomDate()) | ||
} | ||
|
||
return dates | ||
} | ||
|
||
/** | ||
* Function to get content of a comment | ||
*/ | ||
private fun getComments(amount: Int): List<String>{ | ||
val comments = mutableListOf<String>() | ||
|
||
for(counter in 0..amount - 1){ | ||
comments.add(commentTextMocks[counter]) | ||
} | ||
|
||
return comments | ||
} | ||
|
||
/** | ||
* Function to generate random data for comments which contains ids, | ||
* userIds, dates and a comment from a user | ||
*/ | ||
fun generateComments(amount: Int): List<String>{ | ||
val ids = getCommentIds(amount) | ||
val userIds = getUsersIds(amount) | ||
val dates = getDates(amount) | ||
val comments = getComments(amount) | ||
|
||
for (counter in 0..amount - 1){ | ||
val comment = Comment(ids[counter], userIds[counter], comments[counter], dates[counter]) | ||
allComments.add(comment) | ||
} | ||
|
||
return ids | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
project/app/src/main/java/com/nexte/nexte/Entities/Comment/CommentRealm.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.nexte.nexte.Entities.Comment | ||
import io.realm.RealmObject | ||
import io.realm.annotations.PrimaryKey | ||
import java.util.* | ||
|
||
/** | ||
* Class to define global data for the whole application. | ||
* @param id contains the id of the comment | ||
* @param userId contains the id from the user which is commenting | ||
* @param comment contains the comment | ||
* @param date contains the date of the comment | ||
* */ | ||
open class CommentRealm(@PrimaryKey var id: String? = null, | ||
var userId: String? = null, | ||
var comment: String? = null, | ||
var date: Date? = null): RealmObject() { | ||
|
||
enum class ServerRequest(val request: Map<String, String>) { | ||
COMMENTS(hashMapOf("route" to "comments", "method" to "get")), | ||
ADD_COMMENT(hashMapOf("route" to "comment", "method" to "post")), | ||
DELETE_COMMENT(hashMapOf("route" to "comment", "method" to "delete")), | ||
REPORT_COMMENT(hashMapOf("route" to "report-comment", "method" to "post")) | ||
} | ||
} |
4 changes: 1 addition & 3 deletions
4
project/app/src/main/java/com/nexte/nexte/Entities/Like/Like.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
project/app/src/main/java/com/nexte/nexte/Entities/Like/LikeAdapter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.nexte.nexte.Entities.Like | ||
|
||
interface LikeAdapter { | ||
fun getAll(): List<Like> | ||
fun get(identifier: String): Like? | ||
fun updateOrInsert(like: Like): Like? | ||
fun delete(identifier: String): Like? | ||
} |
Oops, something went wrong.