Browse Source

Pendel Logic is not working

delete button for session in Recycleview implementing
master
Feyzu 2 years ago
parent
commit
b5f9b40647
24 changed files with 423 additions and 138 deletions
  1. +5
    -2
      .idea/misc.xml
  2. +59
    -0
      app/src/main/java/com/example/acapendulum20/PendulumSettingsFragment.kt
  3. +8
    -7
      app/src/main/java/com/example/acapendulum20/canvas/CanvasPendulum.kt
  4. +3
    -3
      app/src/main/java/com/example/acapendulum20/data/MeasurementDao.kt
  5. +30
    -5
      app/src/main/java/com/example/acapendulum20/fragments/add/AddFragment.kt
  6. +3
    -1
      app/src/main/java/com/example/acapendulum20/fragments/list/ListAdapter.kt
  7. +2
    -1
      app/src/main/java/com/example/acapendulum20/fragments/pendulum/PendulumFragment.kt
  8. +8
    -0
      app/src/main/java/com/example/acapendulum20/fragments/pendulum/PendulumSettingsFragment.kt
  9. +11
    -4
      app/src/main/java/com/example/acapendulum20/fragments/pendulum/StartPendulumFragment.kt
  10. +18
    -2
      app/src/main/java/com/example/acapendulum20/fragments/update/MeasurementList.kt
  11. +39
    -8
      app/src/main/java/com/example/acapendulum20/fragments/update/UpdateFragment.kt
  12. +1
    -0
      app/src/main/java/com/example/acapendulum20/model/Measurement.kt
  13. +2
    -2
      app/src/main/java/com/example/acapendulum20/model/User.kt
  14. +5
    -2
      app/src/main/java/com/example/acapendulum20/repository/MeasurementRepository.kt
  15. +7
    -3
      app/src/main/java/com/example/acapendulum20/viewmodel/MeasurementViewmodel.kt
  16. +1
    -1
      app/src/main/res/layout/custom_row.xml
  17. +23
    -27
      app/src/main/res/layout/custom_row_measurement.xml
  18. +9
    -0
      app/src/main/res/layout/dropdown_item.xml
  19. +62
    -33
      app/src/main/res/layout/fragment_add.xml
  20. +14
    -0
      app/src/main/res/layout/fragment_pendulum_settings.xml
  21. +24
    -0
      app/src/main/res/layout/fragment_start_pendulum.xml
  22. +65
    -37
      app/src/main/res/layout/fragment_update.xml
  23. +12
    -0
      app/src/main/res/navigation/my_nav.xml
  24. +12
    -0
      app/src/main/res/values/strings.xml

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

@ -12,16 +12,19 @@
<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_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/dropdown_item.xml" value="0.39739583333333334" />
<entry key="..\:/Users/Feyzu/AndroidStudioProjects/acaPendulum20/app/src/main/res/layout/dropdownitem.xml" value="0.39739583333333334" />
<entry key="..\:/Users/Feyzu/AndroidStudioProjects/acaPendulum20/app/src/main/res/layout/fragment_add.xml" value="0.33" />
<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.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_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.5" />
<entry key="..\:/Users/Feyzu/AndroidStudioProjects/acaPendulum20/app/src/main/res/layout/start_pendulum_fragment.xml" value="0.38697916666666665" />
<entry key="..\:/Users/Feyzu/AndroidStudioProjects/acaPendulum20/app/src/main/res/menu/delete_menu.xml" value="0.5541666666666667" />
<entry key="..\:/Users/Feyzu/AndroidStudioProjects/acaPendulum20/app/src/main/res/mipmap-anydpi-v26/elektromagnet.xml" value="0.3165" />
<entry key="..\:/Users/Feyzu/AndroidStudioProjects/acaPendulum20/app/src/main/res/mipmap-anydpi-v26/elektromagnet_round.xml" value="0.5255" />
<entry key="..\:/Users/Feyzu/AndroidStudioProjects/acaPendulum20/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml" value="0.398" />
</map>
</option>
</component>


+ 59
- 0
app/src/main/java/com/example/acapendulum20/PendulumSettingsFragment.kt View File

@ -0,0 +1,59 @@
package com.example.acapendulum20
import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
// TODO: Rename parameter arguments, choose names that match
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
private const val ARG_PARAM1 = "param1"
private const val ARG_PARAM2 = "param2"
/**
* A simple [Fragment] subclass.
* Use the [PendulumSettingsFragment.newInstance] factory method to
* create an instance of this fragment.
*/
class PendulumSettingsFragment : Fragment() {
// TODO: Rename and change types of parameters
private var param1: String? = null
private var param2: String? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
arguments?.let {
param1 = it.getString(ARG_PARAM1)
param2 = it.getString(ARG_PARAM2)
}
}
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_pendulum_settings, container, false)
}
companion object {
/**
* Use this factory method to create a new instance of
* this fragment using the provided parameters.
*
* @param param1 Parameter 1.
* @param param2 Parameter 2.
* @return A new instance of fragment PendulumSettingsFragment.
*/
// TODO: Rename and change types and number of parameters
@JvmStatic
fun newInstance(param1: String, param2: String) =
PendulumSettingsFragment().apply {
arguments = Bundle().apply {
putString(ARG_PARAM1, param1)
putString(ARG_PARAM2, param2)
}
}
}
}

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

@ -147,14 +147,15 @@ class Pendulum {
var startPosition: Position = Position(0f, 0f)
var stopPosition: Position = Position(0f, 0f)
var stringLength = 900f
//start angle
var startAngle: Double = Math.PI / 12
var angleVelocity: Float = 0.0f //
var angleAcceleration: Float = 0.0f //
var ballRadius: Float = 70.0f //
var magneticField: Boolean = false
var gravity = 0.981f
var stringLength = 750f
var ballRadius: Float = 70.0f
var damping = 0.996f
var angleVelocity: Float = 0.0f
var angleAcceleration: Float = 0.0f
var gravity = 0.981f
var magneticField: Boolean = false
}

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

@ -3,7 +3,6 @@ package com.example.acapendulum20.data
import androidx.lifecycle.LiveData
import androidx.room.*
import com.example.acapendulum20.model.Measurement
import com.example.acapendulum20.model.User
@Dao
interface MeasurementDao {
@ -14,11 +13,12 @@ interface MeasurementDao {
@Update
fun finishMeasurement(measurement: Measurement)
@Delete
fun deleteMeasurement(measurement: Measurement)
@Query("SELECT * FROM measurement_table WHERE owner =:id AND completed = 1")
fun readAllData(id: String): LiveData<List<Measurement>>
@Query("SELECT * FROM measurement_table ")
fun readAllData(): LiveData<List<Measurement>>
}

+ 30
- 5
app/src/main/java/com/example/acapendulum20/fragments/add/AddFragment.kt View File

@ -1,12 +1,13 @@
package com.example.acapendulum20.fragments.add
import android.app.DatePickerDialog
import android.os.Bundle
import android.text.Editable
import android.text.TextUtils
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ArrayAdapter
import android.widget.Toast
import androidx.lifecycle.ViewModelProvider
import androidx.navigation.fragment.findNavController
@ -15,8 +16,10 @@ import com.example.acapendulum20.model.User
import com.example.acapendulum20.viewmodel.UserViewmodel
import kotlinx.android.synthetic.main.fragment_add.*
import kotlinx.android.synthetic.main.fragment_add.view.*
import kotlinx.android.synthetic.main.fragment_start_pendulum.view.*
import java.util.*
class AddFragment : Fragment() {
private lateinit var mUserViewModel: UserViewmodel
@ -30,6 +33,28 @@ class AddFragment : Fragment() {
mUserViewModel = ViewModelProvider(this).get(UserViewmodel::class.java)
//dropdown sex
val sex = resources.getStringArray(R.array.sex)
val arrayAdapterSex = ArrayAdapter(requireContext(), R.layout.dropdown_item, sex)
view.chooseSex_et.setAdapter(arrayAdapterSex)
//dropdown handiness
val handiness = resources.getStringArray(R.array.usedHand)
val arrayAdapterHandiness = ArrayAdapter(requireContext(), R.layout.dropdown_item, handiness)
view.addHandiness_et.setAdapter(arrayAdapterHandiness)
//Date picker
view.addBirthday_et.setOnClickListener{
val c = Calendar.getInstance()
val year = c.get(Calendar.YEAR)
val month = c.get(Calendar.MONTH)
val day = c.get(Calendar.DAY_OF_MONTH)
val datePickerDialog = DatePickerDialog(requireActivity(), { view, year, monthOfYear, dayOfMonth ->
addBirthday_et.text = (dayOfMonth.toString() + "-" + (monthOfYear + 1) + "-" + year) }, year, month, day)
datePickerDialog.show()
}
view.add_btn.setOnClickListener{
insertDataToDatabase()
}
@ -39,13 +64,13 @@ class AddFragment : Fragment() {
private fun insertDataToDatabase() {
val firstName = addFirstName_et.text.toString()
val lastName = addLastName_et.text.toString()
val age = addAge_et.text.toString()
val sex = addSex_et.text.toString()
val birthday = addBirthday_et.text.toString()
val sex = chooseSex_et.text.toString()
val handiness = addHandiness_et.text.toString()
if(inputCheck(firstName, lastName, sex, handiness, age)){
if(inputCheck(firstName, lastName, sex, handiness, birthday)){
//Create User Object
val user = User(UUID.randomUUID().toString(), firstName, lastName,Integer.parseInt(age), sex, handiness)
val user = User(UUID.randomUUID().toString(), firstName, lastName, birthday, sex, handiness)
//Add Data to Database
mUserViewModel.addUser(user)
Toast.makeText(requireContext(),"Successfully added!", Toast.LENGTH_LONG).show()


+ 3
- 1
app/src/main/java/com/example/acapendulum20/fragments/list/ListAdapter.kt View File

@ -7,10 +7,12 @@ import androidx.navigation.findNavController
import androidx.recyclerview.widget.RecyclerView
import com.example.acapendulum20.R
import com.example.acapendulum20.model.User
import com.example.acapendulum20.viewmodel.MeasurementViewmodel
import kotlinx.android.synthetic.main.custom_row.view.*
class ListAdapter: RecyclerView.Adapter<ListAdapter.MyViewHolder>() {
private var userList = emptyList<User>()
class MyViewHolder(itemView: View): RecyclerView.ViewHolder(itemView) {
@ -30,7 +32,7 @@ class ListAdapter: RecyclerView.Adapter<ListAdapter.MyViewHolder>() {
holder.itemView.id_txt.text = (position+1).toString()
holder.itemView.firstName_txt.text = currentItem.firstName
holder.itemView.lastName_txt.text = currentItem.lastName
holder.itemView.age_txt.text = currentItem.age.toString()
holder.itemView.age_txt.text = currentItem.birthday
holder.itemView.sex_txt.text = currentItem.sex
holder.itemView.handiness_txt.text = currentItem.handiness


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

@ -106,10 +106,11 @@ class PendulumFragment : Fragment() {
val measuredTime = ((endTime - args.measurement.startTime).toDouble()) / 1000
//val measuredVelocity = args.measurement.measuredVelocity
val targetVelocity = args.measurement.targetVelocity
val usedHand = args.measurement.usedHand
//println(measuredTime)
if (save === true){
val measurement = Measurement(args.measurement.id,targetVelocity,maxAttemptTime,velocity,measuredTime,args.measurement.startTime,endTime,true, args.measurement.owner)
val measurement = Measurement(args.measurement.id,targetVelocity,maxAttemptTime,velocity,measuredTime,args.measurement.startTime,endTime,true, usedHand,args.measurement.owner)
mMeasurementViewmodel.finishMeasurement(measurement)
}
}


+ 8
- 0
app/src/main/java/com/example/acapendulum20/fragments/pendulum/PendulumSettingsFragment.kt View File

@ -0,0 +1,8 @@
package com.example.acapendulum20.fragments.pendulum
import android.app.DatePickerDialog
import java.util.*
class PendulumSettingsFragment {
}

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

@ -6,6 +6,7 @@ import android.text.TextUtils
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ArrayAdapter
import android.widget.Toast
import androidx.fragment.app.Fragment
import androidx.lifecycle.ViewModelProvider
@ -19,6 +20,8 @@ import com.example.acapendulum20.model.Measurement
import com.example.acapendulum20.model.User
import com.example.acapendulum20.viewmodel.MeasurementViewmodel
import com.example.acapendulum20.viewmodel.UserViewmodel
import kotlinx.android.synthetic.main.custom_row_measurement.*
import kotlinx.android.synthetic.main.fragment_add.view.*
import kotlinx.android.synthetic.main.fragment_start_pendulum.*
import kotlinx.android.synthetic.main.fragment_start_pendulum.view.*
import java.time.Instant
@ -35,11 +38,17 @@ class StartPendulumFragment: Fragment() {
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
// Inflate the layout for this fragment
val view = inflater.inflate(R.layout.fragment_start_pendulum, container, false)
mMeasurementViewmodel = ViewModelProvider(this).get(MeasurementViewmodel::class.java)
//dropdown handiness
val usedHand = resources.getStringArray(R.array.usedHand)
val arrayAdapter = ArrayAdapter(requireContext(), R.layout.dropdown_item, usedHand)
view.chooseHandiness_et.setAdapter(arrayAdapter)
//navigate to pendulumFragment
view.startPendulum_btn.setOnClickListener{
startMeasurement()
@ -49,15 +58,13 @@ class StartPendulumFragment: Fragment() {
private fun startMeasurement() {
val targetVelocity = (targetVelocity_et.text).toString()
val maxAttemptTime = (maxAttemptTime_et.text).toString()
val usedHand = (chooseHandiness_et.text).toString()
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)){
//Create Measurement Object
val measurement = Measurement(UUID.randomUUID().toString(), targetVelocity.toFloat(),maxAttemptTime.toLong(),0.00f,0.00,startTime,0,false,owner)
val measurement = Measurement(UUID.randomUUID().toString(), targetVelocity.toFloat(),maxAttemptTime.toLong(),0.00f,0.00,startTime,0,false, usedHand,owner)
//Add Data to Database
mMeasurementViewmodel.addMeasurement(measurement)
Toast.makeText(requireContext(),"Successfully added!", Toast.LENGTH_LONG).show()


+ 18
- 2
app/src/main/java/com/example/acapendulum20/fragments/update/MeasurementList.kt View File

@ -4,15 +4,22 @@ package com.example.acapendulum20.fragments.list
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.get
import androidx.recyclerview.widget.RecyclerView
import com.example.acapendulum20.R
import com.example.acapendulum20.canvas.CanvasPendulum
import com.example.acapendulum20.model.Measurement
import com.example.acapendulum20.repository.MeasurementRepository
import kotlinx.android.synthetic.main.custom_row_measurement.view.*
import java.text.SimpleDateFormat
import java.util.*
import com.example.acapendulum20.viewmodel.MeasurementViewmodel
class MeasurementList: RecyclerView.Adapter<MeasurementList.MyViewHolder>() {
private lateinit var mMeasurementViewmodel: MeasurementViewmodel
private var sessionList = emptyList<Measurement>()
class MyViewHolder(itemView: View): RecyclerView.ViewHolder(itemView) {
@ -28,6 +35,7 @@ class MeasurementList: RecyclerView.Adapter<MeasurementList.MyViewHolder>() {
}
override fun onBindViewHolder(holder: MyViewHolder, position: Int) {
val currentItem = sessionList[position]
fun convertLongToTime(time: Long): String {
@ -35,14 +43,18 @@ class MeasurementList: RecyclerView.Adapter<MeasurementList.MyViewHolder>() {
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 = "Start: " + convertLongToTime(currentItem.startTime)
holder.itemView.dateEnd_txt.text = "End: " + convertLongToTime(currentItem.endTime)
holder.itemView.targetVelocity_txt.text ="target: " + currentItem.targetVelocity.toString() + "cm/s"
holder.itemView.velocity_txt.text ="measured: " + currentItem.measuredVelocity.toString() + "cm/s"
holder.itemView.maxTime_txt.text ="max time: " + currentItem.maxAttemptTime.toString() + "sec"
holder.itemView.time_txt.text ="measured time: " + currentItem.measuredTime.toString() + "sec"
holder.itemView.usedHand_txt.text = "used hand: " + currentItem.usedHand
holder.itemView.deleteMeasurement_btn.setOnClickListener{
deleteMeasurement()
}
}
fun setData(measurement: List<Measurement>){
@ -50,5 +62,9 @@ class MeasurementList: RecyclerView.Adapter<MeasurementList.MyViewHolder>() {
notifyDataSetChanged()
}
private fun deleteMeasurement() {
mMeasurementViewmodel = ViewModelProvider(this).get(MeasurementViewmodel::class.java)
}
}

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

@ -1,10 +1,11 @@
package com.example.acapendulum20.fragments.update
import android.app.AlertDialog
import android.app.DatePickerDialog
import android.os.Bundle
import android.text.Editable
import android.text.TextUtils
import android.view.*
import android.widget.ArrayAdapter
import androidx.fragment.app.Fragment
import android.widget.Toast
import androidx.lifecycle.Observer
@ -14,11 +15,18 @@ import androidx.navigation.fragment.navArgs
import androidx.recyclerview.widget.LinearLayoutManager
import com.example.acapendulum20.R
import com.example.acapendulum20.fragments.list.MeasurementList
import com.example.acapendulum20.model.Measurement
import com.example.acapendulum20.model.User
import com.example.acapendulum20.viewmodel.MeasurementViewmodel
import com.example.acapendulum20.viewmodel.UserViewmodel
import kotlinx.android.synthetic.main.fragment_add.*
import kotlinx.android.synthetic.main.fragment_add.view.*
import kotlinx.android.synthetic.main.fragment_start_pendulum.*
import kotlinx.android.synthetic.main.fragment_update.*
import kotlinx.android.synthetic.main.fragment_update.view.*
import kotlinx.coroutines.processNextEventInCurrentThread
import java.util.*
import kotlin.system.measureNanoTime
class UpdateFragment : Fragment() {
@ -34,6 +42,28 @@ class UpdateFragment : Fragment() {
// Inflate the layout for this fragment
val view = inflater.inflate(R.layout.fragment_update, container, false)
//dropdown sex
val sex = resources.getStringArray(R.array.sex)
val arrayAdapter = ArrayAdapter(requireContext(), R.layout.dropdown_item, sex)
view.updateSex_et.setAdapter(arrayAdapter)
//dropdown handiness
val handiness = resources.getStringArray(R.array.usedHand)
val arrayAdapterHandiness = ArrayAdapter(requireContext(), R.layout.dropdown_item, handiness)
view.updateHandiness_et.setAdapter(arrayAdapterHandiness)
//Date picker
view.updateBirthday_et.setOnClickListener{
val c = Calendar.getInstance()
val year = c.get(Calendar.YEAR)
val month = c.get(Calendar.MONTH)
val day = c.get(Calendar.DAY_OF_MONTH)
val datePickerDialog = DatePickerDialog(requireActivity(), { view, year, monthOfYear, dayOfMonth ->
updateBirthday_et.text = (dayOfMonth.toString() + "-" + (monthOfYear + 1) + "-" + year) }, year, month, day)
datePickerDialog.show()
}
//Recylerview
val adapter = MeasurementList()
val recyclerView = view.SessionRecyclerview
@ -49,9 +79,9 @@ class UpdateFragment : Fragment() {
view.updateFirstName_et.setText(args.currentUser.firstName)
view.updateLastName_et.setText(args.currentUser.lastName)
view.updateAge_et.setText(args.currentUser.age.toString())
view.updateSex_et.setText(args.currentUser.sex)
view.updateHandiness_et.setText(args.currentUser.handiness)
view.updateBirthday_et.setText(args.currentUser.birthday)
view.updateSex_et.hint = args.currentUser.sex
view.updateHandiness_et.hint = args.currentUser.handiness
//navigate to fragment_start_pendulum
view.startTest_btn.setOnClickListener{
@ -74,13 +104,13 @@ class UpdateFragment : Fragment() {
private fun updateItem(){
val firstName = updateFirstName_et.text.toString()
val lastName = updateLastName_et.text.toString()
val age = Integer.parseInt(updateAge_et.text.toString())
val birthday = updateBirthday_et.text.toString()
val sex = updateSex_et.text.toString()
val handiness = updateHandiness_et.text.toString()
if(inputCheck(firstName, lastName, sex, handiness, updateAge_et.text)){
if(inputCheck(firstName, lastName, sex, handiness, birthday)){
// Create User Object
val updatedUser = User(args.currentUser.id, firstName, lastName, age, sex, handiness)
val updatedUser = User(args.currentUser.id, firstName, lastName, birthday, sex, handiness)
// update current User
mUserViewModel.updateUser(updatedUser)
Toast.makeText(requireContext(), "Updated Successfully!", Toast.LENGTH_SHORT).show()
@ -91,7 +121,7 @@ class UpdateFragment : Fragment() {
}
}
private fun inputCheck(firstName: String, lastName: String, sex: String, handiness:String, age: Editable): Boolean{
private fun inputCheck(firstName: String, lastName: String, sex: String, handiness:String, age: String): Boolean{
return !(TextUtils.isEmpty(firstName) && TextUtils.isEmpty(lastName) && TextUtils.isEmpty(sex) && TextUtils.isEmpty(handiness) && age.isEmpty())
}
@ -118,4 +148,5 @@ class UpdateFragment : Fragment() {
builder.setMessage("Are you sure you want to delete ${args.currentUser.firstName}?")
builder.create().show()
}
}

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

@ -21,5 +21,6 @@ data class Measurement(
val startTime: Long,
val endTime: Long,
val completed: Boolean,
val usedHand: String,
val owner: String,
): Parcelable

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

@ -7,12 +7,12 @@ import kotlinx.android.parcel.Parcelize
@Parcelize
@Entity(tableName = "user_table")
data class User (
data class User(
@PrimaryKey
val id: String,
val firstName: String,
val lastName: String,
val age: Int,
val birthday: String,
val sex: String,
val handiness: String,
): Parcelable

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

@ -2,9 +2,7 @@ package com.example.acapendulum20.repository
import androidx.lifecycle.LiveData
import com.example.acapendulum20.data.MeasurementDao
import com.example.acapendulum20.data.UserDao
import com.example.acapendulum20.model.Measurement
import com.example.acapendulum20.model.User
class MeasurementRepository(private val measurementDao: MeasurementDao) {
@ -22,4 +20,9 @@ class MeasurementRepository(private val measurementDao: MeasurementDao) {
return measurementDao.readAllData(id)
}
suspend fun deleteMeasurement(measurement: Measurement){
measurementDao.deleteMeasurement(measurement)
}
}

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

@ -1,10 +1,8 @@
package com.example.acapendulum20.viewmodel
import android.app.Application
import android.content.Context
import androidx.lifecycle.AndroidViewModel
import androidx.lifecycle.LiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.example.acapendulum20.data.PendulumDatabase
import com.example.acapendulum20.model.Measurement
@ -14,7 +12,7 @@ import kotlinx.coroutines.launch
class MeasurementViewmodel(application: Application): AndroidViewModel(application) {
lateinit var readAllData: LiveData<List<Measurement>>
//lateinit var readAllData: LiveData<List<Measurement>>
private val repository: MeasurementRepository
init{
@ -37,4 +35,10 @@ class MeasurementViewmodel(application: Application): AndroidViewModel(applicati
fun readAllDataForUserId(id: String){
readAllData= repository.readAllDataMeasurement(id)
}
fun deleteMeasurement(measurement: Measurement){
viewModelScope.launch(Dispatchers.IO) {
repository.deleteMeasurement(measurement)
}
}
}

+ 1
- 1
app/src/main/res/layout/custom_row.xml View File

@ -47,7 +47,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="6dp"
android:text="(30)"
android:text="(11.11.2000)"
android:textSize="18sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="@+id/lastName_txt"


+ 23
- 27
app/src/main/res/layout/custom_row_measurement.xml View File

@ -11,8 +11,8 @@
<Button
android:id="@+id/deleteMeasurement_btn"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_width="24dp"
android:layout_height="24dp"
android:background="@drawable/ic_baseline_delete_24"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintDimensionRatio="1:1"
@ -20,7 +20,7 @@
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.504"
app:layout_constraintVertical_bias="0.0"
app:layout_constraintWidth_percent=".06" />
<TextView
@ -37,12 +37,11 @@
<TextView
android:id="@+id/dateStart_txt"
android:layout_width="165dp"
android:layout_width="250dp"
android:layout_height="24dp"
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" />
@ -51,27 +50,24 @@
android:id="@+id/targetVelocity_txt"
android:layout_width="165dp"
android:layout_height="24dp"
android:layout_marginTop="4dp"
android:text="targetVelocity"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.142"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/dateStart_txt"
app:layout_constraintVertical_bias="0.0" />
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.35" />
<TextView
android:id="@+id/velocity_txt"
android:layout_width="165dp"
android:layout_height="24dp"
android:layout_marginTop="4dp"
android:layout_marginEnd="4dp"
android:text="measuredVelocity"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
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_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.35000002" />
<TextView
android:id="@+id/maxTime_txt"
@ -79,35 +75,35 @@
android:layout_height="24dp"
android:layout_marginTop="4dp"
android:text="maxTime"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.142"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/targetVelocity_txt"
app:layout_constraintVertical_bias="0.0" />
app:layout_constraintTop_toBottomOf="@+id/targetVelocity_txt" />
<TextView
android:id="@+id/time_txt"
android:layout_width="165dp"
android:layout_height="24dp"
android:layout_marginTop="4dp"
android:text="measuredTime"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintHorizontal_bias="0.98"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/velocity_txt"
app:layout_constraintVertical_bias="0.0" />
app:layout_constraintTop_toBottomOf="@+id/velocity_txt"
app:layout_constraintVertical_bias="0.142" />
<TextView
android:id="@+id/dateEnd_txt"
android:id="@+id/usedHand_txt"
android:layout_width="165dp"
android:layout_height="24dp"
android:text="dateEnd"
android:layout_marginTop="4dp"
android:text="usedHand"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0" />
app:layout_constraintTop_toBottomOf="@+id/maxTime_txt"
app:layout_constraintVertical_bias="1.0" />
</androidx.constraintlayout.widget.ConstraintLayout>

+ 9
- 0
app/src/main/res/layout/dropdown_item.xml View File

@ -0,0 +1,9 @@
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TextView"
android:padding="14dp"
android:textColor="@color/black"
android:textSize="16sp"
android:textStyle="bold" />

+ 62
- 33
app/src/main/res/layout/fragment_add.xml View File

@ -7,13 +7,36 @@
android:padding="40dp"
tools:context=".fragments.add.AddFragment">
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/textInputLayout1"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.ExposedDropdownMenu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="64dp"
app:layout_constraintBottom_toTopOf="@+id/add_btn"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.525"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textInputLayout"
tools:ignore="MissingConstraints">
<AutoCompleteTextView
android:id="@+id/addHandiness_et"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:hint="handiness"
android:inputType="none" />
</com.google.android.material.textfield.TextInputLayout>
<EditText
android:id="@+id/addFirstName_et"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName"
android:hint="First Name"
android:hint="first Name"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
@ -24,56 +47,62 @@
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:ems="10"
android:hint="last Name"
android:inputType="textPersonName"
android:hint="Last Name"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.525"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/addFirstName_et" />
<EditText
android:id="@+id/addAge_et"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:ems="10"
android:inputType="number"
android:hint="Age"
app:layout_constraintTop_toBottomOf="@+id/addLastName_et"
tools:layout_editor_absoluteX="100dp" />
<EditText
android:id="@+id/addSex_et"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
<TextView
android:id="@+id/addBirthday_et"
android:layout_width="333dp"
android:layout_height="51dp"
android:layout_marginTop="12dp"
android:ems="10"
android:inputType="textPersonName"
android:hint="Sex"
android:hint="Age"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.512"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/addAge_et" />
android:textColor="?attr/editTextColor"
android:background="?attr/editTextBackground"
android:gravity="center_vertical"
android:textAppearance="?android:attr/textAppearanceMediumInverse"
app:layout_constraintTop_toBottomOf="@+id/addLastName_et" />
<EditText
android:id="@+id/addHandiness_et"
<Button
android:id="@+id/add_btn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:ems="10"
android:inputType="textPersonName"
android:hint="Handiness"
android:layout_marginBottom="224dp"
android:text="Add"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/addSex_et" />
app:layout_constraintHorizontal_bias="0.525"
app:layout_constraintStart_toStartOf="parent" />
<Button
android:id="@+id/add_btn"
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/textInputLayout"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.ExposedDropdownMenu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:text="Add"
android:layout_marginTop="12dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.525"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/addHandiness_et" />
app:layout_constraintTop_toBottomOf="@+id/addBirthday_et"
tools:ignore="MissingConstraints">
<AutoCompleteTextView
android:id="@+id/chooseSex_et"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:hint="choose sex"
android:inputType="none" />
</com.google.android.material.textfield.TextInputLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

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

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".PendulumSettingsFragment">
<!-- TODO: Update blank fragment layout -->
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/hello_blank_fragment" />
</FrameLayout>

+ 24
- 0
app/src/main/res/layout/fragment_start_pendulum.xml View File

@ -46,4 +46,28 @@
app:layout_constraintTop_toBottomOf="@+id/targetVelocity_et"
app:layout_constraintVertical_bias="0.079" />
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/textInputLayout"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.ExposedDropdownMenu"
android:layout_width="160dp"
android:layout_height="63dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.226"
tools:ignore="MissingConstraints">
<AutoCompleteTextView
android:id="@+id/chooseHandiness_et"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:hint="choose handiness"
android:inputType="none" />
</com.google.android.material.textfield.TextInputLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

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

@ -8,6 +8,29 @@
tools:context=".fragments.update.UpdateFragment"
android:padding="24dp">
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/textInputLayout1"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.ExposedDropdownMenu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.666"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.377"
tools:ignore="MissingConstraints">
<AutoCompleteTextView
android:id="@+id/updateHandiness_et"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:hint=""
android:inputType="none" />
</com.google.android.material.textfield.TextInputLayout>
<EditText
android:id="@+id/updateFirstName_et"
android:layout_width="match_parent"
@ -20,11 +43,12 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<EditText
android:id="@+id/updateLastName_et"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_marginTop="8dp"
android:ems="10"
android:hint="Last Name"
android:inputType="textPersonName"
@ -33,62 +57,55 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/updateFirstName_et" />
<EditText
android:id="@+id/updateAge_et"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:ems="10"
android:hint="Age"
android:inputType="number"
android:minHeight="48dp"
app:layout_constraintTop_toBottomOf="@+id/updateLastName_et"
tools:layout_editor_absoluteX="100dp" />
<EditText
android:id="@+id/updateSex_et"
<TextView
android:id="@+id/updateBirthday_et"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_marginTop="8dp"
android:ems="10"
android:hint="Sex"
android:inputType="textPersonName"
android:hint="Birthday"
android:minHeight="48dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/updateAge_et" />
android:textColor="?attr/editTextColor"
android:background="?attr/editTextBackground"
android:gravity="center_vertical"
android:textAppearance="?android:attr/textAppearanceMediumInverse"
app:layout_constraintTop_toBottomOf="@+id/updateLastName_et" />
<EditText
android:id="@+id/updateHandiness_et"
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/textInputLayout"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.ExposedDropdownMenu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:ems="10"
android:hint="Handiness"
android:inputType="textPersonName"
android:minHeight="48dp"
android:layout_marginTop="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.458"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/updateSex_et" />
app:layout_constraintTop_toBottomOf="@+id/updateBirthday_et"
tools:ignore="MissingConstraints">
<Button
android:id="@+id/update_btn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:text="Update"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/updateHandiness_et" />
<AutoCompleteTextView
android:id="@+id/updateSex_et"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:inputType="none"
android:hint="" />
</com.google.android.material.textfield.TextInputLayout>
<Button
android:id="@+id/startTest_btn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Start Test"
app:layout_constraintBottom_toTopOf="@+id/SessionRecyclerview"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.333"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/update_btn" />
app:layout_constraintTop_toBottomOf="@+id/update_btn"
app:layout_constraintVertical_bias="1.0" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/SessionRecyclerview"
@ -96,8 +113,19 @@
android:layout_height="251dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.538"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="1.0" />
<Button
android:id="@+id/update_btn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="328dp"
android:text="Update"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

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

@ -55,6 +55,9 @@
<argument
android:name="currentUser"
app:argType="com.example.acapendulum20.model.User" />
<action
android:id="@+id/action_startPendulumFragment_to_pendulumSettingsFragment"
app:destination="@id/pendulumSettingsFragment" />
</fragment>
<fragment
android:id="@+id/pendulumFragment"
@ -71,4 +74,13 @@
android:name="currentUser"
app:argType="com.example.acapendulum20.model.User" />
</fragment>
<fragment
android:id="@+id/pendulumSettingsFragment"
android:name="com.example.acapendulum20.PendulumSettingsFragment"
android:label="fragment_pendulum_settings"
tools:layout="@layout/fragment_pendulum_settings" >
<action
android:id="@+id/action_pendulumSettingsFragment_to_startPendulumFragment"
app:destination="@id/startPendulumFragment" />
</fragment>
</navigation>

+ 12
- 0
app/src/main/res/values/strings.xml View File

@ -3,4 +3,16 @@
<!-- TODO: Remove or change this placeholder text -->
<string name="hello_blank_fragment">Hello blank fragment</string>
<string name="textview">TextView</string>
<string-array name="sex">
<item>male</item>
<item>female</item>
<item>diverse</item>
</string-array>
<string-array name="usedHand">
<item>right</item>
<item>left</item>
</string-array>
</resources>

Loading…
Cancel
Save