1 package com.android.onboarding.contracts.fragment 2 3 import android.os.Bundle 4 import android.support.v4.app.Fragment 5 6 /** 7 * This abstract class allows setting and getting the input argument from the subclass of fragment. 8 * When extending this abstract class, you must declare a single argument type and implement the 9 * [performExtractArguments] and [performSetArguments] methods. 10 * 11 * When using the fragment, [setTypedArguments] and [getTypedArguments] should be used in place of 12 * [setArguments] and [getArguments]. 13 * 14 * @param <I> The type of the input argument. 15 */ 16 abstract class OnboardingFragment<I> : Fragment() { 17 18 /** 19 * Supplies the construction arguments for this fragment. 20 * 21 * @param argument The argument Bundle. 22 */ 23 @Deprecated("Use setTypedArguments() instead") setArgumentsnull24 final override fun setArguments(args: Bundle?) { 25 super.setArguments(args) 26 } 27 28 /** 29 * Sets the typed argument that is given by the onboarding contract. 30 * 31 * @param argument The typed argument. 32 */ setTypedArgumentsnull33 fun setTypedArguments(argument: I) { 34 setArguments(performSetArguments(argument)) 35 } 36 37 /** 38 * Gets the typed argument that is given by the onboarding contract. 39 * 40 * @return The typed argument. 41 */ getTypedArgumentsnull42 fun getTypedArguments(): I? { 43 return performExtractArguments(getArguments()) 44 } 45 46 /** 47 * Performs the setting of the typed argument of the onboarding contract. 48 * 49 * @param args The typed argument that would be set in the bundle of fragment argument. 50 * @return The bundle. 51 */ performSetArgumentsnull52 protected abstract fun performSetArguments(args: I): Bundle 53 54 /** 55 * Performs the extraction of the typed argument of the onboarding contract. 56 * 57 * @param args The bundle that can be available from getArguments(). 58 * @return The typed argument that would be extracted from the bundle of fragment argument. 59 */ 60 protected abstract fun performExtractArguments(args: Bundle?): I? 61 } 62