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.picker.preview.ui.fragment 17 18 import android.os.Bundle 19 import android.view.LayoutInflater 20 import android.view.View 21 import android.view.ViewGroup 22 import androidx.core.content.ContextCompat 23 import androidx.fragment.app.activityViewModels 24 import androidx.navigation.fragment.findNavController 25 import com.android.wallpaper.R 26 import com.android.wallpaper.module.CustomizationSections 27 import com.android.wallpaper.module.InjectorProvider 28 import com.android.wallpaper.picker.AppbarFragment 29 import com.android.wallpaper.picker.customization.ui.binder.ScreenPreviewBinder 30 import com.android.wallpaper.picker.customization.ui.viewmodel.ScreenPreviewViewModel 31 import com.android.wallpaper.picker.preview.ui.viewmodel.WallpaperPreviewViewModel 32 import com.android.wallpaper.util.PreviewUtils 33 import dagger.hilt.android.AndroidEntryPoint 34 35 /** 36 * This fragment displays the preview of the selected wallpaper on all available workspaces and 37 * device displays. 38 */ 39 @AndroidEntryPoint(AppbarFragment::class) 40 class SmallPreviewFragment : Hilt_SmallPreviewFragment() { 41 private val wallpaperPreviewViewModel by activityViewModels<WallpaperPreviewViewModel>() 42 onCreateViewnull43 override fun onCreateView( 44 inflater: LayoutInflater, 45 container: ViewGroup?, 46 savedInstanceState: Bundle? 47 ): View { 48 val view = 49 inflater.inflate(R.layout.fragment_small_preview, container, /* attachToRoot= */ false) 50 setUpToolbar(view) 51 bindScreenPreview(view) 52 53 return view 54 } 55 56 // TODO(b/291761856): Use real string getDefaultTitlenull57 override fun getDefaultTitle(): CharSequence { 58 return "Small Preview" 59 } 60 getToolbarColorIdnull61 override fun getToolbarColorId(): Int { 62 return android.R.color.transparent 63 } 64 getToolbarTextColornull65 override fun getToolbarTextColor(): Int { 66 return ContextCompat.getColor(requireContext(), R.color.system_on_surface) 67 } 68 69 // TODO(b/291761856): Replace placeholder preview bindScreenPreviewnull70 private fun bindScreenPreview(view: View) { 71 ScreenPreviewBinder.bind( 72 activity = requireActivity(), 73 previewView = view.requireViewById(R.id.preview), 74 viewModel = 75 ScreenPreviewViewModel( 76 previewUtils = 77 PreviewUtils( 78 context = requireContext(), 79 authorityMetadataKey = 80 requireContext() 81 .getString( 82 R.string.grid_control_metadata_name, 83 ), 84 ), 85 wallpaperInfoProvider = { wallpaperPreviewViewModel.editingWallpaper }, 86 wallpaperInteractor = 87 InjectorProvider.getInjector().getWallpaperInteractor(requireContext()), 88 screen = CustomizationSections.Screen.HOME_SCREEN, 89 onPreviewClicked = { 90 findNavController() 91 .navigate(R.id.action_smallPreviewFragment_to_fullPreviewFragment) 92 } 93 ), 94 lifecycleOwner = viewLifecycleOwner, 95 offsetToStart = false, 96 onWallpaperPreviewDirty = { activity?.recreate() }, 97 ) 98 } 99 } 100