Commit f45680cd authored by Lukas Bersinger's avatar Lukas Bersinger
Browse files

add option to show all tasks

parent 355d67c9
......@@ -14,7 +14,8 @@
<activity android:name=".activities.TimeTrackingActivity"
android:theme="@style/AppTheme.NoActionBar" />
<activity android:name=".activities.EditTaskActivity" />
<activity android:name=".activities.MainActivity">
<activity android:name=".activities.MainActivity"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
......
......@@ -3,6 +3,7 @@ package ch.ost.rj.mge.miniproject.tasktracker.activities
import android.content.Intent
import android.os.Bundle
import android.widget.FrameLayout
import android.widget.ImageButton
import androidx.appcompat.app.AppCompatActivity
import ch.ost.rj.mge.miniproject.tasktracker.R
import ch.ost.rj.mge.miniproject.tasktracker.fragments.TaskListEmptyFragment
......@@ -16,6 +17,7 @@ class MainActivity : AppCompatActivity(), TaskListFragment.OnItemClickListener {
private lateinit var btnAddTask: FloatingActionButton
private var showAll = false
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
......@@ -27,6 +29,12 @@ class MainActivity : AppCompatActivity(), TaskListFragment.OnItemClickListener {
startActivity(intent)
}
val btnShowAll: ImageButton = findViewById(R.id.btnShowAll)
btnShowAll.setOnClickListener {
showAll = !showAll
updateTasks()
}
taskListContainer = findViewById(R.id.fltTaskListContainer)
}
......@@ -39,7 +47,25 @@ class MainActivity : AppCompatActivity(), TaskListFragment.OnItemClickListener {
override fun onResume() {
super.onResume()
val tasks: List<Task> = TaskRepository.getOpenTasks()
updateTasks()
}
override fun onPause() {
super.onPause()
val transaction = supportFragmentManager.beginTransaction()
for (fragment in supportFragmentManager.fragments) {
transaction.remove(fragment)
}
transaction.commit()
}
private fun updateTasks() {
val tasks: List<Task> = if (showAll) {
TaskRepository.getAllTasks()
} else {
TaskRepository.getOpenTasks()
}
if (tasks.isNotEmpty()) {
val listFragment = TaskListFragment.newInstance(tasks)
......@@ -53,14 +79,4 @@ class MainActivity : AppCompatActivity(), TaskListFragment.OnItemClickListener {
.commit()
}
}
override fun onPause() {
super.onPause()
val transaction = supportFragmentManager.beginTransaction()
for (fragment in supportFragmentManager.fragments) {
transaction.remove(fragment)
}
transaction.commit()
}
}
\ No newline at end of file
......@@ -9,6 +9,9 @@ import ch.ost.rj.mge.miniproject.tasktracker.models.Task
@Dao
interface TaskDao {
@Query("SELECT * FROM tasks ORDER BY due_date")
fun getTasks(): List<Task>
@Query("SELECT * FROM tasks WHERE completed = 0 ORDER BY due_date")
fun getOpenTasksByDueDate(): List<Task>
......
......@@ -18,6 +18,10 @@ object TaskRepository {
.build()
}
fun getAllTasks(): List<Task> {
return appDatabase.taskDao().getTasks()
}
fun getOpenTasks(): List<Task> {
return appDatabase.taskDao().getOpenTasksByDueDate()
}
......
<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="M9,16.2L4.8,12l-1.4,1.4L9,19 21,7l-1.4,-1.4L9,16.2z"/>
</vector>
......@@ -6,14 +6,63 @@
android:layout_height="match_parent"
tools:context=".activities.MainActivity">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="0dp"
android:background="@color/colorPrimary"
android:elevation="4dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/txtToolbarTitle"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_gravity="clip_vertical|start|center_vertical"
android:layout_marginTop="4dp"
android:layout_marginBottom="4dp"
android:fontFamily="sans-serif-medium"
android:gravity="clip_vertical|center_vertical"
android:textAppearance="@android:style/TextAppearance.DeviceDefault.Widget.ActionBar.Title"
android:textColor="@android:color/primary_text_dark"
android:text="@string/app_name"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/btnShowAll"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ImageButton
android:id="@+id/btnShowAll"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_gravity="end"
android:layout_marginEnd="8dp"
android:backgroundTint="@color/colorPrimary"
android:contentDescription="@string/btnShowAll"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/ic_baseline_done_24" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.appcompat.widget.Toolbar>
<FrameLayout
android:id="@+id/fltTaskListContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
app:layout_constraintTop_toBottomOf="@+id/toolbar">
</FrameLayout>
......
......@@ -17,4 +17,5 @@
<string name="btnBack">Back</string>
<string name="swtMarkDone">done</string>
<string name="btnEdit">edit</string>
<string name="btnShowAll">show all</string>
</resources>
\ No newline at end of file
......@@ -16,4 +16,5 @@
<string name="btnBack">Zurück</string>
<string name="swtMarkDone">erledigt</string>
<string name="btnEdit">bearbeiten</string>
<string name="btnShowAll">Alle anzeigen</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