From ae94ff052ea71a27d1cbdb78a37e2239a38ac398 Mon Sep 17 00:00:00 2001 From: Jun Date: Tue, 16 Apr 2024 15:17:43 +0900 Subject: [PATCH 1/4] =?UTF-8?q?[#44]=20=EC=A4=91=EA=B0=84=20=EC=BB=A4?= =?UTF-8?q?=EB=B0=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- MungNolZa/app/src/main/AndroidManifest.xml | 18 ++- .../data/repository/BoardRepository.kt | 12 +- .../data/repository/BoardRepositoryImpl.kt | 79 +++++++-- .../data/repository/UserRepository.kt | 7 - .../data/repository/UserRepositoryImpl.kt | 28 ---- .../repository/FreeBoardRepository.kt | 4 + .../repository/FreeBoardRepositoryImpl.kt | 35 ++++ .../ui/freeboard/AddBoardActivity.kt | 152 ++++++++++++++++++ .../ui/freeboard/fragment/AddBoardFragment.kt | 62 +++++-- .../freeboard/fragment/ModifyBoardFragment.kt | 14 +- .../fragment/ShowDetailBoardFragment.kt | 121 ++++++-------- .../freeboard/viewmodel/AddBoardViewModel.kt | 8 + .../ui/freeboard/viewmodel/BoardViewModel.kt | 38 +++++ .../viewmodel/ShowDetailBoardViewModel.kt | 5 - .../ui/main/fragment/FreeBoardFragment.kt | 15 +- .../main/res/layout/activity_add_board.xml | 18 +++ .../src/main/res/layout/activity_board.xml | 12 +- .../app/src/main/res/layout/activity_main.xml | 2 +- .../main/res/layout/fragment_add_board.xml | 2 + .../main/res/layout/fragment_free_board.xml | 14 +- .../main/res/layout/fragment_modify_board.xml | 5 +- 21 files changed, 490 insertions(+), 161 deletions(-) delete mode 100644 MungNolZa/app/src/main/java/kr/co/lion/mungnolza/data/repository/UserRepository.kt delete mode 100644 MungNolZa/app/src/main/java/kr/co/lion/mungnolza/data/repository/UserRepositoryImpl.kt create mode 100644 MungNolZa/app/src/main/java/kr/co/lion/mungnolza/ui/freeboard/AddBoardActivity.kt create mode 100644 MungNolZa/app/src/main/java/kr/co/lion/mungnolza/ui/freeboard/viewmodel/BoardViewModel.kt create mode 100644 MungNolZa/app/src/main/res/layout/activity_add_board.xml diff --git a/MungNolZa/app/src/main/AndroidManifest.xml b/MungNolZa/app/src/main/AndroidManifest.xml index 0ce0789..ed0dfa2 100644 --- a/MungNolZa/app/src/main/AndroidManifest.xml +++ b/MungNolZa/app/src/main/AndroidManifest.xml @@ -18,10 +18,12 @@ android:supportsRtl="true" android:theme="@style/Theme.MungNolZa" tools:targetApi="31"> + - @@ -47,19 +49,19 @@ - - + android:windowSoftInputMode="adjustPan"> + + diff --git a/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/data/repository/BoardRepository.kt b/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/data/repository/BoardRepository.kt index e2c9e38..1aaeceb 100644 --- a/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/data/repository/BoardRepository.kt +++ b/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/data/repository/BoardRepository.kt @@ -1,8 +1,18 @@ package kr.co.lion.mungnolza.data.repository +import android.net.Uri import kr.co.lion.mungnolza.model.BoardModel interface BoardRepository { - suspend fun getBoardData(boardIdx: Int): BoardModel? + suspend fun getBoardList():ArrayList + + suspend fun insertBoard(boardModel:BoardModel) + + suspend fun deleteBoard(boardModel: BoardModel) + + suspend fun getBoardImageListPath(boardModel: BoardModel):Uri? + + suspend fun updateBoard(boardModel:BoardModel, isRemoveImage:Boolean) + } \ 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 421b210..d05cbca 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,28 +1,87 @@ package kr.co.lion.mungnolza.data.repository +import android.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.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.model.UserModel +import kr.co.lion.mungnolza.util.ContentState -class BoardRepositoryImpl : BoardRepository{ +class BoardRepositoryImpl() : BoardRepository { - override suspend fun getBoardData(boardIdx: Int): BoardModel? { - var boardModel: BoardModel? = null + private val boardStore = Firebase.firestore.collection("Board") + private val storage = Firebase.storage.reference - val job = CoroutineScope(Dispatchers.IO).launch { - val collectionReference = Firebase.firestore.collection("Board") - val querySnapshot = - collectionReference.whereEqualTo("boardIdx", boardIdx).get().await() + override suspend fun getBoardList(): ArrayList { + val boardList = arrayListOf() - if (querySnapshot.isEmpty == false) { - boardModel = querySnapshot.documents[0].toObject(BoardModel::class.java) + 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 boardModel = it.toObject(BoardModel::class.java) + boardList.add(boardModel) } + + } catch (e: Exception) { + Log.e("FirebaseResult", "Error Get Board Data: ${e.message}") } - return boardModel + return boardList + } + + override suspend fun insertBoard(boardModel: BoardModel) { + boardStore.add(boardModel) } + + override suspend fun updateBoard(boardModel: BoardModel, isRemoveImage: Boolean) { + try{ + val query = boardStore.whereEqualTo("boardIdx",boardModel.boardIdx).get().await() + + // 저장 데이터를 HashMap으로 만든다. + val map = mutableMapOf() + map["boardTitle"] = boardModel.boardTitle + map["boardContent"] = boardModel.boardContent + + if(boardModel.boardImagePathList.isNotEmpty()){ + map["boardImagePathList"] = boardModel.boardImagePathList + } + if(isRemoveImage == true){ + map["boardImagePathList"] = null + } + + query.documents[0].reference.update(map) + }catch (e: Exception) { + Log.e("FirebaseResult", "Error Update Board Data: ${e.message}") + } + + } + + override suspend fun deleteBoard(boardModel: BoardModel) { + // 삭제가 아닌 BoardState 변경 + } + + override suspend fun getBoardImageListPath(boardModel: BoardModel):Uri?{ + var response:Uri? = null + val path = "board/${boardModel.boardIdx}/${boardModel.boardImagePathList}" + try{ + response = storage.child(path).downloadUrl.await() + }catch (e:Exception){ + Log.e("FirebaseResult", + "Error Get BoardImageListPath : ${storage.child(path)}") + } + return response + + } + + } \ No newline at end of file diff --git a/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/data/repository/UserRepository.kt b/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/data/repository/UserRepository.kt deleted file mode 100644 index d1cd87e..0000000 --- a/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/data/repository/UserRepository.kt +++ /dev/null @@ -1,7 +0,0 @@ -package kr.co.lion.mungnolza.data.repository - -import kr.co.lion.mungnolza.model.UserModel - -interface UserRepository { - suspend fun getUserData(uniqueNumber:Int): UserModel? -} \ No newline at end of file diff --git a/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/data/repository/UserRepositoryImpl.kt b/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/data/repository/UserRepositoryImpl.kt deleted file mode 100644 index 4ea4bbc..0000000 --- a/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/data/repository/UserRepositoryImpl.kt +++ /dev/null @@ -1,28 +0,0 @@ -package kr.co.lion.mungnolza.data.repository - -import com.google.firebase.Firebase -import com.google.firebase.firestore.firestore -import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.launch -import kotlinx.coroutines.tasks.await -import kr.co.lion.mungnolza.model.UserModel - -class UserRepositoryImpl : UserRepository { - - override suspend fun getUserData(uniqueNumber: Int): UserModel? { - var userModel: UserModel? = null - - val job = CoroutineScope(Dispatchers.IO).launch { - val collectionReference = Firebase.firestore.collection("User") - val querySnapshot = - collectionReference.whereEqualTo("uniqueNumber", uniqueNumber).get().await() - - if (querySnapshot.isEmpty == false) { - userModel = querySnapshot.documents[0].toObject(UserModel::class.java) - } - } - job.join() - return userModel - } -} \ 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 index 74bd392..5c08a35 100644 --- 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 @@ -6,4 +6,8 @@ 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 index 46e2187..f526ffd 100644 --- 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 @@ -8,6 +8,9 @@ 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 @@ -46,4 +49,36 @@ class FreeBoardRepositoryImpl : FreeBoardRepository { } 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/ui/freeboard/AddBoardActivity.kt b/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/ui/freeboard/AddBoardActivity.kt new file mode 100644 index 0000000..85b7a2e --- /dev/null +++ b/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/ui/freeboard/AddBoardActivity.kt @@ -0,0 +1,152 @@ +package kr.co.lion.mungnolza.ui.freeboard + +import android.os.Bundle +import android.os.SystemClock +import android.view.LayoutInflater +import androidx.activity.enableEdgeToEdge +import androidx.appcompat.app.AppCompatActivity +import androidx.core.view.ViewCompat +import androidx.core.view.WindowInsetsCompat +import androidx.fragment.app.Fragment +import androidx.fragment.app.FragmentManager +import com.google.android.material.transition.MaterialSharedAxis +import kr.co.lion.mungnolza.R +import kr.co.lion.mungnolza.databinding.ActivityAddBoardBinding +import kr.co.lion.mungnolza.ui.freeboard.fragment.AddBoardFragment +import kr.co.lion.mungnolza.ui.freeboard.fragment.ModifyBoardFragment +import kr.co.lion.mungnolza.ui.freeboard.fragment.ShowDetailBoardFragment +import kr.co.lion.mungnolza.ui.main.fragment.FreeBoardFragment +import kr.co.lion.mungnolza.util.BoardFragmentName + +class AddBoardActivity : AppCompatActivity() { + + private var _binding: ActivityAddBoardBinding ?= null + private val binding get() = _binding!! + + lateinit var addBoardActivity: AddBoardActivity + + var oldFragment: Fragment? = null + var newFragment: Fragment? = null + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + + _binding = ActivityAddBoardBinding.inflate(layoutInflater) + + replaceFragment(BoardFragmentName.ADD_BOARD_FRAGMENT,false,true,null) + + setContentView(binding.root) + + } + + override fun onDestroy() { + super.onDestroy() + _binding = null + } + + fun replaceFragment(name: BoardFragmentName, addToBackStack:Boolean, isAnimate:Boolean, data:Bundle?){ + + SystemClock.sleep(200) + + // Fragment를 교체할 수 있는 객체를 추출한다. + val fragmentTransaction = supportFragmentManager.beginTransaction() + + // oldFragment에 newFragment가 가지고 있는 Fragment 객체를 담아준다. + if(newFragment != null){ + oldFragment = newFragment + } + + // 이름으로 분기한다. + // Fragment의 객체를 생성하여 변수에 담아준다. + when(name){ + BoardFragmentName.FREE_BOARD_FRAGMENT -> { + newFragment = FreeBoardFragment() + } + + BoardFragmentName.ADD_BOARD_FRAGMENT -> { + newFragment = AddBoardFragment() + } + BoardFragmentName.SHOW_DETAIL_BOARD_FRAGMENT -> { + newFragment = ShowDetailBoardFragment() + } + BoardFragmentName.MODIFY_BOARD_FRAGMENT -> { + newFragment = ModifyBoardFragment() + } + + + else -> { + + } + + } + + // 새로운 Fragment에 전달할 객체가 있다면 arguments 프로퍼티에 넣어준다. + if(data != null){ + newFragment?.arguments = data + } + + if(newFragment != null){ + // 애니메이션 설정 + if(isAnimate == true){ + + // oldFragment -> newFragment + // oldFragment : exitTransition + // newFragment : enterTransition + + // newFragment -> oldFragment + // oldFragment : reenterTransition + // newFragment : returnTransition + + // MaterialSharedAxis : 좌우, 위아래, 공중 바닥 사이로 이동하는 애니메이션 효과 + // X - 좌우 + + // Y - 위아래 + // Z - 공중 바닥 + // 두 번째 매개변수 : 새로운 화면이 나타나는 것인지 여부를 설정해준다. + // true : 새로운 화면이 나타나는 애니메이션이 동작한다. + // false : 이전으로 되돌아가는 애니메이션이 동작한다. + + if(oldFragment != null){ + // old에서 new가 새롭게 보여질 때 old의 애니메이션 + oldFragment?.exitTransition = MaterialSharedAxis(MaterialSharedAxis.X, true) + // new에서 old로 되돌아갈때 old의 애니메이션 + oldFragment?.reenterTransition = MaterialSharedAxis(MaterialSharedAxis.X, false) + + oldFragment?.enterTransition = null + oldFragment?.returnTransition = null + } + + // old에서 new가 새롭게 보여질 때 new의 애니메이션 + newFragment?.enterTransition = MaterialSharedAxis(MaterialSharedAxis.X, true) + // new에서 old로 되돌아갈때 new의 애니메이션 + newFragment?.returnTransition = MaterialSharedAxis(MaterialSharedAxis.X, false) + + newFragment?.exitTransition = null + newFragment?.reenterTransition = null + + + } + + // Fragment를 교체한다.(이전 Fragment가 없으면 새롭게 추가하는 역할을 수행한다) + // 첫 번째 매개 변수 : Fragment를 배치할 FragmentContainerView의 ID + // 두 번째 매개 변수 : 보여주고하는 Fragment 객체를 + fragmentTransaction.replace(R.id.fragmentContainerAddBoard, newFragment!!) + + // addToBackStack 변수의 값이 true면 새롭게 보여질 Fragment를 BackStack에 포함시켜 준다. + if(addToBackStack == true){ + // BackStack 포함 시킬때 이름을 지정해주면 원하는 Fragment를 BackStack에서 제거할 수 있다. + fragmentTransaction.addToBackStack(name.str) + } + // Fragment 교체를 확정한다. + fragmentTransaction.commit() + } + } + + // BackStack에서 Fragment를 제거한다. + fun removeFragment(name: BoardFragmentName){ + SystemClock.sleep(200) + + // 지정한 이름으로 있는 Fragment를 BackStack에서 제거한다. + supportFragmentManager.popBackStack(name.str, FragmentManager.POP_BACK_STACK_INCLUSIVE) + } +} \ No newline at end of file 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 7044776..d809cbb 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 @@ -17,23 +17,33 @@ import androidx.activity.result.ActivityResultLauncher import androidx.activity.result.contract.ActivityResultContracts import androidx.appcompat.app.AppCompatActivity 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.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 class AddBoardFragment : Fragment() { lateinit var binding: FragmentAddBoardBinding - lateinit var boardActivity: BoardActivity + lateinit var addBoardActivity: AddBoardActivity lateinit var addBoardViewModel: AddBoardViewModel lateinit var boardImageList: MutableList @@ -50,13 +60,14 @@ class AddBoardFragment : Fragment() { inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?, ): View? { + binding = DataBindingUtil.inflate(layoutInflater,R.layout.fragment_add_board,container,false) + - binding = DataBindingUtil.inflate(inflater, R.layout.fragment_add_board, container, false) addBoardViewModel = AddBoardViewModel() binding.addBoardViewModel = addBoardViewModel binding.lifecycleOwner = this - boardActivity = activity as BoardActivity + addBoardActivity = activity as AddBoardActivity initData() setToolbar() @@ -72,6 +83,38 @@ class AddBoardFragment : Fragment() { adapterAddBoard = RecyclerViewAdapterAddBoard() } + fun uploadBoardData(){ + lifecycleScope.launch { + var serverFileName:String? = null + + if(isAddPicture){ + + } + + val boardRepository = BoardRepositoryImpl() + val userRepository = UserRepositoryImpl() + + // boardIdx 수정 필요 + val boardIdx = 2 + val boardTitle = addBoardViewModel.editTextTitleAddBoard.value!! + val boardContent = addBoardViewModel.editTextContentAddBoard.value!! + val boardImagePathList = mutableListOf() + val boardWriterIdx = "" + val simpleDateFormat = SimpleDateFormat("yyyy-MM-dd-HH-mm") + val boardWriteDate = simpleDateFormat.format(Date()) + val boardLikeNumber = 0 + val boardState = 1 + + val boardModel = BoardModel(boardIdx,boardTitle,boardContent,boardImagePathList,boardWriterIdx,boardWriteDate,boardWriteDate,boardLikeNumber,boardState) + + boardRepository.insertBoard(boardModel) + + val intent = Intent(requireContext(),BoardActivity::class.java) + intent.putExtra("boardData",boardModel) + startActivity(intent) + } + } + fun setCarousel() { binding.apply { // RecyclerView 셋팅 @@ -92,17 +135,14 @@ class AddBoardFragment : Fragment() { toolbarAddBoard.apply { setNavigationIcon(R.drawable.ic_arrow_back_24) - // 백버튼 이벤트 - setNavigationOnClickListener { - boardActivity.removeFragment(BoardFragmentName.ADD_BOARD_FRAGMENT) - } + inflateMenu(R.menu.menu_add_board) setOnMenuItemClickListener { when (it.itemId) { // 완료 버튼 이벤트 R.id.menuCompleteAddBoard -> { - + uploadBoardData() } } true @@ -137,13 +177,13 @@ class AddBoardFragment : Fragment() { val bitmap = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { // 이미지를 생성할 수 있는 객체를 생성한다. val source = - ImageDecoder.createSource(boardActivity.contentResolver, uri) + ImageDecoder.createSource(addBoardActivity.contentResolver, uri) // Bitmap을 생성한다. ImageDecoder.decodeBitmap(source) } else { // 컨텐츠 프로바이더를 통해 이미지 데이터에 접근한다. val cursor = - boardActivity.contentResolver.query(uri, null, null, null, null) + addBoardActivity.contentResolver.query(uri, null, null, null, null) if (cursor != null) { cursor.moveToNext() @@ -159,7 +199,7 @@ class AddBoardFragment : Fragment() { } // 회전 각도값을 가져온다. - val degree = BoardUtil.getDegree(boardActivity, uri) + val degree = BoardUtil.getDegree(addBoardActivity, uri) // 회전 이미지를 가져온다. val bitmap2 = BoardUtil.rotateBitmap(bitmap!!, degree.toFloat()) // 크기를 줄인 이미지를 가져온다. diff --git a/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/ui/freeboard/fragment/ModifyBoardFragment.kt b/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/ui/freeboard/fragment/ModifyBoardFragment.kt index f14686b..cb5a8ac 100644 --- a/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/ui/freeboard/fragment/ModifyBoardFragment.kt +++ b/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/ui/freeboard/fragment/ModifyBoardFragment.kt @@ -12,6 +12,7 @@ import kr.co.lion.mungnolza.R import kr.co.lion.mungnolza.databinding.FragmentModifyBoardBinding import kr.co.lion.mungnolza.databinding.RowAddBoardBinding import kr.co.lion.mungnolza.databinding.RowModifyBoardBinding +import kr.co.lion.mungnolza.model.BoardModel import kr.co.lion.mungnolza.ui.freeboard.BoardActivity import kr.co.lion.mungnolza.ui.freeboard.viewmodel.ModifyBoardViewModel import kr.co.lion.mungnolza.util.BoardFragmentName @@ -22,6 +23,7 @@ class ModifyBoardFragment : Fragment() { lateinit var boardActivity: BoardActivity lateinit var modifyBoardViewModel: ModifyBoardViewModel + lateinit var boardData:BoardModel override fun onCreateView( @@ -35,13 +37,24 @@ class ModifyBoardFragment : Fragment() { binding.modifyBoardViewModel = modifyBoardViewModel binding.lifecycleOwner = this + boardData = arguments?.getParcelable("boardData")!! + + setToolbar() setCarousel() + setData() return binding.root } + fun setData(){ + binding.apply { + editTextTitleModifyBoard.setText(boardData.boardTitle) + editTextContentModifyBoard.setText(boardData.boardContent) + } + } + fun setCarousel(){ binding.apply{ // RecyclerView 셋팅 @@ -97,5 +110,4 @@ class ModifyBoardFragment : Fragment() { holder.rowModifyBoardBinding.imageViewCarouselModifyBoard.setImageResource(R.drawable.img_dog) } } - } \ No newline at end of file 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 ad0825c..0d9504b 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,57 +1,42 @@ package kr.co.lion.mungnolza.ui.freeboard.fragment import android.content.DialogInterface +import android.os.Build import android.os.Bundle +import android.util.Log import androidx.fragment.app.Fragment import android.view.LayoutInflater import android.view.View import android.view.ViewGroup -import android.view.WindowManager -import androidx.databinding.DataBindingUtil -import androidx.fragment.app.DialogFragment import androidx.fragment.app.viewModels -import androidx.lifecycle.ViewModelProvider -import androidx.lifecycle.lifecycleScope -import androidx.recyclerview.widget.RecyclerView -import com.google.android.material.bottomsheet.BottomSheetDialog 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.launch -import kotlinx.coroutines.plus 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.data.repository.UserRepository -import kr.co.lion.mungnolza.data.repository.UserRepositoryImpl import kr.co.lion.mungnolza.databinding.FragmentShowDetailBoardBinding -import kr.co.lion.mungnolza.databinding.RowAddBoardBinding -import kr.co.lion.mungnolza.databinding.RowShowDetailBoardBinding import kr.co.lion.mungnolza.model.BoardModel import kr.co.lion.mungnolza.model.UserModel 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.ShowDetailBoardViewModel +import kr.co.lion.mungnolza.ui.freeboard.viewmodel.BoardViewModel import kr.co.lion.mungnolza.util.BoardFragmentName class ShowDetailBoardFragment : Fragment() { - private var _binding: FragmentShowDetailBoardBinding?= null + private var _binding: FragmentShowDetailBoardBinding? = null private val binding get() = _binding!! lateinit var boardActivity: BoardActivity - private val showDetailBoardViewModel by viewModels() - var userModel: UserModel?= null - var boardModel: BoardModel?= null + private val boardViewModel by viewModels() - var imagePathList = mutableListOf() + var userData: UserModel? = null + var boardData: BoardModel? = null + var imagePathList = mutableListOf() - var boardIdx:Int = 0 + var boardIdx: Int = 0 override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, @@ -63,9 +48,15 @@ class ShowDetailBoardFragment : Fragment() { setTest() - applyUserData() + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { + boardData = boardActivity.intent.getParcelableExtra("boardData", BoardModel::class.java) + } else { + boardData = boardActivity.intent.getParcelableExtra("boardData") + } + + Log.d("ShowDetailBoardFragment intent 데이터", "${boardData?.boardImagePathList?.get(0)}") - // boardIdx = arguments?.getInt("boardIdx")!! + applyUserData() return binding.root } @@ -86,33 +77,35 @@ class ShowDetailBoardFragment : Fragment() { // ---------------------------------------------------------------------------- - fun setTest(){ + fun setTest() { } - fun applyUserData(){ - binding.editTextTitleShowDetailBoard.setText(showDetailBoardViewModel.getBoardData().boardTitle) - binding.editTextContentShowDetailBoard.setText(showDetailBoardViewModel.getBoardData().boardContent) - binding.textViewDateShowDetailBoard.text = showDetailBoardViewModel.getBoardData().boardWriteDate + suspend fun applyImage(){ + // binding.imageViewProfileShowDetailBoard.setImageURI() + } + fun applyUserData() { + binding.editTextTitleShowDetailBoard.setText(boardData?.boardTitle) + binding.editTextContentShowDetailBoard.setText(boardData?.boardContent) + binding.textViewDateShowDetailBoard.text = boardData?.boardWriteDate - // 유저 정보는 boardModel로 접근해야 하는데 테스트는 일단 직접 호출 - binding.textViewNickNameShowDetailBoard.text = showDetailBoardViewModel.getUserData().userNickname + // 유저 정보는 boardModel로 접근해야 하는데 테스트는 일단 직접 호출 } - fun setCommentButton(){ - binding.apply{ + fun setCommentButton() { + binding.apply { imageViewCommentShowDetailBoard.setOnClickListener { showBottomCommentSheet() } } } - fun setCarousel(){ - binding.apply{ + fun setCarousel() { + binding.apply { // RecyclerView 셋팅 - recyclerViewPhotosShowDetailBoard.apply{ + recyclerViewPhotosShowDetailBoard.apply { // 어댑터 adapter = BoardCarouselAdapter() // 레이아웃 매니저 @@ -125,9 +118,9 @@ class ShowDetailBoardFragment : Fragment() { } // 툴바 설정 - fun setToolbar(){ - binding.apply{ - toolbarShowDetailBoard.apply{ + fun setToolbar() { + binding.apply { + toolbarShowDetailBoard.apply { setNavigationIcon(R.drawable.ic_arrow_back_24) setNavigationOnClickListener { @@ -138,10 +131,18 @@ class ShowDetailBoardFragment : Fragment() { inflateMenu(R.menu.menu_show_detail_board) setOnMenuItemClickListener { - when(it.itemId){ + when (it.itemId) { // 수정 아이콘 클릭 시 R.id.menuItemModifyShowDetailBoard -> { - boardActivity.replaceFragment(BoardFragmentName.MODIFY_BOARD_FRAGMENT,true,true,null) + val bundle = Bundle() + bundle.putParcelable("boardData",boardData) + + boardActivity.replaceFragment( + BoardFragmentName.MODIFY_BOARD_FRAGMENT, + true, + true, + bundle + ) } // 삭제 아이콘 클릭 시 @@ -155,51 +156,31 @@ class ShowDetailBoardFragment : Fragment() { } } - fun setDeleteDialog(){ + fun setDeleteDialog() { val materialAlertDialogBuilder = MaterialAlertDialogBuilder(requireContext()) - materialAlertDialogBuilder.apply{ + materialAlertDialogBuilder.apply { setTitle("삭제") setMessage("정말로 삭제하시겠습니까?") - setPositiveButton("삭제"){ dialogInterface: DialogInterface, i: Int -> + setPositiveButton("삭제") { dialogInterface: DialogInterface, i: Int -> } - setNegativeButton("닫기"){ dialogInterface: DialogInterface, i: Int -> + setNegativeButton("닫기") { dialogInterface: DialogInterface, i: Int -> } show() } } - fun showBottomCommentSheet(){ + fun showBottomCommentSheet() { val bottomCommentFragment = BottomCommentFragment() - bottomCommentFragment.apply{ + bottomCommentFragment.apply { } bottomCommentFragment.show(boardActivity.supportFragmentManager, "BottomCommentSheet") } -// inner class RecyclerViewAdapterShowDetailBoard: RecyclerView.Adapter() { -// inner class ViewHolderShowDetailBoard(rowShowDetailBoardBinding: RowShowDetailBoardBinding): RecyclerView.ViewHolder(rowShowDetailBoardBinding.root){ -// val rowShowDetailBoardBinding: RowShowDetailBoardBinding -// -// init{ -// this.rowShowDetailBoardBinding = rowShowDetailBoardBinding -// } -// } -// -// override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolderShowDetailBoard { -// val rowShowDetailBoardBinding = RowShowDetailBoardBinding.inflate(layoutInflater) -// val viewHolderAddBoard = ViewHolderShowDetailBoard(rowShowDetailBoardBinding) -// return viewHolderAddBoard -// } -// -// override fun getItemCount(): Int = 5 -// -// override fun onBindViewHolder(holder: ViewHolderShowDetailBoard, position: Int) { -// holder.rowShowDetailBoardBinding.imageViewCarouselShowDetailBoard.setImageResource(R.drawable.img_dog) -// } -// } + } \ 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 c51227e..cdc2a68 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 @@ -1,6 +1,14 @@ 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() { + + val editTextTitleAddBoard = MutableLiveData() + val editTextContentAddBoard = MutableLiveData() + + } \ No newline at end of file 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 new file mode 100644 index 0000000..0e52b84 --- /dev/null +++ b/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/ui/freeboard/viewmodel/BoardViewModel.kt @@ -0,0 +1,38 @@ +package kr.co.lion.mungnolza.ui.freeboard.viewmodel + +import android.net.Uri +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.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 + +class BoardViewModel( + private val boardRepository:BoardRepository, + private val userRepository: UserRepository +):ViewModel() { + + private var _boardList = MutableStateFlow>(emptyList()) + val boardList = _boardList.asStateFlow() + + init{ + + } + + private fun getBoardList():ArrayList { + var boardList = ArrayList() + viewModelScope.launch(Dispatchers.IO) { + boardList = boardRepository.getBoardList() + } + 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/freeboard/viewmodel/ShowDetailBoardViewModel.kt b/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/ui/freeboard/viewmodel/ShowDetailBoardViewModel.kt index 3644cf7..1576554 100644 --- a/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/ui/freeboard/viewmodel/ShowDetailBoardViewModel.kt +++ b/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/ui/freeboard/viewmodel/ShowDetailBoardViewModel.kt @@ -1,13 +1,8 @@ package kr.co.lion.mungnolza.ui.freeboard.viewmodel import androidx.lifecycle.ViewModel -import androidx.lifecycle.viewModelScope -import kotlinx.coroutines.launch -import kr.co.lion.mungnolza.data.repository.BoardRepository -import kr.co.lion.mungnolza.data.repository.UserRepository import kr.co.lion.mungnolza.model.BoardModel import kr.co.lion.mungnolza.model.UserModel -import javax.inject.Inject class ShowDetailBoardViewModel:ViewModel() { 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 5599011..ee8b600 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 @@ -2,6 +2,7 @@ package kr.co.lion.mungnolza.ui.main.fragment import android.content.Intent import android.os.Bundle +import android.util.Log import androidx.fragment.app.Fragment import android.view.LayoutInflater import android.view.View @@ -13,7 +14,9 @@ import androidx.lifecycle.repeatOnLifecycle import androidx.recyclerview.widget.LinearLayoutManager import com.google.android.material.divider.MaterialDividerItemDecoration import kotlinx.coroutines.launch +import kr.co.lion.mungnolza.R import kr.co.lion.mungnolza.databinding.FragmentFreeBoardBinding +import kr.co.lion.mungnolza.ui.freeboard.AddBoardActivity 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 @@ -42,11 +45,11 @@ class FreeBoardFragment : Fragment() { 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) + Log.d("FreeBoardFragment intent 데이터","${selectedItem}") + intent.putExtra("boardData", selectedItemData) startActivity(intent) } ) @@ -54,6 +57,12 @@ class FreeBoardFragment : Fragment() { } } } + + binding.buttonAddBoardFreeBoard.setOnClickListener{ + val intent = Intent(requireContext(), AddBoardActivity::class.java) + startActivity(intent) + } + } private fun setRecyclerViewFreeBoard() { @@ -68,6 +77,4 @@ class FreeBoardFragment : Fragment() { } } - - } \ No newline at end of file diff --git a/MungNolZa/app/src/main/res/layout/activity_add_board.xml b/MungNolZa/app/src/main/res/layout/activity_add_board.xml new file mode 100644 index 0000000..8e72483 --- /dev/null +++ b/MungNolZa/app/src/main/res/layout/activity_add_board.xml @@ -0,0 +1,18 @@ + + + + + \ No newline at end of file diff --git a/MungNolZa/app/src/main/res/layout/activity_board.xml b/MungNolZa/app/src/main/res/layout/activity_board.xml index e79fcd2..ee223e4 100644 --- a/MungNolZa/app/src/main/res/layout/activity_board.xml +++ b/MungNolZa/app/src/main/res/layout/activity_board.xml @@ -11,19 +11,9 @@ android:id="@+id/fragmentContainerFreeBoard" android:layout_width="0dp" android:layout_height="0dp" - app:layout_constraintBottom_toTopOf="@+id/bottomNavigationActivityBoard" - app:layout_constraintEnd_toEndOf="parent" - app:layout_constraintStart_toStartOf="parent" - app:layout_constraintTop_toTopOf="parent" /> - - + app:layout_constraintTop_toTopOf="parent" /> \ No newline at end of file diff --git a/MungNolZa/app/src/main/res/layout/activity_main.xml b/MungNolZa/app/src/main/res/layout/activity_main.xml index d1cb78a..e5a4b77 100644 --- a/MungNolZa/app/src/main/res/layout/activity_main.xml +++ b/MungNolZa/app/src/main/res/layout/activity_main.xml @@ -19,7 +19,7 @@ @@ -79,6 +80,7 @@ android:layout_height="@dimen/edittext_height_board_content" android:background="@color/transparent" android:gravity="start|top" + android:text="@={addBoardViewModel.editTextContentAddBoard}" android:inputType="text|textMultiLine" /> 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 5f3b99a..ac034e1 100644 --- a/MungNolZa/app/src/main/res/layout/fragment_free_board.xml +++ b/MungNolZa/app/src/main/res/layout/fragment_free_board.xml @@ -11,10 +11,9 @@ android:id="@+id/toolbar" android:layout_width="match_parent" 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"/> + app:title="@string/menu_item_bottom_navigation_freeboard" /> + + + + \ No newline at end of file diff --git a/MungNolZa/app/src/main/res/layout/fragment_modify_board.xml b/MungNolZa/app/src/main/res/layout/fragment_modify_board.xml index 31aca9d..4120714 100644 --- a/MungNolZa/app/src/main/res/layout/fragment_modify_board.xml +++ b/MungNolZa/app/src/main/res/layout/fragment_modify_board.xml @@ -74,9 +74,10 @@ + android:gravity="start|top" + android:inputType="text|textMultiLine" /> Date: Wed, 17 Apr 2024 00:29:23 +0900 Subject: [PATCH 2/4] =?UTF-8?q?[#44]=20=EA=B2=8C=EC=8B=9C=ED=8C=90=20?= =?UTF-8?q?=ED=99=94=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 From 288be5907f4c5ad9de6dd8727178f669df7f8a41 Mon Sep 17 00:00:00 2001 From: Jun Date: Wed, 17 Apr 2024 00:41:55 +0900 Subject: [PATCH 3/4] =?UTF-8?q?[#44]=20=EA=B9=83=20=EC=B6=A9=EB=8F=8C=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- MungNolZa/app/src/main/AndroidManifest.xml | 11 ++++------- .../co/lion/mungnolza/datasource/MainDataStore.kt | 3 --- .../mungnolza/repository/user/UserRepository.kt | 4 +--- .../repository/user/UserRepositoryImpl.kt | 3 --- .../freeboard/fragment/ShowDetailBoardFragment.kt | 7 +------ .../ui/main/fragment/FreeBoardFragment.kt | 14 +++----------- 6 files changed, 9 insertions(+), 33 deletions(-) diff --git a/MungNolZa/app/src/main/AndroidManifest.xml b/MungNolZa/app/src/main/AndroidManifest.xml index 0e79e2f..f28a2a8 100644 --- a/MungNolZa/app/src/main/AndroidManifest.xml +++ b/MungNolZa/app/src/main/AndroidManifest.xml @@ -21,16 +21,16 @@ android:theme="@style/Theme.MungNolZa" tools:targetApi="31"> -======= + ->>>>>>> 0e73214e0419402e5d3d00412ff2905432afe7a8 + @@ -64,17 +64,14 @@ >>>>>> 0e73214e0419402e5d3d00412ff2905432afe7a8 android:exported="true" /> >>>>>> 0e73214e0419402e5d3d00412ff2905432afe7a8 object MainDataStore { private fun getContext(): Context = App.context() 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 index a9460d6..52ac17b 100644 --- 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 @@ -5,10 +5,8 @@ import java.net.URI interface UserRepository { suspend fun fetchAllUserData() : List -<<<<<<< HEAD -======= + suspend fun fetchUserAddress(uniqueNumber: String) : String ->>>>>>> 0e73214e0419402e5d3d00412ff2905432afe7a8 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 index f5e8bb5..5e604ec 100644 --- 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 @@ -22,8 +22,6 @@ class UserRepositoryImpl : UserRepository { } } -<<<<<<< HEAD -======= override suspend fun fetchUserAddress(uniqueNumber: String): String { return try { val querySnapshot = userStore.whereEqualTo("uniqueNumber", uniqueNumber).get().await() @@ -35,7 +33,6 @@ class UserRepositoryImpl : UserRepository { } } ->>>>>>> 0e73214e0419402e5d3d00412ff2905432afe7a8 override suspend fun fetchAllUserNickName(uniqueNumber: String): List { return withContext(Dispatchers.IO) { try { 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 458b0bf..82a1dc8 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 @@ -10,7 +10,7 @@ import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import androidx.fragment.app.viewModels -<<<<<<< HEAD + import androidx.lifecycle.lifecycleScope import com.bumptech.glide.Glide import com.google.android.material.carousel.CarouselLayoutManager @@ -23,11 +23,6 @@ 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 com.google.android.material.carousel.CarouselLayoutManager -import com.google.android.material.dialog.MaterialAlertDialogBuilder -import kr.co.lion.mungnolza.R ->>>>>>> 0e73214e0419402e5d3d00412ff2905432afe7a8 import kr.co.lion.mungnolza.databinding.FragmentShowDetailBoardBinding import kr.co.lion.mungnolza.model.BoardModel import kr.co.lion.mungnolza.model.UserModel 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 1327d85..c41e8df 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 @@ -25,11 +25,9 @@ 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() } -<<<<<<< HEAD + private lateinit var freeBoardAdapter: FreeBoardAdapter -======= ->>>>>>> 0e73214e0419402e5d3d00412ff2905432afe7a8 override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) _binding = FragmentFreeBoardBinding.bind(view) @@ -49,13 +47,10 @@ class FreeBoardFragment : Fragment(R.layout.fragment_free_board) { val writerData = viewModel.findUserData(selectedItemData.boardWriterIdx) val intent = Intent(requireContext(), BoardActivity::class.java) -<<<<<<< HEAD + intent.putExtra("boardData", selectedItemData) intent.putExtra("userData", writerData) -======= - intent.putExtra("content", selectedItemData) - intent.putExtra("writer", writerData) ->>>>>>> 0e73214e0419402e5d3d00412ff2905432afe7a8 + startActivity(intent) } @@ -84,8 +79,5 @@ class FreeBoardFragment : Fragment(R.layout.fragment_free_board) { super.onDestroyView() _binding = null } -<<<<<<< HEAD -======= ->>>>>>> 0e73214e0419402e5d3d00412ff2905432afe7a8 } \ No newline at end of file From cfc24456d646ee99eba55247976f534b71825e78 Mon Sep 17 00:00:00 2001 From: Jun Date: Wed, 17 Apr 2024 09:36:33 +0900 Subject: [PATCH 4/4] =?UTF-8?q?[#44]=20=EA=B9=83=20=EC=B6=A9=EB=8F=8C=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= 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 | 10 +- .../fragment/ShowDetailBoardFragment.kt | 9 +- .../co/lion/mungnolza/ui/main/MainActivity.kt | 2 + .../ui/main/fragment/HomeFragment.kt | 5 +- .../petsitter_main/PetsitterMainActivity.kt | 31 +++ .../fragment/PetsitterFreeBoardFragment.kt | 21 ++ .../fragment/PetsitterHomeFragment.kt | 76 +++++++ ...ent.kt => PetsitterReviewWriteActivity.kt} | 65 +++--- .../ReservationListActivity.kt | 3 +- .../fragment/ReservationListLastFragment.kt | 15 +- .../res/layout/activity_petsitter_main.xml | 33 +++ .../activity_petsitter_review_write.xml | 189 ++++++++++++++++++ .../app/src/main/res/layout/fragment_home.xml | 2 +- .../fragment_pet_sitter_review_write.xml | 174 ---------------- .../layout/fragment_petsitter_free_board.xml | 58 ++++++ .../res/layout/fragment_petsitter_home.xml | 82 ++++++++ .../res/layout/fragment_show_detail_board.xml | 32 +-- .../row_petsitter_home_chat_person_list.xml | 23 +++ .../petsitter_bottom_navigation_graph.xml | 18 ++ MungNolZa/app/src/main/res/values/strings.xml | 2 + 21 files changed, 602 insertions(+), 251 deletions(-) create mode 100644 MungNolZa/app/src/main/java/kr/co/lion/mungnolza/ui/petsitter_main/PetsitterMainActivity.kt create mode 100644 MungNolZa/app/src/main/java/kr/co/lion/mungnolza/ui/petsitter_main/fragment/PetsitterFreeBoardFragment.kt create mode 100644 MungNolZa/app/src/main/java/kr/co/lion/mungnolza/ui/petsitter_main/fragment/PetsitterHomeFragment.kt rename MungNolZa/app/src/main/java/kr/co/lion/mungnolza/ui/reservation_list/{fragment/PetSitterReviewWriteFragment.kt => PetsitterReviewWriteActivity.kt} (71%) create mode 100644 MungNolZa/app/src/main/res/layout/activity_petsitter_main.xml create mode 100644 MungNolZa/app/src/main/res/layout/activity_petsitter_review_write.xml delete mode 100644 MungNolZa/app/src/main/res/layout/fragment_pet_sitter_review_write.xml create mode 100644 MungNolZa/app/src/main/res/layout/fragment_petsitter_free_board.xml create mode 100644 MungNolZa/app/src/main/res/layout/fragment_petsitter_home.xml create mode 100644 MungNolZa/app/src/main/res/layout/row_petsitter_home_chat_person_list.xml create mode 100644 MungNolZa/app/src/main/res/navigation/petsitter_bottom_navigation_graph.xml diff --git a/MungNolZa/app/build.gradle.kts b/MungNolZa/app/build.gradle.kts index cad10a7..4c2ec78 100644 --- a/MungNolZa/app/build.gradle.kts +++ b/MungNolZa/app/build.gradle.kts @@ -39,6 +39,7 @@ android { jvmTarget = "1.8" } + viewBinding { enable = true } @@ -46,6 +47,8 @@ android { buildFeatures{ dataBinding = true } + + } dependencies { diff --git a/MungNolZa/app/src/main/AndroidManifest.xml b/MungNolZa/app/src/main/AndroidManifest.xml index f28a2a8..c140409 100644 --- a/MungNolZa/app/src/main/AndroidManifest.xml +++ b/MungNolZa/app/src/main/AndroidManifest.xml @@ -22,8 +22,17 @@ tools:targetApi="31"> + + + + @@ -64,7 +73,6 @@ () - - override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?, @@ -71,10 +69,12 @@ class ShowDetailBoardFragment : Fragment() { lifecycleScope.launch { initData() + } applyUserData() + return binding.root } @@ -115,7 +115,6 @@ class ShowDetailBoardFragment : Fragment() { imgUri = userRepository.fetchUserProfileImage(userData?.userProfileImgPath!!)!! Log.d("프로필 이미지 uri","${imgUri}") - } job1.join() @@ -144,9 +143,9 @@ class ShowDetailBoardFragment : Fragment() { lifecycleScope.launch { - delay(1000) + Log.d("이미지 Uri 리스트 Glide 이전",imgUri.toString()) - Glide.with(requireContext()) + Glide.with(this@ShowDetailBoardFragment) .load(imgUri) .error(R.drawable.eunwoo) .into(binding.imageViewProfileShowDetailBoard) 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 3e2ee41..4fa6b36 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 @@ -18,8 +18,10 @@ class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) + binding = ActivityMainBinding.inflate(layoutInflater) setContentView(binding.root) + initView() } 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 4478cf5..0a5ad11 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 @@ -27,10 +27,7 @@ class HomeFragment : Fragment(), View.OnClickListener { private val binding get() = _binding!! private val viewModel: MainViewModel by activityViewModels { MainViewModelFactory() } private var myPet: List? = null - override fun onCreateView( - inflater: LayoutInflater, container: ViewGroup?, - savedInstanceState: Bundle? - ): View { + override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View { _binding = FragmentHomeBinding.inflate(inflater, container, false) initView() return binding.root diff --git a/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/ui/petsitter_main/PetsitterMainActivity.kt b/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/ui/petsitter_main/PetsitterMainActivity.kt new file mode 100644 index 0000000..513512d --- /dev/null +++ b/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/ui/petsitter_main/PetsitterMainActivity.kt @@ -0,0 +1,31 @@ +package kr.co.lion.mungnolza.ui.petsitter_main + +import android.os.Build +import androidx.appcompat.app.AppCompatActivity +import android.os.Bundle +import androidx.navigation.fragment.NavHostFragment +import androidx.navigation.ui.NavigationUI +import kr.co.lion.mungnolza.R +import kr.co.lion.mungnolza.databinding.ActivityPetsitterMainBinding +import kr.co.lion.mungnolza.model.PetImgModel + +class PetsitterMainActivity : AppCompatActivity() { + + private lateinit var activityPetsitterMainBinding: ActivityPetsitterMainBinding + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + + activityPetsitterMainBinding = ActivityPetsitterMainBinding.inflate(layoutInflater) + setContentView(activityPetsitterMainBinding.root) + + initView() + } + + private fun initView(){ + val navHostFragment = supportFragmentManager.findFragmentById(R.id.fragment_container_petsitter) as NavHostFragment + val navController = navHostFragment.navController + NavigationUI.setupWithNavController(activityPetsitterMainBinding.navigationView, navController) + + } +} \ No newline at end of file diff --git a/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/ui/petsitter_main/fragment/PetsitterFreeBoardFragment.kt b/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/ui/petsitter_main/fragment/PetsitterFreeBoardFragment.kt new file mode 100644 index 0000000..65d0346 --- /dev/null +++ b/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/ui/petsitter_main/fragment/PetsitterFreeBoardFragment.kt @@ -0,0 +1,21 @@ +package kr.co.lion.mungnolza.ui.petsitter_main.fragment + +import android.os.Bundle +import androidx.fragment.app.Fragment +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import kr.co.lion.mungnolza.R +import kr.co.lion.mungnolza.databinding.FragmentPetsitterFreeBoardBinding + +class PetsitterFreeBoardFragment : Fragment() { + + lateinit var fragmentPetsitterFreeBoardBinding: FragmentPetsitterFreeBoardBinding + + override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { + // Inflate the layout for this fragment + fragmentPetsitterFreeBoardBinding = FragmentPetsitterFreeBoardBinding.inflate(inflater, container, false) + + return fragmentPetsitterFreeBoardBinding.root + } +} \ No newline at end of file diff --git a/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/ui/petsitter_main/fragment/PetsitterHomeFragment.kt b/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/ui/petsitter_main/fragment/PetsitterHomeFragment.kt new file mode 100644 index 0000000..797de33 --- /dev/null +++ b/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/ui/petsitter_main/fragment/PetsitterHomeFragment.kt @@ -0,0 +1,76 @@ +package kr.co.lion.mungnolza.ui.petsitter_main.fragment + +import android.os.Bundle +import androidx.fragment.app.Fragment +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import androidx.recyclerview.widget.LinearLayoutManager +import androidx.recyclerview.widget.RecyclerView +import com.google.android.material.divider.MaterialDividerItemDecoration +import kr.co.lion.mungnolza.R +import kr.co.lion.mungnolza.databinding.FragmentPetsitterHomeBinding +import kr.co.lion.mungnolza.databinding.RowPetsitterHomeChatPersonListBinding + +class PetsitterHomeFragment : Fragment() { + + lateinit var fragmentPetsitterHomeBinding : FragmentPetsitterHomeBinding + + override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { + // Inflate the layout for this fragment + fragmentPetsitterHomeBinding = FragmentPetsitterHomeBinding.inflate(inflater, container, false) + + return fragmentPetsitterHomeBinding.root + } + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + setRecyclerView() + } + + // RecyclerView 설정 + fun setRecyclerView(){ + fragmentPetsitterHomeBinding.apply { + recyclerViewPetsitterHomeChatList.apply { + // 어뎁터 설정 + adapter = RecyclerMainAdapter() + // 레이아웃 + layoutManager = LinearLayoutManager(requireContext(), LinearLayoutManager.HORIZONTAL, false) + // 데코 + //val deco = MaterialDividerItemDecoration(requireContext(), MaterialDividerItemDecoration.HORIZONTAL) + //addItemDecoration(deco) + } + } + } + + // RecyclerView의 어뎁터 + inner class RecyclerMainAdapter : RecyclerView.Adapter(){ + inner class RecyclerMainViewHolder(rowPetsitterHomeChatPersonListBinding: RowPetsitterHomeChatPersonListBinding) : RecyclerView.ViewHolder(rowPetsitterHomeChatPersonListBinding.root){ + val rowPetsitterHomeChatPersonListBinding : RowPetsitterHomeChatPersonListBinding + + init { + this.rowPetsitterHomeChatPersonListBinding = rowPetsitterHomeChatPersonListBinding + this.rowPetsitterHomeChatPersonListBinding.root.layoutParams = ViewGroup.LayoutParams( + ViewGroup.LayoutParams.WRAP_CONTENT, + ViewGroup.LayoutParams.MATCH_PARENT + ) + } + } + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerMainViewHolder { + val rowPetsitterHomeChatPersonListBinding = RowPetsitterHomeChatPersonListBinding.inflate(layoutInflater, parent, false) + val recyclerMainViewHolder = RecyclerMainViewHolder(rowPetsitterHomeChatPersonListBinding) + + return recyclerMainViewHolder + } + + override fun getItemCount(): Int { + return 10 + } + + override fun onBindViewHolder(holder: RecyclerMainViewHolder, position: Int) { + holder.rowPetsitterHomeChatPersonListBinding.imageViewRowPetsitterHomeChatListPerson.setImageResource(R.drawable.eunwoo) + holder.rowPetsitterHomeChatPersonListBinding.textViewRowPetsitterHomeChatListPersonName.text = "영준" + } + } +} \ No newline at end of file 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/PetsitterReviewWriteActivity.kt similarity index 71% rename from MungNolZa/app/src/main/java/kr/co/lion/mungnolza/ui/reservation_list/fragment/PetSitterReviewWriteFragment.kt rename to MungNolZa/app/src/main/java/kr/co/lion/mungnolza/ui/reservation_list/PetsitterReviewWriteActivity.kt index fa90b38..090356b 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/PetsitterReviewWriteActivity.kt @@ -1,20 +1,20 @@ -package kr.co.lion.mungnolza.ui.reservation_list.fragment +package kr.co.lion.mungnolza.ui.reservation_list import android.content.DialogInterface +import androidx.appcompat.app.AppCompatActivity import android.os.Bundle import android.util.Log -import androidx.fragment.app.Fragment -import android.view.LayoutInflater -import android.view.View -import android.view.ViewGroup import com.google.android.material.dialog.MaterialAlertDialogBuilder import kotlinx.coroutines.CoroutineScope 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.databinding.FragmentPetSitterReviewWriteBinding + +import kr.co.lion.mungnolza.databinding.ActivityPetsitterReviewWriteBinding +import kr.co.lion.mungnolza.ext.hideSoftInput +import kr.co.lion.mungnolza.ext.showErrorDialog import kr.co.lion.mungnolza.model.PetsitterReviewModel + import kr.co.lion.mungnolza.ui.reservation_list.viewmodel.PetSitterReviewWriteViewModel import kr.co.lion.mungnolza.util.ReservationListFragmentName import java.text.SimpleDateFormat @@ -24,53 +24,34 @@ import kr.co.lion.mungnolza.ext.hideSoftInput import kr.co.lion.mungnolza.ext.showErrorDialog import kr.co.lion.mungnolza.repository.PetsitterReviewRepository -class PetSitterReviewWriteFragment : Fragment() { +class PetsitterReviewWriteActivity : AppCompatActivity() { - lateinit var fragmentPetSitterReviewWriteBinding: FragmentPetSitterReviewWriteBinding - lateinit var reservationListActivity: ReservationListActivity + lateinit var activityPetsitterReviewWriteBinding: ActivityPetsitterReviewWriteBinding lateinit var petSitterReviewWriteViewModel : PetSitterReviewWriteViewModel - override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { - // Inflate the layout for this fragment + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) - fragmentPetSitterReviewWriteBinding = FragmentPetSitterReviewWriteBinding.inflate(layoutInflater) - reservationListActivity = activity as ReservationListActivity + activityPetsitterReviewWriteBinding = ActivityPetsitterReviewWriteBinding.inflate(layoutInflater) + setContentView(activityPetsitterReviewWriteBinding.root) // ViewModel 객체를 생성한다. petSitterReviewWriteViewModel = PetSitterReviewWriteViewModel() // 생성한 ViewModel 객체를 layout 파일에 설정해준다. - fragmentPetSitterReviewWriteBinding.petSitterReviewWriteViewModel = petSitterReviewWriteViewModel + activityPetsitterReviewWriteBinding.petSitterReviewWriteViewModel = petSitterReviewWriteViewModel // ViewModel의 생명주기를 Fragment와 일치시킨다. Fragment가 살아 있을 때 ViewModel 객체도 살아 있게끔 해준다. - fragmentPetSitterReviewWriteBinding.lifecycleOwner = this + activityPetsitterReviewWriteBinding.lifecycleOwner = this - - setToolbar() setButtonDone() setTextField() initData() - - return fragmentPetSitterReviewWriteBinding.root - } - - // 툴바 설정 - fun setToolbar(){ - fragmentPetSitterReviewWriteBinding.apply { - toolbarPetSitterReviewWrite.apply { - // 뒤로가기 - setNavigationIcon(R.drawable.ic_arrow_back_24px) - setNavigationOnClickListener { - // PetSitterReviewWriteFragment를 사라지게 한다. - reservationListActivity.removeFragment(ReservationListFragmentName.PETSITTER_REVIEW_WRITE_FRAGMENT) - } - } - } } // 작성 완료 버튼 (이벤트 설정) fun setButtonDone(){ // buttonPetsitterReviewWriteDone 작성완료 버튼 설정 - fragmentPetSitterReviewWriteBinding.apply { + activityPetsitterReviewWriteBinding.apply { buttonPetsitterReviewWriteDone.apply { // 버튼을 눌럿을 때 setOnClickListener { @@ -84,10 +65,10 @@ class PetSitterReviewWriteFragment : Fragment() { savePetsitterReviewData() // 키보드를 내려준다 - context.hideSoftInput(reservationListActivity) + context.hideSoftInput(this@PetsitterReviewWriteActivity) // 작성완료 다이어로그를 띄운다 - val materialAlertDialogBuilder = MaterialAlertDialogBuilder(reservationListActivity) + val materialAlertDialogBuilder = MaterialAlertDialogBuilder(this@PetsitterReviewWriteActivity) materialAlertDialogBuilder.setTitle("작성 완료") materialAlertDialogBuilder.setMessage("후기 작성이 완료되었습니다 !") materialAlertDialogBuilder.setPositiveButton("확인"){ dialogInterface: DialogInterface, i: Int -> @@ -101,7 +82,7 @@ class PetSitterReviewWriteFragment : Fragment() { } // 데잍 - fun savePetsitterReviewData() { + fun savePetsitterReviewData() { CoroutineScope(Dispatchers.Main).launch { // 펫시터 후기 번호 시퀀스 값을 가져온다. val reviewIdxSequence = PetsitterReviewRepository.getReviewIdx() @@ -136,7 +117,7 @@ class PetSitterReviewWriteFragment : Fragment() { // 별점수를 입력하지 않았다면 if(starCount == 0f){ // 다이어로그 띄워준다 - showErrorDialog(reservationListActivity, fragmentPetSitterReviewWriteBinding.ratingBar2, "별점 입력 오류", "펫시터에게 별점을 남겨주세요.") + showErrorDialog(this@PetsitterReviewWriteActivity, activityPetsitterReviewWriteBinding.ratingBar2, "별점 입력 오류", "펫시터에게 별점을 남겨주세요.") return false } @@ -144,7 +125,7 @@ class PetSitterReviewWriteFragment : Fragment() { if(reviewText.isEmpty()){ // 다이어로그 띄워준다 // 다이어로그의 확인 클릭시, 뷰에 포커스를 주고 키보드를 올린다. - showErrorDialog(reservationListActivity, fragmentPetSitterReviewWriteBinding.textfieldPetsitterReviewWrite, "후기 작성 오류", "펫시터에게 후기를 작성해주세요.") + showErrorDialog(this@PetsitterReviewWriteActivity, activityPetsitterReviewWriteBinding.textfieldPetsitterReviewWrite, "후기 작성 오류", "펫시터에게 후기를 작성해주세요.") return false } return true @@ -157,9 +138,10 @@ class PetSitterReviewWriteFragment : Fragment() { petSitterReviewWriteViewModel.textfieldPetsitterReviewWrite.value = "" } + // 임시 가짜 데이터 셋팅 fun initData(){ - fragmentPetSitterReviewWriteBinding.apply { + activityPetsitterReviewWriteBinding.apply { imageViewPetSitterReviewWrite.setImageResource(R.drawable.petsitter) textViewPetSitterReviewWriteName.setText("이영주 펫시터") textViewPetSitterReviewWriteScore.setText("5점") @@ -167,4 +149,5 @@ class PetSitterReviewWriteFragment : Fragment() { textViewPetSitterReviewWriteCountReview.setText("89개의 후기") } } + } \ No newline at end of file diff --git a/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/ui/reservation_list/ReservationListActivity.kt b/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/ui/reservation_list/ReservationListActivity.kt index 94f18db..faa37d0 100644 --- a/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/ui/reservation_list/ReservationListActivity.kt +++ b/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/ui/reservation_list/ReservationListActivity.kt @@ -6,7 +6,6 @@ import android.os.SystemClock import androidx.fragment.app.Fragment import androidx.fragment.app.FragmentManager import com.google.android.material.transition.MaterialSharedAxis -import kr.co.lion.mungnolza.ui.reservation_list.fragment.PetSitterReviewWriteFragment import kr.co.lion.mungnolza.ui.main.fragment.ReservationListFragment import kr.co.lion.mungnolza.R import kr.co.lion.mungnolza.databinding.ActivityReservationListBinding @@ -55,7 +54,7 @@ class ReservationListActivity : AppCompatActivity() { } // 펫시터 후기 작성 화면 프래그먼트 ReservationListFragmentName.PETSITTER_REVIEW_WRITE_FRAGMENT -> { - newFragment = PetSitterReviewWriteFragment() + /*newFragment = PetSitterReviewWriteFragment()*/ } } diff --git a/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/ui/reservation_list/fragment/ReservationListLastFragment.kt b/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/ui/reservation_list/fragment/ReservationListLastFragment.kt index 648fc21..4482b88 100644 --- a/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/ui/reservation_list/fragment/ReservationListLastFragment.kt +++ b/MungNolZa/app/src/main/java/kr/co/lion/mungnolza/ui/reservation_list/fragment/ReservationListLastFragment.kt @@ -1,5 +1,6 @@ package kr.co.lion.mungnolza.ui.reservation_list.fragment +import android.content.Intent import android.os.Bundle import androidx.fragment.app.Fragment import android.view.LayoutInflater @@ -12,19 +13,17 @@ import kr.co.lion.mungnolza.R import kr.co.lion.mungnolza.ui.reservation_list.ReservationListActivity import kr.co.lion.mungnolza.databinding.FragmentReservationListLastBinding import kr.co.lion.mungnolza.databinding.RowReservationListLastBinding +import kr.co.lion.mungnolza.ui.reservation_list.PetsitterReviewWriteActivity import kr.co.lion.mungnolza.util.ReservationListFragmentName class ReservationListLastFragment : Fragment() { lateinit var fragmentReservationListLastBinding : FragmentReservationListLastBinding - //lateinit var reservationListActivity: ReservationListActivity - override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { // Inflate the layout for this fragment fragmentReservationListLastBinding = FragmentReservationListLastBinding.inflate(layoutInflater) - //reservationListActivity = activity as ReservationListActivity return fragmentReservationListLastBinding.root } @@ -94,13 +93,15 @@ class ReservationListLastFragment : Fragment() { // '후기작성' 항목을 누르면 동작하는 리스너 holder.rowReservationListLastBinding.textViewRowReservationiListLastWriteReview.setOnClickListener { - // PetSitterReviewWriteFragment가 보여진다 - (requireActivity() as ReservationListActivity).replaceFragment(ReservationListFragmentName.PETSITTER_REVIEW_WRITE_FRAGMENT, true, true, null) + // PetsitterReviewWriteActivity가 보여진다 + val intent = Intent(context, PetsitterReviewWriteActivity::class.java) + startActivity(intent) } // '후기작성' 아이콘 항목을 누르면 동작하는 리스너 holder.rowReservationListLastBinding.imageViewRowReservationListLastEdit.setOnClickListener { - // PetSitterReviewWriteFragment가 보여진다 - (requireActivity() as ReservationListActivity).replaceFragment(ReservationListFragmentName.PETSITTER_REVIEW_WRITE_FRAGMENT, true, true, null) + // PetsitterReviewWriteActivity가 보여진다 + val intent = Intent(context, PetsitterReviewWriteActivity::class.java) + startActivity(intent) } } } diff --git a/MungNolZa/app/src/main/res/layout/activity_petsitter_main.xml b/MungNolZa/app/src/main/res/layout/activity_petsitter_main.xml new file mode 100644 index 0000000..e900608 --- /dev/null +++ b/MungNolZa/app/src/main/res/layout/activity_petsitter_main.xml @@ -0,0 +1,33 @@ + + + + + + + + + diff --git a/MungNolZa/app/src/main/res/layout/activity_petsitter_review_write.xml b/MungNolZa/app/src/main/res/layout/activity_petsitter_review_write.xml new file mode 100644 index 0000000..2ec29f7 --- /dev/null +++ b/MungNolZa/app/src/main/res/layout/activity_petsitter_review_write.xml @@ -0,0 +1,189 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ 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 ab03256..8967344 100644 --- a/MungNolZa/app/src/main/res/layout/fragment_home.xml +++ b/MungNolZa/app/src/main/res/layout/fragment_home.xml @@ -6,7 +6,7 @@ android:orientation="vertical"> diff --git a/MungNolZa/app/src/main/res/layout/fragment_pet_sitter_review_write.xml b/MungNolZa/app/src/main/res/layout/fragment_pet_sitter_review_write.xml deleted file mode 100644 index 84a3f6d..0000000 --- a/MungNolZa/app/src/main/res/layout/fragment_pet_sitter_review_write.xml +++ /dev/null @@ -1,174 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/MungNolZa/app/src/main/res/layout/fragment_petsitter_free_board.xml b/MungNolZa/app/src/main/res/layout/fragment_petsitter_free_board.xml new file mode 100644 index 0000000..d49b44b --- /dev/null +++ b/MungNolZa/app/src/main/res/layout/fragment_petsitter_free_board.xml @@ -0,0 +1,58 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/MungNolZa/app/src/main/res/layout/fragment_petsitter_home.xml b/MungNolZa/app/src/main/res/layout/fragment_petsitter_home.xml new file mode 100644 index 0000000..1a7ce12 --- /dev/null +++ b/MungNolZa/app/src/main/res/layout/fragment_petsitter_home.xml @@ -0,0 +1,82 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/MungNolZa/app/src/main/res/layout/fragment_show_detail_board.xml b/MungNolZa/app/src/main/res/layout/fragment_show_detail_board.xml index 6c55a4b..5bd4959 100644 --- a/MungNolZa/app/src/main/res/layout/fragment_show_detail_board.xml +++ b/MungNolZa/app/src/main/res/layout/fragment_show_detail_board.xml @@ -60,11 +60,14 @@ android:orientation="horizontal" android:padding="@dimen/profile_layout_padding"> - + android:layout_height="@dimen/profile_imageview_width" + app:civ_border_width="1dp" + tools:srcCompat="@tools:sample/avatars" /> + + + android:layout_height="wrap_content"> + android:layout_height="wrap_content"> - - @@ -175,6 +169,12 @@ app:srcCompat="@drawable/ic_comment_24px" /> + + diff --git a/MungNolZa/app/src/main/res/layout/row_petsitter_home_chat_person_list.xml b/MungNolZa/app/src/main/res/layout/row_petsitter_home_chat_person_list.xml new file mode 100644 index 0000000..d4ab23f --- /dev/null +++ b/MungNolZa/app/src/main/res/layout/row_petsitter_home_chat_person_list.xml @@ -0,0 +1,23 @@ + + + + + + + \ No newline at end of file diff --git a/MungNolZa/app/src/main/res/navigation/petsitter_bottom_navigation_graph.xml b/MungNolZa/app/src/main/res/navigation/petsitter_bottom_navigation_graph.xml new file mode 100644 index 0000000..7036439 --- /dev/null +++ b/MungNolZa/app/src/main/res/navigation/petsitter_bottom_navigation_graph.xml @@ -0,0 +1,18 @@ + + + + + + \ No newline at end of file diff --git a/MungNolZa/app/src/main/res/values/strings.xml b/MungNolZa/app/src/main/res/values/strings.xml index 5622c71..66a0844 100644 --- a/MungNolZa/app/src/main/res/values/strings.xml +++ b/MungNolZa/app/src/main/res/values/strings.xml @@ -92,5 +92,7 @@ 예약 목록 보기 전체 보기 예약이 완료되었어요 + + Hello blank fragment \ No newline at end of file