This file contains hidden or 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
| import androidx.compose.foundation.Image | |
| import androidx.compose.foundation.layout.fillMaxWidth | |
| import androidx.compose.foundation.layout.height | |
| import androidx.compose.material3.MaterialTheme | |
| import androidx.compose.runtime.Composable | |
| import androidx.compose.ui.Modifier | |
| import androidx.compose.ui.layout.ContentScale | |
| import androidx.compose.ui.unit.dp | |
| import coil.compose.rememberImagePainter | |
| import kotlinx.serialization.Serializable |
This file contains hidden or 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
| rules_version = '2'; | |
| service cloud.firestore { | |
| match /databases/{database}/documents { | |
| function signedIn() { | |
| return request.auth.uid != null; | |
| } | |
| match /users/{user} { | |
| allow read, write: if (signedIn() == true); | |
| } | |
| match /posts/{post} { |
This file contains hidden or 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
| rules_version = '2'; | |
| service cloud.firestore { | |
| match /databases/{database}/documents { | |
| function signedIn() { | |
| return request.auth.uid != null; | |
| } | |
| match /users/{user} { | |
| allow read, write: if (signedIn() == true); | |
| } | |
| match /posts/{post} { |
This file contains hidden or 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
| rules_version = '2'; | |
| service cloud.firestore { | |
| match /databases/{database}/documents { | |
| match /{document=**} { | |
| allow read, write | |
| } | |
| } | |
| } |
This file contains hidden or 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
| fun changeLike(postItem: PostItem, onCompleted: (Result<Boolean>) -> Unit) { | |
| val currentUser = FirebaseAuthHelper.instance.currentUser | |
| val document = FirebaseFirestore.getInstance().collection("posts").document(postItem.uuid) | |
| if (currentUser != null) { | |
| // Подготавливаем здесь контент | |
| FirebaseFirestore.getInstance().runTransaction { transition -> | |
| //Обновляем поля | |
| transition.update(document, "likeItems", newLikes) | |
| newLikes | |
| }.addOnSuccessListener { result -> |
This file contains hidden or 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
| suspend fun sendComment(commentItem: CommentItem) { | |
| val currentUser = FirebaseAuthHelper.instance.currentUser | |
| commentItem.userId = currentUser?.uid.orEmpty() | |
| commentItem.userName = currentUser?.displayName.orEmpty() | |
| val collection = | |
| FirebaseFirestore.getInstance().collection("posts").document(commentItem.postId) | |
| .collection("comments") | |
| val document = collection.document(commentItem.uuid) | |
| document.set(commentItem).await() |
This file contains hidden or 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
| fun startListenToComments(postId: String, result: (List<CommentItem>) -> Unit) { | |
| val collection = FirebaseFirestore.getInstance().collection("posts").document(postId) | |
| .collection("comments") | |
| commentListener = collection.orderBy("date", Query.Direction.DESCENDING) | |
| .addSnapshotListener(MetadataChanges.INCLUDE) { data, firebaseFirestoreExceptioor -> | |
| if (data != null) { | |
| val comments = data.toObjects(CommentItem::class.java) | |
| result(comments) | |
| } | |
| } |
This file contains hidden or 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
| val storage = Firebase.storage | |
| suspend fun uploadImage(bytes: ByteArray): Uri? { | |
| //Ссылка на объект | |
| val reference = storage.reference.child("image-${Date()}.jpg") | |
| var uploadTask = reference.putBytes(bytes) | |
| // Ожидаем загрузку | |
| uploadTask.await() | |
| //Обрабатываем конечный url | |
| return reference.downloadUrl.await() |
This file contains hidden or 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
| suspend fun deletePost(id: String) { | |
| val collection = FirebaseFirestore.getInstance().collection("posts") | |
| val document = collection.document(id) | |
| document.delete().await() | |
| } |
This file contains hidden or 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
| //Создание | |
| suspend fun createPost(postItem: PostItem) { | |
| val currentUser = FirebaseAuthHelper.instance.currentUser | |
| postItem.userId = currentUser?.uid.orEmpty() | |
| postItem.userName = currentUser?.displayName.orEmpty() | |
| val collection = FirebaseFirestore.getInstance().collection("posts") | |
| val document = collection.document(postItem.uuid) | |
| document.set(postItem).await() | |
| } |
NewerOlder