1 /*
<lambda>null2  * Copyright (C) 2023 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 @file:JvmName("JavaFlowHelper")
18 
19 package com.android.intentresolver.contentpreview
20 
21 import com.android.intentresolver.widget.ScrollableImagePreviewView.Preview
22 import java.util.function.Consumer
23 import kotlinx.coroutines.CoroutineScope
24 import kotlinx.coroutines.flow.Flow
25 import kotlinx.coroutines.flow.filter
26 import kotlinx.coroutines.flow.map
27 import kotlinx.coroutines.flow.toList
28 import kotlinx.coroutines.launch
29 
30 internal fun mapFileIntoToPreview(
31     flow: Flow<FileInfo>,
32     typeClassifier: MimeTypeClassifier,
33     editAction: Runnable?
34 ): Flow<Preview> =
35     flow
36         .filter { it.previewUri != null }
fileInfonull37         .map { fileInfo ->
38             Preview(
39                 ContentPreviewUi.getPreviewType(typeClassifier, fileInfo.mimeType),
40                 requireNotNull(fileInfo.previewUri),
41                 editAction
42             )
43         }
44 
collectToListnull45 internal fun <T> collectToList(
46     clientScope: CoroutineScope,
47     flow: Flow<T>,
48     callback: Consumer<List<T>>
49 ) {
50     clientScope.launch { callback.accept(flow.toList()) }
51 }
52