Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Karan Kumar (New) committed May 4, 2024
0 parents commit e7ae42c
Show file tree
Hide file tree
Showing 63 changed files with 1,334 additions and 0 deletions.
15 changes: 15 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
*.iml
.gradle
/local.properties
/.idea/caches
/.idea/libraries
/.idea/modules.xml
/.idea/workspace.xml
/.idea/navEditor.xml
/.idea/assetWizardSettings.xml
.DS_Store
/build
/captures
.externalNativeBuild
.cxx
local.properties
3 changes: 3 additions & 0 deletions .idea/.gitignore

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

1 change: 1 addition & 0 deletions .idea/.name

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

6 changes: 6 additions & 0 deletions .idea/compiler.xml

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

10 changes: 10 additions & 0 deletions .idea/deploymentTargetSelector.xml

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

19 changes: 19 additions & 0 deletions .idea/gradle.xml

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

6 changes: 6 additions & 0 deletions .idea/kotlinc.xml

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

10 changes: 10 additions & 0 deletions .idea/migrations.xml

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

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.

1 change: 1 addition & 0 deletions androidktx/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
77 changes: 77 additions & 0 deletions androidktx/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
plugins {
alias(libs.plugins.android.library)
alias(libs.plugins.jetbrains.kotlin.android)
id("maven-publish")
}

android {
namespace = "com.kevintorch.androidktx"
compileSdk = 34

defaultConfig {
minSdk = 21

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles("consumer-rules.pro")
}

buildTypes {
release {
isMinifyEnabled = false
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = "1.8"
}
}

dependencies {

implementation(libs.androidx.core.ktx)
// implementation(libs.androidx.appcompat)
implementation(libs.material)
}

afterEvaluate {
publishing {
publications {
register<MavenPublication>("release") {
groupId = "com.github.kevintorch"
artifactId = "Kandroid-ktx"
version = "1.0.0"

from(components["release"])
}
}
}
}






















Empty file added androidktx/consumer-rules.pro
Empty file.
21 changes: 21 additions & 0 deletions androidktx/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.kevintorch.androidktx

import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4

import org.junit.Test
import org.junit.runner.RunWith

import org.junit.Assert.*

/**
* Instrumented test, which will execute on an Android device.
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
@Test
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
assertEquals("com.kevintorch.androidktx.test", appContext.packageName)
}
}
4 changes: 4 additions & 0 deletions androidktx/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

</manifest>
30 changes: 30 additions & 0 deletions androidktx/src/main/java/com/kevintorch/androidktx/AdapterExt.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.kevintorch.androidktx

import android.content.Context
import android.view.View
import android.view.ViewGroup
import android.widget.ArrayAdapter
import androidx.annotation.IdRes
import androidx.annotation.LayoutRes

fun <T> Context.arrayAdapter(
@LayoutRes resource: Int = -1,
@IdRes textViewResourceId: Int = 0,
objects: MutableList<T> = mutableListOf(),
idSelector: (T?, position: Int) -> Long = { _, position -> position.toLong() },
viewCreator: (ArrayAdapter<T>.(position: Int, convertView: View?, parent: ViewGroup) -> View)? = null,
): ArrayAdapter<T> {
return object : ArrayAdapter<T>(this, resource, textViewResourceId, objects) {
override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
return if (viewCreator != null) {
viewCreator(position, convertView, parent)
} else {
super.getView(position, convertView, parent)
}
}

override fun getItemId(position: Int): Long {
return idSelector(getItem(position), position)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.kevintorch.androidktx

fun Boolean?.isTrue(): Boolean = this == true
fun Boolean?.isFalse(): Boolean = this == false
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.kevintorch.androidktx

fun <E> MutableList<E>.appendAll(collection: Collection<E>): MutableList<E> {
addAll(collection)
return this
}
31 changes: 31 additions & 0 deletions androidktx/src/main/java/com/kevintorch/androidktx/ColorsExt.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.kevintorch.androidktx

import android.content.Context
import android.content.res.ColorStateList
import android.graphics.drawable.ColorDrawable
import androidx.annotation.AttrRes
import androidx.annotation.ColorInt
import androidx.annotation.ColorRes
import androidx.core.content.ContextCompat
import androidx.core.content.res.ResourcesCompat

@ColorInt
fun Context.getColorInt(@ColorRes color: Int): Int = ContextCompat.getColor(this, color)

fun Int.toColorDrawable(): ColorDrawable = ColorDrawable(this)

fun Context.colorDrawableFrom(@ColorRes color: Int): ColorDrawable =
getColorInt(color).toColorDrawable()

fun Context.getColorStateList(color: Int): ColorStateList? =
ResourcesCompat.getColorStateList(resources, color, theme)

@ColorInt
fun Context.getColorAttr(@AttrRes colorAttr: Int): Int {
val a = obtainStyledAttributes(null, intArrayOf(colorAttr))
try {
return a.getColor(0, 0)
} finally {
a.recycle()
}
}
15 changes: 15 additions & 0 deletions androidktx/src/main/java/com/kevintorch/androidktx/ContextExt.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.kevintorch.androidktx

import android.app.Application
import android.content.Context
import android.graphics.drawable.Drawable
import android.view.LayoutInflater
import androidx.annotation.DrawableRes
import androidx.appcompat.content.res.AppCompatResources

val Context.layoutInflator get() = LayoutInflater.from(this)

inline fun <reified App : Application> Context.getApplication(): App? = applicationContext as? App

fun Context.getCompatDrawable(@DrawableRes drawable: Int): Drawable? =
AppCompatResources.getDrawable(applicationContext, drawable)
26 changes: 26 additions & 0 deletions androidktx/src/main/java/com/kevintorch/androidktx/GlobalExt.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.kevintorch.androidktx

fun lerp(
outputMin: Float,
outputMax: Float,
inputMin: Float,
inputMax: Float,
value: Float
): Float {
return if (value <= inputMin) {
outputMin
} else {
if (value >= inputMax) outputMax else lerp(
outputMin, outputMax,
(value - inputMin) / (inputMax - inputMin)
)
}
}

fun lerp(startValue: Float, endValue: Float, fraction: Float): Float {
return startValue + fraction * (endValue - startValue)
}

fun lerp(startValue: Int, endValue: Int, fraction: Float): Int {
return startValue + Math.round(fraction * (endValue - startValue).toFloat())
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package com.kevintorch.androidktx

val IntRange.size: Int get() = last - first
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.kevintorch.androidktx

fun String.findContentDispositionValue(name: String): String? {
val regex = """$name\s*=\s*"(.+?)"""".toRegex()
val match = regex.find(this)
return match?.groupValues?.get(1)
}
Loading

0 comments on commit e7ae42c

Please sign in to comment.