Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- abstract class DecorableFragment: Fragment() {
- private lateinit var topContent: LinearLayout
- private lateinit var content: LinearLayout
- private lateinit var bottomContent: LinearLayout
- override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
- val view = inflater.inflate(R.layout.fragment_decorable, container, false)
- topContent = view.findViewById(R.id.fragment_decorable_top_content)
- content = view.findViewById(R.id.fragment_decorable_content)
- bottomContent = view.findViewById(R.id.fragment_decorable_bottom_content)
- onCreateContent(inflater, content, savedInstanceState)
- onCreateDecoration(DecorationInstaller(topContent), DecorationInstaller(bottomContent), savedInstanceState)
- return view
- }
- open fun onCreateContent(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?) {
- }
- open fun onCreateDecoration(
- topInstaller: DecorationInstaller,
- bottomInstaller: DecorationInstaller,
- savedInstanceState: Bundle?
- ) {
- }
- class DecorationInstaller (private val container: ViewGroup) {
- private fun ViewGroup.addDecoration(decoration: Decoration): View {
- if(!decoration.initialized) {
- decoration.create(LayoutInflater.from(context), this)
- }
- addView(decoration.decorationView)
- return decoration.decorationView!!
- }
- fun add(decoration: Decoration): View {
- return container.addDecoration(decoration)
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement