From 0b9297097a87ff51e51193911f64c33b72cb44fd Mon Sep 17 00:00:00 2001 From: Anv0l Date: Sat, 26 Apr 2025 15:04:40 +0300 Subject: [PATCH 1/5] =?UTF-8?q?=D0=A1=D0=B4=D0=B5=D0=BB=D0=B0=D0=BB=20?= =?UTF-8?q?=D0=B7=D0=B0=D0=B4=D0=B0=D0=BD=D0=B8=D0=B5=20=E2=84=961?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/build.gradle | 26 +++---- .../java/otus/gpb/homework/fragments/Const.kt | 6 ++ .../otus/gpb/homework/fragments/FragmentA.kt | 72 +++++++++++++++++++ .../otus/gpb/homework/fragments/FragmentAA.kt | 27 +++++++ .../otus/gpb/homework/fragments/FragmentB.kt | 19 +++++ .../gpb/homework/fragments/MainActivity.kt | 26 +++++++ app/src/main/res/layout/activity_main.xml | 40 +++++++++-- app/src/main/res/layout/fragment_a.xml | 38 ++++++++++ app/src/main/res/layout/fragment_aa.xml | 19 +++++ app/src/main/res/layout/fragment_ab.xml | 6 ++ app/src/main/res/layout/fragment_b.xml | 17 +++++ 11 files changed, 280 insertions(+), 16 deletions(-) create mode 100644 app/src/main/java/otus/gpb/homework/fragments/Const.kt create mode 100644 app/src/main/java/otus/gpb/homework/fragments/FragmentA.kt create mode 100644 app/src/main/java/otus/gpb/homework/fragments/FragmentAA.kt create mode 100644 app/src/main/java/otus/gpb/homework/fragments/FragmentB.kt create mode 100644 app/src/main/res/layout/fragment_a.xml create mode 100644 app/src/main/res/layout/fragment_aa.xml create mode 100644 app/src/main/res/layout/fragment_ab.xml create mode 100644 app/src/main/res/layout/fragment_b.xml diff --git a/app/build.gradle b/app/build.gradle index c5cf1b8..66b055d 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -4,17 +4,17 @@ plugins { } kotlin { - jvmToolchain(17) + jvmToolchain(20) } android { - compileSdk 34 + compileSdk 35 namespace "otus.gpb.homework.fragments" defaultConfig { applicationId "otus.gpb.homework.fragments" minSdk 26 - targetSdk 34 + targetSdk 35 versionCode 1 versionName "1.0" @@ -28,21 +28,23 @@ android { } } compileOptions { - sourceCompatibility JavaVersion.VERSION_17 - targetCompatibility JavaVersion.VERSION_17 + sourceCompatibility JavaVersion.VERSION_20 + targetCompatibility JavaVersion.VERSION_20 } kotlinOptions { - jvmTarget = '17' + jvmTarget = '20' } } dependencies { - implementation 'androidx.core:core-ktx:1.7.0' - 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.core:core-ktx:1.16.0" + implementation 'androidx.appcompat:appcompat:1.7.0' + implementation 'com.google.android.material:material:1.12.0' + implementation 'androidx.constraintlayout:constraintlayout:2.2.1' + implementation "androidx.fragment:fragment-ktx:1.8.6" testImplementation 'junit:junit:4.13.2' - androidTestImplementation 'androidx.test.ext:junit:1.1.3' - androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' + androidTestImplementation 'androidx.test.ext:junit:1.2.1' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.6.1' + } \ No newline at end of file diff --git a/app/src/main/java/otus/gpb/homework/fragments/Const.kt b/app/src/main/java/otus/gpb/homework/fragments/Const.kt new file mode 100644 index 0000000..b128b32 --- /dev/null +++ b/app/src/main/java/otus/gpb/homework/fragments/Const.kt @@ -0,0 +1,6 @@ +package otus.gpb.homework.fragments + +const val RESULT_KEY_A = "key_color_a" +const val RESULT_KEY_A_A = "key_color_a_a" +const val RESUlT_BUNDLE = "bundle" + 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..22cd9c9 --- /dev/null +++ b/app/src/main/java/otus/gpb/homework/fragments/FragmentA.kt @@ -0,0 +1,72 @@ +package otus.gpb.homework.fragments + +import android.content.Context +import android.os.Bundle +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.Button +import androidx.activity.OnBackPressedCallback +import androidx.core.os.bundleOf +import androidx.fragment.app.Fragment +import androidx.fragment.app.FragmentManager +import androidx.fragment.app.setFragmentResultListener + +class FragmentA : Fragment() { + + override fun onAttach(context: Context) { + super.onAttach(context) + + val callback = object : OnBackPressedCallback(true) { + override fun handleOnBackPressed() { + if (childFragmentManager.backStackEntryCount > 0) { + childFragmentManager.popBackStack() + } else { + isEnabled = false + @Suppress("DEPRECATION") + requireActivity().onBackPressed() + } + } + } + + requireActivity().onBackPressedDispatcher.addCallback(callback) + } + + override fun onCreateView( + inflater: LayoutInflater, + container: ViewGroup?, + savedInstanceState: Bundle? + ): View? { + return inflater.inflate(R.layout.fragment_a, container, false) + } + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + + view.findViewById