Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Anddep 1104 dialog navigation command animations #9

Open
wants to merge 3 commits into
base: dev/G-0.5.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion navigation/RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@
* ANDDEP-1110 Add removeAll and removeUntil fragment animations
* Fix RemoveUntil command execution for single removal
* Add methods to listen for changes of tab head in TabFragmentNavigator
* Update removeUntil and removeAll animations: now they inherit animations from the first fragment of the removing bunch.
* Update removeUntil and removeAll animations: now they inherit animations from the first fragment of the removing bunch.
* ANDDEP-1104 added `StyledAnimations` for dialog appear animation
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,8 @@ object DefaultAnimations {
/**
* Animations to be executed for each
* [ru.surfstudio.android.navigation.command.dialog.base.DialogNavigationCommand].
*
* Warning! Dialog animations are not yet implemented.
*/
@Deprecated("Dialog animations are not yet implemented.")
var dialog: Animations = NoResourceAnimations
var dialog: Animations = EmptyResourceAnimations

/**
* Animations to be executed for each WidgetNavigationCommand
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package ru.surfstudio.android.navigation.animation.styled

import androidx.annotation.StyleRes
import ru.surfstudio.android.navigation.animation.Animations
import java.io.Serializable

/**
* Style resources based animations
*
* @param style style resource
*/
data class StyledAnimations(
@StyleRes val style: Int
) : Animations, Serializable
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import ru.surfstudio.android.navigation.animation.Animations
import ru.surfstudio.android.navigation.animation.resource.BaseResourceAnimations
import ru.surfstudio.android.navigation.animation.set.SetAnimations
import ru.surfstudio.android.navigation.animation.shared.SharedElementAnimations
import ru.surfstudio.android.navigation.animation.styled.StyledAnimations

/**
* Supplier which is responsible for inflating Activity transition with animations.
Expand Down Expand Up @@ -38,6 +39,8 @@ open class ActivityAnimationSupplier {
setSharedElementAnimations(activity, options, animations)
is BaseResourceAnimations ->
setResourceAnimations(activity, options, animations)
is StyledAnimations ->
throw UnsupportedOperationException("StyledAnimations is only for dialogs")
else -> null
}
}
Expand All @@ -51,11 +54,11 @@ open class ActivityAnimationSupplier {
*
* @return [Bundle] options with animations
*/
fun setResourceAnimations(
private fun setResourceAnimations(
context: Context,
options: Bundle?,
animations: BaseResourceAnimations
): Bundle? {
): Bundle {
val resourceAnimations = ActivityOptionsCompat.makeCustomAnimation(
context,
animations.enterAnimation,
Expand All @@ -75,11 +78,11 @@ open class ActivityAnimationSupplier {
*
* @return [Bundle] options with animations
*/
fun setSharedElementAnimations(
private fun setSharedElementAnimations(
activity: Activity,
options: Bundle?,
animations: SharedElementAnimations
): Bundle? {
): Bundle {
val sharedElements = animations.sharedElements
.map { androidx.core.util.Pair(it.sharedView, it.transitionName) }
val resourceAnimations =
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package ru.surfstudio.android.navigation.animation.utils

import androidx.fragment.app.DialogFragment
import ru.surfstudio.android.navigation.animation.Animations
import ru.surfstudio.android.navigation.animation.styled.StyledAnimations

/**
* Supplier which is responsible for inflating DialogFragments with animations.
*/
open class DialogAnimationSupplier {

/**
* Supplies animations to [DialogFragment]
*
* @param dialog dialog which animates
* @param animations animations object, only [StyledAnimations] support
*/
fun supplyWithAnimations(dialog: DialogFragment, animations: Animations) {
if (animations is StyledAnimations) {
setResourceAnimations(dialog, animations)
}
}

/**
* Sets windowAnimation to [DialogFragment]'s dialog
*/
private fun setResourceAnimations(dialogFragment: DialogFragment, animations: StyledAnimations) {
dialogFragment.dialog?.window?.setWindowAnimations(animations.style)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import ru.surfstudio.android.navigation.animation.Animations
import ru.surfstudio.android.navigation.animation.resource.BaseResourceAnimations
import ru.surfstudio.android.navigation.animation.set.SetAnimations
import ru.surfstudio.android.navigation.animation.shared.SharedElementAnimations
import ru.surfstudio.android.navigation.animation.styled.StyledAnimations

/**
* Supplier, which is responsible for inflating [FragmentTransaction] with animations.
Expand All @@ -25,6 +26,9 @@ open class FragmentAnimationSupplier {
setResourceAnimations(transaction, animations, false)
is SharedElementAnimations ->
setSharedElementAnimations(transaction, animations)
is StyledAnimations ->
throw UnsupportedOperationException("StyledAnimations is only for dialogs")

}
return transaction
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@ package ru.surfstudio.android.navigation.command.dialog

import ru.surfstudio.android.navigation.animation.Animations
import ru.surfstudio.android.navigation.animation.DefaultAnimations
import ru.surfstudio.android.navigation.animation.resource.NoResourceAnimations
import ru.surfstudio.android.navigation.command.dialog.base.DialogNavigationCommand
import ru.surfstudio.android.navigation.route.dialog.DialogRoute

/**
* Dismiss dialog from the screen
*/
data class Dismiss(override val route: DialogRoute) : DialogNavigationCommand {

override val animations: Animations = DefaultAnimations.dialog
}
data class Dismiss(
override val route: DialogRoute,
override val animations: Animations = DefaultAnimations.dialog
) : DialogNavigationCommand
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@ package ru.surfstudio.android.navigation.command.dialog

import ru.surfstudio.android.navigation.animation.Animations
import ru.surfstudio.android.navigation.animation.DefaultAnimations
import ru.surfstudio.android.navigation.animation.resource.EmptyResourceAnimations
import ru.surfstudio.android.navigation.animation.resource.NoResourceAnimations
import ru.surfstudio.android.navigation.command.dialog.base.DialogNavigationCommand
import ru.surfstudio.android.navigation.route.dialog.DialogRoute

/**
* Show dialog on the screen
*/
data class Show(override val route: DialogRoute) : DialogNavigationCommand {

override val animations: Animations = DefaultAnimations.dialog
}
data class Show(
override val route: DialogRoute,
override val animations: Animations = DefaultAnimations.dialog
) : DialogNavigationCommand
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ open class DialogCommandExecutor(

override fun execute(command: DialogNavigationCommand) {
when (command) {
is Show -> dialogNavigator.show(command.route)
is Dismiss -> dialogNavigator.dismiss(command.route)
is Show -> dialogNavigator.show(command.route, command.animations)
is Dismiss -> dialogNavigator.dismiss(command.route, command.animations)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,25 @@ package ru.surfstudio.android.navigation.navigator.dialog

import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.DialogFragment
import ru.surfstudio.android.navigation.animation.Animations
import ru.surfstudio.android.navigation.animation.utils.DialogAnimationSupplier
import ru.surfstudio.android.navigation.route.dialog.DialogRoute

class DialogNavigator(val activity: AppCompatActivity) : DialogNavigatorInterface {

override fun show(route: DialogRoute) {
private var animationSupplier = DialogAnimationSupplier()

override fun show(route: DialogRoute, animations: Animations) {
val tag = route.getId()
val dialog = route.createDialog()
dialog.show(activity.supportFragmentManager, tag)
dialog.showNow(activity.supportFragmentManager, tag)
animationSupplier.supplyWithAnimations(dialog, animations)
}

override fun dismiss(route: DialogRoute) {
override fun dismiss(route: DialogRoute, animations: Animations) {
val tag = route.getId()
val dialog = activity.supportFragmentManager.findFragmentByTag(tag) as? DialogFragment
dialog?.let { animationSupplier.supplyWithAnimations(it, animations) }
dialog?.dismiss()
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package ru.surfstudio.android.navigation.navigator.dialog

import ru.surfstudio.android.navigation.animation.Animations
import ru.surfstudio.android.navigation.route.dialog.DialogRoute

interface DialogNavigatorInterface {

fun show(route: DialogRoute)
fun show(route: DialogRoute, animations: Animations)

fun dismiss(route: DialogRoute)
fun dismiss(route: DialogRoute, animations: Animations)
}
4 changes: 4 additions & 0 deletions navigation/sample-standard/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@
android:name=".screen.main.MainActivityView"
android:label="Main Activity" />

<activity
android:name=".screen.dialogs.DialogsActivityView"
android:label="Dialogs Activity" />

</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package ru.surfstudio.android.navigation.sample_standard.screen.dialogs

import android.os.Bundle
import android.os.PersistableBundle
import com.jakewharton.rxbinding2.view.clicks
import kotlinx.android.synthetic.main.activity_dialogs.*
import ru.surfstudio.android.core.mvp.binding.rx.ui.BaseRxActivityView
import ru.surfstudio.android.navigation.sample_standard.R
import javax.inject.Inject

class DialogsActivityView : BaseRxActivityView() {

@Inject
lateinit var bm: DialogsBindModel

override fun createConfigurator() = DialogsScreenConfigurator(intent)

override fun getContentView(): Int = R.layout.activity_dialogs

override fun getScreenName(): String = "Dialogs"

override fun onCreate(savedInstanceState: Bundle?, persistentState: PersistableBundle?, viewRecreated: Boolean) {
super.onCreate(savedInstanceState, persistentState, viewRecreated)

dialogs_default_btn.clicks() bindTo { bm.openDialogButtonClicked.accept() }
dialogs_fade_btn.clicks() bindTo { bm.openDialogWithFadeButtonClicked.accept() }
dialogs_slide_btn.clicks() bindTo { bm.openDialogWithSlideButtonClicked.accept() }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package ru.surfstudio.android.navigation.sample_standard.screen.dialogs

import ru.surfstudio.android.core.mvp.binding.rx.relation.mvp.Action
import ru.surfstudio.android.dagger.scope.PerScreen
import javax.inject.Inject

@PerScreen
class DialogsBindModel @Inject constructor() {
val openDialogButtonClicked = Action<Unit>()
val openDialogWithFadeButtonClicked = Action<Unit>()
val openDialogWithSlideButtonClicked = Action<Unit>()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package ru.surfstudio.android.navigation.sample_standard.screen.dialogs

import ru.surfstudio.android.core.mvp.binding.rx.ui.BaseRxPresenter
import ru.surfstudio.android.core.mvp.presenter.BasePresenterDependency
import ru.surfstudio.android.dagger.scope.PerScreen
import ru.surfstudio.android.navigation.animation.styled.StyledAnimations
import ru.surfstudio.android.navigation.command.dialog.Show
import ru.surfstudio.android.navigation.executor.NavigationCommandExecutor
import ru.surfstudio.android.navigation.sample_standard.R
import ru.surfstudio.android.navigation.sample_standard.screen.base.presenter.CommandExecutionPresenter
import ru.surfstudio.android.navigation.sample_standard.screen.dialogs.amazing.AmazingDialogRoute
import javax.inject.Inject

@PerScreen
class DialogsPresenter @Inject constructor(
basePresenterDependency: BasePresenterDependency,
private val bm: DialogsBindModel,
override val commandExecutor: NavigationCommandExecutor
) : BaseRxPresenter(basePresenterDependency), CommandExecutionPresenter {

override fun onFirstLoad() {
bm.openDialogButtonClicked bindTo { openDialog() }
bm.openDialogWithFadeButtonClicked bindTo { openDialogWithFade() }
bm.openDialogWithSlideButtonClicked bindTo { openDialogWithSlide() }
}

private fun openDialog() {
Show(AmazingDialogRoute()).execute()
}

private fun openDialogWithFade() {
Show(AmazingDialogRoute(), StyledAnimations(R.style.FadeDialogAnimation)).execute()
}

private fun openDialogWithSlide() {
Show(AmazingDialogRoute(), StyledAnimations(R.style.SlideDialogAnimation)).execute()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package ru.surfstudio.android.navigation.sample_standard.screen.dialogs

import androidx.appcompat.app.AppCompatActivity
import ru.surfstudio.android.navigation.route.activity.ActivityRoute

class DialogsRoute : ActivityRoute() {
override fun getScreenClass(): Class<out AppCompatActivity> = DialogsActivityView::class.java
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package ru.surfstudio.android.navigation.sample_standard.screen.dialogs

import android.content.Intent
import dagger.Component
import dagger.Module
import dagger.Provides
import ru.surfstudio.android.core.mvp.configurator.BindableScreenComponent
import ru.surfstudio.android.core.mvp.configurator.ScreenComponent
import ru.surfstudio.android.dagger.scope.PerScreen
import ru.surfstudio.android.navigation.sample_standard.di.ui.ActivityComponent
import ru.surfstudio.android.navigation.sample_standard.di.ui.configurator.ActivityScreenConfigurator
import ru.surfstudio.android.navigation.sample_standard.di.ui.screen.ScreenModule
import ru.surfstudio.android.sample.dagger.ui.base.dagger.screen.DefaultActivityScreenModule

/**
* Конфигуратор активити главного экрана
*/
class DialogsScreenConfigurator(intent: Intent) : ActivityScreenConfigurator(intent) {
@PerScreen
@Component(dependencies = [ActivityComponent::class],
modules = [DefaultActivityScreenModule::class, DialogsScreenModule::class])
internal interface DialogsScreenComponent
: BindableScreenComponent<DialogsActivityView>

@Module
internal class DialogsScreenModule : ScreenModule() {

@Provides
@PerScreen
fun providePresenters(presenter: DialogsPresenter) = Any()
}

override fun createScreenComponent(defaultActivityComponent: ActivityComponent,
defaultActivityScreenModule: DefaultActivityScreenModule,
intent: Intent): ScreenComponent<*> {
return DaggerDialogsScreenConfigurator_DialogsScreenComponent.builder()
.activityComponent(defaultActivityComponent)
.defaultActivityScreenModule(defaultActivityScreenModule)
.dialogsScreenModule(DialogsScreenModule())
.build()
}
}
Loading