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/ColorViewModel.kt b/app/src/main/java/otus/gpb/homework/fragments/ColorViewModel.kt new file mode 100644 index 0000000..100779e --- /dev/null +++ b/app/src/main/java/otus/gpb/homework/fragments/ColorViewModel.kt @@ -0,0 +1,14 @@ +package otus.gpb.homework.fragments + +import androidx.lifecycle.LiveData +import androidx.lifecycle.MutableLiveData +import androidx.lifecycle.ViewModel + +class ColorViewModel : ViewModel() { + private val _currentColor = MutableLiveData() + val currentColor: LiveData get() = _currentColor + + fun setColor(color: Int) { + _currentColor.value = color + } +} \ 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..634ef16 --- /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" \ 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..5b51b30 --- /dev/null +++ b/app/src/main/java/otus/gpb/homework/fragments/FragmentA.kt @@ -0,0 +1,63 @@ +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 + +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