diff --git a/app/src/main/kotlin/org/ntlab/leftoverrecipe/fragment/RegistDialogFragment.kt b/app/src/main/kotlin/org/ntlab/leftoverrecipe/fragment/RegistDialogFragment.kt index 965f673..7028bf0 100644 --- a/app/src/main/kotlin/org/ntlab/leftoverrecipe/fragment/RegistDialogFragment.kt +++ b/app/src/main/kotlin/org/ntlab/leftoverrecipe/fragment/RegistDialogFragment.kt @@ -57,6 +57,7 @@ imageView.visibility = View.VISIBLE this.bitmap = bitmap + imageView.setImageBitmap(bitmap) } } } diff --git a/app/src/main/kotlin/org/ntlab/leftoverrecipe/model/db/RecipeData.kt b/app/src/main/kotlin/org/ntlab/leftoverrecipe/model/db/RecipeData.kt index 60ebb0b..c357a74 100644 --- a/app/src/main/kotlin/org/ntlab/leftoverrecipe/model/db/RecipeData.kt +++ b/app/src/main/kotlin/org/ntlab/leftoverrecipe/model/db/RecipeData.kt @@ -1,12 +1,13 @@ package org.ntlab.leftoverrecipe.model.db import io.realm.RealmObject +import java.util.* /** * Created by matsumoto_k on 2017/07/06. */ open class RecipeData( - //open var date: Date = Date(), + open var date: Date = Date(), open var recipeName: String = "", open var makeTimeZone: String = "", open var comment: String = "", diff --git a/app/src/main/kotlin/org/ntlab/leftoverrecipe/viewmodel/RegistDialogViewModel.kt b/app/src/main/kotlin/org/ntlab/leftoverrecipe/viewmodel/RegistDialogViewModel.kt index 37040b3..ff156c3 100644 --- a/app/src/main/kotlin/org/ntlab/leftoverrecipe/viewmodel/RegistDialogViewModel.kt +++ b/app/src/main/kotlin/org/ntlab/leftoverrecipe/viewmodel/RegistDialogViewModel.kt @@ -5,12 +5,16 @@ import android.databinding.BaseObservable import android.databinding.Bindable import android.databinding.ObservableField +import android.databinding.ObservableInt +import android.graphics.Bitmap import android.view.View import android.widget.Toast import org.ntlab.leftoverrecipe.api.recipe.RecipeApiResponse import org.ntlab.leftoverrecipe.contract.RegistDialogViewContract import org.ntlab.leftoverrecipe.model.db.RecipeData import org.ntlab.leftoverrecipe.model.db.RecipeDataRealm +import org.ntlab.leftoverrecipe.util.BitmapUtil +import java.util.* /** * Created by matsumoto_k on 2017/05/20. @@ -25,6 +29,11 @@ @Bindable var comment = ObservableField() + @Bindable + var selectedPosition = ObservableInt() + + var bitmap: Bitmap? = null + init { recipeTitle.set(recipeData.recipeTitle) println(recipeData.recipeTitle) @@ -35,8 +44,22 @@ //記録する val recipeData = RecipeData() - recipeData.recipeName = recipeName.get() - recipeData.comment = comment.get() + + val cal = Calendar.getInstance() + cal.timeInMillis = System.currentTimeMillis() + + recipeData.date = cal.time + + if (recipeName.get() != null) + recipeData.recipeName = recipeName.get() + if (comment.get() != null) + recipeData.comment = comment.get() + if (bitmap != null) + recipeData.image = BitmapUtil.createImageByteArray(this.bitmap!!) + if (selectedPosition.get() != null) { + println(selectedPosition.get()) + } + RecipeDataRealm.insert(recipeData) println(comment.get()) diff --git a/app/src/main/res/layout/fragment_regist_dialog.xml b/app/src/main/res/layout/fragment_regist_dialog.xml index 4cb4d7f..07b9aae 100644 --- a/app/src/main/res/layout/fragment_regist_dialog.xml +++ b/app/src/main/res/layout/fragment_regist_dialog.xml @@ -63,6 +63,7 @@ android:layout_marginStart="8dp" android:layout_marginTop="8dp" android:entries="@array/spinner_values" + android:selectedItemPosition="@={viewModel.selectedPosition}" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/editText" tools:layout_editor_absoluteY="85dp"> @@ -84,6 +85,7 @@ android:layout_height="300dp" android:layout_marginStart="8dp" android:layout_marginTop="8dp" + android:adjustViewBounds="true" android:visibility="gone" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/dialogCaptureButton" />