Open
Conversation
NailShaykhrazievItis
suggested changes
Jan 8, 2023
| super.onViewCreated(view, savedInstanceState) | ||
| binding = FragmentMainBinding.bind(view) | ||
| if (savedInstanceState != null) { | ||
| counter = savedInstanceState.getInt("s") |
|
|
||
| private fun checkET(editText: EditText): Boolean { | ||
| var flag = true | ||
| val numberList = listOf( |
There was a problem hiding this comment.
не стоит так хардкодить, для проверки строки на соответствие того, что строка числовая, можно использовать другие методы, посмотрите 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) |
There was a problem hiding this comment.
использовать view binding вместо findViewById
| } | ||
|
|
||
| private fun checkET(editText: EditText): Boolean { | ||
| var flag = true |
| 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) { |
There was a problem hiding this comment.
можно переписать с помощью when
пример: when (counterFromBundle.toString().toInt()) {
in 0..50 -> {...}
in 51..100 -> {...}
100 -> {...}
}
| binding = FragmentSecondBinding.bind(view) | ||
|
|
||
| binding?.run { | ||
| binding!!.tvCounter.text = "Counter value: $counterFromBundle" |
There was a problem hiding this comment.
null safety, заменить !!. на ?.
There was a problem hiding this comment.
и здесь вы уже используете run {}, поэтому нужно убрать часть "binding!!."
binding?.run {
tvCounter.text = "Counter value: $counterFromBundle"
//...
}
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
XRecorder_11102022_233014.mp4