Skip to content

Commit

Permalink
의약품 상세 정보 화면에서 툴바 접히는 기능 수정중
Browse files Browse the repository at this point in the history
  • Loading branch information
pknujsp committed Jul 24, 2023
1 parent 5129ac1 commit 885249a
Show file tree
Hide file tree
Showing 7 changed files with 177 additions and 195 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import kotlinx.coroutines.cancel
import kotlinx.coroutines.channels.BufferOverflow
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.asSharedFlow
import kotlinx.coroutines.launch
import kotlinx.coroutines.plus
import kotlinx.coroutines.suspendCancellableCoroutine
Expand All @@ -51,6 +52,18 @@ object SystemBarColorAnalyzer {
private const val criteriaColor = 140
private var systemBarController: SystemBarController? = null

private val _statusBarColor = MutableSharedFlow<SystemBarStyler.SystemBarColor>(
onBufferOverflow = BufferOverflow.DROP_OLDEST, replay = 1,
extraBufferCapacity = 5,
)
val statusBarColor = _statusBarColor.asSharedFlow()

private val _navigationBarColor = MutableSharedFlow<SystemBarStyler.SystemBarColor>(
onBufferOverflow = BufferOverflow.DROP_OLDEST, replay = 1,
extraBufferCapacity = 5,
)
val navigationBarColor = _navigationBarColor.asSharedFlow()

init {
coroutineScope.launch(Dispatchers.Default) {
onChangedFragmentFlow.collect {
Expand Down Expand Up @@ -83,7 +96,8 @@ object SystemBarColorAnalyzer {
statusBarBitmap.recycle()
navigationBarBitmap.recycle()

Log.d("wap", "${System.currentTimeMillis() - start}MS, status : $statusBarColor, nav : $navigationBarColor")
_statusBarColor.emit(statusBarColor)
_navigationBarColor.emit(navigationBarColor)

return statusBarColor to navigationBarColor
}
Expand Down Expand Up @@ -145,7 +159,7 @@ object SystemBarColorAnalyzer {
waitLock.withLock {
if (waiting?.isActive == true) waiting?.cancel()
waiting = launch(Dispatchers.Default) {
delay(70)
delay(80)
onChangedFragmentFlow.emit(Unit)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import com.android.mediproject.core.model.medicine.medicinedetailinfo.cache.Medi
import com.android.mediproject.core.model.medicine.medicinedetailinfo.toMedicineDetailInfoDto
import com.android.mediproject.core.model.requestparameters.GetMedicineIdParameter
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.catch
import kotlinx.coroutines.flow.channelFlow
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.flow.zip
Expand Down Expand Up @@ -39,8 +38,6 @@ class GetMedicineDetailsUseCase @Inject constructor(
),
) { r1, r2 ->
r1 to r2
}.catch {
trySend(Result.failure(it))
}.collectLatest { result ->
val medicineInfoResult = result.first
val medicineIdResult = result.second
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ abstract class DataGoKrBaseResponse {
}

inline fun <reified T : DataGoKrBaseResponse> T.toResult(): Result<T> = header?.run {
if (resultCode == "00") Result.success(this as T)
if (resultCode == "00") Result.success(this@toResult as T)
else Result.failure(Throwable(resultMsg))
} ?: Result.failure(Throwable("Response Failed"))
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ data class MedicineDetailInfoResponse(
@SerialName("body") val body: Body,
) : DataGoKrBaseResponse() {

val CHANGE_DATE_FORMAT = "yyyyMMdd"

@Serializable
data class Body(
@SerialName("items") val items: List<Item>, @SerialName("numOfRows") val numOfRows: Int, // 100
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,21 @@ import com.android.mediproject.core.model.requestparameters.GetMedicineIdParamet
import com.android.mediproject.core.network.module.AwsNetworkApi
import com.android.mediproject.core.network.onResponse
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.channelFlow
import javax.inject.Inject

class MedicineIdDataSourceImpl @Inject constructor(private val awsNetworkApi: AwsNetworkApi) : MedicineIdDataSource {
override fun getMedicineId(getMedicineIdParameter: GetMedicineIdParameter): Flow<Result<MedicineIdResponse>> = flow {
awsNetworkApi.getMedicineId(getMedicineIdParameter).onResponse().fold(onSuccess = { response ->
Result.success(response)
}, onFailure = {
Result.failure(it)
}).also { emit(it) }
override fun getMedicineId(getMedicineIdParameter: GetMedicineIdParameter): Flow<Result<MedicineIdResponse>> = channelFlow {
runCatching {
awsNetworkApi.getMedicineId(getMedicineIdParameter)
}.fold(
onSuccess = { response ->
send(response.onResponse())
},
onFailure = { error ->
send(Result.failure(error))
},
)
}

}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package com.android.mediproject.feature.medicine.main

import android.graphics.Color
import android.os.Bundle
import android.view.View
import androidx.core.view.doOnPreDraw
import androidx.core.view.isVisible
import androidx.fragment.app.viewModels
import androidx.navigation.fragment.findNavController
import com.android.mediproject.core.common.dialog.LoadingDialog
import com.android.mediproject.core.common.uiutil.SystemBarColorAnalyzer
import com.android.mediproject.core.common.uiutil.SystemBarController
import com.android.mediproject.core.common.uiutil.SystemBarStyler
import com.android.mediproject.core.common.util.navArgs
Expand Down Expand Up @@ -44,21 +46,13 @@ class MedicineInfoFragment : BaseFragment<FragmentMedicineInfoBinding, MedicineI
viewModel = fragmentViewModel
medicineInfoArgs = navArgs

toolbar.setNavigationOnClickListener {
findNavController().popBackStack()
}

root.doOnPreDraw {
topAppBar.removeOnOffsetChangedListener(null)
// smoothly hide medicinePrimaryInfoViewgroup when collapsing toolbar
topAppBar.addOnOffsetChangedListener { appBarLayout, verticalOffset ->
medicineInfoBar.alpha = 1.0f + (verticalOffset.toFloat() / appBarLayout.totalScrollRange.toFloat())
medicineInfoBar2.alpha = -(verticalOffset.toFloat() / appBarLayout.totalScrollRange.toFloat())

// 스크롤 할 때 마다 medicinePrimaryInfoViewgroup의 투명도 조정
medicinePrimaryInfoViewgroup.alpha = 1.0f + (verticalOffset.toFloat() / appBarLayout.totalScrollRange.toFloat()).apply {
if (this == -1.0f) {
medicinePrimaryInfoViewgroup.visibility = View.INVISIBLE
} else if (this > -0.8f) {
medicinePrimaryInfoViewgroup.isVisible = true
}
}
SystemBarColorAnalyzer.convert()
}
}
}
Expand Down Expand Up @@ -101,34 +95,23 @@ class MedicineInfoFragment : BaseFragment<FragmentMedicineInfoBinding, MedicineI
}

}
}

launch {
SystemBarColorAnalyzer.statusBarColor.collect {
binding.toolbar.setNavigationIconTint(if (it == SystemBarStyler.SystemBarColor.WHITE) Color.WHITE else Color.BLACK)
}
}
}
androidx.appcompat.R.style.Base_Widget_AppCompat_Toolbar_Button_Navigation
}

private fun setBarStyle() = binding.apply {
systemBarStyler.changeMode(
topViews = listOf(
SystemBarStyler.ChangeView(
medicineInfoBar,
SystemBarStyler.SpacingType.PADDING,
),
),
)

systemBarStyler.changeMode(
topViews = listOf(
SystemBarStyler.ChangeView(
medicineInfoBar2,
SystemBarStyler.SpacingType.PADDING,
),
),
)

}


// 탭 레이아웃 초기화
private fun initTabs() {

binding.apply {
contentViewPager.adapter = MedicineInfoPageAdapter(childFragmentManager, viewLifecycleOwner.lifecycle)

Expand Down
Loading

0 comments on commit 885249a

Please sign in to comment.