Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Lukas Bersinger
TaskTracker
Commits
2b38fd9b
Commit
2b38fd9b
authored
Oct 24, 2020
by
Lukas Bersinger
Browse files
move task create form to fragment
parent
9a0a96cc
Changes
5
Hide whitespace changes
Inline
Side-by-side
app/src/main/java/ch/ost/rj/mge/miniproject/tasktracker/activities/AddTaskActivity.kt
View file @
2b38fd9b
...
...
@@ -8,25 +8,17 @@ import android.widget.TextView
import
androidx.appcompat.app.AppCompatActivity
import
androidx.core.widget.doOnTextChanged
import
ch.ost.rj.mge.miniproject.tasktracker.R
import
ch.ost.rj.mge.miniproject.tasktracker.fragments.TaskFormFragment
import
ch.ost.rj.mge.miniproject.tasktracker.models.Task
import
ch.ost.rj.mge.miniproject.tasktracker.repositories.TaskRepository
import
java.text.DateFormat
import
java.util.*
class
AddTaskActivity
:
AppCompatActivity
()
{
class
AddTaskActivity
:
AppCompatActivity
()
,
TaskFormFragment
.
OnTaskChangeListener
{
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
?)
{
...
...
@@ -43,49 +35,6 @@ class AddTaskActivity : AppCompatActivity() {
createTask
()
}
fldName
=
findViewById
(
R
.
id
.
fldTaskName
)
fldName
.
doOnTextChanged
{
text
,
_
,
_
,
_
->
task
.
name
=
text
.
toString
()
updateValidity
()
}
fldEstimateHours
=
findViewById
(
R
.
id
.
fldEstimateHours
)
fldEstimateHours
.
doOnTextChanged
{
text
,
_
,
_
,
_
->
val
input
=
text
.
toString
().
toLongOrNull
()
if
(
input
!=
null
)
{
estimateHours
=
input
updateEstimate
()
}
}
fldEstimateMinutes
=
findViewById
(
R
.
id
.
fldEstimateMinutes
)
fldEstimateMinutes
.
doOnTextChanged
{
text
,
_
,
_
,
_
->
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
()
}
...
...
@@ -98,19 +47,18 @@ class AddTaskActivity : AppCompatActivity() {
btnCreate
.
isEnabled
=
task
.
isValid
()
}
fun
updateEstimate
(
)
{
task
.
estimatedTimeMinutes
=
estimateMinutes
+
(
estimateHours
*
60
)
override
fun
onTitleChange
(
title
:
String
)
{
task
.
name
=
title
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
)
override
fun
onDueDateChange
(
dueDate
:
Calendar
)
{
task
.
dueDate
=
dueDate
updateValidity
()
}
override
fun
onEstimateChange
(
hours
:
Long
,
minutes
:
Long
)
{
task
.
estimatedTimeMinutes
=
(
hours
*
60
)
+
minutes
updateValidity
()
}
}
\ No newline at end of file
app/src/main/java/ch/ost/rj/mge/miniproject/tasktracker/fragments/TaskFormFragment.kt
0 → 100644
View file @
2b38fd9b
package
ch.ost.rj.mge.miniproject.tasktracker.fragments
import
android.app.DatePickerDialog
import
android.content.Context
import
android.os.Bundle
import
android.view.LayoutInflater
import
android.view.View
import
android.view.ViewGroup
import
android.widget.ImageButton
import
android.widget.TextView
import
androidx.core.widget.doOnTextChanged
import
androidx.fragment.app.Fragment
import
ch.ost.rj.mge.miniproject.tasktracker.R
import
java.text.DateFormat
import
java.util.*
class
TaskFormFragment
:
Fragment
()
{
private
var
changeListener
:
OnTaskChangeListener
?
=
null
private
var
estimateMinutes
=
0L
private
var
estimateHours
=
0L
override
fun
onCreateView
(
inflater
:
LayoutInflater
,
container
:
ViewGroup
?,
savedInstanceState
:
Bundle
?
):
View
?
{
val
fragment
=
inflater
.
inflate
(
R
.
layout
.
fragment_task_form
,
container
,
false
)
val
fldName
:
TextView
=
fragment
.
findViewById
(
R
.
id
.
fldTaskName
)
fldName
.
doOnTextChanged
{
text
,
_
,
_
,
_
->
changeListener
?.
onTitleChange
(
text
.
toString
())
}
val
fldEstimateHours
:
TextView
=
fragment
.
findViewById
(
R
.
id
.
fldEstimateHours
)
fldEstimateHours
.
doOnTextChanged
{
text
,
_
,
_
,
_
->
val
input
=
text
.
toString
().
toLongOrNull
()
if
(
input
!=
null
)
{
estimateHours
=
input
changeListener
?.
onEstimateChange
(
estimateHours
,
estimateMinutes
)
}
}
val
fldEstimateMinutes
:
TextView
=
fragment
.
findViewById
(
R
.
id
.
fldEstimateMinutes
)
fldEstimateMinutes
.
doOnTextChanged
{
text
,
_
,
_
,
_
->
val
input
=
text
.
toString
().
toLongOrNull
()
if
(
input
!=
null
)
{
estimateMinutes
=
input
changeListener
?.
onEstimateChange
(
estimateHours
,
estimateMinutes
)
}
}
val
txtDueDate
:
TextView
=
fragment
.
findViewById
(
R
.
id
.
txtDueDate
)
val
btnDatePicker
:
ImageButton
=
fragment
.
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
)
val
datePickerContext
=
context
if
(
datePickerContext
!=
null
)
{
DatePickerDialog
(
datePickerContext
,
{
_
,
year
,
month
,
dayOfMonth
->
val
date
=
Calendar
.
getInstance
()
date
.
set
(
Calendar
.
YEAR
,
year
)
date
.
set
(
Calendar
.
MONTH
,
month
)
date
.
set
(
Calendar
.
DAY_OF_MONTH
,
dayOfMonth
)
txtDueDate
.
text
=
DateFormat
.
getDateInstance
().
format
(
date
.
time
)
changeListener
?.
onDueDateChange
(
date
)
},
initialYear
,
initialMonth
,
initialDayOfMonth
).
show
()
}
}
return
fragment
}
override
fun
onAttach
(
context
:
Context
)
{
super
.
onAttach
(
context
)
if
(
context
is
OnTaskChangeListener
)
{
changeListener
=
context
}
else
{
throw
RuntimeException
(
context
.
toString
()
+
" must implement OnTaskChangeListener"
)
}
}
override
fun
onDetach
()
{
super
.
onDetach
()
changeListener
=
null
}
companion
object
{
@JvmStatic
fun
newInstance
()
=
TaskListEmptyFragment
().
apply
{
}
}
interface
OnTaskChangeListener
{
fun
onTitleChange
(
title
:
String
)
fun
onDueDateChange
(
dueDate
:
Calendar
)
fun
onEstimateChange
(
hours
:
Long
,
minutes
:
Long
)
}
}
\ No newline at end of file
app/src/main/java/ch/ost/rj/mge/miniproject/tasktracker/fragments/TaskListEmptyFragment.kt
View file @
2b38fd9b
...
...
@@ -7,12 +7,6 @@ import android.view.View
import
android.view.ViewGroup
import
ch.ost.rj.mge.miniproject.tasktracker.R
/**
* A simple [Fragment] subclass.
* Use the [TaskListEmptyFragment.newInstance] factory method to
* create an instance of this fragment.
*/
class
TaskListEmptyFragment
:
Fragment
()
{
override
fun
onCreateView
(
...
...
@@ -24,12 +18,6 @@ class TaskListEmptyFragment : Fragment() {
}
companion
object
{
/**
* Use this factory method to create a new instance of
* this fragment using the provided parameters.
*
* @return A new instance of fragment TaskListEmptyFragment.
*/
@JvmStatic
fun
newInstance
()
=
TaskListEmptyFragment
().
apply
{
}
}
...
...
app/src/main/res/layout/activity_add_task.xml
View file @
2b38fd9b
...
...
@@ -6,84 +6,6 @@
android:layout_height=
"match_parent"
tools:context=
".activities.AddTaskActivity"
>
<EditText
android:id=
"@+id/fldTaskName"
android:layout_width=
"0dp"
android:layout_height=
"wrap_content"
android:layout_marginStart=
"16dp"
android:layout_marginEnd=
"16dp"
android:ems=
"10"
android:importantForAutofill=
"no"
android:inputType=
"textPersonName"
android:focusable=
"true"
app:layout_constraintEnd_toEndOf=
"parent"
app:layout_constraintHorizontal_bias=
"0.0"
app:layout_constraintStart_toStartOf=
"parent"
app:layout_constraintTop_toBottomOf=
"@+id/lblTaskName"
/>
<TextView
android:id=
"@+id/lblTaskName"
android:layout_width=
"0dp"
android:layout_height=
"wrap_content"
android:layout_marginStart=
"16dp"
android:layout_marginTop=
"16dp"
android:layout_marginEnd=
"16dp"
android:text=
"@string/lblTaskName"
android:labelFor=
"@id/fldTaskName"
app:layout_constraintEnd_toEndOf=
"parent"
app:layout_constraintStart_toStartOf=
"parent"
app:layout_constraintTop_toTopOf=
"parent"
/>
<TextView
android:id=
"@+id/lblDueDate"
android:layout_width=
"0dp"
android:layout_height=
"wrap_content"
android:layout_marginStart=
"16dp"
android:layout_marginTop=
"16dp"
android:layout_marginEnd=
"16dp"
android:text=
"@string/lblDueDate"
app:layout_constraintEnd_toEndOf=
"parent"
app:layout_constraintStart_toStartOf=
"parent"
app:layout_constraintTop_toBottomOf=
"@+id/fldTaskName"
/>
<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:text=
"@string/lblEstimateTime"
app:layout_constraintEnd_toEndOf=
"parent"
app:layout_constraintHorizontal_bias=
"1.0"
app:layout_constraintStart_toStartOf=
"parent"
app:layout_constraintTop_toBottomOf=
"@+id/btnDatePicker"
/>
<ImageButton
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_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"
...
...
@@ -105,46 +27,14 @@
app:layout_constraintBottom_toBottomOf=
"parent"
app:layout_constraintStart_toStartOf=
"parent"
/>
<EditText
android:id=
"@+id/fldEstimateHours"
android:layout_width=
"100dp"
<fragment
android:id=
"@+id/fragment"
android:name=
"ch.ost.rj.mge.miniproject.tasktracker.fragments.TaskFormFragment"
android:layout_width=
"0dp"
android:layout_height=
"wrap_content"
android:layout_marginStart=
"16dp"
android:ems=
"10"
android:inputType=
"number"
android:text=
"0"
android:textAlignment=
"textEnd"
app:layout_constraintEnd_toEndOf=
"parent"
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"
/>
app:layout_constraintTop_toTopOf=
"parent"
tools:layout=
"@layout/fragment_task_form"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
app/src/main/res/layout/fragment_task_form.xml
0 → 100644
View file @
2b38fd9b
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android=
"http://schemas.android.com/apk/res/android"
xmlns:app=
"http://schemas.android.com/apk/res-auto"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
>
<EditText
android:id=
"@+id/fldTaskName"
android:layout_width=
"0dp"
android:layout_height=
"wrap_content"
android:layout_marginStart=
"16dp"
android:layout_marginEnd=
"16dp"
android:ems=
"10"
android:focusable=
"true"
android:importantForAutofill=
"no"
android:inputType=
"textPersonName"
app:layout_constraintEnd_toEndOf=
"parent"
app:layout_constraintHorizontal_bias=
"0.0"
app:layout_constraintStart_toStartOf=
"parent"
app:layout_constraintTop_toBottomOf=
"@+id/lblTaskName"
/>
<TextView
android:id=
"@+id/lblTaskName"
android:layout_width=
"0dp"
android:layout_height=
"wrap_content"
android:layout_marginStart=
"16dp"
android:layout_marginTop=
"16dp"
android:layout_marginEnd=
"16dp"
android:labelFor=
"@id/fldTaskName"
android:text=
"@string/lblTaskName"
app:layout_constraintEnd_toEndOf=
"parent"
app:layout_constraintStart_toStartOf=
"parent"
app:layout_constraintTop_toTopOf=
"parent"
/>
<TextView
android:id=
"@+id/lblDueDate"
android:layout_width=
"0dp"
android:layout_height=
"wrap_content"
android:layout_marginStart=
"16dp"
android:layout_marginTop=
"16dp"
android:layout_marginEnd=
"16dp"
android:text=
"@string/lblDueDate"
app:layout_constraintEnd_toEndOf=
"parent"
app:layout_constraintStart_toStartOf=
"parent"
app:layout_constraintTop_toBottomOf=
"@+id/fldTaskName"
/>
<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:text=
"@string/lblEstimateTime"
app:layout_constraintEnd_toEndOf=
"parent"
app:layout_constraintHorizontal_bias=
"1.0"
app:layout_constraintStart_toStartOf=
"parent"
app:layout_constraintTop_toBottomOf=
"@+id/btnDatePicker"
/>
<ImageButton
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_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"
/>
<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"
android:autofillHints=
""
/>
<TextView
android:id=
"@+id/lblEstimateHours"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
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"
android:autofillHints=
""
/>
<TextView
android:id=
"@+id/lblEstimateMinutes"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment