Skip to content

Commit

Permalink
#193 DUR 성분/품목 정보 표시 기능 제작 1차완료, 2차로 레이아웃 수정 예정
Browse files Browse the repository at this point in the history
  • Loading branch information
pknujsp committed Jul 27, 2023
1 parent e8110ce commit 4e62597
Show file tree
Hide file tree
Showing 33 changed files with 447 additions and 166 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ internal fun Project.configureAndroidCompose(
compose = true
}

defaultConfig {
minSdk = libs.findVersion("minSdk").get().toString().toInt()
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}

composeOptions {
kotlinCompilerExtensionVersion = libs.findVersion("kotlinCompilerExtension").get().toString()
}
Expand Down Expand Up @@ -59,4 +64,4 @@ private fun Project.buildComposeMetricsParameters(): List<String> {
metricParameters.add("plugin:androidx.compose.compiler.plugins.kotlin:reportsDestination=" + reportsFolder.absolutePath)
}
return metricParameters.toList()
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package com.android.mediproject.core.common.recyclerview

import android.util.Log
import android.view.View
import android.widget.TextView
import androidx.core.view.isVisible
import androidx.recyclerview.widget.AsyncDifferConfig
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.ListAdapter
import androidx.recyclerview.widget.RecyclerView
import com.google.android.material.progressindicator.CircularProgressIndicator
import kotlin.reflect.KProperty

abstract class MListAdapter<T, VH : RecyclerView.ViewHolder> : ListAdapter<T, VH> {

private var init = true
private var iView: IView? = null

constructor(diffCallback: DiffUtil.ItemCallback<T>) : super(diffCallback)
Expand All @@ -19,14 +19,17 @@ abstract class MListAdapter<T, VH : RecyclerView.ViewHolder> : ListAdapter<T, VH
override fun onCurrentListChanged(previousList: MutableList<T>, currentList: MutableList<T>) {
super.onCurrentListChanged(previousList, currentList)
iView?.run {
val isFirstLoad = previousList.isEmpty() && currentList.isNotEmpty()
Log.d(
"MListAdapter", "previousListEmpty : ${previousList.isEmpty()}, currentListEmpty : ${currentList.isEmpty()}",
)

progressBarIsVisible.call(isFirstLoad)
loadTextViewIsVisible.call(isFirstLoad)
msgTextViewIsVisible.call(previousList.isEmpty() && currentList.isEmpty())
listViewIsVisible.call(currentList.isNotEmpty())
msgTextViewIsVisible(if (!init and previousList.isEmpty() and currentList.isEmpty()) View.VISIBLE else View.GONE)
loadTextViewIsVisible(if (init) View.VISIBLE else View.GONE)
progressBarIsVisible(if (init) View.VISIBLE else View.GONE)
listViewIsVisible(if (currentList.isNotEmpty()) View.VISIBLE else View.GONE)

if (previousList.isEmpty() && currentList.isNotEmpty()) listViewScrollToPosition(0)
if (previousList.isEmpty() and currentList.isNotEmpty()) listViewScrollToPosition(0)
init = false
}
}

Expand Down Expand Up @@ -54,10 +57,10 @@ abstract class MListAdapter<T, VH : RecyclerView.ViewHolder> : ListAdapter<T, VH
emptyMsg: String,
loadMsg: String,
) {
val msgTextViewIsVisible: KProperty<Boolean> = msgTextView::isVisible
val loadTextViewIsVisible: KProperty<Boolean> = loadTextView::isVisible
val progressBarIsVisible: KProperty<Boolean> = progressBar::isVisible
val listViewIsVisible: KProperty<Boolean> = listView::isVisible
val msgTextViewIsVisible: (Int) -> Unit = msgTextView::setVisibility
val loadTextViewIsVisible: (Int) -> Unit = loadTextView::setVisibility
val progressBarIsVisible: (Int) -> Unit = progressBar::setVisibility
val listViewIsVisible: (Int) -> Unit = listView::setVisibility
val listViewScrollToPosition: (Int) -> Unit = listView::scrollToPosition

init {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import com.android.mediproject.core.model.dur.DurType
import com.android.mediproject.core.network.datasource.dur.DurProductDataSource
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.channelFlow
import kotlinx.coroutines.flow.last
import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.sync.withLock
import javax.inject.Inject
Expand All @@ -23,12 +22,8 @@ class DurProductRepositoryImpl @Inject constructor(
override fun hasDur(itemName: String?, itemSeq: String?): Flow<Result<List<DurType>>> = channelFlow {
val response = durProductDataSource.getDurProductList(itemName = itemName, itemSeq = itemSeq)
response.onSuccess {
if (it.body.items.isNotEmpty()) {
val durTypeList = it.body.items.map { item -> DurType.valueOf(item.typeName) }
send(Result.success(durTypeList))
} else {
send(Result.failure(Throwable("No Dur")))
}
val durTypeList = it.body.items.firstOrNull()?.typeNames?.map { type -> DurType.typeOf(type) } ?: emptyList()
send(Result.success(durTypeList))
}.onFailure {
send(Result.failure(it))
}
Expand All @@ -39,16 +34,18 @@ class DurProductRepositoryImpl @Inject constructor(
durProductCacheMap[itemSeq]?.keys?.filter { it !in durTypes } ?: durTypes
}
val map = mutableMapOf<DurType, Result<List<DurItem>>>()
durProductDataSource.getDurList(itemSeq, filteredDurTypes).last().forEach { (durType, response) ->
response.onSuccess {
cache(itemSeq, durType, it)
durType to Result.success(DurItemWrapperFactory.createForDurProduct(durType, it).convert())
}.onFailure {
durType to Result.failure<List<DurItem>>(it)
durProductDataSource.getDurList(itemSeq, filteredDurTypes).collect { resultMap ->
resultMap.forEach { (durType, response) ->
response.onSuccess {
cache(itemSeq, durType, it)
map[durType] = Result.success(DurItemWrapperFactory.createForDurProduct(durType, it).convert())
}.onFailure {
map[durType] = Result.failure(it)
}
}
}

send(map)
send(map)
}
}

private suspend fun cache(key: String, durType: DurType, response: DataGoKrResponse<*>) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@ import com.android.mediproject.core.model.dur.durproduct.dosing.DurProductDosing
import com.android.mediproject.core.model.dur.durproduct.dosing.DurProductDosingCautionWrapper
import com.android.mediproject.core.model.dur.durproduct.efficacygroupduplication.DurProductEfficacyGroupDuplicationResponse
import com.android.mediproject.core.model.dur.durproduct.efficacygroupduplication.DurProductEfficacyGroupDuplicationWrapper
import com.android.mediproject.core.model.dur.durproduct.extendedreleasetablet.DurProductExReleaseTabletSplitAttentionResponse
import com.android.mediproject.core.model.dur.durproduct.extendedreleasetablet.DurProductExReleaseTableSplitAttentionWrapper
import com.android.mediproject.core.model.dur.durproduct.extendedreleasetablet.DurProductExReleaseTabletSplitAttentionResponse
import com.android.mediproject.core.model.dur.durproduct.pregnancy.DurProductPregnantWomanTabooResponse
import com.android.mediproject.core.model.dur.durproduct.pregnancy.DurProductPregnantWomanTabooWrapper
import com.android.mediproject.core.model.dur.durproduct.senior.DurProductSeniorCautionResponse
import com.android.mediproject.core.model.dur.durproduct.senior.DurProductSeniorCautionWrapper
import com.android.mediproject.core.model.dur.durproduct.specialtyagegroup.DurProductSpecialtyAgeGroupTabooResponse
import com.android.mediproject.core.model.dur.durproduct.specialtyagegroup.DurProductSpecialtyWrapper
import com.android.mediproject.core.model.dur.durproduct.specialtyagegroup.DurProductSpecialtyAgeGroupTabooWrapper

class DurItemWrapperFactory {
companion object {
inline fun <reified T : DataGoKrResponse<*>> createForDurProduct(durType: DurType, response: T): DurItemWrapper = when (durType) {
DurType.SPECIALTY_AGE_GROUP_TABOO -> DurProductSpecialtyWrapper(response as DurProductSpecialtyAgeGroupTabooResponse)
DurType.SPECIALTY_AGE_GROUP_TABOO -> DurProductSpecialtyAgeGroupTabooWrapper(response as DurProductSpecialtyAgeGroupTabooResponse)
DurType.SENIOR_CAUTION -> DurProductSeniorCautionWrapper(response as DurProductSeniorCautionResponse)
DurType.DOSING_CAUTION -> DurProductDosingCautionWrapper(response as DurProductDosingCautionResponse)
DurType.EFFICACY_GROUP_DUPLICATION -> DurProductEfficacyGroupDuplicationWrapper(response as DurProductEfficacyGroupDuplicationResponse)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,13 @@ package com.android.mediproject.core.model.dur

enum class DurType(val type: String) {
CAPACITY_ATTENTION("용량주의"), DOSING_CAUTION("투여기간주의"), EFFICACY_GROUP_DUPLICATION("효능군중복"), EX_RELEASE_TABLET_SPLIT_ATTENTION("서방정분할주의"),
COMBINATION_TABOO("병용금기"), SPECIALTY_AGE_GROUP_TABOO("특정연령대금기"), SENIOR_CAUTION("노인주의"), PREGNANT_WOMAN_TABOO("임부금기")
COMBINATION_TABOO("병용금기"), SPECIALTY_AGE_GROUP_TABOO("특정연령대금기"), SENIOR_CAUTION("노인주의"), PREGNANT_WOMAN_TABOO("임부금기");

companion object {
fun typeOf(type: String): DurType {
return DurType.values().find { it.type == type } ?: throw IllegalArgumentException("Unknown DurType: $type")
}

const val excludeType = "첨가제주의"
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.android.mediproject.core.model.dur.duringr.combination

import android.text.Spanned
import com.android.mediproject.core.model.dur.DurItemWrapper
import com.android.mediproject.core.model.dur.DurType
import com.android.mediproject.core.model.dur.duringr.ui.DurIngrItem
Expand All @@ -13,7 +14,10 @@ data class DurIngrCombinationTaboo(
val mixtureIngrEngName: String,
val remark: String,
override val prohibitContent: String = "",
) : DurIngrItem(DurType.COMBINATION_TABOO)
) : DurIngrItem(DurType.COMBINATION_TABOO) {
override val content: Spanned
get() = TODO("Not yet implemented")
}

class DurIngrCombinationTabooWrapper(
override val response: DurIngrCombinationTabooResponse,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
package com.android.mediproject.core.model.dur.durproduct.capacity

import android.graphics.Typeface
import android.text.Spannable
import android.text.SpannableStringBuilder
import android.text.Spanned
import android.text.style.RelativeSizeSpan
import android.text.style.StyleSpan
import androidx.core.text.toSpanned
import com.android.mediproject.core.model.dur.DurItemWrapper
import com.android.mediproject.core.model.dur.DurType
import com.android.mediproject.core.model.dur.durproduct.ui.DurProductItem
import java.lang.ref.WeakReference

/**
* 용량주의
Expand All @@ -13,7 +21,19 @@ import com.android.mediproject.core.model.dur.durproduct.ui.DurProductItem
data class DurProductCapacityAttention(
val itemName: String,
override val prohibitContent: String,
) : DurProductItem(DurType.CAPACITY_ATTENTION)
) : DurProductItem(DurType.CAPACITY_ATTENTION) {
override val content: Spanned
get() = WeakReference(SpannableStringBuilder()).get()!!.let { builder ->
builder.append(itemName)
builder.setSpan(StyleSpan(Typeface.BOLD), 0, itemName.length, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)
builder.setSpan(RelativeSizeSpan(1.2f), 0, itemName.length, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)

builder.append("\n")
builder.append(prohibitContent)

builder.toSpanned()
}
}


fun DurProductCapacityAttentionResponse.Item.toDurProductCapacityAttention() = DurProductCapacityAttention(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
package com.android.mediproject.core.model.dur.durproduct.combination

import android.graphics.Typeface
import android.text.Spannable
import android.text.SpannableStringBuilder
import android.text.Spanned
import android.text.style.RelativeSizeSpan
import android.text.style.StyleSpan
import androidx.core.text.toSpanned
import com.android.mediproject.core.model.dur.DurItemWrapper
import com.android.mediproject.core.model.dur.DurType
import com.android.mediproject.core.model.dur.durproduct.ui.DurProductItem
import java.lang.ref.WeakReference

data class DurProductCombinationTaboo(
val itemName: String,
Expand All @@ -14,7 +22,18 @@ data class DurProductCombinationTaboo(
val mixtureIngrEngName: String,
val remark: String,
override val prohibitContent: String,
) : DurProductItem(DurType.COMBINATION_TABOO)
) : DurProductItem(DurType.COMBINATION_TABOO) {
override val content: Spanned = WeakReference(SpannableStringBuilder()).get()!!.let { builder ->
builder.append(itemName)
builder.setSpan(StyleSpan(Typeface.BOLD), 0, itemName.length, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)
builder.setSpan(RelativeSizeSpan(1.2f), 0, itemName.length, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)

builder.append("\n")
builder.append(prohibitContent)

builder.toSpanned()
}
}

class DurProductCombinationTabooWrapper(
override val response: DurProductCombinationTabooResponse,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
package com.android.mediproject.core.model.dur.durproduct.dosing

import android.graphics.Typeface
import android.text.Spannable
import android.text.SpannableStringBuilder
import android.text.Spanned
import android.text.style.RelativeSizeSpan
import android.text.style.StyleSpan
import androidx.core.text.toSpanned
import com.android.mediproject.core.model.dur.DurItemWrapper
import com.android.mediproject.core.model.dur.DurType
import com.android.mediproject.core.model.dur.durproduct.ui.DurProductItem
import java.lang.ref.WeakReference

/**
* 투여기간 주의
Expand All @@ -13,7 +21,19 @@ import com.android.mediproject.core.model.dur.durproduct.ui.DurProductItem
data class DurProductDosingCaution(
val itemName: String,
override val prohibitContent: String,
) : DurProductItem(DurType.DOSING_CAUTION)
) : DurProductItem(DurType.DOSING_CAUTION) {
override val content: Spanned
get() = WeakReference(SpannableStringBuilder()).get()!!.let { builder ->
builder.append(itemName)
builder.setSpan(StyleSpan(Typeface.BOLD), 0, itemName.length, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)
builder.setSpan(RelativeSizeSpan(1.2f), 0, itemName.length, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)

builder.append("\n")
builder.append(prohibitContent)

builder.toSpanned()
}
}


class DurProductDosingCautionWrapper(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
package com.android.mediproject.core.model.dur.durproduct.efficacygroupduplication

import android.graphics.Typeface
import android.text.Spannable
import android.text.SpannableStringBuilder
import android.text.Spanned
import android.text.style.RelativeSizeSpan
import android.text.style.StyleSpan
import androidx.core.text.toSpanned
import com.android.mediproject.core.model.dur.DurItemWrapper
import com.android.mediproject.core.model.dur.DurType
import com.android.mediproject.core.model.dur.durproduct.ui.DurProductItem
import java.lang.ref.WeakReference

data class DurProductEfficacyGroupDuplication(
val itemName: String,
Expand All @@ -11,7 +19,19 @@ data class DurProductEfficacyGroupDuplication(
val ingrKorName: String,
val ingrEngName: String,
override val prohibitContent: String,
) : DurProductItem(DurType.EFFICACY_GROUP_DUPLICATION)
) : DurProductItem(DurType.EFFICACY_GROUP_DUPLICATION) {
override val content: Spanned
get() = WeakReference(SpannableStringBuilder()).get()!!.let { builder ->
builder.append(ingrEngName)
builder.setSpan(StyleSpan(Typeface.BOLD), 0, itemName.length, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)
builder.setSpan(RelativeSizeSpan(1.2f), 0, itemName.length, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)

builder.append("\n")
builder.append(itemName)

builder.toSpanned()
}
}

class DurProductEfficacyGroupDuplicationWrapper(
override val response: DurProductEfficacyGroupDuplicationResponse,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
package com.android.mediproject.core.model.dur.durproduct.extendedreleasetablet

import android.graphics.Typeface
import android.text.Spannable
import android.text.SpannableStringBuilder
import android.text.Spanned
import android.text.style.RelativeSizeSpan
import android.text.style.StyleSpan
import androidx.core.text.toSpanned
import com.android.mediproject.core.model.dur.DurItemWrapper
import com.android.mediproject.core.model.dur.DurType
import com.android.mediproject.core.model.dur.durproduct.ui.DurProductItem
import com.android.mediproject.core.model.dur.toHtml
import java.lang.ref.WeakReference

/**
* 서방정 분할 주의
Expand All @@ -17,7 +23,17 @@ data class DurProductExReleaseTabletSplitAttention(
override val prohibitContent: String,
) : DurProductItem(DurType.EX_RELEASE_TABLET_SPLIT_ATTENTION) {

override val content: Spanned = "<b>$itemName<b>\n$prohibitContent".toHtml()
override val content: Spanned
get() = WeakReference(SpannableStringBuilder()).get()!!.let { builder ->
builder.append(itemName)
builder.setSpan(StyleSpan(Typeface.BOLD), 0, itemName.length, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)
builder.setSpan(RelativeSizeSpan(1.2f), 0, itemName.length, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)

builder.append("\n")
builder.append(prohibitContent)

builder.toSpanned()
}
}

class DurProductExReleaseTableSplitAttentionWrapper(
Expand Down
Loading

0 comments on commit 4e62597

Please sign in to comment.