blob: f37b246df8e51ef70be4628948a4c321054f9fd9 [file] [log] [blame]
Alejandro Nijamkin0f02b082022-11-24 13:43:43 -08001/*
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 */
17
Alejandro Nijamkinabda67b2022-11-30 14:34:56 -080018package com.android.customization.picker.quickaffordance.ui.fragment
Alejandro Nijamkin0f02b082022-11-24 13:43:43 -080019
Alejandro Nijamkin573aae82022-12-02 08:41:09 -080020import android.os.Bundle
21import android.view.LayoutInflater
22import android.view.View
23import android.view.ViewGroup
24import androidx.lifecycle.ViewModelProvider
25import androidx.lifecycle.get
26import com.android.customization.module.ThemePickerInjector
27import com.android.customization.picker.quickaffordance.ui.binder.KeyguardQuickAffordancePickerBinder
Alejandro Nijamkin5ec382d2022-12-06 16:43:36 -080028import com.android.customization.picker.quickaffordance.ui.binder.KeyguardQuickAffordancePreviewBinder
29import com.android.customization.picker.quickaffordance.ui.viewmodel.KeyguardQuickAffordancePickerViewModel
Alejandro Nijamkin573aae82022-12-02 08:41:09 -080030import com.android.wallpaper.R
31import com.android.wallpaper.module.InjectorProvider
Alejandro Nijamkinabda67b2022-11-30 14:34:56 -080032import com.android.wallpaper.picker.AppbarFragment
Alejandro Nijamkinc27b1d32022-12-21 15:27:35 -080033import com.android.wallpaper.picker.undo.ui.binder.RevertToolbarButtonBinder
Alejandro Nijamkin5ec382d2022-12-06 16:43:36 -080034import kotlinx.coroutines.ExperimentalCoroutinesApi
35import kotlinx.coroutines.suspendCancellableCoroutine
Alejandro Nijamkinabda67b2022-11-30 14:34:56 -080036
Alejandro Nijamkin5ec382d2022-12-06 16:43:36 -080037@OptIn(ExperimentalCoroutinesApi::class)
Alejandro Nijamkinabda67b2022-11-30 14:34:56 -080038class KeyguardQuickAffordancePickerFragment : AppbarFragment() {
39 companion object {
Alejandro Nijamkin839e75c2022-12-02 15:50:52 -080040 const val DESTINATION_ID = "quick_affordances"
41 @JvmStatic
Alejandro Nijamkinabda67b2022-11-30 14:34:56 -080042 fun newInstance(): KeyguardQuickAffordancePickerFragment {
43 return KeyguardQuickAffordancePickerFragment()
44 }
45 }
46
Alejandro Nijamkin573aae82022-12-02 08:41:09 -080047 override fun onCreateView(
48 inflater: LayoutInflater,
49 container: ViewGroup?,
50 savedInstanceState: Bundle?
51 ): View {
52 val view =
53 inflater.inflate(
54 R.layout.fragment_lock_screen_quick_affordances,
55 container,
56 false,
57 )
58 setUpToolbar(view)
59 val injector = InjectorProvider.getInjector() as ThemePickerInjector
Alejandro Nijamkin5ec382d2022-12-06 16:43:36 -080060 val wallpaperInfoFactory = injector.getCurrentWallpaperInfoFactory(requireContext())
61 val viewModel: KeyguardQuickAffordancePickerViewModel =
62 ViewModelProvider(
63 requireActivity(),
64 injector.getKeyguardQuickAffordancePickerViewModelFactory(requireContext()),
65 )
66 .get()
Alejandro Nijamkinc27b1d32022-12-21 15:27:35 -080067 setUpToolbarMenu(R.menu.undoable_customization_menu)
68 RevertToolbarButtonBinder.bind(
69 view = view.requireViewById(toolbarId),
70 viewModel = viewModel.undo,
71 lifecycleOwner = this,
72 )
73
Alejandro Nijamkin5ec382d2022-12-06 16:43:36 -080074 KeyguardQuickAffordancePreviewBinder.bind(
75 activity = requireActivity(),
76 previewView = view.requireViewById(R.id.preview),
77 viewModel = viewModel,
78 lifecycleOwner = this,
79 wallpaperInfoProvider = {
80 suspendCancellableCoroutine { continuation ->
81 wallpaperInfoFactory.createCurrentWallpaperInfos(
82 { homeWallpaper, lockWallpaper, _ ->
83 continuation.resume(lockWallpaper ?: homeWallpaper, null)
84 },
85 /* forceRefresh= */ true,
86 )
87 }
88 },
89 )
Alejandro Nijamkin573aae82022-12-02 08:41:09 -080090 KeyguardQuickAffordancePickerBinder.bind(
91 view = view,
Alejandro Nijamkin5ec382d2022-12-06 16:43:36 -080092 viewModel = viewModel,
Alejandro Nijamkin573aae82022-12-02 08:41:09 -080093 lifecycleOwner = this,
94 )
95 return view
96 }
97
98 override fun getDefaultTitle(): CharSequence {
99 return requireContext().getString(R.string.keyguard_quick_affordance_title)
100 }
Alejandro Nijamkinabda67b2022-11-30 14:34:56 -0800101}