Skip to content

Task/hw 3#4

Open
GorlovDanila wants to merge 6 commits intomasterfrom
task/hw-3
Open

Task/hw 3#4
GorlovDanila wants to merge 6 commits intomasterfrom
task/hw-3

Conversation

@GorlovDanila
Copy link
Copy Markdown
Owner

XRecorder_11102022_233014.mp4

super.onViewCreated(view, savedInstanceState)
binding = FragmentMainBinding.bind(view)
if (savedInstanceState != null) {
counter = savedInstanceState.getInt("s")
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

вынести в константу "s"


private fun checkET(editText: EditText): Boolean {
var flag = true
val numberList = listOf(
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

не стоит так хардкодить, для проверки строки на соответствие того, что строка числовая, можно использовать другие методы, посмотрите toIntOrNull в Kotlin или другие способы

var counterDialog = counter
val view =
LayoutInflater.from(requireContext()).inflate(R.layout.dialog_fragment, null, false)
val editText = view.findViewById<EditText>(R.id.et_text)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

использовать view binding вместо findViewById

}

private fun checkET(editText: EditText): Boolean {
var flag = true
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

дублируется метод

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
val counterFromBundle: Int? = arguments?.getInt(ARG_COUNTER_VALUE)
if (counterFromBundle.toString().toInt() in 0..50) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

можно переписать с помощью when
пример: when (counterFromBundle.toString().toInt()) {
in 0..50 -> {...}
in 51..100 -> {...}

100 -> {...}
}

binding = FragmentSecondBinding.bind(view)

binding?.run {
binding!!.tvCounter.text = "Counter value: $counterFromBundle"
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

null safety, заменить !!. на ?.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

и здесь вы уже используете run {}, поэтому нужно убрать часть "binding!!."
binding?.run {
tvCounter.text = "Counter value: $counterFromBundle"
//...
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants