Browse Source

Pendel Logic READY

Pendelsession information save in profile in progress
new fragment "fragment_start_pendulum" finished
last step save Data from Pendulum in Profil
master
Feyzu 3 years ago
parent
commit
ae0daffd0b
18 changed files with 272 additions and 98 deletions
  1. +2
    -1
      .idea/misc.xml
  2. +5
    -2
      app/src/main/AndroidManifest.xml
  3. +9
    -2
      app/src/main/java/com/example/acapendulum20/canvas/CanvasPendulum.kt
  4. +9
    -0
      app/src/main/java/com/example/acapendulum20/data/MeasurementDao.kt
  5. +8
    -8
      app/src/main/java/com/example/acapendulum20/data/PendulumDatabase.kt
  6. +0
    -33
      app/src/main/java/com/example/acapendulum20/data/UserDatabase.kt
  7. +30
    -12
      app/src/main/java/com/example/acapendulum20/fragments/pendulum/PendulumFragment.kt
  8. +10
    -4
      app/src/main/java/com/example/acapendulum20/fragments/pendulum/StartPendulumFragment.kt
  9. +49
    -0
      app/src/main/java/com/example/acapendulum20/fragments/update/SessionList.kt
  10. +21
    -3
      app/src/main/java/com/example/acapendulum20/fragments/update/UpdateFragment.kt
  11. +6
    -13
      app/src/main/java/com/example/acapendulum20/model/Measurement.kt
  12. +0
    -1
      app/src/main/java/com/example/acapendulum20/model/User.kt
  13. +10
    -0
      app/src/main/java/com/example/acapendulum20/repository/MeasurementRepository.kt
  14. +17
    -8
      app/src/main/java/com/example/acapendulum20/viewmodel/MeasurementViewmodel.kt
  15. +2
    -2
      app/src/main/java/com/example/acapendulum20/viewmodel/UserViewmodel.kt
  16. +85
    -0
      app/src/main/res/layout/custom_row_measurement.xml
  17. +2
    -2
      app/src/main/res/layout/fragment_pendulum.xml
  18. +7
    -7
      app/src/main/res/navigation/my_nav.xml

+ 2
- 1
.idea/misc.xml View File

@ -11,9 +11,10 @@
<entry key="..\:/Users/Feyzu/AndroidStudioProjects/acaPendulum20/app/src/main/res/drawable/ic_launcher_background.xml" value="0.17" /> <entry key="..\:/Users/Feyzu/AndroidStudioProjects/acaPendulum20/app/src/main/res/drawable/ic_launcher_background.xml" value="0.17" />
<entry key="..\:/Users/Feyzu/AndroidStudioProjects/acaPendulum20/app/src/main/res/layout/activity_main.xml" value="0.29713114754098363" /> <entry key="..\:/Users/Feyzu/AndroidStudioProjects/acaPendulum20/app/src/main/res/layout/activity_main.xml" value="0.29713114754098363" />
<entry key="..\:/Users/Feyzu/AndroidStudioProjects/acaPendulum20/app/src/main/res/layout/custom_row.xml" value="0.384375" /> <entry key="..\:/Users/Feyzu/AndroidStudioProjects/acaPendulum20/app/src/main/res/layout/custom_row.xml" value="0.384375" />
<entry key="..\:/Users/Feyzu/AndroidStudioProjects/acaPendulum20/app/src/main/res/layout/custom_row_measurement.xml" value="0.5" />
<entry key="..\:/Users/Feyzu/AndroidStudioProjects/acaPendulum20/app/src/main/res/layout/fragment_add.xml" value="0.45416666666666666" /> <entry key="..\:/Users/Feyzu/AndroidStudioProjects/acaPendulum20/app/src/main/res/layout/fragment_add.xml" value="0.45416666666666666" />
<entry key="..\:/Users/Feyzu/AndroidStudioProjects/acaPendulum20/app/src/main/res/layout/fragment_list.xml" value="0.45416666666666666" /> <entry key="..\:/Users/Feyzu/AndroidStudioProjects/acaPendulum20/app/src/main/res/layout/fragment_list.xml" value="0.45416666666666666" />
<entry key="..\:/Users/Feyzu/AndroidStudioProjects/acaPendulum20/app/src/main/res/layout/fragment_pendulum.xml" value="0.1" />
<entry key="..\:/Users/Feyzu/AndroidStudioProjects/acaPendulum20/app/src/main/res/layout/fragment_pendulum.xml" value="0.33" />
<entry key="..\:/Users/Feyzu/AndroidStudioProjects/acaPendulum20/app/src/main/res/layout/fragment_pendulum2.xml" value="0.5541666666666667" /> <entry key="..\:/Users/Feyzu/AndroidStudioProjects/acaPendulum20/app/src/main/res/layout/fragment_pendulum2.xml" value="0.5541666666666667" />
<entry key="..\:/Users/Feyzu/AndroidStudioProjects/acaPendulum20/app/src/main/res/layout/fragment_start_pendulum.xml" value="0.33" /> <entry key="..\:/Users/Feyzu/AndroidStudioProjects/acaPendulum20/app/src/main/res/layout/fragment_start_pendulum.xml" value="0.33" />
<entry key="..\:/Users/Feyzu/AndroidStudioProjects/acaPendulum20/app/src/main/res/layout/fragment_update.xml" value="0.33" /> <entry key="..\:/Users/Feyzu/AndroidStudioProjects/acaPendulum20/app/src/main/res/layout/fragment_update.xml" value="0.33" />


