diff --git a/.idea/misc.xml b/.idea/misc.xml index 726c172..5292b8d 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -13,9 +13,9 @@ - + - + diff --git a/app/src/main/java/com/example/acapendulum20/canvas/CanvasPendulum.kt b/app/src/main/java/com/example/acapendulum20/canvas/CanvasPendulum.kt index a4fcae1..0fa4b7b 100644 --- a/app/src/main/java/com/example/acapendulum20/canvas/CanvasPendulum.kt +++ b/app/src/main/java/com/example/acapendulum20/canvas/CanvasPendulum.kt @@ -53,7 +53,6 @@ class CanvasPendulum @JvmOverloads constructor( ) //draw sensor left - paint.style = Paint.Style.FILL_AND_STROKE paint.strokeWidth = 1f paint.color = Color.RED @@ -67,7 +66,6 @@ class CanvasPendulum @JvmOverloads constructor( canvas?.drawCircle((width / 3).toFloat(), 910f, 30f, paint) //draw sensor right - paint.style = Paint.Style.FILL_AND_STROKE paint.strokeWidth = 1f paint.color = Color.RED diff --git a/app/src/main/java/com/example/acapendulum20/data/MeasurementDao.kt b/app/src/main/java/com/example/acapendulum20/data/MeasurementDao.kt index 75b3b54..42e932d 100644 --- a/app/src/main/java/com/example/acapendulum20/data/MeasurementDao.kt +++ b/app/src/main/java/com/example/acapendulum20/data/MeasurementDao.kt @@ -1,4 +1,15 @@ package com.example.acapendulum20.data -class MeasurementDao { +import androidx.lifecycle.LiveData +import androidx.room.* +import com.example.acapendulum20.model.Measurement +import com.example.acapendulum20.model.User + +@Dao +interface MeasurementDao { + + @Insert(onConflict = OnConflictStrategy.IGNORE ) + fun addMeasurement(measurement: Measurement) + + } \ No newline at end of file diff --git a/app/src/main/java/com/example/acapendulum20/data/MeasurementDatabase.kt b/app/src/main/java/com/example/acapendulum20/data/MeasurementDatabase.kt index 61bb5d7..136d79b 100644 --- a/app/src/main/java/com/example/acapendulum20/data/MeasurementDatabase.kt +++ b/app/src/main/java/com/example/acapendulum20/data/MeasurementDatabase.kt @@ -1,4 +1,35 @@ package com.example.acapendulum20.data -class MeasurementDatabase { +import android.content.Context +import android.icu.util.Measure +import androidx.room.Database +import androidx.room.Room +import androidx.room.RoomDatabase +import com.example.acapendulum20.model.User +import com.example.acapendulum20.model.Measurement + +@Database(entities = [Measurement::class], version = 1, exportSchema = false) +abstract class MeasurementDatabase: RoomDatabase() { + abstract fun measurementDao(): MeasurementDao + + companion object { + @Volatile + private var INSTANCE: MeasurementDatabase? = null + + fun getDatabase(context: Context): MeasurementDatabase{ + val tempInstance = INSTANCE + if(tempInstance != null){ + return tempInstance + } + synchronized(this){ + val instance = Room.databaseBuilder( + context.applicationContext, + MeasurementDatabase::class.java, + "measurement_database" + ).build() + INSTANCE = instance + return instance + } + } + } } \ No newline at end of file diff --git a/app/src/main/java/com/example/acapendulum20/fragments/add/AddFragment.kt b/app/src/main/java/com/example/acapendulum20/fragments/add/AddFragment.kt index 769cd97..cde7400 100644 --- a/app/src/main/java/com/example/acapendulum20/fragments/add/AddFragment.kt +++ b/app/src/main/java/com/example/acapendulum20/fragments/add/AddFragment.kt @@ -33,20 +33,19 @@ class AddFragment : Fragment() { view.add_btn.setOnClickListener{ insertDataToDatabase() } - return view } private fun insertDataToDatabase() { val firstName = addFirstName_et.text.toString() val lastName = addLastName_et.text.toString() - val age = addAge_et.text + val age = addAge_et.text.toString() val sex = addSex_et.text.toString() val handiness = addHandiness_et.text.toString() if(inputCheck(firstName, lastName, sex, handiness, age)){ - //Create User Objeect - val user = User(UUID.randomUUID().toString(), firstName, lastName,Integer.parseInt(age.toString()), sex, handiness) + //Create User Object + val user = User(UUID.randomUUID().toString(), firstName, lastName,Integer.parseInt(age), sex, handiness) //Add Data to Database mUserViewModel.addUser(user) Toast.makeText(requireContext(),"Successfully added!", Toast.LENGTH_LONG).show() @@ -57,8 +56,8 @@ class AddFragment : Fragment() { } } - private fun inputCheck(firstName: String, lastName: String, sex: String, handiness:String, age: Editable): Boolean{ - return !(TextUtils.isEmpty(firstName) && TextUtils.isEmpty(lastName) && TextUtils.isEmpty(sex) && TextUtils.isEmpty(handiness) && age.isEmpty()) + private fun inputCheck(firstName: String, lastName: String, sex: String, handiness: String, age: String): Boolean{ + val validated = !TextUtils.isEmpty(firstName) && !TextUtils.isEmpty(lastName) && !TextUtils.isEmpty(sex) && !TextUtils.isEmpty(handiness) && !age.isEmpty() + return validated } - } \ No newline at end of file diff --git a/app/src/main/java/com/example/acapendulum20/fragments/list/ListFragment.kt b/app/src/main/java/com/example/acapendulum20/fragments/list/ListFragment.kt index 737fdbf..a72a821 100644 --- a/app/src/main/java/com/example/acapendulum20/fragments/list/ListFragment.kt +++ b/app/src/main/java/com/example/acapendulum20/fragments/list/ListFragment.kt @@ -37,7 +37,6 @@ class ListFragment : Fragment() { adapter.setData(user) }) - view.floatingActionButton.setOnClickListener { findNavController().navigate(R.id.action_listFragment_to_addFragment) } diff --git a/app/src/main/java/com/example/acapendulum20/fragments/pendulum/PendulumFragment.kt b/app/src/main/java/com/example/acapendulum20/fragments/pendulum/PendulumFragment.kt index f75d0fb..985c004 100644 --- a/app/src/main/java/com/example/acapendulum20/fragments/pendulum/PendulumFragment.kt +++ b/app/src/main/java/com/example/acapendulum20/fragments/pendulum/PendulumFragment.kt @@ -2,19 +2,29 @@ package com.example.acapendulum20.fragments.pendulum import android.annotation.SuppressLint import android.os.Bundle +import android.os.CountDownTimer import android.view.LayoutInflater import android.view.MotionEvent import android.view.View import android.view.View.OnTouchListener import android.view.ViewGroup import android.widget.Button +import android.widget.TextView import androidx.fragment.app.Fragment +import androidx.navigation.fragment.navArgs import com.example.acapendulum20.R import com.example.acapendulum20.canvas.CanvasPendulum +import com.example.acapendulum20.viewmodel.MeasurementViewmodel +import kotlinx.android.synthetic.main.fragment_pendulum.* +import java.time.LocalDateTime class PendulumFragment : Fragment() { + private val args by navArgs() + + private lateinit var mMeasurementViewmodel: MeasurementViewmodel + @SuppressLint("ClickableViewAccessibility") override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, @@ -27,11 +37,29 @@ class PendulumFragment : Fragment() { //activate the magnet val button = view.findViewById