From 455320a33a2e953dfb10dd2830c6b78b83dedf50 Mon Sep 17 00:00:00 2001 From: Alexandr Kalevich Date: Mon, 25 Apr 2022 00:50:09 +0300 Subject: [PATCH 1/3] Git Test Linux 22.04 --- .idea/.gitignore | 3 + .idea/compiler.xml | 6 ++ .idea/gradle.xml | 19 ++++++ .idea/misc.xml | 18 ++++++ .idea/vcs.xml | 6 ++ app/build.gradle | 16 +++++ app/src/main/AndroidManifest.xml | 4 +- .../krottv/tmstemp/FullscreenFragment.kt | 36 +++++++++++ .../com/github/krottv/tmstemp/MainActivity.kt | 11 ---- .../github/krottv/tmstemp/RecyclerFragment.kt | 22 +++++++ .../tmstemp/binder/MainActivityDataBinder.kt | 5 ++ .../MainActivityRecyclerScrollDataBinder.kt | 60 +++++++++++++++++++ .../tmstemp/data/MessagesRemoteDataSource.kt | 7 +++ .../data/MessagesRemoteDataSourceError.kt | 12 ++++ .../data/MessagesRemoteDataSourceFake.kt | 21 +++++++ .../github/krottv/tmstemp/domain/Message.kt | 4 ++ .../tmstemp/presentation/MessageViewModel.kt | 31 ++++++++++ .../krottv/tmstemp/view/MainActivity.kt | 40 +++++++++++++ .../krottv/tmstemp/view/MessageAdapter.kt | 36 +++++++++++ .../krottv/tmstemp/view/MessageViewHolder.kt | 14 +++++ app/src/main/res/layout/activity_main.xml | 27 ++++----- .../main/res/layout/fullscreen_message.xml | 47 +++++++++++++++ app/src/main/res/layout/loading.xml | 16 +++++ app/src/main/res/layout/messages_fragment.xml | 22 +++++++ app/src/main/res/layout/recycler_cell.xml | 52 ++++++++++++++++ app/src/main/res/layout/recycler_view.xml | 37 ++++++++++++ app/src/main/res/layout/show_error.xml | 19 ++++++ app/src/main/res/navigation/nav_graph.xml | 23 +++++++ build.gradle | 11 ++++ 29 files changed, 597 insertions(+), 28 deletions(-) create mode 100644 .idea/.gitignore create mode 100644 .idea/compiler.xml create mode 100644 .idea/gradle.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/vcs.xml create mode 100644 app/src/main/java/com/github/krottv/tmstemp/FullscreenFragment.kt delete mode 100644 app/src/main/java/com/github/krottv/tmstemp/MainActivity.kt create mode 100644 app/src/main/java/com/github/krottv/tmstemp/RecyclerFragment.kt create mode 100644 app/src/main/java/com/github/krottv/tmstemp/binder/MainActivityDataBinder.kt create mode 100644 app/src/main/java/com/github/krottv/tmstemp/binder/MainActivityRecyclerScrollDataBinder.kt create mode 100644 app/src/main/java/com/github/krottv/tmstemp/data/MessagesRemoteDataSource.kt create mode 100644 app/src/main/java/com/github/krottv/tmstemp/data/MessagesRemoteDataSourceError.kt create mode 100644 app/src/main/java/com/github/krottv/tmstemp/data/MessagesRemoteDataSourceFake.kt create mode 100644 app/src/main/java/com/github/krottv/tmstemp/domain/Message.kt create mode 100644 app/src/main/java/com/github/krottv/tmstemp/presentation/MessageViewModel.kt create mode 100644 app/src/main/java/com/github/krottv/tmstemp/view/MainActivity.kt create mode 100644 app/src/main/java/com/github/krottv/tmstemp/view/MessageAdapter.kt create mode 100644 app/src/main/java/com/github/krottv/tmstemp/view/MessageViewHolder.kt create mode 100644 app/src/main/res/layout/fullscreen_message.xml create mode 100644 app/src/main/res/layout/loading.xml create mode 100644 app/src/main/res/layout/messages_fragment.xml create mode 100644 app/src/main/res/layout/recycler_cell.xml create mode 100644 app/src/main/res/layout/recycler_view.xml create mode 100644 app/src/main/res/layout/show_error.xml create mode 100644 app/src/main/res/navigation/nav_graph.xml diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..fb7f4a8 --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml new file mode 100644 index 0000000..4e3844e --- /dev/null +++ b/.idea/gradle.xml @@ -0,0 +1,19 @@ + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..fb74a58 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index 93d31ce..0eebe9d 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,11 +1,16 @@ plugins { id 'com.android.application' id 'org.jetbrains.kotlin.android' + id 'androidx.navigation.safeargs.kotlin' } android { compileSdk 31 + viewBinding { + enabled = true + } + defaultConfig { applicationId "com.github.krottv.tmstemp" minSdk 24 @@ -32,6 +37,17 @@ android { } dependencies { + implementation "androidx.navigation:navigation-fragment-ktx:2.4.2" + implementation "androidx.navigation:navigation-ui-ktx:2.4.2" + implementation "androidx.fragment:fragment-ktx:1.4.1" + implementation "androidx.activity:activity-ktx:1.4.0" + + implementation("io.coil-kt:coil:2.0.0-rc03") + + implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.4.1' + implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.4.1' + implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.4.1' + implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.1' implementation 'androidx.core:core-ktx:1.7.0' implementation 'androidx.appcompat:appcompat:1.4.1' diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index a551aff..e24bb3d 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,6 +1,8 @@ + + diff --git a/app/src/main/java/com/github/krottv/tmstemp/FullscreenFragment.kt b/app/src/main/java/com/github/krottv/tmstemp/FullscreenFragment.kt new file mode 100644 index 0000000..602ce49 --- /dev/null +++ b/app/src/main/java/com/github/krottv/tmstemp/FullscreenFragment.kt @@ -0,0 +1,36 @@ +package com.github.krottv.tmstemp + +import android.os.Bundle +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import androidx.fragment.app.Fragment +import coil.load +import com.github.krottv.tmstemp.databinding.FullscreenMessageBinding +import com.github.krottv.tmstemp.domain.Message + +class FullscreenFragment: Fragment() { + + lateinit var binding: FullscreenMessageBinding + + override fun onCreateView( + inflater: LayoutInflater, + container: ViewGroup?, + savedInstanceState: Bundle? + ): View { + + binding = FullscreenMessageBinding.inflate(inflater, container, false) + + val item: Message = requireArguments().getParcelable("message")!! + + binding.mainText.text = item.mainText + binding.imageView.load(item.mainImage) + binding.anyText.text = item.littleText + + return binding.root + } + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/github/krottv/tmstemp/MainActivity.kt b/app/src/main/java/com/github/krottv/tmstemp/MainActivity.kt deleted file mode 100644 index 8952f64..0000000 --- a/app/src/main/java/com/github/krottv/tmstemp/MainActivity.kt +++ /dev/null @@ -1,11 +0,0 @@ -package com.github.krottv.tmstemp - -import androidx.appcompat.app.AppCompatActivity -import android.os.Bundle - -class MainActivity : AppCompatActivity() { - override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) - setContentView(R.layout.activity_main) - } -} \ No newline at end of file diff --git a/app/src/main/java/com/github/krottv/tmstemp/RecyclerFragment.kt b/app/src/main/java/com/github/krottv/tmstemp/RecyclerFragment.kt new file mode 100644 index 0000000..a9a7058 --- /dev/null +++ b/app/src/main/java/com/github/krottv/tmstemp/RecyclerFragment.kt @@ -0,0 +1,22 @@ +package com.github.krottv.tmstemp + +import android.os.Bundle +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import androidx.fragment.app.Fragment + +class RecyclerFragment: Fragment() { + + override fun onCreateView( + inflater: LayoutInflater, + container: ViewGroup?, + savedInstanceState: Bundle? + ): View? { + return super.onCreateView(inflater, container, savedInstanceState) + } + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/github/krottv/tmstemp/binder/MainActivityDataBinder.kt b/app/src/main/java/com/github/krottv/tmstemp/binder/MainActivityDataBinder.kt new file mode 100644 index 0000000..8b81aeb --- /dev/null +++ b/app/src/main/java/com/github/krottv/tmstemp/binder/MainActivityDataBinder.kt @@ -0,0 +1,5 @@ +package com.github.krottv.tmstemp.binder + +interface MainActivityDataBinder { + fun bind() +} \ No newline at end of file diff --git a/app/src/main/java/com/github/krottv/tmstemp/binder/MainActivityRecyclerScrollDataBinder.kt b/app/src/main/java/com/github/krottv/tmstemp/binder/MainActivityRecyclerScrollDataBinder.kt new file mode 100644 index 0000000..04145e3 --- /dev/null +++ b/app/src/main/java/com/github/krottv/tmstemp/binder/MainActivityRecyclerScrollDataBinder.kt @@ -0,0 +1,60 @@ +package com.github.krottv.tmstemp.binder + +import android.app.Activity +import android.transition.* +import android.view.LayoutInflater +import android.widget.TextView +import androidx.recyclerview.widget.LinearLayoutManager +import androidx.recyclerview.widget.RecyclerView +import com.github.krottv.tmstemp.R +import com.github.krottv.tmstemp.databinding.ActivityMainBinding +import com.github.krottv.tmstemp.domain.Message +import com.github.krottv.tmstemp.view.MessageAdapter + + +class MainActivityRecyclerScrollDataBinder(private val activity: Activity): MainActivityDataBinder { + + private lateinit var container: ActivityMainBinding + + private val customTransition = TransitionSet().apply { + addTransition(ChangeBounds()) + addTransition(Fade(Fade.IN)) + } + + override fun bind() { + container = ActivityMainBinding.inflate(LayoutInflater.from(activity)) + activity.setContentView(container.root) + } + + fun onDataLoaded(data: List) { + + val scene = Scene.getSceneForLayout(container.container, R.layout.recycler_view, activity) + + TransitionManager.go(scene, customTransition) + + val recyclerView = container.container.findViewById(R.id.recycler) + recyclerView.layoutManager = LinearLayoutManager(activity) + + if (recyclerView.adapter == null) { + recyclerView.adapter = MessageAdapter(data) + } else { + (recyclerView.adapter as MessageAdapter).data = data + } + } + + fun showError(exception: Throwable) { + + val scene = Scene.getSceneForLayout(container.container, R.layout.show_error, activity) + + TransitionManager.go(scene, customTransition) + + container.container.findViewById(R.id.errorText).apply { + text = exception.message + } + } + + fun showProgress() { + val scene = Scene.getSceneForLayout(container.container, R.layout.loading, activity) + TransitionManager.go(scene, customTransition) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/github/krottv/tmstemp/data/MessagesRemoteDataSource.kt b/app/src/main/java/com/github/krottv/tmstemp/data/MessagesRemoteDataSource.kt new file mode 100644 index 0000000..7edbbbc --- /dev/null +++ b/app/src/main/java/com/github/krottv/tmstemp/data/MessagesRemoteDataSource.kt @@ -0,0 +1,7 @@ +package com.github.krottv.tmstemp.data + +import com.github.krottv.tmstemp.domain.Message + +interface MessagesRemoteDataSource { + suspend fun getMessages(): List +} \ No newline at end of file diff --git a/app/src/main/java/com/github/krottv/tmstemp/data/MessagesRemoteDataSourceError.kt b/app/src/main/java/com/github/krottv/tmstemp/data/MessagesRemoteDataSourceError.kt new file mode 100644 index 0000000..1a66ecc --- /dev/null +++ b/app/src/main/java/com/github/krottv/tmstemp/data/MessagesRemoteDataSourceError.kt @@ -0,0 +1,12 @@ +package com.github.krottv.tmstemp.data + +import com.github.krottv.tmstemp.domain.Message +import kotlinx.coroutines.delay +import java.lang.IllegalStateException + +class MessagesRemoteDataSourceError: MessagesRemoteDataSource { + override suspend fun getMessages(): List { + delay(2000) + throw IllegalStateException("IllegalStateException") + } +} \ No newline at end of file diff --git a/app/src/main/java/com/github/krottv/tmstemp/data/MessagesRemoteDataSourceFake.kt b/app/src/main/java/com/github/krottv/tmstemp/data/MessagesRemoteDataSourceFake.kt new file mode 100644 index 0000000..b733a32 --- /dev/null +++ b/app/src/main/java/com/github/krottv/tmstemp/data/MessagesRemoteDataSourceFake.kt @@ -0,0 +1,21 @@ +package com.github.krottv.tmstemp.data + +import com.github.krottv.tmstemp.domain.Message +import kotlinx.coroutines.delay + +class MessagesRemoteDataSourceFake: MessagesRemoteDataSource { + override suspend fun getMessages(): List { + delay(2000) + val message = Message( + "https://images.unsplash.com/photo-1505062351414-586330b076f2?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1080&q=80", + "https://images.unsplash.com/photo-1505062351414-586330b076f2?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1080&q=80", + "Пункт такойто", + "Какой-то текст Какой-то текст Какой-то текст Какой-то текст" + ) + val result = ArrayList(20) + for (i in 0..20) { + result.add(message.copy(mainText = "Пункт $i")) + } + return result + } +} \ No newline at end of file diff --git a/app/src/main/java/com/github/krottv/tmstemp/domain/Message.kt b/app/src/main/java/com/github/krottv/tmstemp/domain/Message.kt new file mode 100644 index 0000000..7a50f03 --- /dev/null +++ b/app/src/main/java/com/github/krottv/tmstemp/domain/Message.kt @@ -0,0 +1,4 @@ +package com.github.krottv.tmstemp.domain + +data class Message(val mainImage: String, val littleImage: String, val mainText: String, val littleText: String) { +} \ No newline at end of file diff --git a/app/src/main/java/com/github/krottv/tmstemp/presentation/MessageViewModel.kt b/app/src/main/java/com/github/krottv/tmstemp/presentation/MessageViewModel.kt new file mode 100644 index 0000000..8fa4724 --- /dev/null +++ b/app/src/main/java/com/github/krottv/tmstemp/presentation/MessageViewModel.kt @@ -0,0 +1,31 @@ +package com.github.krottv.tmstemp.presentation + +import androidx.lifecycle.ViewModel +import androidx.lifecycle.viewModelScope +import com.github.krottv.tmstemp.data.MessagesRemoteDataSource +import com.github.krottv.tmstemp.data.MessagesRemoteDataSourceError +import com.github.krottv.tmstemp.data.MessagesRemoteDataSourceFake +import com.github.krottv.tmstemp.domain.Message +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.flow.MutableStateFlow +import kotlinx.coroutines.flow.StateFlow +import kotlinx.coroutines.launch + +class MessageViewModel: ViewModel() { + private val fakeMessages: MessagesRemoteDataSource = MessagesRemoteDataSourceFake() + + private val _state = MutableStateFlow>?>(null) + val state: StateFlow>?> = _state + + fun loadData() { + viewModelScope.launch(Dispatchers.IO) { + val result = try { + Result.success(fakeMessages.getMessages()) + } catch (exception: Throwable) { + Result.failure(exception) + } + + _state.emit(result) + } + } +} diff --git a/app/src/main/java/com/github/krottv/tmstemp/view/MainActivity.kt b/app/src/main/java/com/github/krottv/tmstemp/view/MainActivity.kt new file mode 100644 index 0000000..c8f2a03 --- /dev/null +++ b/app/src/main/java/com/github/krottv/tmstemp/view/MainActivity.kt @@ -0,0 +1,40 @@ +package com.github.krottv.tmstemp.view + +import androidx.appcompat.app.AppCompatActivity +import android.os.Bundle +import androidx.lifecycle.ViewModelProvider +import androidx.lifecycle.lifecycleScope +import com.github.krottv.tmstemp.binder.MainActivityDataBinder +import com.github.krottv.tmstemp.binder.MainActivityRecyclerScrollDataBinder +import com.github.krottv.tmstemp.presentation.MessageViewModel +import kotlinx.coroutines.launch + +class MainActivity : AppCompatActivity() { + override fun onCreate(savedInstanceState: Bundle?) { + + lateinit var mainActivityDataBinder: MainActivityDataBinder + + super.onCreate(savedInstanceState) + + mainActivityDataBinder = MainActivityRecyclerScrollDataBinder(this) + mainActivityDataBinder.bind() + + val viewModel: MessageViewModel = ViewModelProvider(this)[MessageViewModel::class.java] + + viewModel.loadData() + + lifecycleScope.launch { + viewModel.state.collect { + if (it != null) { + if (it.isSuccess) { + mainActivityDataBinder.onDataLoaded(it.getOrThrow()) + } else { + mainActivityDataBinder.showError(it.exceptionOrNull() as Throwable) + } + } else { + mainActivityDataBinder.showProgress() + } + } + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/github/krottv/tmstemp/view/MessageAdapter.kt b/app/src/main/java/com/github/krottv/tmstemp/view/MessageAdapter.kt new file mode 100644 index 0000000..c408a4d --- /dev/null +++ b/app/src/main/java/com/github/krottv/tmstemp/view/MessageAdapter.kt @@ -0,0 +1,36 @@ +package com.github.krottv.tmstemp.view + +import android.view.LayoutInflater +import android.view.ViewGroup +import android.widget.ImageView +import androidx.recyclerview.widget.DefaultItemAnimator +import androidx.recyclerview.widget.RecyclerView +import coil.load +import com.github.krottv.tmstemp.R +import com.github.krottv.tmstemp.domain.Message + +class MessageAdapter(var data: List): RecyclerView.Adapter() { + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MessageViewHolder { + val view = LayoutInflater.from(parent.context).inflate(R.layout.recycler_cell, parent, false) + return MessageViewHolder(view) + } + + override fun onBindViewHolder(holder: MessageViewHolder, position: Int) { + val cell = data[position] + holder.mainImage.apply { + load(cell.mainImage) + scaleType = ImageView.ScaleType.CENTER_CROP + } + holder.littleImage.apply { + load(cell.littleImage) + scaleType = ImageView.ScaleType.CENTER_CROP + } + holder.mainText.text = cell.mainText + holder.littleText.text = cell.littleText + } + + override fun getItemCount(): Int { + return data.size + } +} \ No newline at end of file diff --git a/app/src/main/java/com/github/krottv/tmstemp/view/MessageViewHolder.kt b/app/src/main/java/com/github/krottv/tmstemp/view/MessageViewHolder.kt new file mode 100644 index 0000000..e77857e --- /dev/null +++ b/app/src/main/java/com/github/krottv/tmstemp/view/MessageViewHolder.kt @@ -0,0 +1,14 @@ +package com.github.krottv.tmstemp.view + +import android.view.View +import android.widget.ImageView +import android.widget.TextView +import androidx.recyclerview.widget.RecyclerView +import com.github.krottv.tmstemp.R + +class MessageViewHolder(view: View): RecyclerView.ViewHolder(view) { + val mainImage: ImageView = view.findViewById(R.id.mainImage) + val littleImage: ImageView = view.findViewById(R.id.littleImage) + val mainText: TextView = view.findViewById(R.id.mainText) + val littleText: TextView = view.findViewById(R.id.littleText) +} \ No newline at end of file diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 4fc2444..bf18798 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -1,18 +1,13 @@ - - - - - - \ No newline at end of file + android:layout_height="match_parent"> + + \ No newline at end of file diff --git a/app/src/main/res/layout/fullscreen_message.xml b/app/src/main/res/layout/fullscreen_message.xml new file mode 100644 index 0000000..4a62a6f --- /dev/null +++ b/app/src/main/res/layout/fullscreen_message.xml @@ -0,0 +1,47 @@ + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/loading.xml b/app/src/main/res/layout/loading.xml new file mode 100644 index 0000000..3e7fa63 --- /dev/null +++ b/app/src/main/res/layout/loading.xml @@ -0,0 +1,16 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/messages_fragment.xml b/app/src/main/res/layout/messages_fragment.xml new file mode 100644 index 0000000..92ddb23 --- /dev/null +++ b/app/src/main/res/layout/messages_fragment.xml @@ -0,0 +1,22 @@ + + + + + + diff --git a/app/src/main/res/layout/recycler_cell.xml b/app/src/main/res/layout/recycler_cell.xml new file mode 100644 index 0000000..85a8c8c --- /dev/null +++ b/app/src/main/res/layout/recycler_cell.xml @@ -0,0 +1,52 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/recycler_view.xml b/app/src/main/res/layout/recycler_view.xml new file mode 100644 index 0000000..f378b89 --- /dev/null +++ b/app/src/main/res/layout/recycler_view.xml @@ -0,0 +1,37 @@ + + + + + + + + diff --git a/app/src/main/res/layout/show_error.xml b/app/src/main/res/layout/show_error.xml new file mode 100644 index 0000000..f612ab7 --- /dev/null +++ b/app/src/main/res/layout/show_error.xml @@ -0,0 +1,19 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/navigation/nav_graph.xml b/app/src/main/res/navigation/nav_graph.xml new file mode 100644 index 0000000..d1ffcb7 --- /dev/null +++ b/app/src/main/res/navigation/nav_graph.xml @@ -0,0 +1,23 @@ + + + + + + + + + \ No newline at end of file diff --git a/build.gradle b/build.gradle index 0ccd671..277b80e 100644 --- a/build.gradle +++ b/build.gradle @@ -1,4 +1,15 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. + +buildscript { + repositories { + google() + } + dependencies { + def nav_version = "2.4.2" + classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$nav_version" + } +} + plugins { id 'com.android.application' version '7.1.2' apply false id 'com.android.library' version '7.1.2' apply false From 819b29235741cd0beb47e178cfab65d7c8268e26 Mon Sep 17 00:00:00 2001 From: Alexandr Kalevich Date: Tue, 26 Apr 2022 03:18:20 +0300 Subject: [PATCH 2/3] Homework 24 --- .idea/gradle.xml | 1 + .idea/misc.xml | 5 ++ .../krottv/tmstemp/FullscreenFragment.kt | 36 --------- .../github/krottv/tmstemp/RecyclerFragment.kt | 22 ------ .../MainActivityRecyclerScrollDataBinder.kt | 47 +---------- .../tmstemp/binder/RecyclerFragmentBinder.kt | 67 ++++++++++++++++ .../tmstemp/data/MessagesRemoteDataSource.kt | 4 +- .../data/MessagesRemoteDataSourceError.kt | 4 +- .../data/MessagesRemoteDataSourceFake.kt | 9 +-- .../github/krottv/tmstemp/domain/Message.kt | 4 - .../krottv/tmstemp/domain/MessageModel.kt | 36 +++++++++ .../tmstemp/presentation/MessageViewModel.kt | 6 +- .../krottv/tmstemp/view/FullscreenFragment.kt | 67 ++++++++++++++++ .../krottv/tmstemp/view/MainActivity.kt | 27 +------ .../krottv/tmstemp/view/MessageAdapter.kt | 17 ++-- .../krottv/tmstemp/view/MessageViewHolder.kt | 1 - .../krottv/tmstemp/view/RecyclerFragment.kt | 78 +++++++++++++++++++ .../main/res/layout/fullscreen_message.xml | 1 + app/src/main/res/layout/messages_fragment.xml | 4 +- app/src/main/res/layout/recycler_cell.xml | 12 +-- app/src/main/res/layout/recycler_view.xml | 37 --------- app/src/main/res/layout/scene_container.xml | 20 +++++ app/src/main/res/navigation/nav_graph.xml | 23 ++++-- 23 files changed, 317 insertions(+), 211 deletions(-) delete mode 100644 app/src/main/java/com/github/krottv/tmstemp/FullscreenFragment.kt delete mode 100644 app/src/main/java/com/github/krottv/tmstemp/RecyclerFragment.kt create mode 100644 app/src/main/java/com/github/krottv/tmstemp/binder/RecyclerFragmentBinder.kt delete mode 100644 app/src/main/java/com/github/krottv/tmstemp/domain/Message.kt create mode 100644 app/src/main/java/com/github/krottv/tmstemp/domain/MessageModel.kt create mode 100644 app/src/main/java/com/github/krottv/tmstemp/view/FullscreenFragment.kt create mode 100644 app/src/main/java/com/github/krottv/tmstemp/view/RecyclerFragment.kt delete mode 100644 app/src/main/res/layout/recycler_view.xml create mode 100644 app/src/main/res/layout/scene_container.xml diff --git a/.idea/gradle.xml b/.idea/gradle.xml index 4e3844e..526b4c2 100644 --- a/.idea/gradle.xml +++ b/.idea/gradle.xml @@ -1,5 +1,6 @@ + diff --git a/app/src/main/java/com/github/krottv/tmstemp/FullscreenFragment.kt b/app/src/main/java/com/github/krottv/tmstemp/FullscreenFragment.kt deleted file mode 100644 index 602ce49..0000000 --- a/app/src/main/java/com/github/krottv/tmstemp/FullscreenFragment.kt +++ /dev/null @@ -1,36 +0,0 @@ -package com.github.krottv.tmstemp - -import android.os.Bundle -import android.view.LayoutInflater -import android.view.View -import android.view.ViewGroup -import androidx.fragment.app.Fragment -import coil.load -import com.github.krottv.tmstemp.databinding.FullscreenMessageBinding -import com.github.krottv.tmstemp.domain.Message - -class FullscreenFragment: Fragment() { - - lateinit var binding: FullscreenMessageBinding - - override fun onCreateView( - inflater: LayoutInflater, - container: ViewGroup?, - savedInstanceState: Bundle? - ): View { - - binding = FullscreenMessageBinding.inflate(inflater, container, false) - - val item: Message = requireArguments().getParcelable("message")!! - - binding.mainText.text = item.mainText - binding.imageView.load(item.mainImage) - binding.anyText.text = item.littleText - - return binding.root - } - - override fun onViewCreated(view: View, savedInstanceState: Bundle?) { - super.onViewCreated(view, savedInstanceState) - } -} \ No newline at end of file diff --git a/app/src/main/java/com/github/krottv/tmstemp/RecyclerFragment.kt b/app/src/main/java/com/github/krottv/tmstemp/RecyclerFragment.kt deleted file mode 100644 index a9a7058..0000000 --- a/app/src/main/java/com/github/krottv/tmstemp/RecyclerFragment.kt +++ /dev/null @@ -1,22 +0,0 @@ -package com.github.krottv.tmstemp - -import android.os.Bundle -import android.view.LayoutInflater -import android.view.View -import android.view.ViewGroup -import androidx.fragment.app.Fragment - -class RecyclerFragment: Fragment() { - - override fun onCreateView( - inflater: LayoutInflater, - container: ViewGroup?, - savedInstanceState: Bundle? - ): View? { - return super.onCreateView(inflater, container, savedInstanceState) - } - - override fun onViewCreated(view: View, savedInstanceState: Bundle?) { - super.onViewCreated(view, savedInstanceState) - } -} \ No newline at end of file diff --git a/app/src/main/java/com/github/krottv/tmstemp/binder/MainActivityRecyclerScrollDataBinder.kt b/app/src/main/java/com/github/krottv/tmstemp/binder/MainActivityRecyclerScrollDataBinder.kt index 04145e3..8b9d9da 100644 --- a/app/src/main/java/com/github/krottv/tmstemp/binder/MainActivityRecyclerScrollDataBinder.kt +++ b/app/src/main/java/com/github/krottv/tmstemp/binder/MainActivityRecyclerScrollDataBinder.kt @@ -1,60 +1,15 @@ package com.github.krottv.tmstemp.binder import android.app.Activity -import android.transition.* import android.view.LayoutInflater -import android.widget.TextView -import androidx.recyclerview.widget.LinearLayoutManager -import androidx.recyclerview.widget.RecyclerView -import com.github.krottv.tmstemp.R import com.github.krottv.tmstemp.databinding.ActivityMainBinding -import com.github.krottv.tmstemp.domain.Message -import com.github.krottv.tmstemp.view.MessageAdapter class MainActivityRecyclerScrollDataBinder(private val activity: Activity): MainActivityDataBinder { - private lateinit var container: ActivityMainBinding - - private val customTransition = TransitionSet().apply { - addTransition(ChangeBounds()) - addTransition(Fade(Fade.IN)) - } - override fun bind() { - container = ActivityMainBinding.inflate(LayoutInflater.from(activity)) + val container = ActivityMainBinding.inflate(LayoutInflater.from(activity)) activity.setContentView(container.root) } - fun onDataLoaded(data: List) { - - val scene = Scene.getSceneForLayout(container.container, R.layout.recycler_view, activity) - - TransitionManager.go(scene, customTransition) - - val recyclerView = container.container.findViewById(R.id.recycler) - recyclerView.layoutManager = LinearLayoutManager(activity) - - if (recyclerView.adapter == null) { - recyclerView.adapter = MessageAdapter(data) - } else { - (recyclerView.adapter as MessageAdapter).data = data - } - } - - fun showError(exception: Throwable) { - - val scene = Scene.getSceneForLayout(container.container, R.layout.show_error, activity) - - TransitionManager.go(scene, customTransition) - - container.container.findViewById(R.id.errorText).apply { - text = exception.message - } - } - - fun showProgress() { - val scene = Scene.getSceneForLayout(container.container, R.layout.loading, activity) - TransitionManager.go(scene, customTransition) - } } \ No newline at end of file diff --git a/app/src/main/java/com/github/krottv/tmstemp/binder/RecyclerFragmentBinder.kt b/app/src/main/java/com/github/krottv/tmstemp/binder/RecyclerFragmentBinder.kt new file mode 100644 index 0000000..ecabf04 --- /dev/null +++ b/app/src/main/java/com/github/krottv/tmstemp/binder/RecyclerFragmentBinder.kt @@ -0,0 +1,67 @@ +package com.github.krottv.tmstemp.binder + +import android.os.Bundle +import android.transition.* +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.TextView +import androidx.fragment.app.Fragment +import androidx.recyclerview.widget.LinearLayoutManager +import androidx.recyclerview.widget.RecyclerView +import com.github.krottv.tmstemp.R +import com.github.krottv.tmstemp.databinding.SceneContainerBinding +import com.github.krottv.tmstemp.domain.MessageModel +import com.github.krottv.tmstemp.view.MessageAdapter + +class RecyclerFragmentBinder(private val fragment: Fragment, private val onItemClick: (View, MessageModel) -> Unit) { + + private lateinit var binding: SceneContainerBinding + + fun bindView( + inflater: LayoutInflater, + container: ViewGroup?, + savedInstanceState: Bundle? + ): View { + binding = SceneContainerBinding.inflate(inflater, container, false) + + return binding.root + } + + + private val customTransition = TransitionSet().apply { + addTransition(ChangeBounds()) + addTransition(Fade(Fade.IN)) + } + + fun onDataLoaded(data: List) { + + val scene = Scene.getSceneForLayout(binding.sceneRoot, R.layout.messages_fragment, fragment.requireContext()) + TransitionManager.go(scene, customTransition) + + val recyclerView = scene.sceneRoot.findViewById(R.id.container) + recyclerView.layoutManager = LinearLayoutManager(fragment.requireContext()) + + if (recyclerView.adapter == null) { + recyclerView.adapter = MessageAdapter(data, onItemClick) + } else { + (recyclerView.adapter as MessageAdapter).data = data + } + } + + fun showError(exception: Throwable) { + + val scene = Scene.getSceneForLayout(binding.sceneRoot, R.layout.show_error, fragment.requireContext()) + TransitionManager.go(scene, customTransition) + + scene.sceneRoot.findViewById(R.id.errorText).apply { + text = exception.message + } + } + + fun showProgress() { + + val scene = Scene.getSceneForLayout(binding.sceneRoot, R.layout.loading, fragment.requireContext()) + TransitionManager.go(scene, customTransition) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/github/krottv/tmstemp/data/MessagesRemoteDataSource.kt b/app/src/main/java/com/github/krottv/tmstemp/data/MessagesRemoteDataSource.kt index 7edbbbc..5d674f6 100644 --- a/app/src/main/java/com/github/krottv/tmstemp/data/MessagesRemoteDataSource.kt +++ b/app/src/main/java/com/github/krottv/tmstemp/data/MessagesRemoteDataSource.kt @@ -1,7 +1,7 @@ package com.github.krottv.tmstemp.data -import com.github.krottv.tmstemp.domain.Message +import com.github.krottv.tmstemp.domain.MessageModel interface MessagesRemoteDataSource { - suspend fun getMessages(): List + suspend fun getMessages(): List } \ No newline at end of file diff --git a/app/src/main/java/com/github/krottv/tmstemp/data/MessagesRemoteDataSourceError.kt b/app/src/main/java/com/github/krottv/tmstemp/data/MessagesRemoteDataSourceError.kt index 1a66ecc..206edf1 100644 --- a/app/src/main/java/com/github/krottv/tmstemp/data/MessagesRemoteDataSourceError.kt +++ b/app/src/main/java/com/github/krottv/tmstemp/data/MessagesRemoteDataSourceError.kt @@ -1,11 +1,11 @@ package com.github.krottv.tmstemp.data -import com.github.krottv.tmstemp.domain.Message +import com.github.krottv.tmstemp.domain.MessageModel import kotlinx.coroutines.delay import java.lang.IllegalStateException class MessagesRemoteDataSourceError: MessagesRemoteDataSource { - override suspend fun getMessages(): List { + override suspend fun getMessages(): List { delay(2000) throw IllegalStateException("IllegalStateException") } diff --git a/app/src/main/java/com/github/krottv/tmstemp/data/MessagesRemoteDataSourceFake.kt b/app/src/main/java/com/github/krottv/tmstemp/data/MessagesRemoteDataSourceFake.kt index b733a32..47966d7 100644 --- a/app/src/main/java/com/github/krottv/tmstemp/data/MessagesRemoteDataSourceFake.kt +++ b/app/src/main/java/com/github/krottv/tmstemp/data/MessagesRemoteDataSourceFake.kt @@ -1,18 +1,17 @@ package com.github.krottv.tmstemp.data -import com.github.krottv.tmstemp.domain.Message +import com.github.krottv.tmstemp.domain.MessageModel import kotlinx.coroutines.delay class MessagesRemoteDataSourceFake: MessagesRemoteDataSource { - override suspend fun getMessages(): List { + override suspend fun getMessages(): List { delay(2000) - val message = Message( - "https://images.unsplash.com/photo-1505062351414-586330b076f2?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1080&q=80", + val message = MessageModel( "https://images.unsplash.com/photo-1505062351414-586330b076f2?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1080&q=80", "Пункт такойто", "Какой-то текст Какой-то текст Какой-то текст Какой-то текст" ) - val result = ArrayList(20) + val result = ArrayList(20) for (i in 0..20) { result.add(message.copy(mainText = "Пункт $i")) } diff --git a/app/src/main/java/com/github/krottv/tmstemp/domain/Message.kt b/app/src/main/java/com/github/krottv/tmstemp/domain/Message.kt deleted file mode 100644 index 7a50f03..0000000 --- a/app/src/main/java/com/github/krottv/tmstemp/domain/Message.kt +++ /dev/null @@ -1,4 +0,0 @@ -package com.github.krottv.tmstemp.domain - -data class Message(val mainImage: String, val littleImage: String, val mainText: String, val littleText: String) { -} \ No newline at end of file diff --git a/app/src/main/java/com/github/krottv/tmstemp/domain/MessageModel.kt b/app/src/main/java/com/github/krottv/tmstemp/domain/MessageModel.kt new file mode 100644 index 0000000..5bd1276 --- /dev/null +++ b/app/src/main/java/com/github/krottv/tmstemp/domain/MessageModel.kt @@ -0,0 +1,36 @@ +package com.github.krottv.tmstemp.domain + +import android.os.Parcel +import android.os.Parcelable +import androidx.annotation.Keep + +@Keep +data class MessageModel(val mainImage: String, val mainText: String, val littleText: String): Parcelable { + constructor(parcel: Parcel) : this( + parcel.readString()!!, + parcel.readString()!!, + parcel.readString()!! + ) + + fun transitionId() = mainText + "_" + + override fun writeToParcel(parcel: Parcel, flags: Int) { + parcel.writeString(mainImage) + parcel.writeString(mainText) + parcel.writeString(littleText) + } + + override fun describeContents(): Int { + return 0 + } + + companion object CREATOR : Parcelable.Creator { + override fun createFromParcel(parcel: Parcel): MessageModel { + return MessageModel(parcel) + } + + override fun newArray(size: Int): Array { + return arrayOfNulls(size) + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/github/krottv/tmstemp/presentation/MessageViewModel.kt b/app/src/main/java/com/github/krottv/tmstemp/presentation/MessageViewModel.kt index 8fa4724..2d18502 100644 --- a/app/src/main/java/com/github/krottv/tmstemp/presentation/MessageViewModel.kt +++ b/app/src/main/java/com/github/krottv/tmstemp/presentation/MessageViewModel.kt @@ -5,7 +5,7 @@ import androidx.lifecycle.viewModelScope import com.github.krottv.tmstemp.data.MessagesRemoteDataSource import com.github.krottv.tmstemp.data.MessagesRemoteDataSourceError import com.github.krottv.tmstemp.data.MessagesRemoteDataSourceFake -import com.github.krottv.tmstemp.domain.Message +import com.github.krottv.tmstemp.domain.MessageModel import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow @@ -14,8 +14,8 @@ import kotlinx.coroutines.launch class MessageViewModel: ViewModel() { private val fakeMessages: MessagesRemoteDataSource = MessagesRemoteDataSourceFake() - private val _state = MutableStateFlow>?>(null) - val state: StateFlow>?> = _state + private val _state = MutableStateFlow>?>(null) + val state: StateFlow>?> = _state fun loadData() { viewModelScope.launch(Dispatchers.IO) { diff --git a/app/src/main/java/com/github/krottv/tmstemp/view/FullscreenFragment.kt b/app/src/main/java/com/github/krottv/tmstemp/view/FullscreenFragment.kt new file mode 100644 index 0000000..8ec9488 --- /dev/null +++ b/app/src/main/java/com/github/krottv/tmstemp/view/FullscreenFragment.kt @@ -0,0 +1,67 @@ +package com.github.krottv.tmstemp.view + +import android.os.Bundle +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import androidx.core.view.doOnPreDraw +import androidx.fragment.app.Fragment +import androidx.navigation.fragment.FragmentNavigatorExtras +import androidx.navigation.fragment.findNavController +import androidx.transition.AutoTransition +import coil.load +import com.github.krottv.tmstemp.databinding.FullscreenMessageBinding +import com.github.krottv.tmstemp.domain.MessageModel +import java.util.concurrent.TimeUnit + +class FullscreenFragment: Fragment() { + + companion object { + const val TRANSITION_ID = "Fullscreen" + } + + private lateinit var binding: FullscreenMessageBinding + + override fun onCreateView( + inflater: LayoutInflater, + container: ViewGroup?, + savedInstanceState: Bundle? + ): View { + sharedElementEnterTransition = AutoTransition() + sharedElementReturnTransition = AutoTransition() + + binding = FullscreenMessageBinding.inflate(inflater, container, false) + + binding.root.transitionName = TRANSITION_ID + + return binding.root + } + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + + val item: MessageModel = requireArguments().getParcelable("currentMessage")!! + + postponeEnterTransition(3000, TimeUnit.MILLISECONDS) + + binding.anyText.text = item.littleText + binding.imageView.load(item.mainImage) { + listener { request, result -> + (view.parent as? View)?.doOnPreDraw { + startPostponedEnterTransition() + } + } + } + binding.mainText.apply { + text = item.mainText + setOnClickListener { + val navController = findNavController() + + val action = FullscreenFragmentDirections.actionFullscreenFragmentToRecyclerFragment() + val extras = FragmentNavigatorExtras(view to RecyclerFragment.TRANSITION_ID) + + navController.navigate(action, extras) + } + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/github/krottv/tmstemp/view/MainActivity.kt b/app/src/main/java/com/github/krottv/tmstemp/view/MainActivity.kt index c8f2a03..e528fe2 100644 --- a/app/src/main/java/com/github/krottv/tmstemp/view/MainActivity.kt +++ b/app/src/main/java/com/github/krottv/tmstemp/view/MainActivity.kt @@ -2,39 +2,14 @@ package com.github.krottv.tmstemp.view import androidx.appcompat.app.AppCompatActivity import android.os.Bundle -import androidx.lifecycle.ViewModelProvider -import androidx.lifecycle.lifecycleScope import com.github.krottv.tmstemp.binder.MainActivityDataBinder import com.github.krottv.tmstemp.binder.MainActivityRecyclerScrollDataBinder -import com.github.krottv.tmstemp.presentation.MessageViewModel -import kotlinx.coroutines.launch class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { - - lateinit var mainActivityDataBinder: MainActivityDataBinder - super.onCreate(savedInstanceState) - mainActivityDataBinder = MainActivityRecyclerScrollDataBinder(this) + val mainActivityDataBinder: MainActivityDataBinder = MainActivityRecyclerScrollDataBinder(this) mainActivityDataBinder.bind() - - val viewModel: MessageViewModel = ViewModelProvider(this)[MessageViewModel::class.java] - - viewModel.loadData() - - lifecycleScope.launch { - viewModel.state.collect { - if (it != null) { - if (it.isSuccess) { - mainActivityDataBinder.onDataLoaded(it.getOrThrow()) - } else { - mainActivityDataBinder.showError(it.exceptionOrNull() as Throwable) - } - } else { - mainActivityDataBinder.showProgress() - } - } - } } } \ No newline at end of file diff --git a/app/src/main/java/com/github/krottv/tmstemp/view/MessageAdapter.kt b/app/src/main/java/com/github/krottv/tmstemp/view/MessageAdapter.kt index c408a4d..656ea99 100644 --- a/app/src/main/java/com/github/krottv/tmstemp/view/MessageAdapter.kt +++ b/app/src/main/java/com/github/krottv/tmstemp/view/MessageAdapter.kt @@ -1,15 +1,15 @@ package com.github.krottv.tmstemp.view import android.view.LayoutInflater +import android.view.View import android.view.ViewGroup import android.widget.ImageView -import androidx.recyclerview.widget.DefaultItemAnimator import androidx.recyclerview.widget.RecyclerView import coil.load import com.github.krottv.tmstemp.R -import com.github.krottv.tmstemp.domain.Message +import com.github.krottv.tmstemp.domain.MessageModel -class MessageAdapter(var data: List): RecyclerView.Adapter() { +class MessageAdapter(var data: List, private val onItemClick: (View, MessageModel) -> Unit): RecyclerView.Adapter() { override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MessageViewHolder { val view = LayoutInflater.from(parent.context).inflate(R.layout.recycler_cell, parent, false) @@ -22,12 +22,15 @@ class MessageAdapter(var data: List): RecyclerView.Adapter + val navController = findNavController() + + val action = RecyclerFragmentDirections.actionRecyclerFragmentToFullscreenFragment(item) + val extras = FragmentNavigatorExtras(view to FullscreenFragment.TRANSITION_ID) + + navController.navigate(action, extras) + } + + fragment.bindView(inflater, container, savedInstanceState).transitionName = TRANSITION_ID + + return fragment.bindView(inflater, container, savedInstanceState) + } + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + + postponeEnterTransition(1000, TimeUnit.MILLISECONDS) + + viewModel.loadData() + + lifecycleScope.launch { + viewLifecycleOwner.repeatOnLifecycle(Lifecycle.State.STARTED) { + viewModel.state.collect { + if (it != null) { + if (it.isSuccess) { + fragment.onDataLoaded(it.getOrThrow()) + + (view.parent as? ViewGroup)?.doOnPreDraw { + startPostponedEnterTransition() + } + } else { + fragment.showError(it.exceptionOrNull() as Throwable) + } + } else { + fragment.showProgress() + } + } + } + } + } +} \ No newline at end of file diff --git a/app/src/main/res/layout/fullscreen_message.xml b/app/src/main/res/layout/fullscreen_message.xml index 4a62a6f..af2697c 100644 --- a/app/src/main/res/layout/fullscreen_message.xml +++ b/app/src/main/res/layout/fullscreen_message.xml @@ -33,6 +33,7 @@ @@ -32,21 +33,12 @@ android:layout_width="0dp" android:layout_height="wrap_content" android:layout_marginStart="21dp" - android:layout_marginEnd="46dp" android:text="Какой-то текст Какой-то текст Какой-то текст Какой-то текст" android:textSize="11sp" app:layout_constraintBottom_toBottomOf="@+id/mainImage" - app:layout_constraintEnd_toStartOf="@+id/littleImage" + app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toEndOf="@+id/mainImage" app:layout_constraintTop_toBottomOf="@+id/mainText" /> - \ No newline at end of file diff --git a/app/src/main/res/layout/recycler_view.xml b/app/src/main/res/layout/recycler_view.xml deleted file mode 100644 index f378b89..0000000 --- a/app/src/main/res/layout/recycler_view.xml +++ /dev/null @@ -1,37 +0,0 @@ - - - - - - - - diff --git a/app/src/main/res/layout/scene_container.xml b/app/src/main/res/layout/scene_container.xml new file mode 100644 index 0000000..f540014 --- /dev/null +++ b/app/src/main/res/layout/scene_container.xml @@ -0,0 +1,20 @@ + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/navigation/nav_graph.xml b/app/src/main/res/navigation/nav_graph.xml index d1ffcb7..135a69d 100644 --- a/app/src/main/res/navigation/nav_graph.xml +++ b/app/src/main/res/navigation/nav_graph.xml @@ -3,21 +3,28 @@ xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/nav_graph" - app:startDestination="@id/fullscreenFragment"> + app:startDestination="@id/recyclerFragment"> + + + + tools:layout="@layout/fullscreen_message"> + - \ No newline at end of file From 8990a7531e3be15f9a4d1b56b61aa86709f81068 Mon Sep 17 00:00:00 2001 From: Alexandr Kalevich Date: Thu, 28 Apr 2022 19:03:54 +0300 Subject: [PATCH 3/3] Navigate fix --- .../com/github/krottv/tmstemp/view/FullscreenFragment.kt | 7 +------ .../com/github/krottv/tmstemp/view/RecyclerFragment.kt | 6 ------ 2 files changed, 1 insertion(+), 12 deletions(-) diff --git a/app/src/main/java/com/github/krottv/tmstemp/view/FullscreenFragment.kt b/app/src/main/java/com/github/krottv/tmstemp/view/FullscreenFragment.kt index 8ec9488..4b99d96 100644 --- a/app/src/main/java/com/github/krottv/tmstemp/view/FullscreenFragment.kt +++ b/app/src/main/java/com/github/krottv/tmstemp/view/FullscreenFragment.kt @@ -55,12 +55,7 @@ class FullscreenFragment: Fragment() { binding.mainText.apply { text = item.mainText setOnClickListener { - val navController = findNavController() - - val action = FullscreenFragmentDirections.actionFullscreenFragmentToRecyclerFragment() - val extras = FragmentNavigatorExtras(view to RecyclerFragment.TRANSITION_ID) - - navController.navigate(action, extras) + findNavController().navigateUp() } } } diff --git a/app/src/main/java/com/github/krottv/tmstemp/view/RecyclerFragment.kt b/app/src/main/java/com/github/krottv/tmstemp/view/RecyclerFragment.kt index ea85f01..7b6973f 100644 --- a/app/src/main/java/com/github/krottv/tmstemp/view/RecyclerFragment.kt +++ b/app/src/main/java/com/github/krottv/tmstemp/view/RecyclerFragment.kt @@ -17,10 +17,6 @@ import java.util.concurrent.TimeUnit class RecyclerFragment: Fragment() { - companion object { - const val TRANSITION_ID = "RecyclerView" - } - private lateinit var fragment: RecyclerFragmentBinder private lateinit var viewModel: MessageViewModel @@ -43,8 +39,6 @@ class RecyclerFragment: Fragment() { navController.navigate(action, extras) } - fragment.bindView(inflater, container, savedInstanceState).transitionName = TRANSITION_ID - return fragment.bindView(inflater, container, savedInstanceState) }