-
Notifications
You must be signed in to change notification settings - Fork 13
Translation from java to kotlin was done #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
@@ -0,0 +1 @@ | |||
KotlinHomeWork No newline at end of file |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Лучше .idea добавить в gitignore
|
||
class MainActivity2 : AppCompatActivity() { | ||
|
||
private lateinit var greetings: String |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lateinit - хорошо!
Здесь можно сделать ещё лучше, если написать
private val greetings: String by lazy { getString(R.string.hello) }
тогда greeting проинициализируется при первом обращении, которое случится, когда context уже будет.
Очень полезный делегат, часто используется
setContentView(R.layout.activity_main) | ||
|
||
greetings = getString(R.string.hello) | ||
name = if(savedInstanceState?.getString(NAME_KEY) != null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
вот так посимпатичнее:
name = savedInstanceState?.getString(NAME_KEY) ?: getString(R.string.anon)
|
||
} | ||
|
||
@SuppressLint("SetTextI18n") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
лучше всё-таки послушаться компилятора и оставить String.format("%s, %s!", greetings, name)
} | ||
|
||
companion object{ | ||
const val NAME_KEY: String = "com.example.kotlinhomework.MainActivity.NAME_KEY" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
private потерялся private
testImplementation 'junit:junit:4.+' | ||
androidTestImplementation 'androidx.test.ext:junit:1.1.2' | ||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' | ||
implementation "androidx.core:core-ktx:+" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ты используешь что-то из этого пакета?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:+ лучше избегать
стоит выбрать самую послденюю актуальную версию и далее обновлять мануально. Всё новое может стать в какой-то момент слишком новым и несовместимым.
No description provided.