mirror of
https://gitee.com/zhangsken/AndroidIDE.git
synced 2026-10-16 07:49:44 +08:00
feat(templates): update source for empty activity
This commit is contained in:
+1
-4
@@ -79,10 +79,7 @@ class AndroidModuleTemplateBuilder : ModuleTemplateBuilder() {
|
||||
configure: TypeSpec.Builder.() -> Unit
|
||||
) {
|
||||
sources {
|
||||
createClass(data.packageName, name) {
|
||||
|
||||
configure()
|
||||
}
|
||||
createClass(data.packageName, name, configure)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+16
-2
@@ -53,17 +53,25 @@ import ${data.packageName}.databinding.ActivityMainBinding
|
||||
|
||||
public class MainActivity : AppCompatActivity() {
|
||||
|
||||
private lateinit var binding: ActivityMainBinding
|
||||
private var _binding: ActivityMainBinding? = null
|
||||
|
||||
private val binding: ActivityMainBinding
|
||||
get() = checkNotNull(_binding) { "Activity has been destroyed" }
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
// Inflate and get instance of binding
|
||||
binding = ActivityMainBinding.inflate(layoutInflater)
|
||||
_binding = ActivityMainBinding.inflate(layoutInflater)
|
||||
|
||||
// set content view to binding's root
|
||||
setContentView(binding.root)
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
super.onDestroy()
|
||||
_binding = null
|
||||
}
|
||||
}
|
||||
"""
|
||||
}
|
||||
@@ -89,6 +97,12 @@ public class MainActivity extends AppCompatActivity {
|
||||
// set content view to binding's root
|
||||
setContentView(binding.getRoot());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
this.binding = null;
|
||||
}
|
||||
}
|
||||
"""
|
||||
}
|
||||
|
||||
@@ -138,11 +138,11 @@ class TemplateBuilderTest {
|
||||
}
|
||||
|
||||
// Write the Java version of the project
|
||||
template.setupRootProjectParams("EmptyActivityProjectJava", language = Language.Java)
|
||||
template.setupRootProjectParams(name = "EmptyActivityProjectJava", language = Language.Java)
|
||||
template.executeRecipe()
|
||||
|
||||
// Write the Kotlin version of the project
|
||||
template.setupRootProjectParams("EmptyActivityProjectKt", language = Language.Kotlin)
|
||||
template.setupRootProjectParams(name = "EmptyActivityProjectKt", language = Language.Kotlin)
|
||||
template.executeRecipe()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user