Commit 4ed99ca4 authored by Lukas Bersinger's avatar Lukas Bersinger
Browse files

set up add task view

parent 059fb678
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Kotlin2JvmCompilerArguments">
<option name="jvmTarget" value="1.8" />
</component>
</project>
\ No newline at end of file
......@@ -22,6 +22,15 @@ android {
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = "1.8"
}
}
dependencies {
......
package ch.ost.rj.mge.miniproject.tasktracker.activities
import androidx.appcompat.app.AppCompatActivity
import android.app.DatePickerDialog
import android.os.Bundle
import android.text.Editable
import android.widget.Button
import android.widget.ImageButton
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import androidx.core.widget.doAfterTextChanged
import androidx.core.widget.doOnTextChanged
import ch.ost.rj.mge.miniproject.tasktracker.R
import ch.ost.rj.mge.miniproject.tasktracker.models.Task
import kotlinx.android.synthetic.main.activity_add_task.*
import java.text.DateFormat
import java.util.*
class AddTaskActivity : AppCompatActivity() {
private lateinit var btnCancel: Button
private lateinit var btnCreate: Button
private lateinit var fldName: TextView
private lateinit var txtDueDate: TextView
private lateinit var btnDatePicker: ImageButton
private lateinit var fldEstimateHours: TextView
private lateinit var fldEstimateMinutes: TextView
private var estimateMinutes = 0L
private var estimateHours = 0L
private val task = Task()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_add_task)
btnCancel = findViewById(R.id.btnCancelCreateTask);
btnCancel.setOnClickListener {
finish()
}
btnCreate = findViewById(R.id.btnCreateTask);
btnCreate.setOnClickListener {
createTask();
}
fldName = findViewById(R.id.fldTaskName)
fldName.doOnTextChanged { text, start, before, count ->
task.name = text.toString()
updateValidity()
}
fldEstimateHours = findViewById(R.id.fldEstimateHours)
fldEstimateHours.doOnTextChanged { text, start, before, count ->
val input = text.toString().toLongOrNull()
if (input != null) {
estimateHours = input
updateEstimate()
}
}
fldEstimateMinutes = findViewById(R.id.fldEstimateMinutes)
fldEstimateMinutes.doOnTextChanged { text, start, before, count ->
val input = text.toString().toLongOrNull()
if (input != null) {
estimateMinutes = input
updateEstimate()
}
}
txtDueDate = findViewById(R.id.txtDueDate)
btnDatePicker = findViewById(R.id.btnDatePicker)
btnDatePicker.setOnClickListener {
val c = Calendar.getInstance()
val initialYear = c.get(Calendar.YEAR)
val initialMonth = c.get(Calendar.MONTH)
val initialDayOfMonth = c.get(Calendar.DAY_OF_MONTH)
DatePickerDialog(
this,
{ _, year, month, dayOfMonth -> updateDueDate(year, month, dayOfMonth) },
initialYear,
initialMonth,
initialDayOfMonth
).show()
}
updateValidity();
}
fun createTask() {
// TODO: Create Task
finish();
}
fun updateValidity() {
btnCreate.isEnabled = task.isValid();
}
fun updateEstimate() {
task.estimatedTimeMinutes = estimateMinutes + (estimateHours * 60)
updateValidity()
}
fun updateDueDate(year: Int, month: Int, dayOfMonth: Int) {
val date = Calendar.getInstance()
date.set(Calendar.YEAR, year)
date.set(Calendar.MONTH, month)
date.set(Calendar.DAY_OF_MONTH, dayOfMonth)
task.dueDate = date
txtDueDate.text = DateFormat.getDateInstance().format(date.time)
updateValidity()
}
}
\ No newline at end of file
......@@ -5,12 +5,28 @@ import java.util.*
class Task {
var id: UUID = UUID.randomUUID()
var name: String? = null
var dueDate: Date? = null
var dueDate: Calendar? = null
var estimatedTimeMinutes: Long = 0
var actualTimeMinutes: Long = 0
var actualTimeSeconds: Long = 0
fun differenceMinutes(): Long {
return this.actualTimeMinutes - this.estimatedTimeMinutes
return Math.round(this.actualTimeSeconds / 60.0) - this.estimatedTimeMinutes
}
fun isValid(): Boolean {
if (name == null || name!!.isEmpty()) {
return false
}
if (dueDate == null) {
return false
}
if (estimatedTimeMinutes == 0L) {
return false
}
return true
}
}
<vector android:height="24dp" android:tint="#FFFFFF"
android:viewportHeight="24" android:viewportWidth="24"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M11.99,2C6.47,2 2,6.48 2,12s4.47,10 9.99,10C17.52,22 22,17.52 22,12S17.52,2 11.99,2zM12,20c-4.42,0 -8,-3.58 -8,-8s3.58,-8 8,-8 8,3.58 8,8 -3.58,8 -8,8z"/>
<path android:fillColor="@android:color/white" android:pathData="M12.5,7H11v6l5.25,3.15 0.75,-1.23 -4.5,-2.67z"/>
</vector>
......@@ -41,36 +41,110 @@
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:labelFor="@id/fldDueDate"
android:text="@string/lblDueDate"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/fldTaskName" />
<EditText
android:id="@+id/fldDueDate"
<TextView
android:id="@+id/lblEstimate"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:clickable="true"
android:ems="10"
android:focusable="true"
android:inputType="date"
app:layout_constraintEnd_toStartOf="@+id/btnDatepicker"
android:text="@string/lblEstimateTime"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/lblDueDate" />
app:layout_constraintTop_toBottomOf="@+id/btnDatePicker" />
<ImageButton
android:id="@+id/btnDatepicker"
android:id="@+id/btnDatePicker"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:backgroundTint="@color/design_default_color_background"
android:contentDescription="@string/btnDatePicker"
android:tint="@color/colorPrimary"
app:layout_constraintBottom_toBottomOf="@+id/fldDueDate"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/lblDueDate"
app:srcCompat="@drawable/ic_baseline_calendar_today_24" />
<TextView
android:id="@+id/txtDueDate"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:text="-"
android:textAppearance="@style/TextAppearance.AppCompat.Large"
app:layout_constraintBottom_toBottomOf="@+id/btnDatePicker"
app:layout_constraintEnd_toStartOf="@+id/btnDatePicker"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/lblDueDate" />
<Button
android:id="@+id/btnCreateTask"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_marginBottom="16dp"
android:text="@string/btnCreateTask"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
<Button
android:id="@+id/btnCancelCreateTask"
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/btnCancelCreateTask"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<EditText
android:id="@+id/fldEstimateHours"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:ems="10"
android:inputType="number"
android:text="0"
android:textAlignment="textEnd"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/lblEstimate" />
<TextView
android:id="@+id/lblEstimateHours"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:text="@string/lblEstimateHours"
app:layout_constraintBaseline_toBaselineOf="@+id/fldEstimateHours"
app:layout_constraintStart_toEndOf="@+id/fldEstimateHours" />
<EditText
android:id="@+id/fldEstimateMinutes"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:ems="10"
android:inputType="number"
android:text="0"
android:textAlignment="textEnd"
app:layout_constraintStart_toEndOf="@+id/lblEstimateHours"
app:layout_constraintTop_toBottomOf="@+id/lblEstimate" />
<TextView
android:id="@+id/lblEstimateMinutes"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:text="@string/lblEstimateMinutes"
app:layout_constraintBaseline_toBaselineOf="@+id/fldEstimateMinutes"
app:layout_constraintStart_toEndOf="@+id/fldEstimateMinutes" />
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
......@@ -4,4 +4,10 @@
<string name="txtTaskListEmpty">Alles erledigt</string>
<string name="lblTaskName">Name</string>
<string name="lblDueDate">Fälligkeitsdatum</string>
<string name="lblEstimateTime">Geschätzte Dauer</string>
<string name="btnDatePicker">Datum auswählen</string>
<string name="btnCreateTask">Speichern</string>
<string name="btnCancelCreateTask">Abbrechen</string>
<string name="lblEstimateHours">h</string>
<string name="lblEstimateMinutes">m</string>
</resources>
\ No newline at end of file
#Wed Oct 14 16:23:41 CEST 2020
#Sun Oct 18 16:24:10 CEST 2020
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-all.zip
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