Skip to content

Commit

Permalink
[mod] #151 유저 타입에 맞게 아이콘 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
Jokwanhee committed May 6, 2024
1 parent 5278522 commit 3b58e60
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ data class ResponseHomeDto(
data class ResponseHomeDataDto(
@SerialName("user_type")
val userType: String,
@SerialName("opponent_user_type")
val opponentUserType: String,
@SerialName("user_id")
val userId: Long,
@SerialName("user_goal_step_count")
Expand All @@ -37,6 +39,7 @@ data class ResponseHomeDto(

fun toHomeData(): HomeData = HomeData(
userType = data.userType,
opponentUserType = data.opponentUserType,
userId = data.userId,
userGoalStepCount = data.userGoalStepCount,
opponentUserGoalStepCount = data.opponentUserGoalStepCount,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package sopt.motivoo.domain.entity.home

data class HomeData(
val userType: String,
val opponentUserType: String,
val userId: Long,
val userGoalStepCount: Int,
val opponentUserId: Long,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@ class HomeFragment : BindingFragment<FragmentHomeBinding>(R.layout.fragment_home
requireContext().getString(R.string.home_parent) -> Parent
else -> null
}
viewModel.anotherUserType.value = when (homeState.homeData.userType) {
requireContext().getString(R.string.home_child) -> Parent
requireContext().getString(R.string.home_parent) -> Child
viewModel.anotherUserType.value = when (homeState.homeData.opponentUserType) {
requireContext().getString(R.string.home_child) -> Child
requireContext().getString(R.string.home_parent) -> Parent
else -> null
}

Expand Down
3 changes: 2 additions & 1 deletion app/src/main/res/layout/fragment_home.xml
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,8 @@
app:layout_constraintTop_toBottomOf="@id/iv_mission_completed"
app:myStepCountText="@{String.valueOf(vm.stepCount)}"
app:otherStepCountText="@{String.valueOf(vm.otherStepCount)}"
app:userType="@{vm.userType}" />
app:userType="@{vm.userType}"
app:otherUserType="@{vm.anotherUserType}"/>

<androidx.appcompat.widget.AppCompatButton
android:id="@+id/btn_verify_exercise"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import androidx.annotation.DrawableRes
import androidx.core.content.ContextCompat
import androidx.core.graphics.drawable.toBitmap
import com.android.utils.BitmapCacheManager
import com.android.utils.BitmapCacheManager.Companion.OTHER_IMAGE
import com.android.utils.Child
import com.android.utils.MotivooUserType
import com.android.utils.Parent
Expand Down Expand Up @@ -196,6 +197,7 @@ class MotivooOtherPieChart @JvmOverloads constructor(
override fun onDetachedFromWindow() {
super.onDetachedFromWindow()
otherImageBitmap = null
BitmapCacheManager.getInstance().removeBitmapFromMemoryCache(OTHER_IMAGE)
scope.cancel()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import androidx.annotation.DrawableRes
import androidx.core.content.ContextCompat
import androidx.core.graphics.drawable.toBitmap
import com.android.utils.BitmapCacheManager
import com.android.utils.BitmapCacheManager.Companion.MY_IMAGE
import com.android.utils.Child
import com.android.utils.MotivooUserType
import com.android.utils.Parent
Expand Down Expand Up @@ -175,6 +176,7 @@ class MotivooPieChart @JvmOverloads constructor(

override fun onDetachedFromWindow() {
super.onDetachedFromWindow()
BitmapCacheManager.getInstance().removeBitmapFromMemoryCache(MY_IMAGE)
myImageBitmap = null
scope.cancel()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,32 @@ class MotivooStepCountText @JvmOverloads constructor(
Child -> {
binding.tvStepCountTitle.text =
context.getString(R.string.home_my_step_count)
binding.tvOtherStepCountTitle.text =
context.getString(R.string.home_parent_step_count)
}

Parent -> {
binding.tvStepCountTitle.text =
context.getString(R.string.home_my_step_count)
binding.tvOtherStepCountTitle.text =
context.getString(R.string.home_child_step_count)
}

else -> Unit
}
field = value
}

var otherUserType: MotivooUserType? = null
set(value) {
when (value) {
Child -> binding.tvOtherStepCountTitle.text =
context.getString(R.string.home_child_step_count)

Parent -> binding.tvOtherStepCountTitle.text =
context.getString(R.string.home_parent_step_count)

else -> Unit
}
field = value
}

init {
initView()
context.theme.obtainStyledAttributes(
Expand All @@ -47,6 +57,7 @@ class MotivooStepCountText @JvmOverloads constructor(
binding.tvOtherStepCount.text =
getString(R.styleable.MotivooStepCountText_otherStepCountText)
userType = getInt(R.styleable.MotivooStepCountText_userType, 0).toMotivooUserType
otherUserType = getInt(R.styleable.MotivooStepCountText_otherStepCountText, 0).toMotivooUserType
recycle()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ class BitmapCacheManager(
bitmapCache.get(key)
}

fun removeBitmapFromMemoryCache(key: String) = bitmapCache.remove(key)

companion object {
const val MY_IMAGE = "MY_IMAGE"
const val OTHER_IMAGE = "OTHER_IMAGE"
Expand Down
4 changes: 4 additions & 0 deletions motivoo_design/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
<enum name="Child" value="1"/>
<enum name="Parent" value="2"/>
</attr>
<attr name="otherUserType" format="enum">
<enum name="Child" value="1"/>
<enum name="Parent" value="2"/>
</attr>
</declare-styleable>
<declare-styleable name="MotivooMissionCard">
</declare-styleable>
Expand Down

0 comments on commit 3b58e60

Please sign in to comment.