Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

44 feature 자유게시판 데이터 적용 #67

Merged
merged 6 commits into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions MungNolZa/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,16 @@ android {
jvmTarget = "1.8"
}


viewBinding {
enable = true
}

buildFeatures{
dataBinding = true
}


}

dependencies {
Expand All @@ -57,6 +60,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")
Expand Down
24 changes: 16 additions & 8 deletions MungNolZa/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,24 @@
android:supportsRtl="true"
android:theme="@style/Theme.MungNolZa"
tools:targetApi="31">
<activity
android:name=".ui.freeboard.AddBoardActivity"
android:exported="false" />

<activity
android:name=".ui.reservation_list.PetsitterReviewWriteActivity"
android:exported="true" />
<activity
android:name=".ui.petsitter_main.PetsitterMainActivity"
android:exported="true" />

<activity
android:name=".ui.appointment.NoPetActivity"
android:exported="true" />
<activity
android:name=".ui.intro.activity.AddressActivity"
android:exported="true" />

<activity
android:name=".ui.TestActivity"
android:exported="true" />
Expand All @@ -57,23 +63,25 @@
<activity
android:name=".ui.main.MainActivity"
android:exported="true"
android:windowSoftInputMode="adjustPan" />
<activity
android:name=".ui.intro.activity.JoinActivity"
android:exported="true" />
<activity
android:name=".ui.intro.activity.StartActivity"
android:exported="true">
android:windowSoftInputMode="adjustPan">
<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.JoinActivity"
android:exported="true" />
<activity
android:name=".ui.intro.activity.StartActivity"
android:exported="true"></activity>
<activity
android:name=".ui.onboarding.OnBoardingActivity"
android:exported="true" />
<activity
android:name=".ui.intro.activity.LoginActivity"
android:exported="true" />

<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="AIzaSyCgqqrHlGVDDd9td3yIA-LWul8eRStLv54" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,22 @@
package kr.co.lion.mungnolza.data.repository

import android.content.Context
import android.net.Uri
import android.widget.ImageView
import kr.co.lion.mungnolza.model.BoardModel


interface BoardRepository {
suspend fun getBoardData(boardIdx: Int): BoardModel?
suspend fun getBoardList():ArrayList<BoardModel>

suspend fun insertBoard(boardModel:BoardModel)

suspend fun deleteBoard(boardModel: BoardModel)


suspend fun updateBoard(boardModel:BoardModel, isRemoveImage:Boolean)

suspend fun getBoardImageUri(boardIdx:Int,imageFilePath: String):Uri?

suspend fun getBoardImageUriList(boardModel:BoardModel): MutableList<Uri?>
}
Original file line number Diff line number Diff line change
@@ -1,28 +1,97 @@
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
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<BoardModel> {
val boardList = arrayListOf<BoardModel>()

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<String, Any?>()
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 getBoardImageUri(boardIdx:Int,imageFilePath: String):Uri?{
var response:Uri? = null
val path = "board/${boardIdx}/${imageFilePath}"
try{
response = storage.child(path).downloadUrl.await()
}catch (e:Exception){
Log.e("FirebaseResult",
"Error Get BoardImageListPath : ${storage.child(path)}")
}
return response
}

override suspend fun getBoardImageUriList(boardModel:BoardModel): MutableList<Uri?> {
var imageUriList:MutableList<Uri?> = mutableListOf()

boardModel.boardImagePathList.forEach {
imageUriList.add(getBoardImageUri(boardModel.boardIdx,it!!)!!)
}
return imageUriList
}

}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ 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()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import java.net.URI

interface UserRepository {
suspend fun fetchAllUserData() : List<UserModel>

suspend fun fetchUserAddress(uniqueNumber: String) : String
suspend fun fetchAllUserNickName(uniqueNumber: String) : List<String>
suspend fun fetchUserProfileImage(path: String) : URI?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
Loading