From a19a90809fe9455693e52798c2e1c9f52e475cb0 Mon Sep 17 00:00:00 2001 From: Jun Date: Wed, 17 Apr 2024 00:29:23 +0900 Subject: [PATCH] =?UTF-8?q?[#44]=20=EA=B2=8C=EC=8B=9C=ED=8C=90=20=ED=99=94?= =?UTF-8?q?=EB=A9=B4=20=ED=9D=90=EB=A6=84=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- MungNolZa/app/build.gradle.kts | 3 + MungNolZa/app/src/main/AndroidManifest.xml | 1 + .../data/repository/BoardRepository.kt | 6 +- .../data/repository/BoardRepositoryImpl.kt | 16 ++- .../mungnolza/datasource/MainDataStore.kt | 52 +++++++++ .../mungnolza/model/BoardAddUerInfoModel.kt | 4 +- .../kr/co/lion/mungnolza/model/PetImgModel.kt | 12 +++ .../kr/co/lion/mungnolza/model/PetModel.kt | 29 +++++ .../kr/co/lion/mungnolza/model/UserModel.kt | 24 +++-- .../repository/FreeBoardRepository.kt | 13 --- .../repository/FreeBoardRepositoryImpl.kt | 84 --------------- .../mungnolza/repository/UserRepository.kt | 9 -- .../repository/UserRepositoryImpl.kt | 32 ------ .../freeboard/FreeBoardRepository.kt | 9 ++ .../freeboard/FreeBoardRepositoryImpl.kt | 43 ++++++++ .../mungnolza/repository/pet/PetRepository.kt | 9 ++ .../repository/pet/PetRepositoryImpl.kt | 36 +++++++ .../repository/user/UserRepository.kt | 10 ++ .../repository/user/UserRepositoryImpl.kt | 50 +++++++++ .../co/lion/mungnolza/ui/chat/ChatActivity.kt | 2 +- .../freeboard/adapter/BoardCarouselAdapter.kt | 7 +- .../adapter/BoardCarouselViewHolder.kt | 14 ++- .../ui/freeboard/fragment/AddBoardFragment.kt | 9 +- .../fragment/ShowDetailBoardFragment.kt | 100 ++++++++++++++---- .../freeboard/viewmodel/AddBoardViewModel.kt | 2 - .../ui/freeboard/viewmodel/BoardViewModel.kt | 6 +- .../ui/main/adapter/FreeBoardAdapter.kt | 12 ++- .../ui/main/adapter/HomeReviewAdapter.kt | 41 +++++++ .../ui/main/fragment/FreeBoardFragment.kt | 34 +++--- .../ui/main/fragment/MainChatFragment.kt | 5 +- .../ui/main/viewmodel/MainViewModel.kt | 81 +++++++++++--- .../ui/main/viewmodel/MainViewModelFactory.kt | 10 +- .../fragment/PetSitterReviewWriteFragment.kt | 2 +- .../java/kr/co/lion/mungnolza/util/App.kt | 22 ++++ .../main/res/layout/fragment_detail_chat.xml | 6 +- .../main/res/layout/fragment_free_board.xml | 17 ++- .../main/res/layout/fragment_main_chat.xml | 27 +++-- .../main/res/layout/row_review_preview.xml | 75 +++++++++++++ 38 files changed, 667 insertions(+), 247 deletions(-) create mode 100644 MungNolZa/app/src/main/java/kr/co/lion/mungnolza/datasource/MainDataStore.kt create mode 100644 MungNolZa/app/src/main/java/kr/co/lion/mungnolza/model/PetImgModel.kt create mode 100644 MungNolZa/app/src/main/java/kr/co/lion/mungnolza/model/PetModel.kt delete mode 100644 MungNolZa/app/src/main/java/kr/co/lion/mungnolza/repository/FreeBoardRepository.kt delete mode 100644 MungNolZa/app/src/main/java/kr/co/lion/mungnolza/repository/FreeBoardRepositoryImpl.kt delete mode 100644 MungNolZa/app/src/main/java/kr/co/lion/mungnolza/repository/UserRepository.kt delete mode 100644 MungNolZa/app/src/main/java/kr/co/lion/mungnolza/repository/UserRepositoryImpl.kt create mode 100644 MungNolZa/app/src/main/java/kr/co/lion/mungnolza/repository/freeboard/FreeBoardRepository.kt create mode 100644 MungNolZa/app/src/main/java/kr/co/lion/mungnolza/repository/freeboard/FreeBoardRepositoryImpl.kt create mode 100644 MungNolZa/app/src/main/java/kr/co/lion/mungnolza/repository/pet/PetRepository.kt create mode 100644 MungNolZa/app/src/main/java/kr/co/lion/mungnolza/repository/pet/PetRepositoryImpl.kt create mode 100644 MungNolZa/app/src/main/java/kr/co/lion/mungnolza/repository/user/UserRepository.kt create mode 100644 MungNolZa/app/src/main/java/kr/co/lion/mungnolza/repository/user/UserRepositoryImpl.kt create mode 100644 MungNolZa/app/src/main/java/kr/co/lion/mungnolza/ui/main/adapter/HomeReviewAdapter.kt create mode 100644 MungNolZa/app/src/main/java/kr/co/lion/mungnolza/util/App.kt create mode 100644 MungNolZa/app/src/main/res/layout/row_review_preview.xml diff --git a/MungNolZa/app/build.gradle.kts b/MungNolZa/app/build.gradle.kts index b5f37f0..cad10a7 100644 --- a/MungNolZa/app/build.gradle.kts +++ b/MungNolZa/app/build.gradle.kts @@ -57,6 +57,7 @@ dependencies { implementation("androidx.activity:activity:1.8.2") implementation("com.google.android.gms:play-services-maps:18.2.0") implementation("androidx.coordinatorlayout:coordinatorlayout:1.2.0") + implementation("androidx.datastore:datastore-core:1.0.0") testImplementation("junit:junit:4.13.2") androidTestImplementation("androidx.test.ext:junit:1.1.5") androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1") @@ -89,4 +90,6 @@ dependencies { implementation("com.google.android.gms:play-services-maps:18.2.0") implementation("com.google.android.gms:play-services-location:21.2.0") + implementation("androidx.datastore:datastore-preferences:1.0.0") + } \ No newline at end of file diff --git a/MungNolZa/app/src/main/AndroidManifest.xml b/MungNolZa/app/src/main/AndroidManifest.xml index ed0dfa2..9c896ae 100644 --- a/MungNolZa/app/src/main/AndroidManifest.xml +++ b/MungNolZa/app/src/main/AndroidManifest.xml @@ -9,6 +9,7 @@ } \ No newline at end of file diff --git a/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/data/repository/BoardRepositoryImpl.kt b/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/data/repository/BoardRepositoryImpl.kt index d05cbca..43c5f8a 100644 --- a/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/data/repository/BoardRepositoryImpl.kt +++ b/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/data/repository/BoardRepositoryImpl.kt @@ -1,7 +1,10 @@ package kr.co.lion.mungnolza.data.repository +import android.content.Context import android.net.Uri import android.util.Log +import android.widget.ImageView +import com.bumptech.glide.Glide import com.google.firebase.Firebase import com.google.firebase.firestore.Query import com.google.firebase.firestore.firestore @@ -70,9 +73,9 @@ class BoardRepositoryImpl() : BoardRepository { // 삭제가 아닌 BoardState 변경 } - override suspend fun getBoardImageListPath(boardModel: BoardModel):Uri?{ + override suspend fun getBoardImageUri(boardIdx:Int,imageFilePath: String):Uri?{ var response:Uri? = null - val path = "board/${boardModel.boardIdx}/${boardModel.boardImagePathList}" + val path = "board/${boardIdx}/${imageFilePath}" try{ response = storage.child(path).downloadUrl.await() }catch (e:Exception){ @@ -80,8 +83,15 @@ class BoardRepositoryImpl() : BoardRepository { "Error Get BoardImageListPath : ${storage.child(path)}") } return response - } + override suspend fun getBoardImageUriList(boardModel:BoardModel): MutableList { + var imageUriList:MutableList = mutableListOf() + + boardModel.boardImagePathList.forEach { + imageUriList.add(getBoardImageUri(boardModel.boardIdx,it!!)!!) + } + return imageUriList + } } \ No newline at end of file diff --git a/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/datasource/MainDataStore.kt b/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/datasource/MainDataStore.kt new file mode 100644 index 0000000..07fe394 --- /dev/null +++ b/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/datasource/MainDataStore.kt @@ -0,0 +1,52 @@ +package kr.co.lion.mungnolza.datasource + +import android.content.Context +import androidx.datastore.core.DataStore +import androidx.datastore.preferences.core.Preferences +import androidx.datastore.preferences.core.booleanPreferencesKey +import androidx.datastore.preferences.core.edit +import androidx.datastore.preferences.core.stringPreferencesKey +import androidx.datastore.preferences.preferencesDataStore +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.map +import kr.co.lion.mungnolza.util.App + + +object MainDataStore { + private fun getContext(): Context = App.context() + + private val mDataStore: DataStore + get() = getContext().dataStore + + private val Context.dataStore : DataStore by preferencesDataStore("user_pref") + private val FIRST_FLAG = booleanPreferencesKey("FIRST_FLAG") + private val USER_NUMBER = stringPreferencesKey("USER_NUMBER") + + suspend fun setupFirstData(){ + mDataStore.edit { pref -> + pref[FIRST_FLAG] = true + } + } + + suspend fun getFirstFlag(): Boolean{ + var currentValue = false + + mDataStore.edit { pref-> + currentValue = pref[FIRST_FLAG] ?: false + } + + return currentValue + } + + suspend fun setUserNumber(uniqueNumber: String){ + mDataStore.edit { pref-> + pref[USER_NUMBER] = uniqueNumber + } + } + + fun getUserNumber(): Flow { + return mDataStore.data.map { preferences -> + preferences[USER_NUMBER] ?: "" + } + } +} \ No newline at end of file diff --git a/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/model/BoardAddUerInfoModel.kt b/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/model/BoardAddUerInfoModel.kt index b36e73b..6f82a78 100644 --- a/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/model/BoardAddUerInfoModel.kt +++ b/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/model/BoardAddUerInfoModel.kt @@ -1,9 +1,9 @@ package kr.co.lion.mungnolza.model -import android.net.Uri +import java.net.URI data class BoardAddUerInfoModel ( val contentData: BoardModel, val writerNickName: String, - val imgUri: Uri + val imgUri: URI ) \ No newline at end of file diff --git a/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/model/PetImgModel.kt b/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/model/PetImgModel.kt new file mode 100644 index 0000000..493a6f5 --- /dev/null +++ b/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/model/PetImgModel.kt @@ -0,0 +1,12 @@ +package kr.co.lion.mungnolza.model + +import android.os.Parcelable +import kotlinx.parcelize.Parcelize +import kotlinx.parcelize.RawValue +import java.net.URI + +@Parcelize +data class PetImgModel ( + val petInfo: @RawValue PetModel, + val imgUrl: URI +): Parcelable \ No newline at end of file diff --git a/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/model/PetModel.kt b/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/model/PetModel.kt new file mode 100644 index 0000000..9957519 --- /dev/null +++ b/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/model/PetModel.kt @@ -0,0 +1,29 @@ +package kr.co.lion.mungnolza.model + +import android.os.Parcelable +import kotlinx.parcelize.Parcelize + +@Parcelize +data class PetModel ( + val ownerIdx: String, + val petName: String, + val petBreed: String, + val petGender: String, + val petWeight: String, + val petAge: String, + val isNeutering: Boolean, + val petSignificant: String, + val imgName: String +): Parcelable { + constructor(): this( + ownerIdx = "", + petName = "", + petBreed = "", + petGender = "", + petWeight = "", + petAge = "", + isNeutering = true, + petSignificant = "", + imgName = "" + ) +} \ No newline at end of file diff --git a/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/model/UserModel.kt b/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/model/UserModel.kt index 8da63fb..9aaaf17 100644 --- a/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/model/UserModel.kt +++ b/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/model/UserModel.kt @@ -1,16 +1,20 @@ package kr.co.lion.mungnolza.model +import android.os.Parcelable +import kotlinx.parcelize.Parcelize + +@Parcelize data class UserModel( - var uniqueNumber: String, - var userNickname: String, - var userName: String, - var userEmail: String, - var userPhone: String, - var userAddress: String, - var userProfileImgPath: String, - var userAgeRange : String, - var userGender: String -){ + val uniqueNumber: String, + val userNickname: String, + val userName: String, + val userEmail: String, + val userPhone: String, + val userAddress: String, + val userProfileImgPath: String, + val userAgeRange : String, + val userGender: String +): Parcelable { constructor(): this( uniqueNumber = "", userNickname = "", diff --git a/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/repository/FreeBoardRepository.kt b/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/repository/FreeBoardRepository.kt deleted file mode 100644 index 5c08a35..0000000 --- a/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/repository/FreeBoardRepository.kt +++ /dev/null @@ -1,13 +0,0 @@ -package kr.co.lion.mungnolza.repository - -import android.net.Uri -import kr.co.lion.mungnolza.model.BoardModel - -interface FreeBoardRepository { - suspend fun fetchAllBoardData(): ArrayList - suspend fun fetchAllBoardImage(boardIdx: String, imgName: String): Uri? - - suspend fun insertBoardData(boardModel: BoardModel) - - suspend fun updateBoardData(boardModel:BoardModel, isRemoveImage:Boolean) -} \ No newline at end of file diff --git a/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/repository/FreeBoardRepositoryImpl.kt b/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/repository/FreeBoardRepositoryImpl.kt deleted file mode 100644 index f526ffd..0000000 --- a/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/repository/FreeBoardRepositoryImpl.kt +++ /dev/null @@ -1,84 +0,0 @@ -package kr.co.lion.mungnolza.repository - -import android.net.Uri -import android.util.Log -import com.google.firebase.Firebase -import com.google.firebase.firestore.FirebaseFirestore -import com.google.firebase.firestore.Query -import com.google.firebase.firestore.firestore -import com.google.firebase.storage.StorageReference -import com.google.firebase.storage.storage -import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.launch -import kotlinx.coroutines.tasks.await -import kr.co.lion.mungnolza.model.BoardModel -import kr.co.lion.mungnolza.util.ContentState - -class FreeBoardRepositoryImpl : FreeBoardRepository { - private val boardStore = Firebase.firestore.collection("Board") - private val storage = Firebase.storage.reference - override suspend fun fetchAllBoardData(): ArrayList { - val boardList = ArrayList() - - try{ - var query = boardStore.whereEqualTo("boardState", ContentState.CONTENT_STATE_NORMAL.number) - query = query.orderBy("boardIdx", Query.Direction.DESCENDING) - - val querySnapshot = query.get().await() - querySnapshot.forEach { - val contentModel = it.toObject(BoardModel::class.java) - boardList.add(contentModel) - } - - }catch (e: Exception) { - Log.e("FirebaseResult", "Error fetching Board: ${e.message}") - } - - return boardList - } - - override suspend fun fetchAllBoardImage(boardIdx: String, imgName: String): Uri?{ - var response: Uri? = null - val path = "board/$boardIdx/$imgName" - try { - response = storage.child(path).downloadUrl.await() - }catch (e: Exception){ - Log.e("FirebaseResult", - "Error fetching BoardImage path : ${storage.child(path)}") - } - return response - } - - // insert - override suspend fun insertBoardData(boardModel: BoardModel){ - val job = CoroutineScope(Dispatchers.IO).launch { - boardStore.add(boardModel) - } - job.join() - } - - // update - override suspend fun updateBoardData(boardModel:BoardModel, isRemoveImage:Boolean){ - val job = CoroutineScope(Dispatchers.IO).launch { - val query = boardStore.whereEqualTo("boardIdx", boardModel.boardIdx).get().await() - - val map = mutableMapOf() - map["boardTitle"] = boardModel.boardTitle - map["boardContent"] = boardModel.boardContent - map["boardWriteDate"] = boardModel.boardWriteDate - - if(boardModel.boardImagePathList.isNotEmpty()){ - map["boardImagePathList"] = boardModel.boardImagePathList - } - - if(isRemoveImage == true){ - map["boardImagePathList"] = null - } - - query.documents[0].reference.update(map) - } - - job.join() - } -} \ No newline at end of file diff --git a/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/repository/UserRepository.kt b/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/repository/UserRepository.kt deleted file mode 100644 index 1a10ed3..0000000 --- a/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/repository/UserRepository.kt +++ /dev/null @@ -1,9 +0,0 @@ -package kr.co.lion.mungnolza.repository - -import android.net.Uri -import kr.co.lion.mungnolza.model.UserModel - -interface UserRepository { - suspend fun fetchAllUserNickName(uniqueNumber: String) : String - suspend fun fetchUserProfileImage(path: String) : Uri -} \ No newline at end of file diff --git a/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/repository/UserRepositoryImpl.kt b/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/repository/UserRepositoryImpl.kt deleted file mode 100644 index f3420c1..0000000 --- a/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/repository/UserRepositoryImpl.kt +++ /dev/null @@ -1,32 +0,0 @@ -package kr.co.lion.mungnolza.repository - -import android.net.Uri -import android.util.Log -import com.google.firebase.Firebase -import com.google.firebase.firestore.firestore -import com.google.firebase.storage.storage -import kotlinx.coroutines.tasks.await -import kr.co.lion.mungnolza.model.UserModel - -class UserRepositoryImpl : UserRepository { - private val userStore = Firebase.firestore.collection("User") - private val storage = Firebase.storage.reference - override suspend fun fetchAllUserNickName(uniqueNumber: String): String { - var nickName = "" - try { - val querySnapshot = userStore.whereEqualTo("uniqueNumber", uniqueNumber).get().await() - for (document in querySnapshot) { - nickName = document.getString("userNickname").toString() - } - } catch (e: Exception) { - Log.e("FirebaseResult", "Error fetching users: ${e.message}") - } - - return nickName - } - - override suspend fun fetchUserProfileImage(path: String): Uri { - return storage.child(path).downloadUrl.await() - } - -} \ No newline at end of file diff --git a/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/repository/freeboard/FreeBoardRepository.kt b/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/repository/freeboard/FreeBoardRepository.kt new file mode 100644 index 0000000..2037d19 --- /dev/null +++ b/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/repository/freeboard/FreeBoardRepository.kt @@ -0,0 +1,9 @@ +package kr.co.lion.mungnolza.repository.freeboard + +import java.net.URI +import kr.co.lion.mungnolza.model.BoardModel + +interface FreeBoardRepository { + suspend fun fetchAllBoardData(): List + suspend fun fetchAllBoardImage(boardIdx: String, imgName: String): URI? +} \ No newline at end of file diff --git a/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/repository/freeboard/FreeBoardRepositoryImpl.kt b/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/repository/freeboard/FreeBoardRepositoryImpl.kt new file mode 100644 index 0000000..3fcd09f --- /dev/null +++ b/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/repository/freeboard/FreeBoardRepositoryImpl.kt @@ -0,0 +1,43 @@ +package kr.co.lion.mungnolza.repository.freeboard + +import java.net.URI +import android.util.Log +import com.google.firebase.Firebase +import com.google.firebase.firestore.Query +import com.google.firebase.firestore.firestore +import com.google.firebase.storage.storage +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.tasks.await +import kotlinx.coroutines.withContext +import kr.co.lion.mungnolza.model.BoardModel +import kr.co.lion.mungnolza.util.ContentState + +class FreeBoardRepositoryImpl : FreeBoardRepository { + private val boardStore = Firebase.firestore.collection("Board") + private val storage = Firebase.storage.reference + override suspend fun fetchAllBoardData(): List { + return try { + var query = + boardStore.whereEqualTo("boardState", ContentState.CONTENT_STATE_NORMAL.number) + query = query.orderBy("boardIdx", Query.Direction.DESCENDING) + + val querySnapshot = query.get().await() + querySnapshot.map { it.toObject(BoardModel::class.java) } + + } catch (e: Exception) { + Log.e("FirebaseResult", "Error fetching Board: ${e.message}") + emptyList() + } + } + + override suspend fun fetchAllBoardImage(boardIdx: String, imgName: String): URI? { + val path = "board/$boardIdx/$imgName" + return try { + val response = storage.child(path).downloadUrl.await().toString() + URI.create(response) + } catch (e: Exception) { + Log.e("FirebaseResult", "Error fetching BoardImage : ${storage.child(path)}") + null + } + } +} \ No newline at end of file diff --git a/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/repository/pet/PetRepository.kt b/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/repository/pet/PetRepository.kt new file mode 100644 index 0000000..605e859 --- /dev/null +++ b/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/repository/pet/PetRepository.kt @@ -0,0 +1,9 @@ +package kr.co.lion.mungnolza.repository.pet + +import kr.co.lion.mungnolza.model.PetModel +import java.net.URI + +interface PetRepository { + suspend fun fetchMyPetData(ownerIdx: String): List + suspend fun fetchMyPetImage(userIdx: String, petName: String): URI? +} \ No newline at end of file diff --git a/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/repository/pet/PetRepositoryImpl.kt b/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/repository/pet/PetRepositoryImpl.kt new file mode 100644 index 0000000..e5935ad --- /dev/null +++ b/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/repository/pet/PetRepositoryImpl.kt @@ -0,0 +1,36 @@ +package kr.co.lion.mungnolza.repository.pet + +import android.util.Log +import com.google.firebase.Firebase +import com.google.firebase.firestore.firestore +import com.google.firebase.storage.storage +import kotlinx.coroutines.tasks.await +import kr.co.lion.mungnolza.model.PetModel +import java.net.URI + +class PetRepositoryImpl: PetRepository { + private val petStore = Firebase.firestore.collection("Pet") + private val storage = Firebase.storage.reference + override suspend fun fetchMyPetData(ownerIdx: String): List { + return try { + val querySnapshot = petStore.whereEqualTo("ownerIdx", ownerIdx).get().await() + querySnapshot.map { it.toObject(PetModel::class.java) } + }catch (e: Exception){ + Log.d("FirebaseResult", "Error fetching pet: ${e.message}") + emptyList() + } + } + + override suspend fun fetchMyPetImage(userIdx: String, imgName: String): URI? { + val path = "user/$userIdx/$imgName" + + return try { + val response = storage.child(path).downloadUrl.await().toString() + URI.create(response) + }catch (e: Exception){ + Log.d("FirebaseResult", "Error fetching PetImage : ${storage.child(path)}") + null + } + } + +} \ No newline at end of file diff --git a/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/repository/user/UserRepository.kt b/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/repository/user/UserRepository.kt new file mode 100644 index 0000000..24d78e0 --- /dev/null +++ b/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/repository/user/UserRepository.kt @@ -0,0 +1,10 @@ +package kr.co.lion.mungnolza.repository.user + +import kr.co.lion.mungnolza.model.UserModel +import java.net.URI + +interface UserRepository { + suspend fun fetchAllUserData() : List + suspend fun fetchAllUserNickName(uniqueNumber: String) : List + suspend fun fetchUserProfileImage(path: String) : URI? +} \ No newline at end of file diff --git a/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/repository/user/UserRepositoryImpl.kt b/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/repository/user/UserRepositoryImpl.kt new file mode 100644 index 0000000..d7efc61 --- /dev/null +++ b/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/repository/user/UserRepositoryImpl.kt @@ -0,0 +1,50 @@ +package kr.co.lion.mungnolza.repository.user + +import android.util.Log +import com.google.firebase.Firebase +import com.google.firebase.firestore.firestore +import com.google.firebase.storage.storage +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.tasks.await +import kotlinx.coroutines.withContext +import kr.co.lion.mungnolza.model.UserModel +import java.net.URI +class UserRepositoryImpl : UserRepository { + private val userStore = Firebase.firestore.collection("User") + private val storage = Firebase.storage.reference + override suspend fun fetchAllUserData(): List { + return try { + val querySnapshot = userStore.get().await() + querySnapshot.map { it.toObject(UserModel::class.java) } + }catch (e: Exception){ + Log.e("FirebaseResult", "Error fetching users: ${e.message}") + emptyList() + } + } + + override suspend fun fetchAllUserNickName(uniqueNumber: String): List { + return withContext(Dispatchers.IO) { + try { + val querySnapshot = userStore.whereEqualTo("uniqueNumber", uniqueNumber).get().await() + + querySnapshot.map { it.getString("userNickname").toString() } + + } catch (e: Exception) { + Log.e("FirebaseResult", "Error fetching users: ${e.message}") + emptyList() + } + } + } + + override suspend fun fetchUserProfileImage(path: String): URI? { + return withContext(Dispatchers.IO) { + try { + val response = storage.child(path).downloadUrl.await().toString() + URI.create(response) + } catch (e: Exception) { + Log.e("FirebaseResult", "Error fetching UserProfileImage : ${storage.child(path)}") + null + } + } + } +} \ No newline at end of file diff --git a/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/ui/chat/ChatActivity.kt b/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/ui/chat/ChatActivity.kt index e06dc02..b7fa3d2 100644 --- a/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/ui/chat/ChatActivity.kt +++ b/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/ui/chat/ChatActivity.kt @@ -23,7 +23,7 @@ class ChatActivity : AppCompatActivity() { super.onCreate(savedInstanceState) binding = ActivityChatBinding.inflate(layoutInflater) - replaceFragment(ChatFragmentName.MAIN_CHAT_FRAGMENT,false,false,null) + replaceFragment(ChatFragmentName.DETAIL_CHAT_FRAGMENT,false,false,null) setContentView(binding.root) } diff --git a/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/ui/freeboard/adapter/BoardCarouselAdapter.kt b/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/ui/freeboard/adapter/BoardCarouselAdapter.kt index 8e6d926..22f8e46 100644 --- a/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/ui/freeboard/adapter/BoardCarouselAdapter.kt +++ b/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/ui/freeboard/adapter/BoardCarouselAdapter.kt @@ -1,19 +1,20 @@ package kr.co.lion.mungnolza.ui.freeboard.adapter +import android.net.Uri import android.view.LayoutInflater import android.view.ViewGroup import androidx.recyclerview.widget.RecyclerView import kr.co.lion.mungnolza.R import kr.co.lion.mungnolza.databinding.RowShowDetailBoardBinding -class BoardCarouselAdapter(): RecyclerView.Adapter() { +class BoardCarouselAdapter(var imageUriList:MutableList): RecyclerView.Adapter() { override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): BoardCarouselViewHolder { - return BoardCarouselViewHolder(RowShowDetailBoardBinding.inflate(LayoutInflater.from(parent.context),parent, false)) + return BoardCarouselViewHolder(RowShowDetailBoardBinding.inflate(LayoutInflater.from(parent.context),parent, false), imageUriList) } // override fun getItemCount(): Int = itemList.size - override fun getItemCount(): Int = 10 + override fun getItemCount(): Int = imageUriList.size override fun onBindViewHolder(holder: BoardCarouselViewHolder, position: Int) { holder.bind() diff --git a/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/ui/freeboard/adapter/BoardCarouselViewHolder.kt b/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/ui/freeboard/adapter/BoardCarouselViewHolder.kt index 978d689..4484c4f 100644 --- a/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/ui/freeboard/adapter/BoardCarouselViewHolder.kt +++ b/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/ui/freeboard/adapter/BoardCarouselViewHolder.kt @@ -1,16 +1,26 @@ package kr.co.lion.mungnolza.ui.freeboard.adapter +import android.net.Uri import androidx.recyclerview.widget.RecyclerView +import com.bumptech.glide.Glide +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.launch import kr.co.lion.mungnolza.R import kr.co.lion.mungnolza.databinding.RowShowDetailBoardBinding class BoardCarouselViewHolder( - private val binding:RowShowDetailBoardBinding + private val binding:RowShowDetailBoardBinding, + private val imageUriList:MutableList ) :RecyclerView.ViewHolder(binding.root) { fun bind(){ itemView.apply{ - binding.imageViewCarouselShowDetailBoard.setImageResource(R.drawable.img_dog) + CoroutineScope(Dispatchers.Main).launch { + imageUriList.forEach { + Glide.with(context).load(imageUriList).into(binding.imageViewCarouselShowDetailBoard) + } + } } } diff --git a/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/ui/freeboard/fragment/AddBoardFragment.kt b/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/ui/freeboard/fragment/AddBoardFragment.kt index d809cbb..8e8c2bf 100644 --- a/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/ui/freeboard/fragment/AddBoardFragment.kt +++ b/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/ui/freeboard/fragment/AddBoardFragment.kt @@ -6,7 +6,6 @@ import android.graphics.BitmapFactory import android.graphics.ImageDecoder import android.os.Build import android.os.Bundle -import android.os.SystemClock import android.provider.MediaStore import android.util.Log import androidx.fragment.app.Fragment @@ -20,22 +19,16 @@ import androidx.databinding.DataBindingUtil import androidx.lifecycle.lifecycleScope import androidx.recyclerview.widget.RecyclerView import com.google.android.material.carousel.CarouselLayoutManager -import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch import kr.co.lion.mungnolza.R -import kr.co.lion.mungnolza.data.repository.BoardRepository import kr.co.lion.mungnolza.data.repository.BoardRepositoryImpl import kr.co.lion.mungnolza.databinding.FragmentAddBoardBinding import kr.co.lion.mungnolza.databinding.RowAddBoardBinding import kr.co.lion.mungnolza.model.BoardModel -import kr.co.lion.mungnolza.repository.UserRepository -import kr.co.lion.mungnolza.repository.UserRepositoryImpl +import kr.co.lion.mungnolza.repository.user.UserRepositoryImpl import kr.co.lion.mungnolza.ui.freeboard.AddBoardActivity import kr.co.lion.mungnolza.ui.freeboard.BoardActivity import kr.co.lion.mungnolza.ui.freeboard.viewmodel.AddBoardViewModel -import kr.co.lion.mungnolza.ui.freeboard.viewmodel.BoardViewModel -import kr.co.lion.mungnolza.util.BoardFragmentName import kr.co.lion.mungnolza.util.BoardUtil import java.text.SimpleDateFormat import java.util.Date diff --git a/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/ui/freeboard/fragment/ShowDetailBoardFragment.kt b/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/ui/freeboard/fragment/ShowDetailBoardFragment.kt index 0d9504b..8549e32 100644 --- a/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/ui/freeboard/fragment/ShowDetailBoardFragment.kt +++ b/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/ui/freeboard/fragment/ShowDetailBoardFragment.kt @@ -1,6 +1,7 @@ package kr.co.lion.mungnolza.ui.freeboard.fragment import android.content.DialogInterface +import android.net.Uri import android.os.Build import android.os.Bundle import android.util.Log @@ -9,16 +10,28 @@ import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import androidx.fragment.app.viewModels +import androidx.lifecycle.lifecycleScope +import com.bumptech.glide.Glide import com.google.android.material.carousel.CarouselLayoutManager import com.google.android.material.dialog.MaterialAlertDialogBuilder +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.delay +import kotlinx.coroutines.job +import kotlinx.coroutines.launch import kr.co.lion.mungnolza.R +import kr.co.lion.mungnolza.data.repository.BoardRepository +import kr.co.lion.mungnolza.data.repository.BoardRepositoryImpl import kr.co.lion.mungnolza.databinding.FragmentShowDetailBoardBinding import kr.co.lion.mungnolza.model.BoardModel import kr.co.lion.mungnolza.model.UserModel +import kr.co.lion.mungnolza.repository.user.UserRepository +import kr.co.lion.mungnolza.repository.user.UserRepositoryImpl import kr.co.lion.mungnolza.ui.freeboard.BoardActivity import kr.co.lion.mungnolza.ui.freeboard.adapter.BoardCarouselAdapter import kr.co.lion.mungnolza.ui.freeboard.viewmodel.BoardViewModel import kr.co.lion.mungnolza.util.BoardFragmentName +import java.net.URI class ShowDetailBoardFragment : Fragment() { @@ -33,10 +46,17 @@ class ShowDetailBoardFragment : Fragment() { var userData: UserModel? = null var boardData: BoardModel? = null + var boardList: ArrayList? = null + + lateinit var userRepository: UserRepository + lateinit var boardRepository: BoardRepository + var imgUri: URI? = null + + var imageUriList: MutableList = mutableListOf() var imagePathList = mutableListOf() - var boardIdx: Int = 0 + override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, @@ -48,14 +68,10 @@ class ShowDetailBoardFragment : Fragment() { setTest() - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { - boardData = boardActivity.intent.getParcelableExtra("boardData", BoardModel::class.java) - } else { - boardData = boardActivity.intent.getParcelableExtra("boardData") + lifecycleScope.launch { + initData() } - Log.d("ShowDetailBoardFragment intent 데이터", "${boardData?.boardImagePathList?.get(0)}") - applyUserData() return binding.root @@ -64,10 +80,10 @@ class ShowDetailBoardFragment : Fragment() { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - setToolbar() setCarousel() - setCommentButton() + setToolbar() + setCommentButton() } override fun onDestroy() { @@ -77,19 +93,67 @@ class ShowDetailBoardFragment : Fragment() { // ---------------------------------------------------------------------------- - fun setTest() { + suspend fun initData(){ + userRepository = UserRepositoryImpl() + boardRepository = BoardRepositoryImpl() + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { + boardData = boardActivity.intent.getParcelableExtra("boardData", BoardModel::class.java) + userData = boardActivity.intent.getParcelableExtra("userData", UserModel::class.java) + } else { + boardData = boardActivity.intent.getParcelableExtra("boardData") + userData = boardActivity.intent.getParcelableExtra("userData") + } + boardData?.boardImagePathList?.forEach { + Log.d("게시판 boardImagePathList","${it}") + } + + + val job1 = CoroutineScope(Dispatchers.IO).launch { + imgUri = userRepository.fetchUserProfileImage(userData?.userProfileImgPath!!)!! + Log.d("프로필 이미지 uri","${imgUri}") + + + } + job1.join() + + val job2 = CoroutineScope(Dispatchers.IO).launch { + boardList = boardRepository.getBoardList() + imageUriList = boardRepository.getBoardImageUriList(boardData!!) + imageUriList.forEach { + Log.d("이미지 Uri 리스트",it.toString()) + } + + + } + job2.join() } + fun setTest() { - suspend fun applyImage(){ - // binding.imageViewProfileShowDetailBoard.setImageURI() } - fun applyUserData() { - binding.editTextTitleShowDetailBoard.setText(boardData?.boardTitle) - binding.editTextContentShowDetailBoard.setText(boardData?.boardContent) - binding.textViewDateShowDetailBoard.text = boardData?.boardWriteDate + fun applyUserData() { + binding.apply{ + editTextTitleShowDetailBoard.setText(boardData?.boardTitle) + editTextContentShowDetailBoard.setText(boardData?.boardContent) + textViewDateShowDetailBoard.text = boardData?.boardWriteDate + textViewNickNameShowDetailBoard.text = userData?.userNickname + + + lifecycleScope.launch { + delay(1000) + Log.d("이미지 Uri 리스트 Glide 이전",imgUri.toString()) + Glide.with(requireContext()) + .load(imgUri) + .error(R.drawable.eunwoo) + .into(binding.imageViewProfileShowDetailBoard) + + // boardRepository.applyBoardImage(requireContext(), boardData!!.boardImagePathList[0]!!, binding.imageViewProfileShowDetailBoard) + } + + } // 유저 정보는 boardModel로 접근해야 하는데 테스트는 일단 직접 호출 } @@ -107,7 +171,7 @@ class ShowDetailBoardFragment : Fragment() { // RecyclerView 셋팅 recyclerViewPhotosShowDetailBoard.apply { // 어댑터 - adapter = BoardCarouselAdapter() + adapter = BoardCarouselAdapter(imageUriList) // 레이아웃 매니저 layoutManager = CarouselLayoutManager() // layoutManager = CarouselLayoutManager(MultiBrowseCarouselStrategy()) @@ -181,6 +245,4 @@ class ShowDetailBoardFragment : Fragment() { bottomCommentFragment.show(boardActivity.supportFragmentManager, "BottomCommentSheet") } - - } \ No newline at end of file diff --git a/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/ui/freeboard/viewmodel/AddBoardViewModel.kt b/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/ui/freeboard/viewmodel/AddBoardViewModel.kt index cdc2a68..c76dfcd 100644 --- a/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/ui/freeboard/viewmodel/AddBoardViewModel.kt +++ b/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/ui/freeboard/viewmodel/AddBoardViewModel.kt @@ -2,8 +2,6 @@ package kr.co.lion.mungnolza.ui.freeboard.viewmodel import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel -import kr.co.lion.mungnolza.data.repository.BoardRepository -import kr.co.lion.mungnolza.repository.UserRepository class AddBoardViewModel:ViewModel() { diff --git a/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/ui/freeboard/viewmodel/BoardViewModel.kt b/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/ui/freeboard/viewmodel/BoardViewModel.kt index 0e52b84..74f635a 100644 --- a/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/ui/freeboard/viewmodel/BoardViewModel.kt +++ b/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/ui/freeboard/viewmodel/BoardViewModel.kt @@ -9,8 +9,7 @@ import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.launch import kr.co.lion.mungnolza.data.repository.BoardRepository import kr.co.lion.mungnolza.model.BoardModel -import kr.co.lion.mungnolza.repository.FreeBoardRepository -import kr.co.lion.mungnolza.repository.UserRepository +import kr.co.lion.mungnolza.repository.user.UserRepository class BoardViewModel( private val boardRepository:BoardRepository, @@ -32,7 +31,4 @@ class BoardViewModel( return boardList } - private suspend fun getBoardImg(boardModel: BoardModel): Uri?{ - return boardRepository.getBoardImageListPath(boardModel) - } } \ No newline at end of file diff --git a/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/ui/main/adapter/FreeBoardAdapter.kt b/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/ui/main/adapter/FreeBoardAdapter.kt index 488a041..625087e 100644 --- a/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/ui/main/adapter/FreeBoardAdapter.kt +++ b/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/ui/main/adapter/FreeBoardAdapter.kt @@ -11,9 +11,15 @@ class FreeBoardAdapter( private val dataSet: List, private val onClick: (Int) -> Unit ) : RecyclerView.Adapter() { + class FreeBoardAdapterViewHolder( private val binding: RowFreeBoardBinding, private val onClick: (Int) -> Unit ) : RecyclerView.ViewHolder(binding.root) { + init { + binding.root.setOnClickListener { + onClick.invoke(adapterPosition) + } + } fun bind(item: BoardAddUerInfoModel) { with(binding) { tvTitle.text = item.contentData.boardTitle @@ -23,12 +29,8 @@ class FreeBoardAdapter( tvNickname.text = item.writerNickName Glide.with(binding.root) - .load(item.imgUri) + .load(item.imgUri.toString()) .into(thumbnail) - - root.setOnClickListener { - onClick.invoke(item.contentData.boardIdx) - } } } } diff --git a/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/ui/main/adapter/HomeReviewAdapter.kt b/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/ui/main/adapter/HomeReviewAdapter.kt new file mode 100644 index 0000000..ce16b24 --- /dev/null +++ b/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/ui/main/adapter/HomeReviewAdapter.kt @@ -0,0 +1,41 @@ +package kr.co.lion.mungnolza.ui.main.adapter + +import android.view.ViewGroup +import androidx.recyclerview.widget.DiffUtil +import androidx.recyclerview.widget.ListAdapter +import androidx.recyclerview.widget.RecyclerView +import kr.co.lion.mungnolza.databinding.RowReviewPreviewBinding +import kr.co.lion.mungnolza.model.PetsitterReviewModel + +class HomeReviewAdapter: ListAdapter(DiffCallback) { + class HomeReviewAdapterViewHolder(private val binding: RowReviewPreviewBinding) : + RecyclerView.ViewHolder(binding.root) { + fun bind(item: PetsitterReviewModel){ + with(binding){ + + } + } + } + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): HomeReviewAdapterViewHolder { + TODO("Not yet implemented") + } + + override fun onBindViewHolder(holder: HomeReviewAdapterViewHolder, position: Int) { + holder.bind(getItem(position)) + } + + companion object { + private val DiffCallback = object : DiffUtil.ItemCallback() { + + override fun areItemsTheSame(oldItem: PetsitterReviewModel, newItem: PetsitterReviewModel): Boolean { + return oldItem.reviewIdx == newItem.reviewIdx + } + + override fun areContentsTheSame(oldItem: PetsitterReviewModel, newItem: PetsitterReviewModel): Boolean { + return oldItem == newItem + + } + } + } +} \ No newline at end of file diff --git a/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/ui/main/fragment/FreeBoardFragment.kt b/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/ui/main/fragment/FreeBoardFragment.kt index ee8b600..c2f1a17 100644 --- a/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/ui/main/fragment/FreeBoardFragment.kt +++ b/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/ui/main/fragment/FreeBoardFragment.kt @@ -22,38 +22,46 @@ import kr.co.lion.mungnolza.ui.main.adapter.FreeBoardAdapter import kr.co.lion.mungnolza.ui.main.viewmodel.MainViewModel import kr.co.lion.mungnolza.ui.main.viewmodel.MainViewModelFactory -class FreeBoardFragment : Fragment() { +class FreeBoardFragment : Fragment(R.layout.fragment_free_board) { private var _binding: FragmentFreeBoardBinding? = null private val binding get() = _binding!! private val viewModel: MainViewModel by activityViewModels { MainViewModelFactory() } private lateinit var freeBoardAdapter: FreeBoardAdapter - override fun onCreateView( - inflater: LayoutInflater, container: ViewGroup?, - savedInstanceState: Bundle?, - ): View { - _binding = FragmentFreeBoardBinding.inflate(inflater, container, false) + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + _binding = FragmentFreeBoardBinding.bind(view) initView() - - return binding.root } private fun initView() { viewLifecycleOwner.lifecycleScope.launch { repeatOnLifecycle(Lifecycle.State.STARTED) { viewModel.boardContentList.collect { boardList -> - freeBoardAdapter = FreeBoardAdapter( + val freeBoardAdapter = FreeBoardAdapter( dataSet = boardList, onClick = { selectedItemIdx -> - val selectedItem = boardList.find { it.contentData.boardIdx == selectedItemIdx } - val selectedItemData = selectedItem?.contentData + val selectedItem = boardList[selectedItemIdx] + + val selectedItemData = selectedItem.contentData + val writerData = viewModel.findUserData(selectedItemData.boardWriterIdx) + val intent = Intent(requireContext(), BoardActivity::class.java) - Log.d("FreeBoardFragment intent 데이터","${selectedItem}") intent.putExtra("boardData", selectedItemData) + intent.putExtra("userData", writerData) + startActivity(intent) } ) - setRecyclerViewFreeBoard() + with(binding.recyclerViewFreeBoard) { + adapter = freeBoardAdapter + layoutManager = LinearLayoutManager(requireContext()) + val deco = MaterialDividerItemDecoration( + requireContext(), + MaterialDividerItemDecoration.VERTICAL + ) + addItemDecoration(deco) + } } } } diff --git a/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/ui/main/fragment/MainChatFragment.kt b/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/ui/main/fragment/MainChatFragment.kt index 68c16cc..e16c3ac 100644 --- a/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/ui/main/fragment/MainChatFragment.kt +++ b/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/ui/main/fragment/MainChatFragment.kt @@ -1,5 +1,6 @@ package kr.co.lion.mungnolza.ui.main.fragment +import android.content.Intent import android.os.Bundle import androidx.fragment.app.Fragment import android.view.LayoutInflater @@ -69,7 +70,7 @@ class MainChatFragment : Fragment() { } override fun getItemCount(): Int { - return 100 + return 3 } override fun onBindViewHolder(holder: ViewHolderMainChat, position: Int) { @@ -79,7 +80,9 @@ class MainChatFragment : Fragment() { holder.rowMainChatBinding.imageViewProfileRowMainChat.setImageResource(R.drawable.img_jch) holder.rowMainChatBinding.root.setOnClickListener { + val intent = Intent(requireContext(),ChatActivity::class.java) + startActivity(intent) } } } diff --git a/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/ui/main/viewmodel/MainViewModel.kt b/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/ui/main/viewmodel/MainViewModel.kt index 98b87d9..51bfcdf 100644 --- a/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/ui/main/viewmodel/MainViewModel.kt +++ b/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/ui/main/viewmodel/MainViewModel.kt @@ -1,42 +1,64 @@ package kr.co.lion.mungnolza.ui.main.viewmodel -import android.net.Uri -import android.util.Log import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope -import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.flow.collect import kotlinx.coroutines.launch +import kr.co.lion.mungnolza.datasource.MainDataStore import kr.co.lion.mungnolza.model.BoardAddUerInfoModel -import kr.co.lion.mungnolza.model.BoardModel +import kr.co.lion.mungnolza.model.PetImgModel import kr.co.lion.mungnolza.model.UserModel -import kr.co.lion.mungnolza.repository.FreeBoardRepositoryImpl -import kr.co.lion.mungnolza.repository.UserRepositoryImpl +import kr.co.lion.mungnolza.repository.freeboard.FreeBoardRepositoryImpl +import kr.co.lion.mungnolza.repository.pet.PetRepositoryImpl +import kr.co.lion.mungnolza.repository.user.UserRepositoryImpl +import java.net.URI class MainViewModel( private val freeBoardRepository: FreeBoardRepositoryImpl, - private val userRepository: UserRepositoryImpl + private val userRepository: UserRepositoryImpl, + private val petRepositoryImpl: PetRepositoryImpl ): ViewModel() { + private val _userList = MutableStateFlow>(emptyList()) val userList = _userList.asStateFlow() private var _boardContentList = MutableStateFlow>(emptyList()) val boardContentList = _boardContentList.asStateFlow() + private val _myUserNumber = MutableStateFlow(null) + private val myUserNumber = _myUserNumber.asStateFlow() + + private val _myPetData = MutableStateFlow>(emptyList()) + val myPetData = _myPetData.asStateFlow() + init { - fetchAllBoardDataWithUserInfo() + viewModelScope.launch { + fetchAllUserData() + fetchAllBoardDataWithUserInfo() + + //MainDataStore.setUserNumber("1234") + MainDataStore.getUserNumber().collect { + _myUserNumber.value = it + } + } + + } + + private suspend fun fetchAllUserData(){ + val response = userRepository.fetchAllUserData() + _userList.value = response } - private fun fetchAllBoardDataWithUserInfo() = viewModelScope.launch(Dispatchers.IO) { + private suspend fun fetchAllBoardDataWithUserInfo(){ val response = freeBoardRepository.fetchAllBoardData() val contentList = ArrayList() - response.forEach { - val nickName = userRepository.fetchAllUserNickName(it.boardWriterIdx) - val imgUri = fetchBoardImg(it.boardIdx.toString(), it.boardImagePathList[0].toString()) - val content = imgUri?.let { uri -> BoardAddUerInfoModel(it, nickName, uri) } + response.mapIndexed { index, boardModel -> + val nickName = userRepository.fetchAllUserNickName(boardModel.boardWriterIdx) + val imgUri = fetchBoardImg(boardModel.boardIdx.toString(), boardModel.boardImagePathList[0].toString()) + val content = imgUri?.let { uri -> BoardAddUerInfoModel(boardModel, nickName[index], uri) } if (content != null) { contentList.add(content) } @@ -44,11 +66,40 @@ class MainViewModel( _boardContentList.value = contentList } - private suspend fun fetchBoardImg(boardIdx: String, imgName: String): Uri? { + fun fetchMyAllPetData() = viewModelScope.launch { + val petList = ArrayList() + + myUserNumber.collect { myUserNumber -> + val result = myUserNumber?.let { data-> petRepositoryImpl.fetchMyPetData(data) } + result?.map{ + val imgUri = fetchPetImg(it.ownerIdx, it.imgName) + val pet = imgUri?.let { data -> PetImgModel(it, data) } + + if (pet != null) { + petList.add(pet) + } + } + _myPetData.value = petList + } + } + + private suspend fun fetchPetImg(userIdx: String, petName: String): URI? { + return petRepositoryImpl.fetchMyPetImage(userIdx, petName) + } + + private suspend fun fetchBoardImg(boardIdx: String, imgName: String): URI? { return freeBoardRepository.fetchAllBoardImage(boardIdx, imgName) } - suspend fun fetchUserProfileImage(path: String): Uri { + suspend fun fetchUserProfileImage(path: String): URI? { return userRepository.fetchUserProfileImage(path) } + + fun findUserData(writerIdx: String): UserModel? { + return userList.value.find { it.uniqueNumber == writerIdx } + } + + fun setMyPetData(myPets: List){ + _myPetData.value = myPets + } } \ No newline at end of file diff --git a/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/ui/main/viewmodel/MainViewModelFactory.kt b/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/ui/main/viewmodel/MainViewModelFactory.kt index 557de2f..1a427a7 100644 --- a/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/ui/main/viewmodel/MainViewModelFactory.kt +++ b/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/ui/main/viewmodel/MainViewModelFactory.kt @@ -2,17 +2,19 @@ package kr.co.lion.mungnolza.ui.main.viewmodel import androidx.lifecycle.ViewModel import androidx.lifecycle.ViewModelProvider -import kr.co.lion.mungnolza.repository.FreeBoardRepository -import kr.co.lion.mungnolza.repository.FreeBoardRepositoryImpl -import kr.co.lion.mungnolza.repository.UserRepositoryImpl +import kr.co.lion.mungnolza.repository.freeboard.FreeBoardRepositoryImpl +import kr.co.lion.mungnolza.repository.pet.PetRepositoryImpl +import kr.co.lion.mungnolza.repository.user.UserRepositoryImpl import java.lang.IllegalArgumentException class MainViewModelFactory: ViewModelProvider.Factory{ private val boardRepository = FreeBoardRepositoryImpl() private val userRepository = UserRepositoryImpl() + private val petRepositoryImpl = PetRepositoryImpl() + override fun create(modelClass: Class): T { if (modelClass.isAssignableFrom(MainViewModel::class.java)){ - return MainViewModel(boardRepository, userRepository) as T + return MainViewModel(boardRepository, userRepository, petRepositoryImpl) as T } throw IllegalArgumentException("unknown ViewModel class") } diff --git a/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/ui/reservation_list/fragment/PetSitterReviewWriteFragment.kt b/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/ui/reservation_list/fragment/PetSitterReviewWriteFragment.kt index a0ce6a8..fa90b38 100644 --- a/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/ui/reservation_list/fragment/PetSitterReviewWriteFragment.kt +++ b/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/ui/reservation_list/fragment/PetSitterReviewWriteFragment.kt @@ -13,7 +13,6 @@ import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch import kr.co.lion.mungnolza.ui.reservation_list.ReservationListActivity import kr.co.lion.mungnolza.R -import kr.co.lion.mungnolza.repository.PetsitterReviewRepository import kr.co.lion.mungnolza.databinding.FragmentPetSitterReviewWriteBinding import kr.co.lion.mungnolza.model.PetsitterReviewModel import kr.co.lion.mungnolza.ui.reservation_list.viewmodel.PetSitterReviewWriteViewModel @@ -23,6 +22,7 @@ import java.util.Date // ContextExt.kt에 정의된 확장 함수를 import import kr.co.lion.mungnolza.ext.hideSoftInput import kr.co.lion.mungnolza.ext.showErrorDialog +import kr.co.lion.mungnolza.repository.PetsitterReviewRepository class PetSitterReviewWriteFragment : Fragment() { diff --git a/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/util/App.kt b/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/util/App.kt new file mode 100644 index 0000000..95b28b1 --- /dev/null +++ b/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/util/App.kt @@ -0,0 +1,22 @@ +package kr.co.lion.mungnolza.util + +import android.app.Application +import android.content.Context +import com.google.firebase.firestore.FirebaseFirestore +import com.google.firebase.ktx.Firebase +import com.google.firebase.storage.FirebaseStorage +import com.google.firebase.storage.ktx.storage + +class App: Application() { + init { + instance = this + } + + companion object{ + + private var instance: App? = null + fun context(): Context { + return instance?.applicationContext!! + } + } +} \ No newline at end of file diff --git a/MungNolZa/app/src/main/res/layout/fragment_detail_chat.xml b/MungNolZa/app/src/main/res/layout/fragment_detail_chat.xml index 34c7039..2f30483 100644 --- a/MungNolZa/app/src/main/res/layout/fragment_detail_chat.xml +++ b/MungNolZa/app/src/main/res/layout/fragment_detail_chat.xml @@ -26,15 +26,19 @@ app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" > + + android:textStyle="bold" + tools:layout_editor_absoluteX="16dp" + tools:layout_editor_absoluteY="18dp" /> + android:theme="?attr/actionBarTheme" > + + + + + + + \ No newline at end of file diff --git a/MungNolZa/app/src/main/res/layout/fragment_main_chat.xml b/MungNolZa/app/src/main/res/layout/fragment_main_chat.xml index 29718b4..d8a7bc0 100644 --- a/MungNolZa/app/src/main/res/layout/fragment_main_chat.xml +++ b/MungNolZa/app/src/main/res/layout/fragment_main_chat.xml @@ -11,28 +11,33 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:minHeight="?attr/actionBarSize" - app:title="@string/menu_item_bottom_navigation_chatting" android:theme="?attr/actionBarTheme"> + + + + - - - - + android:layout_height="match_parent" /> \ No newline at end of file diff --git a/MungNolZa/app/src/main/res/layout/row_review_preview.xml b/MungNolZa/app/src/main/res/layout/row_review_preview.xml new file mode 100644 index 0000000..62b2afa --- /dev/null +++ b/MungNolZa/app/src/main/res/layout/row_review_preview.xml @@ -0,0 +1,75 @@ + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file