1 /* <lambda>null2 * 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.content.Context 19 import android.os.Bundle 20 import android.view.LayoutInflater 21 import android.view.View 22 import android.view.ViewGroup 23 import androidx.cardview.widget.CardView 24 import androidx.core.content.ContextCompat 25 import androidx.core.view.ViewCompat 26 import androidx.fragment.app.activityViewModels 27 import androidx.navigation.fragment.findNavController 28 import androidx.transition.Transition 29 import com.android.wallpaper.R 30 import com.android.wallpaper.picker.AppbarFragment 31 import com.android.wallpaper.picker.preview.ui.binder.CropWallpaperButtonBinder 32 import com.android.wallpaper.picker.preview.ui.binder.FullWallpaperPreviewBinder 33 import com.android.wallpaper.picker.preview.ui.binder.PreviewTooltipBinder 34 import com.android.wallpaper.picker.preview.ui.binder.WorkspacePreviewBinder 35 import com.android.wallpaper.picker.preview.ui.transition.ChangeScaleAndPosition 36 import com.android.wallpaper.picker.preview.ui.util.AnimationUtil 37 import com.android.wallpaper.picker.preview.ui.viewmodel.WallpaperPreviewViewModel 38 import com.android.wallpaper.util.DisplayUtils 39 import dagger.hilt.android.AndroidEntryPoint 40 import dagger.hilt.android.qualifiers.ApplicationContext 41 import javax.inject.Inject 42 43 /** Shows full preview of user selected wallpaper for cropping, zooming and positioning. */ 44 @AndroidEntryPoint(AppbarFragment::class) 45 class FullPreviewFragment : Hilt_FullPreviewFragment() { 46 47 @Inject @ApplicationContext lateinit var appContext: Context 48 @Inject lateinit var displayUtils: DisplayUtils 49 50 private lateinit var currentView: View 51 52 private val wallpaperPreviewViewModel by activityViewModels<WallpaperPreviewViewModel>() 53 private var useLightToolbar = false 54 55 override fun onCreate(savedInstanceState: Bundle?) { 56 super.onCreate(savedInstanceState) 57 enterTransition = AnimationUtil.getFastFadeInTransition() 58 returnTransition = AnimationUtil.getFastFadeOutTransition() 59 sharedElementEnterTransition = ChangeScaleAndPosition() 60 } 61 62 override fun onCreateView( 63 inflater: LayoutInflater, 64 container: ViewGroup?, 65 savedInstanceState: Bundle? 66 ): View? { 67 currentView = inflater.inflate(R.layout.fragment_full_preview, container, false) 68 setUpToolbar(currentView, true, true) 69 70 val previewCard: CardView = currentView.requireViewById(R.id.preview_card) 71 ViewCompat.setTransitionName( 72 previewCard, 73 SmallPreviewFragment.FULL_PREVIEW_SHARED_ELEMENT_ID 74 ) 75 76 CropWallpaperButtonBinder.bind( 77 button = currentView.requireViewById(R.id.crop_wallpaper_button), 78 viewModel = wallpaperPreviewViewModel, 79 lifecycleOwner = viewLifecycleOwner, 80 ) { 81 findNavController().popBackStack() 82 } 83 84 WorkspacePreviewBinder.bindFullWorkspacePreview( 85 surface = currentView.requireViewById(R.id.workspace_surface), 86 viewModel = wallpaperPreviewViewModel, 87 lifecycleOwner = viewLifecycleOwner, 88 ) 89 90 PreviewTooltipBinder.bindFullPreviewTooltip( 91 tooltipStub = currentView.requireViewById(R.id.tooltip_stub), 92 viewModel = wallpaperPreviewViewModel.fullTooltipViewModel, 93 lifecycleOwner = viewLifecycleOwner, 94 ) 95 96 return currentView 97 } 98 99 override fun onViewStateRestored(savedInstanceState: Bundle?) { 100 super.onViewStateRestored(savedInstanceState) 101 var isFirstBinding = false 102 if (savedInstanceState == null) { 103 isFirstBinding = true 104 } 105 106 FullWallpaperPreviewBinder.bind( 107 applicationContext = appContext, 108 view = currentView, 109 viewModel = wallpaperPreviewViewModel, 110 transition = sharedElementEnterTransition as? Transition, 111 displayUtils = displayUtils, 112 lifecycleOwner = viewLifecycleOwner, 113 savedInstanceState = savedInstanceState, 114 isFirstBinding = isFirstBinding, 115 ) { isFullScreen -> 116 useLightToolbar = isFullScreen 117 setUpToolbar(view) 118 } 119 } 120 121 // TODO(b/291761856): Use real string 122 override fun getDefaultTitle(): CharSequence { 123 return "" 124 } 125 126 override fun getToolbarTextColor(): Int { 127 return if (useLightToolbar) { 128 ContextCompat.getColor(requireContext(), android.R.color.system_on_primary_light) 129 } else { 130 ContextCompat.getColor(requireContext(), R.color.system_on_surface) 131 } 132 } 133 134 override fun isStatusBarLightText(): Boolean { 135 return requireContext().resources.getBoolean(R.bool.isFragmentStatusBarLightText) or 136 useLightToolbar 137 } 138 } 139