Skip to content

Commit

Permalink
For mozilla-mobile#7698: Adds search back button animation
Browse files Browse the repository at this point in the history
  • Loading branch information
sblatz committed Jan 22, 2020
1 parent 0b1a673 commit 342cda4
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 11 deletions.
21 changes: 18 additions & 3 deletions app/src/main/java/org/mozilla/fenix/search/SearchFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import android.view.ViewStub
import androidx.appcompat.app.AlertDialog
import androidx.core.view.isVisible
import androidx.fragment.app.Fragment
import androidx.interpolator.view.animation.FastOutSlowInInterpolator
import androidx.navigation.fragment.findNavController
import androidx.transition.TransitionInflater
import kotlinx.android.synthetic.main.fragment_search.*
Expand Down Expand Up @@ -132,7 +133,8 @@ class SearchFragment : Fragment(), UserInteractionHandler {
view.toolbar_component_wrapper,
searchInteractor,
historyStorageProvider(),
(activity as HomeActivity).browsingModeManager.mode.isPrivate
(activity as HomeActivity).browsingModeManager.mode.isPrivate,
::animateBackButtonAway
)

val urlView = toolbarView.view
Expand Down Expand Up @@ -198,8 +200,11 @@ class SearchFragment : Fragment(), UserInteractionHandler {
qrFeature.get()?.scan(R.id.container)
}

view.back_button.setOnClickListener {
findNavController().navigateUp()
view.back_button.apply {
setOnClickListener {
animateBackButtonAway()
findNavController().navigateUp()
}
}

val stubListener = ViewStub.OnInflateListener { _, inflated ->
Expand Down Expand Up @@ -352,7 +357,17 @@ class SearchFragment : Fragment(), UserInteractionHandler {
}
}

private fun animateBackButtonAway() {
val xTranslation =
requireView().back_button.width.toFloat() * BACK_BUTTON_ANIMATION_WIDTH_MULTIPLIER

requireView().back_button
.animate()
.translationX(xTranslation).interpolator = FastOutSlowInInterpolator()
}

companion object {
private const val BACK_BUTTON_ANIMATION_WIDTH_MULTIPLIER = -1.5f
private const val SHARED_TRANSITION_MS = 200L
private const val REQUEST_CODE_CAMERA_PERMISSIONS = 1
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ class ToolbarView(
private val container: ViewGroup,
private val interactor: ToolbarInteractor,
private val historyStorage: HistoryStorage?,
private val isPrivate: Boolean
private val isPrivate: Boolean,
private val animateBackButtonAway: () -> Unit
) : LayoutContainer {

override val containerView: View?
Expand Down Expand Up @@ -120,6 +121,7 @@ class ToolbarView(

setOnEditListener(object : mozilla.components.concept.toolbar.Toolbar.OnEditListener {
override fun onCancelEditing(): Boolean {
animateBackButtonAway()
interactor.onEditingCanceled()
// We need to return false to not show display mode
return false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package org.mozilla.fenix.detektrules
import io.gitlab.arturbosch.detekt.api.ConsoleReport
import io.gitlab.arturbosch.detekt.api.Detektion

class CustomRulesetConsoleReport: ConsoleReport() {
class CustomRulesetConsoleReport : ConsoleReport() {
override fun render(detektion: Detektion): String? {
return detektion.findings["mozilla-detekt-rules"]?.fold("") { output, finding ->
output + finding.locationAsString + ": " + finding.messageOrDescription()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import io.gitlab.arturbosch.detekt.api.Config
import io.gitlab.arturbosch.detekt.api.RuleSet
import io.gitlab.arturbosch.detekt.api.RuleSetProvider

class CustomRulesetProvider: RuleSetProvider {
class CustomRulesetProvider : RuleSetProvider {
override val ruleSetId: String = "mozilla-detekt-rules"

override fun instance(config: Config): RuleSet = RuleSet(
Expand All @@ -17,6 +17,4 @@ class CustomRulesetProvider: RuleSetProvider {
MozillaBannedPropertyAccess(config)
)
)


}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import io.gitlab.arturbosch.detekt.api.Rule
import io.gitlab.arturbosch.detekt.api.Severity
import org.jetbrains.kotlin.psi.*

class MozillaBannedPropertyAccess(config: Config = Config.empty): Rule(config) {
class MozillaBannedPropertyAccess(config: Config = Config.empty) : Rule(config) {
override val issue = Issue(
"MozillaBannedPropertyAccess",
Severity.Defect,
Expand All @@ -27,7 +27,6 @@ class MozillaBannedPropertyAccess(config: Config = Config.empty): Rule(config) {
listOf<String>()
} else {
bannedPropertiesList.split(",")

}
}

Expand All @@ -44,7 +43,7 @@ class MozillaBannedPropertyAccess(config: Config = Config.empty): Rule(config) {
CodeSmell(
issue,
Entity.from(expression),
"Using ${possiblyBannedPropertyAccess} is not allowed because accessing property ${it} is against Mozilla policy. See 'mozilla-detekt-rules' stanza in 'config/detekt.yml' for more information.\n"
"Using $possiblyBannedPropertyAccess is not allowed because accessing property $it is against Mozilla policy. See 'mozilla-detekt-rules' stanza in 'config/detekt.yml' for more information.\n"
)
}.forEach { report(it) }
}
Expand Down

0 comments on commit 342cda4

Please sign in to comment.