Skip to content

Commit

Permalink
First implementation stab at “Make the annotation bar movable/dockable
Browse files Browse the repository at this point in the history
…#101”

Start of refactoring of build.gradle’s dependencies. Moving them into “Libs.kt” and several Plugin classes. This not only groups related dependencies and makes updating several dependencies with the same version number easier, but also will allow us to configure CI to use a dependency cache and point mentioned classes to the CI to use them as a hash to decide when to update the cache, which should speed up the build process.
Upping veersion code to 43
  • Loading branch information
Dima-Android committed Jan 25, 2024
1 parent 2db483b commit 8264657
Show file tree
Hide file tree
Showing 17 changed files with 255 additions and 214 deletions.
1 change: 1 addition & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.1")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.7.1")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.5.1")
implementation("org.jetbrains.kotlinx:kotlinx-collections-immutable:0.3.5")

//Crash
implementation("com.google.firebase:firebase-crashlytics-ktx:18.5.1")
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/java/org/zotero/android/architecture/KotlinX.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package org.zotero.android.architecture

import kotlinx.collections.immutable.ImmutableSet
import kotlinx.collections.immutable.toImmutableSet

/**
* Used to force a when statement to be exhaustive.
*/
Expand All @@ -14,3 +17,5 @@ fun <T : CharSequence> T?.nonEmptyStringOrNull(): T? = if (this.isNullOrBlank())
} else {
this
}

fun <T> emptyImmutableSet(): ImmutableSet<T> = emptySet<T>().toImmutableSet()
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ internal fun BoxScope.AllItemsBottomPanel(
.fillMaxWidth()
.height(layoutType.calculateAllItemsBottomPanelHeight())
.align(Alignment.BottomStart)
if (viewState.isEditing) {
if (viewState.selectedKeys != null) {
EditingBottomPanel(
modifier = commonModifier,
viewState = viewState,
Expand Down Expand Up @@ -57,7 +57,7 @@ private fun EditingBottomPanel(
horizontalArrangement = Arrangement.SpaceEvenly,
verticalAlignment = Alignment.CenterVertically,
) {
val isRestoreAndDeleteEnabled = viewState.getSelectedKeys().isNotEmpty()
val isRestoreAndDeleteEnabled = viewState.isAnythingSelected()
if (viewState.isCollectionTrash) {
IconWithPadding(
drawableRes = Drawables.restore_trash,
Expand Down Expand Up @@ -96,7 +96,7 @@ private fun EditingBottomPanel(
isEnabled = isRestoreAndDeleteEnabled,
tintColor = if (isRestoreAndDeleteEnabled) CustomTheme.colors.zoteroDefaultBlue else CustomTheme.colors.disabledContent,
onClick = {
viewModel.showRemoveFromCollectionQuestion(viewState.getSelectedKeys().toSet())
viewModel.showRemoveFromCollectionQuestion()
}
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,15 @@ internal fun AllItemsScreen(
NewDivider()
}
}
AllItemsTable(viewState, layoutType, viewModel)
AllItemsTable(
layoutType = layoutType,
itemCellModels = viewState.itemCellModels,
isEditing = viewState.isEditing,
isItemSelected = viewState::isSelected,
onItemTapped = viewModel::onItemTapped,
onAccessoryTapped = viewModel::onAccessoryTapped,
onItemLongTapped = viewModel::onItemLongTapped
)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import androidx.compose.material.Text
import androidx.compose.material.ripple.rememberRipple
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.runtime.snapshots.SnapshotStateList
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource
Expand All @@ -39,23 +40,30 @@ import org.zotero.android.uicomponents.theme.CustomTheme

@Composable
internal fun AllItemsTable(
viewState: AllItemsViewState,
layoutType: CustomLayoutSize.LayoutType,
viewModel: AllItemsViewModel
itemCellModels: SnapshotStateList<ItemCellModel>,
isItemSelected: (key: String) -> Boolean,
isEditing: Boolean,
onItemTapped: (item: ItemCellModel) -> Unit,
onItemLongTapped: (key: String) -> Unit,
onAccessoryTapped: (key: String) -> Unit,
) {
LazyColumn(
state = rememberLazyListState(),
) {
itemsIndexed(
items = viewState.itemCellModels
items = itemCellModels, key = { _, item -> item.hashCode() }
) { index, item ->
Box(modifier = Modifier.animateItemPlacement()) {
ItemRow(
cellModel = item,
layoutType = layoutType,
viewState = viewState,
viewModel = viewModel,
showBottomDivider = index != viewState.itemCellModels.size - 1
showBottomDivider = index != itemCellModels.size - 1,
isEditing = isEditing,
onItemTapped = onItemTapped,
onItemLongTapped = onItemLongTapped,
onAccessoryTapped = onAccessoryTapped,
isItemSelected = isItemSelected,
)
}
}
Expand All @@ -64,14 +72,17 @@ internal fun AllItemsTable(

@Composable
private fun ItemRow(
viewModel: AllItemsViewModel,
viewState: AllItemsViewState,
cellModel: ItemCellModel,
isItemSelected: (key: String) -> Boolean,
layoutType: CustomLayoutSize.LayoutType,
showBottomDivider: Boolean = false
showBottomDivider: Boolean = false,
isEditing: Boolean,
onItemTapped: (item: ItemCellModel) -> Unit,
onItemLongTapped: (key: String) -> Unit,
onAccessoryTapped: (key: String) -> Unit,
) {
var rowModifier: Modifier = Modifier.height(64.dp)
if (cellModel.isSelected) {
if (isItemSelected(cellModel.key)) {
rowModifier = rowModifier.background(color = CustomTheme.colors.popupSelectedRow)
}
Box {
Expand All @@ -80,21 +91,22 @@ private fun ItemRow(
modifier = rowModifier
.combinedClickable(
interactionSource = remember { MutableInteractionSource() },
indication = if (viewState.isEditing) null else rememberRipple(),
onClick = { viewModel.onItemTapped(cellModel) },
onLongClick = { viewModel.onItemLongTapped(cellModel.key) }
indication = if (isEditing) null else rememberRipple(),
onClick = { onItemTapped(cellModel) },
onLongClick = { onItemLongTapped(cellModel.key) }
)
) {
ItemRowLeftPart(
viewState = viewState,
layoutType = layoutType,
model = cellModel
model = cellModel,
isEditing = isEditing,
isItemSelected = isItemSelected,
)
Spacer(modifier = Modifier.width(16.dp))
ItemRowCentralPart(
model = cellModel,
viewState = viewState,
viewModel = viewModel,
isEditing = isEditing,
onAccessoryTapped = onAccessoryTapped,
)
}
if (showBottomDivider) {
Expand All @@ -107,16 +119,17 @@ private fun ItemRow(

@Composable
private fun ItemRowLeftPart(
viewState: AllItemsViewState,
layoutType: CustomLayoutSize.LayoutType,
model: ItemCellModel
model: ItemCellModel,
isItemSelected: (key: String) -> Boolean,
isEditing: Boolean,
) {
AnimatedContent(targetState = viewState.isEditing, label = "") { isEditing ->
AnimatedContent(targetState = isEditing, label = "") { isEditing ->
if (isEditing) {
Row {
Spacer(modifier = Modifier.width(16.dp))
CircleCheckBox(
isChecked = model.isSelected,
isChecked = isItemSelected(model.key),
layoutType = layoutType
)
}
Expand All @@ -133,8 +146,8 @@ private fun ItemRowLeftPart(
@Composable
private fun ItemRowCentralPart(
model: ItemCellModel,
viewState: AllItemsViewState,
viewModel: AllItemsViewModel,
isEditing: Boolean,
onAccessoryTapped: (key: String) -> Unit,
) {
Column {
Row(verticalAlignment = Alignment.CenterVertically) {
Expand Down Expand Up @@ -181,8 +194,8 @@ private fun ItemRowCentralPart(
Spacer(modifier = Modifier.width(8.dp))
ItemRowRightPart(
model = model,
viewState = viewState,
viewModel = viewModel,
isEditing = isEditing,
onAccessoryTapped = onAccessoryTapped,
)
}
}
Expand All @@ -191,22 +204,22 @@ private fun ItemRowCentralPart(
@Composable
private fun RowScope.ItemRowRightPart(
model: ItemCellModel,
viewState: AllItemsViewState,
viewModel: AllItemsViewModel,
isEditing: Boolean,
onAccessoryTapped: (key: String) -> Unit,
) {
SetAccessory(
accessory = model.accessory,
)
AnimatedContent(
modifier = Modifier.align(Alignment.CenterVertically),
targetState = viewState.isEditing,
targetState = isEditing,
label = ""
) { isEditing ->
if (!isEditing) {
Row {
IconWithPadding(
onClick = {
viewModel.onAccessoryTapped(model.key)
onAccessoryTapped(model.key)
},
drawableRes = Drawables.info_24px
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ private fun allItemsTopBarActions(
)
}
} else {
val allSelected = viewState.getSelectedKeys().size == (viewState.itemCellModels.size)
val allSelected = viewState.areAllSelected
if (allSelected) {
buttonsList.add {
NewHeadingTextButton(
Expand Down
Loading

0 comments on commit 8264657

Please sign in to comment.