Skip to content

Commit 55c4300

Browse files
committed
refactor: Removendo arquivos desnecessários e reorganizando projeto
1 parent 5a817fc commit 55c4300

30 files changed

+770
-1247
lines changed

app/src/main/java/com/paradoxo/threadscompose/MainActivity.kt

Lines changed: 13 additions & 883 deletions
Large diffs are not rendered by default.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package com.paradoxo.threadscompose.model
2+
3+
data class Comment(
4+
val id: String = "",
5+
val profilePicAuthor: String = "",
6+
)
Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,21 @@
11
package com.paradoxo.threadscompose.model
22

3-
4-
enum class NotificationType {
5-
All,
6-
Comment,
7-
Mention,
8-
Follow,
9-
Like,
10-
Verified,
11-
}
12-
13-
143
data class Notification(
154
val id: String = "",
165
val title: String = "",
176
val description: String = "",
187
val image: Int = 0,
198
val time: String = "",
209
val extraContent: String? = null,
21-
val type: NotificationType = NotificationType.Follow,
10+
val type: NotificationTypeEnum = NotificationTypeEnum.Follow,
2211
var isFollowing: Boolean = false,
2312
)
13+
14+
enum class NotificationTypeEnum {
15+
All,
16+
Comment,
17+
Mention,
18+
Follow,
19+
Like,
20+
Verified,
21+
}

app/src/main/java/com/paradoxo/threadscompose/model/Post.kt

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,3 @@ data class Post(
1010
val likes: List<String> = emptyList(),
1111
val comments: List<Comment> = emptyList()
1212
)
13-
14-
data class Comment(
15-
val id: String = "",
16-
val profilePicAuthor: String = "",
17-
)
18-

app/src/main/java/com/paradoxo/threadscompose/network/firebase/MediaFirebaseStorage.kt

Lines changed: 2 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,13 @@ import kotlinx.coroutines.tasks.await
1313
import kotlinx.coroutines.withContext
1414
import java.util.UUID
1515

16-
class MediaFirebaseStorage() {
17-
16+
class MediaFirebaseStorage {
1817
private val idCurrentUser = Firebase.auth.currentUser?.uid
19-
2018
private val storage = Firebase.storage
2119
private val storageRef = storage.reference
2220
private val ref = storageRef.child("users/$idCurrentUser/medias/posts/")
2321

24-
25-
suspend fun uploadMediaOk(
22+
suspend fun uploadMedia(
2623
medias: List<String>,
2724
onSuccess: () -> Unit = {},
2825
onError: () -> Unit = {},
@@ -60,109 +57,4 @@ class MediaFirebaseStorage() {
6057
}
6158
}
6259
}
63-
64-
65-
suspend fun uploadMediaFazUploadMasRetornoEstaSendoImediato(
66-
medias: List<String>,
67-
onSuccess: () -> Unit = {},
68-
onError: () -> Unit = {},
69-
): List<String> {
70-
val dispatcher = Dispatchers.IO
71-
val downloadUrls = mutableListOf<String>()
72-
73-
withContext(dispatcher) {
74-
val stackTasks = medias.map { imageUri ->
75-
val uuid = UUID.randomUUID().toString()
76-
val currentRef = ref.child(uuid)
77-
78-
async(dispatcher) {
79-
val file = Uri.parse(imageUri)
80-
val uploadTask = currentRef.putFile(file)
81-
82-
uploadTask.continueWithTask { task ->
83-
if (!task.isSuccessful) {
84-
task.exception?.let {
85-
throw it
86-
}
87-
}
88-
currentRef.downloadUrl
89-
}.addOnCompleteListener { task ->
90-
if (task.isSuccessful) {
91-
val downloadUri = task.result.toString()
92-
downloadUrls.add(downloadUri)
93-
Log.i("imageUpload", "imageUpload link: $downloadUri")
94-
} else {
95-
Log.i(
96-
"imageUpload",
97-
"imageUpload error: ${task.exception}"
98-
)
99-
}
100-
}
101-
}
102-
}
103-
try {
104-
stackTasks.awaitAll()
105-
withContext(Dispatchers.Main) {
106-
onSuccess()
107-
}
108-
} catch (e: Exception) {
109-
withContext(Dispatchers.Main) {
110-
onError()
111-
}
112-
Log.i("imageUpload", "imageUpload error: ${e.message}")
113-
}
114-
}
115-
116-
return downloadUrls
117-
}
118-
119-
suspend fun uploadMediaFuncional(
120-
medias: List<String>,
121-
onSuccess: () -> Unit = {},
122-
onError: () -> Unit = {},
123-
) {
124-
val dispatcher = Dispatchers.IO
125-
126-
withContext(dispatcher) {
127-
val stackTasks = medias.map { imageUri ->
128-
val uuid = UUID.randomUUID().toString()
129-
val currentRef = ref.child(uuid)
130-
131-
async(dispatcher) {
132-
val file = Uri.parse(imageUri)
133-
val uploadTask = currentRef.putFile(file)
134-
135-
uploadTask.continueWithTask { task ->
136-
if (!task.isSuccessful) {
137-
task.exception?.let {
138-
throw it
139-
}
140-
}
141-
currentRef.downloadUrl
142-
}.addOnCompleteListener { task ->
143-
if (task.isSuccessful) {
144-
val downloadUri = task.result
145-
Log.i("imageUpload", "imageUpload link: $downloadUri")
146-
} else {
147-
Log.i(
148-
"imageUpload",
149-
"imageUpload error: ${task.exception}"
150-
)
151-
}
152-
}
153-
}
154-
}
155-
try {
156-
stackTasks.awaitAll()
157-
withContext(Dispatchers.Main) {
158-
onSuccess()
159-
}
160-
} catch (e: Exception) {
161-
withContext(Dispatchers.Main) {
162-
onError()
163-
}
164-
Log.i("imageUpload", "imageUpload error: ${e.message}")
165-
}
166-
}
167-
}
16860
}

app/src/main/java/com/paradoxo/threadscompose/network/firebase/PostFirestore.kt

Lines changed: 16 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,12 @@ package com.paradoxo.threadscompose.network.firebase
22

33
import android.util.Log
44
import com.google.firebase.firestore.FirebaseFirestore
5+
import com.google.firebase.firestore.Query
56
import com.paradoxo.threadscompose.model.Comment
67
import com.paradoxo.threadscompose.model.Post
78
import kotlinx.coroutines.CoroutineScope
8-
import kotlinx.coroutines.Dispatchers
99
import kotlinx.coroutines.Dispatchers.IO
10-
import kotlinx.coroutines.async
1110
import kotlinx.coroutines.launch
12-
import kotlinx.coroutines.withContext
1311
import java.util.UUID
1412

1513
class PostFirestore {
@@ -24,6 +22,7 @@ class PostFirestore {
2422
) {
2523
dbPosts
2624
.whereEqualTo("mainPost", true)
25+
.orderBy("date", Query.Direction.DESCENDING)
2726
.get()
2827
.addOnSuccessListener {
2928
val posts = it.toObjects(Post::class.java)
@@ -36,29 +35,32 @@ class PostFirestore {
3635
}
3736
}
3837

39-
40-
suspend fun insertPost(
38+
fun savePost(
4139
posts: List<Post>,
4240
onSuccess: () -> Unit = {},
4341
onError: () -> Unit = {},
4442
) {
4543
if (posts.size > 1) {
46-
saveThread(posts, onSuccess, onError)
44+
savePostThread(posts, onSuccess, onError)
4745
} else {
46+
val post = posts.first().copy(
47+
id = UUID.randomUUID().toString(),
48+
mainPost = true
49+
)
4850
dbPosts.document()
49-
.set(posts)
51+
.set(post)
5052
.addOnSuccessListener {
5153
onSuccess()
52-
Log.i("insertPost", "Post inserido com sucesso")
54+
Log.i("savePost", "Post salvo com sucesso")
5355
}
5456
.addOnFailureListener {
5557
onError()
56-
Log.i("insertPost", "Erro ao inserir post ${it.message}")
58+
Log.i("savePost", "Erro ao salvar post ${it.message}")
5759
}
5860
}
5961
}
6062

61-
private fun saveThread(
63+
private fun savePostThread(
6264
posts: List<Post>,
6365
onSuccess: () -> Unit,
6466
onError: () -> Unit
@@ -70,7 +72,7 @@ class PostFirestore {
7072
CoroutineScope(IO).launch {
7173
try {
7274
postsInThreadFormat.forEach { post ->
73-
val urls = mediaFirebaseStorage.uploadMediaOk(post.medias)
75+
val urls = mediaFirebaseStorage.uploadMedia(post.medias)
7476
val newPost = post.copy(medias = urls)
7577
val documentReference = dbPosts.document()
7678
batch.set(documentReference, newPost)
@@ -79,46 +81,18 @@ class PostFirestore {
7981
batch.commit()
8082
.addOnSuccessListener {
8183
onSuccess()
82-
Log.i("insertPost", "Post inserido com sucesso")
84+
Log.i("savePostThread", "Thread salvo com sucesso")
8385
}
8486
.addOnFailureListener {
8587
onError()
86-
Log.i("insertPost", "Erro ao inserir post ${it.message}")
88+
Log.i("savePostThread", "Erro ao salvar Thread ${it.message}")
8789
}
8890
} catch (e: Exception) {
89-
Log.e("saveThread", "Error uploading media: ${e.message}")
91+
Log.e("savePostThread", "Erro ao salvar Thread ${e.message}")
9092
}
9193
}
9294
}
9395

94-
95-
96-
97-
private fun saveThreadOld(
98-
posts: List<Post>,
99-
onSuccess: () -> Unit,
100-
onError: () -> Unit
101-
) {
102-
val batch = firebaseFirestore.batch()
103-
104-
val postsInThreadFormat: List<Post> = generatePostsInThreadFormat(posts)
105-
106-
postsInThreadFormat.forEach { post ->
107-
val documentReference = dbPosts.document()
108-
batch.set(documentReference, post)
109-
}
110-
111-
batch.commit()
112-
.addOnSuccessListener {
113-
onSuccess()
114-
Log.i("insertPost", "Post inserido com sucesso")
115-
}
116-
.addOnFailureListener {
117-
onError()
118-
Log.i("insertPost", "Erro ao inserir post ${it.message}")
119-
}
120-
}
121-
12296
private fun generatePostsInThreadFormat(posts: List<Post>): List<Post> {
12397
val postsInThreadFormat = mutableListOf<Post>()
12498
val randomIdList: List<String> = mutableListOf<String>().apply {
@@ -149,7 +123,6 @@ class PostFirestore {
149123
)
150124
}
151125

152-
153126
return postsInThreadFormat
154127
}
155128
}

app/src/main/java/com/paradoxo/threadscompose/network/firebase/UserFirestore.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import com.paradoxo.threadscompose.model.UserAccount
66

77
class UserFirestore {
88
private val firebaseFirestore = FirebaseFirestore.getInstance()
9-
val dbUsers = firebaseFirestore.collection("users")
9+
private val dbUsers = firebaseFirestore.collection("users")
1010

1111

1212
fun getUserById(
@@ -19,7 +19,7 @@ class UserFirestore {
1919
.addOnSuccessListener {
2020
it.toObject(UserAccount::class.java)?.let { userAccount ->
2121
onSuccess(userAccount)
22-
Log.i("getUserById", "Usuário obtido com sucesso ${userAccount?.name}")
22+
Log.i("getUserById", "Usuário obtido com sucesso ${userAccount.name}")
2323
} ?: run {
2424
onError()
2525
Log.i("getUserById", "Usuário não encontrado")
@@ -41,11 +41,11 @@ class UserFirestore {
4141
.set(userAccount)
4242
.addOnSuccessListener {
4343
onSuccess()
44-
Log.i("saveUser", "Usuário inserido com sucesso")
44+
Log.i("saveUser", "Usuário salvo com sucesso")
4545
}
4646
.addOnFailureListener {
4747
onError()
48-
Log.i("saveUser", "Erro ao inserir usuário ${it.message}")
48+
Log.i("saveUser", "Erro ao salvar usuário ${it.message}")
4949
}
5050
}
5151
}

app/src/main/java/com/paradoxo/threadscompose/sampleData/SampleData.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package com.paradoxo.threadscompose.sampleData
33
import com.paradoxo.threadscompose.R
44
import com.paradoxo.threadscompose.model.Comment
55
import com.paradoxo.threadscompose.model.Notification
6-
import com.paradoxo.threadscompose.model.NotificationType
6+
import com.paradoxo.threadscompose.model.NotificationTypeEnum
77
import com.paradoxo.threadscompose.model.Post
88
import com.paradoxo.threadscompose.model.UserAccount
99
import com.paradoxo.threadscompose.utils.getCurrentTime
@@ -40,7 +40,7 @@ class SampleData {
4040
"Buscando a magia em cada dia.",
4141
"Vivendo a vida ao máximo!"
4242
)
43-
val images = listOf(
43+
private val images = listOf(
4444
"https://raw.githubusercontent.com/git-jr/sample-files/7bc859dfa8a6241fa9c0d723ba6e7517bdfedd50/profile%20pics/profile_pic_emoji_1.png",
4545
"https://raw.githubusercontent.com/git-jr/sample-files/7bc859dfa8a6241fa9c0d723ba6e7517bdfedd50/profile%20pics/profile_pic_emoji_2.png",
4646
"https://raw.githubusercontent.com/git-jr/sample-files/7bc859dfa8a6241fa9c0d723ba6e7517bdfedd50/profile%20pics/profile_pic_emoji_3.png",
@@ -94,8 +94,8 @@ class SampleData {
9494
extraContent = if (Random.nextBoolean()) "Conteúdo extra $it" else null,
9595
image = R.drawable.profile_pic_emoji_4,
9696
time = "1d",
97-
type = if (it in 2..4) NotificationType.values().sortedArray()[it] else
98-
NotificationType.values().sortedArray()[Random.nextInt(0, 5)],
97+
type = if (it in 2..4) NotificationTypeEnum.values().sortedArray()[it] else
98+
NotificationTypeEnum.values().sortedArray()[Random.nextInt(0, 5)],
9999
isFollowing = Random.nextBoolean(),
100100
)
101101
)

0 commit comments

Comments
 (0)