Skip to content

Commit

Permalink
Merge pull request #63 from ttoklip/faet/#2_마이페이지_구현
Browse files Browse the repository at this point in the history
Faet/#2 마이페이지 구현
  • Loading branch information
hangunhee39 authored Feb 19, 2024
2 parents ee8c20d + 49f9123 commit 4cac561
Show file tree
Hide file tree
Showing 10 changed files with 277 additions and 37 deletions.
9 changes: 5 additions & 4 deletions app/src/main/java/com/umc/ttoklip/data/api/MyPostApi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,19 @@ import com.umc.ttoklip.data.model.mypage.MyQuestionResponse
import com.umc.ttoklip.data.model.mypage.MyTogetherResponse
import retrofit2.Response
import retrofit2.http.GET
import retrofit2.http.Query

interface MyPostApi {
@GET("/api/v1/my-page/question")
suspend fun getMyQuestions(): Response<ResponseBody<MyQuestionResponse>>
suspend fun getMyQuestions(@Query("page") page: Int): Response<ResponseBody<MyQuestionResponse>>

@GET("/api/v1/my-page/participate-deals")
suspend fun getMyTogethers(): Response<ResponseBody<MyTogetherResponse>>
suspend fun getMyTogethers(@Query("page") page: Int): Response<ResponseBody<MyTogetherResponse>>

@GET("/api/v1/my-page/honeytip")
suspend fun getMyHoneyTips(): Response<ResponseBody<MyHoneyTipsResponse>>
suspend fun getMyHoneyTips(@Query("page") page: Int): Response<ResponseBody<MyHoneyTipsResponse>>

@GET("/api/v1/my-page/community")
suspend fun getMyCommunications(): Response<ResponseBody<MyCommunitiesResponse>>
suspend fun getMyCommunications(@Query("page") page: Int): Response<ResponseBody<MyCommunitiesResponse>>

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ package com.umc.ttoklip.data.model.mypage

data class Community(
val content: String,
val questionId: Long,
val title: String
val id: Int,
val title: String,
val writer: String,
val category: String,
val commentCount: Int
)
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package com.umc.ttoklip.data.model.mypage

data class CommunityX(
val communityId: Long,
val id: Int,
val content: String,
val title: String
val title: String,
val writer: String,
val commentCount: Int,
val likeCount: Int,
val scrapCount: Int
)
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ package com.umc.ttoklip.data.model.mypage

data class HoneyTip(
val content: String,
val honeyTipId: Long,
val title: String
val id: Int,
val title: String,
val category: String,
val writer: String,
val likeCount: Int,
val scrapCount: Int,
val commentCount: Int
)
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.umc.ttoklip.data.model.mypage

data class MyQuestionResponse(
val communities: List<Community>,
val questions: List<Community>,
val isFirst: Boolean,
val isLast: Boolean,
val totalElements: Int,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import com.umc.ttoklip.data.model.mypage.MyTogetherResponse
import com.umc.ttoklip.module.NetworkResult

interface MyPostRepository {
suspend fun getBMyQuestions(): NetworkResult<MyQuestionResponse>
suspend fun getMyTogethers(): NetworkResult<MyTogetherResponse>
suspend fun getMyHoneyTips(): NetworkResult<MyHoneyTipsResponse>
suspend fun getMyCommunications(): NetworkResult<MyCommunitiesResponse>
suspend fun getMyQuestions(page: Int): NetworkResult<MyQuestionResponse>
suspend fun getMyTogethers(page: Int): NetworkResult<MyTogetherResponse>
suspend fun getMyHoneyTips(page: Int): NetworkResult<MyHoneyTipsResponse>
suspend fun getMyCommunications(page: Int): NetworkResult<MyCommunitiesResponse>
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@ import com.umc.ttoklip.module.handleApi
import javax.inject.Inject

class MyPostRepositoryImpl @Inject constructor(private val api: MyPostApi) : MyPostRepository {
override suspend fun getBMyQuestions(): NetworkResult<MyQuestionResponse> {
return handleApi({ api.getMyQuestions() }) { response: ResponseBody<MyQuestionResponse> -> response.result }
override suspend fun getMyQuestions(page: Int): NetworkResult<MyQuestionResponse> {
return handleApi({ api.getMyQuestions(page) }) { response: ResponseBody<MyQuestionResponse> -> response.result }
}

override suspend fun getMyTogethers(): NetworkResult<MyTogetherResponse> {
return handleApi({ api.getMyTogethers() }) { response: ResponseBody<MyTogetherResponse> -> response.result }
override suspend fun getMyTogethers(page: Int): NetworkResult<MyTogetherResponse> {
return handleApi({ api.getMyTogethers(page) }) { response: ResponseBody<MyTogetherResponse> -> response.result }
}

override suspend fun getMyHoneyTips(): NetworkResult<MyHoneyTipsResponse> {
return handleApi({ api.getMyHoneyTips() }) { response: ResponseBody<MyHoneyTipsResponse> -> response.result }
override suspend fun getMyHoneyTips(page: Int): NetworkResult<MyHoneyTipsResponse> {
return handleApi({ api.getMyHoneyTips(page) }) { response: ResponseBody<MyHoneyTipsResponse> -> response.result }
}

override suspend fun getMyCommunications(): NetworkResult<MyCommunitiesResponse> {
return handleApi({ api.getMyCommunications() }) { response: ResponseBody<MyCommunitiesResponse> -> response.result }
override suspend fun getMyCommunications(page: Int): NetworkResult<MyCommunitiesResponse> {
return handleApi({ api.getMyCommunications(page) }) { response: ResponseBody<MyCommunitiesResponse> -> response.result }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import com.umc.ttoklip.databinding.ItemListHoneyTipBinding
import java.io.Serializable
import java.text.SimpleDateFormat
import java.util.Date
import kotlin.String

class HoneyTipListRVA(private var listener: OnItemClickListener) :
ListAdapter<HoneyTipMain, HoneyTipListRVA.HoneyTipListViewHolder>(object :
Expand Down Expand Up @@ -51,7 +50,11 @@ class HoneyTipListRVA(private var listener: OnItemClickListener) :
fun bind(honeyTip: HoneyTipMain) {
binding.titleTv.text = honeyTip.title
binding.writerTv.text = honeyTip.writer
binding.dateTv.text = calculateDate(honeyTip.writtenTime)
binding.dateTv.text = if (honeyTip.writtenTime.isNotBlank()) {
calculateDate(honeyTip.writtenTime)
} else {
""
}
binding.bodyTv.text = honeyTip.content
binding.commentCountTv.text = honeyTip.commentCount.toString()
binding.likeCountTv.text = honeyTip.likeCount.toString()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,30 +1,38 @@
package com.umc.ttoklip.presentation.mypage

import android.content.Intent
import android.view.View
import android.widget.AdapterView
import androidx.activity.viewModels
import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.DividerItemDecoration
import androidx.recyclerview.widget.LinearLayoutManager
import com.umc.ttoklip.R
import com.umc.ttoklip.data.model.honeytip.HoneyTipMain
import com.umc.ttoklip.databinding.ActivityMyHoneyTipBinding
import com.umc.ttoklip.presentation.base.BaseActivity
import com.umc.ttoklip.presentation.hometown.ReadCommunicationActivity
import com.umc.ttoklip.presentation.honeytip.adapter.HoneyTipListRVA
import com.umc.ttoklip.presentation.honeytip.adapter.OnItemClickListener
import com.umc.ttoklip.presentation.mypage.vm.ScrapViewModel
import com.umc.ttoklip.presentation.search.SearchViewModel
import com.umc.ttoklip.presentation.search.SearchViewModelImpl
import com.umc.ttoklip.presentation.honeytip.read.ReadHoneyTipActivity
import com.umc.ttoklip.presentation.honeytip.read.ReadQuestionActivity
import com.umc.ttoklip.presentation.mypage.vm.MyHoneyTipViewModel
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.launch

@AndroidEntryPoint
class MyHoneyTipActivity : BaseActivity<ActivityMyHoneyTipBinding>(R.layout.activity_my_honey_tip),
OnItemClickListener {
private val viewModel: ScrapViewModel by viewModels<ScrapViewModel>()
private val viewModel: MyHoneyTipViewModel by viewModels<MyHoneyTipViewModel>()
private val adapter by lazy {
HoneyTipListRVA(this)
}

override fun initView() {
val sortFilters = listOf(
getString(R.string.sort_most_recent),
getString(R.string.sort_popularity),
getString(R.string.sort_most_comments),
getString(R.string.sort_most_scrap)
"꿀팁 공유",
"질문해요",
"소통해요"
)
binding.honeyTipFilterSpinner.adapter =
SortSpinnerAdapter(this, sortFilters)
Expand All @@ -43,8 +51,7 @@ class MyHoneyTipActivity : BaseActivity<ActivityMyHoneyTipBinding>(R.layout.acti
HoneyTips("똑똑이", "음식물 쓰레기 냄새 방지!!", "집에 가끔씩이지만 나타나는 바퀴벌레, 잘못 처리하면 알깐다고도...", "1일전", 0),
HoneyTips("똑똑이", "음식물 쓰레기 냄새 방지!!", "집에 가끔씩이지만 나타나는 바퀴벌레, 잘못 처리하면 알깐다고도...", "1일전", 0),
)*/
val honeyTipList = mutableListOf<HoneyTipMain>()
val adapter = HoneyTipListRVA(this)

binding.myHoneyTipRv.layoutManager = LinearLayoutManager(this)
binding.myHoneyTipRv.adapter = adapter
binding.myHoneyTipRv.addItemDecoration(
Expand All @@ -53,14 +60,95 @@ class MyHoneyTipActivity : BaseActivity<ActivityMyHoneyTipBinding>(R.layout.acti
DividerItemDecoration.VERTICAL
)
)
adapter.submitList(honeyTipList)

binding.honeyTipFilterSpinner.onItemSelectedListener =
object : AdapterView.OnItemSelectedListener {
override fun onItemSelected(p0: AdapterView<*>?, p1: View?, p2: Int, p3: Long) {

viewModel.reset()

when (binding.honeyTipFilterSpinner.selectedItem.toString()) {
"소통해요" -> {
viewModel.getMyComms()
}

"꿀팁 공유" -> {
viewModel.getMyHoneyTips()
}

"질문해요" -> {
viewModel.getMyQuestions()
}

else -> {}
}
}

override fun onNothingSelected(p0: AdapterView<*>?) {

}
}

binding.myHoneyTipBackBtn.setOnClickListener {
onBackPressedDispatcher.onBackPressed()
}
}

override fun initObserver() = Unit
override fun initObserver() {
with(lifecycleScope) {
launch {
viewModel.honeyTipList.collect {
adapter.submitList(it.map { tips ->
HoneyTipMain(
tips.id,
tips.title,
tips.content,
tips.writer,
tips.likeCount,
tips.commentCount,
tips.scrapCount,
""
)
})
}
}

launch {
viewModel.commsList.collect {
adapter.submitList(it.map { comms ->
HoneyTipMain(
comms.id,
comms.title,
comms.content,
comms.writer,
comms.likeCount,
comms.commentCount,
comms.scrapCount,
""
)
})
}
}

launch {
viewModel.questionList.collect {
adapter.submitList(it.map { question ->
HoneyTipMain(
question.id,
question.title,
question.content,
question.writer,
0,
question.commentCount,
0,
""
)
})
}
}

}
}


/*override fun onClick(honeyTips: HoneyTips) {
Expand All @@ -69,6 +157,26 @@ class MyHoneyTipActivity : BaseActivity<ActivityMyHoneyTipBinding>(R.layout.acti
}*/

override fun onClick(honeyTip: HoneyTipMain) {
when (binding.honeyTipFilterSpinner.selectedItem.toString()) {
"소통해요" -> {
val intent = Intent(this, ReadCommunicationActivity::class.java)
intent.putExtra("postId", honeyTip.id.toLong())
startActivity(intent)
}

"꿀팁 공유" -> {
val intent = Intent(this, ReadHoneyTipActivity::class.java)
intent.putExtra("postId", honeyTip.id)
startActivity(intent)
}

"질문해요" -> {
val intent = Intent(this, ReadQuestionActivity::class.java)
intent.putExtra("postId", honeyTip.id)
startActivity(intent)
}

else -> {}
}
}
}
Loading

0 comments on commit 4cac561

Please sign in to comment.