Skip to content

Commit

Permalink
chore: upgrade deps and target sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
jakeaaron committed Aug 7, 2021
1 parent 68730aa commit debee49
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 41 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = "1.4.21"
ext.kotlin_version = "1.5.10"
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.1.1'
classpath 'com.android.tools.build:gradle:4.1.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1' // Add this line
classpath "org.jacoco:org.jacoco.core:0.8.5"
Expand Down
22 changes: 14 additions & 8 deletions currency-formatter/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ apply plugin: 'com.github.dcendents.android-maven'
apply plugin: 'jacoco'

android {
compileSdkVersion 30
compileSdkVersion 31
buildToolsVersion "30.0.2"

defaultConfig {
minSdkVersion 16
targetSdkVersion 30
targetSdkVersion 31
versionCode 1
versionName "1.0.0"

Expand All @@ -30,6 +30,12 @@ android {
kotlinOptions {
jvmTarget = "1.8"
}

compileOptions {
sourceCompatibility 1.8
targetCompatibility 1.8
}

}

jacoco {
Expand All @@ -42,16 +48,16 @@ tasks.withType(Test) {

dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.appcompat:appcompat:1.3.1'

implementation "androidx.core:core-ktx:1.3.2"
implementation "androidx.core:core-ktx:1.6.0"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"

testImplementation 'junit:junit:4.13.1'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
androidTestImplementation 'androidx.test.ext:junit-ktx:1.1.2'
androidTestImplementation 'androidx.test:core-ktx:1.3.0'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
androidTestImplementation 'androidx.test.ext:junit-ktx:1.1.3'
androidTestImplementation 'androidx.test:core-ktx:1.4.0'

}
repositories {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,10 @@ class MultiCurrencyFormatterTest {
return Pair(scenario, act!!)
}

private fun setUpFormatter(activity: FragmentActivity): MultiCurrencyFormatter =
MultiCurrencyFormatter.newInstance(
activity,
EditText(activity)
)
private fun setUpFormatter(activity: FragmentActivity): MultiCurrencyFormatter = MultiCurrencyFormatter.newInstance(
activity,
EditText(activity)
)

@Test
fun setting_and_getting_amount() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.jacoballenwood.formatter

import android.os.Handler
import android.os.Looper
import android.widget.EditText
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleObserver
Expand All @@ -11,6 +13,7 @@ import com.jacoballenwood.formatter.main.CurrencyTextWatcher
import com.jacoballenwood.formatter.main.TextChangeListener
import com.jacoballenwood.formatter.main.impl.CurrencyFormatterImpl
import java.math.BigDecimal
import java.text.DecimalFormatSymbols
import java.util.*

class MultiCurrencyFormatter private constructor(
Expand All @@ -28,15 +31,15 @@ class MultiCurrencyFormatter private constructor(
@OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
fun destroy() {
currencyTextWatcher.destroy()
lifecycleOwner.lifecycle.removeObserver(
this
)
lifecycleOwner.lifecycle.removeObserver(this)
lifecycleObserver = null
}
}

init {
lifecycleOwner.lifecycle.addObserver(lifecycleObserver!!)
Handler(Looper.getMainLooper()).post {
lifecycleOwner.lifecycle.addObserver(lifecycleObserver!!)
}
}

/**
Expand Down Expand Up @@ -150,4 +153,7 @@ class MultiCurrencyFormatter private constructor(
)
}

}
}

val MultiCurrencyFormatter.decimalFormatSymbols: DecimalFormatSymbols
get() = this.currencyTextWatcher.formatter.underlyingDecimalFormat.decimalFormatSymbols
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,14 @@ fun String.withSuperscript(startIdx: Int, endIdx: Int): Spannable = SpannableStr
endIdx,
0
)
}

fun String.indexOfLastDigit(): Int {
var result = 0
for (i in this.indices) {
if (Character.isDigit(this[i])) {
result = i
}
}
return result
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@ import java.math.BigDecimal
import java.text.DecimalFormat
import java.util.*

private var instance: CurrencyFormatterImpl? = null

interface CurrencyFormatter : CurrencyAttrs {
val underlyingDecimalFormat: DecimalFormat
fun parse(currency: String): BigDecimal
fun format(currency: String, decimals: Boolean): String
fun format(currency: BigDecimal, decimals: Boolean): String

companion object {
private var instance: CurrencyFormatterImpl? = null

/**
* Returns a [CurrencyFormatterImpl] for the specified locale. This is equivalent to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,7 @@ class CurrencyFormatterImpl internal constructor(
/**
*
*/
override fun format(currency: String, decimals: Boolean): String {
return format(parse(currency), decimals)
}
override fun format(currency: String, decimals: Boolean): String = format(parse(currency), decimals)

/**
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import android.text.Spannable
import android.text.TextWatcher
import android.widget.EditText
import com.jacoballenwood.formatter.ext.fitText
import com.jacoballenwood.formatter.ext.indexOfLastDigit
import com.jacoballenwood.formatter.ext.withSuperscript
import com.jacoballenwood.formatter.main.*
import com.jacoballenwood.formatter.util.StringUtil.indexOfLastDigit
import java.lang.ref.WeakReference
import java.math.BigDecimal

Expand Down Expand Up @@ -80,7 +80,7 @@ class CurrencyTextWatcherImpl internal constructor(
val sel = if (currentIndexOfCents > -1) {
(indexOfDecimalPoint + currentIndexOfCents) + if (isDeleting) 0 else 1
} else
indexOfLastDigit(requireEditText.text?.toString()) + 1
(requireEditText.text?.toString()?.indexOfLastDigit() ?: 0) + 1
if (sel <= requireEditText.length())
requireEditText.setSelection(sel)
else
Expand Down

This file was deleted.

0 comments on commit debee49

Please sign in to comment.