Commit 1c8afb59 authored by Lukas Bersinger's avatar Lukas Bersinger
Browse files

add empty list display

parent 7b2deb68
......@@ -3,10 +3,8 @@ package ch.ost.rj.mge.miniproject.tasktracker.activities
import android.os.Bundle
import android.widget.FrameLayout
import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import ch.ost.rj.mge.miniproject.tasktracker.R
import ch.ost.rj.mge.miniproject.tasktracker.adapters.TaskListAdapter
import ch.ost.rj.mge.miniproject.tasktracker.fragments.TaskListEmptyFragment
import ch.ost.rj.mge.miniproject.tasktracker.fragments.TaskListFragment
import ch.ost.rj.mge.miniproject.tasktracker.models.Task
import ch.ost.rj.mge.miniproject.tasktracker.repositories.TaskRepository
......@@ -16,6 +14,8 @@ class MainActivity : AppCompatActivity() {
private var taskRepository = TaskRepository()
private lateinit var listFragment: TaskListFragment
private lateinit var listEmptyFragment: TaskListEmptyFragment
private lateinit var taskListContainer: FrameLayout
private lateinit var btnAddTask: FloatingActionButton
......@@ -34,11 +34,16 @@ class MainActivity : AppCompatActivity() {
val tasks: List<Task> = taskRepository.getTasks()
listFragment = TaskListFragment.newInstance(tasks)
if (tasks.isNotEmpty()) {
listFragment = TaskListFragment.newInstance(tasks)
supportFragmentManager.beginTransaction()
.replace(R.id.fltTaskListContainer, listFragment)
.commit()
} else {
listEmptyFragment = TaskListEmptyFragment.newInstance()
supportFragmentManager.beginTransaction()
.add(R.id.fltTaskListContainer, listFragment)
.replace(R.id.fltTaskListContainer, listEmptyFragment)
.commit()
}
}
......
package ch.ost.rj.mge.miniproject.tasktracker.fragments
import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
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(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_task_list_empty, container, false)
}
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 { }
}
}
\ No newline at end of file
......@@ -6,6 +6,12 @@ class TaskRepository {
fun getTasks(): ArrayList<Task> {
val tasks = ArrayList<Task>()
// val testTask = Task()
// testTask.name = "Test"
//
// tasks.add(testTask)
return tasks
}
......
<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="M19.77,5.03l1.4,1.4L8.43,19.17l-5.6,-5.6 1.4,-1.4 4.2,4.2L19.77,5.03m0,-2.83L8.43,13.54l-4.2,-4.2L0,13.57 8.43,22 24,6.43 19.77,2.2z"/>
</vector>
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".fragments.TaskListEmptyFragment" >
<ImageView
tools:ignore="ContentDescription"
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="128dp"
android:scaleType="centerInside"
android:scaleX="2"
android:scaleY="2"
android:src="@drawable/ic_baseline_done_outline_24"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_optimizationLevel="dimensions"
app:tint="@android:color/tertiary_text_light" />
<TextView
android:id="@+id/txtTaskListEmpty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="@string/txtTaskListEmpty"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/imageView" />
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
<resources>
<string name="app_name">TaskTracker</string>
<string name="txtTaskListEmpty">Alles erledigt</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