リビジョン 4116efde
| learn/android/TempRecorderJetpackKt/.idea/misc.xml | ||
|---|---|---|
|
<?xml version="1.0" encoding="UTF-8"?>
|
||
|
<project version="4">
|
||
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
||
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
||
|
<output url="file://$PROJECT_DIR$/build/classes" />
|
||
|
</component>
|
||
|
<component name="ProjectType">
|
||
| learn/android/TempRecorderJetpackKt/app/build.gradle | ||
|---|---|---|
|
|
||
|
defaultConfig {
|
||
|
applicationId "com.torutk.android.temprecorder.jetpackkt"
|
||
|
minSdkVersion 19
|
||
|
minSdkVersion 29
|
||
|
targetSdkVersion 30
|
||
|
versionCode 1
|
||
|
versionName "1.0"
|
||
| ... | ... | |
|
buildFeatures {
|
||
|
viewBinding true
|
||
|
}
|
||
|
compileOptions {
|
||
|
targetCompatibility JavaVersion.VERSION_1_8
|
||
|
sourceCompatibility JavaVersion.VERSION_1_8
|
||
|
}
|
||
|
kotlinOptions {
|
||
|
jvmTarget = "1.8"
|
||
|
}
|
||
|
}
|
||
|
|
||
|
dependencies {
|
||
|
implementation fileTree(dir: "libs", include: ["*.jar"])
|
||
|
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
||
|
implementation 'androidx.core:core-ktx:1.3.1'
|
||
|
implementation 'androidx.activity:activity-ktx:1.1.0'
|
||
|
implementation 'androidx.appcompat:appcompat:1.2.0'
|
||
|
implementation 'androidx.constraintlayout:constraintlayout:2.0.1'
|
||
|
implementation 'androidx.recyclerview:recyclerview:1.1.0'
|
||
| learn/android/TempRecorderJetpackKt/app/src/main/java/com/torutk/android/temprecorder/jetpackkt/MainActivity.kt | ||
|---|---|---|
|
package com.torutk.android.temprecorder.jetpackkt
|
||
|
|
||
|
import android.os.Bundle
|
||
|
import androidx.activity.viewModels
|
||
|
import androidx.appcompat.app.AppCompatActivity
|
||
|
import androidx.lifecycle.Observer
|
||
|
import androidx.lifecycle.ViewModelProvider
|
||
|
import com.torutk.android.temprecorder.jetpackkt.databinding.ActivityMainBinding
|
||
|
import kotlinx.android.synthetic.main.activity_main.*
|
||
|
import java.time.LocalDateTime
|
||
|
import java.time.format.DateTimeFormatter
|
||
|
|
||
|
// 検温日時の表示形式を定義
|
||
|
internal val DATE_TIME_VIEW_FORMATTER = DateTimeFormatter.ofPattern("MM.dd HH:mm")
|
||
|
|
||
|
class MainActivity : AppCompatActivity() {
|
||
|
private lateinit var binding: ActivityMainBinding
|
||
|
|
||
|
private lateinit var binding: ActivityMainBinding // ViewBinding
|
||
|
private val model: MainViewModel by viewModels() // ViewModel
|
||
|
|
||
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||
|
super.onCreate(savedInstanceState)
|
||
|
binding = ActivityMainBinding.inflate(layoutInflater)
|
||
|
setContentView(binding.root)
|
||
|
|
||
|
// 検温日時の変更監視と表示設定
|
||
|
val measuredAtObserver = Observer<LocalDateTime> {
|
||
|
binding.textviewMainMeasuredat.text = it.format(DATE_TIME_VIEW_FORMATTER)
|
||
|
}
|
||
|
model.measuredAt.observe(this, measuredAtObserver)
|
||
|
// 検温日時の増減操作
|
||
|
binding.buttonMainIncminite.setOnClickListener {
|
||
|
model.measuredAt.value = model.measuredAt.value?.plusMinutes(10)
|
||
|
}
|
||
|
binding.buttonMainDecminite.setOnClickListener {
|
||
|
model.measuredAt.value = model.measuredAt.value?.minusMinutes(10)
|
||
|
}
|
||
|
|
||
|
// 体温入力用のNumberPicker設定
|
||
|
with (binding.numberpickerMainIntegral) {
|
||
|
minValue = 35
|
||
|
maxValue = 40
|
||
| ... | ... | |
|
value = 5
|
||
|
}
|
||
|
}
|
||
|
|
||
|
override fun onResume() {
|
||
|
super.onResume()
|
||
|
model.measuredAt.value = LocalDateTime.now()
|
||
|
}
|
||
|
}
|
||
| learn/android/TempRecorderJetpackKt/app/src/main/java/com/torutk/android/temprecorder/jetpackkt/MainViewModel.kt | ||
|---|---|---|
|
package com.torutk.android.temprecorder.jetpackkt
|
||
|
|
||
|
import androidx.lifecycle.MutableLiveData
|
||
|
import androidx.lifecycle.ViewModel
|
||
|
import java.time.LocalDateTime
|
||
|
|
||
|
class MainViewModel : ViewModel() {
|
||
|
val measuredAt: MutableLiveData<LocalDateTime> = MutableLiveData(LocalDateTime.now())
|
||
|
}
|
||
refs #167 Add ViewModel with measuredAt