-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9bbabb7
commit 4f74b67
Showing
29 changed files
with
801 additions
and
30 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
<resources> | ||
<string name="app_name">Biblioteca</string> | ||
<string name="app_name">Biblioteca Sample</string> | ||
</resources> |
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
55 changes: 55 additions & 0 deletions
55
biblioteca/src/main/java/me/padamchopra/biblioteca/BibliotecaPayload.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,55 @@ | ||
package me.padamchopra.biblioteca | ||
|
||
import android.os.Parcelable | ||
import kotlinx.parcelize.Parcelize | ||
import me.padamchopra.biblioteca.models.BibliotecaSection | ||
import me.padamchopra.biblioteca.models.ProvidedColors | ||
import me.padamchopra.biblioteca.models.ProvidedTypography | ||
|
||
@Parcelize | ||
class BibliotecaPayload private constructor( | ||
var themeColors: ProvidedColors? = null, | ||
var themeTypography: ProvidedTypography? = null, | ||
var themeSections: List<BibliotecaSection> = listOf() | ||
): Parcelable { | ||
companion object { | ||
const val EXTRA_KEY = "biblioteca_bundle" | ||
} | ||
|
||
class Builder { | ||
private val mPayload = BibliotecaPayload() | ||
|
||
fun setProvidedColors(colors: ProvidedColors): Builder { | ||
mPayload.themeColors = colors | ||
return this | ||
} | ||
|
||
fun setProvidedColors(colorsBuilder: ProvidedColors.Builder): Builder { | ||
mPayload.themeColors = colorsBuilder.build() | ||
return this | ||
} | ||
|
||
fun setProvidedTypography(typography: ProvidedTypography): Builder { | ||
mPayload.themeTypography = typography | ||
return this | ||
} | ||
|
||
fun setProvidedTypography(typographyBuilder: ProvidedTypography.Builder): Builder { | ||
mPayload.themeTypography = typographyBuilder.build() | ||
return this | ||
} | ||
|
||
fun addExtraThemeSection(section: BibliotecaSection): Builder { | ||
mPayload.themeSections = mPayload.themeSections.plus(section) | ||
return this | ||
} | ||
|
||
fun addExtraThemeSection(sectionBuilder: BibliotecaSection.Builder): Builder { | ||
mPayload.themeSections = mPayload.themeSections.plus(sectionBuilder.build()) | ||
return this | ||
} | ||
|
||
fun build(): BibliotecaPayload = mPayload | ||
} | ||
|
||
} |
5 changes: 5 additions & 0 deletions
5
biblioteca/src/main/java/me/padamchopra/biblioteca/mapper/DataMapper.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,5 @@ | ||
package me.padamchopra.biblioteca.mapper | ||
|
||
internal interface DataMapper<I, O> { | ||
fun mapTo(input: I): O | ||
} |
38 changes: 38 additions & 0 deletions
38
biblioteca/src/main/java/me/padamchopra/biblioteca/mapper/ProvidedColorsToSectionMapper.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,38 @@ | ||
package me.padamchopra.biblioteca.mapper | ||
|
||
import androidx.compose.runtime.Composable | ||
import me.padamchopra.biblioteca.models.BibliotecaSection | ||
import me.padamchopra.biblioteca.models.ProvidedColors | ||
import me.padamchopra.biblioteca.models.SectionIndexProvider | ||
import me.padamchopra.biblioteca.ui.components.ColorSectionElement | ||
import me.padamchopra.biblioteca.utils.ColorSourceType | ||
|
||
internal class ProvidedColorsToSectionMapper : DataMapper<SectionIndexProvider<ProvidedColors>, BibliotecaSection> { | ||
override fun mapTo(input: SectionIndexProvider<ProvidedColors>): BibliotecaSection { | ||
val list: MutableList<@Composable () -> Unit> = mutableListOf() | ||
|
||
for (mapEntry in input.data.colorSourceType.entries) { | ||
if (mapEntry.value == ColorSourceType.COMPOSE_COLOR) { | ||
list.add @Composable { | ||
ColorSectionElement( | ||
name = mapEntry.key, | ||
color = input.data.map[mapEntry.key] | ||
) | ||
} | ||
} else { | ||
list.add @Composable { | ||
ColorSectionElement( | ||
name = mapEntry.key, | ||
color = input.data.resourceMap[mapEntry.key] | ||
) | ||
} | ||
} | ||
} | ||
|
||
return BibliotecaSection( | ||
index = input.index, | ||
title = "Colors", | ||
composables = list | ||
) | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
...oteca/src/main/java/me/padamchopra/biblioteca/mapper/ProvidedTypographyToSectionMapper.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,29 @@ | ||
package me.padamchopra.biblioteca.mapper | ||
|
||
import androidx.compose.runtime.Composable | ||
import me.padamchopra.biblioteca.models.BibliotecaSection | ||
import me.padamchopra.biblioteca.models.ProvidedTypography | ||
import me.padamchopra.biblioteca.models.SectionIndexProvider | ||
import me.padamchopra.biblioteca.ui.components.TypographySectionElement | ||
|
||
internal class ProvidedTypographyToSectionMapper: DataMapper<SectionIndexProvider<ProvidedTypography>, BibliotecaSection> { | ||
override fun mapTo(input: SectionIndexProvider<ProvidedTypography>): BibliotecaSection { | ||
val list: MutableList<@Composable () -> Unit> = mutableListOf() | ||
|
||
for (mapEntry in input.data.map) { | ||
list.add @Composable { | ||
TypographySectionElement( | ||
name = mapEntry.key, | ||
textStyle = mapEntry.value, | ||
showcaseText = input.data.showcaseText | ||
) | ||
} | ||
} | ||
|
||
return BibliotecaSection( | ||
index = input.index, | ||
title = "Typography", | ||
composables = list | ||
) | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
biblioteca/src/main/java/me/padamchopra/biblioteca/models/BibliotecaSection.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,32 @@ | ||
package me.padamchopra.biblioteca.models | ||
|
||
import android.os.Parcelable | ||
import androidx.compose.runtime.Composable | ||
import kotlinx.parcelize.Parcelize | ||
|
||
@Parcelize | ||
class BibliotecaSection internal constructor( | ||
var index: Int = 0, | ||
var title: String = "Section Title", | ||
var composables: List<@Composable () -> Unit> = listOf() | ||
): Parcelable { | ||
class Builder { | ||
private val mSection: BibliotecaSection = BibliotecaSection() | ||
|
||
fun setTitle(title: String): Builder { | ||
mSection.title = title | ||
return this | ||
} | ||
|
||
fun addComposable(composable: @Composable () -> Unit): Builder { | ||
mSection.composables = mSection.composables.plus(composable) | ||
return this | ||
} | ||
|
||
fun build(): BibliotecaSection = mSection | ||
} | ||
|
||
internal fun changeIndex(newIndex: Int) { | ||
this.index = newIndex | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
biblioteca/src/main/java/me/padamchopra/biblioteca/models/ProvidedColors.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,33 @@ | ||
package me.padamchopra.biblioteca.models | ||
|
||
import android.os.Parcelable | ||
import androidx.annotation.ColorRes | ||
import androidx.compose.ui.graphics.Color | ||
import kotlinx.parcelize.Parcelize | ||
import kotlinx.parcelize.RawValue | ||
import me.padamchopra.biblioteca.utils.ColorSourceType | ||
|
||
@Parcelize | ||
class ProvidedColors private constructor( | ||
val map: MutableMap<String, @RawValue Color> = mutableMapOf(), | ||
val resourceMap: MutableMap<String, Int> = mutableMapOf(), | ||
val colorSourceType: MutableMap<String, ColorSourceType> = mutableMapOf() | ||
): Parcelable { | ||
class Builder { | ||
private val mColors: ProvidedColors = ProvidedColors() | ||
|
||
fun addColor(name: String, color: Color): Builder { | ||
mColors.map[name] = color | ||
mColors.colorSourceType[name] = ColorSourceType.COMPOSE_COLOR | ||
return this | ||
} | ||
|
||
fun addColor(name: String, @ColorRes colorId: Int): Builder { | ||
mColors.resourceMap[name] = colorId | ||
mColors.colorSourceType[name] = ColorSourceType.RESOURCE_COLOR | ||
return this | ||
} | ||
|
||
fun build(): ProvidedColors = mColors | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
biblioteca/src/main/java/me/padamchopra/biblioteca/models/ProvidedTypography.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,28 @@ | ||
package me.padamchopra.biblioteca.models | ||
|
||
import android.os.Parcelable | ||
import androidx.compose.ui.text.TextStyle | ||
import kotlinx.parcelize.Parcelize | ||
import kotlinx.parcelize.RawValue | ||
|
||
@Parcelize | ||
class ProvidedTypography private constructor( | ||
var showcaseText: String = "Lorem Ipsum", | ||
val map: MutableMap<String, @RawValue TextStyle> = mutableMapOf() | ||
): Parcelable { | ||
class Builder { | ||
private val mTypography: ProvidedTypography = ProvidedTypography() | ||
|
||
fun addTextStyle(name: String, textStyle: TextStyle): Builder { | ||
mTypography.map[name] = textStyle | ||
return this | ||
} | ||
|
||
fun setShowcaseText(text: String): Builder { | ||
mTypography.showcaseText = text | ||
return this | ||
} | ||
|
||
fun build(): ProvidedTypography = mTypography | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
biblioteca/src/main/java/me/padamchopra/biblioteca/models/SectionIndexProvider.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,6 @@ | ||
package me.padamchopra.biblioteca.models | ||
|
||
internal data class SectionIndexProvider<T>( | ||
val index: Int, | ||
val data: T | ||
) |
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
Oops, something went wrong.