diff --git a/app/src/main/java/com/example/acapendulum20/fragments/update/SessionList.kt b/app/src/main/java/com/example/acapendulum20/fragments/update/SessionList.kt index 8f439a9..7c3f02b 100644 --- a/app/src/main/java/com/example/acapendulum20/fragments/update/SessionList.kt +++ b/app/src/main/java/com/example/acapendulum20/fragments/update/SessionList.kt @@ -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() { @@ -31,9 +30,16 @@ class SessionList: RecyclerView.Adapter() { 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() diff --git a/app/src/main/java/com/example/acapendulum20/fragments/update/UpdateFragment.kt b/app/src/main/java/com/example/acapendulum20/fragments/update/UpdateFragment.kt index ad8146b..edcf5bf 100644 --- a/app/src/main/java/com/example/acapendulum20/fragments/update/UpdateFragment.kt +++ b/app/src/main/java/com/example/acapendulum20/fragments/update/UpdateFragment.kt @@ -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) }) diff --git a/app/src/main/java/com/example/acapendulum20/repository/MeasurementRepository.kt b/app/src/main/java/com/example/acapendulum20/repository/MeasurementRepository.kt index 3b7da9c..50f5f09 100644 --- a/app/src/main/java/com/example/acapendulum20/repository/MeasurementRepository.kt +++ b/app/src/main/java/com/example/acapendulum20/repository/MeasurementRepository.kt @@ -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> { + return measurementDao.readAllData(id) } } \ No newline at end of file diff --git a/app/src/main/java/com/example/acapendulum20/viewmodel/MeasurementViewmodel.kt b/app/src/main/java/com/example/acapendulum20/viewmodel/MeasurementViewmodel.kt index dad82c9..5690123 100644 --- a/app/src/main/java/com/example/acapendulum20/viewmodel/MeasurementViewmodel.kt +++ b/app/src/main/java/com/example/acapendulum20/viewmodel/MeasurementViewmodel.kt @@ -14,13 +14,12 @@ import kotlinx.coroutines.launch class MeasurementViewmodel(application: Application): AndroidViewModel(application) { - val readAllData: LiveData> + lateinit var readAllData: LiveData> 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) } } \ No newline at end of file diff --git a/app/src/main/res/layout/custom_row_measurement.xml b/app/src/main/res/layout/custom_row_measurement.xml index 423fe5a..719466f 100644 --- a/app/src/main/res/layout/custom_row_measurement.xml +++ b/app/src/main/res/layout/custom_row_measurement.xml @@ -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"> + app:layout_constraintVertical_bias="0.0" /> + 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" /> + app:layout_constraintTop_toBottomOf="@+id/dateStart_txt" + app:layout_constraintVertical_bias="0.0" /> + app:layout_constraintHorizontal_bias="1.0" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toBottomOf="@+id/dateEnd_txt" + app:layout_constraintVertical_bias="0.0" /> + app:layout_constraintVertical_bias="0.0" /> + app:layout_constraintHorizontal_bias="1.0" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toBottomOf="@id/velocity_txt" + app:layout_constraintVertical_bias="0.0" /> + app:layout_constraintHorizontal_bias="1.0" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="parent" + app:layout_constraintVertical_bias="0.0" /> \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_update.xml b/app/src/main/res/layout/fragment_update.xml index 043d541..11f7f7a 100644 --- a/app/src/main/res/layout/fragment_update.xml +++ b/app/src/main/res/layout/fragment_update.xml @@ -92,12 +92,12 @@ + app:layout_constraintTop_toTopOf="parent" + app:layout_constraintVertical_bias="1.0" /> \ No newline at end of file