mirror of
https://github.com/a-mayb3/KanbanCloneAndroid.git
synced 2026-03-21 18:15:38 +01:00
Started working on rendering project details in ProjectDetailActivity.kt
This commit is contained in:
parent
39f28f619a
commit
110f356d78
5 changed files with 149 additions and 25 deletions
|
|
@ -8,6 +8,11 @@ class Project{
|
|||
val description: String = ""
|
||||
val users: List<User> = emptyList()
|
||||
val tasks: List<Task> = emptyList()
|
||||
|
||||
|
||||
override fun toString(): String {
|
||||
return "Project(id=$id, name='$name', description='$description', users=$users, tasks=$tasks)"
|
||||
}
|
||||
}
|
||||
|
||||
data class ProjectBase(
|
||||
|
|
|
|||
|
|
@ -1,13 +1,32 @@
|
|||
package com.campusaula.edbole.kanban_clone_android.ui
|
||||
|
||||
import android.health.connect.datatypes.units.Percentage
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import android.widget.TextView
|
||||
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.Project
|
||||
import com.campusaula.edbole.kanban_clone_android.kanban.Task
|
||||
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 ProjectDetailActivity : AppCompatActivity() {
|
||||
|
||||
private lateinit var api: ApiService
|
||||
|
||||
private lateinit var projectTitleText : TextView
|
||||
private lateinit var projectDescriptionText : TextView
|
||||
private lateinit var completedPercentageText: TextView
|
||||
private lateinit var returnActionButton: FloatingActionButton
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
enableEdgeToEdge()
|
||||
|
|
@ -17,5 +36,57 @@ class ProjectDetailActivity : AppCompatActivity() {
|
|||
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
|
||||
insets
|
||||
}
|
||||
api = RetrofitInstance.getRetrofit(applicationContext).create(ApiService::class.java)
|
||||
projectTitleText = findViewById(R.id.projectTitleText)
|
||||
projectDescriptionText = findViewById(R.id.projectDescriptionText)
|
||||
completedPercentageText = findViewById(R.id.completedPercentageText)
|
||||
returnActionButton = findViewById(R.id.returnActionButton)
|
||||
returnActionButton.setOnClickListener { finish() }
|
||||
|
||||
val projectId : Int = intent.getIntExtra("project_id", -1)
|
||||
|
||||
if (projectId > 0) {
|
||||
Log.d("ProjectDetailActivity", "Received project ID: $projectId")
|
||||
lifecycleScope.launch {
|
||||
try {
|
||||
val projectResponse = api.getProjectById(projectId)
|
||||
|
||||
if (projectResponse.isSuccessful && projectResponse.body() != null) {
|
||||
Log.d("ProjectDetailActivity", "Fetched project: ${projectResponse.body()!!.name}")
|
||||
val project = projectResponse.body()!!
|
||||
|
||||
|
||||
Log.d("ProjectDetailActivity", "Displaying project details for: $project")
|
||||
|
||||
projectTitleText.text = project.name
|
||||
projectDescriptionText.text = project.description
|
||||
|
||||
var percentageFinished = 0.0;
|
||||
val tasks: List<Task> = project.tasks
|
||||
val totalTasks: Int = tasks.size
|
||||
val perTaskPercentage = if (totalTasks > 0) (1.0 / totalTasks)*100 else 0.0
|
||||
|
||||
for (task in tasks) {
|
||||
if (task.status == TaskStatus.COMPLETED) {
|
||||
percentageFinished += perTaskPercentage
|
||||
}
|
||||
}
|
||||
completedPercentageText.text = "Completed: ${"%.2f".format(percentageFinished * 100)}%"
|
||||
|
||||
|
||||
} else {
|
||||
Log.e("ProjectDetailActivity", "Failed to fetch project: ${projectResponse.code()} - ${projectResponse.message()}")
|
||||
finish()
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Log.e("ProjectDetailActivity", "Error fetching project", e)
|
||||
finish()
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Log.e("ProjectDetailActivity", "No project ID found in intent")
|
||||
finish()
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -37,7 +37,7 @@ class ProjectItemAdapter(
|
|||
private val descTv: TextView = itemView.findViewById(R.id.projectDescription)
|
||||
|
||||
fun bind(project: Project) {
|
||||
nameTv.text = project.name
|
||||
nameTv.text = project.id.toString() + " " + project.name
|
||||
descTv.text = project.description
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,4 +7,50 @@
|
|||
android:layout_height="match_parent"
|
||||
tools:context=".ui.ProjectDetailActivity">
|
||||
|
||||
<com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:clickable="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="Project Name"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/projectTitleText"
|
||||
android:padding="12dp"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
android:layout_marginTop="4dp"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintHorizontal_bias="0.5"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
android:textSize="24sp" />
|
||||
|
||||
<TextView
|
||||
android:text="Completed: 100%"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/completedPercentageText"
|
||||
app:layout_constraintTop_toBottomOf="@+id/projectTitleText"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintHorizontal_bias="0.5"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
android:paddingRight="12dp"
|
||||
android:paddingLeft="12dp" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/projectDescriptionText"
|
||||
app:layout_constraintTop_toBottomOf="@+id/completedPercentageText"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintHorizontal_bias="0.5"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
android:text="Project description"
|
||||
android:padding="12dp" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
|
@ -1,32 +1,34 @@
|
|||
<?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"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="12dp">
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="8dp"
|
||||
android:layout_margin="8dp">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/projectName"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Project name"
|
||||
android:textStyle="bold"
|
||||
android:textSize="16sp"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
android:id="@+id/projectName"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Project name"
|
||||
android:textStyle="bold"
|
||||
android:textSize="16sp"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/projectDescription"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Project description"
|
||||
android:textSize="14sp"
|
||||
android:ellipsize="end"
|
||||
android:maxLines="2"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/projectName"
|
||||
android:layout_marginTop="4dp" />
|
||||
android:id="@+id/projectDescription"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Project description"
|
||||
android:textSize="14sp"
|
||||
android:ellipsize="end"
|
||||
android:maxLines="2"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/projectName"
|
||||
android:layout_marginTop="4dp" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue