Skip to content
Extraits de code Groupes Projets
Valider 7416d476 rédigé par Monnot's avatar Monnot
Parcourir les fichiers

Implemented delete button and started task activity

parent 2a367330
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -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'
......
......@@ -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" />
......
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
......@@ -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)}
}
}
......
......@@ -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
}
......
<?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
......@@ -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" />
......
......@@ -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"
......
<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
......@@ -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
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter