chore: simplify progress item initialization and error message handling #226
1 changed files with 16 additions and 37 deletions
|
@ -7,6 +7,7 @@ import android.view.ViewGroup
|
||||||
import android.widget.ImageView
|
import android.widget.ImageView
|
||||||
import android.widget.ProgressBar
|
import android.widget.ProgressBar
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
|
import androidx.annotation.StringRes
|
||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
import androidx.recyclerview.widget.DividerItemDecoration
|
import androidx.recyclerview.widget.DividerItemDecoration
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
|
@ -42,37 +43,17 @@ class DownloadWizardProgressFragment : DownloadWizardActivity.DownloadWizardStep
|
||||||
}
|
}
|
||||||
|
|
||||||
private data class ProgressItem(
|
private data class ProgressItem(
|
||||||
val titleRes: Int,
|
@StringRes val titleRes: Int,
|
||||||
var state: ProgressState,
|
var state: ProgressState = ProgressState.NotStarted,
|
||||||
var errorMessage: SimplifiedErrorMessages?,
|
var errorMessage: SimplifiedErrorMessages? = null,
|
||||||
)
|
)
|
||||||
|
|
||||||
private val progressItems = arrayOf(
|
private val progressItems = arrayOf(
|
||||||
ProgressItem(
|
ProgressItem(R.string.download_wizard_progress_step_preparing),
|
||||||
R.string.download_wizard_progress_step_preparing,
|
ProgressItem(R.string.download_wizard_progress_step_connecting),
|
||||||
ProgressState.NotStarted,
|
ProgressItem(R.string.download_wizard_progress_step_authenticating),
|
||||||
null
|
ProgressItem(R.string.download_wizard_progress_step_downloading),
|
||||||
),
|
ProgressItem(R.string.download_wizard_progress_step_finalizing)
|
||||||
ProgressItem(
|
|
||||||
R.string.download_wizard_progress_step_connecting,
|
|
||||||
ProgressState.NotStarted,
|
|
||||||
null
|
|
||||||
),
|
|
||||||
ProgressItem(
|
|
||||||
R.string.download_wizard_progress_step_authenticating,
|
|
||||||
ProgressState.NotStarted,
|
|
||||||
null
|
|
||||||
),
|
|
||||||
ProgressItem(
|
|
||||||
R.string.download_wizard_progress_step_downloading,
|
|
||||||
ProgressState.NotStarted,
|
|
||||||
null
|
|
||||||
),
|
|
||||||
ProgressItem(
|
|
||||||
R.string.download_wizard_progress_step_finalizing,
|
|
||||||
ProgressState.NotStarted,
|
|
||||||
null
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
private val adapter = ProgressItemAdapter()
|
private val adapter = ProgressItemAdapter()
|
||||||
|
@ -156,9 +137,8 @@ class DownloadWizardProgressFragment : DownloadWizardActivity.DownloadWizardStep
|
||||||
refreshButtons()
|
refreshButtons()
|
||||||
}
|
}
|
||||||
|
|
||||||
is EuiccChannelManagerService.ForegroundTaskState.InProgress -> {
|
is EuiccChannelManagerService.ForegroundTaskState.InProgress ->
|
||||||
updateProgress(it.progress)
|
updateProgress(it.progress)
|
||||||
}
|
|
||||||
|
|
||||||
else -> {}
|
else -> {}
|
||||||
}
|
}
|
||||||
|
@ -252,14 +232,13 @@ class DownloadWizardProgressFragment : DownloadWizardActivity.DownloadWizardStep
|
||||||
icon.setImageResource(R.drawable.ic_error_outline)
|
icon.setImageResource(R.drawable.ic_error_outline)
|
||||||
icon.visibility = View.VISIBLE
|
icon.visibility = View.VISIBLE
|
||||||
|
|
||||||
if (item.errorMessage != null) {
|
item.errorMessage?.titleResId?.let {
|
||||||
errorTitle.visibility = View.VISIBLE
|
errorTitle.visibility = View.VISIBLE
|
||||||
errorTitle.text = getString(item.errorMessage!!.titleResId)
|
errorTitle.text = getString(it)
|
||||||
|
}
|
||||||
if (item.errorMessage!!.suggestResId != null) {
|
item.errorMessage?.suggestResId?.let {
|
||||||
errorSuggestion.visibility = View.VISIBLE
|
errorSuggestion.visibility = View.VISIBLE
|
||||||
errorSuggestion.text = getString(item.errorMessage!!.suggestResId!!)
|
errorSuggestion.text = getString(it)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue