-
Notifications
You must be signed in to change notification settings - Fork 6
popup media element and media image thumbnail support #449
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 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 hidden or 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 hidden or 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
70 changes: 70 additions & 0 deletions
70
...src/main/java/com/arcgismaps/toolkit/popup/internal/element/media/MediaElementDefaults.kt
This file contains hidden or 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,70 @@ | ||
/* | ||
* Copyright 2024 Esri | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.arcgismaps.toolkit.popup.internal.element.media | ||
|
||
import androidx.compose.foundation.shape.RoundedCornerShape | ||
import androidx.compose.material3.MaterialTheme | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.unit.Dp | ||
import androidx.compose.ui.unit.dp | ||
|
||
/** | ||
* A central place for theming values. To be promoted to a public theme type. | ||
*/ | ||
internal object MediaElementDefaults { | ||
@Composable | ||
fun shapes(): MediaElementShapes = MediaElementShapes( | ||
borderThickness = 1.dp, | ||
containerShape = RoundedCornerShape(5.dp), | ||
tileShape = RoundedCornerShape(8.dp), | ||
galleryPadding = 15.dp, | ||
tileStrokeWidth = 0.5.dp, | ||
tileWidth = 276.dp, | ||
tileHeight = 225.dp | ||
) | ||
|
||
@Suppress("unused") | ||
@Composable | ||
fun colors() : MediaElementColors = MediaElementColors( | ||
containerColor = MaterialTheme.colorScheme.background, | ||
galleryContainerColor = MaterialTheme.colorScheme.onBackground, | ||
borderColor = MaterialTheme.colorScheme.outline, | ||
tileBorderColor = MaterialTheme.colorScheme.outline.copy(alpha = 0.6f), | ||
tileTextBackgroundColor = MaterialTheme.colorScheme.onBackground, | ||
tileTextColor = MaterialTheme.colorScheme.background | ||
) | ||
} | ||
|
||
internal data class MediaElementShapes( | ||
val borderThickness: Dp, | ||
val containerShape: RoundedCornerShape, | ||
val tileShape: RoundedCornerShape, | ||
val galleryPadding: Dp, | ||
val tileStrokeWidth: Dp, | ||
val tileWidth: Dp, | ||
val tileHeight: Dp | ||
) | ||
|
||
internal data class MediaElementColors( | ||
val containerColor : Color, | ||
val galleryContainerColor: Color, | ||
val tileBorderColor : Color, | ||
val borderColor : Color, | ||
val tileTextBackgroundColor: Color, | ||
val tileTextColor: Color | ||
) |
97 changes: 97 additions & 0 deletions
97
...up/src/main/java/com/arcgismaps/toolkit/popup/internal/element/media/MediaElementState.kt
This file contains hidden or 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,97 @@ | ||
/* | ||
* Copyright 2024 Esri | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.arcgismaps.toolkit.popup.internal.element.media | ||
|
||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.Immutable | ||
import androidx.compose.runtime.saveable.Saver | ||
import androidx.compose.runtime.saveable.rememberSaveable | ||
import com.arcgismaps.mapping.popup.MediaPopupElement | ||
import com.arcgismaps.mapping.popup.Popup | ||
import com.arcgismaps.mapping.popup.PopupMedia | ||
import com.arcgismaps.mapping.popup.PopupMediaType | ||
import com.arcgismaps.toolkit.popup.internal.element.state.PopupElementState | ||
|
||
/** | ||
* Represents the state of an [MediaPopupElement] | ||
*/ | ||
@Immutable | ||
internal class MediaElementState( | ||
val description: String, | ||
val title: String, | ||
val media: List<PopupMediaState>, | ||
override val id : Int = createId(), | ||
) : PopupElementState() { | ||
|
||
constructor(mediaPopupElement: MediaPopupElement): this( | ||
description = mediaPopupElement.description, | ||
title = mediaPopupElement.title, | ||
media = mediaPopupElement.media | ||
.filter { it.type is PopupMediaType.Image } | ||
.map { PopupMediaState(it) } | ||
) | ||
|
||
companion object { | ||
fun Saver( | ||
element: MediaPopupElement | ||
): Saver<MediaElementState, Any> = Saver( | ||
save = { null }, | ||
restore = { | ||
MediaElementState( | ||
element | ||
) | ||
} | ||
) | ||
|
||
} | ||
} | ||
|
||
@Composable | ||
internal fun rememberMediaElementState( | ||
element: MediaPopupElement, | ||
popup: Popup | ||
): MediaElementState { | ||
return rememberSaveable( | ||
inputs = arrayOf(popup, element), | ||
saver = MediaElementState.Saver(element) | ||
) { | ||
MediaElementState( | ||
element | ||
) | ||
} | ||
} | ||
|
||
/** | ||
* Represents the state of a [PopupMedia value]. | ||
*/ | ||
internal class PopupMediaState( | ||
val title: String, | ||
val caption: String, | ||
@Suppress("unused") val refreshInterval: Long, | ||
@Suppress("unused") val linkUrl: String, | ||
val sourceUrl: String, | ||
val type: PopupMediaType | ||
) { | ||
constructor(media: PopupMedia) : this( | ||
title = media.title, | ||
caption = media.caption, | ||
refreshInterval = media.imageRefreshInterval, | ||
linkUrl = media.value?.linkUrl ?: "", | ||
sourceUrl = media.value?.sourceUrl ?: "", | ||
type = media.type | ||
) | ||
} |
95 changes: 95 additions & 0 deletions
95
...up/src/main/java/com/arcgismaps/toolkit/popup/internal/element/media/MediaPopupElement.kt
This file contains hidden or 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,95 @@ | ||
/* | ||
* Copyright 2024 Esri | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.arcgismaps.toolkit.popup.internal.element.media | ||
|
||
import androidx.compose.foundation.layout.Arrangement | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.foundation.lazy.LazyListState | ||
import androidx.compose.foundation.lazy.LazyRow | ||
import androidx.compose.foundation.lazy.items | ||
import androidx.compose.foundation.lazy.rememberLazyListState | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.tooling.preview.Preview | ||
import androidx.compose.ui.unit.dp | ||
import com.arcgismaps.mapping.popup.PopupMediaType | ||
import com.arcgismaps.toolkit.popup.internal.ui.ExpandableCard | ||
|
||
@Composable | ||
internal fun MediaPopupElement( | ||
state: MediaElementState | ||
) { | ||
MediaPopupElement( | ||
title = state.title, | ||
description = state.description, | ||
stateId = state.id, | ||
media = state.media | ||
) | ||
} | ||
|
||
@Composable | ||
private fun MediaPopupElement( | ||
description: String, | ||
title: String, | ||
@Suppress("UNUSED_PARAMETER") stateId: Int, | ||
media: List<PopupMediaState> | ||
) { | ||
ExpandableCard( | ||
title = title, | ||
description = description | ||
) { | ||
Column( | ||
modifier = Modifier.padding(MediaElementDefaults.shapes().galleryPadding) | ||
) { | ||
val listState = rememberLazyListState() | ||
MediaGallery(listState, media) | ||
} | ||
} | ||
} | ||
|
||
@Composable | ||
private fun MediaGallery(state: LazyListState, media: List<PopupMediaState>) { | ||
LazyRow( | ||
state = state, | ||
horizontalArrangement = Arrangement.spacedBy(15.dp), | ||
) { | ||
items(media, key = { it.title + it.type + it.caption }) { | ||
MediaTile(it) | ||
} | ||
} | ||
} | ||
|
||
@Preview | ||
@Composable | ||
private fun MediaPopupElementPreview() { | ||
MediaPopupElement( | ||
title = "Media", | ||
description = "description of Media", | ||
stateId = 1, | ||
media = listOf( | ||
PopupMediaState( | ||
"Photo 1.jpg", | ||
"caption", | ||
1234L, | ||
linkUrl = "", | ||
sourceUrl = "https://i.postimg.cc/65yws9mR/Screenshot-2024-02-02-at-6-20-49-PM.png", | ||
PopupMediaType.Image, | ||
) | ||
) | ||
) | ||
} |
Oops, something went wrong.
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.