2019-01-29 20:20:29 +01:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
2019-07-12 20:38:15 +02:00
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2019-01-29 20:20:29 +01:00
|
|
|
|
|
|
|
package org.mozilla.fenix.search
|
|
|
|
|
|
|
|
import androidx.constraintlayout.widget.ConstraintLayout
|
|
|
|
import androidx.constraintlayout.widget.ConstraintLayout.LayoutParams.PARENT_ID
|
2019-12-20 03:16:50 +01:00
|
|
|
import androidx.constraintlayout.widget.ConstraintLayout.LayoutParams.TOP
|
|
|
|
import androidx.constraintlayout.widget.ConstraintLayout.LayoutParams.BOTTOM
|
|
|
|
import androidx.constraintlayout.widget.ConstraintSet
|
2019-01-29 20:20:29 +01:00
|
|
|
import androidx.recyclerview.widget.LinearLayoutManager
|
2019-01-31 00:51:49 +01:00
|
|
|
import kotlinx.android.synthetic.main.component_awesomebar.*
|
2019-01-29 20:20:29 +01:00
|
|
|
import kotlinx.android.synthetic.main.fragment_search.*
|
|
|
|
import mozilla.components.support.base.log.logger.Logger
|
|
|
|
import org.mozilla.fenix.Experiments.AATestDescriptor
|
|
|
|
import org.mozilla.fenix.isInExperiment
|
|
|
|
|
|
|
|
internal fun SearchFragment.layoutComponents(layout: ConstraintLayout) {
|
|
|
|
context?.let {
|
|
|
|
when {
|
|
|
|
it.isInExperiment(AATestDescriptor) -> {
|
|
|
|
setInExperimentConstraints(layout)
|
|
|
|
}
|
|
|
|
else -> {
|
|
|
|
setOutOfExperimentConstraints(layout)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} // we're unattached if context is null
|
|
|
|
}
|
|
|
|
|
|
|
|
internal fun SearchFragment.setInExperimentConstraints(layout: ConstraintLayout) {
|
|
|
|
Logger.debug("Loading in experiment constraints")
|
2019-12-20 03:16:50 +01:00
|
|
|
|
|
|
|
ConstraintSet().apply {
|
|
|
|
clone(layout)
|
|
|
|
|
|
|
|
// Move the search bar to the bottom of the layout
|
|
|
|
clear(toolbar_wrapper.id, TOP)
|
2019-12-23 17:15:34 +01:00
|
|
|
connect(toolbar_wrapper.id, BOTTOM, pill_wrapper.id, TOP)
|
2019-12-20 03:16:50 +01:00
|
|
|
|
|
|
|
connect(awesomeBar.id, TOP, PARENT_ID, TOP)
|
|
|
|
connect(awesomeBar.id, BOTTOM, toolbar_wrapper.id, TOP)
|
2019-01-29 20:20:29 +01:00
|
|
|
(awesomeBar.layoutManager as? LinearLayoutManager)?.reverseLayout = true
|
2019-12-20 03:16:50 +01:00
|
|
|
|
2019-12-23 17:15:34 +01:00
|
|
|
connect(pill_wrapper.id, BOTTOM, PARENT_ID, BOTTOM)
|
2019-12-20 03:16:50 +01:00
|
|
|
|
|
|
|
applyTo(layout)
|
2019-01-29 20:20:29 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
internal fun SearchFragment.setOutOfExperimentConstraints(layout: ConstraintLayout) {
|
|
|
|
Logger.debug("Loading out of experiment constraints")
|
2019-12-20 03:16:50 +01:00
|
|
|
|
|
|
|
ConstraintSet().apply {
|
|
|
|
clone(layout)
|
|
|
|
|
|
|
|
// Move the search bar to the top of the layout
|
|
|
|
connect(toolbar_wrapper.id, TOP, PARENT_ID, TOP)
|
|
|
|
clear(toolbar_wrapper.id, BOTTOM)
|
|
|
|
|
|
|
|
connect(fill_link_from_clipboard.id, TOP, toolbar_wrapper.id, BOTTOM)
|
|
|
|
|
|
|
|
clear(awesomeBar.id, TOP)
|
|
|
|
connect(awesomeBar.id, TOP, search_with_shortcuts.id, BOTTOM)
|
2019-12-23 17:15:34 +01:00
|
|
|
connect(awesomeBar.id, BOTTOM, pill_wrapper.id, TOP)
|
2019-01-29 20:20:29 +01:00
|
|
|
(awesomeBar.layoutManager as? LinearLayoutManager)?.reverseLayout = false
|
2019-12-20 03:16:50 +01:00
|
|
|
|
2019-12-23 17:15:34 +01:00
|
|
|
connect(pill_wrapper.id, BOTTOM, PARENT_ID, BOTTOM)
|
2019-12-20 03:16:50 +01:00
|
|
|
|
|
|
|
applyTo(layout)
|
2019-01-29 20:20:29 +01:00
|
|
|
}
|
|
|
|
}
|