Commit 170af1fd authored by Lukas Bersinger's avatar Lukas Bersinger
Browse files

allow marking tasks as done

parent be9f0441
package ch.ost.rj.mge.miniproject.tasktracker.activities
import android.annotation.SuppressLint
import android.content.Intent
import android.os.Bundle
import android.os.Handler
import android.os.Looper
import android.widget.Button
import android.widget.ImageButton
import android.widget.Switch
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.SwitchCompat
import ch.ost.rj.mge.miniproject.tasktracker.R
import ch.ost.rj.mge.miniproject.tasktracker.models.Task
import ch.ost.rj.mge.miniproject.tasktracker.repositories.TaskRepository
import com.google.android.material.switchmaterial.SwitchMaterial
import java.text.DateFormat
import java.util.*
import kotlin.math.floor
......@@ -35,6 +39,8 @@ class TimeTrackingActivity : AppCompatActivity() {
private lateinit var btnStart: Button
private lateinit var btnStop: Button
private lateinit var swtDone: SwitchMaterial
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_time_tracking)
......@@ -46,6 +52,18 @@ class TimeTrackingActivity : AppCompatActivity() {
txtActualTime = findViewById(R.id.txtActualTime)
val btnBack: Button = findViewById(R.id.btnBack)
btnBack.setOnClickListener {
finish()
}
swtDone = findViewById(R.id.swtMarkDone)
swtDone.setOnClickListener {
task.isCompleted = swtDone.isChecked
TaskRepository.updateTask(task)
updateButtonState()
}
btnStart = findViewById(R.id.btnStart)
btnStart.setOnClickListener {
task.timerStartDate = Calendar.getInstance()
......@@ -85,6 +103,8 @@ class TimeTrackingActivity : AppCompatActivity() {
val txtDueDate: TextView = findViewById(R.id.txtDueDate)
txtDueDate.text = DateFormat.getDateInstance().format(task.dueDate!!.time)
swtDone.isChecked = task.isCompleted
setEstimatedTime()
updateActualTime()
updateButtonState()
......@@ -124,9 +144,17 @@ class TimeTrackingActivity : AppCompatActivity() {
}
private fun updateButtonState() {
val timerRunning = task.isTimerRunning()
btnStart.isEnabled = !timerRunning
btnStop.isEnabled = timerRunning
if (swtDone.isChecked) {
btnStart.isEnabled = false
btnStop.isEnabled = false
} else {
val timerRunning = task.isTimerRunning()
btnStart.isEnabled = !timerRunning
btnStop.isEnabled = timerRunning
swtDone.isEnabled = !timerRunning
}
}
private fun startTimer() {
......
......@@ -44,6 +44,7 @@
android:layout_gravity="end"
android:layout_marginEnd="8dp"
android:backgroundTint="@color/colorPrimary"
android:contentDescription="@string/btnEdit"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
......@@ -59,7 +60,7 @@
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:text="TextView"
android:text=""
android:textAlignment="center"
android:textAppearance="@style/TextAppearance.AppCompat.Display2"
android:textColor="@android:color/primary_text_light"
......@@ -86,7 +87,7 @@
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:text="TextView"
android:text=""
android:textAppearance="@style/TextAppearance.AppCompat.Large"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
......@@ -110,7 +111,7 @@
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:text="TextView"
android:text=""
android:textAppearance="@style/TextAppearance.AppCompat.Large"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
......@@ -154,5 +155,26 @@
app:layout_constraintStart_toEndOf="@+id/btnStop"
app:layout_constraintTop_toBottomOf="@+id/txtActualTime" />
<Button
android:id="@+id/btnBack"
style="@style/Widget.MaterialComponents.Button.TextButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginBottom="16dp"
android:text="@string/btnBack"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<com.google.android.material.switchmaterial.SwitchMaterial
android:id="@+id/swtMarkDone"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_marginTop="64dp"
android:layout_marginEnd="16dp"
android:text="@string/swtMarkDone"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/btnStop" />
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
......@@ -13,4 +13,7 @@
<string name="lblActualTime">Gemessene Zeit</string>
<string name="btnStart">Start</string>
<string name="btnStop">Stop</string>
<string name="btnBack">Zurück</string>
<string name="swtMarkDone">erledigt</string>
<string name="btnEdit">bearbeiten</string>
</resources>
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment