From 2b6659f4ecd1bb9fee4d63d79a8a951845d559ba Mon Sep 17 00:00:00 2001 From: davidoskky Date: Wed, 11 Jan 2023 22:13:12 +0100 Subject: [PATCH 01/10] Swipe down to close images --- .../android/ImageActivity.kt | 1 + .../android/fragments/ImageFragment.kt | 5 +++++ .../src/main/res/layout/fragment_image.xml | 20 ++++++++++++------- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/ImageActivity.kt b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/ImageActivity.kt index 16db2e8..5444485 100644 --- a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/ImageActivity.kt +++ b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/ImageActivity.kt @@ -19,6 +19,7 @@ class ImageActivity : AppCompatActivity() { super.onCreate(savedInstanceState) binding = ActivityImageBinding.inflate(layoutInflater) val view = binding.root + binding.pager.requestDisallowInterceptTouchEvent(true) setContentView(view) diff --git a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/fragments/ImageFragment.kt b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/fragments/ImageFragment.kt index 7b46b8c..09cecd0 100644 --- a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/fragments/ImageFragment.kt +++ b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/fragments/ImageFragment.kt @@ -27,6 +27,11 @@ class ImageFragment : Fragment() { _binding = FragmentImageBinding.inflate(inflater, container, false) val view = binding?.root + binding?.swipeRefreshLayout?.setProgressViewEndTarget(false, 0) + binding?.swipeRefreshLayout?.setOnRefreshListener { + activity?.finish() + } + binding!!.photoView.visibility = View.VISIBLE Glide.with(requireActivity()) .asBitmap() diff --git a/androidApp/src/main/res/layout/fragment_image.xml b/androidApp/src/main/res/layout/fragment_image.xml index 3bd2094..da5fc86 100644 --- a/androidApp/src/main/res/layout/fragment_image.xml +++ b/androidApp/src/main/res/layout/fragment_image.xml @@ -4,13 +4,19 @@ android:layout_width="match_parent" android:layout_height="match_parent"> - + android:layout_height="match_parent"> + + + \ No newline at end of file From 68bbf5b2d35c25000b4ab2ea998f6696423e4160 Mon Sep 17 00:00:00 2001 From: davidoskky Date: Fri, 20 Jan 2023 16:36:52 +0100 Subject: [PATCH 02/10] Animate swipe down to close images --- .../android/fragments/ImageFragment.kt | 26 +++++++++--- .../src/main/res/layout/fragment_image.xml | 14 +++---- .../src/main/res/xml/image_close_scene.xml | 41 +++++++++++++++++++ 3 files changed, 67 insertions(+), 14 deletions(-) create mode 100644 androidApp/src/main/res/xml/image_close_scene.xml diff --git a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/fragments/ImageFragment.kt b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/fragments/ImageFragment.kt index 09cecd0..1060167 100644 --- a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/fragments/ImageFragment.kt +++ b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/fragments/ImageFragment.kt @@ -4,6 +4,7 @@ import android.os.Bundle import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import androidx.constraintlayout.motion.widget.MotionLayout import androidx.fragment.app.Fragment import bou.amine.apps.readerforselfossv2.android.databinding.FragmentImageBinding import com.bumptech.glide.Glide @@ -27,11 +28,6 @@ class ImageFragment : Fragment() { _binding = FragmentImageBinding.inflate(inflater, container, false) val view = binding?.root - binding?.swipeRefreshLayout?.setProgressViewEndTarget(false, 0) - binding?.swipeRefreshLayout?.setOnRefreshListener { - activity?.finish() - } - binding!!.photoView.visibility = View.VISIBLE Glide.with(requireActivity()) .asBitmap() @@ -39,6 +35,26 @@ class ImageFragment : Fragment() { .load(imageUrl) .into(binding!!.photoView) + val transitionListener = object : MotionLayout.TransitionListener { + override fun onTransitionStarted(motionLayout: MotionLayout?, startId: Int, endId: Int) { + // Nothing + } + + override fun onTransitionChange(motionLayout: MotionLayout?, startId: Int, endId: Int, progress: Float + ) { + // Nothing + } + + override fun onTransitionCompleted(motionLayout: MotionLayout?, currentId: Int) { + activity?.finish() + } + + override fun onTransitionTrigger(motionLayout: MotionLayout?, triggerId: Int, positive: Boolean, progress: Float) { + // Nothing + } + } + binding!!.root.setTransitionListener(transitionListener) + return view } diff --git a/androidApp/src/main/res/layout/fragment_image.xml b/androidApp/src/main/res/layout/fragment_image.xml index da5fc86..907501c 100644 --- a/androidApp/src/main/res/layout/fragment_image.xml +++ b/androidApp/src/main/res/layout/fragment_image.xml @@ -1,13 +1,10 @@ - - - + android:layout_height="match_parent" + app:layoutDescription="@xml/image_close_scene"> - - \ No newline at end of file + \ No newline at end of file diff --git a/androidApp/src/main/res/xml/image_close_scene.xml b/androidApp/src/main/res/xml/image_close_scene.xml new file mode 100644 index 0000000..77fbc6b --- /dev/null +++ b/androidApp/src/main/res/xml/image_close_scene.xml @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file From ddc72d85b0e401ba107d2c79a1713584767ccfa4 Mon Sep 17 00:00:00 2001 From: davidoskky Date: Sat, 21 Jan 2023 16:37:25 +0100 Subject: [PATCH 03/10] Close the image fragment only if the image has been dragged down --- .../readerforselfossv2/android/fragments/ImageFragment.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/fragments/ImageFragment.kt b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/fragments/ImageFragment.kt index 1060167..5b9d3fb 100644 --- a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/fragments/ImageFragment.kt +++ b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/fragments/ImageFragment.kt @@ -46,7 +46,9 @@ class ImageFragment : Fragment() { } override fun onTransitionCompleted(motionLayout: MotionLayout?, currentId: Int) { - activity?.finish() + if (motionLayout?.currentState == binding?.root?.endState) { + activity?.finish() + } } override fun onTransitionTrigger(motionLayout: MotionLayout?, triggerId: Int, positive: Boolean, progress: Float) { From ae927ebc57bed342149b2d78680d27a796bde1b0 Mon Sep 17 00:00:00 2001 From: davidoskky Date: Wed, 25 Jan 2023 00:46:43 +0100 Subject: [PATCH 04/10] Resolve issues when swiping down to close images --- androidApp/build.gradle.kts | 3 +- .../android/ImageActivity.kt | 28 ++++++++++++++-- .../android/fragments/ImageFragment.kt | 22 ------------- .../src/main/res/layout/activity_image.xml | 32 ++++++++++++------- .../src/main/res/layout/fragment_image.xml | 8 ++--- .../src/main/res/xml/image_close_scene.xml | 16 +++++----- 6 files changed, 59 insertions(+), 50 deletions(-) diff --git a/androidApp/build.gradle.kts b/androidApp/build.gradle.kts index 556b4ba..f94882a 100644 --- a/androidApp/build.gradle.kts +++ b/androidApp/build.gradle.kts @@ -115,7 +115,6 @@ dependencies { implementation(project(":shared")) implementation("com.google.android.material:material:1.5.0") implementation("androidx.appcompat:appcompat:1.4.1") - implementation("androidx.constraintlayout:constraintlayout:2.1.3") implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.0") implementation("androidx.preference:preference-ktx:1.1.1") @@ -131,7 +130,7 @@ dependencies { implementation("androidx.cardview:cardview:1.0.0") implementation("androidx.annotation:annotation:1.3.0") implementation("androidx.work:work-runtime-ktx:2.7.1") - implementation("androidx.constraintlayout:constraintlayout:2.1.3") + implementation("androidx.constraintlayout:constraintlayout:2.1.4") implementation("org.jsoup:jsoup:1.14.3") //multidex diff --git a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/ImageActivity.kt b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/ImageActivity.kt index 5444485..fe4bd64 100644 --- a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/ImageActivity.kt +++ b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/ImageActivity.kt @@ -3,6 +3,7 @@ package bou.amine.apps.readerforselfossv2.android import android.os.Bundle import android.view.MenuItem import androidx.appcompat.app.AppCompatActivity +import androidx.constraintlayout.motion.widget.MotionLayout import androidx.fragment.app.Fragment import androidx.fragment.app.FragmentActivity import androidx.viewpager2.adapter.FragmentStateAdapter @@ -19,7 +20,6 @@ class ImageActivity : AppCompatActivity() { super.onCreate(savedInstanceState) binding = ActivityImageBinding.inflate(layoutInflater) val view = binding.root - binding.pager.requestDisallowInterceptTouchEvent(true) setContentView(view) @@ -32,12 +32,36 @@ class ImageActivity : AppCompatActivity() { binding.pager.adapter = ScreenSlidePagerAdapter(this) binding.pager.setCurrentItem(position, false) + + val transitionListener = object : MotionLayout.TransitionListener { + override fun onTransitionStarted(motionLayout: MotionLayout?, startId: Int, endId: Int) { + binding.root.setOnClickListener { + } + // Nothing + } + + override fun onTransitionChange(motionLayout: MotionLayout?, startId: Int, endId: Int, progress: Float + ) { + // Nothing + } + + override fun onTransitionCompleted(motionLayout: MotionLayout?, currentId: Int) { + if (motionLayout?.currentState == binding.root.endState) { + onBackPressedDispatcher.onBackPressed() + } + } + + override fun onTransitionTrigger(motionLayout: MotionLayout?, triggerId: Int, positive: Boolean, progress: Float) { + // Nothing + } + } + binding.root.setTransitionListener(transitionListener) } override fun onOptionsItemSelected(item: MenuItem): Boolean { when (item.itemId) { android.R.id.home -> { - onBackPressed() + onBackPressedDispatcher.onBackPressed() return true } } diff --git a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/fragments/ImageFragment.kt b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/fragments/ImageFragment.kt index 5b9d3fb..d8ac8c0 100644 --- a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/fragments/ImageFragment.kt +++ b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/fragments/ImageFragment.kt @@ -35,28 +35,6 @@ class ImageFragment : Fragment() { .load(imageUrl) .into(binding!!.photoView) - val transitionListener = object : MotionLayout.TransitionListener { - override fun onTransitionStarted(motionLayout: MotionLayout?, startId: Int, endId: Int) { - // Nothing - } - - override fun onTransitionChange(motionLayout: MotionLayout?, startId: Int, endId: Int, progress: Float - ) { - // Nothing - } - - override fun onTransitionCompleted(motionLayout: MotionLayout?, currentId: Int) { - if (motionLayout?.currentState == binding?.root?.endState) { - activity?.finish() - } - } - - override fun onTransitionTrigger(motionLayout: MotionLayout?, triggerId: Int, positive: Boolean, progress: Float) { - // Nothing - } - } - binding!!.root.setTransitionListener(transitionListener) - return view } diff --git a/androidApp/src/main/res/layout/activity_image.xml b/androidApp/src/main/res/layout/activity_image.xml index 66f62c8..fbf442f 100644 --- a/androidApp/src/main/res/layout/activity_image.xml +++ b/androidApp/src/main/res/layout/activity_image.xml @@ -1,8 +1,10 @@ - + android:layout_height="match_parent" + app:layoutDescription="@xml/image_close_scene"> + /> - + android:layout_height="match_parent" + android:fillViewport="true" + app:layout_constraintTop_toBottomOf="@+id/appBarLayout"> - + + + + + diff --git a/androidApp/src/main/res/layout/fragment_image.xml b/androidApp/src/main/res/layout/fragment_image.xml index 907501c..223c47e 100644 --- a/androidApp/src/main/res/layout/fragment_image.xml +++ b/androidApp/src/main/res/layout/fragment_image.xml @@ -1,10 +1,8 @@ - + android:layout_height="match_parent"> - \ No newline at end of file + \ No newline at end of file diff --git a/androidApp/src/main/res/xml/image_close_scene.xml b/androidApp/src/main/res/xml/image_close_scene.xml index 77fbc6b..79ee284 100644 --- a/androidApp/src/main/res/xml/image_close_scene.xml +++ b/androidApp/src/main/res/xml/image_close_scene.xml @@ -10,26 +10,26 @@ motion:motionInterpolator="linear"> + motion:touchAnchorId="@+id/scrollView" + motion:touchAnchorSide="top" + motion:onTouchUp="autoCompleteToStart" /> + motion:layout_constraintTop_toBottomOf="@+id/appBarLayout" + motion:layout_constraintEnd_toEndOf="parent" + motion:layout_constraintStart_toStartOf="parent"> Date: Wed, 25 Jan 2023 01:54:35 +0100 Subject: [PATCH 05/10] Adapt the style of the image activity to the rest of the application --- androidApp/src/main/AndroidManifest.xml | 3 ++- .../amine/apps/readerforselfossv2/android/ImageActivity.kt | 2 +- androidApp/src/main/res/layout/activity_image.xml | 7 ++----- androidApp/src/main/res/values/styles.xml | 4 ++++ 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/androidApp/src/main/AndroidManifest.xml b/androidApp/src/main/AndroidManifest.xml index 6709e23..ee32159 100644 --- a/androidApp/src/main/AndroidManifest.xml +++ b/androidApp/src/main/AndroidManifest.xml @@ -69,7 +69,8 @@ android:name=".ReaderActivity"> + android:name=".ImageActivity" + android:theme="@style/Theme.AppCompat.Translucent"> @@ -48,6 +47,7 @@ class ImageActivity : AppCompatActivity() { override fun onTransitionCompleted(motionLayout: MotionLayout?, currentId: Int) { if (motionLayout?.currentState == binding.root.endState) { onBackPressedDispatcher.onBackPressed() + overridePendingTransition(0, 0) } } diff --git a/androidApp/src/main/res/layout/activity_image.xml b/androidApp/src/main/res/layout/activity_image.xml index fbf442f..632163a 100644 --- a/androidApp/src/main/res/layout/activity_image.xml +++ b/androidApp/src/main/res/layout/activity_image.xml @@ -9,12 +9,9 @@ + android:layout_height="wrap_content"> - @color/white @color/white + + From be7cae365ae181fb15ff5f94a86dafcd93d666ef Mon Sep 17 00:00:00 2001 From: davidoskky Date: Wed, 25 Jan 2023 02:09:41 +0100 Subject: [PATCH 06/10] Rename activity style to avoid interferences --- androidApp/src/main/AndroidManifest.xml | 2 +- androidApp/src/main/res/values/styles.xml | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/androidApp/src/main/AndroidManifest.xml b/androidApp/src/main/AndroidManifest.xml index ee32159..9c51a4a 100644 --- a/androidApp/src/main/AndroidManifest.xml +++ b/androidApp/src/main/AndroidManifest.xml @@ -70,7 +70,7 @@ + android:theme="@style/Theme.AppCompat.ImageActivity"> @color/white - From a549169a7c6b8585d7e3d3420b1ae25caf0ead2e Mon Sep 17 00:00:00 2001 From: davidoskky Date: Wed, 25 Jan 2023 10:27:38 +0100 Subject: [PATCH 07/10] Add a dark hue to the underlying article when swiping to close images --- androidApp/src/main/res/values/colors.xml | 1 + androidApp/src/main/res/values/styles.xml | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/androidApp/src/main/res/values/colors.xml b/androidApp/src/main/res/values/colors.xml index 1e45a00..2505bff 100644 --- a/androidApp/src/main/res/values/colors.xml +++ b/androidApp/src/main/res/values/colors.xml @@ -12,4 +12,5 @@ @color/colorAccent @color/pink #FF282828 + #33000000 diff --git a/androidApp/src/main/res/values/styles.xml b/androidApp/src/main/res/values/styles.xml index 01bbc0d..9ba9049 100644 --- a/androidApp/src/main/res/values/styles.xml +++ b/androidApp/src/main/res/values/styles.xml @@ -28,7 +28,7 @@ From 3f1f86a78eaaebad04ed18441380b954373e6326 Mon Sep 17 00:00:00 2001 From: davidoskky Date: Wed, 25 Jan 2023 10:34:03 +0100 Subject: [PATCH 08/10] Adjust the image closing animation --- androidApp/src/main/res/xml/image_close_scene.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/androidApp/src/main/res/xml/image_close_scene.xml b/androidApp/src/main/res/xml/image_close_scene.xml index 79ee284..2e3f356 100644 --- a/androidApp/src/main/res/xml/image_close_scene.xml +++ b/androidApp/src/main/res/xml/image_close_scene.xml @@ -6,7 +6,7 @@ From 014858f06b36079e3a857f6ade08cb31a938d3cf Mon Sep 17 00:00:00 2001 From: davidoskky Date: Wed, 25 Jan 2023 20:40:20 +0100 Subject: [PATCH 09/10] Remove unused import --- .../apps/readerforselfossv2/android/fragments/ImageFragment.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/fragments/ImageFragment.kt b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/fragments/ImageFragment.kt index d8ac8c0..7b46b8c 100644 --- a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/fragments/ImageFragment.kt +++ b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/fragments/ImageFragment.kt @@ -4,7 +4,6 @@ import android.os.Bundle import android.view.LayoutInflater import android.view.View import android.view.ViewGroup -import androidx.constraintlayout.motion.widget.MotionLayout import androidx.fragment.app.Fragment import bou.amine.apps.readerforselfossv2.android.databinding.FragmentImageBinding import com.bumptech.glide.Glide From 2245565f9586d3078a4f3e48074d39f0257d48d8 Mon Sep 17 00:00:00 2001 From: davidoskky Date: Wed, 25 Jan 2023 21:25:32 +0100 Subject: [PATCH 10/10] Remove unnecessary definition --- .../bou/amine/apps/readerforselfossv2/android/ImageActivity.kt | 2 -- 1 file changed, 2 deletions(-) diff --git a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/ImageActivity.kt b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/ImageActivity.kt index 1799e6b..c566ab9 100644 --- a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/ImageActivity.kt +++ b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/ImageActivity.kt @@ -34,8 +34,6 @@ class ImageActivity : AppCompatActivity() { val transitionListener = object : MotionLayout.TransitionListener { override fun onTransitionStarted(motionLayout: MotionLayout?, startId: Int, endId: Int) { - binding.root.setOnClickListener { - } // Nothing }