blob: d2245db1bc364987e6570f419bc809fbd69b5eb2 [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
Alejandro Nijamkinabda67b2022-11-30 14:34:56 -080035
Alejandro Nijamkin5ec382d2022-12-06 16:43:36 -080036@OptIn(ExperimentalCoroutinesApi::class)
Alejandro Nijamkinabda67b2022-11-30 14:34:56 -080037class KeyguardQuickAffordancePickerFragment : AppbarFragment() {
38 companion object {
Alejandro Nijamkin839e75c2022-12-02 15:50:52 -080039 const val DESTINATION_ID = "quick_affordances"
40 @JvmStatic
Alejandro Nijamkinabda67b2022-11-30 14:34:56 -080041 fun newInstance(): KeyguardQuickAffordancePickerFragment {
42 return KeyguardQuickAffordancePickerFragment()
43 }
44 }
45
Alejandro Nijamkin573aae82022-12-02 08:41:09 -080046 override fun onCreateView(
47 inflater: LayoutInflater,
48 container: ViewGroup?,
49 savedInstanceState: Bundle?
50 ): View {
51 val view =
52 inflater.inflate(
53 R.layout.fragment_lock_screen_quick_affordances,
54 container,
55 false,
56 )
57 setUpToolbar(view)
58 val injector = InjectorProvider.getInjector() as ThemePickerInjector
Alejandro Nijamkin5ec382d2022-12-06 16:43:36 -080059 val viewModel: KeyguardQuickAffordancePickerViewModel =
60 ViewModelProvider(
61 requireActivity(),
62 injector.getKeyguardQuickAffordancePickerViewModelFactory(requireContext()),
63 )
64 .get()
Alejandro Nijamkinc27b1d32022-12-21 15:27:35 -080065 setUpToolbarMenu(R.menu.undoable_customization_menu)
66 RevertToolbarButtonBinder.bind(
67 view = view.requireViewById(toolbarId),
68 viewModel = viewModel.undo,
69 lifecycleOwner = this,
70 )
71
Alejandro Nijamkin5ec382d2022-12-06 16:43:36 -080072 KeyguardQuickAffordancePreviewBinder.bind(
73 activity = requireActivity(),
74 previewView = view.requireViewById(R.id.preview),
75 viewModel = viewModel,
76 lifecycleOwner = this,
Alejandro Nijamkin5ec382d2022-12-06 16:43:36 -080077 )
Alejandro Nijamkin573aae82022-12-02 08:41:09 -080078 KeyguardQuickAffordancePickerBinder.bind(
79 view = view,
Alejandro Nijamkin5ec382d2022-12-06 16:43:36 -080080 viewModel = viewModel,
Alejandro Nijamkin573aae82022-12-02 08:41:09 -080081 lifecycleOwner = this,
82 )
83 return view
84 }
85
86 override fun getDefaultTitle(): CharSequence {
87 return requireContext().getString(R.string.keyguard_quick_affordance_title)
88 }
Alejandro Nijamkinabda67b2022-11-30 14:34:56 -080089}