Adapted project creation form

This commit is contained in:
Marta Borgia Leiva 2026-02-12 11:44:29 +01:00
parent d7eb6ab646
commit 528e749d79
2 changed files with 114 additions and 96 deletions

View file

@ -3,9 +3,8 @@ package com.campusaula.edbole.kanban_clone_android.ui
import android.content.Intent import android.content.Intent
import android.os.Bundle import android.os.Bundle
import android.util.Log import android.util.Log
import android.widget.AutoCompleteTextView
import android.widget.Button import android.widget.Button
import android.widget.MultiAutoCompleteTextView import android.widget.EditText
import android.widget.Toast import android.widget.Toast
import androidx.activity.enableEdgeToEdge import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
@ -25,8 +24,8 @@ class CreateProjectActivity : AppCompatActivity() {
private lateinit var api: ApiService private lateinit var api: ApiService
private lateinit var returnActionButton : FloatingActionButton private lateinit var returnActionButton : FloatingActionButton
private lateinit var newProjectName : AutoCompleteTextView private lateinit var newProjectName : EditText
private lateinit var newProjectDescription : AutoCompleteTextView private lateinit var newProjectDescription : EditText
private lateinit var newProjectCreateButton : Button private lateinit var newProjectCreateButton : Button
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
@ -42,47 +41,63 @@ class CreateProjectActivity : AppCompatActivity() {
api = RetrofitInstance.getRetrofit(applicationContext).create(ApiService::class.java) api = RetrofitInstance.getRetrofit(applicationContext).create(ApiService::class.java)
returnActionButton = findViewById(R.id.returnActionButton) returnActionButton = findViewById(R.id.returnActionButton)
returnActionButton.setOnClickListener { finish() } returnActionButton.setOnClickListener {
finish()
val intent = Intent(this@CreateProjectActivity, MainActivity::class.java)
startActivity(intent)
}
newProjectName = findViewById(R.id.newProjectName) newProjectName = findViewById(R.id.newProjectName)
newProjectDescription = findViewById(R.id.newProjectDescription) newProjectDescription = findViewById(R.id.newProjectDescription)
newProjectCreateButton = findViewById(R.id.newProjectCreateButton) newProjectCreateButton = findViewById(R.id.newProjectCreateButton)
newProjectCreateButton.setOnClickListener { newProjectCreateButton.setOnClickListener {
val projectName = newProjectName.text.toString() val projectName = newProjectName.text.toString().trim()
val projectDescription = newProjectDescription.text.toString() val projectDescription = newProjectDescription.text.toString().trim()
if (projectName.isEmpty() || projectDescription.isEmpty()) { if (projectName.isEmpty()) {
Toast Toast.makeText(this, "Project name cannot be empty", Toast.LENGTH_SHORT).show()
.makeText(this, "Please fill in all fields", Toast.LENGTH_SHORT)
.show()
return@setOnClickListener return@setOnClickListener
} }
lifecycleScope.launch { lifecycleScope.launch {
try {
val projectCreate : ProjectCreate = ProjectCreate(projectName, projectDescription) Log.d("CreateProjectActivity", "Creating project: $projectName")
val projectCreate = ProjectCreate(projectName, projectDescription)
val response = api.createProject(projectCreate) val response = api.createProject(projectCreate)
if (response.isSuccessful){ if (response.isSuccessful) {
Toast Log.d("CreateProjectActivity", "Project created successfully: ${response.body()}")
.makeText(this@CreateProjectActivity, "Project created successfully", Toast.LENGTH_SHORT) Toast.makeText(
.show() this@CreateProjectActivity,
Log.d("CreateProjectActivity", "Created project: ${response.body()}") "Project created successfully",
startActivity(Intent(this@CreateProjectActivity, MainActivity::class.java)) Toast.LENGTH_SHORT
).show()
finish()
// Volver a MainActivity para ver el nuevo proyecto
val intent = Intent(this@CreateProjectActivity, MainActivity::class.java)
startActivity(intent)
} else { } else {
Log.e("CreateProjectActivity", "Error creating project: ${response.code()} - ${response.message()}") val errorBody = response.errorBody()?.string()
Toast Log.e("CreateProjectActivity", "Error creating project: $errorBody")
.makeText(this@CreateProjectActivity, "Error creating project", Toast.LENGTH_SHORT) Toast.makeText(
.show() this@CreateProjectActivity,
"Error creating project: ${response.code()}",
Toast.LENGTH_SHORT
).show()
}
} catch (e: Exception) {
Log.e("CreateProjectActivity", "Exception creating project: ${e.message}")
Toast.makeText(
this@CreateProjectActivity,
"Failed to create project: ${e.message}",
Toast.LENGTH_SHORT
).show()
} }
} }
} }
} }
} }

View file

@ -16,80 +16,83 @@
app:srcCompat="@android:drawable/ic_menu_revert" app:srcCompat="@android:drawable/ic_menu_revert"
android:id="@+id/returnActionButton" android:id="@+id/returnActionButton"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginBottom="16dp" android:layout_marginBottom="@dimen/fab_margin_bottom"
android:layout_marginEnd="16dp" android:layout_marginEnd="@dimen/fab_margin_end"
app:layout_constraintEnd_toEndOf="parent" /> app:layout_constraintEnd_toEndOf="parent" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="@dimen/bottom_padding_for_fab">
<TextView <TextView
android:text="Create a new project..." android:text="Create a new project..."
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:id="@+id/activityTitle" android:id="@+id/activityTitle"
app:layout_constraintTop_toTopOf="parent" android:padding="@dimen/padding_standard"
app:layout_constraintStart_toStartOf="parent" android:textSize="@dimen/text_size_title"
app:layout_constraintHorizontal_bias="0.5" android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent" android:layout_marginTop="@dimen/margin_tiny" />
android:padding="12dp"
android:textSize="24dp"
android:layout_marginTop="4dp" />
<MultiAutoCompleteTextView
android:layout_width="match_parent"
android:layout_height="500dp"
android:id="@+id/newProjectDescription"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/newProjectDescriptionLabel"
android:hint="This is my new super-special project that will change the world!!!"
android:textAlignment="textStart"
android:gravity="start|top"
android:padding="12dp" />
<AutoCompleteTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/newProjectName"
app:layout_constraintTop_toBottomOf="@+id/newProjectNameLabel"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintEnd_toEndOf="parent"
android:hint="My new project!"
android:padding="12dp" />
<TextView <TextView
android:text="Project name:" android:text="Project name:"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:id="@+id/newProjectNameLabel" android:id="@+id/newProjectNameLabel"
tools:layout_editor_absoluteX="0dp" android:textSize="@dimen/text_size_subtitle"
android:labelFor="@id/activityTitle" android:textStyle="bold"
app:layout_constraintTop_toBottomOf="@+id/activityTitle" android:layout_marginTop="@dimen/margin_medium"
android:layout_marginTop="16dp" /> android:paddingLeft="@dimen/padding_standard"
android:paddingRight="@dimen/padding_standard" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/newProjectName"
android:hint="My new project!"
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 <TextView
android:text="Project description:" android:text="Project description:"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:id="@+id/newProjectDescriptionLabel" android:id="@+id/newProjectDescriptionLabel"
app:layout_constraintStart_toStartOf="parent" android:textSize="@dimen/text_size_subtitle"
app:layout_constraintHorizontal_bias="0.0" android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent" android:layout_marginTop="@dimen/margin_medium"
app:layout_constraintTop_toBottomOf="@+id/newProjectName" android:paddingLeft="@dimen/padding_standard"
android:layout_marginTop="20dp" /> android:paddingRight="@dimen/padding_standard" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/newProjectDescription"
android:hint="This is my new super-special project that will change the world!!!"
android:inputType="textMultiLine"
android:minLines="3"
android:maxLines="5"
android:gravity="start|top"
android:padding="@dimen/padding_standard"
android:layout_marginLeft="@dimen/margin_standard"
android:layout_marginRight="@dimen/margin_standard"
android:layout_marginTop="@dimen/margin_small" />
<Button <Button
android:text="Create new project" android:text="Create new project"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:id="@+id/newProjectCreateButton" android:id="@+id/newProjectCreateButton"
app:layout_constraintStart_toStartOf="parent" android:backgroundTint="@color/primary_green"
app:layout_constraintHorizontal_bias="0.5" android:layout_marginTop="@dimen/margin_large"
app:layout_constraintEnd_toEndOf="parent" android:layout_marginLeft="@dimen/margin_standard"
android:layout_marginTop="15dp" android:layout_marginRight="@dimen/margin_standard" />
app:layout_constraintTop_toBottomOf="@+id/newProjectDescription"
android:padding="20dp"
android:layout_margin="12dp" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>