Browse Source

Implemented successfully delete Measurements

Resetted Pendulum Logic to 55cd99ef36
master
Schahin Rouhanizadeh 2 years ago
parent
commit
ddc27b61f0
6 changed files with 60 additions and 47 deletions
  1. +4
    -5
      .idea/misc.xml
  2. +34
    -30
      app/src/main/java/com/example/acapendulum20/canvas/CanvasPendulum.kt
  3. +4
    -2
      app/src/main/java/com/example/acapendulum20/fragments/pendulum/PendulumFragment.kt
  4. +9
    -5
      app/src/main/java/com/example/acapendulum20/fragments/update/MeasurementList.kt
  5. +8
    -4
      app/src/main/java/com/example/acapendulum20/fragments/update/UpdateFragment.kt
  6. +1
    -1
      app/src/main/java/com/example/acapendulum20/viewmodel/MeasurementViewmodel.kt

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

@ -12,19 +12,18 @@
<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/custom_row_measurement.xml" value="0.5" />
<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_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.33" /> <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.5" />
<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/start_pendulum_fragment.xml" value="0.38697916666666665" /> <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/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.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/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" />
<entry key="..\:/Users/Schahin/Projects/acaPendulum2.0/app/src/main/res/layout/fragment_add.xml" value="0.25" />
<entry key="..\:/Users/Schahin/Projects/acaPendulum2.0/app/src/main/res/layout/fragment_pendulum.xml" value="0.25052083333333336" />
</map> </map>
</option> </option>
</component> </component>


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

@ -26,6 +26,7 @@ class CanvasPendulum @JvmOverloads constructor(
this.canvas = it this.canvas = it
} }
//println("ONDRAW")
//draw line //draw line
mPendulum.startPosition.x = (width / 2).toFloat() mPendulum.startPosition.x = (width / 2).toFloat()
paint.isAntiAlias = true paint.isAntiAlias = true
@ -47,7 +48,7 @@ class CanvasPendulum @JvmOverloads constructor(
canvas?.drawCircle( canvas?.drawCircle(
mPendulum.stopPosition.x, mPendulum.stopPosition.x,
mPendulum.stopPosition.y, mPendulum.stopPosition.y,
mPendulum.ballRadius,
mPendulum.ballr,
paint paint
) )
@ -56,7 +57,7 @@ class CanvasPendulum @JvmOverloads constructor(
paint.strokeWidth = 1f paint.strokeWidth = 1f
paint.color = Color.RED paint.color = Color.RED
if (mPendulum.angleVelocity > 0) { if (mPendulum.angleVelocity > 0) {
if (mPendulum.stopPosition.x < (width / 3) - 30f && mPendulum.stopPosition.x + 30 > (width / 3) - 30f - mPendulum.ballRadius) {
if (mPendulum.stopPosition.x < (width / 3) - 30f && mPendulum.stopPosition.x + 30 > (width / 3) - 30f - mPendulum.ballr) {
paint.style = Paint.Style.FILL_AND_STROKE paint.style = Paint.Style.FILL_AND_STROKE
paint.strokeWidth = 10f paint.strokeWidth = 10f
paint.color = Color.GREEN paint.color = Color.GREEN
@ -69,7 +70,7 @@ class CanvasPendulum @JvmOverloads constructor(
paint.strokeWidth = 1f paint.strokeWidth = 1f
paint.color = Color.RED paint.color = Color.RED
if (mPendulum.angleVelocity < 0) { if (mPendulum.angleVelocity < 0) {
if (mPendulum.stopPosition.x > (width / 1.5) - 30f && mPendulum.stopPosition.x + 30 < (width / 1.5) + 30f + mPendulum.ballRadius) {
if (mPendulum.stopPosition.x > (width / 1.5) - 30f && mPendulum.stopPosition.x + 30 < (width / 1.5) + 30f + mPendulum.ballr) {
paint.style = Paint.Style.FILL_AND_STROKE paint.style = Paint.Style.FILL_AND_STROKE
paint.strokeWidth = 10f paint.strokeWidth = 10f
paint.color = Color.GREEN paint.color = Color.GREEN
@ -85,39 +86,45 @@ class CanvasPendulum @JvmOverloads constructor(
if (mPendulum.magneticField) { if (mPendulum.magneticField) {
var gravity = 0.981f
var damping = 0.996f
if (mPendulum.stopPosition.x > canvas.width / 4f && mPendulum.stopPosition.x <= canvas.width * 0.75f) { if (mPendulum.stopPosition.x > canvas.width / 4f && mPendulum.stopPosition.x <= canvas.width * 0.75f) {
mPendulum.gravity = 1.981f
gravity = 1.981f
if (mPendulum.stopPosition.x > canvas.width / 3.toFloat() && mPendulum.stopPosition.x <= canvas.width / 1.5.toFloat()) { if (mPendulum.stopPosition.x > canvas.width / 3.toFloat() && mPendulum.stopPosition.x <= canvas.width / 1.5.toFloat()) {
mPendulum.gravity = 2.981f
gravity = 2.981f
if (mPendulum.stopPosition.x >= canvas.width / 2.toFloat() - 3 && mPendulum.stopPosition.x <= canvas.width / 2.toFloat() + 3) { if (mPendulum.stopPosition.x >= canvas.width / 2.toFloat() - 3 && mPendulum.stopPosition.x <= canvas.width / 2.toFloat() + 3) {
mPendulum.damping = 0.3f
damping = 0.3f
} }
} }
} }
mPendulum.angleAcceleration = ((-1 * mPendulum.gravity / mPendulum.stringLength) * (mPendulum.startAngle)).toFloat()
mPendulum.angleAcceleration =
((-1 * gravity / mPendulum.r) * (mPendulum.angle)).toFloat()
mPendulum.angleVelocity += mPendulum.angleAcceleration mPendulum.angleVelocity += mPendulum.angleAcceleration
mPendulum.angleVelocity *= mPendulum.damping
mPendulum.startAngle += mPendulum.angleVelocity
mPendulum.angleVelocity *= damping
mPendulum.angle += mPendulum.angleVelocity
//Polar to cartesian conversion //Polar to cartesian conversion
mPendulum.stopPosition.x = mPendulum.stringLength * (sin(mPendulum.startAngle)).toFloat()
mPendulum.stopPosition.y = mPendulum.stringLength * (cos(mPendulum.startAngle)).toFloat()
mPendulum.stopPosition.x = mPendulum.r * (sin(mPendulum.angle)).toFloat()
mPendulum.stopPosition.y = mPendulum.r * (cos(mPendulum.angle)).toFloat()
//Origin transition //Origin transition
mPendulum.stopPosition.x += mPendulum.startPosition.x mPendulum.stopPosition.x += mPendulum.startPosition.x
} }
if (!mPendulum.magneticField) { if (!mPendulum.magneticField) {
val gravity = 0.981f
val damping = 0.996f
mPendulum.angleAcceleration = ((-1 * mPendulum.gravity / mPendulum.stringLength) * (mPendulum.startAngle)).toFloat()
mPendulum.angleAcceleration =
((-1 * gravity / mPendulum.r) * (mPendulum.angle)).toFloat()
mPendulum.angleVelocity += mPendulum.angleAcceleration mPendulum.angleVelocity += mPendulum.angleAcceleration
mPendulum.angleVelocity *= mPendulum.damping
mPendulum.startAngle += mPendulum.angleVelocity
mPendulum.angleVelocity *= damping
mPendulum.angle += mPendulum.angleVelocity
//Polar to cartesian conversion //Polar to cartesian conversion
mPendulum.stopPosition.x = mPendulum.stringLength * (sin(mPendulum.startAngle)).toFloat()
mPendulum.stopPosition.y = mPendulum.stringLength * (cos(mPendulum.startAngle)).toFloat()
mPendulum.stopPosition.x = mPendulum.r * (sin(mPendulum.angle)).toFloat()
mPendulum.stopPosition.y = mPendulum.r * (cos(mPendulum.angle)).toFloat()
//Origin transition //Origin transition
mPendulum.stopPosition.x += mPendulum.startPosition.x mPendulum.stopPosition.x += mPendulum.startPosition.x
} }
@ -131,11 +138,11 @@ class CanvasPendulum @JvmOverloads constructor(
mPendulum.magneticField = magnet mPendulum.magneticField = magnet
} }
fun getVelocity(): Double {
var currentVelocity = mPendulum.angleVelocity * 1000
fun getVelocity(): Double {
var currentVelocity = mPendulum.angleVelocity * 1000
val roundoff = (currentVelocity * 100.0).roundToInt() / 100.0
return abs(roundoff)
val roundoff = (currentVelocity * 100.0).roundToInt() / 100.0
return abs(roundoff)
} }
} }
@ -147,15 +154,12 @@ class Pendulum {
var startPosition: Position = Position(0f, 0f) var startPosition: Position = Position(0f, 0f)
var stopPosition: Position = Position(0f, 0f) var stopPosition: Position = Position(0f, 0f)
var r = 800f
var startAngle: Double = Math.PI / 12
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
//PI/6 Max ausschwingen
var angle: Double = Math.PI / 12
var angleVelocity: Float = 0.0f //
var angleAcceleration: Float = 0.0f //
var ballr: Float = 70.0f //
var magneticField: Boolean = false var magneticField: Boolean = false
} }

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

@ -84,13 +84,15 @@ class PendulumFragment : Fragment() {
magnetButton.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")
mCanvasPendulum.startMagnet(true) mCanvasPendulum.startMagnet(true)
//mCanvasPendulum.magnet(true)
} }
if (event?.action == MotionEvent.ACTION_UP){ if (event?.action == MotionEvent.ACTION_UP){
//println("button action UP")
println("button action UP")
mCanvasPendulum.stopMagnet(false) mCanvasPendulum.stopMagnet(false)
//mCanvasPendulum.magnet(false)
} }
return true return true
} }


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

@ -16,9 +16,9 @@ import java.text.SimpleDateFormat
import java.util.* import java.util.*
import com.example.acapendulum20.viewmodel.MeasurementViewmodel import com.example.acapendulum20.viewmodel.MeasurementViewmodel
class MeasurementList: RecyclerView.Adapter<MeasurementList.MyViewHolder>() {
class MeasurementList(private var mMeasurementViewmodel: MeasurementViewmodel): RecyclerView.Adapter<MeasurementList.MyViewHolder>() {
private lateinit var mMeasurementViewmodel: MeasurementViewmodel
private var sessionList = emptyList<Measurement>() private var sessionList = emptyList<Measurement>()
@ -52,7 +52,7 @@ class MeasurementList: RecyclerView.Adapter<MeasurementList.MyViewHolder>() {
holder.itemView.usedHand_txt.text = "used hand: " + currentItem.usedHand holder.itemView.usedHand_txt.text = "used hand: " + currentItem.usedHand
holder.itemView.deleteMeasurement_btn.setOnClickListener{ holder.itemView.deleteMeasurement_btn.setOnClickListener{
deleteMeasurement()
deleteMeasurement(currentItem)
} }
} }
@ -62,8 +62,12 @@ class MeasurementList: RecyclerView.Adapter<MeasurementList.MyViewHolder>() {
notifyDataSetChanged() notifyDataSetChanged()
} }
private fun deleteMeasurement() {
mMeasurementViewmodel = ViewModelProvider(this).get(MeasurementViewmodel::class.java)
private fun deleteMeasurement(currentItem: Measurement) {
//mMeasurementViewmodel = ViewModelProvider(this).get(MeasurementViewmodel::class.java)
println(mMeasurementViewmodel)
println(currentItem)
mMeasurementViewmodel.deleteMeasurement(currentItem)
println("Hopefully deleted the Measurement")
} }
} }


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

@ -64,19 +64,23 @@ class UpdateFragment : Fragment() {
datePickerDialog.show() datePickerDialog.show()
} }
mUserViewModel = ViewModelProvider(this).get(UserViewmodel::class.java)
mMeasurementViewmodel = ViewModelProvider(this).get(MeasurementViewmodel::class.java)
mMeasurementViewmodel.readAllDataForUserId(args.currentUser.id)
//Recylerview //Recylerview
val adapter = MeasurementList()
val adapter = MeasurementList(mMeasurementViewmodel)
val recyclerView = view.SessionRecyclerview val recyclerView = view.SessionRecyclerview
recyclerView.adapter = adapter recyclerView.adapter = adapter
recyclerView.layoutManager = LinearLayoutManager(requireContext()) recyclerView.layoutManager = LinearLayoutManager(requireContext())
mUserViewModel = ViewModelProvider(this).get(UserViewmodel::class.java)
mMeasurementViewmodel = ViewModelProvider(this).get(MeasurementViewmodel::class.java)
mMeasurementViewmodel.readAllDataForUserId(args.currentUser.id)
mMeasurementViewmodel.readAllData.observe(viewLifecycleOwner, Observer { measurement -> mMeasurementViewmodel.readAllData.observe(viewLifecycleOwner, Observer { measurement ->
adapter.setData(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)
view.updateBirthday_et.setText(args.currentUser.birthday) view.updateBirthday_et.setText(args.currentUser.birthday)


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

@ -12,7 +12,7 @@ import kotlinx.coroutines.launch
class MeasurementViewmodel(application: Application): AndroidViewModel(application) { class MeasurementViewmodel(application: Application): AndroidViewModel(application) {
//lateinit var readAllData: LiveData<List<Measurement>>
lateinit var readAllData: LiveData<List<Measurement>>
private val repository: MeasurementRepository private val repository: MeasurementRepository
init{ init{


Loading…
Cancel
Save