Skip to content

Commit

Permalink
Merge pull request #39 from APP-Android2/36-feature-메인-화면-자유-게시판
Browse files Browse the repository at this point in the history
[#36] feature 메인 화면 자유 게시판
  • Loading branch information
chanho0908 authored Apr 12, 2024
2 parents 5e4fe0d + eaff8ea commit 68cb83f
Show file tree
Hide file tree
Showing 28 changed files with 476 additions and 311 deletions.
19 changes: 10 additions & 9 deletions MungNolZa/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.READ_MEDIA_VISUAL_USER_SELECTED" />
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
<uses-permission android:name="android.permission.INTERNET" />

<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
Expand All @@ -19,10 +20,7 @@
tools:targetApi="31">
<activity
android:name=".ui.TestActivity"
android:exported="true" >


</activity>
android:exported="true"/>
<activity
android:name=".ui.dialog.DialogSampleActivity"
android:exported="true" />
Expand All @@ -34,7 +32,7 @@
android:exported="true" />
<activity
android:name=".ui.matching_petsitter.MatchingPetsitterActivity"
android:exported="true"/>
android:exported="true" />
<activity
android:name=".ui.chat.ChatActivity"
android:exported="true" />
Expand Down Expand Up @@ -67,7 +65,10 @@
<activity
android:name=".ui.intro.activity.LoginActivity"
android:exported="true" />
<meta-data android:name="com.google.android.geo.API_KEY"
android:value="AIzaSyCgqqrHlGVDDd9td3yIA-LWul8eRStLv54"/>

<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="AIzaSyCgqqrHlGVDDd9td3yIA-LWul8eRStLv54" />
</application>

</manifest>
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
)
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
)
}
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 = ""
)
}
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?
}
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
}
}
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
}
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()
}

}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@ package kr.co.lion.mungnolza.ui.main

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.lifecycle.lifecycleScope
import androidx.navigation.fragment.NavHostFragment
import androidx.navigation.ui.NavigationUI
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kr.co.lion.mungnolza.R
import kr.co.lion.mungnolza.databinding.ActivityMainBinding

Expand All @@ -20,5 +24,6 @@ class MainActivity : AppCompatActivity() {
val navHostFragment = supportFragmentManager.findFragmentById(R.id.fragment_container) as NavHostFragment
val navController = navHostFragment.navController
NavigationUI.setupWithNavController(binding.navigationView, navController)

}
}
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])
}
}
Loading

0 comments on commit 68cb83f

Please sign in to comment.