Skip to content

Commit

Permalink
Merge pull request #42 from APP-Android2/30-feature-자유게시판구현
Browse files Browse the repository at this point in the history
30 feature 자유게시판구현
  • Loading branch information
ayz1070 authored Apr 12, 2024
2 parents 654df68 + ca60903 commit e387f3d
Show file tree
Hide file tree
Showing 14 changed files with 236 additions and 50 deletions.
7 changes: 2 additions & 5 deletions MungNolZa/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
tools:targetApi="31">
<activity
android:name=".ui.TestActivity"
android:exported="true"/>
android:exported="true" />

<activity
android:name=".ui.dialog.DialogSampleActivity"
android:exported="true" />
Expand Down Expand Up @@ -53,11 +54,7 @@
<activity
android:name=".ui.intro.activity.StartActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".ui.intro.activity.OnBoardingActivity"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package kr.co.lion.mungnolza.data.repository

import kr.co.lion.mungnolza.model.BoardModel


interface BoardRepository {
suspend fun getBoardData(boardIdx: Int): BoardModel?
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
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.BoardModel
import kr.co.lion.mungnolza.model.UserModel

class BoardRepositoryImpl : BoardRepository{

override suspend fun getBoardData(boardIdx: Int): BoardModel? {
var boardModel: BoardModel? = null

val job = CoroutineScope(Dispatchers.IO).launch {
val collectionReference = Firebase.firestore.collection("Board")
val querySnapshot =
collectionReference.whereEqualTo("boardIdx", boardIdx).get().await()

if (querySnapshot.isEmpty == false) {
boardModel = querySnapshot.documents[0].toObject(BoardModel::class.java)
}
}
return boardModel
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package kr.co.lion.mungnolza.data.repository

import kr.co.lion.mungnolza.model.UserModel

interface UserRepository {
suspend fun getUserData(uniqueNumber:Int): UserModel?
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
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
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package kr.co.lion.mungnolza.model

import android.os.Parcelable

import kotlinx.parcelize.Parcelize

@Parcelize
data class BoardModel(
var boardIdx: Int,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
package kr.co.lion.mungnolza.model

class CommentModel {
}
data class CommentModel(
var commentIdx:Int,
var commentContent:String,
var commentDate:String,
var boardIdx:Int,
var writerIdx:Int,
var commentState:Int
)
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import androidx.fragment.app.FragmentManager
import com.google.android.material.transition.MaterialSharedAxis
import kr.co.lion.mungnolza.R
import kr.co.lion.mungnolza.databinding.ActivityBoardBinding
import kr.co.lion.mungnolza.model.BoardModel
import kr.co.lion.mungnolza.model.UserModel
import kr.co.lion.mungnolza.ui.freeboard.fragment.AddBoardFragment
import kr.co.lion.mungnolza.ui.main.fragment.FreeBoardFragment
import kr.co.lion.mungnolza.ui.freeboard.fragment.ModifyBoardFragment
Expand All @@ -21,11 +23,13 @@ class BoardActivity : AppCompatActivity() {
var oldFragment: Fragment? = null
var newFragment: Fragment? = null



override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityBoardBinding.inflate(layoutInflater)

replaceFragment(BoardFragmentName.FREE_BOARD_FRAGMENT,false,false,null)
replaceFragment(BoardFragmentName.SHOW_DETAIL_BOARD_FRAGMENT,false,false,null)

setContentView(binding.root)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package kr.co.lion.mungnolza.ui.freeboard.adapter

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<BoardCarouselViewHolder>() {

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): BoardCarouselViewHolder {
return BoardCarouselViewHolder(RowShowDetailBoardBinding.inflate(LayoutInflater.from(parent.context),parent, false))
}

// override fun getItemCount(): Int = itemList.size
override fun getItemCount(): Int = 10

override fun onBindViewHolder(holder: BoardCarouselViewHolder, position: Int) {
holder.bind()
//holder.bind(itemList[position])
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package kr.co.lion.mungnolza.ui.freeboard.adapter

import androidx.recyclerview.widget.RecyclerView
import kr.co.lion.mungnolza.R
import kr.co.lion.mungnolza.databinding.RowShowDetailBoardBinding

class BoardCarouselViewHolder(
private val binding:RowShowDetailBoardBinding
) :RecyclerView.ViewHolder(binding.root) {

fun bind(){
itemView.apply{
binding.imageViewCarouselShowDetailBoard.setImageResource(R.drawable.img_dog)
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package kr.co.lion.mungnolza.ui.freeboard.factory

import androidx.lifecycle.ViewModelProvider

class ShowDetailBoardViewModelFactory : ViewModelProvider.Factory{

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,49 +9,98 @@ 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.util.BoardFragmentName


class ShowDetailBoardFragment : Fragment() {

lateinit var binding: FragmentShowDetailBoardBinding
private var _binding: FragmentShowDetailBoardBinding?= null
private val binding get() = _binding!!

lateinit var boardActivity: BoardActivity

lateinit var showDetailBoardViewModel: ShowDetailBoardViewModel
private val showDetailBoardViewModel by viewModels<ShowDetailBoardViewModel>()

var userModel: UserModel?= null
var boardModel: BoardModel?= null

var imagePathList = mutableListOf<String>()


var boardIdx:Int = 0

override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?,
): View? {
binding = DataBindingUtil.inflate(inflater,
R.layout.fragment_show_detail_board,container,false)
showDetailBoardViewModel = ShowDetailBoardViewModel()
binding.showDetailBoardViewModel = showDetailBoardViewModel
binding.lifecycleOwner = this
_binding = FragmentShowDetailBoardBinding.inflate(layoutInflater)

boardActivity = activity as BoardActivity

boardIdx = arguments?.getInt("boardIdx")!!
setTest()

applyUserData()

// boardIdx = arguments?.getInt("boardIdx")!!

return binding.root
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

setToolbar()
setCarousel()
setCommentButton()

return binding.root
}

override fun onDestroy() {
_binding = null
super.onDestroy()
}

// ----------------------------------------------------------------------------

fun setTest(){

}

fun applyUserData(){
binding.editTextTitleShowDetailBoard.setText(showDetailBoardViewModel.getBoardData().boardTitle)
binding.editTextContentShowDetailBoard.setText(showDetailBoardViewModel.getBoardData().boardContent)
binding.textViewDateShowDetailBoard.text = showDetailBoardViewModel.getBoardData().boardWriteDate

// 유저 정보는 boardModel로 접근해야 하는데 테스트는 일단 직접 호출
binding.textViewNickNameShowDetailBoard.text = showDetailBoardViewModel.getUserData().userNickname

}


fun setCommentButton(){
binding.apply{
imageViewCommentShowDetailBoard.setOnClickListener {
Expand All @@ -65,7 +114,7 @@ class ShowDetailBoardFragment : Fragment() {
// RecyclerView 셋팅
recyclerViewPhotosShowDetailBoard.apply{
// 어댑터
adapter = RecyclerViewAdapterShowDetailBoard()
adapter = BoardCarouselAdapter()
// 레이아웃 매니저
layoutManager = CarouselLayoutManager()
// layoutManager = CarouselLayoutManager(MultiBrowseCarouselStrategy())
Expand Down Expand Up @@ -132,25 +181,25 @@ class ShowDetailBoardFragment : Fragment() {
bottomCommentFragment.show(boardActivity.supportFragmentManager, "BottomCommentSheet")
}

inner class RecyclerViewAdapterShowDetailBoard: RecyclerView.Adapter<RecyclerViewAdapterShowDetailBoard.ViewHolderShowDetailBoard>() {
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)
}
}
// inner class RecyclerViewAdapterShowDetailBoard: RecyclerView.Adapter<RecyclerViewAdapterShowDetailBoard.ViewHolderShowDetailBoard>() {
// 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)
// }
// }
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,24 @@
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() {

fun getUserData():UserModel{
return UserModel("1","카리나","최나연","[email protected]","010-2222-3333","송파에서 제일 비싼 집","","22","")
}

fun getBoardData():BoardModel{
return BoardModel(1,"카리나 어때?","나보다 별로지 않아?\nㅇㅅㅇ",
mutableListOf(),"1","2024-04-12-10:30","2024-04-12-10:48",2,1)
}


}
Loading

0 comments on commit e387f3d

Please sign in to comment.