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
cafda6fcb5
6 changed files with 71 additions and 54 deletions
  1. +11
    -5
      app/src/main/java/com/example/acapendulum20/fragments/update/SessionList.kt
  2. +1
    -1
      app/src/main/java/com/example/acapendulum20/fragments/update/UpdateFragment.kt
  3. +2
    -2
      app/src/main/java/com/example/acapendulum20/repository/MeasurementRepository.kt
  4. +3
    -6
      app/src/main/java/com/example/acapendulum20/viewmodel/MeasurementViewmodel.kt
  5. +50
    -36
      app/src/main/res/layout/custom_row_measurement.xml
  6. +4
    -4
      app/src/main/res/layout/fragment_update.xml

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

@ -1,16 +1,15 @@
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.text.SimpleDateFormat
import java.util.*
class SessionList: RecyclerView.Adapter<SessionList.MyViewHolder>() {
@ -31,9 +30,16 @@ class SessionList: RecyclerView.Adapter<SessionList.MyViewHolder>() {
override fun onBindViewHolder(holder: MyViewHolder, position: Int) {
val currentItem = sessionList[position]
fun convertLongToTime(time: Long): String {
val date = Date(time)
val format = SimpleDateFormat("dd.MM.yyyy HH:mm")
return format.format(date)
}
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.dateStart_txt.text = convertLongToTime(currentItem.startTime)
holder.itemView.dateEnd_txt.text = convertLongToTime(currentItem.endTime)
holder.itemView.targetVelocity_txt.text = currentItem.targetVelocity.toString()
holder.itemView.velocity_txt.text = currentItem.measuredVelocity.toString()
holder.itemView.maxTime_txt.text = currentItem.maxAttemptTime.toString()


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

@ -44,7 +44,7 @@ class UpdateFragment : Fragment() {
mUserViewModel = ViewModelProvider(this).get(UserViewmodel::class.java)
mMeasurementViewmodel = ViewModelProvider(this).get(MeasurementViewmodel::class.java)
//val measurmentAnzeigen = MeasurementViewmodel(this,args.currentUser.id)
mMeasurementViewmodel.readAllDataForUserId(args.currentUser.id)
mMeasurementViewmodel.readAllData.observe(viewLifecycleOwner, Observer { measurement ->
adapter.setData(measurement)
})


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

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

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

@ -14,13 +14,12 @@ import kotlinx.coroutines.launch
class MeasurementViewmodel(application: Application): AndroidViewModel(application) {
val readAllData: LiveData<List<Measurement>>
lateinit var readAllData: LiveData<List<Measurement>>
private val repository: MeasurementRepository
init{
val measurementDao = PendulumDatabase.getDatabase(application).measurementDao()
repository = MeasurementRepository(measurementDao)
readAllData = repository.readAllData
}
fun addMeasurement(measurement: Measurement){
@ -35,9 +34,7 @@ class MeasurementViewmodel(application: Application): AndroidViewModel(applicati
}
}
fun readAllDataMeasurement(id: String){
viewModelScope.launch(Dispatchers.IO) {
repository.readAllDataMeasurement(id)
}
fun readAllDataForUserId(id: String){
readAllData= repository.readAllDataMeasurement(id)
}
}

+ 50
- 36
app/src/main/res/layout/custom_row_measurement.xml View File

@ -4,82 +4,96 @@
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">
android:layout_height="wrap_content"
android:background="@color/cardview_shadow_start_color"
android:padding="24sp"
android:layout_margin="5dp">
<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_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.022" />
app:layout_constraintVertical_bias="0.0" />
<TextView
android:id="@+id/dateStart_txt"
android:layout_width="135dp"
android:layout_width="165dp"
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" />
android:text="dateStart"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.142"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0" />
<TextView
android:id="@+id/targetVelocity_txt"
android:layout_width="135dp"
android:layout_width="165dp"
android:layout_height="24dp"
android:layout_marginStart="60dp"
android:layout_marginTop="8dp"
android:layout_marginTop="4dp"
android:text="targetVelocity"
app:layout_constraintEnd_toStartOf="@id/velocity_txt"
app:layout_constraintHorizontal_bias="0.2"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.142"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/dateStart_txt" />
app:layout_constraintTop_toBottomOf="@+id/dateStart_txt"
app:layout_constraintVertical_bias="0.0" />
<TextView
android:id="@+id/velocity_txt"
android:layout_width="135dp"
android:layout_width="165dp"
android:layout_height="24dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="76dp"
android:text="velocity"
android:layout_marginTop="4dp"
android:text="measuredVelocity"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/dateEnd_txt" />
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/dateEnd_txt"
app:layout_constraintVertical_bias="0.0" />
<TextView
android:id="@+id/maxTime_txt"
android:layout_width="135dp"
android:layout_width="165dp"
android:layout_height="24dp"
android:layout_marginTop="4dp"
android:text="maxTime"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/time_txt"
app:layout_constraintHorizontal_bias="0.938"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.142"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/targetVelocity_txt"
app:layout_constraintVertical_bias="0.012" />
app:layout_constraintVertical_bias="0.0" />
<TextView
android:id="@+id/time_txt"
android:layout_width="135dp"
android:layout_width="165dp"
android:layout_height="24dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="76dp"
android:text="time"
android:layout_marginTop="4dp"
android:text="measuredTime"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/velocity_txt" />
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/velocity_txt"
app:layout_constraintVertical_bias="0.0" />
<TextView
android:id="@+id/dateEnd_txt"
android:layout_width="135dp"
android:layout_width="165dp"
android:layout_height="24dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="76dp"
android:text="DatumUhrzeitEnde"
android:text="dateEnd"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0" />
</androidx.constraintlayout.widget.ConstraintLayout>

+ 4
- 4
app/src/main/res/layout/fragment_update.xml View File

@ -92,12 +92,12 @@
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/SessionRecyclerview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_width="359dp"
android:layout_height="251dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/startTest_btn"
app:layout_constraintVertical_bias="0.292" />
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="1.0" />
</androidx.constraintlayout.widget.ConstraintLayout>

Loading…
Cancel
Save