Android Extensions: Support cache in custom Views

This commit is contained in:
Yan Zhulanow
2017-06-02 22:26:01 +03:00
parent c9cd1a4d75
commit 1a1db5a6f1
5 changed files with 47 additions and 1 deletions
@@ -28,7 +28,7 @@ enum class AndroidClassType(className: String, val supportsCache: Boolean = fals
DIALOG(AndroidConst.DIALOG_FQNAME, supportsCache = false),
SUPPORT_FRAGMENT_ACTIVITY(AndroidConst.SUPPORT_FRAGMENT_ACTIVITY_FQNAME, supportsCache = true),
SUPPORT_FRAGMENT(AndroidConst.SUPPORT_FRAGMENT_FQNAME, supportsCache = true, fragment = true),
VIEW(AndroidConst.VIEW_FQNAME),
VIEW(AndroidConst.VIEW_FQNAME, supportsCache = true),
UNKNOWN("");
val internalClassName: String = className.replace('.', '/')
@@ -14,4 +14,5 @@ public class MyActivity : Activity() {
// 1 GETSTATIC test/R\$id\.login
// 1 INVOKEVIRTUAL android/view/View\.findViewById
// 0 INVOKEVIRTUAL test/MyActivity\._\$_findCachedViewById
// 0 INVOKEVIRTUAL android/view/View\._\$_findCachedViewById
// 1 CHECKCAST android/widget/Button
@@ -0,0 +1,17 @@
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/item_detail_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ItemDetailActivity"
tools:ignore="MergeRootFrame" >
<Button
android:id="@+id/login"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Sign in" />
</FrameLayout>
@@ -0,0 +1,22 @@
package test
import android.view.View
import android.app.Activity
import android.content.Context
import kotlinx.android.synthetic.main.layout.view.*
class MyView(context: Context) : View(context)
class MyActivity : Activity() {
init { MyView(this).login }
}
// 2 public _\$_findCachedViewById
// 1 INVOKEVIRTUAL test/MyActivity\.findViewById
// 2 public _\$_clearFindViewByIdCache
// 1 GETSTATIC test/R\$id\.login
// 0 INVOKEVIRTUAL android/view/View\.findViewById
// 1 INVOKEVIRTUAL test/MyView\.findViewById
// 0 INVOKEVIRTUAL test/MyActivity\._\$_findCachedViewById
// 0 INVOKEVIRTUAL android/view/View\._\$_findCachedViewById
// 1 CHECKCAST android/widget/Button
@@ -173,4 +173,10 @@ public class AndroidBytecodeShapeTestGenerated extends AbstractAndroidBytecodeSh
String fileName = KotlinTestUtils.navigationMetadata("plugins/android-extensions/android-extensions-compiler/testData/codegen/bytecodeShape/viewStub/");
doTest(fileName);
}
@TestMetadata("viewWithCache")
public void testViewWithCache() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("plugins/android-extensions/android-extensions-compiler/testData/codegen/bytecodeShape/viewWithCache/");
doTest(fileName);
}
}