-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a way to remove archived group. Closes #133
- Loading branch information
1 parent
3abcc2c
commit 4ded7bd
Showing
7 changed files
with
236 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
113 changes: 113 additions & 0 deletions
113
app/src/main/java/org/zotero/android/screens/libraries/DeleteGroupPopup.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
package org.zotero.android.screens.libraries | ||
|
||
import androidx.compose.foundation.background | ||
import androidx.compose.foundation.clickable | ||
import androidx.compose.foundation.interaction.MutableInteractionSource | ||
import androidx.compose.foundation.layout.Row | ||
import androidx.compose.foundation.layout.Spacer | ||
import androidx.compose.foundation.layout.fillMaxHeight | ||
import androidx.compose.foundation.layout.height | ||
import androidx.compose.foundation.layout.width | ||
import androidx.compose.foundation.shape.RoundedCornerShape | ||
import androidx.compose.material.Icon | ||
import androidx.compose.material.Text | ||
import androidx.compose.material.ripple.rememberRipple | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.draw.shadow | ||
import androidx.compose.ui.platform.LocalDensity | ||
import androidx.compose.ui.res.painterResource | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.compose.ui.unit.IntOffset | ||
import androidx.compose.ui.unit.IntRect | ||
import androidx.compose.ui.unit.IntSize | ||
import androidx.compose.ui.unit.LayoutDirection | ||
import androidx.compose.ui.unit.dp | ||
import androidx.compose.ui.window.Popup | ||
import androidx.compose.ui.window.PopupPositionProvider | ||
import androidx.compose.ui.window.PopupProperties | ||
import org.zotero.android.uicomponents.CustomScaffold | ||
import org.zotero.android.uicomponents.Drawables | ||
import org.zotero.android.uicomponents.Strings | ||
import org.zotero.android.uicomponents.theme.CustomTheme | ||
|
||
@Composable | ||
internal fun DeleteGroupPopup( | ||
onDeleteGroup: () -> Unit, | ||
dismissDeleteGroupPopup: () -> Unit, | ||
) { | ||
val backgroundColor = CustomTheme.colors.topBarBackgroundColor | ||
Popup( | ||
properties = PopupProperties( | ||
dismissOnBackPress = true, | ||
dismissOnClickOutside = true | ||
), | ||
onDismissRequest = dismissDeleteGroupPopup, | ||
popupPositionProvider = createDeleteGroupPopupPositionProvider(), | ||
) { | ||
CustomScaffold( | ||
modifier = Modifier | ||
.width(250.dp) | ||
.height(48.dp) | ||
.shadow( | ||
elevation = 4.dp, | ||
shape = RoundedCornerShape(16.dp), | ||
), | ||
backgroundColor = backgroundColor, | ||
) { | ||
Row( | ||
modifier = Modifier | ||
.fillMaxHeight() | ||
.background(color = CustomTheme.colors.cardBackground) | ||
.clickable( | ||
interactionSource = remember { MutableInteractionSource() }, | ||
indication = rememberRipple(bounded = true), | ||
onClick = { onDeleteGroup() } | ||
), | ||
verticalAlignment = Alignment.CenterVertically | ||
) { | ||
Spacer(modifier = Modifier.width(16.dp)) | ||
Text( | ||
modifier = Modifier.weight(1f), | ||
text = stringResource(id = Strings.remove), | ||
maxLines = 1, | ||
style = CustomTheme.typography.newBody, | ||
) | ||
Icon( | ||
painter = painterResource(id = Drawables.delete_24px), | ||
contentDescription = null, | ||
tint = CustomTheme.colors.error | ||
) | ||
Spacer(modifier = Modifier.width(8.dp)) | ||
} | ||
} | ||
} | ||
} | ||
|
||
@Composable | ||
private fun createDeleteGroupPopupPositionProvider() = object : PopupPositionProvider { | ||
val localDensity = LocalDensity.current | ||
override fun calculatePosition( | ||
anchorBounds: IntRect, | ||
windowSize: IntSize, | ||
layoutDirection: LayoutDirection, | ||
popupContentSize: IntSize | ||
): IntOffset { | ||
val extraXOffset = with(localDensity) { | ||
14.dp.toPx() | ||
}.toInt() | ||
val extraYOffset = with(localDensity) { | ||
6.dp.toPx() | ||
}.toInt() | ||
|
||
val xOffset = anchorBounds.left + extraXOffset | ||
val yOffset = anchorBounds.bottom + extraYOffset | ||
|
||
return IntOffset( | ||
x = xOffset, | ||
y = yOffset | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.