Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .idea/jarRepositories.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ plugins {
id 'com.android.application'
}

apply plugin: 'kotlin-android'

android {
compileSdkVersion 30

Expand Down Expand Up @@ -35,4 +37,9 @@ dependencies {
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:+"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}
repositories {
mavenCentral()
}
69 changes: 0 additions & 69 deletions app/src/main/java/com/example/kotlinhomework/MainActivity.java

This file was deleted.

52 changes: 52 additions & 0 deletions app/src/main/java/com/example/kotlinhomework/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package com.example.kotlinhomework

import android.content.Intent
import android.os.Bundle
import android.widget.Button
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity

class MainActivity : AppCompatActivity() {
private var greetings: String? = null
private var name: String? = null
private var textView: TextView? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
greetings = getString(R.string.hello)
name = savedInstanceState?.getString(NAME_KEY) ?: getString(R.string.anon)
textView = findViewById(R.id.textViewHello)
val button = findViewById<Button>(R.id.buttonNameYourSelf)
button.setOnClickListener {
val intent = Intent(this@MainActivity, com.example.kotlinhomework.SecondActivity::class.java)
startActivityForResult(intent, com.example.kotlinhomework.SecondActivity.GET_NAME_REQUEST_CODE)
}
}

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if (requestCode == com.example.kotlinhomework.SecondActivity.GET_NAME_REQUEST_CODE && resultCode == RESULT_OK)
name = data?.getStringExtra(com.example.kotlinhomework.SecondActivity.NAME_KEY) ?: name
}

override fun onResume() {
super.onResume()
textView!!.text = String.format(
"%s, %s!",
greetings,
name
)
}

override fun onSaveInstanceState(outState: Bundle) {
super.onSaveInstanceState(outState)
outState.putString(
NAME_KEY,
name,
)
}

companion object {
private const val NAME_KEY = "com.example.kotlinhomework.MainActivity.NAME_KEY"
}
}
57 changes: 0 additions & 57 deletions app/src/main/java/com/example/kotlinhomework/SecondActivity.java

This file was deleted.

47 changes: 47 additions & 0 deletions app/src/main/java/com/example/kotlinhomework/SecondActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.example.kotlinhomework

import android.content.Intent
import android.os.Bundle
import android.text.Editable
import android.text.TextUtils
import android.text.TextWatcher
import android.view.View
import android.widget.Button
import android.widget.EditText
import androidx.appcompat.app.AppCompatActivity

class SecondActivity : AppCompatActivity() {
private var editText: EditText? = null
private var button: Button? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_second)
editText = findViewById(R.id.editTextTextPersonName)
button = findViewById(R.id.buttonName)
button?.isEnabled = false
editText?.addTextChangedListener(object : TextWatcher {
override fun beforeTextChanged(charSequence: CharSequence, i: Int, i1: Int, i2: Int) {
// Nothing to do
}

override fun onTextChanged(charSequence: CharSequence, i: Int, i1: Int, i2: Int) {
// Nothing to do
}

override fun afterTextChanged(editable: Editable) {
button?.isEnabled = !TextUtils.isEmpty(editable)
}
})
button?.setOnClickListener(View.OnClickListener {
val intent = Intent()
intent.putExtra(NAME_KEY, editText?.text.toString())
setResult(RESULT_OK, intent)
finish()
})
}

companion object {
const val NAME_KEY = "com.example.kotlinhomework.SecondActivity.NAME_KEY"
const val GET_NAME_REQUEST_CODE = 1234
}
}
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = '1.4.21'
repositories {
google()
jcenter()
}
dependencies {
classpath "com.android.tools.build:gradle:7.0.0-alpha02"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down