From e2a0157e17a4a767811e7897803098eab3bf3dc2 Mon Sep 17 00:00:00 2001 From: chanho Date: Thu, 11 Apr 2024 12:35:41 +0900 Subject: [PATCH 1/5] =?UTF-8?q?[#36]=20FireBase=20->=20=EC=9C=A0=EC=A0=80?= =?UTF-8?q?=20=EC=9D=B4=EB=AF=B8=EC=A7=80,=20=EC=A0=95=EB=B3=B4=20?= =?UTF-8?q?=EA=B0=80=EC=A0=B8=EC=98=A4=EA=B8=B0=20=EC=99=84=EB=A3=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kr/co/lion/mungnolza/model/UserModel.kt | 28 +++++++++++--- .../mungnolza/repository/UserRepository.kt | 11 ++++++ .../repository/UserRepositoryImpl.kt | 38 +++++++++++++++++++ 3 files changed, 71 insertions(+), 6 deletions(-) create mode 100644 MungNolZa/app/src/main/java/kr/co/lion/mungnolza/repository/UserRepository.kt create mode 100644 MungNolZa/app/src/main/java/kr/co/lion/mungnolza/repository/UserRepositoryImpl.kt 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 41d3bbd..8da63fb 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,9 +1,25 @@ package kr.co.lion.mungnolza.model data class UserModel( - var userIdx:Int, - var userId:String, - var userPw:String, - var userNickName:String, - var userState:Int -) \ No newline at end of file + 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 +){ + constructor(): this( + uniqueNumber = "", + userNickname = "", + userName = "", + userEmail = "", + userPhone = "", + userAddress = "", + userProfileImgPath = "", + userAgeRange = "", + userGender = "" + ) +} \ 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 new file mode 100644 index 0000000..34d0a7f --- /dev/null +++ b/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/repository/UserRepository.kt @@ -0,0 +1,11 @@ +package kr.co.lion.mungnolza.repository + +import android.net.Uri +import com.google.firebase.firestore.FirebaseFirestore +import com.google.firebase.storage.StorageReference +import kr.co.lion.mungnolza.model.UserModel + +interface UserRepository { + suspend fun fetchAllUser() : ArrayList + 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 new file mode 100644 index 0000000..cab1c83 --- /dev/null +++ b/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/repository/UserRepositoryImpl.kt @@ -0,0 +1,38 @@ +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.firestore +import com.google.firebase.storage.StorageReference +import com.google.firebase.storage.storage +import kotlinx.coroutines.tasks.await +import kr.co.lion.mungnolza.model.UserModel + +class UserRepositoryImpl : UserRepository { + private val store: FirebaseFirestore = Firebase.firestore + private val storage = Firebase.storage.reference + override suspend fun fetchAllUser(): ArrayList { + val userList = ArrayList() + + try { + val querySnapshot = store.collection("User").get().await() + for (document in querySnapshot) { + val user = document.toObject(UserModel::class.java) + Log.e("FirebaseResult", "Error fetching users: ${user}") + + userList.add(user) + } + } catch (e: Exception) { + Log.e("FirebaseResult", "Error fetching users: ${e.message}") + } + + return userList + } + + override suspend fun fetchUserProfileImage(path: String): Uri { + return storage.child(path).downloadUrl.await() + } + +} \ No newline at end of file From d14bdcc82bac0f40ac6c398881eff51f344a0ffe Mon Sep 17 00:00:00 2001 From: chanho Date: Fri, 12 Apr 2024 01:30:34 +0900 Subject: [PATCH 2/5] =?UTF-8?q?[#36]=20Repository=20->=20Main=20=EA=B2=8C?= =?UTF-8?q?=EC=8B=9C=ED=8C=90=20=ED=99=94=EB=A9=B4=20=EA=B2=8C=EC=8B=9C?= =?UTF-8?q?=EA=B8=80=20=EA=B0=80=EC=A0=B8=EC=98=A4=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mungnolza/model/BoardAddUerInfoModel.kt | 13 +++++ .../kr/co/lion/mungnolza/model/BoardModel.kt | 31 +++++++++--- .../repository/FreeBoardRepository.kt | 9 ++++ .../repository/FreeBoardRepositoryImpl.kt | 49 +++++++++++++++++++ .../mungnolza/repository/UserRepository.kt | 4 +- .../repository/UserRepositoryImpl.kt | 18 +++---- 6 files changed, 101 insertions(+), 23 deletions(-) create mode 100644 MungNolZa/app/src/main/java/kr/co/lion/mungnolza/model/BoardAddUerInfoModel.kt create mode 100644 MungNolZa/app/src/main/java/kr/co/lion/mungnolza/repository/FreeBoardRepository.kt create mode 100644 MungNolZa/app/src/main/java/kr/co/lion/mungnolza/repository/FreeBoardRepositoryImpl.kt 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 new file mode 100644 index 0000000..cfd9ba6 --- /dev/null +++ b/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/model/BoardAddUerInfoModel.kt @@ -0,0 +1,13 @@ +package kr.co.lion.mungnolza.model + +import android.net.Uri +import android.os.Parcelable +import kotlinx.parcelize.Parcelize +import kotlinx.parcelize.RawValue + +@Parcelize +data class BoardAddUerInfoModel ( + val contentData: @RawValue BoardModel, + val writerNickName: String, + val imgUri: Uri +): Parcelable \ No newline at end of file diff --git a/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/model/BoardModel.kt b/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/model/BoardModel.kt index 4913002..2c84775 100644 --- a/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/model/BoardModel.kt +++ b/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/model/BoardModel.kt @@ -1,13 +1,28 @@ package kr.co.lion.mungnolza.model +import android.os.Parcelable +import kotlinx.parcelize.Parcelize + data class BoardModel( - var boardIdx:Int, - var boardTitle:String, - var boardType:Int, - var boardImageList:MutableList, - var boardWriterIdx:Int, - var boardWriteDate:String, - var boardState:Int + var boardIdx: Int, + var boardTitle: String, + var boardContent: String, + var boardImagePathList: MutableList, + var boardWriterIdx: String, + var boardWriteDate: String, + var boardModifyDate: String, + var boardLikeNumber: Int, + var boardState: Int ){ - constructor():this(0, "", 0, mutableListOf(), 0, "", 0) + constructor() : this( + boardIdx = 0, + boardTitle = "", + boardContent= "", + boardImagePathList = mutableListOf(), + boardWriterIdx = "", + boardWriteDate = "", + boardModifyDate = "", + boardLikeNumber = 0, + boardState = 0 + ) } \ No newline at end of file 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 new file mode 100644 index 0000000..74bd392 --- /dev/null +++ b/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/repository/FreeBoardRepository.kt @@ -0,0 +1,9 @@ +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? +} \ 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 new file mode 100644 index 0000000..46e2187 --- /dev/null +++ b/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/repository/FreeBoardRepositoryImpl.kt @@ -0,0 +1,49 @@ +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.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 + } +} \ 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 index 34d0a7f..1a10ed3 100644 --- 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 @@ -1,11 +1,9 @@ package kr.co.lion.mungnolza.repository import android.net.Uri -import com.google.firebase.firestore.FirebaseFirestore -import com.google.firebase.storage.StorageReference import kr.co.lion.mungnolza.model.UserModel interface UserRepository { - suspend fun fetchAllUser() : ArrayList + 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 index cab1c83..f3420c1 100644 --- 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 @@ -3,32 +3,26 @@ 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.firestore -import com.google.firebase.storage.StorageReference import com.google.firebase.storage.storage import kotlinx.coroutines.tasks.await import kr.co.lion.mungnolza.model.UserModel class UserRepositoryImpl : UserRepository { - private val store: FirebaseFirestore = Firebase.firestore + private val userStore = Firebase.firestore.collection("User") private val storage = Firebase.storage.reference - override suspend fun fetchAllUser(): ArrayList { - val userList = ArrayList() - + override suspend fun fetchAllUserNickName(uniqueNumber: String): String { + var nickName = "" try { - val querySnapshot = store.collection("User").get().await() + val querySnapshot = userStore.whereEqualTo("uniqueNumber", uniqueNumber).get().await() for (document in querySnapshot) { - val user = document.toObject(UserModel::class.java) - Log.e("FirebaseResult", "Error fetching users: ${user}") - - userList.add(user) + nickName = document.getString("userNickname").toString() } } catch (e: Exception) { Log.e("FirebaseResult", "Error fetching users: ${e.message}") } - return userList + return nickName } override suspend fun fetchUserProfileImage(path: String): Uri { From 1af403383c9f8ccfb16511209d54a2fccd97f260 Mon Sep 17 00:00:00 2001 From: chanho Date: Fri, 12 Apr 2024 02:19:21 +0900 Subject: [PATCH 3/5] =?UTF-8?q?[#36]=20=EA=B8=B0=ED=83=80=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD=20=EC=82=AC=ED=95=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- MungNolZa/app/src/main/AndroidManifest.xml | 19 ++- .../freeboard/viewmodel/FreeBoardViewModel.kt | 6 - .../ui/main/fragment/adapter/BoardAdapter.kt | 4 - .../main/fragment/adapter/ChattingAdapter.kt | 4 - .../ui/main/viewmodel/TestViewModel.kt | 7 - .../kr/co/lion/mungnolza/util/BoardUtil.kt | 5 + .../src/main/res/layout/row_free_board.xml | 159 +++++++++--------- .../app/src/main/res/menu/menu_free_board.xml | 2 +- MungNolZa/app/src/main/res/values/colors.xml | 1 - MungNolZa/app/src/main/res/values/dimens.xml | 8 +- MungNolZa/app/src/main/res/values/strings.xml | 2 +- 11 files changed, 100 insertions(+), 117 deletions(-) delete mode 100644 MungNolZa/app/src/main/java/kr/co/lion/mungnolza/ui/freeboard/viewmodel/FreeBoardViewModel.kt delete mode 100644 MungNolZa/app/src/main/java/kr/co/lion/mungnolza/ui/main/fragment/adapter/BoardAdapter.kt delete mode 100644 MungNolZa/app/src/main/java/kr/co/lion/mungnolza/ui/main/fragment/adapter/ChattingAdapter.kt delete mode 100644 MungNolZa/app/src/main/java/kr/co/lion/mungnolza/ui/main/viewmodel/TestViewModel.kt diff --git a/MungNolZa/app/src/main/AndroidManifest.xml b/MungNolZa/app/src/main/AndroidManifest.xml index fb44823..fde04e3 100644 --- a/MungNolZa/app/src/main/AndroidManifest.xml +++ b/MungNolZa/app/src/main/AndroidManifest.xml @@ -1,12 +1,13 @@ + - + + - - - - + android:exported="true"/> @@ -34,7 +32,7 @@ android:exported="true" /> + android:exported="true" /> @@ -67,7 +65,10 @@ - + + + \ No newline at end of file diff --git a/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/ui/freeboard/viewmodel/FreeBoardViewModel.kt b/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/ui/freeboard/viewmodel/FreeBoardViewModel.kt deleted file mode 100644 index d11c7ca..0000000 --- a/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/ui/freeboard/viewmodel/FreeBoardViewModel.kt +++ /dev/null @@ -1,6 +0,0 @@ -package kr.co.lion.mungnolza.ui.freeboard.viewmodel - -import androidx.lifecycle.ViewModel - -class FreeBoardViewModel: ViewModel() { -} \ No newline at end of file diff --git a/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/ui/main/fragment/adapter/BoardAdapter.kt b/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/ui/main/fragment/adapter/BoardAdapter.kt deleted file mode 100644 index a97adfd..0000000 --- a/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/ui/main/fragment/adapter/BoardAdapter.kt +++ /dev/null @@ -1,4 +0,0 @@ -package kr.co.lion.mungnolza.ui.main.fragment.adapter - -class BoardAdapter { -} \ No newline at end of file diff --git a/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/ui/main/fragment/adapter/ChattingAdapter.kt b/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/ui/main/fragment/adapter/ChattingAdapter.kt deleted file mode 100644 index 27a3724..0000000 --- a/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/ui/main/fragment/adapter/ChattingAdapter.kt +++ /dev/null @@ -1,4 +0,0 @@ -package kr.co.lion.mungnolza.ui.main.fragment.adapter - -class ChattingAdapter { -} \ No newline at end of file diff --git a/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/ui/main/viewmodel/TestViewModel.kt b/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/ui/main/viewmodel/TestViewModel.kt deleted file mode 100644 index e6fc57e..0000000 --- a/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/ui/main/viewmodel/TestViewModel.kt +++ /dev/null @@ -1,7 +0,0 @@ -package kr.co.lion.mungnolza.ui.main.viewmodel - -import androidx.lifecycle.ViewModel - -class TestViewModel: ViewModel() { - -} \ No newline at end of file diff --git a/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/util/BoardUtil.kt b/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/util/BoardUtil.kt index 688c858..5246118 100644 --- a/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/util/BoardUtil.kt +++ b/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/util/BoardUtil.kt @@ -135,4 +135,9 @@ enum class BoardFragmentName(var str:String){ // EDIT_BOARD_FRAGMENT(), +} + +enum class ContentState(var str:String, var number:Int){ + CONTENT_STATE_NORMAL("정상", 1), + CONTENT_STATE_REMOVE("삭제", 2), } \ No newline at end of file diff --git a/MungNolZa/app/src/main/res/layout/row_free_board.xml b/MungNolZa/app/src/main/res/layout/row_free_board.xml index 09c3e47..6ebf7c1 100644 --- a/MungNolZa/app/src/main/res/layout/row_free_board.xml +++ b/MungNolZa/app/src/main/res/layout/row_free_board.xml @@ -1,94 +1,93 @@ - + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:padding="15dp"> - + android:text="제목" + android:textSize="@dimen/board_text_title_size" + android:textStyle="bold" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="parent" /> - + - + + - + - + - + - - + + - \ No newline at end of file diff --git a/MungNolZa/app/src/main/res/menu/menu_free_board.xml b/MungNolZa/app/src/main/res/menu/menu_free_board.xml index 52acb4b..9f2cd06 100644 --- a/MungNolZa/app/src/main/res/menu/menu_free_board.xml +++ b/MungNolZa/app/src/main/res/menu/menu_free_board.xml @@ -4,7 +4,7 @@ \ No newline at end of file diff --git a/MungNolZa/app/src/main/res/values/colors.xml b/MungNolZa/app/src/main/res/values/colors.xml index d568934..f1dc93f 100644 --- a/MungNolZa/app/src/main/res/values/colors.xml +++ b/MungNolZa/app/src/main/res/values/colors.xml @@ -22,6 +22,5 @@ #FFEA9F #ffea9f - #e0e0e0 \ No newline at end of file diff --git a/MungNolZa/app/src/main/res/values/dimens.xml b/MungNolZa/app/src/main/res/values/dimens.xml index 41e4d35..6dbd18b 100644 --- a/MungNolZa/app/src/main/res/values/dimens.xml +++ b/MungNolZa/app/src/main/res/values/dimens.xml @@ -49,7 +49,7 @@ 10dp 10dp 10dp - 10sp + 13sp 70dp @@ -74,8 +74,8 @@ 40dp 35dp 35dp - 15dp - 15dp + 20dp + 20dp 15dp 15dp @@ -93,7 +93,7 @@ 18sp - 14sp + 15sp 5dp 3dp 10dp diff --git a/MungNolZa/app/src/main/res/values/strings.xml b/MungNolZa/app/src/main/res/values/strings.xml index 3cbfdf8..55cb017 100644 --- a/MungNolZa/app/src/main/res/values/strings.xml +++ b/MungNolZa/app/src/main/res/values/strings.xml @@ -71,7 +71,7 @@ 채팅 - 자유게시판 + 자유 게시판 예약 프로필 From 581cde1a0326a1bc1088508dec7c57a87ac52646 Mon Sep 17 00:00:00 2001 From: chanho Date: Fri, 12 Apr 2024 02:19:38 +0900 Subject: [PATCH 4/5] =?UTF-8?q?[#36]=20=EB=A9=94=EC=9D=B8=20=ED=99=94?= =?UTF-8?q?=EB=A9=B4=20=EA=B2=8C=EC=8B=9C=ED=8C=90=20=EA=B8=80=20=EB=B3=B4?= =?UTF-8?q?=EC=97=AC=EC=A3=BC=EA=B8=B0=20=EC=99=84=EB=A3=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mungnolza/model/BoardAddUerInfoModel.kt | 8 +- .../kr/co/lion/mungnolza/model/BoardModel.kt | 4 +- .../co/lion/mungnolza/ui/main/MainActivity.kt | 5 + .../ui/main/adapter/FreeBoardAdapter.kt | 50 ++++++ .../ui/main/fragment/FreeBoardFragment.kt | 157 +++++------------- .../ui/main/fragment/HomeFragment.kt | 17 +- .../ui/main/fragment/MainChatFragment.kt | 20 +-- .../ui/main/viewmodel/MainViewModel.kt | 55 ++++++ .../ui/main/viewmodel/MainViewModelFactory.kt | 19 +++ .../main/res/layout/fragment_free_board.xml | 64 +++---- .../app/src/main/res/layout/fragment_home.xml | 4 +- .../main/res/layout/fragment_main_chat.xml | 11 +- 12 files changed, 227 insertions(+), 187 deletions(-) create mode 100644 MungNolZa/app/src/main/java/kr/co/lion/mungnolza/ui/main/adapter/FreeBoardAdapter.kt create mode 100644 MungNolZa/app/src/main/java/kr/co/lion/mungnolza/ui/main/viewmodel/MainViewModel.kt create mode 100644 MungNolZa/app/src/main/java/kr/co/lion/mungnolza/ui/main/viewmodel/MainViewModelFactory.kt 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 cfd9ba6..b36e73b 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,13 +1,9 @@ package kr.co.lion.mungnolza.model import android.net.Uri -import android.os.Parcelable -import kotlinx.parcelize.Parcelize -import kotlinx.parcelize.RawValue -@Parcelize data class BoardAddUerInfoModel ( - val contentData: @RawValue BoardModel, + val contentData: BoardModel, val writerNickName: String, val imgUri: Uri -): Parcelable \ No newline at end of file +) \ No newline at end of file diff --git a/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/model/BoardModel.kt b/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/model/BoardModel.kt index 2c84775..0d6112b 100644 --- a/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/model/BoardModel.kt +++ b/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/model/BoardModel.kt @@ -2,7 +2,7 @@ package kr.co.lion.mungnolza.model import android.os.Parcelable import kotlinx.parcelize.Parcelize - +@Parcelize data class BoardModel( var boardIdx: Int, var boardTitle: String, @@ -13,7 +13,7 @@ data class BoardModel( var boardModifyDate: String, var boardLikeNumber: Int, var boardState: Int -){ +): Parcelable{ constructor() : this( boardIdx = 0, boardTitle = "", diff --git a/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/ui/main/MainActivity.kt b/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/ui/main/MainActivity.kt index 7eed982..d505580 100644 --- a/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/ui/main/MainActivity.kt +++ b/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/ui/main/MainActivity.kt @@ -2,8 +2,12 @@ package kr.co.lion.mungnolza.ui.main import androidx.appcompat.app.AppCompatActivity import android.os.Bundle +import androidx.lifecycle.lifecycleScope import androidx.navigation.fragment.NavHostFragment import androidx.navigation.ui.NavigationUI +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.launch import kr.co.lion.mungnolza.R import kr.co.lion.mungnolza.databinding.ActivityMainBinding @@ -20,5 +24,6 @@ class MainActivity : AppCompatActivity() { val navHostFragment = supportFragmentManager.findFragmentById(R.id.fragment_container) as NavHostFragment val navController = navHostFragment.navController NavigationUI.setupWithNavController(binding.navigationView, navController) + } } \ 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 new file mode 100644 index 0000000..488a041 --- /dev/null +++ b/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/ui/main/adapter/FreeBoardAdapter.kt @@ -0,0 +1,50 @@ +package kr.co.lion.mungnolza.ui.main.adapter + +import android.view.LayoutInflater +import android.view.ViewGroup +import androidx.recyclerview.widget.RecyclerView +import com.bumptech.glide.Glide +import kr.co.lion.mungnolza.databinding.RowFreeBoardBinding +import kr.co.lion.mungnolza.model.BoardAddUerInfoModel + +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) { + fun bind(item: BoardAddUerInfoModel) { + with(binding) { + tvTitle.text = item.contentData.boardTitle + tvContent.text = "${item.contentData.boardContent.substring(0, 20)}..." + tvLike.text = item.contentData.boardLikeNumber.toString() + tvDate.text = item.contentData.boardWriteDate + tvNickname.text = item.writerNickName + + Glide.with(binding.root) + .load(item.imgUri) + .into(thumbnail) + + root.setOnClickListener { + onClick.invoke(item.contentData.boardIdx) + } + } + } + } + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): FreeBoardAdapterViewHolder { + val inflater = LayoutInflater.from(parent.context) + + return FreeBoardAdapterViewHolder( + RowFreeBoardBinding.inflate(inflater, parent, false), + onClick + ) + } + + override fun getItemCount() = dataSet.size + + override fun onBindViewHolder(holder: FreeBoardAdapterViewHolder, position: Int) { + holder.bind(dataSet[position]) + } +} \ 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 47fd497..5599011 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 @@ -1,150 +1,73 @@ 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 import android.view.View import android.view.ViewGroup +import androidx.fragment.app.activityViewModels +import androidx.lifecycle.Lifecycle +import androidx.lifecycle.lifecycleScope +import androidx.lifecycle.repeatOnLifecycle import androidx.recyclerview.widget.LinearLayoutManager -import androidx.recyclerview.widget.RecyclerView import com.google.android.material.divider.MaterialDividerItemDecoration -import kr.co.lion.mungnolza.R +import kotlinx.coroutines.launch import kr.co.lion.mungnolza.databinding.FragmentFreeBoardBinding -import kr.co.lion.mungnolza.databinding.RowFreeBoardBinding - +import kr.co.lion.mungnolza.ui.freeboard.BoardActivity +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() { 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? { + ): View { _binding = FragmentFreeBoardBinding.inflate(inflater, container, false) - - - setSearchBar() - setRecyclerViewFreeBoard() - setRecyclerViewSearchFreeBoard() - + initView() return binding.root } - - fun setSearchBar(){ - binding.apply{ - searchBarFreeBoard.apply{ - // SearchBar에 보여줄 메시지 - hint = "여기를 눌러 검색해주세요" - // 메뉴 - inflateMenu(R.menu.menu_search_free_board) - - } - - searchViewFreeBoard.apply{ - // SearchView에 보여줄 메시지 - hint = "검색어를 입력해주세요" - } - } - } - - fun setRecyclerViewFreeBoard(){ - binding.apply { - recyclerViewFreeBoard.apply { - // 어뎁터 - adapter = RecyclerViewAdapterFreeBoard() - // 레이아웃 매니저 - layoutManager = LinearLayoutManager(requireContext()) - // 데코레이션 - val deco = MaterialDividerItemDecoration(requireContext(), MaterialDividerItemDecoration.VERTICAL) - addItemDecoration(deco) + private fun initView() { + viewLifecycleOwner.lifecycleScope.launch { + repeatOnLifecycle(Lifecycle.State.STARTED) { + viewModel.boardContentList.collect { boardList -> + freeBoardAdapter = FreeBoardAdapter( + dataSet = boardList, + onClick = { selectedItemIdx -> + + val selectedItem = boardList.find { it.contentData.boardIdx == selectedItemIdx } + val selectedItemData = selectedItem?.contentData + val intent = Intent(requireContext(), BoardActivity::class.java) + intent.putExtra("content", selectedItemData) + startActivity(intent) + } + ) + setRecyclerViewFreeBoard() + } } } } - // 검색 화면의 RecyclerView를 구성하는 메서드 - fun setRecyclerViewSearchFreeBoard(){ - binding.apply { - recyclerViewSearchFreeBoard.apply { - // 어뎁터 - adapter = RecyclerViewAdapterSearchFreeBoard() - // 레이아웃 매니저 - layoutManager = LinearLayoutManager(requireContext()) - // 데코레이션 - val deco = MaterialDividerItemDecoration(requireContext(), MaterialDividerItemDecoration.VERTICAL) - addItemDecoration(deco) - } - } - } - - // 메인 화면의 RecyclerView의 어뎁터 - inner class RecyclerViewAdapterFreeBoard : RecyclerView.Adapter(){ - inner class ViewHolderFreeBoard(rowFreeBoardBinding: RowFreeBoardBinding) : RecyclerView.ViewHolder(rowFreeBoardBinding.root){ - val rowFreeBoardBinding:RowFreeBoardBinding - - init { - this.rowFreeBoardBinding = rowFreeBoardBinding - - this.rowFreeBoardBinding.root.layoutParams = ViewGroup.LayoutParams( - ViewGroup.LayoutParams.MATCH_PARENT, - ViewGroup.LayoutParams.WRAP_CONTENT - ) - } - } - override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolderFreeBoard { - val rowMainBinding = RowFreeBoardBinding.inflate(layoutInflater) - val mainViewHolder = ViewHolderFreeBoard(rowMainBinding) - return mainViewHolder - } - - override fun getItemCount(): Int { - return 100 - } - - override fun onBindViewHolder(holder: ViewHolderFreeBoard, position: Int) { - holder.rowFreeBoardBinding.textViewTitleFreeBoardRow.text = "제목 $position" - holder.rowFreeBoardBinding.textViewNickNameFreeBoardRow.text = "작성자 $position" - holder.rowFreeBoardBinding.textViewContentFreeBoardRow.text = "강아지 너무 귀엽죠!!\n참고로 암컷입니다!!! 남자 아닙니다!!" - holder.rowFreeBoardBinding.textViewDateFreeBoardRow.text = "2024-03-26" - holder.rowFreeBoardBinding.imageViewPhotoFreeBoardRow.setImageResource(R.drawable.img_dog) - - holder.rowFreeBoardBinding.root.setOnClickListener { - //boardActivity.replaceFragment(BoardFragmentName.SHOW_DETAIL_BOARD_FRAGMENT,true,true,null) - } + private fun setRecyclerViewFreeBoard() { + with(binding.recyclerViewFreeBoard) { + adapter = freeBoardAdapter + layoutManager = LinearLayoutManager(requireContext()) + val deco = MaterialDividerItemDecoration( + requireContext(), + MaterialDividerItemDecoration.VERTICAL + ) + addItemDecoration(deco) } } - // 검색 화면의 RecyclerView의 어뎁터 - inner class RecyclerViewAdapterSearchFreeBoard : RecyclerView.Adapter(){ - inner class ViewHolderSearchFreeBoard(rowMainBinding: RowFreeBoardBinding) : RecyclerView.ViewHolder(rowMainBinding.root){ - val rowFreeBoardBinding:RowFreeBoardBinding - - init { - this.rowFreeBoardBinding = rowMainBinding - this.rowFreeBoardBinding.root.layoutParams = ViewGroup.LayoutParams( - ViewGroup.LayoutParams.MATCH_PARENT, - ViewGroup.LayoutParams.WRAP_CONTENT - ) - } - } - - override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolderSearchFreeBoard { - val rowMainBinding = RowFreeBoardBinding.inflate(layoutInflater) - val searchViewHolder = ViewHolderSearchFreeBoard(rowMainBinding) - return searchViewHolder - } - - override fun getItemCount(): Int { - return 100 - } - - override fun onBindViewHolder(holder: ViewHolderSearchFreeBoard, position: Int) { - holder.rowFreeBoardBinding.textViewTitleFreeBoardRow.text = "제목 $position" - holder.rowFreeBoardBinding.textViewNickNameFreeBoardRow.text = "작성자 $position" - } - } } \ No newline at end of file diff --git a/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/ui/main/fragment/HomeFragment.kt b/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/ui/main/fragment/HomeFragment.kt index 0a870b0..84ae41b 100644 --- a/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/ui/main/fragment/HomeFragment.kt +++ b/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/ui/main/fragment/HomeFragment.kt @@ -5,16 +5,27 @@ import androidx.fragment.app.Fragment import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import androidx.fragment.app.activityViewModels import kr.co.lion.mungnolza.R +import kr.co.lion.mungnolza.databinding.FragmentHomeBinding +import kr.co.lion.mungnolza.ui.main.viewmodel.MainViewModel +import kr.co.lion.mungnolza.ui.main.viewmodel.MainViewModelFactory class HomeFragment : Fragment() { + private var _binding: FragmentHomeBinding? = null + private val binding get() = _binding!! + private val viewModel: MainViewModel by activityViewModels { MainViewModelFactory() } override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? - ): View? { - // Inflate the layout for this fragment - return inflater.inflate(R.layout.fragment_home, container, false) + ): View { + _binding = FragmentHomeBinding.inflate(inflater, container, false) + initView() + return binding.root } + private fun initView(){ + viewModel + } } \ No newline at end of file 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 477294d..68c16cc 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 @@ -22,35 +22,17 @@ class MainChatFragment : Fragment() { private var _binding: FragmentMainChatBinding ? = null private val binding get() = _binding!! - override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?, - ): View? { + ): View { _binding = FragmentMainChatBinding.inflate(inflater, container, false) - - setToolbar() setRecyclerViewMainChat() return binding.root } - fun initData(){ - - } - - fun setToolbar(){ - binding.apply{ - toolbarMainChat.apply{ - - setNavigationIcon(R.drawable.ic_arrow_back_24px) - - inflateMenu(R.menu.menu_main_chat) - } - } - } - fun setRecyclerViewMainChat(){ binding.apply { recyclerViewMainChat.apply { 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 new file mode 100644 index 0000000..e7d2bc6 --- /dev/null +++ b/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/ui/main/viewmodel/MainViewModel.kt @@ -0,0 +1,55 @@ +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.model.BoardAddUerInfoModel +import kr.co.lion.mungnolza.model.BoardModel +import kr.co.lion.mungnolza.model.UserModel +import kr.co.lion.mungnolza.repository.FreeBoardRepositoryImpl +import kr.co.lion.mungnolza.repository.UserRepositoryImpl + +class MainViewModel( + private val freeBoardRepository: FreeBoardRepositoryImpl, + private val userRepository: UserRepositoryImpl +): ViewModel() { + private val _userList = MutableStateFlow>(emptyList()) + val userList = _userList.asStateFlow() + + private var _boardContentList = MutableStateFlow>(emptyList()) + val boardContentList = _boardContentList.asStateFlow() + + init { + Log.d("dasdsaas", "초기화") + fetchAllBoardDataWithUserInfo() + } + + private fun fetchAllBoardDataWithUserInfo() = viewModelScope.launch(Dispatchers.IO) { + 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) } + if (content != null) { + contentList.add(content) + } + } + _boardContentList.value = contentList + } + + private suspend fun fetchBoardImg(boardIdx: String, imgName: String): Uri? { + return freeBoardRepository.fetchAllBoardImage(boardIdx, imgName) + } + + suspend fun fetchUserProfileImage(path: String): Uri { + return userRepository.fetchUserProfileImage(path) + } +} \ 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 new file mode 100644 index 0000000..557de2f --- /dev/null +++ b/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/ui/main/viewmodel/MainViewModelFactory.kt @@ -0,0 +1,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 java.lang.IllegalArgumentException + +class MainViewModelFactory: ViewModelProvider.Factory{ + private val boardRepository = FreeBoardRepositoryImpl() + private val userRepository = UserRepositoryImpl() + override fun create(modelClass: Class): T { + if (modelClass.isAssignableFrom(MainViewModel::class.java)){ + return MainViewModel(boardRepository, userRepository) as T + } + throw IllegalArgumentException("unknown ViewModel class") + } +} \ No newline at end of file diff --git a/MungNolZa/app/src/main/res/layout/fragment_free_board.xml b/MungNolZa/app/src/main/res/layout/fragment_free_board.xml index 3c410b6..5f3b99a 100644 --- a/MungNolZa/app/src/main/res/layout/fragment_free_board.xml +++ b/MungNolZa/app/src/main/res/layout/fragment_free_board.xml @@ -1,41 +1,47 @@ - - + android:layout_height="match_parent" + android:orientation="vertical" + android:transitionGroup="true"> - + android:layout_height="wrap_content" + app:title="@string/menu_item_bottom_navigation_freeboard" + android:minHeight="?attr/actionBarSize" + android:theme="?attr/actionBarTheme" + app:menu="@menu/menu_free_board"/> - + android:layout_height="match_parent"> - + - + android:layout_height="match_parent" + android:layout_marginTop="90dp" /> - - \ No newline at end of file + + + + + + \ No newline at end of file diff --git a/MungNolZa/app/src/main/res/layout/fragment_home.xml b/MungNolZa/app/src/main/res/layout/fragment_home.xml index 9a753b8..f3284fe 100644 --- a/MungNolZa/app/src/main/res/layout/fragment_home.xml +++ b/MungNolZa/app/src/main/res/layout/fragment_home.xml @@ -15,7 +15,7 @@ android:layout_height="wrap_content" android:layout_gravity="center" android:fontFamily="@font/binggrae_bold" - android:text="@string/toolbar_main_text" + android:text="멍놀자" android:textColor="@android:color/black" android:textSize="@dimen/shared_toolbar_title_size" android:textStyle="bold" /> @@ -26,7 +26,7 @@ android:id="@+id/imageView6" android:layout_width="match_parent" android:layout_height="wrap_content" - /> + /> - Date: Fri, 12 Apr 2024 02:33:02 +0900 Subject: [PATCH 5/5] =?UTF-8?q?[#36]=20=EC=A3=BC=EC=84=9D=20=EC=A0=9C?= =?UTF-8?q?=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/kr/co/lion/mungnolza/ui/main/viewmodel/MainViewModel.kt | 1 - 1 file changed, 1 deletion(-) 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 e7d2bc6..98b87d9 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 @@ -26,7 +26,6 @@ class MainViewModel( val boardContentList = _boardContentList.asStateFlow() init { - Log.d("dasdsaas", "초기화") fetchAllBoardDataWithUserInfo() }