-
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package com.example.kotlinhomework | ||
|
||
import android.annotation.SuppressLint | ||
import android.app.Activity | ||
import android.content.Intent | ||
import android.os.Bundle | ||
import android.widget.Button | ||
import android.widget.TextView | ||
import androidx.appcompat.app.AppCompatActivity | ||
|
||
|
||
class MainActivity2 : AppCompatActivity() { | ||
|
||
private lateinit var greetings: String | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. lateinit - хорошо! Очень полезный делегат, часто используется |
||
private lateinit var name: String | ||
private lateinit var textView: TextView | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more. вот так посимпатичнее: |
||
savedInstanceState.getString(NAME_KEY)!! | ||
else getString(R.string.anon) | ||
|
||
textView = findViewById(R.id.textViewHello) | ||
val button: Button = findViewById(R.id.buttonNameYourSelf) | ||
|
||
button.setOnClickListener { | ||
val intent = Intent(this@MainActivity2, SecondActivity2::class.java) | ||
startActivityForResult(intent, SecondActivity2.GET_NAME_REQUEST_CODE) | ||
} | ||
} | ||
|
||
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { | ||
super.onActivityResult(requestCode, resultCode, data) | ||
|
||
if (requestCode == SecondActivity2.GET_NAME_REQUEST_CODE && resultCode == Activity.RESULT_OK && data != null){ | ||
val nameFromData = data.getStringExtra(SecondActivity2.NAME_KEY) | ||
if(nameFromData != null) | ||
name = nameFromData | ||
} | ||
|
||
} | ||
|
||
@SuppressLint("SetTextI18n") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. лучше всё-таки послушаться компилятора и оставить String.format("%s, %s!", greetings, name) |
||
override fun onResume() { | ||
super.onResume() | ||
textView.text = "$greetings, $name!" | ||
|
||
} | ||
|
||
override fun onSaveInstanceState(outState: Bundle) { | ||
super.onSaveInstanceState(outState) | ||
outState.putString(NAME_KEY, 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 commentThe reason will be displayed to describe this comment to others. Learn more. private потерялся private |
||
} | ||
} |
This file was deleted.
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.
:+ лучше избегать
стоит выбрать самую послденюю актуальную версию и далее обновлять мануально. Всё новое может стать в какой-то момент слишком новым и несовместимым.