diff --git a/app/build.gradle b/app/build.gradle index 45dfe4fe2fff8a688bf64f594c109794a4530d89..e54929db1dfb64705c6fd7dcee8da1e326aedc79 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -40,6 +40,8 @@ dependencies { implementation "androidx.recyclerview:recyclerview:1.1.0" implementation 'androidx.constraintlayout:constraintlayout:1.1.3' implementation 'com.google.android.material:material:1.0.0' + implementation 'androidx.navigation:navigation-fragment-ktx:2.2.2' + implementation 'androidx.navigation:navigation-ui-ktx:2.2.2' testImplementation 'junit:junit:4.+' // androidTestImplementation 'com.android.support.test:runner:1.0.2' androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 1f60532c238fdfe9e9e2db0c340bec3478a8d696..8f40618e6b0a9b18cace0f38ca53d55e9ec41c06 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -9,7 +9,7 @@ android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/Theme.DM_td2"> - tools:replace="android:appComponentFactory" + <activity android:name=".task.TaskActivity"></activity> <activity android:name=".MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> diff --git a/app/src/main/java/com/clemhaowen/dm_td2/task/TaskActivity.kt b/app/src/main/java/com/clemhaowen/dm_td2/task/TaskActivity.kt new file mode 100644 index 0000000000000000000000000000000000000000..def471eb3933d83d8142a7160689836e71ff7ecb --- /dev/null +++ b/app/src/main/java/com/clemhaowen/dm_td2/task/TaskActivity.kt @@ -0,0 +1,12 @@ +package com.clemhaowen.dm_td2.task + +import androidx.appcompat.app.AppCompatActivity +import android.os.Bundle +import com.clemhaowen.dm_td2.R + +class TaskActivity : AppCompatActivity() { + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_task) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/clemhaowen/dm_td2/tasklist/TaskAdapter.kt b/app/src/main/java/com/clemhaowen/dm_td2/tasklist/TaskAdapter.kt index 7cb0633d3fdc744de5ede25df883157f1c8c6d9b..e1edfbba2cdabe99997a456cde86eb2fb381b70a 100644 --- a/app/src/main/java/com/clemhaowen/dm_td2/tasklist/TaskAdapter.kt +++ b/app/src/main/java/com/clemhaowen/dm_td2/tasklist/TaskAdapter.kt @@ -4,11 +4,15 @@ 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.recyclerview.widget.RecyclerView import com.clemhaowen.dm_td2.R class TaskListAdapter(private val taskList: List<String>) : RecyclerView.Adapter<TaskListAdapter.TaskViewHolder>() { + + var onDeleteClickListener: ((String) -> Unit)? = null + override fun getItemCount(): Int = taskList.size override fun onCreateViewHolder(parent: ViewGroup, position: Int): TaskViewHolder { @@ -24,6 +28,10 @@ class TaskListAdapter(private val taskList: List<String>) : RecyclerView.Adapter itemView.apply { val textView = findViewById<TextView>(R.id.task_title) textView.text = taskTitle + val deleteButton = findViewById<ImageButton>(R.id.delete_task) + deleteButton.setOnClickListener { + onDeleteClickListener?.invoke(taskTitle)} + } } diff --git a/app/src/main/java/com/clemhaowen/dm_td2/tasklist/TaskListFragment.kt b/app/src/main/java/com/clemhaowen/dm_td2/tasklist/TaskListFragment.kt index 9de2452956de1cd3a3fcd2209b88e85c5cbff22d..0a480244331a2d37e43c4834ae6bb1b7b3204885 100644 --- a/app/src/main/java/com/clemhaowen/dm_td2/tasklist/TaskListFragment.kt +++ b/app/src/main/java/com/clemhaowen/dm_td2/tasklist/TaskListFragment.kt @@ -11,7 +11,7 @@ import com.clemhaowen.dm_td2.R class TaskListFragment : Fragment() { - private val taskList = listOf("Task 1", "Task 2", "Task 3") + private var taskList = mutableListOf("Task 1", "Task 2", "Task 3") // TODO uncomment when Task is implemented /*private val taskList = listOf( Task(id = "id_1", title = "Task 1", description = "description 1"), @@ -32,7 +32,11 @@ class TaskListFragment : Fragment() { recyclerView?.layoutManager = LinearLayoutManager(activity) // TODO uncomment when TaskListAdapter is created recyclerView?.adapter = TaskListAdapter(taskList) - + (recyclerView?.adapter as TaskListAdapter).onDeleteClickListener = { task -> + // Supprimer la tâche + taskList.remove(task) + (recyclerView?.adapter as TaskListAdapter).notifyDataSetChanged() + } // En utilisant les synthetics, on écrit juste l'id directement (c'est magique ✨): //R.id.fragment_tasklist_recyclerView.layoutManager = LinearLayoutManager(activity) // ça marche pas } diff --git a/app/src/main/res/layout/activity_task.xml b/app/src/main/res/layout/activity_task.xml new file mode 100644 index 0000000000000000000000000000000000000000..378b76ed590e371b6e12abe40806055122387d2c --- /dev/null +++ b/app/src/main/res/layout/activity_task.xml @@ -0,0 +1,41 @@ +<?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=".task.TaskActivity"> + + <LinearLayout + android:layout_width="match_parent" + android:layout_height="match_parent" + android:orientation="vertical" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="parent"> + + <EditText + android:id="@+id/editTextTextPersonName" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:ems="10" + android:inputType="textPersonName" + android:textAlignment="center" + tools:text="@android:string/unknownName" /> + + <EditText + android:id="@+id/editTextTextMultiLine" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:ems="10" + android:gravity="start|top" + android:inputType="textMultiLine" + tools:text="@android:string/unknownName" /> + + <Button + android:id="@+id/button" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:text="Validate" /> + </LinearLayout> + +</androidx.constraintlayout.widget.ConstraintLayout> \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_task_list.xml b/app/src/main/res/layout/fragment_task_list.xml index 369364ec4a8ba0d477f6de4fa300cb7b8426fa66..a73afd55f74804180a9b396eb34897399bbc282a 100644 --- a/app/src/main/res/layout/fragment_task_list.xml +++ b/app/src/main/res/layout/fragment_task_list.xml @@ -22,6 +22,7 @@ android:layout_marginEnd="30dp" android:layout_marginBottom="30dp" android:clickable="true" + android:contentDescription="@android:string/untitled" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:srcCompat="@drawable/ic_baseline_add_24" /> diff --git a/app/src/main/res/layout/item_task.xml b/app/src/main/res/layout/item_task.xml index fb14c484c7484fedb8903091387edcb0af69cac1..85325a5512868e389def96560477e649bfa16c46 100644 --- a/app/src/main/res/layout/item_task.xml +++ b/app/src/main/res/layout/item_task.xml @@ -13,7 +13,7 @@ android:layout_height="wrap_content" /> <ImageButton - android:id="@+id/imageButton" + android:id="@+id/delete_task" android:layout_width="match_parent" android:layout_height="wrap_content" android:contentDescription="@android:string/unknownName" diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 1e5b763196a1bb2c4b2bee050b48dc1179aedbc8..748696f2d493c7f1866271ab24bfb883cf7cdc2a 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1,3 +1,12 @@ <resources> <string name="app_name">DM_td2</string> + <string name="title_activity_task">TaskActivity</string> + <!-- Strings used for fragments for navigation --> + <string name="first_fragment_label">First Fragment</string> + <string name="second_fragment_label">Second Fragment</string> + <string name="next">Next</string> + <string name="previous">Previous</string> + + <string name="hello_first_fragment">Hello first fragment</string> + <string name="hello_second_fragment">Hello second fragment. Arg: %1$s</string> </resources> \ No newline at end of file diff --git a/app/src/main/res/values/themes.xml b/app/src/main/res/values/themes.xml index 7005f2739bd639560bc6ac488290f87bbf455d25..5c7ea1b436e49b360c5c5c663d8b9d6872614603 100644 --- a/app/src/main/res/values/themes.xml +++ b/app/src/main/res/values/themes.xml @@ -7,4 +7,13 @@ <item name="colorAccent">@color/teal_200</item> <!-- Customize your theme here. --> </style> + + <style name="Theme.DM_td2.NoActionBar"> + <item name="windowActionBar">false</item> + <item name="windowNoTitle">true</item> + </style> + + <style name="Theme.DM_td2.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" /> + + <style name="Theme.DM_td2.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" /> </resources> \ No newline at end of file