Skip to content

Commit 53b53ff

Browse files
author
roman_tcaregorodtcev
committed
Base extensions have been added
1 parent e2e8c66 commit 53b53ff

38 files changed

Lines changed: 948 additions & 6 deletions

.idea/modules.xml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/build.gradle

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,11 @@ android {
2525
dependencies {
2626
implementation fileTree(dir: 'libs', include: ['*.jar'])
2727
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
28-
implementation 'androidx.appcompat:appcompat:1.0.0-beta01'
29-
implementation 'androidx.core:core-ktx:1.1.0-alpha05'
28+
implementation "androidx.appcompat:appcompat:$appcompat"
3029
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
30+
implementation project(":lib")
31+
3132
testImplementation 'junit:junit:4.12'
32-
androidTestImplementation 'androidx.test:runner:1.1.0-alpha4'
33-
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha4'
33+
androidTestImplementation 'androidx.test:runner:1.2.0-alpha03'
34+
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0-alpha03'
3435
}

build.gradle

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
buildscript {
44
ext.kotlin_version = '1.3.30'
5+
ext.appcompat = '1.1.0-alpha04'
6+
57
repositories {
68
google()
79
jcenter()
@@ -10,6 +12,7 @@ buildscript {
1012
dependencies {
1113
classpath 'com.android.tools.build:gradle:3.3.2'
1214
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
15+
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
1316
// NOTE: Do not place your application dependencies here; they belong
1417
// in the individual module build.gradle files
1518
}
@@ -19,7 +22,7 @@ allprojects {
1922
repositories {
2023
google()
2124
jcenter()
22-
25+
2326
}
2427
}
2528

lib/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

lib/build.gradle

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
apply plugin: 'com.android.library'
2+
apply plugin: 'kotlin-android'
3+
4+
apply plugin: 'com.github.dcendents.android-maven'
5+
group = 'com.github.Omega-R'
6+
7+
android {
8+
compileSdkVersion 28
9+
10+
defaultConfig {
11+
minSdkVersion 14
12+
targetSdkVersion 28
13+
versionCode 1
14+
versionName "1.0"
15+
16+
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
17+
18+
}
19+
20+
buildTypes {
21+
release {
22+
minifyEnabled false
23+
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
24+
}
25+
}
26+
27+
}
28+
29+
dependencies {
30+
implementation fileTree(dir: 'libs', include: ['*.jar'])
31+
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
32+
implementation "com.android.support:appcompat-v7:$appcompat"
33+
implementation 'androidx.recyclerview:recyclerview:1.1.0-alpha04'
34+
35+
testImplementation 'junit:junit:4.12'
36+
androidTestImplementation 'com.android.support.test:runner:1.0.2'
37+
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
38+
}
39+
repositories {
40+
mavenCentral()
41+
}

lib/proguard-rules.pro

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Add project specific ProGuard rules here.
2+
# You can control the set of applied configuration files using the
3+
# proguardFiles setting in build.gradle.
4+
#
5+
# For more details, see
6+
# http://developer.android.com/guide/developing/tools/proguard.html
7+
8+
# If your project uses WebView with JS, uncomment the following
9+
# and specify the fully qualified class name to the JavaScript interface
10+
# class:
11+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12+
# public *;
13+
#}
14+
15+
# Uncomment this to preserve the line number information for
16+
# debugging stack traces.
17+
#-keepattributes SourceFile,LineNumberTable
18+
19+
# If you keep the line number information, uncomment this to
20+
# hide the original source file name.
21+
#-renamesourcefileattribute SourceFile
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package omega_r.com.extensions;
2+
3+
import android.content.Context;
4+
import android.support.test.InstrumentationRegistry;
5+
import android.support.test.runner.AndroidJUnit4;
6+
7+
import org.junit.Test;
8+
import org.junit.runner.RunWith;
9+
10+
import static org.junit.Assert.*;
11+
12+
/**
13+
* Instrumented test, which will execute on an Android device.
14+
*
15+
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
16+
*/
17+
@RunWith(AndroidJUnit4.class)
18+
public class ExampleInstrumentedTest {
19+
@Test
20+
public void useAppContext() {
21+
// Context of the app under test.
22+
Context appContext = InstrumentationRegistry.getTargetContext();
23+
24+
assertEquals("omega_r.com.extensions.test", appContext.getPackageName());
25+
}
26+
}

lib/src/main/AndroidManifest.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2+
package="omega_r.com.extensions"/>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package omega_r.com.extensions.activity
2+
3+
import android.app.Activity
4+
import android.graphics.drawable.Drawable
5+
import android.view.View
6+
import androidx.annotation.*
7+
import omega_r.com.extensions.context.getCompatColor
8+
import omega_r.com.extensions.context.getCompatDrawable
9+
10+
fun <T : View> Activity.bind(@IdRes res: Int): Lazy<T> {
11+
@Suppress("UNCHECKED_CAST")
12+
return lazy(LazyThreadSafetyMode.NONE) { findViewById<T>(res) }
13+
}
14+
15+
fun Activity.bindColor(@ColorRes res: Int): Lazy<Int> {
16+
return lazy(LazyThreadSafetyMode.NONE) { this.getCompatColor(res) }
17+
}
18+
19+
fun Activity.bindInt(@IntegerRes res: Int): Lazy<Int> {
20+
return lazy(LazyThreadSafetyMode.NONE) { this.resources.getInteger(res) }
21+
}
22+
23+
fun Activity.bindString(@StringRes res: Int): Lazy<String> {
24+
return lazy(LazyThreadSafetyMode.NONE) { this.resources.getString(res) }
25+
}
26+
27+
fun Activity.bindDrawable(@DrawableRes res: Int): Lazy<Drawable?> {
28+
return lazy(LazyThreadSafetyMode.NONE) { this.getCompatDrawable(res) }
29+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package omega_r.com.extensions.bitmap
2+
3+
import android.graphics.Bitmap
4+
import java.io.ByteArrayInputStream
5+
import java.io.ByteArrayOutputStream
6+
import java.io.InputStream
7+
import java.io.OutputStream
8+
9+
fun Bitmap.toOutputStream(
10+
compressFormat: Bitmap.CompressFormat = Bitmap.CompressFormat.JPEG,
11+
quality: Int = 100
12+
): OutputStream {
13+
val stream = ByteArrayOutputStream()
14+
compress(compressFormat, quality, stream)
15+
return stream
16+
}
17+
18+
fun Bitmap.toInputStream(
19+
compressFormat: Bitmap.CompressFormat = Bitmap.CompressFormat.JPEG,
20+
quality: Int = 100
21+
): InputStream {
22+
val stream = ByteArrayOutputStream()
23+
compress(compressFormat, quality, stream)
24+
val byteArray = stream.toByteArray()
25+
return ByteArrayInputStream(byteArray)
26+
}

0 commit comments

Comments
 (0)