// Copyright (C) 2025 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only

/*!
    \title Android Fragments with Qt Quick for Android
    \brief Tutorial on using Qt Quick Views in Android Fragments
    \page qtquick-for-android-fragments.html
    \ingroup qq4a-extra-topics

    You can have a \l QtQuickView in an Android UI layout by using a ViewGroup-based
    object. Here we'll use a
    \l{https://developer.android.com/reference/android/widget/FrameLayout}{FrameLayout}.

    If you're not familiar with the \l QtQuickView API, read its documentation
    before continuing with this tutorial.

    To start, create a new project in Android Studio using the
    \uicontrol{Bottom Navigation Views Activity} template.

    //!TODO add Qt Academy Link here when the course is published.

    \list 1
        \li Locate the Fragment or Activity under which you want your QtQuickView
        to be visible. Here we use \c HomeFragment and \c fragment_home.xml.

        \li In \c fragment_home.xml create a FrameLayout and set its \c id as
        shown below.
        \code
        <FrameLayout
        android:id="@+id/homeQmlFrame"
        android:layout_width="0dp"
        android:layout_height="0dp"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHeight_percent="0.8"/>
        \endcode
        Note this id, as it needed to be referred to in \c HomeFragment when
        binding the layout.

        \li Inside HomeFragment.kt, add an import statement for FrameLayout:
        \code
        import android.widget.FrameLayout
        \endcode

        \li Add your imports for your \l QtQuickView and Screen01 QML type
        and declare them inside the class:

        \code
        import org.qtproject.qt.android.QtQuickView
        import org.qtproject.example.RoboApp.RoboContent.Screen01

        class HomeFragment : Fragment() {

        private var binding: FragmentHomeBinding? = null
        private lateinit var homeQmlContent: Screen01
        private lateinit var homeQtQuickView: QtQuickView
        \endcode

        \li Inside the overloaded \c onCreateView() function:
            \list 1
                \li Assign your QtQuickView, giving it the Activity context using \c this.Activity
                \code
                homeQtQuickView = QtQuickView(this.activity)
                homeQmlContent = Screen01()
                \endcode
                \li Initialize the layout parameters with
                \l {https://developer.android.com/reference/android/widget/FrameLayout.LayoutParams}{FrameLayout.LayoutParams}
                \code
                val params = FrameLayout.LayoutParams(
                   ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)

                binding = FragmentHomeBinding.inflate(inflater, container, false)
                val root: View = binding.root
                \li Add it to the layout:
                \code
                binding.homeQmlFrame.addView(homeQtQuickView, params)
                \endcode
                \li Load your QML content:
                \code
                homeQtQuickView.loadContent(homeQmlContent)
                return root
                \endcode
            \endlist
    \endlist
    Your Qt Quick content will now appear in your home fragment.
*/
