1 package com.example.android.bubbles.ui.photo 2 3 import android.os.Bundle 4 import android.transition.Fade 5 import android.view.LayoutInflater 6 import android.view.View 7 import android.view.ViewGroup 8 import android.widget.ImageView 9 import androidx.annotation.DrawableRes 10 import androidx.fragment.app.Fragment 11 import com.example.android.bubbles.R 12 import com.example.android.bubbles.getNavigationController 13 14 /** 15 * Shows the specified [DrawableRes] as a full-screen photo. 16 */ 17 class PhotoFragment : Fragment() { 18 19 companion object { 20 private const val ARG_PHOTO = "photo" 21 <lambda>null22 fun newInstance(@DrawableRes photo: Int) = PhotoFragment().apply { 23 arguments = Bundle().apply { 24 putInt(ARG_PHOTO, photo) 25 } 26 } 27 } 28 onCreatenull29 override fun onCreate(savedInstanceState: Bundle?) { 30 super.onCreate(savedInstanceState) 31 enterTransition = Fade() 32 } 33 onCreateViewnull34 override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { 35 return inflater.inflate(R.layout.photo_fragment, container, false) 36 } 37 onViewCreatednull38 override fun onViewCreated(view: View, savedInstanceState: Bundle?) { 39 val photoResId = arguments?.getInt(ARG_PHOTO) 40 if (photoResId == null) { 41 fragmentManager?.popBackStack() 42 return 43 } 44 getNavigationController().updateAppBar(hidden = true) 45 view.findViewById<ImageView>(R.id.photo).setImageResource(photoResId) 46 } 47 } 48