From b4215bdb58d840712b0fab0254309bbab10964ea Mon Sep 17 00:00:00 2001 From: Akash Yadav Date: Sat, 24 Jun 2023 23:02:56 +0530 Subject: [PATCH] feat(templates): add 'No AndroidX Activity' template --- .../templates/impl/TemplateProviderImpl.kt | 4 +- .../noAndroidXActivity/noAndroidXActivity.kt | 73 +++++++++++++++++++ .../noAndroidXActivityTemplate.kt | 51 +++++++++++++ .../noAndroidXActivity/noAndroidXLayout.kt | 36 +++++++++ .../noAndroidXActivity/noAndroidXTheme.kt | 31 ++++++++ .../templates/TemplateBuilderTest.kt | 8 ++ 6 files changed, 202 insertions(+), 1 deletion(-) create mode 100644 templates-impl/src/main/java/com/itsaky/androidide/templates/impl/noAndroidXActivity/noAndroidXActivity.kt create mode 100644 templates-impl/src/main/java/com/itsaky/androidide/templates/impl/noAndroidXActivity/noAndroidXActivityTemplate.kt create mode 100644 templates-impl/src/main/java/com/itsaky/androidide/templates/impl/noAndroidXActivity/noAndroidXLayout.kt create mode 100644 templates-impl/src/main/java/com/itsaky/androidide/templates/impl/noAndroidXActivity/noAndroidXTheme.kt diff --git a/templates-impl/src/main/java/com/itsaky/androidide/templates/impl/TemplateProviderImpl.kt b/templates-impl/src/main/java/com/itsaky/androidide/templates/impl/TemplateProviderImpl.kt index b7fc68da0..2cd49f5e1 100644 --- a/templates-impl/src/main/java/com/itsaky/androidide/templates/impl/TemplateProviderImpl.kt +++ b/templates-impl/src/main/java/com/itsaky/androidide/templates/impl/TemplateProviderImpl.kt @@ -27,6 +27,7 @@ import com.itsaky.androidide.templates.impl.composeActivity.composeActivityProje import com.itsaky.androidide.templates.impl.emptyActivity.emptyActivityProject import com.itsaky.androidide.templates.impl.navDrawerActivity.navDrawerActivityProject import com.itsaky.androidide.templates.impl.noActivity.noActivityProjectTemplate +import com.itsaky.androidide.templates.impl.noAndroidXActivity.noAndroidXActivityProject import com.itsaky.androidide.templates.impl.tabbedActivity.tabbedActivityProject /** @@ -35,7 +36,7 @@ import com.itsaky.androidide.templates.impl.tabbedActivity.tabbedActivityProject * @author Akash Yadav */ @Suppress("unused") -@AutoService(ITemplateProvider::class) // +@AutoService(ITemplateProvider::class) class TemplateProviderImpl : ITemplateProvider { private val templates = mutableMapOf>().apply { @@ -53,6 +54,7 @@ class TemplateProviderImpl : ITemplateProvider { navDrawerActivityProject(), bottomNavActivityProject(), tabbedActivityProject(), + noAndroidXActivityProject(), composeActivityProject() ) //@formatter:on diff --git a/templates-impl/src/main/java/com/itsaky/androidide/templates/impl/noAndroidXActivity/noAndroidXActivity.kt b/templates-impl/src/main/java/com/itsaky/androidide/templates/impl/noAndroidXActivity/noAndroidXActivity.kt new file mode 100644 index 000000000..20fe264c0 --- /dev/null +++ b/templates-impl/src/main/java/com/itsaky/androidide/templates/impl/noAndroidXActivity/noAndroidXActivity.kt @@ -0,0 +1,73 @@ +/* + * This file is part of AndroidIDE. + * + * AndroidIDE is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * AndroidIDE is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with AndroidIDE. If not, see . + */ + +package com.itsaky.androidide.templates.impl.noAndroidXActivity + +import com.itsaky.androidide.templates.base.AndroidModuleTemplateBuilder + +internal fun AndroidModuleTemplateBuilder.noAndroidXActivitySrcJava() = """ +package ${data.packageName}; + +import android.app.Activity; +import android.os.Bundle; +import ${data.packageName}.databinding.ActivityMainBinding; + +public class MainActivity extends Activity { + + private ActivityMainBinding binding; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + binding = ActivityMainBinding.inflate(getLayoutInflater()); + setContentView(binding.getRoot()); + } + + @Override + protected void onDestroy() { + super.onDestroy(); + this.binding = null; + } +} +""".trim() + +internal fun AndroidModuleTemplateBuilder.noAndroidXActivitySrcKt() = """ +package ${data.packageName} + +import android.app.Activity +import android.os.Bundle +import ${data.packageName}.databinding.ActivityMainBinding + +public class MainActivity : Activity() { + + private var _binding: ActivityMainBinding? = null + + private val binding: ActivityMainBinding + get() = checkNotNull(_binding) { "Activity has been destroyed" } + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + _binding = ActivityMainBinding.inflate(layoutInflater) + setContentView(binding.root) + } + + override fun onDestroy() { + super.onDestroy() + _binding = null + } +} + """.trim() \ No newline at end of file diff --git a/templates-impl/src/main/java/com/itsaky/androidide/templates/impl/noAndroidXActivity/noAndroidXActivityTemplate.kt b/templates-impl/src/main/java/com/itsaky/androidide/templates/impl/noAndroidXActivity/noAndroidXActivityTemplate.kt new file mode 100644 index 000000000..c7d335ded --- /dev/null +++ b/templates-impl/src/main/java/com/itsaky/androidide/templates/impl/noAndroidXActivity/noAndroidXActivityTemplate.kt @@ -0,0 +1,51 @@ +/* + * This file is part of AndroidIDE. + * + * AndroidIDE is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * AndroidIDE is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with AndroidIDE. If not, see . + */ + +package com.itsaky.androidide.templates.impl.noAndroidXActivity + +import com.itsaky.androidide.templates.base.modules.android.defaultAppModule +import com.itsaky.androidide.templates.base.util.AndroidModuleResManager +import com.itsaky.androidide.templates.impl.R +import com.itsaky.androidide.templates.impl.base.createRecipe +import com.itsaky.androidide.templates.impl.base.emptyThemesAndColors +import com.itsaky.androidide.templates.impl.base.emptyValuesFile +import com.itsaky.androidide.templates.impl.base.writeMainActivity +import com.itsaky.androidide.templates.impl.baseProjectImpl + +fun noAndroidXActivityProject() = baseProjectImpl { + templateName = R.string.template_no_AndroidX + thumb = R.drawable.template_empty_noandroidx + defaultAppModule { + recipe = createRecipe { + emptyThemesAndColors() + res { + writeXmlResource("colors", + AndroidModuleResManager.ResourceType.VALUES, source = emptyValuesFile()) + writeXmlResource("themes", AndroidModuleResManager.ResourceType.VALUES, + source = noAndroidXTheme()) + + writeXmlResource("activity_main", AndroidModuleResManager.ResourceType.LAYOUT, + source = noAndroidXActivityLayout()) + } + + sources { + writeMainActivity(this, ktSrc = ::noAndroidXActivitySrcKt, + javaSrc = ::noAndroidXActivitySrcJava) + } + } + } +} \ No newline at end of file diff --git a/templates-impl/src/main/java/com/itsaky/androidide/templates/impl/noAndroidXActivity/noAndroidXLayout.kt b/templates-impl/src/main/java/com/itsaky/androidide/templates/impl/noAndroidXActivity/noAndroidXLayout.kt new file mode 100644 index 000000000..63dfc9593 --- /dev/null +++ b/templates-impl/src/main/java/com/itsaky/androidide/templates/impl/noAndroidXActivity/noAndroidXLayout.kt @@ -0,0 +1,36 @@ +/* + * This file is part of AndroidIDE. + * + * AndroidIDE is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * AndroidIDE is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with AndroidIDE. If not, see . + */ + +package com.itsaky.androidide.templates.impl.noAndroidXActivity + +internal fun noAndroidXActivityLayout() = """ + + + + + + +""".trim() \ No newline at end of file diff --git a/templates-impl/src/main/java/com/itsaky/androidide/templates/impl/noAndroidXActivity/noAndroidXTheme.kt b/templates-impl/src/main/java/com/itsaky/androidide/templates/impl/noAndroidXActivity/noAndroidXTheme.kt new file mode 100644 index 000000000..c3ea66870 --- /dev/null +++ b/templates-impl/src/main/java/com/itsaky/androidide/templates/impl/noAndroidXActivity/noAndroidXTheme.kt @@ -0,0 +1,31 @@ +/* + * This file is part of AndroidIDE. + * + * AndroidIDE is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * AndroidIDE is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with AndroidIDE. If not, see . + */ + +package com.itsaky.androidide.templates.impl.noAndroidXActivity + +import com.itsaky.androidide.templates.base.AndroidModuleTemplateBuilder + +internal fun AndroidModuleTemplateBuilder.noAndroidXTheme() = """ + + + + +