Browse Source

Pendel Logic READY

Pendelsession information save in profile in progress
new fragment "fragment_start_pendulum" finished
Measured results saved in UpdateFragment Recyclerview based und User Id successfully
master
Feyzu 3 years ago
parent
commit
a64c528bcb
14 changed files with 69 additions and 70 deletions
  1. +1
    -1
      app/src/main/AndroidManifest.xml
  2. +4
    -4
      app/src/main/java/com/example/acapendulum20/canvas/CanvasPendulum.kt
  3. +1
    -1
      app/src/main/java/com/example/acapendulum20/data/MeasurementDao.kt
  4. +0
    -4
      app/src/main/java/com/example/acapendulum20/data/SessionDao.kt
  5. +0
    -4
      app/src/main/java/com/example/acapendulum20/data/SessionDatabase.kt
  6. +36
    -11
      app/src/main/java/com/example/acapendulum20/fragments/pendulum/PendulumFragment.kt
  7. +1
    -1
      app/src/main/java/com/example/acapendulum20/fragments/pendulum/StartPendulumFragment.kt
  8. +7
    -8
      app/src/main/java/com/example/acapendulum20/fragments/update/MeasurementList.kt
  9. +3
    -5
      app/src/main/java/com/example/acapendulum20/fragments/update/UpdateFragment.kt
  10. +2
    -1
      app/src/main/java/com/example/acapendulum20/model/Measurement.kt
  11. +0
    -22
      app/src/main/java/com/example/acapendulum20/model/Session.kt
  12. +0
    -4
      app/src/main/java/com/example/acapendulum20/repository/SessionRepository.kt
  13. +0
    -4
      app/src/main/java/com/example/acapendulum20/viewmodel/SessionViewmodel.kt
  14. +14
    -0
      app/src/main/res/layout/custom_row_measurement.xml

+ 1
- 1
app/src/main/AndroidManifest.xml View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.acapendulum20"
android:versionCode="2">
android:versionCode="3">
<application


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

@ -132,14 +132,14 @@ class CanvasPendulum @JvmOverloads constructor(
}
fun startMagnet(magnet: Boolean) {
println("startMagnet")
println(magnet)
//println("startMagnet")
//println(magnet)
mPendulum.magneticField = magnet
}
fun stopMagnet(magnet: Boolean) {
println("stopMagnet")
println(magnet)
//println("stopMagnet")
//println(magnet)
mPendulum.magneticField = magnet
}


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

@ -14,7 +14,7 @@ interface MeasurementDao {
@Update
fun finishMeasurement(measurement: Measurement)
@Query("SELECT * FROM measurement_table WHERE owner =:id")
@Query("SELECT * FROM measurement_table WHERE owner =:id AND completed = 1")
fun readAllData(id: String): LiveData<List<Measurement>>
@Query("SELECT * FROM measurement_table ")


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

@ -1,4 +0,0 @@
package com.example.acapendulum20.data
class SessionDao {
}

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

@ -1,4 +0,0 @@
package com.example.acapendulum20.data
class SessionDatabase {
}

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

@ -46,7 +46,8 @@ class PendulumFragment : Fragment() {
val saveButton = view.findViewById<Button>(R.id.speichern_btn)
saveButton.setOnClickListener(){
finishMeasurement()
saveMeasurement(false, 0.00f)
route()
}
//Show targetVelocity and maxAttemptTime
@ -55,44 +56,68 @@ class PendulumFragment : Fragment() {
val timer = view.findViewById<TextView>(R.id.timer_view)
val currentVelocity = view.findViewById<TextView>(R.id.actV_view)
targetVelocity.text = args.measurement.targetVelocity.toString()
maxAttemptTime.text = args.measurement.maxAttemptTime.toString()
// Value endTime
//val endTIme: Long
targetVelocity.text = args.measurement.targetVelocity.toString() + "cm/s"
maxAttemptTime.text = args.measurement.maxAttemptTime.toString() + "sec"
//time count down for "maxAttemptTime" seconds
//with 1 second as countDown interval
object : CountDownTimer(args.measurement.maxAttemptTime*1000, 1000){
object : CountDownTimer(args.measurement.maxAttemptTime*1000, 100){
override fun onTick(millisUntilFinished: Long) {
timer.setText("sec.: " + millisUntilFinished / 1000)
currentVelocity.setText((mCanvasPendulum.getVelocity().toString()) + "cm/s")
val velocity = mCanvasPendulum.getVelocity()
val time = millisUntilFinished / 1000
timer.setText("sec.: " + time)
currentVelocity.setText((velocity.toString()) + "cm/s")
if (velocity >= args.measurement.targetVelocity){
saveMeasurement(true, velocity.toFloat())
cancel()
}
}
override fun onFinish() {
timer.setText("done!")
saveMeasurement(true, 0.00f)
}
}.start()
magnetButton.setOnTouchListener(object : View.OnTouchListener{
override fun onTouch(v: View?, event: MotionEvent?): Boolean {
if (event?.action == MotionEvent.ACTION_DOWN){
println("button action DOWN")
//println("button action DOWN")
mCanvasPendulum.startMagnet(true)
}
if (event?.action == MotionEvent.ACTION_UP){
println("button action UP")
//println("button action UP")
mCanvasPendulum.stopMagnet(false)
}
return true
}
})
return view
}
private fun finishMeasurement(){
private fun saveMeasurement(save: Boolean, velocity: Float){
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)
val maxAttemptTime = args.measurement.maxAttemptTime
val measuredTime = ((endTime - args.measurement.startTime).toDouble()) / 1000
//val measuredVelocity = args.measurement.measuredVelocity
val targetVelocity = args.measurement.targetVelocity
//println(measuredTime)
if (save === true){
val measurement = Measurement(args.measurement.id,targetVelocity,maxAttemptTime,velocity,measuredTime,args.measurement.startTime,endTime,true, args.measurement.owner)
mMeasurementViewmodel.finishMeasurement(measurement)
}
}
private fun route(){
val action = PendulumFragmentDirections.actionPendulumFragmentToUpdateFragment(args.currentUser)
findNavController().navigate(action)
}
}

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

@ -57,7 +57,7 @@ class StartPendulumFragment: Fragment() {
if(inputCheck(targetVelocity, maxAttemptTime)){
//Create Measurement Object
val measurement = Measurement(UUID.randomUUID().toString(), targetVelocity.toFloat(),maxAttemptTime.toLong(),0.00f,0,startTime,0,owner)
val measurement = Measurement(UUID.randomUUID().toString(), targetVelocity.toFloat(),maxAttemptTime.toLong(),0.00f,0.00,startTime,0,false,owner)
//Add Data to Database
mMeasurementViewmodel.addMeasurement(measurement)
Toast.makeText(requireContext(),"Successfully added!", Toast.LENGTH_LONG).show()


app/src/main/java/com/example/acapendulum20/fragments/update/SessionList.kt → app/src/main/java/com/example/acapendulum20/fragments/update/MeasurementList.kt View File


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

@ -8,17 +8,15 @@ import android.view.*
import androidx.fragment.app.Fragment
import android.widget.Toast
import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import androidx.navigation.fragment.findNavController
import androidx.navigation.fragment.navArgs
import androidx.recyclerview.widget.LinearLayoutManager
import com.example.acapendulum20.R
import com.example.acapendulum20.fragments.list.SessionList
import com.example.acapendulum20.fragments.list.MeasurementList
import com.example.acapendulum20.model.User
import com.example.acapendulum20.viewmodel.MeasurementViewmodel
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.view.*
@ -37,7 +35,7 @@ class UpdateFragment : Fragment() {
val view = inflater.inflate(R.layout.fragment_update, container, false)
//Recylerview
val adapter = SessionList()
val adapter = MeasurementList()
val recyclerView = view.SessionRecyclerview
recyclerView.adapter = adapter
recyclerView.layoutManager = LinearLayoutManager(requireContext())
@ -68,7 +66,7 @@ class UpdateFragment : Fragment() {
}
//Add menu
//setHasOptionsMenu(true)
setHasOptionsMenu(true)
return view
}


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

@ -17,8 +17,9 @@ data class Measurement(
val targetVelocity: Float,
val maxAttemptTime: Long,
val measuredVelocity: Float,
val measuredTime: Long,
val measuredTime: Double,
val startTime: Long,
val endTime: Long,
val completed: Boolean,
val owner: String,
): Parcelable

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

@ -1,22 +0,0 @@
package com.example.acapendulum20.model
import android.os.Parcelable
import androidx.room.Entity
import androidx.room.ForeignKey
import androidx.room.PrimaryKey
import kotlinx.android.parcel.Parcelize
/*@Parcelize
@Entity(tableName = "session_table", foreignKeys = [ForeignKey(entity = User::class,
parentColumns = arrayOf("id"),
childColumns = arrayOf("userRef"),
onDelete = ForeignKey.CASCADE)])
data class Session (
@PrimaryKey
val id: String,
val sessionStart: Long,
val sessionEnd: Long,
val userRef: String,
): Parcelable
*/

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

@ -1,4 +0,0 @@
package com.example.acapendulum20.repository
class SessionRepository {
}

+ 0
- 4
app/src/main/java/com/example/acapendulum20/viewmodel/SessionViewmodel.kt View File

@ -1,4 +0,0 @@
package com.example.acapendulum20.viewmodel
class SessionViewmodel {
}

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

@ -9,6 +9,20 @@
android:padding="24sp"
android:layout_margin="5dp">
<Button
android:id="@+id/deleteMeasurement_btn"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="@drawable/ic_baseline_delete_24"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintDimensionRatio="1:1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.504"
app:layout_constraintWidth_percent=".06" />
<TextView
android:id="@+id/nr_txt"
android:layout_width="24dp"


Loading…
Cancel
Save