Skip to content
This repository was archived by the owner on Aug 22, 2024. It is now read-only.

Commit 8c7241c

Browse files
committed
[REFACTOR] [#2] Layout names with convention to find them in a group.
1 parent 0e14975 commit 8c7241c

File tree

5 files changed

+14
-8
lines changed

5 files changed

+14
-8
lines changed

app/src/main/java/com/hossainkhan/android/demo/data/LayoutDataStore.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ class LayoutDataStore @Inject constructor(
2828
private val resources: Resources) {
2929
val supportedLayoutInfos = listOf(
3030
LayoutInformation(
31-
layoutResourceId = R.layout.activity_positioning_top_left,
31+
layoutResourceId = R.layout.preview_positioning_top_left,
3232
title = "Positioning: Top Left",
3333
description = "Top left using constraints."),
3434
LayoutInformation(
35-
layoutResourceId = R.layout.activity_positioning_centered,
35+
layoutResourceId = R.layout.preview_positioning_centered,
3636
title = "Positioning: Centered",
3737
description = "Centered view using constraints on top-bottom and left-right.")
3838
)
@@ -52,7 +52,7 @@ class LayoutDataStore @Inject constructor(
5252
*/
5353
fun getLayoutUrl(@LayoutRes layoutResourceId: Int): String {
5454
// Containes package name and layout name
55-
// com.hossainkhan.android.demo:layout/activity_positioning_top_left
55+
// com.hossainkhan.android.demo:layout/preview_positioning_top_left
5656
val resourceName = resources.getResourceName(layoutResourceId)
5757

5858
if(!resourceName.contains("layout")) {

app/src/main/res/layout/.README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Constraint Layouts
2+
==================
3+
All the constraint layout for preview are defined here along with activity layouts.
4+
5+
For quick navigation, all the preview/demo layout should be prefixed with `preview_`
6+
7+
All layout should be documented well and minimal style should be added to element.

app/src/main/res/layout/activity_positioning_centered.xml renamed to app/src/main/res/layout/preview_positioning_centered.xml

File renamed without changes.

app/src/main/res/layout/activity_positioning_top_left.xml renamed to app/src/main/res/layout/preview_positioning_top_left.xml

File renamed without changes.

app/src/test/java/com/hossainkhan/android/demo/data/LayoutDataStoreTest.kt

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ package com.hossainkhan.android.demo.data
1919
import android.content.res.Resources
2020
import org.junit.Assert.assertEquals
2121
import org.junit.Assert.assertFalse
22-
import org.junit.Assert.assertNull
2322
import org.junit.Before
2423
import org.junit.Test
2524
import org.mockito.Mockito
@@ -46,18 +45,18 @@ class LayoutDataStoreTest {
4645
* Tests conversion from layout file to URL to preview on the web.
4746
*
4847
* Input:
49-
* com.hossainkhan.android.demo:layout/activity_positioning_top_left
48+
* com.hossainkhan.android.demo:layout/preview_positioning_top_left
5049
*
5150
* Output:
52-
* https://github.com/amardeshbd/android-constraint-layout-cheatsheet/blob/master/app/src/main/res/layout/activity_positioning_top_left.xml
51+
* https://github.com/amardeshbd/android-constraint-layout-cheatsheet/blob/master/app/src/main/res/layout/preview_positioning_top_leftxml
5352
*/
5453
@Test
5554
fun getLayoutUrl_givenValidLayout_providesUrlToLayoutResource() {
5655
`when`(resources.getResourceName(anyInt()))
57-
.thenReturn("com.hossainkhan.android.demo:layout/activity_positioning_top_left")
56+
.thenReturn("com.hossainkhan.android.demo:layout/preview_positioning_top_left")
5857

5958

60-
assertEquals("https://github.com/amardeshbd/android-constraint-layout-cheatsheet/blob/master/app/src/main/res/layout/activity_positioning_top_left.xml",
59+
assertEquals("https://github.com/amardeshbd/android-constraint-layout-cheatsheet/blob/master/app/src/main/res/layout/preview_positioning_top_left.xml",
6160
sut.getLayoutUrl(1))
6261
}
6362

0 commit comments

Comments
 (0)