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

[UI/#61] 리듬뷰 / UI 수정사항 대응 #63

Merged
merged 17 commits into from
Sep 22, 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
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package com.kkkk.data.dataSource

import com.kkkk.data.dto.BaseResponse
import com.kkkk.data.dto.request.RecordRequestDto
import com.kkkk.data.dto.request.RhythmRequestDto
import okhttp3.ResponseBody

interface RhythmDataSource {
suspend fun postToGetRhythmUrl(
bpm: Int
request: RhythmRequestDto
): BaseResponse<String>

suspend fun getRhythmWav(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.kkkk.data.dataSourceImpl
import com.kkkk.data.dataSource.RhythmDataSource
import com.kkkk.data.dto.BaseResponse
import com.kkkk.data.dto.request.RecordRequestDto
import com.kkkk.data.dto.request.RhythmRequestDto
import com.kkkk.data.service.RhythmService
import okhttp3.ResponseBody
import javax.inject.Inject
Expand All @@ -13,8 +14,8 @@ constructor(
private val rhythmService: RhythmService
) : RhythmDataSource {

override suspend fun postToGetRhythmUrl(bpm: Int): BaseResponse<String> =
rhythmService.postToGetRhythmUrl(bpm)
override suspend fun postToGetRhythmUrl(request: RhythmRequestDto): BaseResponse<String> =
rhythmService.postToGetRhythmUrl(request)

override suspend fun getRhythmWav(url: String): ResponseBody =
rhythmService.getRhythmWav(url)
Expand Down
17 changes: 17 additions & 0 deletions data/src/main/java/com/kkkk/data/dto/request/RhythmRequestDto.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.kkkk.data.dto.request

import com.kkkk.domain.entity.request.RhythmRequestModel
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
data class RhythmRequestDto(
@SerialName("bpm")
val bpm: Int,
@SerialName("bit")
val bit: Int,
) {
companion object {
fun RhythmRequestModel.toDto() = RhythmRequestDto(bpm, bit)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package com.kkkk.data.repositoryImpl

import com.kkkk.data.dataSource.RhythmDataSource
import com.kkkk.data.dto.request.RecordRequestDto.Companion.toDto
import com.kkkk.data.dto.request.RhythmRequestDto.Companion.toDto
import com.kkkk.domain.entity.request.RecordRequestModel
import com.kkkk.domain.entity.request.RhythmRequestModel
import com.kkkk.domain.repository.RhythmRepository
import javax.inject.Inject

Expand All @@ -12,9 +14,9 @@ constructor(
private val rhythmDataSource: RhythmDataSource,
) : RhythmRepository {

override suspend fun postToGetRhythmUrl(bpm: Int): Result<String> =
override suspend fun postToGetRhythmUrl(request: RhythmRequestModel): Result<String> =
runCatching {
rhythmDataSource.postToGetRhythmUrl(bpm).data
rhythmDataSource.postToGetRhythmUrl(request.toDto()).data
}

override suspend fun getRhythmWav(url: String): Result<ByteArray> =
Expand Down
6 changes: 3 additions & 3 deletions data/src/main/java/com/kkkk/data/service/RhythmService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ package com.kkkk.data.service

import com.kkkk.data.dto.BaseResponse
import com.kkkk.data.dto.request.RecordRequestDto
import com.kkkk.data.dto.request.RhythmRequestDto
import okhttp3.ResponseBody
import retrofit2.http.Body
import retrofit2.http.GET
import retrofit2.http.POST
import retrofit2.http.Path
import retrofit2.http.Url

interface RhythmService {
@POST("/api/v1/rhythm/{bpm}")
@POST("/api/v1/rhythm")
suspend fun postToGetRhythmUrl(
@Path("bpm") bpm: Int,
@Body request: RhythmRequestDto,
): BaseResponse<String>

@GET
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.kkkk.domain.entity.request

data class RhythmRequestModel(
val bpm: Int,
val bit: Int,
)
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package com.kkkk.domain.repository

import com.kkkk.domain.entity.request.RecordRequestModel
import com.kkkk.domain.entity.request.RhythmRequestModel

interface RhythmRepository {
suspend fun postToGetRhythmUrl(
bpm: Int
request: RhythmRequestModel
): Result<String>

suspend fun getRhythmWav(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,34 @@ import android.os.Bundle
import androidx.fragment.app.Fragment
import androidx.fragment.app.commit
import androidx.fragment.app.replace
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.flowWithLifecycle
import androidx.lifecycle.lifecycleScope
import com.kkkk.core.base.BaseActivity
import com.kkkk.presentation.main.profile.ProfileFragment
import com.kkkk.presentation.main.record.RecordFragment
import com.kkkk.presentation.main.rhythm.RhythmFragment
import com.kkkk.presentation.main.rhythm.RhythmViewModel
import com.kkkk.presentation.main.rhythm.StretchFragment
import com.kkkk.presentation.main.study.StudyFragment
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import kr.genti.presentation.R
import kr.genti.presentation.databinding.ActivityMainBinding

@AndroidEntryPoint
class MainActivity : BaseActivity<ActivityMainBinding>(R.layout.activity_main) {

private lateinit var rhythmViewModel: RhythmViewModel

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

initBnvItemIconTintList()
initBnvItemSelectedListener()
initViewModelProvider()
observeStretchViewNavigate()
}

private fun initBnvItemIconTintList() {
Expand Down Expand Up @@ -56,4 +68,18 @@ class MainActivity : BaseActivity<ActivityMainBinding>(R.layout.activity_main) {
replace<T>(R.id.fcv_main, T::class.java.canonicalName)
}
}

private fun initViewModelProvider() {
rhythmViewModel = ViewModelProvider(this)[RhythmViewModel::class.java]
}

private fun observeStretchViewNavigate() {
rhythmViewModel.isStretchView.flowWithLifecycle(lifecycle).onEach { isStretch ->
if (isStretch) {
navigateTo<StretchFragment>()
} else {
navigateTo<RhythmFragment>()
}
}.launchIn(lifecycleScope)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import com.kkkk.core.extension.stringOf
import com.kkkk.core.extension.toast
import com.kkkk.core.state.UiState
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import kr.genti.presentation.R
Expand All @@ -39,6 +38,7 @@ class RecordFragment : BaseFragment<FragmentRecordBinding>(R.layout.fragment_rec
observeReportMonth()
observeChartEntry()
setStatusBarColor(R.color.white)
viewModel.setGraphWithDate()
}

private fun observeReportMonth() {
Expand All @@ -53,11 +53,11 @@ class RecordFragment : BaseFragment<FragmentRecordBinding>(R.layout.fragment_rec
}

private fun observeChartEntry() {
viewModel.chartEntry.flowWithLifecycle(lifecycle).distinctUntilChanged().onEach { state ->
viewModel.chartEntry.flowWithLifecycle(lifecycle).onEach { state ->
when (state) {
is UiState.Success -> {
binding.ivChartLoading.isVisible = false
binding.layoutChart.isVisible = true
setLoadingView(false)
binding.ivChartEmpty.isVisible = false
binding.chartReport.apply {
data = LineData(LineDataSet(state.data, CHART_RECORD).setDataSettings())
invalidate()
Expand All @@ -66,17 +66,33 @@ class RecordFragment : BaseFragment<FragmentRecordBinding>(R.layout.fragment_rec
}

is UiState.Failure -> {
binding.ivChartLoading.isVisible = true
setLoadingView(false)
binding.ivChartEmpty.isVisible = true
toast(stringOf(R.string.error_msg))
}

is UiState.Loading -> binding.ivChartLoading.isVisible = false
is UiState.Loading -> setLoadingView(true)

is UiState.Empty -> binding.ivChartLoading.isVisible = true
is UiState.Empty -> {
setLoadingView(false)
binding.ivChartEmpty.isVisible = true
}
}
}.launchIn(lifecycleScope)
}

private fun setLoadingView(isLoading: Boolean) {
binding.layoutLoading.isVisible = isLoading
if (isLoading) {
binding.layoutChart.visibility = View.INVISIBLE
setStatusBarColor(R.color.transparent_50)
} else {
binding.layoutChart.visibility = View.VISIBLE
setStatusBarColor(R.color.white)
}
}


private fun LineDataSet.setDataSettings(): LineDataSet {
this.apply {
color = colorOf(R.color.purple_50)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@ constructor(
var startDate = ""
var endDate = ""

init {
setGraphWithDate()
}

fun setIsChangingMonth() {
isChangingMonth.value = isChangingMonth.value?.not() ?: false
}
Expand All @@ -48,7 +44,7 @@ constructor(
setGraphWithDate()
}

private fun setGraphWithDate() {
fun setGraphWithDate() {
endDate = DATE_FORMAT.format(Date())
DATE_FORMAT.parse(endDate)?.let { date ->
val postCalendar = Calendar.getInstance().apply {
Expand Down
Loading
Loading