Alejandro Nijamkin | 0f02b08 | 2022-11-24 13:43:43 -0800 | [diff] [blame] | 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 | */ |
| 17 | |
Alejandro Nijamkin | abda67b | 2022-11-30 14:34:56 -0800 | [diff] [blame] | 18 | package com.android.customization.picker.quickaffordance.ui.fragment |
Alejandro Nijamkin | 0f02b08 | 2022-11-24 13:43:43 -0800 | [diff] [blame] | 19 | |
Alejandro Nijamkin | 573aae8 | 2022-12-02 08:41:09 -0800 | [diff] [blame] | 20 | import android.os.Bundle |
| 21 | import android.view.LayoutInflater |
| 22 | import android.view.View |
| 23 | import android.view.ViewGroup |
| 24 | import androidx.lifecycle.ViewModelProvider |
| 25 | import androidx.lifecycle.get |
| 26 | import com.android.customization.module.ThemePickerInjector |
| 27 | import com.android.customization.picker.quickaffordance.ui.binder.KeyguardQuickAffordancePickerBinder |
Alejandro Nijamkin | 5ec382d | 2022-12-06 16:43:36 -0800 | [diff] [blame] | 28 | import com.android.customization.picker.quickaffordance.ui.binder.KeyguardQuickAffordancePreviewBinder |
| 29 | import com.android.customization.picker.quickaffordance.ui.viewmodel.KeyguardQuickAffordancePickerViewModel |
Alejandro Nijamkin | 573aae8 | 2022-12-02 08:41:09 -0800 | [diff] [blame] | 30 | import com.android.wallpaper.R |
| 31 | import com.android.wallpaper.module.InjectorProvider |
Alejandro Nijamkin | abda67b | 2022-11-30 14:34:56 -0800 | [diff] [blame] | 32 | import com.android.wallpaper.picker.AppbarFragment |
Alejandro Nijamkin | c27b1d3 | 2022-12-21 15:27:35 -0800 | [diff] [blame] | 33 | import com.android.wallpaper.picker.undo.ui.binder.RevertToolbarButtonBinder |
Alejandro Nijamkin | 5ec382d | 2022-12-06 16:43:36 -0800 | [diff] [blame] | 34 | import kotlinx.coroutines.ExperimentalCoroutinesApi |
Alejandro Nijamkin | abda67b | 2022-11-30 14:34:56 -0800 | [diff] [blame] | 35 | |
Alejandro Nijamkin | 5ec382d | 2022-12-06 16:43:36 -0800 | [diff] [blame] | 36 | @OptIn(ExperimentalCoroutinesApi::class) |
Alejandro Nijamkin | abda67b | 2022-11-30 14:34:56 -0800 | [diff] [blame] | 37 | class KeyguardQuickAffordancePickerFragment : AppbarFragment() { |
| 38 | companion object { |
Alejandro Nijamkin | 839e75c | 2022-12-02 15:50:52 -0800 | [diff] [blame] | 39 | const val DESTINATION_ID = "quick_affordances" |
| 40 | @JvmStatic |
Alejandro Nijamkin | abda67b | 2022-11-30 14:34:56 -0800 | [diff] [blame] | 41 | fun newInstance(): KeyguardQuickAffordancePickerFragment { |
| 42 | return KeyguardQuickAffordancePickerFragment() |
| 43 | } |
| 44 | } |
| 45 | |
Alejandro Nijamkin | 573aae8 | 2022-12-02 08:41:09 -0800 | [diff] [blame] | 46 | 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 Nijamkin | 5ec382d | 2022-12-06 16:43:36 -0800 | [diff] [blame] | 59 | val viewModel: KeyguardQuickAffordancePickerViewModel = |
| 60 | ViewModelProvider( |
| 61 | requireActivity(), |
| 62 | injector.getKeyguardQuickAffordancePickerViewModelFactory(requireContext()), |
| 63 | ) |
| 64 | .get() |
Alejandro Nijamkin | c27b1d3 | 2022-12-21 15:27:35 -0800 | [diff] [blame] | 65 | setUpToolbarMenu(R.menu.undoable_customization_menu) |
| 66 | RevertToolbarButtonBinder.bind( |
| 67 | view = view.requireViewById(toolbarId), |
| 68 | viewModel = viewModel.undo, |
| 69 | lifecycleOwner = this, |
| 70 | ) |
| 71 | |
Alejandro Nijamkin | 5ec382d | 2022-12-06 16:43:36 -0800 | [diff] [blame] | 72 | KeyguardQuickAffordancePreviewBinder.bind( |
| 73 | activity = requireActivity(), |
| 74 | previewView = view.requireViewById(R.id.preview), |
| 75 | viewModel = viewModel, |
| 76 | lifecycleOwner = this, |
Alejandro Nijamkin | 5ec382d | 2022-12-06 16:43:36 -0800 | [diff] [blame] | 77 | ) |
Alejandro Nijamkin | 573aae8 | 2022-12-02 08:41:09 -0800 | [diff] [blame] | 78 | KeyguardQuickAffordancePickerBinder.bind( |
| 79 | view = view, |
Alejandro Nijamkin | 5ec382d | 2022-12-06 16:43:36 -0800 | [diff] [blame] | 80 | viewModel = viewModel, |
Alejandro Nijamkin | 573aae8 | 2022-12-02 08:41:09 -0800 | [diff] [blame] | 81 | 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 Nijamkin | abda67b | 2022-11-30 14:34:56 -0800 | [diff] [blame] | 89 | } |