Databinding
This commit is contained in:
1
.idea/gradle.xml
generated
1
.idea/gradle.xml
generated
@@ -1,5 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<project version="4">
|
||||||
|
<component name="GradleMigrationSettings" migrationVersion="1" />
|
||||||
<component name="GradleSettings">
|
<component name="GradleSettings">
|
||||||
<option name="linkedExternalProjectsSettings">
|
<option name="linkedExternalProjectsSettings">
|
||||||
<GradleProjectSettings>
|
<GradleProjectSettings>
|
||||||
|
|||||||
@@ -20,6 +20,10 @@ android {
|
|||||||
enabled = true
|
enabled = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dataBinding {
|
||||||
|
enabled = true
|
||||||
|
}
|
||||||
|
|
||||||
buildTypes {
|
buildTypes {
|
||||||
release {
|
release {
|
||||||
minifyEnabled false
|
minifyEnabled false
|
||||||
|
|||||||
@@ -1,15 +1,42 @@
|
|||||||
package dev.andrewkemp.aboutme
|
package dev.andrewkemp.aboutme
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import android.view.View
|
||||||
|
import android.view.inputmethod.InputMethodManager
|
||||||
|
import androidx.databinding.DataBindingUtil
|
||||||
import dev.andrewkemp.aboutme.databinding.ActivityMainBinding
|
import dev.andrewkemp.aboutme.databinding.ActivityMainBinding
|
||||||
|
import kotlinx.android.synthetic.main.activity_main.*
|
||||||
|
|
||||||
class MainActivity : AppCompatActivity() {
|
class MainActivity : AppCompatActivity() {
|
||||||
private lateinit var binding: ActivityMainBinding
|
private lateinit var binding: ActivityMainBinding
|
||||||
|
|
||||||
|
private var myName: MyName = MyName("Andrew Kemp")
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
binding = ActivityMainBinding.inflate(layoutInflater)
|
binding = DataBindingUtil.setContentView(this, R.layout.activity_main)
|
||||||
setContentView(R.layout.activity_main)
|
binding.myName = myName
|
||||||
|
done_button.setOnClickListener {
|
||||||
|
addNickname(it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun addNickname(view: View) {
|
||||||
|
binding.apply {
|
||||||
|
myName?.nickname = nicknameEdit.text.toString()
|
||||||
|
invalidateAll()
|
||||||
|
nicknameEdit.visibility = View.GONE
|
||||||
|
doneButton.visibility = View.GONE
|
||||||
|
nicknameText.visibility = View.VISIBLE
|
||||||
|
}
|
||||||
|
|
||||||
|
hideKeyboard(view)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun hideKeyboard(view: View) {
|
||||||
|
var imm = getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
|
||||||
|
imm.hideSoftInputFromWindow(view.windowToken, 0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
3
app/src/main/java/dev/andrewkemp/aboutme/MyName.kt
Normal file
3
app/src/main/java/dev/andrewkemp/aboutme/MyName.kt
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
package dev.andrewkemp.aboutme
|
||||||
|
|
||||||
|
data class MyName(var name: String = "", var nickname: String = "")
|
||||||
@@ -1,6 +1,15 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<layout
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||||
|
|
||||||
|
<data>
|
||||||
|
<variable
|
||||||
|
name="myName"
|
||||||
|
type="dev.andrewkemp.aboutme.MyName" />
|
||||||
|
</data>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
@@ -12,9 +21,39 @@
|
|||||||
style="@style/NameStyle"
|
style="@style/NameStyle"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="@string/andrew_kemp"
|
android:text="@={myName.name}"
|
||||||
android:textAlignment="center" />
|
android:textAlignment="center" />
|
||||||
|
|
||||||
|
<EditText
|
||||||
|
android:id="@+id/nickname_edit"
|
||||||
|
style="@style/NameStyle"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:ems="10"
|
||||||
|
android:hint="@string/what_is_your_nickname"
|
||||||
|
android:importantForAutofill="no"
|
||||||
|
android:inputType="textMultiLine|textPersonName"
|
||||||
|
android:textAlignment="center" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/done_button"
|
||||||
|
style="@style/Widget.AppCompat.Button.Colored"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center_horizontal"
|
||||||
|
android:layout_marginTop="@dimen/layout_margin"
|
||||||
|
android:fontFamily="@font/roboto"
|
||||||
|
android:text="@string/done" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/nickname_text"
|
||||||
|
style="@style/NameStyle"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@={myName.nickname}"
|
||||||
|
android:textAlignment="center"
|
||||||
|
android:visibility="gone" />
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:id="@+id/star_image"
|
android:id="@+id/star_image"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
@@ -38,3 +77,4 @@
|
|||||||
</ScrollView>
|
</ScrollView>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
</layout>
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
<resources>
|
<resources>
|
||||||
<string name="app_name">About Me</string>
|
<string name="app_name">About Me</string>
|
||||||
<string name="andrew_kemp">Andrew Kemp</string>
|
|
||||||
<string name="yellow_star">Yellow Star</string>
|
<string name="yellow_star">Yellow Star</string>
|
||||||
<string name="bio">
|
<string name="bio">
|
||||||
Hi, my name is Andrew!
|
Hi, my name is Andrew!
|
||||||
@@ -10,4 +9,6 @@
|
|||||||
\n\u2022 Avid video gamer, and world traveler
|
\n\u2022 Avid video gamer, and world traveler
|
||||||
\n\u2022 purveyor of marine life, and avid scuba diver
|
\n\u2022 purveyor of marine life, and avid scuba diver
|
||||||
</string>
|
</string>
|
||||||
|
<string name="what_is_your_nickname">What is your nickname?</string>
|
||||||
|
<string name="done">Done</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
Reference in New Issue
Block a user