Skip to content

Commit

Permalink
v0.1 of Biblioteca Library
Browse files Browse the repository at this point in the history
  • Loading branch information
padamchopra committed Oct 31, 2021
1 parent 9bbabb7 commit 4f74b67
Show file tree
Hide file tree
Showing 29 changed files with 801 additions and 30 deletions.
10 changes: 10 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ android {
minSdk 23
targetSdk 31
versionCode 1
versionName "0.0.3"
versionName "0.1"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
Expand Down Expand Up @@ -63,5 +63,6 @@ dependencies {
androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_version"
debugImplementation "androidx.compose.ui:ui-tooling:$compose_version"

implementation project(':biblioteca')
implementation project(":biblioteca")
//implementation 'com.github.padamchopra:Biblioteca:v0.0.3'
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,22 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import me.padamchopra.biblioteca.BibliotecaActivity
import me.padamchopra.biblioteca.BibliotecaPayload

class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

val bundle: BibliotecaPayload = BibliotecaPayload.Builder().build()

setContent {
MainActivityContent()
MainActivityContent(bundle)
}
}
}

@Composable
private fun MainActivityContent() {
private fun MainActivityContent(bundle: BibliotecaPayload) {

val context = LocalContext.current

Expand All @@ -33,7 +37,9 @@ private fun MainActivityContent() {
contentAlignment = Alignment.Center
) {
Button(onClick = {
context.startActivity(Intent(context, BibliotecaActivity::class.java))
val intent = Intent(context, BibliotecaActivity::class.java)
intent.putExtra(BibliotecaPayload.EXTRA_KEY, bundle)
context.startActivity(intent)
}) {
Text(text = "Open Biblioteca")
}
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values/strings.xml
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>
5 changes: 3 additions & 2 deletions biblioteca/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ plugins {
id 'com.android.library'
id 'kotlin-android'
id 'maven-publish'
id 'kotlin-parcelize'
}

android {
Expand All @@ -11,7 +12,7 @@ android {
minSdk 23
targetSdk 31
versionCode 1
versionName "0.0.3"
versionName "0.1"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro"
Expand Down Expand Up @@ -70,7 +71,7 @@ afterEvaluate {

groupId = 'com.github.padamchopra'
artifactId = 'biblioteca'
version = '0.0.3'
version = '0.1'
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,20 @@ import androidx.activity.compose.setContent
import androidx.activity.viewModels
import me.padamchopra.biblioteca.ui.BibliotecaApp
import me.padamchopra.biblioteca.ui.theme.BibliotecaTheme
import me.padamchopra.biblioteca.ui.viewmodel.BibliotecaViewModule
import me.padamchopra.biblioteca.ui.viewmodel.BibliotecaViewModel

class BibliotecaActivity : ComponentActivity() {

private val viewModel: BibliotecaViewModule by viewModels()
private val viewModel: BibliotecaViewModel by viewModels()

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val payload = intent.getParcelableExtra<BibliotecaPayload>(BibliotecaPayload.EXTRA_KEY)

payload?.let {
viewModel.setPayload(it)
}

setContent {
BibliotecaTheme {
BibliotecaApp(
Expand Down
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
}

}
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
}
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
)
}
}
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
)
}
}
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
}
}
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
}
}
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
}
}
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
)
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ import androidx.compose.material.Scaffold
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import me.padamchopra.biblioteca.ui.components.BibliotecaContentScreen
import me.padamchopra.biblioteca.ui.components.BibliotecaTopAppBar
import me.padamchopra.biblioteca.ui.viewmodel.BibliotecaViewModule
import me.padamchopra.biblioteca.ui.viewmodel.BibliotecaViewModel

@Composable
internal fun BibliotecaApp(
viewModel: BibliotecaViewModule
viewModel: BibliotecaViewModel
) {

val activeTab by viewModel.activeTab.collectAsState()
Expand All @@ -29,6 +30,11 @@ internal fun BibliotecaApp(
)
}
},
content = {}
content = {
BibliotecaContentScreen(
activeTab = activeTab,
viewModel = viewModel
)
}
)
}
Loading

0 comments on commit 4f74b67

Please sign in to comment.