diff --git a/app/src/main/kotlin/com/kroegerama/reswista/ui/AcMain.kt b/app/src/main/kotlin/com/kroegerama/reswista/ui/AcMain.kt index 1b34750..f21e1b1 100644 --- a/app/src/main/kotlin/com/kroegerama/reswista/ui/AcMain.kt +++ b/app/src/main/kotlin/com/kroegerama/reswista/ui/AcMain.kt @@ -2,8 +2,10 @@ package com.kroegerama.reswista.ui import androidx.activity.viewModels import androidx.navigation.fragment.NavHostFragment +import androidx.navigation.navOptions import androidx.navigation.ui.setupWithNavController import com.kroegerama.kaiteki.baseui.ViewBindingActivity +import com.kroegerama.kaiteki.onClick import com.kroegerama.reswista.R import com.kroegerama.reswista.controller.Persistence import com.kroegerama.reswista.databinding.AcMainBinding @@ -27,5 +29,9 @@ class AcMain : ViewBindingActivity(AcMainBinding::inflate) { val navController = (supportFragmentManager.findFragmentById(R.id.navHost) as NavHostFragment).navController setSupportActionBar(toolbar) toolbar.setupWithNavController(navController) + + btnSwitchFrag.onClick { + navController.navigate(R.id.fragStart)//, null, navOptions { popUpTo(R.id.main_nav) { inclusive = true } }) + } } } diff --git a/app/src/main/kotlin/com/kroegerama/reswista/ui/FragStart.kt b/app/src/main/kotlin/com/kroegerama/reswista/ui/FragStart.kt index 685a7ee..fb873fa 100644 --- a/app/src/main/kotlin/com/kroegerama/reswista/ui/FragStart.kt +++ b/app/src/main/kotlin/com/kroegerama/reswista/ui/FragStart.kt @@ -5,8 +5,10 @@ import android.graphics.Color import androidx.fragment.app.activityViewModels import androidx.recyclerview.widget.ConcatAdapter import androidx.recyclerview.widget.RecyclerView +import com.google.android.material.transition.MaterialFadeThrough import com.kroegerama.kaiteki.baseui.ViewBindingFragment import com.kroegerama.kaiteki.onClick +import com.kroegerama.kaiteki.postponeUntilLayout import com.kroegerama.kaiteki.recyclerview.ViewBindingBaseViewHolder import com.kroegerama.reswista.R import com.kroegerama.reswista.StackDirection @@ -28,7 +30,14 @@ class FragStart : ViewBindingFragment( private val itemAdapter by lazy { ItemAdapter() } + override fun prepare() { + enterTransition = MaterialFadeThrough() + exitTransition = MaterialFadeThrough() + } + override fun FragStartBinding.setupGUI() { + postponeUntilLayout(recycler) + val config = SwiperConfig( showCount = 5, swipeDirections = SwipeDirection.LEFT or SwipeDirection.RIGHT or SwipeDirection.UP, @@ -58,7 +67,7 @@ class FragStart : ViewBindingFragment( val startColor = requireContext().getColor(R.color.primary) val endColor = requireContext().getColor(R.color.secondary) val evaluator = ArgbEvaluator() - val count = 10 + val count = 3 fun getColor(pos: Int): Int { val fraction = (pos - 1f) / count diff --git a/app/src/main/res/layout/ac_main.xml b/app/src/main/res/layout/ac_main.xml index d2ee78c..1651f00 100644 --- a/app/src/main/res/layout/ac_main.xml +++ b/app/src/main/res/layout/ac_main.xml @@ -17,8 +17,15 @@ android:id="@+id/navHost" android:name="androidx.navigation.fragment.NavHostFragment" android:layout_width="match_parent" - android:layout_height="match_parent" + android:layout_height="0dp" + android:layout_weight="1" app:defaultNavHost="true" app:navGraph="@navigation/main_nav" /> + + \ No newline at end of file diff --git a/buildSrc/src/main/kotlin/ProjectInfo.kt b/buildSrc/src/main/kotlin/ProjectInfo.kt index 5c7b46d..09f8e5f 100644 --- a/buildSrc/src/main/kotlin/ProjectInfo.kt +++ b/buildSrc/src/main/kotlin/ProjectInfo.kt @@ -1,5 +1,5 @@ object P { - const val projectVersion = "0.9.2" + const val projectVersion = "0.9.3" const val projectGroupId = "com.kroegerama" const val libraryArtifactId = "recycler-swipe-stack" diff --git a/library/src/main/kotlin/com/kroegerama/reswista/StackLayoutManager.kt b/library/src/main/kotlin/com/kroegerama/reswista/StackLayoutManager.kt index bdcc10f..4cf9181 100644 --- a/library/src/main/kotlin/com/kroegerama/reswista/StackLayoutManager.kt +++ b/library/src/main/kotlin/com/kroegerama/reswista/StackLayoutManager.kt @@ -4,22 +4,26 @@ import android.view.View import android.view.ViewGroup import androidx.recyclerview.widget.RecyclerView import com.kroegerama.kaiteki.scale +import timber.log.Timber class StackLayoutManager( private val config: SwiperConfig = SwiperConfig() ) : RecyclerView.LayoutManager() { override fun generateDefaultLayoutParams(): RecyclerView.LayoutParams = - RecyclerView.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT) + RecyclerView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT) override fun onLayoutChildren(recycler: RecyclerView.Recycler, state: RecyclerView.State) { detachAndScrapAttachedViews(recycler) val showCount = config.showCount + val itemCount = state.itemCount + if (itemCount > showCount) { for (pos in showCount downTo 0) { val layout = recycler.getViewForPosition(pos) addAndMeasureView(layout) + layout.translationZ = (-pos).toFloat() when { pos == showCount -> { @@ -37,6 +41,7 @@ class StackLayoutManager( for (pos in itemCount - 1 downTo 0) { val layout = recycler.getViewForPosition(pos) addAndMeasureView(layout) + layout.translationZ = (-pos).toFloat() when { pos > 0 -> { @@ -66,15 +71,23 @@ class StackLayoutManager( } private fun View.resetTransitions() { - clearAnimation() scale(1f) translationX = 0f translationY = 0f - animate().alpha(1f) } private fun View.scaleAndTranslateForPosition(pos: Int) { - clearAnimation() + scale(1f - pos * config.itemScale) + val itemTranslate = config.itemTranslate + when (config.stackDirection) { + StackDirection.Left -> translationX = -pos * measuredWidth * itemTranslate + StackDirection.Up -> translationY = -pos * measuredHeight * itemTranslate + StackDirection.Right -> translationX = pos * measuredWidth * itemTranslate + StackDirection.Down -> translationY = pos * measuredHeight * itemTranslate + } + } + + private fun View.scaleAndTranslateForPositionAnimated(pos: Int) { animate().apply { val scale = 1f - pos * config.itemScale scaleX(scale) diff --git a/library/src/main/kotlin/com/kroegerama/reswista/Utils.kt b/library/src/main/kotlin/com/kroegerama/reswista/Utils.kt index ace52a7..8683b6c 100644 --- a/library/src/main/kotlin/com/kroegerama/reswista/Utils.kt +++ b/library/src/main/kotlin/com/kroegerama/reswista/Utils.kt @@ -8,7 +8,6 @@ fun RecyclerView.setupStack( listener: SwipeListener, block: (RecyclerView.() -> Unit)? = null ) { - itemAnimator = null layoutManager = StackLayoutManager(config) ItemTouchHelper(StackSwipeTouchHelperCallback(listener, config)).attachToRecyclerView(this) block?.invoke(this)