1 /*
2  * Copyright (C) 2022 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 android.view.View
21 import androidx.lifecycle.LiveData
22 import androidx.slice.Slice
23 import androidx.slice.widget.SliceLiveData
24 import androidx.slice.widget.SliceView
25 import com.android.wallpaper.R
26 
27 class PreviewCustomizeSettingsContent(
28     private val context: Context,
29     private val uriSettingsSlice: Uri?
30 ) : FloatingSheetContent<View>(context) {
31 
32     private lateinit var settingsSliceView: SliceView
33     private var settingsLiveData: LiveData<Slice>? = null
34     override val viewId: Int
35         get() = R.layout.preview_customize_settings
36 
onViewCreatednull37     override fun onViewCreated(previewPage: View) {
38         settingsSliceView = previewPage.requireViewById(R.id.settings_slice)
39         settingsSliceView.mode = SliceView.MODE_LARGE
40         settingsSliceView.isScrollable = false
41         if (uriSettingsSlice != null) {
42             settingsLiveData = SliceLiveData.fromUri(context, uriSettingsSlice)
43         }
44         settingsLiveData?.observeForever(settingsSliceView)
45     }
46 
onRecreateViewnull47     override fun onRecreateView(oldPreviewPage: View) {
48         if (settingsLiveData != null && settingsLiveData!!.hasObservers()) {
49             settingsLiveData!!.removeObserver(settingsSliceView)
50         }
51     }
52 }
53