mirror of
https://github.com/a-mayb3/KanbanCloneAndroid.git
synced 2026-03-21 18:15:38 +01:00
Adapted project creation form
This commit is contained in:
parent
d7eb6ab646
commit
528e749d79
2 changed files with 114 additions and 96 deletions
|
|
@ -3,9 +3,8 @@ package com.campusaula.edbole.kanban_clone_android.ui
|
|||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import android.widget.AutoCompleteTextView
|
||||
import android.widget.Button
|
||||
import android.widget.MultiAutoCompleteTextView
|
||||
import android.widget.EditText
|
||||
import android.widget.Toast
|
||||
import androidx.activity.enableEdgeToEdge
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
|
|
@ -25,8 +24,8 @@ class CreateProjectActivity : AppCompatActivity() {
|
|||
private lateinit var api: ApiService
|
||||
|
||||
private lateinit var returnActionButton : FloatingActionButton
|
||||
private lateinit var newProjectName : AutoCompleteTextView
|
||||
private lateinit var newProjectDescription : AutoCompleteTextView
|
||||
private lateinit var newProjectName : EditText
|
||||
private lateinit var newProjectDescription : EditText
|
||||
private lateinit var newProjectCreateButton : Button
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
|
|
@ -42,47 +41,63 @@ class CreateProjectActivity : AppCompatActivity() {
|
|||
api = RetrofitInstance.getRetrofit(applicationContext).create(ApiService::class.java)
|
||||
|
||||
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)
|
||||
newProjectDescription = findViewById(R.id.newProjectDescription)
|
||||
|
||||
newProjectCreateButton = findViewById(R.id.newProjectCreateButton)
|
||||
newProjectCreateButton.setOnClickListener {
|
||||
val projectName = newProjectName.text.toString()
|
||||
val projectDescription = newProjectDescription.text.toString()
|
||||
val projectName = newProjectName.text.toString().trim()
|
||||
val projectDescription = newProjectDescription.text.toString().trim()
|
||||
|
||||
if (projectName.isEmpty() || projectDescription.isEmpty()) {
|
||||
Toast
|
||||
.makeText(this, "Please fill in all fields", Toast.LENGTH_SHORT)
|
||||
.show()
|
||||
if (projectName.isEmpty()) {
|
||||
Toast.makeText(this, "Project name cannot be empty", Toast.LENGTH_SHORT).show()
|
||||
return@setOnClickListener
|
||||
}
|
||||
|
||||
lifecycleScope.launch {
|
||||
try {
|
||||
Log.d("CreateProjectActivity", "Creating project: $projectName")
|
||||
val projectCreate = ProjectCreate(projectName, projectDescription)
|
||||
val response = api.createProject(projectCreate)
|
||||
|
||||
val projectCreate : ProjectCreate = ProjectCreate(projectName, projectDescription)
|
||||
val response = api.createProject(projectCreate)
|
||||
if (response.isSuccessful) {
|
||||
Log.d("CreateProjectActivity", "Project created successfully: ${response.body()}")
|
||||
Toast.makeText(
|
||||
this@CreateProjectActivity,
|
||||
"Project created successfully",
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
finish()
|
||||
|
||||
if (response.isSuccessful){
|
||||
Toast
|
||||
.makeText(this@CreateProjectActivity, "Project created successfully", Toast.LENGTH_SHORT)
|
||||
.show()
|
||||
Log.d("CreateProjectActivity", "Created project: ${response.body()}")
|
||||
startActivity(Intent(this@CreateProjectActivity, MainActivity::class.java))
|
||||
} else {
|
||||
Log.e("CreateProjectActivity", "Error creating project: ${response.code()} - ${response.message()}")
|
||||
Toast
|
||||
.makeText(this@CreateProjectActivity, "Error creating project", Toast.LENGTH_SHORT)
|
||||
.show()
|
||||
// Volver a MainActivity para ver el nuevo proyecto
|
||||
val intent = Intent(this@CreateProjectActivity, MainActivity::class.java)
|
||||
startActivity(intent)
|
||||
} else {
|
||||
val errorBody = response.errorBody()?.string()
|
||||
Log.e("CreateProjectActivity", "Error creating project: $errorBody")
|
||||
Toast.makeText(
|
||||
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()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -16,80 +16,83 @@
|
|||
app:srcCompat="@android:drawable/ic_menu_revert"
|
||||
android:id="@+id/returnActionButton"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
android:layout_marginBottom="16dp"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:layout_marginBottom="@dimen/fab_margin_bottom"
|
||||
android:layout_marginEnd="@dimen/fab_margin_end"
|
||||
app:layout_constraintEnd_toEndOf="parent" />
|
||||
|
||||
<TextView
|
||||
android:text="Create a new project..."
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/activityTitle"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintHorizontal_bias="0.5"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
android:padding="12dp"
|
||||
android:textSize="24dp"
|
||||
android:layout_marginTop="4dp" />
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
android:paddingBottom="@dimen/bottom_padding_for_fab">
|
||||
|
||||
<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" />
|
||||
<TextView
|
||||
android:text="Create a new project..."
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/activityTitle"
|
||||
android:padding="@dimen/padding_standard"
|
||||
android:textSize="@dimen/text_size_title"
|
||||
android:textStyle="bold"
|
||||
android:layout_marginTop="@dimen/margin_tiny" />
|
||||
|
||||
<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
|
||||
android:text="Project name:"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/newProjectNameLabel"
|
||||
android:textSize="@dimen/text_size_subtitle"
|
||||
android:textStyle="bold"
|
||||
android:layout_marginTop="@dimen/margin_medium"
|
||||
android:paddingLeft="@dimen/padding_standard"
|
||||
android:paddingRight="@dimen/padding_standard" />
|
||||
|
||||
<TextView
|
||||
android:text="Project name:"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/newProjectNameLabel"
|
||||
tools:layout_editor_absoluteX="0dp"
|
||||
android:labelFor="@id/activityTitle"
|
||||
app:layout_constraintTop_toBottomOf="@+id/activityTitle"
|
||||
android:layout_marginTop="16dp" />
|
||||
<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
|
||||
android:text="Project description:"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/newProjectDescriptionLabel"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintHorizontal_bias="0.0"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/newProjectName"
|
||||
android:layout_marginTop="20dp" />
|
||||
<TextView
|
||||
android:text="Project description:"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/newProjectDescriptionLabel"
|
||||
android:textSize="@dimen/text_size_subtitle"
|
||||
android:textStyle="bold"
|
||||
android:layout_marginTop="@dimen/margin_medium"
|
||||
android:paddingLeft="@dimen/padding_standard"
|
||||
android:paddingRight="@dimen/padding_standard" />
|
||||
|
||||
<Button
|
||||
android:text="Create new project"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/newProjectCreateButton"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintHorizontal_bias="0.5"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
android:layout_marginTop="15dp"
|
||||
app:layout_constraintTop_toBottomOf="@+id/newProjectDescription"
|
||||
android:padding="20dp"
|
||||
android:layout_margin="12dp" />
|
||||
<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
|
||||
android:text="Create new project"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/newProjectCreateButton"
|
||||
android:backgroundTint="@color/primary_green"
|
||||
android:layout_marginTop="@dimen/margin_large"
|
||||
android:layout_marginLeft="@dimen/margin_standard"
|
||||
android:layout_marginRight="@dimen/margin_standard" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
</LinearLayout>
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue