diff --git a/app/build.gradle b/app/build.gradle index c5cf1b8..87b742e 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -42,7 +42,9 @@ dependencies { implementation 'androidx.appcompat:appcompat:1.5.1' implementation 'com.google.android.material:material:1.6.1' implementation 'androidx.constraintlayout:constraintlayout:2.1.4' + implementation 'androidx.activity:activity:1.8.0' testImplementation 'junit:junit:4.13.2' androidTestImplementation 'androidx.test.ext:junit:1.1.3' androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' + implementation 'com.google.android.material:material:1.12.0' } \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 9604b34..82cf206 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -12,6 +12,14 @@ android:supportsRtl="true" android:theme="@style/Theme.Fragments" tools:targetApi="31"> + + diff --git a/app/src/main/java/otus/gpb/homework/fragments/Activity1.kt b/app/src/main/java/otus/gpb/homework/fragments/Activity1.kt new file mode 100644 index 0000000..a2020b1 --- /dev/null +++ b/app/src/main/java/otus/gpb/homework/fragments/Activity1.kt @@ -0,0 +1,28 @@ +package otus.gpb.homework.fragments + +import android.os.Bundle +import androidx.activity.enableEdgeToEdge +import androidx.appcompat.app.AppCompatActivity +import androidx.core.view.ViewCompat +import androidx.core.view.WindowInsetsCompat + +class Activity1 : AppCompatActivity() { +// private lateinit var fragmentA: FragmentA + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + enableEdgeToEdge() + setContentView(R.layout.activity_1) + ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets -> + val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars()) + v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom) + insets + } + if (savedInstanceState == null) { + supportFragmentManager.beginTransaction() + .replace(R.id.fragment_container, FragmentA(), "FragmentA") + .addToBackStack(null) + .commit() + } + } +} \ No newline at end of file diff --git a/app/src/main/java/otus/gpb/homework/fragments/Activity2.kt b/app/src/main/java/otus/gpb/homework/fragments/Activity2.kt new file mode 100644 index 0000000..09fd7f2 --- /dev/null +++ b/app/src/main/java/otus/gpb/homework/fragments/Activity2.kt @@ -0,0 +1,40 @@ +package otus.gpb.homework.fragments + +import android.content.res.Configuration +import android.os.Bundle +import android.view.View +import android.widget.Button +import android.widget.LinearLayout +import androidx.activity.enableEdgeToEdge +import androidx.appcompat.app.AppCompatActivity +import androidx.core.view.ViewCompat +import androidx.core.view.WindowInsetsCompat + +class Activity2 : AppCompatActivity() { + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + enableEdgeToEdge() + setContentView(R.layout.activity_2) + ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets -> + val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars()) + v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom) + insets + } + if (savedInstanceState == null) { + supportFragmentManager.beginTransaction() + .replace(R.id.fragment_container, FragmentBA(), "FragmentBA") + .commit() + } + val orientation = resources.configuration.orientation + if (orientation == Configuration.ORIENTATION_PORTRAIT) { + val fc = findViewById(R.id.fragment_container2) + fc.visibility = View.GONE + } else if (orientation == Configuration.ORIENTATION_LANDSCAPE) { + if (savedInstanceState == null) { + supportFragmentManager.beginTransaction() + .replace(R.id.fragment_container2, FragmentBB(), "FragmentBB") + .commit() + } + } + } +} \ No newline at end of file diff --git a/app/src/main/java/otus/gpb/homework/fragments/FragmentA.kt b/app/src/main/java/otus/gpb/homework/fragments/FragmentA.kt new file mode 100644 index 0000000..4c25846 --- /dev/null +++ b/app/src/main/java/otus/gpb/homework/fragments/FragmentA.kt @@ -0,0 +1,47 @@ +package otus.gpb.homework.fragments + +import android.os.Bundle +import androidx.fragment.app.Fragment +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.Button + +/** + * A simple [Fragment] subclass. + * Use the [FragmentA.newInstance] factory method to + * create an instance of this fragment. + */ +class FragmentA : Fragment() { + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + } + + override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, + savedInstanceState: Bundle?): View? { + + // Inflate the layout for this fragment + return inflater.inflate(R.layout.fragment_a, container, false) + } + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + view.findViewById