-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #39 from APP-Android2/36-feature-메인-화면-자유-게시판
[#36] feature 메인 화면 자유 게시판
- Loading branch information
Showing
28 changed files
with
476 additions
and
311 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
MungNolZa/app/src/main/java/kr/co/lion/mungnolza/model/BoardAddUerInfoModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package kr.co.lion.mungnolza.model | ||
|
||
import android.net.Uri | ||
|
||
data class BoardAddUerInfoModel ( | ||
val contentData: BoardModel, | ||
val writerNickName: String, | ||
val imgUri: Uri | ||
) |
33 changes: 24 additions & 9 deletions
33
MungNolZa/app/src/main/java/kr/co/lion/mungnolza/model/BoardModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,28 @@ | ||
package kr.co.lion.mungnolza.model | ||
|
||
import android.os.Parcelable | ||
import kotlinx.parcelize.Parcelize | ||
@Parcelize | ||
data class BoardModel( | ||
var boardIdx:Int, | ||
var boardTitle:String, | ||
var boardType:Int, | ||
var boardImageList:MutableList<String?>, | ||
var boardWriterIdx:Int, | ||
var boardWriteDate:String, | ||
var boardState:Int | ||
){ | ||
constructor():this(0, "", 0, mutableListOf(), 0, "", 0) | ||
var boardIdx: Int, | ||
var boardTitle: String, | ||
var boardContent: String, | ||
var boardImagePathList: MutableList<String?>, | ||
var boardWriterIdx: String, | ||
var boardWriteDate: String, | ||
var boardModifyDate: String, | ||
var boardLikeNumber: Int, | ||
var boardState: Int | ||
): Parcelable{ | ||
constructor() : this( | ||
boardIdx = 0, | ||
boardTitle = "", | ||
boardContent= "", | ||
boardImagePathList = mutableListOf(), | ||
boardWriterIdx = "", | ||
boardWriteDate = "", | ||
boardModifyDate = "", | ||
boardLikeNumber = 0, | ||
boardState = 0 | ||
) | ||
} |
28 changes: 22 additions & 6 deletions
28
MungNolZa/app/src/main/java/kr/co/lion/mungnolza/model/UserModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,25 @@ | ||
package kr.co.lion.mungnolza.model | ||
|
||
data class UserModel( | ||
var userIdx:Int, | ||
var userId:String, | ||
var userPw:String, | ||
var userNickName:String, | ||
var userState:Int | ||
) | ||
var uniqueNumber: String, | ||
var userNickname: String, | ||
var userName: String, | ||
var userEmail: String, | ||
var userPhone: String, | ||
var userAddress: String, | ||
var userProfileImgPath: String, | ||
var userAgeRange : String, | ||
var userGender: String | ||
){ | ||
constructor(): this( | ||
uniqueNumber = "", | ||
userNickname = "", | ||
userName = "", | ||
userEmail = "", | ||
userPhone = "", | ||
userAddress = "", | ||
userProfileImgPath = "", | ||
userAgeRange = "", | ||
userGender = "" | ||
) | ||
} |
9 changes: 9 additions & 0 deletions
9
MungNolZa/app/src/main/java/kr/co/lion/mungnolza/repository/FreeBoardRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package kr.co.lion.mungnolza.repository | ||
|
||
import android.net.Uri | ||
import kr.co.lion.mungnolza.model.BoardModel | ||
|
||
interface FreeBoardRepository { | ||
suspend fun fetchAllBoardData(): ArrayList<BoardModel> | ||
suspend fun fetchAllBoardImage(boardIdx: String, imgName: String): Uri? | ||
} |
49 changes: 49 additions & 0 deletions
49
MungNolZa/app/src/main/java/kr/co/lion/mungnolza/repository/FreeBoardRepositoryImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package kr.co.lion.mungnolza.repository | ||
|
||
import android.net.Uri | ||
import android.util.Log | ||
import com.google.firebase.Firebase | ||
import com.google.firebase.firestore.FirebaseFirestore | ||
import com.google.firebase.firestore.Query | ||
import com.google.firebase.firestore.firestore | ||
import com.google.firebase.storage.StorageReference | ||
import com.google.firebase.storage.storage | ||
import kotlinx.coroutines.tasks.await | ||
import kr.co.lion.mungnolza.model.BoardModel | ||
import kr.co.lion.mungnolza.util.ContentState | ||
|
||
class FreeBoardRepositoryImpl : FreeBoardRepository { | ||
private val boardStore = Firebase.firestore.collection("Board") | ||
private val storage = Firebase.storage.reference | ||
override suspend fun fetchAllBoardData(): ArrayList<BoardModel> { | ||
val boardList = ArrayList<BoardModel>() | ||
|
||
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 | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
MungNolZa/app/src/main/java/kr/co/lion/mungnolza/repository/UserRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
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 | ||
} |
32 changes: 32 additions & 0 deletions
32
MungNolZa/app/src/main/java/kr/co/lion/mungnolza/repository/UserRepositoryImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
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() | ||
} | ||
|
||
} |
6 changes: 0 additions & 6 deletions
6
...NolZa/app/src/main/java/kr/co/lion/mungnolza/ui/freeboard/viewmodel/FreeBoardViewModel.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
MungNolZa/app/src/main/java/kr/co/lion/mungnolza/ui/main/adapter/FreeBoardAdapter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package kr.co.lion.mungnolza.ui.main.adapter | ||
|
||
import android.view.LayoutInflater | ||
import android.view.ViewGroup | ||
import androidx.recyclerview.widget.RecyclerView | ||
import com.bumptech.glide.Glide | ||
import kr.co.lion.mungnolza.databinding.RowFreeBoardBinding | ||
import kr.co.lion.mungnolza.model.BoardAddUerInfoModel | ||
|
||
class FreeBoardAdapter( | ||
private val dataSet: List<BoardAddUerInfoModel>, | ||
private val onClick: (Int) -> Unit | ||
) : RecyclerView.Adapter<FreeBoardAdapter.FreeBoardAdapterViewHolder>() { | ||
class FreeBoardAdapterViewHolder( | ||
private val binding: RowFreeBoardBinding, private val onClick: (Int) -> Unit | ||
) : RecyclerView.ViewHolder(binding.root) { | ||
fun bind(item: BoardAddUerInfoModel) { | ||
with(binding) { | ||
tvTitle.text = item.contentData.boardTitle | ||
tvContent.text = "${item.contentData.boardContent.substring(0, 20)}..." | ||
tvLike.text = item.contentData.boardLikeNumber.toString() | ||
tvDate.text = item.contentData.boardWriteDate | ||
tvNickname.text = item.writerNickName | ||
|
||
Glide.with(binding.root) | ||
.load(item.imgUri) | ||
.into(thumbnail) | ||
|
||
root.setOnClickListener { | ||
onClick.invoke(item.contentData.boardIdx) | ||
} | ||
} | ||
} | ||
} | ||
|
||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): FreeBoardAdapterViewHolder { | ||
val inflater = LayoutInflater.from(parent.context) | ||
|
||
return FreeBoardAdapterViewHolder( | ||
RowFreeBoardBinding.inflate(inflater, parent, false), | ||
onClick | ||
) | ||
} | ||
|
||
override fun getItemCount() = dataSet.size | ||
|
||
override fun onBindViewHolder(holder: FreeBoardAdapterViewHolder, position: Int) { | ||
holder.bind(dataSet[position]) | ||
} | ||
} |
Oops, something went wrong.