-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #204 from rubensousa/fix-grid-alignment
Fix grid not aligning correctly to keyline
- Loading branch information
Showing
6 changed files
with
106 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
...roidTest/kotlin/com/rubensousa/dpadrecyclerview/test/tests/alignment/GridAlignmentTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/* | ||
* Copyright 2022 Rúben Sousa | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.rubensousa.dpadrecyclerview.test.tests.alignment | ||
|
||
import androidx.recyclerview.widget.RecyclerView | ||
import com.google.common.truth.Truth.assertThat | ||
import com.rubensousa.dpadrecyclerview.ChildAlignment | ||
import com.rubensousa.dpadrecyclerview.ParentAlignment | ||
import com.rubensousa.dpadrecyclerview.ParentAlignment.Edge | ||
import com.rubensousa.dpadrecyclerview.test.TestAdapterConfiguration | ||
import com.rubensousa.dpadrecyclerview.test.TestLayoutConfiguration | ||
import com.rubensousa.dpadrecyclerview.test.helpers.getItemViewBounds | ||
import com.rubensousa.dpadrecyclerview.test.helpers.getRecyclerViewBounds | ||
import com.rubensousa.dpadrecyclerview.test.helpers.waitForIdleScrollState | ||
import com.rubensousa.dpadrecyclerview.test.tests.DpadRecyclerViewTest | ||
import com.rubensousa.dpadrecyclerview.testing.KeyEvents | ||
import com.rubensousa.dpadrecyclerview.testing.R | ||
import com.rubensousa.dpadrecyclerview.testing.rules.DisableIdleTimeoutRule | ||
import org.junit.Rule | ||
import org.junit.Test | ||
|
||
class GridAlignmentTest : DpadRecyclerViewTest() { | ||
|
||
@get:Rule | ||
val idleTimeoutRule = DisableIdleTimeoutRule() | ||
|
||
override fun getDefaultAdapterConfiguration(): TestAdapterConfiguration { | ||
return super.getDefaultAdapterConfiguration().copy( | ||
numberOfItems = 50, | ||
itemLayoutId = R.layout.dpadrecyclerview_test_item_grid | ||
) | ||
} | ||
|
||
override fun getDefaultLayoutConfiguration(): TestLayoutConfiguration { | ||
return TestLayoutConfiguration( | ||
spans = 5, | ||
orientation = RecyclerView.VERTICAL, | ||
parentAlignment = ParentAlignment( | ||
edge = Edge.NONE, | ||
offset = 0, | ||
fraction = 0.5f | ||
), | ||
childAlignment = ChildAlignment( | ||
offset = 0, | ||
fraction = 0.5f | ||
) | ||
) | ||
} | ||
|
||
@Test | ||
fun testItemInFirstColumnAndLastRowIsAlignedToTheCenter() { | ||
launchFragment() | ||
|
||
// given | ||
val recyclerViewBounds = getRecyclerViewBounds() | ||
val itemViewBounds = getItemViewBounds(position = 0) | ||
|
||
// when | ||
repeat(10) { | ||
KeyEvents.pressDown() | ||
waitForIdleScrollState() | ||
} | ||
|
||
// then | ||
val bounds = getChildrenBounds(position = 45) | ||
assertThat(bounds.top) | ||
.isEqualTo(recyclerViewBounds.height() / 2 - itemViewBounds.height() / 2) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters