From ae94ff052ea71a27d1cbdb78a37e2239a38ac398 Mon Sep 17 00:00:00 2001 From: Jun Date: Tue, 16 Apr 2024 15:17:43 +0900 Subject: [PATCH] =?UTF-8?q?[#44]=20=EC=A4=91=EA=B0=84=20=EC=BB=A4=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" />