mirror of
https://github.com/a-mayb3/KanbanCloneAndroid.git
synced 2026-03-21 18:15:38 +01:00
Task creation from
This commit is contained in:
parent
9e2d6b4793
commit
13ea6e4ef7
4 changed files with 266 additions and 0 deletions
|
|
@ -18,6 +18,18 @@
|
||||||
<activity
|
<activity
|
||||||
android:name=".ui.CreateProjectActivity"
|
android:name=".ui.CreateProjectActivity"
|
||||||
android:exported="false" />
|
android:exported="false" />
|
||||||
|
<activity
|
||||||
|
android:name=".ui.ProjectEditActivity"
|
||||||
|
android:exported="false" />
|
||||||
|
<activity
|
||||||
|
android:name=".ui.CollaboratorAddActivity"
|
||||||
|
android:exported="false" />
|
||||||
|
<activity
|
||||||
|
android:name=".ui.TaskAddActivity"
|
||||||
|
android:exported="false" />
|
||||||
|
<activity
|
||||||
|
android:name=".ui.TaskEditActivity"
|
||||||
|
android:exported="false" />
|
||||||
<activity
|
<activity
|
||||||
android:name=".ui.ProjectDetailActivity"
|
android:name=".ui.ProjectDetailActivity"
|
||||||
android:exported="false" />
|
android:exported="false" />
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@ import com.campusaula.edbole.kanban_clone_android.R
|
||||||
import com.campusaula.edbole.kanban_clone_android.kanban.Project
|
import com.campusaula.edbole.kanban_clone_android.kanban.Project
|
||||||
import com.campusaula.edbole.kanban_clone_android.network.ApiService
|
import com.campusaula.edbole.kanban_clone_android.network.ApiService
|
||||||
import com.campusaula.edbole.kanban_clone_android.network.RetrofitInstance
|
import com.campusaula.edbole.kanban_clone_android.network.RetrofitInstance
|
||||||
|
import com.campusaula.edbole.kanban_clone_android.ui.adapters.ProjectItemAdapter
|
||||||
import com.google.android.material.floatingactionbutton.FloatingActionButton
|
import com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,136 @@
|
||||||
|
package com.campusaula.edbole.kanban_clone_android.ui
|
||||||
|
|
||||||
|
import android.content.Intent
|
||||||
|
import android.os.Bundle
|
||||||
|
import android.util.Log
|
||||||
|
import android.widget.Button
|
||||||
|
import android.widget.EditText
|
||||||
|
import android.widget.Spinner
|
||||||
|
import android.widget.Toast
|
||||||
|
import androidx.activity.enableEdgeToEdge
|
||||||
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
|
import androidx.core.view.ViewCompat
|
||||||
|
import androidx.core.view.WindowInsetsCompat
|
||||||
|
import androidx.lifecycle.lifecycleScope
|
||||||
|
import com.campusaula.edbole.kanban_clone_android.R
|
||||||
|
import com.campusaula.edbole.kanban_clone_android.kanban.TaskBase
|
||||||
|
import com.campusaula.edbole.kanban_clone_android.kanban.TaskStatus
|
||||||
|
import com.campusaula.edbole.kanban_clone_android.network.ApiService
|
||||||
|
import com.campusaula.edbole.kanban_clone_android.network.RetrofitInstance
|
||||||
|
import com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
|
||||||
|
class TaskAddActivity : AppCompatActivity() {
|
||||||
|
|
||||||
|
private lateinit var api: ApiService
|
||||||
|
|
||||||
|
private lateinit var returnActionButton: FloatingActionButton
|
||||||
|
private lateinit var taskTitleInput: EditText
|
||||||
|
private lateinit var taskDescriptionInput: EditText
|
||||||
|
private lateinit var taskStatusSpinner: Spinner
|
||||||
|
private lateinit var createTaskButton: Button
|
||||||
|
|
||||||
|
private var projectId: Int = -1
|
||||||
|
|
||||||
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
|
super.onCreate(savedInstanceState)
|
||||||
|
enableEdgeToEdge()
|
||||||
|
setContentView(R.layout.activity_task_add)
|
||||||
|
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
|
||||||
|
val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
|
||||||
|
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
|
||||||
|
insets
|
||||||
|
}
|
||||||
|
|
||||||
|
api = RetrofitInstance.getRetrofit(applicationContext).create(ApiService::class.java)
|
||||||
|
|
||||||
|
// Get project ID from intent
|
||||||
|
projectId = intent.getIntExtra("project_id", -1)
|
||||||
|
|
||||||
|
if (projectId == -1) {
|
||||||
|
Toast.makeText(this, "Error: Invalid project ID", Toast.LENGTH_SHORT).show()
|
||||||
|
finish()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Initialize views
|
||||||
|
returnActionButton = findViewById(R.id.returnActionButton)
|
||||||
|
taskTitleInput = findViewById(R.id.taskTitleInput)
|
||||||
|
taskDescriptionInput = findViewById(R.id.taskDescriptionInput)
|
||||||
|
taskStatusSpinner = findViewById(R.id.taskStatusSpinner)
|
||||||
|
createTaskButton = findViewById(R.id.createTaskButton)
|
||||||
|
|
||||||
|
// Set default status to PENDING (index 0)
|
||||||
|
taskStatusSpinner.setSelection(0)
|
||||||
|
|
||||||
|
// Set up button listeners
|
||||||
|
returnActionButton.setOnClickListener {
|
||||||
|
finish()
|
||||||
|
|
||||||
|
val intent = Intent(this@TaskAddActivity, ProjectDetailActivity::class.java)
|
||||||
|
intent.putExtra("project_id", projectId)
|
||||||
|
startActivity(intent)
|
||||||
|
}
|
||||||
|
|
||||||
|
createTaskButton.setOnClickListener {
|
||||||
|
createTask()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun createTask() {
|
||||||
|
val title = taskTitleInput.text.toString().trim()
|
||||||
|
val description = taskDescriptionInput.text.toString().trim()
|
||||||
|
val status = TaskStatus.entries[taskStatusSpinner.selectedItemPosition]
|
||||||
|
|
||||||
|
if (title.isEmpty()) {
|
||||||
|
Toast.makeText(this, "Title cannot be empty", Toast.LENGTH_SHORT).show()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
lifecycleScope.launch {
|
||||||
|
try {
|
||||||
|
Log.d("TaskAddActivity", "Creating task: $title")
|
||||||
|
val taskBase = TaskBase(
|
||||||
|
id = 0, // ID will be assigned by the server
|
||||||
|
title = title,
|
||||||
|
description = description,
|
||||||
|
status = status
|
||||||
|
)
|
||||||
|
|
||||||
|
val response = api.createTask(projectId, taskBase)
|
||||||
|
|
||||||
|
if (response.isSuccessful) {
|
||||||
|
Log.d("TaskAddActivity", "Task created successfully")
|
||||||
|
Toast.makeText(
|
||||||
|
this@TaskAddActivity,
|
||||||
|
"Task created successfully",
|
||||||
|
Toast.LENGTH_SHORT
|
||||||
|
).show()
|
||||||
|
setResult(RESULT_OK)
|
||||||
|
finish()
|
||||||
|
|
||||||
|
// Reopen ProjectDetailActivity to show the new task
|
||||||
|
val intent = Intent(this@TaskAddActivity, ProjectDetailActivity::class.java)
|
||||||
|
intent.putExtra("project_id", projectId)
|
||||||
|
startActivity(intent)
|
||||||
|
} else {
|
||||||
|
val errorBody = response.errorBody()?.string()
|
||||||
|
Log.e("TaskAddActivity", "Error creating task: $errorBody")
|
||||||
|
Toast.makeText(
|
||||||
|
this@TaskAddActivity,
|
||||||
|
"Error creating task: ${response.code()}",
|
||||||
|
Toast.LENGTH_SHORT
|
||||||
|
).show()
|
||||||
|
}
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Log.e("TaskAddActivity", "Exception creating task: ${e.message}")
|
||||||
|
Toast.makeText(
|
||||||
|
this@TaskAddActivity,
|
||||||
|
"Failed to create task: ${e.message}",
|
||||||
|
Toast.LENGTH_SHORT
|
||||||
|
).show()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
117
app/src/main/res/layout/activity_task_add.xml
Normal file
117
app/src/main/res/layout/activity_task_add.xml
Normal file
|
|
@ -0,0 +1,117 @@
|
||||||
|
<?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:id="@+id/main"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
tools:context=".ui.TaskAddActivity">
|
||||||
|
|
||||||
|
<com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||||
|
android:id="@+id/returnActionButton"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginEnd="@dimen/fab_margin_end"
|
||||||
|
android:layout_marginBottom="@dimen/fab_margin_bottom"
|
||||||
|
android:contentDescription="Return"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
|
app:srcCompat="@android:drawable/ic_menu_revert" />
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:paddingBottom="@dimen/bottom_padding_for_fab">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/titleLabel"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="Add New Task"
|
||||||
|
android:textSize="@dimen/text_size_title"
|
||||||
|
android:textStyle="bold"
|
||||||
|
android:padding="@dimen/padding_standard"
|
||||||
|
android:layout_marginTop="@dimen/margin_tiny" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/taskTitleLabel"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="Title:"
|
||||||
|
android:textSize="@dimen/text_size_subtitle"
|
||||||
|
android:textStyle="bold"
|
||||||
|
android:layout_marginTop="@dimen/margin_medium"
|
||||||
|
android:paddingLeft="12dp"
|
||||||
|
android:paddingRight="12dp" />
|
||||||
|
|
||||||
|
<EditText
|
||||||
|
android:id="@+id/taskTitleInput"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:hint="Enter task title"
|
||||||
|
android:inputType="text"
|
||||||
|
android:padding="@dimen/padding_standard"
|
||||||
|
android:layout_marginLeft="@dimen/margin_standard"
|
||||||
|
android:layout_marginRight="@dimen/margin_standard"
|
||||||
|
android:layout_marginTop="@dimen/margin_small" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/taskDescriptionLabel"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="Description:"
|
||||||
|
android:textSize="@dimen/text_size_subtitle"
|
||||||
|
android:textStyle="bold"
|
||||||
|
android:layout_marginTop="@dimen/margin_medium"
|
||||||
|
android:paddingLeft="12dp"
|
||||||
|
android:paddingRight="12dp" />
|
||||||
|
|
||||||
|
<EditText
|
||||||
|
android:id="@+id/taskDescriptionInput"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:hint="Enter task description"
|
||||||
|
android:inputType="textMultiLine"
|
||||||
|
android:minLines="3"
|
||||||
|
android:maxLines="5"
|
||||||
|
android:padding="@dimen/padding_standard"
|
||||||
|
android:layout_marginLeft="@dimen/margin_standard"
|
||||||
|
android:layout_marginRight="@dimen/margin_standard"
|
||||||
|
android:layout_marginTop="@dimen/margin_small"
|
||||||
|
android:gravity="start|top" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/taskStatusLabel"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="Status:"
|
||||||
|
android:textSize="@dimen/text_size_subtitle"
|
||||||
|
android:textStyle="bold"
|
||||||
|
android:layout_marginTop="@dimen/margin_medium"
|
||||||
|
android:paddingLeft="12dp"
|
||||||
|
android:paddingRight="12dp" />
|
||||||
|
|
||||||
|
<Spinner
|
||||||
|
android:id="@+id/taskStatusSpinner"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:entries="@array/task_status_options"
|
||||||
|
android:padding="@dimen/padding_standard"
|
||||||
|
android:layout_marginLeft="@dimen/margin_standard"
|
||||||
|
android:layout_marginRight="@dimen/margin_standard"
|
||||||
|
android:layout_marginTop="@dimen/margin_small" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/createTaskButton"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="Create Task"
|
||||||
|
android:backgroundTint="@color/primary_green"
|
||||||
|
android:layout_marginTop="@dimen/margin_large"
|
||||||
|
android:layout_marginLeft="@dimen/margin_standard"
|
||||||
|
android:layout_marginRight="@dimen/margin_standard" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
Loading…
Add table
Add a link
Reference in a new issue