Skip to content
This repository has been archived by the owner on Oct 15, 2020. It is now read-only.

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
imbeerus committed May 26, 2020
1 parent c4c05bb commit 5244963
Show file tree
Hide file tree
Showing 20 changed files with 177 additions and 87 deletions.
7 changes: 7 additions & 0 deletions .idea/dictionaries/ivan.xml

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

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ allprojects {
```
```
dependencies {
implementation 'com.github.lndmflngs:roboto-span-view:1.0.0'
implementation 'com.github.lndmflngs:roboto-span-view:1.0.1'
}
```
## Usage
Expand Down
48 changes: 9 additions & 39 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,43 +1,13 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'

android {
compileSdkVersion 29
buildToolsVersion "29.0.3"

defaultConfig {
applicationId "com.lockwood.robotospandemo"
minSdkVersion 15
targetSdkVersion 29
versionCode 1
versionName "1.0"
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = "1.8"
}

buildTypes {
debug {
applicationIdSuffix ".debug"
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
apply from: rootProject.file('gradle/android/app.gradle')
apply from: rootProject.file('gradle/deps.gradle')

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.core:core-ktx:1.2.0'
implementation "com.google.android.material:material:1.2.0-alpha06"

implementation(
deps.kotlin.stdlib,
deps.android.appcompat,
deps.android.material
)

implementation project(':roboto-library')
}
}
1 change: 1 addition & 0 deletions app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
<item name="colorPrimaryDark">@color/primaryDark</item>
<item name="colorAccent">@color/accent</item>
</style>

</resources>
3 changes: 3 additions & 0 deletions gradle/android/app.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
apply plugin: 'com.android.application'
apply from: rootProject.file('gradle/android/base.gradle')
apply from: rootProject.file('gradle/android/build.gradle')
16 changes: 16 additions & 0 deletions gradle/android/base.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

apply from: rootProject.file('gradle/versions.gradle')

android {
compileSdkVersion versions.compileSdk

defaultConfig {
minSdkVersion versions.minSdk
targetSdkVersion versions.targetSdk
versionCode versions.code
versionName versions.name
}

}
17 changes: 17 additions & 0 deletions gradle/android/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
android {

buildTypes {

debug {
applicationIdSuffix ".debug"
minifyEnabled false
shrinkResources false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
release {
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
9 changes: 9 additions & 0 deletions gradle/android/library.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
apply plugin: 'com.android.library'
apply from: rootProject.file('gradle/android/base.gradle')

android {
defaultConfig {
consumerProguardFiles 'consumer-rules.pro'
}

}
22 changes: 22 additions & 0 deletions gradle/deps.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
ext.deps = [:]

def versions = [:]
versions.kotlin = "1.3.72"
versions.ktx = "1.4.0-alpha01"
versions.appcompat = "1.3.0-alpha01"
versions.multispan = "1.0.2"
versions.material = "1.2.0-alpha06"

def android = [:]
android.ktx = "androidx.core:core-ktx:$versions.ktx"
android.appcompat = "androidx.appcompat:appcompat:$versions.appcompat"
android.material = "com.google.android.material:material:$versions.material"
deps.android = android

def kotlin = [:]
kotlin.stdlib = "org.jetbrains.kotlin:kotlin-stdlib:$versions.kotlin"
deps.kotlin = kotlin

def lndmflngs = [:]
lndmflngs.multispan = "com.github.lndmflngs:multispan-view:$versions.multispan"
deps.lndmflngs = lndmflngs
12 changes: 12 additions & 0 deletions gradle/kotlin/target.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
android {

compileOptions {
sourceCompatibility = '1.8'
targetCompatibility = '1.8'
}

kotlinOptions {
jvmTarget = "1.8"
}

}
7 changes: 7 additions & 0 deletions gradle/publish.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apply plugin: 'com.github.dcendents.android-maven'

group = 'com.github.lndmflngs'

repositories {
mavenCentral()
}
7 changes: 7 additions & 0 deletions gradle/versions.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
ext.versions = [
minSdk : 15,
compileSdk: 29,
targetSdk : 29,
code : 1,
name : '1.0.0'
]
45 changes: 11 additions & 34 deletions roboto-library/build.gradle
Original file line number Diff line number Diff line change
@@ -1,37 +1,14 @@
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'com.github.dcendents.android-maven'

group = 'com.github.lndmflngs'

android {
compileSdkVersion 29

defaultConfig {
minSdkVersion 15
targetSdkVersion 29
versionCode 1
versionName "1.0"
consumerProguardFiles 'consumer-rules.pro'
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = "1.8"
}
}
apply from: rootProject.file('gradle/android/library.gradle')
apply from: rootProject.file('gradle/kotlin/target.gradle')
apply from: rootProject.file('gradle/publish.gradle')
apply from: rootProject.file('gradle/deps.gradle')

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
implementation "androidx.appcompat:appcompat:1.1.0"
implementation "androidx.core:core-ktx:1.2.0"
api "com.github.lndmflngs:multispan-view:1.0.1"
}
implementation(
deps.kotlin.stdlib,
deps.android.appcompat,
deps.android.ktx
)

repositories {
mavenCentral()
}
api deps.lndmflngs.multispan
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ package com.lockwood.multispan.roboto

import android.content.Context
import android.util.AttributeSet
import com.lockwood.multispan.extensions.fetchAttrs
import com.lockwood.multispan.extensions.fetchFourSpanAttrs
import com.lockwood.multispan.roboto.extensions.fetchAttrs
import com.lockwood.multispan.roboto.spannable.RobotoFourSpan
import com.lockwood.multispan.spannable.FourSpan.Companion.FOUR_ITEMS_COUNT
import com.lockwood.multispan.spannable.FourSpan.Companion.ITEM_FOURTH
Expand All @@ -43,7 +43,7 @@ open class RobotoFourSpanView @JvmOverloads constructor(
init {
fetchFourSpanAttrs(context, attrs, defaultTextSize, defaultTextColor)

fetchAttrs(R.styleable.RobotoFourSpanView, context, attrs) {
fetchAttrs(context, R.styleable.RobotoFourSpanView, attrs) {
fourthFont = getRobotoFontFamily(R.styleable.RobotoFourSpanView_fourthRobotoFont)
fourthStyle = getRobotoFontStyle(R.styleable.RobotoFourSpanView_fourthRobotoFont)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ package com.lockwood.multispan.roboto

import android.content.Context
import android.util.AttributeSet
import com.lockwood.multispan.extensions.fetchAttrs
import com.lockwood.multispan.extensions.fetchSingleSpanAttrs
import com.lockwood.multispan.roboto.base.RobotoMultiSpanView
import com.lockwood.multispan.roboto.extensions.fetchAttrs
import com.lockwood.multispan.roboto.spannable.RobotoSingleSpan
import com.lockwood.multispan.spannable.SingleSpan.Companion.ITEM_FIRST
import com.lockwood.multispan.spannable.SingleSpan.Companion.ONE_ITEM_COUNT
Expand All @@ -44,7 +44,7 @@ open class RobotoSingleSpanView @JvmOverloads constructor(
init {
fetchSingleSpanAttrs(context, attrs, defaultTextSize, defaultTextColor)

fetchAttrs(R.styleable.RobotoSingleSpanView, context, attrs) {
fetchAttrs(context, R.styleable.RobotoSingleSpanView, attrs) {
firstFont = getRobotoFontFamily(R.styleable.RobotoSingleSpanView_firstRobotoFont)
firstStyle = getRobotoFontStyle(R.styleable.RobotoSingleSpanView_firstRobotoFont)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ package com.lockwood.multispan.roboto

import android.content.Context
import android.util.AttributeSet
import com.lockwood.multispan.extensions.fetchAttrs
import com.lockwood.multispan.extensions.fetchThreeSpanAttrs
import com.lockwood.multispan.roboto.extensions.fetchAttrs
import com.lockwood.multispan.roboto.spannable.RobotoThreeSpan
import com.lockwood.multispan.spannable.ThreeSpan.Companion.ITEM_THIRD
import com.lockwood.multispan.spannable.ThreeSpan.Companion.THREE_ITEMS_COUNT
Expand All @@ -43,7 +43,7 @@ open class RobotoThreeSpanView @JvmOverloads constructor(
init {
fetchThreeSpanAttrs(context, attrs, defaultTextSize, defaultTextColor)

fetchAttrs(R.styleable.RobotoThreeSpanView, context, attrs) {
fetchAttrs(context, R.styleable.RobotoThreeSpanView, attrs) {
thirdFont = getRobotoFontFamily(R.styleable.RobotoThreeSpanView_thirdRobotoFont)
thirdStyle = getRobotoFontStyle(R.styleable.RobotoThreeSpanView_thirdRobotoFont)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ package com.lockwood.multispan.roboto

import android.content.Context
import android.util.AttributeSet
import com.lockwood.multispan.extensions.fetchAttrs
import com.lockwood.multispan.extensions.fetchTwoSpanAttrs
import com.lockwood.multispan.roboto.extensions.fetchAttrs
import com.lockwood.multispan.roboto.spannable.RobotoTwoSpan
import com.lockwood.multispan.spannable.TwoSpan.Companion.ITEM_SECOND
import com.lockwood.multispan.spannable.TwoSpan.Companion.TWO_ITEMS_COUNT
Expand All @@ -43,7 +43,7 @@ open class RobotoTwoSpanView @JvmOverloads constructor(
init {
fetchTwoSpanAttrs(context, attrs, defaultTextSize, defaultTextColor)

fetchAttrs(R.styleable.RobotoTwoSpanView, context, attrs) {
fetchAttrs(context, R.styleable.RobotoTwoSpanView, attrs) {
secondFont = getRobotoFontFamily(R.styleable.RobotoTwoSpanView_secondRobotoFont)
secondStyle = getRobotoFontStyle(R.styleable.RobotoTwoSpanView_secondRobotoFont)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.lockwood.multispan.roboto.extensions

import android.content.Context
import android.content.res.TypedArray
import android.util.AttributeSet
import androidx.annotation.AttrRes
import androidx.annotation.StyleRes

internal inline fun fetchAttrs(
context: Context,
attrs: IntArray,
set: AttributeSet? = null,
@AttrRes defStyleAttr: Int = 0,
@StyleRes defStyleRes: Int = 0,
fetch: TypedArray .() -> Unit = {}
) {
val typedArray = context.theme.obtainStyledAttributes(
set,
attrs,
defStyleAttr,
defStyleRes
)
with(typedArray) {
try {
fetch()
} finally {
recycle()
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.lockwood.multispan.roboto.extensions

import android.content.res.ColorStateList
import androidx.annotation.ColorInt

internal fun colorToStateList(@ColorInt color: Int): ColorStateList {
return ColorStateList.valueOf(color)
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@

package com.lockwood.multispan.roboto.item

import android.content.res.ColorStateList
import android.text.style.CharacterStyle
import androidx.annotation.ColorInt
import com.lockwood.multispan.item.SpanItem
import com.lockwood.multispan.roboto.extensions.colorToStateList
import com.lockwood.multispan.roboto.span.RobotoSpan
import com.lockwood.multispan.roboto.span.RobotoSpan.Companion.DEF_ROBOTO_FONT_FAMILY
import com.lockwood.multispan.roboto.span.RobotoSpan.Companion.DEF_TEXT_STYLE
Expand All @@ -34,11 +34,15 @@ class RobotoSpanItem(
) : SpanItem {

override fun buildSpan(position: Int): CharacterStyle {
return RobotoSpan(fontFamily, style, textSize, textColor.toStateList())
}
val colorStateList = colorToStateList(textColor)

private fun Int.toStateList(): ColorStateList {
return ColorStateList.valueOf(this)
return RobotoSpan(
fontFamily = fontFamily,
style = style,
size = textSize,
color = colorStateList
)
}


}

0 comments on commit 5244963

Please sign in to comment.