Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
700d8cd
misc
dinhkhoi2k3 Jul 12, 2024
ba0588d
misc
dinhkhoi2k3 Jul 12, 2024
3a21d14
Merge branch 'dev-khoi' of https://github.com/Arcahv/Tasks-Board into…
dinhkhoi2k3 Jul 13, 2024
cd800a7
Update activity_taskboards.xml
dinhkhoi2k3 Jul 13, 2024
54b8d7b
modify TaskItem data class
dinhkhoi2k3 Jul 13, 2024
9cb441b
fix add board button
dinhkhoi2k3 Jul 13, 2024
3189410
fix add board button to add to 1 board
dinhkhoi2k3 Jul 13, 2024
13e9309
misc
dinhkhoi2k3 Jul 13, 2024
8571881
added option for add task
dinhkhoi2k3 Jul 13, 2024
f78b52f
Revert "added option for add task"
dinhkhoi2k3 Jul 13, 2024
050bd3c
add desc when adding task
dinhkhoi2k3 Jul 13, 2024
a8d2713
add due date when adding task
dinhkhoi2k3 Jul 13, 2024
0f390ed
add priority when adding task
dinhkhoi2k3 Jul 13, 2024
ee61957
add task details activity
dinhkhoi2k3 Jul 13, 2024
d022fcc
Edited entities to reflect fields in firestore db (removing redundant…
PISKASOSISKA Jul 14, 2024
a108a13
Merge branch 'development' into dev-khoi
dinhkhoi2k3 Jul 14, 2024
634ea6d
Update board_item.xml
dinhkhoi2k3 Jul 14, 2024
85a6a91
change task item to cardView
dinhkhoi2k3 Jul 14, 2024
7db6c5a
misc
dinhkhoi2k3 Jul 14, 2024
2b7b0bf
delete viewPager2
dinhkhoi2k3 Jul 14, 2024
3ed8a94
Fixed naming to reflect database naming convention
PISKASOSISKA Jul 14, 2024
0ff2c3a
misc
dinhkhoi2k3 Jul 14, 2024
7e81f20
delete unnecessary files
dinhkhoi2k3 Jul 14, 2024
e1f2bad
add checkbox placeholder
dinhkhoi2k3 Jul 14, 2024
9237e9f
add function to checkbox to change status
dinhkhoi2k3 Jul 15, 2024
724c708
add placeholder to edit and delete task
dinhkhoi2k3 Jul 15, 2024
971f663
add edit task func
dinhkhoi2k3 Jul 15, 2024
f94dcae
Update TaskboardsActivity.kt
dinhkhoi2k3 Jul 15, 2024
5d7aa22
Merge branch 'development' into dev-khoi
dinhkhoi2k3 Jul 15, 2024
e655f8b
finish edit task
dinhkhoi2k3 Jul 15, 2024
8380520
finish delete task
dinhkhoi2k3 Jul 15, 2024
1a20202
placeholder to change user
dinhkhoi2k3 Jul 15, 2024
d20ff33
add sign out
dinhkhoi2k3 Jul 15, 2024
ed3af18
remove sign out
dinhkhoi2k3 Jul 15, 2024
93b8b37
placeholder search button
dinhkhoi2k3 Jul 15, 2024
815523b
modify search placeholder
dinhkhoi2k3 Jul 15, 2024
b2bb27d
Added plain gridview for OverviewActivity
sonbeo1907-go-for-it Jul 15, 2024
3a7f475
Added plain gridview for OverviewActivity and Layout View
sonbeo1907-go-for-it Jul 15, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ android {
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}

buildFeatures {
viewBinding = true
}

buildTypes {
release {
isMinifyEnabled = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import com.google.firebase.Timestamp
import com.google.firebase.firestore.PropertyName

data class BoardItem(
var boardId: String = "",
@get:PropertyName("board_id") @set:PropertyName("board_id") var boardId: String = "",
@get:PropertyName("created_at") @set:PropertyName("created_at") var createdAt: Timestamp,
@get:PropertyName("name") @set:PropertyName("name") var name: String,
@get:PropertyName("updated_at") @set:PropertyName("updated_at") var updatedAt: Timestamp,
Expand Down
16 changes: 16 additions & 0 deletions app/src/main/java/com/prm/tasksboard/taskboards/entity/TaskItem.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.prm.tasksboard.taskboards.entity

import com.google.firebase.Timestamp
import com.google.firebase.firestore.PropertyName

data class TaskItem(
@get:PropertyName("task_id") @set:PropertyName("task_id") var taskId: String = "",
@get:PropertyName("title") @set:PropertyName("title") var title: String = "",
@get:PropertyName("description") @set:PropertyName("description") var description: String = "",
@get:PropertyName("status") @set:PropertyName("status") var status: String = "",
@get:PropertyName("due_date") @set:PropertyName("due_date") var dueDate: Timestamp,
@get:PropertyName("priority") @set:PropertyName("priority") var priority: String = "",
@get:PropertyName("created_at") @set:PropertyName("created_at") var createdAt: Timestamp,
) {
constructor() : this("", "", "", "", Timestamp.now(), "", Timestamp.now())
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,37 @@ package com.prm.tasksboard.taskboards.firestore

import android.util.Log
import com.google.android.gms.tasks.Task
import com.google.firebase.Timestamp
import com.google.firebase.auth.FirebaseAuth
import com.google.firebase.firestore.QuerySnapshot
import com.google.firebase.firestore.ktx.firestore
import com.google.firebase.ktx.Firebase
import com.prm.tasksboard.taskboards.entity.BoardItem
import com.prm.tasksboard.taskboards.entity.TaskItem

class DatabaseHandler {
private val db = Firebase.firestore
private val loggedInUserId = FirebaseAuth.getInstance().currentUser?.uid ?: ""

fun addBoardItem(boardItem: BoardItem) {
// Firestore generates a unique ID for the new document
fun addBoardItem(boardItem: BoardItem, callback: (String) -> Unit) {
val docRef = db.collection("boards").document()
boardItem.boardId = docRef.id // Assign the Firestore-generated ID to the boardItem
boardItem.boardId = docRef.id
boardItem.userId = loggedInUserId
boardItem.createdAt = Timestamp.now() // Set created_at to current time

docRef.set(boardItem)
.addOnSuccessListener {
Log.d("FirestoreAdd", "BoardItem successfully added with ID: ${docRef.id}")
callback(docRef.id) // Invoke the callback with the new board's ID
}
.addOnFailureListener { e ->
Log.w("FirestoreAdd", "Error adding BoardItem", e)
Log.w("DatabaseHandler", "Error adding BoardItem", e)
}
}

fun getBoardItemsByUserId(): Task<QuerySnapshot> {
return db.collection("boards")
.whereEqualTo("user_id", loggedInUserId).orderBy("created_at")
.whereEqualTo("user_id", loggedInUserId)
.orderBy("created_at")
.get()
.addOnSuccessListener { result ->
for (document in result) {
Expand Down Expand Up @@ -65,7 +69,7 @@ class DatabaseHandler {
}

fun checkFirestoreConnection() {
db.collection("boards") // Replace "known_collection" with your actual collection name
db.collection("boards")
.whereEqualTo("user_id", loggedInUserId).limit(1)
.get()
.addOnSuccessListener { documents ->
Expand All @@ -79,4 +83,77 @@ class DatabaseHandler {
Log.w("FirestoreCheck", "Error connecting to Firestore: ", exception)
}
}
}

fun addTaskItem(taskItem: TaskItem, boardId: String, callback: () -> Unit) {
val newTaskRef = db.collection("boards").document(boardId).collection("tasks").document()
taskItem.taskId = newTaskRef.id
newTaskRef.set(taskItem)
.addOnSuccessListener {
Log.d("FirestoreAdd", "TaskItem successfully added with ID: ${taskItem.taskId}")
callback()
}
.addOnFailureListener { e ->
Log.w("FirestoreAdd", "Error adding TaskItem", e)
}
}

fun deleteTaskItem(boardId: String, taskId: String, callback: () -> Unit) {
db.collection("boards").document(boardId).collection("tasks").document(taskId)
.delete()
.addOnSuccessListener {
Log.d("FirestoreDelete", "Task $taskId successfully deleted!")
callback()
}
.addOnFailureListener { e -> Log.w("FirestoreDelete", "Error deleting task", e) }
}

fun getTasksByBoardId(boardId: String, callback: (List<TaskItem>) -> Unit) {
db.collection("boards").document(boardId).collection("tasks")
.get()
.addOnSuccessListener { documents ->
val tasks = documents.toObjects(TaskItem::class.java)
callback(tasks)
}
.addOnFailureListener { exception ->
Log.w("DatabaseHandler", "Error getting tasks by board ID", exception)
}
}

fun getAllTasks(callback: (List<TaskItem>) -> Unit) {
val allTasks = mutableListOf<TaskItem>()
db.collection("boards").get().addOnSuccessListener { boardDocuments ->
val boardCount = boardDocuments.size()
var processedBoards = 0
if (boardCount == 0) callback(allTasks) // Immediately return if no boards

boardDocuments.forEach { boardDoc ->
db.collection("boards").document(boardDoc.id).collection("tasks").get()
.addOnSuccessListener { taskDocuments ->
val tasks = taskDocuments.toObjects(TaskItem::class.java)
allTasks.addAll(tasks)
processedBoards++
if (processedBoards == boardCount) {
callback(allTasks)
}
}
}
}
}

fun updateTaskItem(
boardId: String,
taskId: String,
updatedFields: Map<String, Any>,
callback: () -> Unit
) {
db.collection("boards").document(boardId).collection("tasks").document(taskId)
.update(updatedFields)
.addOnSuccessListener {
Log.d("FirestoreUpdate", "Task $taskId successfully updated!")
callback()
}
.addOnFailureListener { e ->
Log.w("FirestoreUpdate", "Error updating task", e)
}
}
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.prm.tasksboard.taskboards.view

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.BaseAdapter
import android.widget.TextView
import com.prm.tasksboard.R
import com.prm.tasksboard.taskboards.entity.BoardItem

internal class GridRVAdapter (
private val boardList: MutableList<BoardItem> = mutableListOf<BoardItem>(),
private val context: Context
):
BaseAdapter() {

private var layoutInflater:LayoutInflater? = null
private lateinit var boardName: TextView

override fun getCount(): Int {
return boardList.size
}

override fun getItem(p0: Int): Any?{
return null
}

override fun getItemId(p0: Int): Long {
return 0
}

override fun getView(position: Int, convertView: View?, parent: ViewGroup?): View? {
var convertView = convertView
if (layoutInflater == null){
layoutInflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
}
if (convertView == null){
convertView = layoutInflater!!.inflate(R.layout.grid_items, null)
}
boardName = convertView!!.findViewById(R.id.boardName)
boardName.setText(boardList.get(position).name)
return convertView
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.prm.tasksboard.taskboards.view

import android.os.Bundle
import android.widget.GridView
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import com.prm.tasksboard.R
import com.prm.tasksboard.taskboards.entity.BoardItem
import com.prm.tasksboard.taskboards.firestore.DatabaseHandler


class OverviewActivity : AppCompatActivity() {
lateinit var boardGridView: GridView
private var boardList = mutableListOf<BoardItem>()
private val dbHandler = DatabaseHandler()
val taskboardsActivity = TaskboardsActivity()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.grid_outer)
boardGridView = findViewById(R.id.idGRV)
dbHandler.getBoardItemsByUserId().addOnSuccessListener { result ->
boardList.clear()
val newItems = result.map { document ->
document.toObject(BoardItem::class.java)
}
.sortedBy { it.createdAt }
boardList.addAll(newItems)
}
val gridAdapter = GridRVAdapter(boardList, this)
boardGridView.adapter = gridAdapter
boardGridView.setOnItemClickListener { _, _, position, _ ->
Toast.makeText( applicationContext, boardList[position].name + " selected", Toast.LENGTH_SHORT).show()
taskboardsActivity.setupSelectedTabLayout(position)
}
}


}
Loading