mirror of
https://github.com/a-mayb3/KanbanCloneAndroid.git
synced 2026-03-21 10:05:39 +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.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 {
|
||||||
|
Log.d("CreateProjectActivity", "Creating project: $projectName")
|
||||||
|
val projectCreate = ProjectCreate(projectName, projectDescription)
|
||||||
|
val response = api.createProject(projectCreate)
|
||||||
|
|
||||||
val projectCreate : ProjectCreate = ProjectCreate(projectName, projectDescription)
|
if (response.isSuccessful) {
|
||||||
val response = api.createProject(projectCreate)
|
Log.d("CreateProjectActivity", "Project created successfully: ${response.body()}")
|
||||||
|
Toast.makeText(
|
||||||
|
this@CreateProjectActivity,
|
||||||
|
"Project created successfully",
|
||||||
|
Toast.LENGTH_SHORT
|
||||||
|
).show()
|
||||||
|
finish()
|
||||||
|
|
||||||
if (response.isSuccessful){
|
// Volver a MainActivity para ver el nuevo proyecto
|
||||||
Toast
|
val intent = Intent(this@CreateProjectActivity, MainActivity::class.java)
|
||||||
.makeText(this@CreateProjectActivity, "Project created successfully", Toast.LENGTH_SHORT)
|
startActivity(intent)
|
||||||
.show()
|
} else {
|
||||||
Log.d("CreateProjectActivity", "Created project: ${response.body()}")
|
val errorBody = response.errorBody()?.string()
|
||||||
startActivity(Intent(this@CreateProjectActivity, MainActivity::class.java))
|
Log.e("CreateProjectActivity", "Error creating project: $errorBody")
|
||||||
} else {
|
Toast.makeText(
|
||||||
Log.e("CreateProjectActivity", "Error creating project: ${response.code()} - ${response.message()}")
|
this@CreateProjectActivity,
|
||||||
Toast
|
"Error creating project: ${response.code()}",
|
||||||
.makeText(this@CreateProjectActivity, "Error creating project", Toast.LENGTH_SHORT)
|
Toast.LENGTH_SHORT
|
||||||
.show()
|
).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"
|
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" />
|
||||||
|
|
||||||
<TextView
|
<LinearLayout
|
||||||
android:text="Create a new project..."
|
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="match_parent"
|
||||||
android:id="@+id/activityTitle"
|
android:orientation="vertical"
|
||||||
app:layout_constraintTop_toTopOf="parent"
|
android:paddingBottom="@dimen/bottom_padding_for_fab">
|
||||||
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" />
|
|
||||||
|
|
||||||
<MultiAutoCompleteTextView
|
<TextView
|
||||||
android:layout_width="match_parent"
|
android:text="Create a new project..."
|
||||||
android:layout_height="500dp"
|
android:layout_width="match_parent"
|
||||||
android:id="@+id/newProjectDescription"
|
android:layout_height="wrap_content"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
android:id="@+id/activityTitle"
|
||||||
app:layout_constraintHorizontal_bias="0.0"
|
android:padding="@dimen/padding_standard"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
android:textSize="@dimen/text_size_title"
|
||||||
app:layout_constraintTop_toBottomOf="@+id/newProjectDescriptionLabel"
|
android:textStyle="bold"
|
||||||
android:hint="This is my new super-special project that will change the world!!!"
|
android:layout_marginTop="@dimen/margin_tiny" />
|
||||||
android:textAlignment="textStart"
|
|
||||||
android:gravity="start|top"
|
|
||||||
android:padding="12dp" />
|
|
||||||
|
|
||||||
<AutoCompleteTextView
|
<TextView
|
||||||
android:layout_width="match_parent"
|
android:text="Project name:"
|
||||||
android:layout_height="wrap_content"
|
android:layout_width="match_parent"
|
||||||
android:id="@+id/newProjectName"
|
android:layout_height="wrap_content"
|
||||||
app:layout_constraintTop_toBottomOf="@+id/newProjectNameLabel"
|
android:id="@+id/newProjectNameLabel"
|
||||||
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"
|
||||||
android:hint="My new project!"
|
android:paddingLeft="@dimen/padding_standard"
|
||||||
android:padding="12dp" />
|
android:paddingRight="@dimen/padding_standard" />
|
||||||
|
|
||||||
<TextView
|
<EditText
|
||||||
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/newProjectName"
|
||||||
android:id="@+id/newProjectNameLabel"
|
android:hint="My new project!"
|
||||||
tools:layout_editor_absoluteX="0dp"
|
android:inputType="text"
|
||||||
android:labelFor="@id/activityTitle"
|
android:padding="@dimen/padding_standard"
|
||||||
app:layout_constraintTop_toBottomOf="@+id/activityTitle"
|
android:layout_marginLeft="@dimen/margin_standard"
|
||||||
android:layout_marginTop="16dp" />
|
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" />
|
||||||
|
|
||||||
<Button
|
<EditText
|
||||||
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/newProjectDescription"
|
||||||
android:id="@+id/newProjectCreateButton"
|
android:hint="This is my new super-special project that will change the world!!!"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
android:inputType="textMultiLine"
|
||||||
app:layout_constraintHorizontal_bias="0.5"
|
android:minLines="3"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
android:maxLines="5"
|
||||||
android:layout_marginTop="15dp"
|
android:gravity="start|top"
|
||||||
app:layout_constraintTop_toBottomOf="@+id/newProjectDescription"
|
android:padding="@dimen/padding_standard"
|
||||||
android:padding="20dp"
|
android:layout_marginLeft="@dimen/margin_standard"
|
||||||
android:layout_margin="12dp" />
|
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