Skip to content

Popup: Adds a file viewer for image attachments #455

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 33 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
4c9844b
File viewer working with FileState class
eri9000 May 28, 2024
2ec6713
adds ViewableFile implementation
eri9000 May 28, 2024
1d0eaa7
remove fileviewer
eri9000 May 28, 2024
964fcf6
remove fileviewer
eri9000 May 28, 2024
eb9f261
remove fileviewer
eri9000 May 28, 2024
c292e73
additional line
eri9000 May 28, 2024
8a56be6
Implement File viewer
eri9000 May 28, 2024
935bd01
remove unused import
eri9000 May 28, 2024
968725d
makes ViewableFile an interface
eri9000 May 30, 2024
19273e1
Merge branch 'Erick/ViewableFile_init' into Erick/FileViewer_Image
eri9000 May 30, 2024
642e10a
adds image file viewer
eri9000 May 31, 2024
28611bb
remove image zoom
eri9000 Jun 3, 2024
0c51d55
Adds image viewer to save and share files
eri9000 Jun 4, 2024
3705f76
update MIME type
eri9000 Jun 4, 2024
48f03f5
Merge branch 'feature-branches/popup' into Erick/FileViewer_Image
eri9000 Jun 4, 2024
c41ed0b
import
eri9000 Jun 4, 2024
1f0619f
doc
eri9000 Jun 4, 2024
e62f1ae
adds top app bar
eri9000 Jun 5, 2024
5ccfece
updates file viewer
eri9000 Jun 5, 2024
e217614
update colors
eri9000 Jun 5, 2024
cdc78f6
removes permission request
eri9000 Jun 5, 2024
d6f61d7
remove imports
eri9000 Jun 5, 2024
3def2c5
fixes the image content scale
eri9000 Jun 6, 2024
a3da7c7
makes saveToDevice a suspend function
eri9000 Jun 13, 2024
5275e6e
make share a suspend function
eri9000 Jun 13, 2024
237dcc3
passes the Popup scope to the file viewer
eri9000 Jun 13, 2024
e4ee006
moves file viewer under UI folder
eri9000 Jun 13, 2024
6a8cae3
remove context switching
eri9000 Jun 14, 2024
62062d3
make authority more unique
eri9000 Jun 17, 2024
8c5a66c
code comments
eri9000 Jun 17, 2024
c3e7834
localize strings
eri9000 Jun 17, 2024
10c1158
remove imageViewer file and use asyncimage directly
eri9000 Jun 17, 2024
493c76d
update desc
eri9000 Jun 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion toolkit/popup/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,15 @@

<!--suppress XmlUnusedNamespaceDeclaration -->
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<application>
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/files" />
</provider>
</application>
</manifest>
18 changes: 15 additions & 3 deletions toolkit/popup/src/main/java/com/arcgismaps/toolkit/popup/Popup.kt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import androidx.compose.runtime.Stable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
Expand Down Expand Up @@ -65,7 +66,8 @@ import com.arcgismaps.toolkit.popup.internal.element.state.mutablePopupElementSt
import com.arcgismaps.toolkit.popup.internal.element.textelement.TextElementState
import com.arcgismaps.toolkit.popup.internal.element.textelement.TextPopupElement
import com.arcgismaps.toolkit.popup.internal.element.textelement.rememberTextElementState
import com.arcgismaps.toolkit.popup.internal.fileviewer.ViewableFile
import com.arcgismaps.toolkit.popup.internal.ui.fileviewer.FileViewer
import com.arcgismaps.toolkit.popup.internal.ui.fileviewer.ViewableFile

@Immutable
private data class PopupState(@Stable val popup: Popup)
Expand Down Expand Up @@ -113,7 +115,14 @@ private fun Popup(popupState: PopupState, modifier: Modifier = Modifier) {

@Composable
private fun Popup(popupState: PopupState, evaluated: Boolean, modifier: Modifier = Modifier) {
val scope = rememberCoroutineScope()
val popup = popupState.popup
val viewableFileState = rememberSaveable { mutableStateOf<ViewableFile?>(null) }
viewableFileState.value?.let { viewableFile ->
FileViewer(scope, fileState = viewableFile) {
viewableFileState.value = null
}
}
Column(
modifier = modifier.fillMaxSize(),
horizontalAlignment = Alignment.CenterHorizontally
Expand All @@ -132,7 +141,9 @@ private fun Popup(popupState: PopupState, evaluated: Boolean, modifier: Modifier
}
HorizontalDivider(modifier = Modifier.fillMaxWidth(), thickness = 2.dp)
if (evaluated) {
PopupBody(popupState)
PopupBody(popupState) {
viewableFileState.value = it
}
}
}
}
Expand Down Expand Up @@ -161,7 +172,8 @@ private fun PopupBody(popupState: PopupState, onFileClicked: (ViewableFile?) ->
is AttachmentsPopupElement -> {
AttachmentsPopupElement(
state = entry.state as AttachmentsElementState,
onFileClicked)
onFileClicked
)
}

is FieldsPopupElement -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.arcgismaps.LoadStatus
import com.arcgismaps.mapping.popup.PopupAttachmentType
import com.arcgismaps.toolkit.popup.internal.fileviewer.ViewableFile
import com.arcgismaps.toolkit.popup.internal.ui.fileviewer.ViewableFile
import com.arcgismaps.toolkit.popup.internal.ui.fileviewer.toViewableFileType
import kotlinx.coroutines.flow.MutableStateFlow

@Composable
Expand All @@ -87,7 +88,15 @@ internal fun AttachmentTile(
// load attachment
state.loadAttachment(coroutineScope)
} else if (loadStatus is LoadStatus.Loaded) {
onClicked(state)
onClicked(
ViewableFile(
state.name,
state.size,
state.path,
state.popupAttachmentType.toViewableFileType(),
state.contentType
)
)
}
// TODO open attachment viewer in `else` here
}
Expand Down Expand Up @@ -274,6 +283,7 @@ internal fun PreviewAttachmentTile() {
size = 1234L,
popupAttachmentType = PopupAttachmentType.Other,
loadStatus = MutableStateFlow(LoadStatus.NotLoaded),
contentType = "image/jpeg",
onLoadAttachment = { Result.success(Unit) },
onLoadThumbnail = null
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,7 @@ import com.arcgismaps.mapping.popup.AttachmentsPopupElement
import com.arcgismaps.mapping.popup.Popup
import com.arcgismaps.mapping.popup.PopupAttachment
import com.arcgismaps.mapping.popup.PopupAttachmentType
import com.arcgismaps.toolkit.popup.internal.fileviewer.ViewableFile
import com.arcgismaps.toolkit.popup.internal.fileviewer.toViewableFileType
import com.arcgismaps.toolkit.popup.internal.element.state.PopupElementState
import com.arcgismaps.toolkit.popup.internal.fileviewer.ViewableFileImpl
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.launch
Expand Down Expand Up @@ -116,27 +113,29 @@ internal fun rememberAttachmentsElementState(
* @param onLoadThumbnail A function that loads the thumbnail of the attachment.
*/
internal class PopupAttachmentState(
name: String,
size: Long,
val name: String,
val size: Long,
val popupAttachmentType: PopupAttachmentType,
val contentType: String,
val loadStatus: StateFlow<LoadStatus>,
private val onLoadAttachment: suspend () -> Result<Unit>,
private val onLoadThumbnail: (suspend () -> Result<BitmapDrawable?>)? = null
) : ViewableFile by ViewableFileImpl(name, size, "", popupAttachmentType.toViewableFileType()) {
) {
private val _thumbnail: MutableState<ImageBitmap?> = mutableStateOf(null)
private lateinit var _attachment: PopupAttachment

/**
* The thumbnail of the attachment. This is `null` until [loadAttachment] is called.
*/
val thumbnail: State<ImageBitmap?> = _thumbnail
override val path: String
val path: String
get() = _attachment.filePath

constructor(attachment: PopupAttachment) : this(
name = attachment.name,
size = attachment.size,
popupAttachmentType = attachment.type,
contentType = attachment.contentType,
loadStatus = attachment.loadStatus,
onLoadAttachment = attachment::retryLoad,
onLoadThumbnail = if (attachment.type == PopupAttachmentType.Image) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.arcgismaps.LoadStatus
import com.arcgismaps.mapping.popup.PopupAttachmentType
import com.arcgismaps.toolkit.popup.internal.fileviewer.ViewableFile
import com.arcgismaps.toolkit.popup.internal.ui.fileviewer.ViewableFile
import com.arcgismaps.toolkit.popup.internal.ui.ExpandableCard
import kotlinx.coroutines.flow.MutableStateFlow

Expand Down Expand Up @@ -96,6 +96,7 @@ private fun AttachmentsPopupElementPreview() {
name = "Photo 1.jpg",
size = 2024,
PopupAttachmentType.Image,
contentType = "image/jpeg",
MutableStateFlow(LoadStatus.Loaded),
{ Result.success(Unit) },
{ Result.success(null) }
Expand Down

This file was deleted.

Loading