Skip to content

Commit

Permalink
- adds category screen
Browse files Browse the repository at this point in the history
  • Loading branch information
pablo03v committed Apr 13, 2024
1 parent bcb7f84 commit 7e8d3e2
Show file tree
Hide file tree
Showing 16 changed files with 432 additions and 154 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"formatVersion": 1,
"database": {
"version": 2,
"identityHash": "5786d9fcd0545b1af0077201c347aca5",
"identityHash": "eec8bb3483c07bec27c31bf05a9b56e7",
"entities": [
{
"tableName": "categories",
Expand Down Expand Up @@ -50,7 +50,7 @@
},
{
"tableName": "items",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `startTime` TEXT NOT NULL, `endTime` TEXT NOT NULL, `ongoing` INTEGER NOT NULL, `pause` INTEGER NOT NULL, `categoryId` INTEGER NOT NULL DEFAULT 0)",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `startTime` TEXT NOT NULL, `endTime` TEXT NOT NULL, `ongoing` INTEGER NOT NULL, `pause` INTEGER NOT NULL, `categoryId` INTEGER NOT NULL DEFAULT 1)",
"fields": [
{
"fieldPath": "id",
Expand Down Expand Up @@ -87,7 +87,7 @@
"columnName": "categoryId",
"affinity": "INTEGER",
"notNull": true,
"defaultValue": "0"
"defaultValue": "1"
}
],
"primaryKey": {
Expand All @@ -103,7 +103,7 @@
"views": [],
"setupQueries": [
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '5786d9fcd0545b1af0077201c347aca5')"
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, 'eec8bb3483c07bec27c31bf05a9b56e7')"
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@ sealed interface CategoryEvent {
data class SetSelectedCategoryConfigurations(val selectedCategoryConfigurations: Int) : CategoryEvent

data class SetSelectedCategory(val selectedCategory: Int) : CategoryEvent

data class SetIsCreateCategoryDialogOpenHome(val isCreateCategoryDialogOpenHome: Boolean) : CategoryEvent
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ data class CategoryState(
// --
val selectedCategoryConfigurations: Int = 1,
val selectedCategory: Int = 1,
val isCreateCategoryDialogOpenHome: Boolean = false,
)
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,14 @@ class CategoryViewModel(
)
}
}

is CategoryEvent.SetIsCreateCategoryDialogOpenHome -> {
_state.update {
it.copy(
isCreateCategoryDialogOpenHome = event.isCreateCategoryDialogOpenHome,
)
}
}
}
}
}
2 changes: 1 addition & 1 deletion app/src/main/java/cloud/pablos/overload/data/item/Item.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ data class Item(
val endTime: String,
val ongoing: Boolean,
val pause: Boolean,
@ColumnInfo(defaultValue = "0")
@ColumnInfo(defaultValue = "1")
val categoryId: Int,
)
29 changes: 28 additions & 1 deletion app/src/main/java/cloud/pablos/overload/data/item/ItemDao.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package cloud.pablos.overload.data.item

import androidx.compose.ui.graphics.Color
import androidx.room.Dao
import androidx.room.Delete
import androidx.room.Query
import androidx.room.Upsert
import cloud.pablos.overload.data.Converters.Companion.convertColorToLong
import cloud.pablos.overload.data.category.CategoryEvent
import cloud.pablos.overload.data.category.CategoryState
import cloud.pablos.overload.ui.tabs.home.getItemsOfDay
import cloud.pablos.overload.ui.views.extractDate
Expand All @@ -30,7 +33,31 @@ interface ItemDao {
fun getAllItems(): Flow<List<Item>>
}

fun startOrStopPause(
fun fabPress(
categoryState: CategoryState,
categoryEvent: (CategoryEvent) -> Unit,
itemState: ItemState,
itemEvent: (ItemEvent) -> Unit,
) {
val categories = categoryState.categories

if (categories.isNotEmpty()) {
startOrStop(categoryState, itemState, itemEvent)
} else if (itemState.items.isNotEmpty()) {
categoryEvent(CategoryEvent.SetId(1))
categoryEvent(CategoryEvent.SetName("Default"))
categoryEvent(CategoryEvent.SetColor(convertColorToLong(Color(204, 230, 255))))
categoryEvent(CategoryEvent.SetEmoji("🕣"))
categoryEvent(CategoryEvent.SetIsDefault(true))
categoryEvent(CategoryEvent.SaveCategory)

startOrStop(categoryState, itemState, itemEvent)
} else {
categoryEvent(CategoryEvent.SetIsCreateCategoryDialogOpenHome(true))
}
}

fun startOrStop(
categoryState: CategoryState,
itemState: ItemState,
itemEvent: (ItemEvent) -> Unit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import cloud.pablos.overload.data.category.CategoryEvent
import cloud.pablos.overload.data.category.CategoryState
import cloud.pablos.overload.data.item.ItemEvent
import cloud.pablos.overload.data.item.ItemState
import cloud.pablos.overload.data.item.startOrStopPause
import cloud.pablos.overload.data.item.fabPress
import cloud.pablos.overload.ui.tabs.home.HomeTabManualDialog
import cloud.pablos.overload.ui.tabs.home.getItemsOfDay
import cloud.pablos.overload.ui.views.TextView
Expand Down Expand Up @@ -237,7 +237,7 @@ fun OverloadNavigationFab(
FloatingActionButton(
onClick = {
if (isLongClick.not()) {
startOrStopPause(categoryState, itemState, itemEvent)
fabPress(categoryState, categoryEvent, itemState, itemEvent)
}
},
interactionSource = interactionSource,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import cloud.pablos.overload.data.category.CategoryEvent
import cloud.pablos.overload.data.category.CategoryState
import cloud.pablos.overload.data.item.ItemEvent
import cloud.pablos.overload.data.item.ItemState
import cloud.pablos.overload.data.item.startOrStopPause
import cloud.pablos.overload.data.item.fabPress
import cloud.pablos.overload.ui.tabs.home.HomeTabDeleteFAB
import cloud.pablos.overload.ui.tabs.home.HomeTabManualDialog
import cloud.pablos.overload.ui.tabs.home.getItemsOfDay
Expand Down Expand Up @@ -141,7 +141,7 @@ fun OverloadNavigationFabSmall(
FloatingActionButton(
onClick = {
if (isLongClick.not()) {
startOrStopPause(categoryState, itemState, itemEvent)
fabPress(categoryState, categoryEvent, itemState, itemEvent)
}
},
interactionSource = interactionSource,
Expand Down
Loading

0 comments on commit 7e8d3e2

Please sign in to comment.