1 /*
2 * Copyright 2024 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 package com.android.photopicker.features.cloudmedia
18
19 import android.content.Context
20 import android.content.Intent
21 import android.provider.MediaStore
22 import androidx.compose.material.icons.Icons
23 import androidx.compose.material.icons.outlined.Cloud
24 import androidx.compose.runtime.Composable
25 import androidx.compose.ui.graphics.vector.ImageVector
26 import androidx.compose.ui.res.stringResource
27 import com.android.photopicker.R
28 import com.android.photopicker.core.banners.Banner
29 import com.android.photopicker.core.banners.BannerDefinitions
30 import com.android.photopicker.data.model.CollectionInfo
31 import com.android.photopicker.data.model.Provider
32
33 /**
34 * A UI banner that shows the user a message asking them to set their CloudMediaProvider app and
35 * provides a secondary action that links to the [ACTION_PICK_IMAGES_SETTINGS] page.
36 */
37 val cloudChooseProviderBanner =
38 object : Banner {
39
40 override val declaration = BannerDefinitions.CLOUD_CHOOSE_PROVIDER
41
42 @Composable
buildTitlenull43 override fun buildTitle(): String {
44 return stringResource(R.string.photopicker_banner_cloud_choose_provider_title)
45 }
46
47 @Composable
buildMessagenull48 override fun buildMessage(): String {
49 return stringResource(R.string.photopicker_banner_cloud_choose_provider_message)
50 }
51
52 @Composable
getIconnull53 override fun getIcon(): ImageVector? {
54 return Icons.Outlined.Cloud
55 }
56
57 @Composable
actionLabelnull58 override fun actionLabel(): String? {
59 return stringResource(R.string.photopicker_banner_cloud_choose_app_button)
60 }
61
onActionnull62 override fun onAction(context: Context) {
63 context.startActivity(Intent(MediaStore.ACTION_PICK_IMAGES_SETTINGS))
64 }
65 }
66
67 /**
68 * Builder for the [BannerDefinitions.CLOUD_CHOOSE_ACCOUNT] banner that shows a secondary action
69 * that links to the active CloudMediaProvider's account configuration page.
70 *
71 * @param cloudProvider the [Provider] details of the active CloudMediaProvider.
72 * @param collectionInfo the associated [CollectionInfo] of the active collection with the active
73 * provider.
74 * @return The [Banner] to be displayed in the UI.
75 */
buildCloudChooseAccountBannernull76 fun buildCloudChooseAccountBanner(cloudProvider: Provider, collectionInfo: CollectionInfo): Banner {
77 return object : Banner {
78
79 override val declaration = BannerDefinitions.CLOUD_CHOOSE_ACCOUNT
80
81 @Composable
82 override fun buildTitle(): String {
83 return stringResource(R.string.photopicker_banner_cloud_choose_account_title)
84 }
85
86 @Composable
87 override fun buildMessage(): String {
88 return stringResource(
89 R.string.photopicker_banner_cloud_choose_account_message,
90 "${cloudProvider.displayName}",
91 )
92 }
93
94 @Composable
95 override fun getIcon(): ImageVector? {
96 return Icons.Outlined.Cloud
97 }
98
99 @Composable
100 override fun actionLabel(): String? {
101 return collectionInfo.accountConfigurationIntent?.let {
102 stringResource(R.string.photopicker_banner_cloud_choose_account_button)
103 }
104 }
105
106 override fun onAction(context: Context) {
107 collectionInfo.accountConfigurationIntent?.let { context.startActivity(it) }
108 }
109 }
110 }
111
112 /**
113 * Builder for a CloudMediaAvailable banner object that indicates to the user their backed up cloud
114 * media is available to be selected in the Photopicker.
115 *
116 * @param cloudProvider the [Provider] details of the active CloudMediaProvider.
117 * @param collectionInfo the associated [CollectionInfo] of the active collection with the active
118 * provider.
119 * @return The [Banner] to be displayed in the UI.
120 */
buildCloudMediaAvailableBannernull121 fun buildCloudMediaAvailableBanner(
122 cloudProvider: Provider,
123 collectionInfo: CollectionInfo
124 ): Banner {
125 return object : Banner {
126
127 override val declaration = BannerDefinitions.CLOUD_MEDIA_AVAILABLE
128
129 @Composable
130 override fun buildTitle(): String {
131 return stringResource(R.string.photopicker_banner_cloud_media_available_title)
132 }
133
134 @Composable
135 override fun buildMessage(): String {
136 return stringResource(
137 R.string.photopicker_banner_cloud_media_available_message,
138 "${cloudProvider.displayName}",
139 collectionInfo.accountName ?: ""
140 )
141 }
142
143 @Composable
144 override fun getIcon(): ImageVector? {
145 return Icons.Outlined.Cloud
146 }
147 }
148 }
149