Skip to content

Commit

Permalink
remove anko extensions, add conversion properties
Browse files Browse the repository at this point in the history
  • Loading branch information
arnis71 committed Aug 11, 2017
1 parent b0fa3a5 commit 9fc2116
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 10 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ allprojects {
}

ext {
libraryVersion = '0.1.3'
libraryVersion = '0.1.4'
}

task clean(type: Delete) {
Expand Down
2 changes: 1 addition & 1 deletion mvp/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ android {
minSdkVersion 16
targetSdkVersion 26
versionCode 1
versionName "1.0"
versionName "0.1"
}
buildTypes {
release {
Expand Down
13 changes: 6 additions & 7 deletions vitals/src/main/java/com/kotlindroid/vitals/Common.kt
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,12 @@ inline fun Any.safeFromException(block: EmptyBlock){
}
}

inline fun fromApi(version: Int, block: EmptyBlock) {
if (Build.VERSION.SDK_INT >= version) block()
}
inline fun toApi(version: Int, block: EmptyBlock) {
if (Build.VERSION.SDK_INT <= version) block()
}

//inline fun fromApi(version: Int, block: EmptyBlock) {
// if (Build.VERSION.SDK_INT >= version) block()
//}
//inline fun toApi(version: Int, block: EmptyBlock) {
// if (Build.VERSION.SDK_INT <= version) block()
//}

fun ByteArray.toBitmap() = BitmapFactory.decodeByteArray(this, 0, this.size)

Expand Down
26 changes: 26 additions & 0 deletions vitals/src/main/java/com/kotlindroid/vitals/Conversions.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.kotlindroid.vitals

/**
* Created by arnis on 8/11/2017.
*/

val Float.d : Double
get() = toDouble()
val Float.s : String
get() = toString()
val Float.i : Int
get() = toInt()

val Double.f : Float
get() = toFloat()
val Double.s : String
get() = toString()
val Double.i : Int
get() = toInt()

val String.d : Double
get() = toDouble()
val String.f : Float
get() = toFloat()
val String.i : Int
get() = toInt()
4 changes: 3 additions & 1 deletion vitals/src/main/java/com/kotlindroid/vitals/View.kt
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,13 @@ fun ImageView.getImageByteArray() : ByteArray = (drawable as BitmapDrawable).bit

fun AppCompatActivity.bitmapFromRes(resId: Int) = BitmapFactory.decodeResource(resources,resId)

fun Context.dpToPx(value: Int) = resources.displayMetrics.density * value
//fun Context.dpToPx(value: Int) = resources.displayMetrics.density * value
val View.screenHeight: Int
get() = resources.displayMetrics.heightPixels
val View.screenWidth: Int
get() = resources.displayMetrics.widthPixels
val View.density: Float
get() = resources.displayMetrics.density

fun Activity.getStringRes(resId: Int) = resources.getString(resId)
fun Context.getStringRes(resId: Int) = resources.getString(resId)
Expand Down

0 comments on commit 9fc2116

Please sign in to comment.