-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update: add some extensions and implement CommonLazy
- Loading branch information
Showing
8 changed files
with
58 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 0 additions & 12 deletions
12
library/src/main/java/io/github/mindjet/library/ActivityEx.kt
This file was deleted.
Oops, something went wrong.
33 changes: 33 additions & 0 deletions
33
library/src/main/java/io/github/mindjet/library/delegate/CommonLazy.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package io.github.mindjet.library.delegate | ||
|
||
import android.app.Activity | ||
import android.view.View | ||
import kotlin.properties.ReadOnlyProperty | ||
import kotlin.reflect.KProperty | ||
|
||
/** | ||
* Created by Mindjet on 2017/10/25. | ||
*/ | ||
class CommonLazy<in T, out R>(private val initializer: (T, KProperty<*>) -> R) : ReadOnlyProperty<T, R> { | ||
|
||
private var value: R? = null | ||
|
||
override fun getValue(thisRef: T, property: KProperty<*>): R { | ||
if (value == null) { | ||
value = initializer(thisRef, property) | ||
} | ||
@Suppress("UNCHECKED_CAST") | ||
return value as R | ||
} | ||
|
||
} | ||
|
||
fun <T : View> Activity.bindView(id: Int): CommonLazy<Activity, T> { | ||
return CommonLazy { activity, prop -> | ||
activity.findViewById(id) ?: viewNotFound(activity, id, prop) | ||
} | ||
} | ||
|
||
fun <T> viewNotFound(activity: Activity, id: Int, kProperty: KProperty<T>): Nothing { | ||
throw ClassNotFoundException("View id $id is not found for ${kProperty.name} in ${activity::class.simpleName}") | ||
} |
11 changes: 11 additions & 0 deletions
11
library/src/main/java/io/github/mindjet/library/extension/ActivityEx.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package io.github.mindjet.library.extension | ||
|
||
import android.app.Activity | ||
import android.content.Intent | ||
|
||
/** | ||
* Created by Mindjet on 2017/10/17. | ||
*/ | ||
inline fun <reified T> Activity.start() { | ||
this.startActivity(Intent(this, T::class.java)) | ||
} |
8 changes: 8 additions & 0 deletions
8
library/src/main/java/io/github/mindjet/library/extension/CollectionEx.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package io.github.mindjet.library.extension | ||
|
||
/** | ||
* Created by Mindjet on 2017/10/25. | ||
*/ | ||
fun Int.toStream(): Array<Any?> { | ||
return arrayOfNulls(this) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...va/io/github/mindjet/library/VersionEx.kt → ...ub/mindjet/library/extension/VersionEx.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package io.github.mindjet.library | ||
package io.github.mindjet.library.extension | ||
|
||
import android.os.Build | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters