-
Notifications
You must be signed in to change notification settings - Fork 144
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Enhancement] Enabling floating Info bar #390
Merged
mariobodemann
merged 3 commits into
gdg-berlin-android:main
from
lucasvillaverde:lvillaverde/floating-info-bar
Jul 15, 2024
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
package de.berlindroid.zeapp.zeui.zehome | ||
|
||
import android.graphics.Bitmap | ||
import androidx.compose.animation.core.animateFloatAsState | ||
import androidx.compose.animation.core.tween | ||
import androidx.compose.foundation.ExperimentalFoundationApi | ||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.PaddingValues | ||
import androidx.compose.foundation.layout.Spacer | ||
|
@@ -14,29 +14,30 @@ import androidx.compose.foundation.layout.padding | |
import androidx.compose.foundation.lazy.LazyColumn | ||
import androidx.compose.foundation.lazy.LazyListState | ||
import androidx.compose.foundation.lazy.items | ||
import androidx.compose.material3.Surface | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.LaunchedEffect | ||
import androidx.compose.runtime.collectAsState | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.runtime.setValue | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.graphics.graphicsLayer | ||
import androidx.compose.ui.platform.LocalSoftwareKeyboardController | ||
import androidx.compose.ui.unit.LayoutDirection | ||
import de.berlindroid.zeapp.ZeDimen | ||
import de.berlindroid.zeapp.zemodels.ZeConfiguration | ||
import de.berlindroid.zeapp.zemodels.ZeSlot | ||
import de.berlindroid.zeapp.zevm.ZeBadgeViewModel | ||
|
||
@OptIn(ExperimentalFoundationApi::class) | ||
@Composable | ||
internal fun ZePages( | ||
paddingValues: PaddingValues, | ||
vm: ZeBadgeViewModel, | ||
lazyListState: LazyListState, | ||
) { | ||
Surface( | ||
Box( | ||
modifier = Modifier.fillMaxSize(), | ||
) { | ||
val uiState by vm.uiState.collectAsState() // should be replace with 'collectAsStateWithLifecycle' | ||
|
@@ -47,7 +48,6 @@ internal fun ZePages( | |
val templateChooser = uiState.currentTemplateChooser | ||
val message = uiState.message | ||
val messageProgress = uiState.messageProgress | ||
val slots = uiState.slots | ||
val badgeConfiguration = uiState.currentBadgeConfig | ||
|
||
if (isKeyboardVisible && editor == null && templateChooser == null) { | ||
|
@@ -73,59 +73,86 @@ internal fun ZePages( | |
TemplateChooserDialog(vm, templateChooser, modifier = Modifier.padding(paddingValues)) | ||
} | ||
|
||
LazyColumn( | ||
state = lazyListState, | ||
modifier = | ||
Modifier | ||
.padding(top = paddingValues.calculateTopPadding()), | ||
contentPadding = | ||
PaddingValues( | ||
start = paddingValues.calculateStartPadding(LayoutDirection.Ltr), | ||
end = paddingValues.calculateEndPadding(LayoutDirection.Ltr), | ||
bottom = paddingValues.calculateBottomPadding(), | ||
), | ||
) { | ||
if (message.isNotEmpty()) { | ||
stickyHeader { | ||
InfoBar(message, messageProgress, vm::copyInfoToClipboard) | ||
} | ||
ZePagesLazyList( | ||
modifier = Modifier.padding(top = paddingValues.calculateTopPadding()), | ||
paddingValues = paddingValues, | ||
lazyListState = lazyListState, | ||
slots = uiState.slots, | ||
sendPageToBadgeAndDisplay = vm::sendPageToBadgeAndDisplay, | ||
slotToBitmap = vm::slotToBitmap, | ||
customizeSlot = vm::customizeSlot, | ||
customizeSponsorSlot = vm::customizeSponsorSlot, | ||
resetSlot = vm::resetSlot, | ||
) | ||
|
||
if (message.isNotEmpty()) { | ||
InfoBar( | ||
modifier = Modifier.align(Alignment.BottomCenter), | ||
message = message, | ||
progress = messageProgress, | ||
copyMoreToClipboard = vm::copyInfoToClipboard, | ||
) | ||
} | ||
} | ||
} | ||
|
||
@Composable | ||
private fun ZePagesLazyList( | ||
paddingValues: PaddingValues, | ||
lazyListState: LazyListState, | ||
slots: Map<ZeSlot, ZeConfiguration>, | ||
sendPageToBadgeAndDisplay: (ZeSlot) -> Unit, | ||
slotToBitmap: (ZeSlot) -> Bitmap, | ||
customizeSponsorSlot: (ZeSlot) -> Unit, | ||
customizeSlot: (ZeSlot) -> Unit, | ||
resetSlot: (ZeSlot) -> Unit, | ||
modifier: Modifier = Modifier, | ||
) { | ||
Comment on lines
+99
to
+110
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Extracting the list in a separate method, this will allow us to enable the preview functionality in the future without depending on the VM |
||
LazyColumn( | ||
state = lazyListState, | ||
modifier = modifier, | ||
contentPadding = | ||
PaddingValues( | ||
start = paddingValues.calculateStartPadding(LayoutDirection.Ltr), | ||
end = paddingValues.calculateEndPadding(LayoutDirection.Ltr), | ||
bottom = paddingValues.calculateBottomPadding(), | ||
), | ||
) { | ||
items( | ||
slots.keys.toList(), | ||
) { slot -> | ||
var isVisible by remember { mutableStateOf(false) } | ||
val alpha: Float by animateFloatAsState( | ||
targetValue = if (isVisible) 1f else 0f, | ||
label = "alpha", | ||
animationSpec = tween(durationMillis = 750), | ||
) | ||
LaunchedEffect(slot) { | ||
isVisible = true | ||
} | ||
items( | ||
slots.keys.toList(), | ||
) { slot -> | ||
var isVisible by remember { mutableStateOf(false) } | ||
val alpha: Float by animateFloatAsState( | ||
targetValue = if (isVisible) 1f else 0f, | ||
label = "alpha", | ||
animationSpec = tween(durationMillis = 750), | ||
) | ||
LaunchedEffect(slot) { | ||
isVisible = true | ||
} | ||
|
||
PagePreview( | ||
modifier = Modifier.graphicsLayer { this.alpha = alpha }, | ||
name = slot::class.simpleName ?: "WTF", | ||
bitmap = vm.slotToBitmap(slot), | ||
customizeThisPage = | ||
if (slot.isSponsor) { | ||
{ vm.customizeSponsorSlot(slot) } | ||
} else { | ||
{ vm.customizeSlot(slot) } | ||
}, | ||
resetThisPage = | ||
if (slot.isSponsor) { | ||
null | ||
} else { | ||
{ vm.resetSlot(slot) } | ||
}, | ||
sendToDevice = { | ||
vm.sendPageToBadgeAndDisplay(slot) | ||
PagePreview( | ||
modifier = Modifier.graphicsLayer { this.alpha = alpha }, | ||
name = slot::class.simpleName ?: "WTF", | ||
bitmap = slotToBitmap(slot), | ||
customizeThisPage = | ||
if (slot.isSponsor) { | ||
{ customizeSponsorSlot(slot) } | ||
} else { | ||
{ customizeSlot(slot) } | ||
}, | ||
) | ||
resetThisPage = | ||
if (slot.isSponsor) { | ||
null | ||
} else { | ||
{ resetSlot(slot) } | ||
}, | ||
sendToDevice = { | ||
sendPageToBadgeAndDisplay(slot) | ||
}, | ||
) | ||
|
||
Spacer(modifier = Modifier.height(ZeDimen.One)) | ||
} | ||
Spacer(modifier = Modifier.height(ZeDimen.One)) | ||
} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To change the InfoBar position, just change the Alignment on this line. e.g. if you want to put it at the top the aligment would be
Aligment.TopCenter