Created
May 16, 2021 16:24
-
-
Save pauloaapereira/f623b0ae3974d24050afdd611293bea7 to your computer and use it in GitHub Desktop.
Android SOLID Error Handling
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ErrorFragment : Fragment() { | |
private var _binding: FragmentErrorBinding? = null | |
private val binding get() = _binding!! | |
companion object { | |
private const val ERROR_KEY = "errorKey" | |
fun newError(error: ErrorView): ErrorFragment { | |
return ErrorFragment().apply { | |
arguments = Bundle().apply { | |
putParcelable(ERROR_KEY, error) | |
} | |
} | |
} | |
} | |
private val error: ErrorView? by lazy { arguments?.getParcelable(ERROR_KEY) } | |
override fun onCreateView( | |
inflater: LayoutInflater, | |
container: ViewGroup?, | |
savedInstanceState: Bundle? | |
): View { | |
_binding = FragmentErrorBinding.inflate(inflater, container, false) | |
return binding.root | |
} | |
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | |
super.onViewCreated(view, savedInstanceState) | |
error?.setupView(binding) | |
} | |
override fun onDestroyView() { | |
super.onDestroyView() | |
_binding = null | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment