-
-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add version of VBPD without reflection in API
- Loading branch information
1 parent
485431c
commit 5927173
Showing
22 changed files
with
165 additions
and
110 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
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
This file was deleted.
Oops, something went wrong.
13 changes: 0 additions & 13 deletions
13
library/src/main/java/by/kirich1409/viewbindingdelegate/internal/ActivityUtils.kt
This file was deleted.
Oops, something went wrong.
30 changes: 0 additions & 30 deletions
30
library/src/main/java/by/kirich1409/viewbindingdelegate/internal/ActivityViewBinder.kt
This file was deleted.
Oops, something went wrong.
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
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,3 +1,4 @@ | ||
include ':app' | ||
include ':library' | ||
include ':vbpd' | ||
include ':vbpd-noreflection' | ||
rootProject.name = "View Binding Delegate" |
File renamed without changes.
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,50 @@ | ||
plugins { | ||
id 'com.android.library' | ||
id 'kotlin-android' | ||
} | ||
|
||
ext { | ||
artifactId = "vbpd-noreflection" | ||
} | ||
|
||
apply from: rootProject.file('publishing.gradle') | ||
|
||
android { | ||
compileSdkVersion rootProject.ext.compileSdkVersion | ||
buildToolsVersion rootProject.ext.buildToolsVersion | ||
|
||
defaultConfig { | ||
minSdkVersion rootProject.ext.minSdkVersion | ||
targetSdkVersion rootProject.ext.targetSdkVersion | ||
} | ||
|
||
compileOptions { | ||
sourceCompatibility JavaVersion.VERSION_1_8 | ||
targetCompatibility JavaVersion.VERSION_1_8 | ||
} | ||
|
||
// For Kotlin projects | ||
kotlinOptions { | ||
jvmTarget = "1.8" | ||
kotlinOptions.freeCompilerArgs += | ||
['-module-name', "com.github.kirich1409.ViewBindingPropertyDelegate.noreflection"] | ||
} | ||
|
||
buildFeatures { | ||
buildConfig = false | ||
viewBinding = false | ||
dataBinding = false | ||
aidl = false | ||
renderScript = false | ||
resValues = false | ||
shaders = false | ||
} | ||
} | ||
|
||
dependencies { | ||
implementation rootProject.ext.dependencies.coreKtx | ||
implementation rootProject.ext.dependencies.fragmentKtx | ||
implementation rootProject.ext.dependencies.kotlinStdlib | ||
implementation rootProject.ext.dependencies.viewBinding | ||
implementation rootProject.ext.dependencies.lifecycleCommonJava8 | ||
} |
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 @@ | ||
<manifest package="by.kirich1409.viewbindingdelegate.noreflection" /> |
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
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
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
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
File renamed without changes.
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 @@ | ||
/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
File renamed without changes.
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 @@ | ||
<manifest package="by.kirich1409.viewbindingdelegate" /> |
49 changes: 49 additions & 0 deletions
49
vbpd/src/main/java/by/kirich1409/viewbindingdelegate/ActivityViewBindingsSimple.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,49 @@ | ||
@file:Suppress("RedundantVisibilityModifier", "unused") | ||
|
||
package by.kirich1409.viewbindingdelegate | ||
|
||
import android.app.Activity | ||
import android.view.View | ||
import androidx.annotation.IdRes | ||
import androidx.annotation.RestrictTo | ||
import androidx.core.app.ActivityCompat | ||
import androidx.core.app.ComponentActivity | ||
import androidx.viewbinding.ViewBinding | ||
|
||
@RestrictTo(RestrictTo.Scope.LIBRARY) | ||
@PublishedApi | ||
internal class ActivityViewBinder<T : ViewBinding>( | ||
private val viewBindingClass: Class<T>, | ||
private val viewProvider: (Activity) -> View | ||
) { | ||
|
||
/** | ||
* Cache static method `ViewBinding.bind(View)` | ||
*/ | ||
private val bindViewMethod by lazy(LazyThreadSafetyMode.NONE) { | ||
viewBindingClass.getMethod("bind", View::class.java) | ||
} | ||
|
||
/** | ||
* Create new [ViewBinding] instance | ||
*/ | ||
@Suppress("UNCHECKED_CAST") | ||
fun bind(activity: Activity): T { | ||
val view = viewProvider(activity) | ||
return bindViewMethod(null, view) as T | ||
} | ||
} | ||
|
||
/** | ||
* Create new [ViewBinding] associated with the [Activity][ComponentActivity] | ||
* | ||
* @param viewBindingRootId Root view's id that will be used as root for the view binding | ||
*/ | ||
@JvmName("viewBindingActivity") | ||
public inline fun <reified T : ViewBinding> ComponentActivity.viewBinding( | ||
@IdRes viewBindingRootId: Int | ||
): ViewBindingProperty<ComponentActivity, T> { | ||
val activityViewBinder = | ||
ActivityViewBinder(T::class.java) { ActivityCompat.requireViewById(this, viewBindingRootId) } | ||
return viewBinding(activityViewBinder::bind) | ||
} |
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
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