mirror of
https://gitee.com/zhangsken/AndroidIDE.git
synced 2026-10-16 07:49:44 +08:00
feat(templates): add navigation drawer activity template
This commit is contained in:
+42
-3
@@ -17,8 +17,9 @@
|
||||
|
||||
package com.itsaky.androidide.templates.base.models
|
||||
|
||||
data class Dependency(val configuration: DependencyConfiguration, val group: String,
|
||||
val artifact: String, val version: String
|
||||
data class Dependency(val configuration: DependencyConfiguration,
|
||||
val group: String, val artifact: String,
|
||||
val version: String
|
||||
) {
|
||||
|
||||
fun value(): String {
|
||||
@@ -29,11 +30,49 @@ data class Dependency(val configuration: DependencyConfiguration, val group: Str
|
||||
|
||||
object AndroidX {
|
||||
|
||||
// Version 2.6.1 results in 'duplicate classes' build issue
|
||||
private const val lifecycleVersion = "2.5.1"
|
||||
|
||||
private const val navigationVersion = "2.5.3"
|
||||
|
||||
@JvmStatic
|
||||
val AppCompat = parseDependency("androidx.appcompat:appcompat:1.6.1")
|
||||
|
||||
@JvmStatic
|
||||
val ConstraintLayout = parseDependency("androidx.constraintlayout:constraintlayout:2.1.4")
|
||||
val ConstraintLayout =
|
||||
parseDependency("androidx.constraintlayout:constraintlayout:2.1.4")
|
||||
|
||||
@JvmStatic
|
||||
val LifeCycle_LiveData = parseDependency(
|
||||
"androidx.lifecycle:lifecycle-livedata:${lifecycleVersion}")
|
||||
|
||||
@JvmStatic
|
||||
val LifeCycle_LiveData_Ktx = parseDependency(
|
||||
"androidx.lifecycle:lifecycle-livedata-ktx:${lifecycleVersion}")
|
||||
|
||||
@JvmStatic
|
||||
val LifeCycle_ViewModel = parseDependency(
|
||||
"androidx.lifecycle:lifecycle-viewmodel:${lifecycleVersion}")
|
||||
|
||||
@JvmStatic
|
||||
val LifeCycle_ViewModel_Ktx = parseDependency(
|
||||
"androidx.lifecycle:lifecycle-viewmodel-ktx:${lifecycleVersion}")
|
||||
|
||||
@JvmStatic
|
||||
val Navigation_Fragment = parseDependency(
|
||||
"androidx.navigation:navigation-fragment:${navigationVersion}")
|
||||
|
||||
@JvmStatic
|
||||
val Navigation_Ui =
|
||||
parseDependency("androidx.navigation:navigation-ui:${navigationVersion}")
|
||||
|
||||
@JvmStatic
|
||||
val Navigation_Fragment_Ktx = parseDependency(
|
||||
"androidx.navigation:navigation-fragment-ktx:${navigationVersion}")
|
||||
|
||||
@JvmStatic
|
||||
val Navigation_Ui_Ktx = parseDependency(
|
||||
"androidx.navigation:navigation-ui-ktx:${navigationVersion}")
|
||||
}
|
||||
|
||||
object Google {
|
||||
|
||||
+1
-1
@@ -42,7 +42,7 @@ plugins {
|
||||
|
||||
android {
|
||||
namespace = "${data.packageName}"
|
||||
compileSdk = (${data.versions.compileSdk.api})
|
||||
compileSdk = ${data.versions.compileSdk.api}
|
||||
buildToolsVersion = "${data.versions.buildTools}"
|
||||
|
||||
defaultConfig {
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24.0"
|
||||
android:viewportHeight="24.0">
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="M12,12m-3.2,0a3.2,3.2 0,1 1,6.4 0a3.2,3.2 0,1 1,-6.4 0" />
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="M9,2L7.17,4H4c-1.1,0 -2,0.9 -2,2v12c0,1.1 0.9,2 2,2h16c1.1,0 2,-0.9 2,-2V6c0,-1.1 -0.9,-2 -2,-2h-3.17L15,2H9zm3,15c-2.76,0 -5,-2.24 -5,-5s2.24,-5 5,-5 5,2.24 5,5 -2.24,5 -5,5z" />
|
||||
</vector>
|
||||
@@ -0,0 +1,9 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24.0"
|
||||
android:viewportHeight="24.0">
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="M22,16V4c0,-1.1 -0.9,-2 -2,-2H8c-1.1,0 -2,0.9 -2,2v12c0,1.1 0.9,2 2,2h12c1.1,0 2,-0.9 2,-2zm-11,-4l2.03,2.71L16,11l4,5H8l3,-4zM2,6v14c0,1.1 0.9,2 2,2h14v-2H4V6H2z" />
|
||||
</vector>
|
||||
@@ -0,0 +1,9 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24.0"
|
||||
android:viewportHeight="24.0">
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="M4,6H2v14c0,1.1 0.9,2 2,2h14v-2H4V6zm16,-4H8c-1.1,0 -2,0.9 -2,2v12c0,1.1 0.9,2 2,2h12c1.1,0 2,-0.9 2,-2V4c0,-1.1 -0.9,-2 -2,-2zm-8,12.5v-9l6,4.5 -6,4.5z" />
|
||||
</vector>
|
||||
@@ -0,0 +1,9 @@
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="rectangle">
|
||||
<gradient
|
||||
android:angle="135"
|
||||
android:centerColor="#009688"
|
||||
android:endColor="#00695C"
|
||||
android:startColor="#4DB6AC"
|
||||
android:type="linear" />
|
||||
</shape>
|
||||
@@ -0,0 +1,26 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.drawerlayout.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/drawer_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:fitsSystemWindows="true"
|
||||
tools:openDrawer="start">
|
||||
|
||||
<include
|
||||
android:id="@+id/app_bar_main"
|
||||
layout="@layout/app_bar_main"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
|
||||
<com.google.android.material.navigation.NavigationView
|
||||
android:id="@+id/nav_view"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_gravity="start"
|
||||
android:fitsSystemWindows="true"
|
||||
app:headerLayout="@layout/nav_header_main"
|
||||
app:menu="@menu/activity_main_drawer" />
|
||||
|
||||
</androidx.drawerlayout.widget.DrawerLayout>
|
||||
@@ -0,0 +1,31 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".MainActivity">
|
||||
|
||||
<com.google.android.material.appbar.AppBarLayout
|
||||
android:id="@+id/appbar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<androidx.appcompat.widget.Toolbar
|
||||
android:id="@+id/toolbar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="?attr/actionBarSize" />
|
||||
|
||||
</com.google.android.material.appbar.AppBarLayout>
|
||||
|
||||
<include layout="@layout/content_main" />
|
||||
|
||||
<com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||
android:id="@+id/fab"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="bottom|end"
|
||||
android:layout_margin="16dp"
|
||||
app:srcCompat="@android:drawable/ic_dialog_email" />
|
||||
|
||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
||||
@@ -0,0 +1,21 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
app:layout_behavior="@string/appbar_scrolling_view_behavior"
|
||||
tools:showIn="@layout/app_bar_main">
|
||||
|
||||
<fragment
|
||||
android:id="@+id/nav_host_fragment_content_main"
|
||||
android:name="androidx.navigation.fragment.NavHostFragment"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
app:defaultNavHost="true"
|
||||
app:layout_constraintLeft_toLeftOf="parent"
|
||||
app:layout_constraintRight_toRightOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:navGraph="@navigation/mobile_navigation" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
@@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".ui.gallery.GalleryFragment">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text_gallery"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="8dp"
|
||||
android:layout_marginTop="8dp"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:textAlignment="center"
|
||||
android:textSize="20sp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
@@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".ui.home.HomeFragment">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text_home"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="8dp"
|
||||
android:layout_marginTop="8dp"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:textAlignment="center"
|
||||
android:textSize="20sp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
@@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".ui.slideshow.SlideshowFragment">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text_slideshow"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="8dp"
|
||||
android:layout_marginTop="8dp"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:textAlignment="center"
|
||||
android:textSize="20sp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
@@ -0,0 +1,35 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/nav_header_height"
|
||||
android:background="@drawable/side_nav_bar"
|
||||
android:gravity="bottom"
|
||||
android:orientation="vertical"
|
||||
android:paddingLeft="@dimen/activity_horizontal_margin"
|
||||
android:paddingTop="@dimen/activity_vertical_margin"
|
||||
android:paddingRight="@dimen/activity_horizontal_margin"
|
||||
android:paddingBottom="@dimen/activity_vertical_margin"
|
||||
android:theme="@style/ThemeOverlay.AppCompat.Dark">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/imageView"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:contentDescription="@string/nav_header_desc"
|
||||
android:paddingTop="@dimen/nav_header_vertical_spacing"
|
||||
app:srcCompat="@mipmap/ic_launcher_round" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingTop="@dimen/nav_header_vertical_spacing"
|
||||
android:text="@string/nav_header_title"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Body1" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/nav_header_subtitle" />
|
||||
</LinearLayout>
|
||||
@@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
tools:showIn="navigation_view">
|
||||
|
||||
<group android:checkableBehavior="single">
|
||||
<item
|
||||
android:id="@+id/nav_home"
|
||||
android:icon="@drawable/ic_menu_camera"
|
||||
android:title="@string/menu_home" />
|
||||
<item
|
||||
android:id="@+id/nav_gallery"
|
||||
android:icon="@drawable/ic_menu_gallery"
|
||||
android:title="@string/menu_gallery" />
|
||||
<item
|
||||
android:id="@+id/nav_slideshow"
|
||||
android:icon="@drawable/ic_menu_slideshow"
|
||||
android:title="@string/menu_slideshow" />
|
||||
</group>
|
||||
</menu>
|
||||
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
<item
|
||||
android:id="@+id/action_settings"
|
||||
android:orderInCategory="100"
|
||||
android:title="@string/action_settings"
|
||||
app:showAsAction="never" />
|
||||
</menu>
|
||||
@@ -0,0 +1,7 @@
|
||||
<resources>
|
||||
<!-- Default screen margins, per the Android Design guidelines. -->
|
||||
<dimen name="activity_horizontal_margin">16dp</dimen>
|
||||
<dimen name="activity_vertical_margin">16dp</dimen>
|
||||
<dimen name="nav_header_vertical_spacing">8dp</dimen>
|
||||
<dimen name="nav_header_height">176dp</dimen>
|
||||
</resources>
|
||||
@@ -17,6 +17,8 @@
|
||||
|
||||
package com.itsaky.androidide.templates.impl
|
||||
|
||||
import com.itsaky.androidide.templates.base.AndroidModuleTemplateBuilder
|
||||
|
||||
/**
|
||||
* Indents the given string for the given [indentation level][level].
|
||||
*/
|
||||
@@ -28,4 +30,9 @@ fun String.indent(level: Int): String {
|
||||
append(" ".repeat(level * 4))
|
||||
}
|
||||
}.toString()
|
||||
}
|
||||
|
||||
internal fun AndroidModuleTemplateBuilder.templateAsset(name: String, path: String
|
||||
): String {
|
||||
return "templates/${name}/${path}"
|
||||
}
|
||||
+128
@@ -0,0 +1,128 @@
|
||||
/*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.itsaky.androidide.templates.impl.navDrawerActivity
|
||||
|
||||
import com.itsaky.androidide.templates.Language.Kotlin
|
||||
import com.itsaky.androidide.templates.SrcSet.Main
|
||||
import com.itsaky.androidide.templates.base.AndroidModuleTemplateBuilder
|
||||
import com.itsaky.androidide.templates.base.baseProject
|
||||
import com.itsaky.androidide.templates.base.models.Dependency
|
||||
import com.itsaky.androidide.templates.base.modules.android.defaultAppModule
|
||||
import com.itsaky.androidide.templates.base.util.AndroidModuleResManager.ResourceType.DRAWABLE
|
||||
import com.itsaky.androidide.templates.base.util.AndroidModuleResManager.ResourceType.LAYOUT
|
||||
import com.itsaky.androidide.templates.base.util.AndroidModuleResManager.ResourceType.MENU
|
||||
import com.itsaky.androidide.templates.base.util.AndroidModuleResManager.ResourceType.NAVIGATION
|
||||
import com.itsaky.androidide.templates.base.util.AndroidModuleResManager.ResourceType.VALUES
|
||||
import com.itsaky.androidide.templates.impl.base.emptyThemesAndColors
|
||||
import com.itsaky.androidide.templates.impl.base.writeMainActivity
|
||||
import com.itsaky.androidide.templates.impl.templateAsset
|
||||
|
||||
fun navigationDrawerActivityProject() = baseProject {
|
||||
defaultAppModule {
|
||||
recipe = {
|
||||
sources {
|
||||
writeMainActivity(this, ktSrc = ::navDrawerActivitySrcKt,
|
||||
javaSrc = ::navDrawerActivitySrcJava)
|
||||
}
|
||||
|
||||
res {
|
||||
copyAssetsRecursively(templateAsset("navDrawer", "res/layout"),
|
||||
resDir(LAYOUT, Main))
|
||||
copyAssetsRecursively(templateAsset("navDrawer", "res/drawable"),
|
||||
resDir(DRAWABLE, Main))
|
||||
copyAssetsRecursively(templateAsset("navDrawer", "res/menu"),
|
||||
resDir(MENU, Main))
|
||||
copyAssetsRecursively(templateAsset("navDrawer", "res/values"),
|
||||
resDir(VALUES, Main))
|
||||
|
||||
writeXmlResource("mobile_navigation", NAVIGATION,
|
||||
source = ::navDrawerNavigationXmlSrc)
|
||||
|
||||
putStringRes("navigation_drawer_open", "Open navigation drawer")
|
||||
putStringRes("navigation_drawer_close", "Close navigation drawer")
|
||||
putStringRes("nav_header_title", "AndroidIDE")
|
||||
putStringRes("nav_header_subtitle", "contact@androidide.com")
|
||||
putStringRes("nav_header_desc", "Navigation header")
|
||||
putStringRes("action_settings", "Settings")
|
||||
putStringRes("menu_home", "Home")
|
||||
putStringRes("menu_gallery", "Gallery")
|
||||
putStringRes("menu_slideshow", "Slideshow")
|
||||
|
||||
emptyThemesAndColors()
|
||||
}
|
||||
|
||||
if (data.language == Kotlin) {
|
||||
navDrawerActivityProjectKt()
|
||||
} else {
|
||||
navDrawerActivityProjectJava()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun AndroidModuleTemplateBuilder.navDrawerActivityProjectJava() {
|
||||
executor.apply {
|
||||
addDependency(Dependency.AndroidX.Navigation_Ui)
|
||||
addDependency(Dependency.AndroidX.Navigation_Fragment)
|
||||
addDependency(Dependency.AndroidX.LifeCycle_LiveData)
|
||||
addDependency(Dependency.AndroidX.LifeCycle_ViewModel)
|
||||
|
||||
sources {
|
||||
writeJavaSrc("${data.packageName}.ui.gallery", "GalleryFragment",
|
||||
source = ::galleryFragmentSrcJava)
|
||||
writeJavaSrc("${data.packageName}.ui.gallery", "GalleryViewModel",
|
||||
source = ::galleryModelSrcJava)
|
||||
|
||||
writeJavaSrc("${data.packageName}.ui.home", "HomeFragment",
|
||||
source = ::homeFragmentSrcJava)
|
||||
writeJavaSrc("${data.packageName}.ui.home", "HomeViewModel",
|
||||
source = ::homeModelSrcJava)
|
||||
|
||||
writeJavaSrc("${data.packageName}.ui.slideshow", "SlideshowFragment",
|
||||
source = ::slideshowFragmentSrcJava)
|
||||
writeJavaSrc("${data.packageName}.ui.slideshow", "SlideshowViewModel",
|
||||
source = ::slideshowModelSrcJava)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun AndroidModuleTemplateBuilder.navDrawerActivityProjectKt() {
|
||||
executor.apply {
|
||||
addDependency(Dependency.AndroidX.Navigation_Ui_Ktx)
|
||||
addDependency(Dependency.AndroidX.Navigation_Fragment_Ktx)
|
||||
addDependency(Dependency.AndroidX.LifeCycle_LiveData_Ktx)
|
||||
addDependency(Dependency.AndroidX.LifeCycle_ViewModel_Ktx)
|
||||
|
||||
sources {
|
||||
writeKtSrc("${data.packageName}.ui.gallery", "GalleryFragment",
|
||||
source = ::galleryFragmentSrcKt)
|
||||
writeKtSrc("${data.packageName}.ui.gallery", "GalleryViewModel",
|
||||
source = ::galleryModelSrcKt)
|
||||
|
||||
writeKtSrc("${data.packageName}.ui.home", "HomeFragment",
|
||||
source = ::homeFragmentSrcKt)
|
||||
writeKtSrc("${data.packageName}.ui.home", "HomeViewModel",
|
||||
source = ::homeModelSrcKt)
|
||||
|
||||
writeKtSrc("${data.packageName}.ui.slideshow", "SlideshowFragment",
|
||||
source = ::slideshowFragmentSrcKt)
|
||||
writeKtSrc("${data.packageName}.ui.slideshow", "SlideshowViewModel",
|
||||
source = ::slideshowModelSrcKt)
|
||||
}
|
||||
}
|
||||
}
|
||||
+153
@@ -0,0 +1,153 @@
|
||||
/*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.itsaky.androidide.templates.impl.navDrawerActivity
|
||||
|
||||
import com.itsaky.androidide.templates.base.AndroidModuleTemplateBuilder
|
||||
|
||||
internal fun AndroidModuleTemplateBuilder.navDrawerActivitySrcJava() = """
|
||||
package ${data.packageName};
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.view.Menu;
|
||||
|
||||
import com.google.android.material.snackbar.Snackbar;
|
||||
import com.google.android.material.navigation.NavigationView;
|
||||
|
||||
import androidx.navigation.NavController;
|
||||
import androidx.navigation.Navigation;
|
||||
import androidx.navigation.ui.AppBarConfiguration;
|
||||
import androidx.navigation.ui.NavigationUI;
|
||||
import androidx.drawerlayout.widget.DrawerLayout;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import ${data.packageName}.databinding.ActivityMainBinding;
|
||||
|
||||
public class MainActivity extends AppCompatActivity {
|
||||
|
||||
private AppBarConfiguration mAppBarConfiguration;
|
||||
private ActivityMainBinding binding;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
binding = ActivityMainBinding.inflate(getLayoutInflater());
|
||||
setContentView(binding.getRoot());
|
||||
|
||||
setSupportActionBar(binding.appBarMain.toolbar);
|
||||
binding.appBarMain.fab.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
|
||||
.setAction("Action", null).show();
|
||||
}
|
||||
});
|
||||
|
||||
DrawerLayout drawer = binding.drawerLayout;
|
||||
NavigationView navigationView = binding.navView;
|
||||
|
||||
// Passing each menu ID as a set of Ids because each
|
||||
// menu should be considered as top level destinations.
|
||||
mAppBarConfiguration = new AppBarConfiguration.Builder(
|
||||
R.id.nav_home, R.id.nav_gallery, R.id.nav_slideshow)
|
||||
.setOpenableLayout(drawer)
|
||||
.build();
|
||||
|
||||
NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment_content_main);
|
||||
NavigationUI.setupActionBarWithNavController(this, navController, mAppBarConfiguration);
|
||||
NavigationUI.setupWithNavController(navigationView, navController);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
// Inflate the menu; this adds items to the action bar if it is present.
|
||||
getMenuInflater().inflate(R.menu.main, menu);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onSupportNavigateUp() {
|
||||
NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment_content_main);
|
||||
return NavigationUI.navigateUp(navController, mAppBarConfiguration)
|
||||
|| super.onSupportNavigateUp();
|
||||
}
|
||||
}
|
||||
""".trim()
|
||||
|
||||
internal fun AndroidModuleTemplateBuilder.navDrawerActivitySrcKt() = """
|
||||
package ${data.packageName}
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.Menu
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.drawerlayout.widget.DrawerLayout
|
||||
import androidx.navigation.findNavController
|
||||
import androidx.navigation.ui.AppBarConfiguration
|
||||
import androidx.navigation.ui.navigateUp
|
||||
import androidx.navigation.ui.setupActionBarWithNavController
|
||||
import androidx.navigation.ui.setupWithNavController
|
||||
import com.google.android.material.navigation.NavigationView
|
||||
import com.google.android.material.snackbar.Snackbar
|
||||
|
||||
import ${data.packageName}.databinding.ActivityMainBinding
|
||||
|
||||
class MainActivity : AppCompatActivity() {
|
||||
|
||||
private lateinit var appBarConfiguration: AppBarConfiguration
|
||||
private lateinit var binding: ActivityMainBinding
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
binding = ActivityMainBinding.inflate(layoutInflater)
|
||||
setContentView(binding.root)
|
||||
|
||||
setSupportActionBar(binding.appBarMain.toolbar)
|
||||
|
||||
binding.appBarMain.fab.setOnClickListener { view ->
|
||||
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
|
||||
.setAction("Action", null).show()
|
||||
}
|
||||
|
||||
val navController = findNavController(R.id.nav_host_fragment_content_main)
|
||||
|
||||
// Passing each menu ID as a set of Ids because each
|
||||
// menu should be considered as top level destinations.
|
||||
appBarConfiguration = AppBarConfiguration(
|
||||
setOf(
|
||||
R.id.nav_home, R.id.nav_gallery, R.id.nav_slideshow
|
||||
), binding.drawerLayout
|
||||
)
|
||||
|
||||
setupActionBarWithNavController(navController, appBarConfiguration)
|
||||
binding.navView.setupWithNavController(navController)
|
||||
}
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
||||
// Inflate the menu; this adds items to the action bar if it is present.
|
||||
menuInflater.inflate(R.menu.main, menu)
|
||||
return true
|
||||
}
|
||||
|
||||
override fun onSupportNavigateUp(): Boolean {
|
||||
val navController = findNavController(R.id.nav_host_fragment_content_main)
|
||||
return navController.navigateUp(appBarConfiguration) || super.onSupportNavigateUp()
|
||||
}
|
||||
}
|
||||
""".trim()
|
||||
+106
@@ -0,0 +1,106 @@
|
||||
/*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.itsaky.androidide.templates.impl.navDrawerActivity
|
||||
|
||||
import com.itsaky.androidide.templates.base.AndroidModuleTemplateBuilder
|
||||
|
||||
internal fun AndroidModuleTemplateBuilder.galleryFragmentSrcJava() = """
|
||||
package ${data.packageName}.ui.gallery;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
|
||||
import ${data.packageName}.databinding.FragmentGalleryBinding;
|
||||
|
||||
public class GalleryFragment extends Fragment {
|
||||
|
||||
private FragmentGalleryBinding binding;
|
||||
|
||||
public View onCreateView(@NonNull LayoutInflater inflater,
|
||||
ViewGroup container, Bundle savedInstanceState) {
|
||||
GalleryViewModel galleryViewModel =
|
||||
new ViewModelProvider(this).get(GalleryViewModel.class);
|
||||
|
||||
binding = FragmentGalleryBinding.inflate(inflater, container, false);
|
||||
View root = binding.getRoot();
|
||||
|
||||
final TextView textView = binding.textGallery;
|
||||
galleryViewModel.getText().observe(getViewLifecycleOwner(), textView::setText);
|
||||
return root;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
super.onDestroyView();
|
||||
binding = null;
|
||||
}
|
||||
}
|
||||
""".trim()
|
||||
|
||||
internal fun AndroidModuleTemplateBuilder.galleryFragmentSrcKt() = """
|
||||
package ${data.packageName}.ui.gallery
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.TextView
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
|
||||
import ${data.packageName}.databinding.FragmentGalleryBinding
|
||||
|
||||
class GalleryFragment : Fragment() {
|
||||
|
||||
private var _binding: FragmentGalleryBinding? = null
|
||||
|
||||
// This property is only valid between onCreateView and
|
||||
// onDestroyView.
|
||||
private val binding get() = _binding!!
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View {
|
||||
val galleryViewModel =
|
||||
ViewModelProvider(this).get(GalleryViewModel::class.java)
|
||||
|
||||
_binding = FragmentGalleryBinding.inflate(inflater, container, false)
|
||||
val root: View = binding.root
|
||||
|
||||
val textView: TextView = binding.textGallery
|
||||
galleryViewModel.text.observe(viewLifecycleOwner) {
|
||||
textView.text = it
|
||||
}
|
||||
return root
|
||||
}
|
||||
|
||||
override fun onDestroyView() {
|
||||
super.onDestroyView()
|
||||
_binding = null
|
||||
}
|
||||
}
|
||||
""".trim()
|
||||
+106
@@ -0,0 +1,106 @@
|
||||
/*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.itsaky.androidide.templates.impl.navDrawerActivity
|
||||
|
||||
import com.itsaky.androidide.templates.base.AndroidModuleTemplateBuilder
|
||||
|
||||
internal fun AndroidModuleTemplateBuilder.homeFragmentSrcJava() = """
|
||||
package ${data.packageName}.ui.home;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
|
||||
import ${data.packageName}.databinding.FragmentHomeBinding;
|
||||
|
||||
public class HomeFragment extends Fragment {
|
||||
|
||||
private FragmentHomeBinding binding;
|
||||
|
||||
public View onCreateView(@NonNull LayoutInflater inflater,
|
||||
ViewGroup container, Bundle savedInstanceState) {
|
||||
HomeViewModel homeViewModel =
|
||||
new ViewModelProvider(this).get(HomeViewModel.class);
|
||||
|
||||
binding = FragmentHomeBinding.inflate(inflater, container, false);
|
||||
View root = binding.getRoot();
|
||||
|
||||
final TextView textView = binding.textHome;
|
||||
homeViewModel.getText().observe(getViewLifecycleOwner(), textView::setText);
|
||||
return root;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
super.onDestroyView();
|
||||
binding = null;
|
||||
}
|
||||
}
|
||||
""".trim()
|
||||
|
||||
internal fun AndroidModuleTemplateBuilder.homeFragmentSrcKt() = """
|
||||
package ${data.packageName}.ui.home
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.TextView
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
|
||||
import ${data.packageName}.databinding.FragmentHomeBinding
|
||||
|
||||
class HomeFragment : Fragment() {
|
||||
|
||||
private var _binding: FragmentHomeBinding? = null
|
||||
|
||||
// This property is only valid between onCreateView and
|
||||
// onDestroyView.
|
||||
private val binding get() = _binding!!
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View {
|
||||
val homeViewModel =
|
||||
ViewModelProvider(this).get(HomeViewModel::class.java)
|
||||
|
||||
_binding = FragmentHomeBinding.inflate(inflater, container, false)
|
||||
val root: View = binding.root
|
||||
|
||||
val textView: TextView = binding.textHome
|
||||
homeViewModel.text.observe(viewLifecycleOwner) {
|
||||
textView.text = it
|
||||
}
|
||||
return root
|
||||
}
|
||||
|
||||
override fun onDestroyView() {
|
||||
super.onDestroyView()
|
||||
_binding = null
|
||||
}
|
||||
}
|
||||
""".trim()
|
||||
+106
@@ -0,0 +1,106 @@
|
||||
/*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.itsaky.androidide.templates.impl.navDrawerActivity
|
||||
|
||||
import com.itsaky.androidide.templates.base.AndroidModuleTemplateBuilder
|
||||
|
||||
internal fun AndroidModuleTemplateBuilder.slideshowFragmentSrcJava() = """
|
||||
package ${data.packageName}.ui.slideshow;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
|
||||
import ${data.packageName}.databinding.FragmentSlideshowBinding;
|
||||
|
||||
public class SlideshowFragment extends Fragment {
|
||||
|
||||
private FragmentSlideshowBinding binding;
|
||||
|
||||
public View onCreateView(@NonNull LayoutInflater inflater,
|
||||
ViewGroup container, Bundle savedInstanceState) {
|
||||
SlideshowViewModel slideshowViewModel =
|
||||
new ViewModelProvider(this).get(SlideshowViewModel.class);
|
||||
|
||||
binding = FragmentSlideshowBinding.inflate(inflater, container, false);
|
||||
View root = binding.getRoot();
|
||||
|
||||
final TextView textView = binding.textSlideshow;
|
||||
slideshowViewModel.getText().observe(getViewLifecycleOwner(), textView::setText);
|
||||
return root;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
super.onDestroyView();
|
||||
binding = null;
|
||||
}
|
||||
}
|
||||
""".trim()
|
||||
|
||||
internal fun AndroidModuleTemplateBuilder.slideshowFragmentSrcKt() = """
|
||||
package ${data.packageName}.ui.slideshow
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.TextView
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
|
||||
import ${data.packageName}.databinding.FragmentSlideshowBinding
|
||||
|
||||
class SlideshowFragment : Fragment() {
|
||||
|
||||
private var _binding: FragmentSlideshowBinding? = null
|
||||
|
||||
// This property is only valid between onCreateView and
|
||||
// onDestroyView.
|
||||
private val binding get() = _binding!!
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View {
|
||||
val slideshowViewModel =
|
||||
ViewModelProvider(this).get(SlideshowViewModel::class.java)
|
||||
|
||||
_binding = FragmentSlideshowBinding.inflate(inflater, container, false)
|
||||
val root: View = binding.root
|
||||
|
||||
val textView: TextView = binding.textSlideshow
|
||||
slideshowViewModel.text.observe(viewLifecycleOwner) {
|
||||
textView.text = it
|
||||
}
|
||||
return root
|
||||
}
|
||||
|
||||
override fun onDestroyView() {
|
||||
super.onDestroyView()
|
||||
_binding = null
|
||||
}
|
||||
}
|
||||
""".trim()
|
||||
+58
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.itsaky.androidide.templates.impl.navDrawerActivity
|
||||
|
||||
import com.itsaky.androidide.templates.base.AndroidModuleTemplateBuilder
|
||||
|
||||
internal fun AndroidModuleTemplateBuilder.galleryModelSrcJava() = """
|
||||
package ${data.packageName}.ui.gallery;
|
||||
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
import androidx.lifecycle.ViewModel;
|
||||
|
||||
public class GalleryViewModel extends ViewModel {
|
||||
|
||||
private final MutableLiveData<String> mText;
|
||||
|
||||
public GalleryViewModel() {
|
||||
mText = new MutableLiveData<>();
|
||||
mText.setValue("This is gallery fragment");
|
||||
}
|
||||
|
||||
public LiveData<String> getText() {
|
||||
return mText;
|
||||
}
|
||||
}
|
||||
""".trim()
|
||||
|
||||
internal fun AndroidModuleTemplateBuilder.galleryModelSrcKt() = """
|
||||
package ${data.packageName}.ui.gallery
|
||||
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.ViewModel
|
||||
|
||||
class GalleryViewModel : ViewModel() {
|
||||
|
||||
private val _text = MutableLiveData<String>().apply {
|
||||
value = "This is gallery Fragment"
|
||||
}
|
||||
val text: LiveData<String> = _text
|
||||
}
|
||||
""".trim()
|
||||
+58
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.itsaky.androidide.templates.impl.navDrawerActivity
|
||||
|
||||
import com.itsaky.androidide.templates.base.AndroidModuleTemplateBuilder
|
||||
|
||||
internal fun AndroidModuleTemplateBuilder.homeModelSrcJava() = """
|
||||
package ${data.packageName}.ui.home;
|
||||
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
import androidx.lifecycle.ViewModel;
|
||||
|
||||
public class HomeViewModel extends ViewModel {
|
||||
|
||||
private final MutableLiveData<String> mText;
|
||||
|
||||
public HomeViewModel() {
|
||||
mText = new MutableLiveData<>();
|
||||
mText.setValue("This is home fragment");
|
||||
}
|
||||
|
||||
public LiveData<String> getText() {
|
||||
return mText;
|
||||
}
|
||||
}
|
||||
""".trim()
|
||||
|
||||
internal fun AndroidModuleTemplateBuilder.homeModelSrcKt() = """
|
||||
package ${data.packageName}.ui.home
|
||||
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.ViewModel
|
||||
|
||||
class HomeViewModel : ViewModel() {
|
||||
|
||||
private val _text = MutableLiveData<String>().apply {
|
||||
value = "This is home Fragment"
|
||||
}
|
||||
val text: LiveData<String> = _text
|
||||
}
|
||||
""".trim()
|
||||
+58
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.itsaky.androidide.templates.impl.navDrawerActivity
|
||||
|
||||
import com.itsaky.androidide.templates.base.AndroidModuleTemplateBuilder
|
||||
|
||||
internal fun AndroidModuleTemplateBuilder.slideshowModelSrcJava() = """
|
||||
package ${data.packageName}.ui.slideshow;
|
||||
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
import androidx.lifecycle.ViewModel;
|
||||
|
||||
public class SlideshowViewModel extends ViewModel {
|
||||
|
||||
private final MutableLiveData<String> mText;
|
||||
|
||||
public SlideshowViewModel() {
|
||||
mText = new MutableLiveData<>();
|
||||
mText.setValue("This is slideshow fragment");
|
||||
}
|
||||
|
||||
public LiveData<String> getText() {
|
||||
return mText;
|
||||
}
|
||||
}
|
||||
""".trim()
|
||||
|
||||
internal fun AndroidModuleTemplateBuilder.slideshowModelSrcKt() = """
|
||||
package ${data.packageName}.ui.slideshow
|
||||
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.ViewModel
|
||||
|
||||
class SlideshowViewModel : ViewModel() {
|
||||
|
||||
private val _text = MutableLiveData<String>().apply {
|
||||
value = "This is slideshow Fragment"
|
||||
}
|
||||
val text: LiveData<String> = _text
|
||||
}
|
||||
""".trim()
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.itsaky.androidide.templates.impl.navDrawerActivity
|
||||
|
||||
import com.itsaky.androidide.templates.base.AndroidModuleTemplateBuilder
|
||||
|
||||
internal fun AndroidModuleTemplateBuilder.navDrawerNavigationXmlSrc() = """
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/mobile_navigation"
|
||||
app:startDestination="@+id/nav_home">
|
||||
|
||||
<fragment
|
||||
android:id="@+id/nav_home"
|
||||
android:name="${data.packageName}.ui.home.HomeFragment"
|
||||
android:label="@string/menu_home"
|
||||
tools:layout="@layout/fragment_home" />
|
||||
|
||||
<fragment
|
||||
android:id="@+id/nav_gallery"
|
||||
android:name="${data.packageName}.ui.gallery.GalleryFragment"
|
||||
android:label="@string/menu_gallery"
|
||||
tools:layout="@layout/fragment_gallery" />
|
||||
|
||||
<fragment
|
||||
android:id="@+id/nav_slideshow"
|
||||
android:name="${data.packageName}.ui.slideshow.SlideshowFragment"
|
||||
android:label="@string/menu_slideshow"
|
||||
tools:layout="@layout/fragment_slideshow" />
|
||||
</navigation>
|
||||
""".trim()
|
||||
@@ -25,6 +25,7 @@ import com.itsaky.androidide.templates.base.modules.createConstructor
|
||||
import com.itsaky.androidide.templates.base.modules.createMethod
|
||||
import com.itsaky.androidide.templates.impl.basicActivity.basicActivityProject
|
||||
import com.itsaky.androidide.templates.impl.emptyActivity.emptyActivityProject
|
||||
import com.itsaky.androidide.templates.impl.navDrawerActivity.navigationDrawerActivityProject
|
||||
import com.itsaky.androidide.xml.permissions.Permission.INTERNET
|
||||
import com.squareup.javapoet.ArrayTypeName
|
||||
import com.squareup.javapoet.ParameterSpec
|
||||
@@ -140,4 +141,11 @@ class TemplateBuilderTest {
|
||||
basicActivityProject()
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `test navigation drawer activity template`() {
|
||||
testTemplate("NavigationDrawerActivity") {
|
||||
navigationDrawerActivityProject()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -19,6 +19,7 @@ package com.itsaky.androidide.templates
|
||||
|
||||
import com.itsaky.androidide.utils.FileProvider
|
||||
import java.io.File
|
||||
import java.io.FileNotFoundException
|
||||
import java.io.InputStream
|
||||
|
||||
/**
|
||||
@@ -32,6 +33,10 @@ class TestRecipeExecutor : RecipeExecutor {
|
||||
File(FileProvider.projectRoot().toFile(), "templates-api/src/main/assets")
|
||||
}
|
||||
|
||||
private val implAssets by lazy {
|
||||
File(FileProvider.projectRoot().toFile(), "templates-impl/src/main/assets")
|
||||
}
|
||||
|
||||
override fun copy(source: File, dest: File) {
|
||||
source.copyTo(dest)
|
||||
}
|
||||
@@ -52,6 +57,15 @@ class TestRecipeExecutor : RecipeExecutor {
|
||||
}
|
||||
|
||||
override fun copyAssetsRecursively(path: String, destDir: File) {
|
||||
File(this.assets, path).copyRecursively(destDir, true)
|
||||
var file = File(this.assets, path)
|
||||
if (!file.exists()) {
|
||||
file = File(this.implAssets, path)
|
||||
}
|
||||
|
||||
if (!file.exists()) {
|
||||
throw FileNotFoundException()
|
||||
}
|
||||
|
||||
file.copyRecursively(destDir, true)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user