mirror of
https://github.com/a-mayb3/KanbanCloneAndroid.git
synced 2026-03-21 18:15:38 +01:00
Started working on project creation
This commit is contained in:
parent
d1c02510d1
commit
31a1d96236
2 changed files with 152 additions and 0 deletions
|
|
@ -1,13 +1,34 @@
|
|||
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.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.ProjectCreate
|
||||
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 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 newProjectCreateButton : Button
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
enableEdgeToEdge()
|
||||
|
|
@ -17,5 +38,51 @@ class CreateProjectActivity : AppCompatActivity() {
|
|||
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
|
||||
insets
|
||||
}
|
||||
|
||||
api = RetrofitInstance.getRetrofit(applicationContext).create(ApiService::class.java)
|
||||
|
||||
returnActionButton = findViewById(R.id.returnActionButton)
|
||||
returnActionButton.setOnClickListener { finish() }
|
||||
|
||||
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()
|
||||
|
||||
if (projectName.isEmpty() || projectDescription.isEmpty()) {
|
||||
Toast
|
||||
.makeText(this, "Please fill in all fields", Toast.LENGTH_SHORT)
|
||||
.show()
|
||||
return@setOnClickListener
|
||||
}
|
||||
|
||||
lifecycleScope.launch {
|
||||
|
||||
val projectCreate : ProjectCreate = ProjectCreate(projectName, projectDescription)
|
||||
val response = api.createProject(projectCreate)
|
||||
|
||||
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()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -7,4 +7,89 @@
|
|||
android:layout_height="match_parent"
|
||||
tools:context=".ui.CreateProjectActivity">
|
||||
|
||||
<com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:clickable="true"
|
||||
android:contentDescription="return back to home"
|
||||
android:focusable="true"
|
||||
app:srcCompat="@android:drawable/ic_menu_revert"
|
||||
android:id="@+id/returnActionButton"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
android:layout_marginBottom="16dp"
|
||||
android:layout_marginEnd="16dp"
|
||||
app:layout_constraintEnd_toEndOf="parent" />
|
||||
|
||||
<TextView
|
||||
android:text="Create a new project..."
|
||||
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" />
|
||||
|
||||
<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
|
||||
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" />
|
||||
|
||||
<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" />
|
||||
|
||||
<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" />
|
||||
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
Loading…
Add table
Add a link
Reference in a new issue