1 /*
2  * 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 package com.android.wallpaper.widget.floatingsheetcontent
17 
18 import android.content.Context
19 import android.net.Uri
20 import com.android.wallpaper.R
21 import com.android.wallpaper.model.WallpaperAction
22 import java.util.Arrays
23 
24 /** This class provides the bottom sheet content for the effects/ sparkle button. */
25 class WallpaperActionSelectionBottomSheetContent(
26     private val context: Context,
27     private val sectionTitle: String?,
28     private val sectionSubtitle: String?,
29     private val clearActionsUri: Uri?,
30     private val wallpaperActions: List<WallpaperAction>?,
31     private var currentlyAppliedEffectId: String?,
32     private var wallpaperEffectSwitchListener:
33         WallpaperActionsToggleAdapter.WallpaperEffectSwitchListener
34 ) : FloatingSheetContent<WallpaperActionSelectionBottomSheet>(context) {
35     private lateinit var wallpaperActionSelectionBottomSheetView:
36         WallpaperActionSelectionBottomSheet
37     override val viewId: Int
38         get() = R.layout.wallpaper_action_selection_bottom_sheet
39 
onViewCreatednull40     override fun onViewCreated(view: WallpaperActionSelectionBottomSheet) {
41         wallpaperActionSelectionBottomSheetView = view
42         if (
43             wallpaperActions == null ||
44                 clearActionsUri == null ||
45                 sectionSubtitle == null ||
46                 sectionTitle == null
47         ) {
48             return
49         }
50 
51         // Initialize the selected toggle.
52         wallpaperActions.forEach {
53             if (currentlyAppliedEffectId == it.effectId) {
54                 it.toggled = true
55             }
56         }
57         wallpaperActionSelectionBottomSheetView.setUpActionToggleOptions(
58             WallpaperActionsToggleAdapter(
59                 // TODO(b/270729418): enable multiple effect options once final design is
60                 //  agreed upon.
61                 // Forcing only one effect item for now
62                 Arrays.asList(wallpaperActions.get(0)),
63                 wallpaperEffectSwitchListener
64             )
65         )
66         wallpaperActionSelectionBottomSheetView.setBottomSheetTitle(sectionTitle)
67         wallpaperActionSelectionBottomSheetView.setBottomSheetSubtitle(sectionSubtitle)
68     }
69 
setCurrentlyAppliedEffectnull70     fun setCurrentlyAppliedEffect(selectedCredential: String?) {
71         currentlyAppliedEffectId = selectedCredential
72     }
73 }
74