宝箱act 顶部UI刷新

This commit is contained in:
renhaoting 2025-12-03 16:39:52 +08:00
parent 77d93b0211
commit 82ff8c5c51
8 changed files with 157 additions and 49 deletions

View File

@ -10,6 +10,10 @@ import com.gamedog.vididin.main.interfaces.OnTabStyleListener
import com.gamedog.vididin.manager.TaskManager
import dagger.hilt.android.AndroidEntryPoint
import kotlin.getValue
import com.gamedog.vididin.manager.taskbeans.BaseTaskState.Companion.STATE_FINISH
import com.gamedog.vididin.manager.taskbeans.BaseTaskState.Companion.STATE_ONGOING
import com.gamedog.vididin.manager.taskbeans.BaseTaskState.Companion.STATE_CLAIMED
import com.gamedog.vididin.manager.taskbeans.BaseTaskState.Companion.STATE_EXPIRED
import com.gamedog.vididin.databinding.ActivityBenefitBinding as ViewBinding
import com.gamedog.vididin.main.MainUiState as UiState
import com.gamedog.vididin.main.MainViewModel as ViewModel
@ -30,7 +34,7 @@ class BenefitActivity : AppViewsActivity<ViewBinding, UiState, ViewModel>(), OnT
override fun ViewBinding.initViews() {
titlebar.setTitleText(R.string.benefit)
loadTaskState()
initAddSubTaskViews()
initViewsByTaskState()
}
override fun ViewBinding.initListeners() {
@ -50,56 +54,81 @@ class BenefitActivity : AppViewsActivity<ViewBinding, UiState, ViewModel>(), OnT
}
private fun loadTaskState() {
val boxStatusBean = TaskManager.instance().boxTaskStatus()
val taskStateHelper = TaskManager.instance().boxTaskStatus()
}
private fun initAddSubTaskViews() {
val boxStatusBean = TaskManager.instance().boxTaskStatus()
private fun initViewsByTaskState() {
val taskStateHelper = TaskManager.instance().boxTaskStatus()
val boxStateList = taskStateHelper.getStatusBean().tasks
val currentBoxIndex = taskStateHelper.getCurrentBoxIndex()
updateTopBoxesUI()
//initAddSubTaskViews()
/*
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/gray_f2"
/>
<com.gamedog.vididin.features.benefit.widget.BenefitTaskItemView
android:id="@+id/task_item_1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginVertical="20dp"
/>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/gray_f2"
/>
<com.gamedog.vididin.features.benefit.widget.BenefitTaskItemView
android:id="@+id/task_item_2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginVertical="20dp"
/>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/gray_f2"
/>
<com.gamedog.vididin.features.benefit.widget.BenefitTaskItemView
android:id="@+id/task_item_3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginVertical="20dp"
/>
*/
}
private fun gotoWatchVideo() {
//TODO("Not yet implemented")
private fun updateTopBoxesUI() {
val taskStateHelper = TaskManager.instance().boxTaskStatus()
val boxStateList = taskStateHelper.getStatusBean().tasks
with (binding) {
boxStateList.forEachIndexed { index, curBoxState ->
val stateEnum = taskStateHelper.getBoxStateEnum(index)
if (index == 0) {
ivSubtask1.setImageResource(getIconResByState(stateEnum))
tvSubtask1State.setText(getStrResByState(stateEnum))
tvSubtask1State.setTextColor(getStrColorByState(stateEnum))
}
if (index == 1) {
ivSubtask2.setImageResource(getIconResByState(stateEnum))
tvSubtask2State.setText(getStrResByState(stateEnum))
tvSubtask2State.setTextColor(getStrColorByState(stateEnum))
}
if (index == 2) {
ivSubtask3.setImageResource(getIconResByState(stateEnum))
tvSubtask3State.setText(getStrResByState(stateEnum))
tvSubtask3State.setTextColor(getStrColorByState(stateEnum))
}
}
val couldClaimCashNum = taskStateHelper.getCouldClaimCashNum()
with (tvResgatar) {
if (couldClaimCashNum > 0) {
(R.mipmap.icon_but_bg_green)
isClickable = true
} else {
setBackgroundResource(R.mipmap.but_bg_grady)
isClickable = false
}
}
}
}
private fun getIconResByState(state: Int): Int {
when (state) {
STATE_EXPIRED -> return R.mipmap.benefit_item_expired
STATE_FINISH, STATE_CLAIMED -> return R.mipmap.benefit_item_finished
else -> return R.mipmap.benefit_item_ongoing
}
}
private fun getStrResByState(state: Int): Int {
when (state) {
STATE_EXPIRED -> return R.string.expired
STATE_FINISH, STATE_CLAIMED -> return R.string.finished
else -> return R.string.ongoing
}
}
private fun getStrColorByState(state: Int): Int {
when (state) {
STATE_EXPIRED -> return R.color.gray_60
STATE_FINISH, STATE_CLAIMED -> return R.color.green_39
else -> return R.color.red_5c
}
}
companion object {

View File

@ -6,6 +6,10 @@ import com.gamedog.vididin.main.fragments.task.BoxTaskRoot
import com.gamedog.vididin.manager.taskbeans.TaskStateBox
import com.gamedog.vididin.manager.taskbeans.TaskStateBoxRoot
import com.gamedog.vididin.manager.taskbeans.TaskStateBoxSub
import com.gamedog.vididin.manager.taskbeans.BaseTaskState.Companion.STATE_FINISH
import com.gamedog.vididin.manager.taskbeans.BaseTaskState.Companion.STATE_ONGOING
import com.gamedog.vididin.manager.taskbeans.BaseTaskState.Companion.STATE_CLAIMED
import com.gamedog.vididin.manager.taskbeans.BaseTaskState.Companion.STATE_EXPIRED
class BoxTaskHelper: BaseTaskHelper<TaskStateBoxRoot, BoxTaskRoot>() {
@ -45,4 +49,74 @@ class BoxTaskHelper: BaseTaskHelper<TaskStateBoxRoot, BoxTaskRoot>() {
return DateUtil.isPeriodExpired(taskStateBoxRoot.startMs, totalDurationDays)
}
private fun isBoxTaskExpired(boxIndex: Int): Boolean {
if (boxIndex >= 0 && boxIndex < mStateBean.tasks.size) {
val curBoxState = mStateBean.tasks[boxIndex]
return DateUtil.isPeriodExpired(mStateBean.startMs, curBoxState.duration_days)
}
return false
}
private fun isBoxAllTasksFinish(boxIndex: Int) : Boolean {
if (boxIndex >= 0 && boxIndex < mStateBean.tasks.size) {
val curBoxState = mStateBean.tasks[boxIndex]
curBoxState.tasks.forEach {
if (it.required_count > it.finishedNum) {
return false
}
}
return true
}
return false
}
fun getCurrentBoxIndex(): Int {
val boxRootStartMs = mStateBean.startMs
mStateBean.tasks.forEachIndexed { index, box ->
if (!DateUtil.isPeriodExpired(boxRootStartMs, box.duration_days)) {
return index
}
}
return -1
}
fun getBoxStateEnum(boxIndex: Int): Int {
if (boxIndex >= 0 && boxIndex < mStateBean.tasks.size) {
val curBoxState = mStateBean.tasks[boxIndex]
if (curBoxState.hasClaimedReward) {
return STATE_CLAIMED
} else {
if (isBoxAllTasksFinish(boxIndex)) {
return STATE_FINISH
} else {
if (isBoxTaskExpired(boxIndex)) {
return STATE_EXPIRED
} else {
return STATE_ONGOING
}
}
}
}
return -1
}
fun getCouldClaimCashNum(): Float {
var waitClaimCashNum = 0F
mStateBean.tasks.forEachIndexed { index, box ->
if (getBoxStateEnum(index) == STATE_FINISH) {
waitClaimCashNum += box.reward_value
}
}
return waitClaimCashNum
}
}

View File

@ -9,5 +9,6 @@ abstract class BaseTaskState {
const val STATE_ONGOING = 0
const val STATE_FINISH = 1
const val STATE_CLAIMED = 2
const val STATE_EXPIRED = 3
}
}

View File

@ -103,6 +103,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/iv_subtask_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/benefit_item_expired"/>
@ -142,9 +143,10 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/iv_subtask_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/benefit_item_ongoing"/>
android:src="@mipmap/benefit_item_finished"/>
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/tv_subtask_2_reward"
android:layout_width="wrap_content"
@ -165,7 +167,7 @@
android:layout_marginTop="6dp"
android:textSize="12sp"
android:textColor="@color/green_39"
android:text="@string/onging"/>
android:text="@string/finished"/>
</LinearLayout>
<!--items-3-->
@ -179,9 +181,10 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/iv_subtask_3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/benefit_item_waitting"/>
android:src="@mipmap/benefit_item_ongoing"/>
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/tv_subtask_3_reward"
@ -205,12 +208,13 @@
android:layout_marginTop="6dp"
android:textSize="12sp"
android:textColor="@color/red_5c"
android:text="@string/waitting"/>
android:text="@string/ongoing"/>
</LinearLayout>
</LinearLayout>
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/tv_resgatar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="25dp"

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 19 KiB

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 21 KiB

View File

@ -44,8 +44,8 @@
<string name="lottery_record">Histórico de Prêmios</string>
<string name="zero_buy">Festa Grátis</string>
<string name="expired">Expirado</string>
<string name="onging">Concluído</string>
<string name="waitting">Em andamento</string>
<string name="finished">Concluído</string>
<string name="ongoing">Em andamento</string>
<string name="benefit_task_top_hint">Conclua todas as tarefas para retirar</string>
<string name="benefit_task_item_description">Assista a notícias ou vídeos curtos por 800 min</string>
<string name="go_and_do">Ir para</string>