+ 5
- 2
app/src/main/AndroidManifest.xml View File

@ -1,14 +1,17 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.acapendulum20">
package="com.example.acapendulum20"
android:versionCode="2">
<application <application
android:allowBackup="true"
android:allowBackup="false"
android:icon="@mipmap/ic_launcher" android:icon="@mipmap/ic_launcher"
android:label="@string/app_name" android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round" android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true" android:supportsRtl="true"
android:theme="@style/Theme.AcaPendulum20"> android:theme="@style/Theme.AcaPendulum20">
<activity <activity
android:name=".MainActivity" android:name=".MainActivity"
android:exported="true"> android:exported="true">


+ 9
- 2
app/src/main/java/com/example/acapendulum20/canvas/CanvasPendulum.kt View File

@ -6,8 +6,8 @@ import android.graphics.Color
import android.graphics.Paint import android.graphics.Paint
import android.util.AttributeSet import android.util.AttributeSet
import android.view.View import android.view.View
import kotlin.math.cos
import kotlin.math.sin
import kotlinx.coroutines.delay
import kotlin.math.*
class CanvasPendulum @JvmOverloads constructor( class CanvasPendulum @JvmOverloads constructor(
@ -142,6 +142,13 @@ class CanvasPendulum @JvmOverloads constructor(
println(magnet) println(magnet)
mPendulum.magneticField = magnet mPendulum.magneticField = magnet
} }
fun getVelocity(): Double {
var currentVelocity = mPendulum.angleVelocity * 1000
val roundoff = (currentVelocity * 100.0).roundToInt() / 100.0
return abs(roundoff)
}
} }
class Position(var x: Float, var y: Float) { class Position(var x: Float, var y: Float) {


+ 9
- 0
app/src/main/java/com/example/acapendulum20/data/MeasurementDao.kt View File

@ -11,5 +11,14 @@ interface MeasurementDao {
@Insert(onConflict = OnConflictStrategy.IGNORE ) @Insert(onConflict = OnConflictStrategy.IGNORE )
fun addMeasurement(measurement: Measurement) fun addMeasurement(measurement: Measurement)
@Update
fun finishMeasurement(measurement: Measurement)
@Query("SELECT * FROM measurement_table WHERE owner =:id")
fun readAllData(id: String): LiveData<List<Measurement>>
@Query("SELECT * FROM measurement_table ")
fun readAllData(): LiveData<List<Measurement>>
} }

app/src/main/java/com/example/acapendulum20/data/MeasurementDatabase.kt → app/src/main/java/com/example/acapendulum20/data/PendulumDatabase.kt View File


+ 0
- 33
app/src/main/java/com/example/acapendulum20/data/UserDatabase.kt View File

@ -1,33 +0,0 @@
package com.example.acapendulum20.data
import android.content.Context
import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase
import com.example.acapendulum20.model.User
@Database(entities = [User::class], version = 1, exportSchema = false)
abstract class UserDatabase: RoomDatabase() {
abstract fun userDao(): UserDao
companion object {
@Volatile
private var INSTANCE: UserDatabase? = null
fun getDatabase(context: Context): UserDatabase{
val tempInstance = INSTANCE
if(tempInstance != null){
return tempInstance
}
synchronized(this){
val instance = Room.databaseBuilder(
context.applicationContext,
UserDatabase::class.java,
"user_database"
).build()
INSTANCE = instance
return instance
}
}
}
}

+ 30
- 12
app/src/main/java/com/example/acapendulum20/fragments/pendulum/PendulumFragment.kt View File

@ -6,23 +6,26 @@ import android.os.CountDownTimer
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.MotionEvent import android.view.MotionEvent
import android.view.View import android.view.View
import android.view.View.OnTouchListener
import android.view.ViewGroup import android.view.ViewGroup
import android.widget.Button import android.widget.Button
import android.widget.TextView import android.widget.TextView
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import androidx.lifecycle.ViewModelProvider
import androidx.navigation.fragment.findNavController
import androidx.navigation.fragment.navArgs import androidx.navigation.fragment.navArgs
import com.example.acapendulum20.R import com.example.acapendulum20.R
import com.example.acapendulum20.canvas.CanvasPendulum import com.example.acapendulum20.canvas.CanvasPendulum
import com.example.acapendulum20.model.Measurement
import com.example.acapendulum20.viewmodel.MeasurementViewmodel import com.example.acapendulum20.viewmodel.MeasurementViewmodel
import kotlinx.android.synthetic.main.fragment_pendulum.* import kotlinx.android.synthetic.main.fragment_pendulum.*
import java.time.LocalDateTime
import java.text.DateFormat
import java.text.SimpleDateFormat
import java.util.*
class PendulumFragment : Fragment() { class PendulumFragment : Fragment() {
private val args by navArgs<PendulumFragmentArgs>() private val args by navArgs<PendulumFragmentArgs>()
private lateinit var mMeasurementViewmodel: MeasurementViewmodel private lateinit var mMeasurementViewmodel: MeasurementViewmodel
@SuppressLint("ClickableViewAccessibility") @SuppressLint("ClickableViewAccessibility")
@ -33,35 +36,41 @@ class PendulumFragment : Fragment() {
// Inflate the layout for this fragment // Inflate the layout for this fragment
val view = inflater.inflate(R.layout.fragment_pendulum, container, false) val view = inflater.inflate(R.layout.fragment_pendulum, container, false)
val mCanvasPendulum: CanvasPendulum = view.findViewById(R.id.canvasContainer)!! val mCanvasPendulum: CanvasPendulum = view.findViewById(R.id.canvasContainer)!!
mMeasurementViewmodel = ViewModelProvider(this).get(MeasurementViewmodel::class.java)
//activate the magnet //activate the magnet
val button = view.findViewById<Button>(R.id.activate_btn)
val magnetButton = view.findViewById<Button>(R.id.activate_btn)
//Save results //Save results
val saveButton = view.findViewById<Button>(R.id.speichern_btn)
saveButton.setOnClickListener(){
finishMeasurement()
}
//Show targetVelocity and maxAttemptTime //Show targetVelocity and maxAttemptTime
val targetVelocity = view.findViewById<TextView>(R.id.targetVelocity_view) val targetVelocity = view.findViewById<TextView>(R.id.targetVelocity_view)
val maxAttemptTime = view.findViewById<TextView>(R.id.maxAttemptTime_view) val maxAttemptTime = view.findViewById<TextView>(R.id.maxAttemptTime_view)
val timer = view.findViewById<TextView>(R.id.timer_view) val timer = view.findViewById<TextView>(R.id.timer_view)
val currentVelocity = view.findViewById<TextView>(R.id.actV_view)
targetVelocity.text = args.targetVelocity.toString()
maxAttemptTime.text = args.maxAttemptTime.toString()
//timer.text =
targetVelocity.text = args.measurement.targetVelocity.toString()
maxAttemptTime.text = args.measurement.maxAttemptTime.toString()
//time count down for 30 seconds
//time count down for "maxAttemptTime" seconds
//with 1 second as countDown interval //with 1 second as countDown interval
object : CountDownTimer(args.maxAttemptTime.toLong()*1000, 1000){
object : CountDownTimer(args.measurement.maxAttemptTime*1000, 1000){
override fun onTick(millisUntilFinished: Long) { override fun onTick(millisUntilFinished: Long) {
timer.setText("sec.: " + millisUntilFinished / 1000) timer.setText("sec.: " + millisUntilFinished / 1000)
currentVelocity.setText((mCanvasPendulum.getVelocity().toString()) + "cm/s")
} }
override fun onFinish() { override fun onFinish() {
timer.setText("done!") timer.setText("done!")
} }
}.start() }.start()
button.setOnTouchListener(object : View.OnTouchListener{
magnetButton.setOnTouchListener(object : View.OnTouchListener{
override fun onTouch(v: View?, event: MotionEvent?): Boolean { override fun onTouch(v: View?, event: MotionEvent?): Boolean {
if (event?.action == MotionEvent.ACTION_DOWN){ if (event?.action == MotionEvent.ACTION_DOWN){
println("button action DOWN") println("button action DOWN")
@ -77,4 +86,13 @@ class PendulumFragment : Fragment() {
}) })
return view return view
} }
private fun finishMeasurement(){
val endTime = System.currentTimeMillis()
val measuredTime = endTime - args.measurement.startTime
val measurement = Measurement(args.measurement.id,args.measurement.targetVelocity,args.measurement.maxAttemptTime,args.measurement.measuredVelocity,measuredTime,args.measurement.startTime,endTime, args.measurement.owner)
mMeasurementViewmodel.finishMeasurement(measurement)
val action = PendulumFragmentDirections.actionPendulumFragmentToUpdateFragment(args.currentUser)
findNavController().navigate(action)
}
} }

+ 10
- 4
app/src/main/java/com/example/acapendulum20/fragments/pendulum/StartPendulumFragment.kt View File

@ -21,7 +21,9 @@ import com.example.acapendulum20.viewmodel.MeasurementViewmodel
import com.example.acapendulum20.viewmodel.UserViewmodel import com.example.acapendulum20.viewmodel.UserViewmodel
import kotlinx.android.synthetic.main.fragment_start_pendulum.* import kotlinx.android.synthetic.main.fragment_start_pendulum.*
import kotlinx.android.synthetic.main.fragment_start_pendulum.view.* import kotlinx.android.synthetic.main.fragment_start_pendulum.view.*
import java.time.Instant
import java.time.LocalDateTime import java.time.LocalDateTime
import java.time.format.DateTimeFormatter
import java.util.* import java.util.*
class StartPendulumFragment: Fragment() { class StartPendulumFragment: Fragment() {
@ -40,23 +42,27 @@ class StartPendulumFragment: Fragment() {
//navigate to pendulumFragment //navigate to pendulumFragment
view.startPendulum_btn.setOnClickListener{ view.startPendulum_btn.setOnClickListener{
insertDataToDatabase()
startMeasurement()
} }
return view return view
} }
private fun insertDataToDatabase() {
private fun startMeasurement() {
val targetVelocity = (targetVelocity_et.text).toString() val targetVelocity = (targetVelocity_et.text).toString()
val maxAttemptTime = (maxAttemptTime_et.text).toString() val maxAttemptTime = (maxAttemptTime_et.text).toString()
val owner = args.owner val owner = args.owner
//val startTime = DateTimeFormatter.ISO_INSTANT.format(Instant.now())
val startTime = System.currentTimeMillis()
//println("${number::class.qualifiedName}") // "kotlin.Int"
if(inputCheck(targetVelocity, maxAttemptTime)){ if(inputCheck(targetVelocity, maxAttemptTime)){
//Create Measurement Object //Create Measurement Object
val measurement = Measurement(UUID.randomUUID().toString(), targetVelocity.toFloat(),maxAttemptTime.toFloat(),0.0f,0.00f,0.00f,owner)
val measurement = Measurement(UUID.randomUUID().toString(), targetVelocity.toFloat(),maxAttemptTime.toLong(),0.00f,0,startTime,0,owner)
//Add Data to Database //Add Data to Database
mMeasurementViewmodel.addMeasurement(measurement) mMeasurementViewmodel.addMeasurement(measurement)
Toast.makeText(requireContext(),"Successfully added!", Toast.LENGTH_LONG).show() Toast.makeText(requireContext(),"Successfully added!", Toast.LENGTH_LONG).show()
//Navigate Back //Navigate Back
val action = StartPendulumFragmentDirections.actionStartPendulumFragmentToPendulumFragment(targetVelocity.toFloat(),maxAttemptTime.toFloat(),owner)
val action = StartPendulumFragmentDirections.actionStartPendulumFragmentToPendulumFragment(measurement, args.currentUser)
findNavController().navigate(action) findNavController().navigate(action)
}else{ }else{
Toast.makeText(requireContext(),"Please fill out all fields.", Toast.LENGTH_LONG).show() Toast.makeText(requireContext(),"Please fill out all fields.", Toast.LENGTH_LONG).show()


+ 49
- 0
app/src/main/java/com/example/acapendulum20/fragments/update/SessionList.kt View File

@ -0,0 +1,49 @@
package com.example.acapendulum20.fragments.list
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.navigation.findNavController
import androidx.recyclerview.widget.RecyclerView
import com.example.acapendulum20.R
import com.example.acapendulum20.fragments.pendulum.PendulumFragmentDirections
import com.example.acapendulum20.model.Measurement
import com.example.acapendulum20.model.User
import kotlinx.android.synthetic.main.custom_row.view.*
import kotlinx.android.synthetic.main.custom_row_measurement.view.*
import java.util.*
class SessionList: RecyclerView.Adapter<SessionList.MyViewHolder>() {
private var sessionList = emptyList<Measurement>()
class MyViewHolder(itemView: View): RecyclerView.ViewHolder(itemView) {
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyViewHolder {
return MyViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.custom_row_measurement, parent, false))
}
override fun getItemCount(): Int {
return sessionList.size
}
override fun onBindViewHolder(holder: MyViewHolder, position: Int) {
val currentItem = sessionList[position]
holder.itemView.nr_txt.text = (position+1).toString()
holder.itemView.dateStart_txt.text = Date(currentItem.startTime).toString()
holder.itemView.dateEnd_txt.text = Date(currentItem.endTime).toString()
holder.itemView.targetVelocity_txt.text = currentItem.targetVelocity.toString()
holder.itemView.velocity_txt.text = currentItem.measuredVelocity.toString()
holder.itemView.maxTime_txt.text = currentItem.maxAttemptTime.toString()
holder.itemView.time_txt.text = currentItem.measuredTime.toString()
}
fun setData(measurement: List<Measurement>){
this.sessionList = measurement
notifyDataSetChanged()
}
}

+ 21
- 3
app/src/main/java/com/example/acapendulum20/fragments/update/UpdateFragment.kt View File

@ -7,12 +7,18 @@ import android.text.TextUtils
import android.view.* import android.view.*
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import android.widget.Toast import android.widget.Toast
import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider import androidx.lifecycle.ViewModelProvider
import androidx.navigation.fragment.findNavController import androidx.navigation.fragment.findNavController
import androidx.navigation.fragment.navArgs import androidx.navigation.fragment.navArgs
import androidx.recyclerview.widget.LinearLayoutManager
import com.example.acapendulum20.R import com.example.acapendulum20.R
import com.example.acapendulum20.fragments.list.SessionList
import com.example.acapendulum20.model.User import com.example.acapendulum20.model.User
import com.example.acapendulum20.viewmodel.MeasurementViewmodel
import com.example.acapendulum20.viewmodel.UserViewmodel import com.example.acapendulum20.viewmodel.UserViewmodel
import kotlinx.android.synthetic.main.fragment_list.view.*
import kotlinx.android.synthetic.main.fragment_update.* import kotlinx.android.synthetic.main.fragment_update.*
import kotlinx.android.synthetic.main.fragment_update.view.* import kotlinx.android.synthetic.main.fragment_update.view.*
@ -21,6 +27,7 @@ class UpdateFragment : Fragment() {
private val args by navArgs<UpdateFragmentArgs>() private val args by navArgs<UpdateFragmentArgs>()
private lateinit var mUserViewModel: UserViewmodel private lateinit var mUserViewModel: UserViewmodel
private lateinit var mMeasurementViewmodel: MeasurementViewmodel
override fun onCreateView( override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?, inflater: LayoutInflater, container: ViewGroup?,
@ -29,7 +36,18 @@ class UpdateFragment : Fragment() {
// Inflate the layout for this fragment // Inflate the layout for this fragment
val view = inflater.inflate(R.layout.fragment_update, container, false) val view = inflater.inflate(R.layout.fragment_update, container, false)
mUserViewModel = ViewModelProvider(this)[UserViewmodel::class.java]
//Recylerview
val adapter = SessionList()
val recyclerView = view.SessionRecyclerview
recyclerView.adapter = adapter
recyclerView.layoutManager = LinearLayoutManager(requireContext())
mUserViewModel = ViewModelProvider(this).get(UserViewmodel::class.java)
mMeasurementViewmodel = ViewModelProvider(this).get(MeasurementViewmodel::class.java)
//val measurmentAnzeigen = MeasurementViewmodel(this,args.currentUser.id)
mMeasurementViewmodel.readAllData.observe(viewLifecycleOwner, Observer { measurement ->
adapter.setData(measurement)
})
view.updateFirstName_et.setText(args.currentUser.firstName) view.updateFirstName_et.setText(args.currentUser.firstName)
view.updateLastName_et.setText(args.currentUser.lastName) view.updateLastName_et.setText(args.currentUser.lastName)
@ -40,7 +58,7 @@ class UpdateFragment : Fragment() {
//navigate to fragment_start_pendulum //navigate to fragment_start_pendulum
view.startTest_btn.setOnClickListener{ view.startTest_btn.setOnClickListener{
val owner = args.currentUser.id val owner = args.currentUser.id
val action = UpdateFragmentDirections.actionUpdateFragmentToStartPendulumFragment(owner)
val action = UpdateFragmentDirections.actionUpdateFragmentToStartPendulumFragment(owner, args.currentUser)
findNavController().navigate(action) findNavController().navigate(action)
} }
@ -50,7 +68,7 @@ class UpdateFragment : Fragment() {
} }
//Add menu //Add menu
setHasOptionsMenu(true)
//setHasOptionsMenu(true)
return view return view
} }


+ 6
- 13
app/src/main/java/com/example/acapendulum20/model/Measurement.kt View File

@ -11,21 +11,14 @@ import java.time.LocalDateTime
@Parcelize @Parcelize
@Entity(tableName = "measurement_table") @Entity(tableName = "measurement_table")
/*, foreignKeys = [ForeignKey(entity = Session::class,
parentColumns = arrayOf("id"),
childColumns = arrayOf("sessionRef"),
onDelete = ForeignKey.CASCADE)]
)
*/
data class Measurement( data class Measurement(
@PrimaryKey @PrimaryKey
val id: String, val id: String,
val targetVelocity: Float, val targetVelocity: Float,
val maxAttemptTime: Float,
val attemptTime: Float,
val startTime: Float,
val endTime: Float,
val maxAttemptTime: Long,
val measuredVelocity: Float,
val measuredTime: Long,
val startTime: Long,
val endTime: Long,
val owner: String, val owner: String,
): Parcelable
): Parcelable

+ 0
- 1
app/src/main/java/com/example/acapendulum20/model/User.kt View File

@ -15,5 +15,4 @@ data class User (
val age: Int, val age: Int,
val sex: String, val sex: String,
val handiness: String, val handiness: String,
): Parcelable ): Parcelable

+ 10
- 0
app/src/main/java/com/example/acapendulum20/repository/MeasurementRepository.kt View File

@ -8,8 +8,18 @@ import com.example.acapendulum20.model.User
class MeasurementRepository(private val measurementDao: MeasurementDao) { class MeasurementRepository(private val measurementDao: MeasurementDao) {
val readAllData: LiveData<List<Measurement>> = measurementDao.readAllData()
suspend fun addMeasurement(measurement: Measurement){ suspend fun addMeasurement(measurement: Measurement){
measurementDao.addMeasurement(measurement) measurementDao.addMeasurement(measurement)
} }
suspend fun finishMeasurement(measurement: Measurement){
measurementDao.finishMeasurement(measurement)
}
suspend fun readAllDataMeasurement(id: String){
var readAllData = measurementDao.readAllData(id)
}
} }

+ 17
- 8
app/src/main/java/com/example/acapendulum20/viewmodel/MeasurementViewmodel.kt View File

@ -1,27 +1,26 @@
package com.example.acapendulum20.viewmodel package com.example.acapendulum20.viewmodel
import android.app.Application import android.app.Application
import android.content.Context
import androidx.lifecycle.AndroidViewModel import androidx.lifecycle.AndroidViewModel
import androidx.lifecycle.LiveData import androidx.lifecycle.LiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope import androidx.lifecycle.viewModelScope
import com.example.acapendulum20.data.MeasurementDao
import com.example.acapendulum20.data.MeasurementDatabase
import com.example.acapendulum20.data.UserDatabase
import com.example.acapendulum20.data.UserDatabase.Companion.getDatabase
import com.example.acapendulum20.data.PendulumDatabase
import com.example.acapendulum20.model.Measurement import com.example.acapendulum20.model.Measurement
import com.example.acapendulum20.model.User
import com.example.acapendulum20.repository.MeasurementRepository import com.example.acapendulum20.repository.MeasurementRepository
import com.example.acapendulum20.repository.UserRepository
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
class MeasurementViewmodel(application: Application): AndroidViewModel(application) { class MeasurementViewmodel(application: Application): AndroidViewModel(application) {
private val repository: MeasurementRepository
val readAllData: LiveData<List<Measurement>>
private val repository: MeasurementRepository
init{ init{
val measurementDao = MeasurementDatabase.getDatabase(application).measurementDao()
val measurementDao = PendulumDatabase.getDatabase(application).measurementDao()
repository = MeasurementRepository(measurementDao) repository = MeasurementRepository(measurementDao)
readAllData = repository.readAllData
} }
fun addMeasurement(measurement: Measurement){ fun addMeasurement(measurement: Measurement){
@ -30,5 +29,15 @@ class MeasurementViewmodel(application: Application): AndroidViewModel(applicati
} }
} }
fun finishMeasurement(measurement: Measurement){
viewModelScope.launch(Dispatchers.IO) {
repository.finishMeasurement(measurement)
}
}
fun readAllDataMeasurement(id: String){
viewModelScope.launch(Dispatchers.IO) {
repository.readAllDataMeasurement(id)
}
}
} }

+ 2
- 2
app/src/main/java/com/example/acapendulum20/viewmodel/UserViewmodel.kt View File

@ -4,7 +4,7 @@ import android.app.Application
import androidx.lifecycle.AndroidViewModel import androidx.lifecycle.AndroidViewModel
import androidx.lifecycle.LiveData import androidx.lifecycle.LiveData
import androidx.lifecycle.viewModelScope import androidx.lifecycle.viewModelScope
import com.example.acapendulum20.data.UserDatabase
import com.example.acapendulum20.data.PendulumDatabase
import com.example.acapendulum20.repository.UserRepository import com.example.acapendulum20.repository.UserRepository
import com.example.acapendulum20.model.User import com.example.acapendulum20.model.User
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
@ -16,7 +16,7 @@ class UserViewmodel(application: Application): AndroidViewModel(application) {
private val repository: UserRepository private val repository: UserRepository
init{ init{
val userDao = UserDatabase.getDatabase(application).userDao()
val userDao = PendulumDatabase.getDatabase(application).userDao()
repository = UserRepository(userDao) repository = UserRepository(userDao)
readAllData = repository.readAllData readAllData = repository.readAllData
} }


+ 85
- 0
app/src/main/res/layout/custom_row_measurement.xml View File

@ -0,0 +1,85 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/nr_txt"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_marginStart="16dp"
android:text="Nr"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@id/dateStart_txt"
app:layout_constraintHorizontal_bias="0.571"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.022" />
<TextView
android:id="@+id/dateStart_txt"
android:layout_width="135dp"
android:layout_height="24dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="4dp"
android:text="Datum und Uhrzeit"
app:layout_constraintEnd_toStartOf="@+id/dateEnd_txt"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/targetVelocity_txt"
android:layout_width="135dp"
android:layout_height="24dp"
android:layout_marginStart="60dp"
android:layout_marginTop="8dp"
android:text="targetVelocity"
app:layout_constraintEnd_toStartOf="@id/velocity_txt"
app:layout_constraintHorizontal_bias="0.2"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/dateStart_txt" />
<TextView
android:id="@+id/velocity_txt"
android:layout_width="135dp"
android:layout_height="24dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="76dp"
android:text="velocity"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/dateEnd_txt" />
<TextView
android:id="@+id/maxTime_txt"
android:layout_width="135dp"
android:layout_height="24dp"
android:text="maxTime"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/time_txt"
app:layout_constraintHorizontal_bias="0.938"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/targetVelocity_txt"
app:layout_constraintVertical_bias="0.012" />
<TextView
android:id="@+id/time_txt"
android:layout_width="135dp"
android:layout_height="24dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="76dp"
android:text="time"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/velocity_txt" />
<TextView
android:id="@+id/dateEnd_txt"
android:layout_width="135dp"
android:layout_height="24dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="76dp"
android:text="DatumUhrzeitEnde"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

+ 2
- 2
app/src/main/res/layout/fragment_pendulum.xml View File

@ -85,8 +85,8 @@
<com.example.acapendulum20.canvas.CanvasPendulum <com.example.acapendulum20.canvas.CanvasPendulum
android:id="@+id/canvasContainer" android:id="@+id/canvasContainer"
android:layout_width="407dp"
android:layout_height="462dp"
android:layout_width="62mm"
android:layout_height="70mm"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"


+ 7
- 7
app/src/main/res/navigation/my_nav.xml View File

@ -52,6 +52,9 @@
<argument <argument
android:name="owner" android:name="owner"
app:argType="string" /> app:argType="string" />
<argument
android:name="currentUser"
app:argType="com.example.acapendulum20.model.User" />
</fragment> </fragment>
<fragment <fragment
android:id="@+id/pendulumFragment" android:id="@+id/pendulumFragment"
@ -62,13 +65,10 @@
android:id="@+id/action_pendulumFragment_to_updateFragment" android:id="@+id/action_pendulumFragment_to_updateFragment"
app:destination="@id/updateFragment" /> app:destination="@id/updateFragment" />
<argument <argument
android:name="targetVelocity"
app:argType="float" />
<argument
android:name="maxAttemptTime"
app:argType="float" />
android:name="measurement"
app:argType="com.example.acapendulum20.model.Measurement" />
<argument <argument
android:name="owner"
app:argType="string" />
android:name="currentUser"
app:argType="com.example.acapendulum20.model.User" />
</fragment> </fragment>
</navigation> </navigation>

Loading…
Cancel
Save