-
Notifications
You must be signed in to change notification settings - Fork 0
Merge bugfix/splash-screen-setup into main
#4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,11 @@ | ||||||
| <?xml version="1.0" encoding="utf-8"?> | ||||||
| <resources> | ||||||
| <style name="Theme.ComposeAndroidTemplate.Starting" parent="Theme.SplashScreen"> | ||||||
| <item name="android:actionBarStyle">@style/Theme.AppCompat.NoActionBar</item> | ||||||
| <!-- TODO: Add your windowSplashScreenBackground color property--> | ||||||
|
CoderMP marked this conversation as resolved.
|
||||||
| <!-- TODO: Add your windowSplashScreenAnimatedIcon drawable property--> | ||||||
| <item name="windowSplashScreenBackground">@color/purple_700</item> | ||||||
|
||||||
| <item name="windowSplashScreenAnimatedIcon">@drawable/ic_launcher_foreground</item> | ||||||
|
||||||
| <item name="windowSplashScreenAnimatedIcon">@drawable/ic_launcher_foreground</item> | |
| <item name="windowSplashScreenAnimatedIcon">@mipmap/ic_launcher</item> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,4 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <resources> | ||
|
|
||
| <style name="Theme.ComposeAndroidTemplate" parent="android:Theme.Material.Light.NoActionBar" /> | ||
| </resources> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,6 +21,8 @@ tasks.register("templateCleanup") { | |
| it[0].sanitized() to it[1].sanitized() | ||
| } | ||
|
|
||
| val nameCasePreserved = repository.split("/")[1].sanitizedPreservingCase() | ||
|
|
||
| file(path = "gradle/libs.versions.toml").replace( | ||
| oldValue = "com.codermp.composeandroidtemplate", | ||
| newValue = "com.$owner.$name" | ||
|
|
@@ -31,7 +33,10 @@ tasks.register("templateCleanup") { | |
| ) | ||
|
|
||
| changePackageName(owner = owner, name = name) | ||
| changeManifestFile(name = name) | ||
| changeManifestFile(name = nameCasePreserved) | ||
| changeAppClassFile(name = nameCasePreserved) | ||
| changeThemeFile(name = nameCasePreserved) | ||
| changeResourceFiles(name = nameCasePreserved) | ||
|
|
||
| // cleanup the cleanup :) | ||
| file(path = ".github/workflows/cleanup.yml").delete() | ||
|
|
@@ -43,18 +48,43 @@ tasks.register("templateCleanup") { | |
| } | ||
| } | ||
|
|
||
| /** | ||
| * [String] extension function that sanitizes a string by removing all non-alphanumeric characters and | ||
| * converting it to lowercase. | ||
| */ | ||
| fun String.sanitized() = replace( | ||
| regex = Regex(pattern = "[^A-Za-z0-9]"), | ||
| replacement = "" | ||
| ).lowercase() | ||
|
|
||
| /** | ||
| * [String] extension function that sanitizes a string by removing all non-alphanumeric characters | ||
| * while preserving the case. This is useful for cases where the original case of the string is | ||
| * important, such as in class names. | ||
| */ | ||
| fun String.sanitizedPreservingCase() = split(regex = Regex("[^A-Za-z0-9]")) | ||
| .filter { it.isNotEmpty() } | ||
| .joinToString("") | ||
|
|
||
| /** | ||
| * [File] extension function that replaces all occurrences of `oldValue` with `newValue` in the file. | ||
| * @param oldValue The string to be replaced. | ||
| * @param newValue The string to replace with. | ||
| */ | ||
| fun File.replace(oldValue: String, newValue: String) { | ||
| writeText(text = readText().replace(oldValue, newValue)) | ||
| } | ||
|
|
||
| fun srcDirectories() = projectDir.listFiles()!! | ||
| /** | ||
| * Returns a list of source directories in the project. | ||
| * It excludes the `buildSrc` directory to avoid unnecessary processing. | ||
| */ | ||
| fun srcDirectories() = projectDir | ||
| .listFiles()!! | ||
| .filter { it.isDirectory && it.name != "buildSrc" } | ||
| .flatMap { it.listFiles()!!.filter { it.isDirectory && it.name == "src" } } | ||
| .flatMap { | ||
| it.listFiles()!!.filter { it.isDirectory && it.name == "src" } | ||
| } | ||
|
|
||
| @Suppress("NestedBlockDepth") | ||
| /** | ||
|
|
@@ -63,12 +93,18 @@ fun srcDirectories() = projectDir.listFiles()!! | |
| * @param name The name of the repository, usually the project name. | ||
| */ | ||
| fun changePackageName(owner: String, name: String) { | ||
| srcDirectories().forEach { | ||
| it.walk().filter { | ||
| it.isFile && (it.extension == "kt" || it.extension == "kts" || it.extension == "xml") | ||
| }.forEach { | ||
| it.replace("com.codermp.composeandroidtemplate", "com.$owner.$name") | ||
| } | ||
| srcDirectories().forEach { directory -> | ||
| directory | ||
| .walk() | ||
| .filter { | ||
| it.isFile && (it.extension == "kt" || it.extension == "kts" || it.extension == "xml") | ||
| } | ||
| .forEach { file -> | ||
| file.replace( | ||
| oldValue = "com.codermp.composeandroidtemplate", | ||
| newValue = "com.$owner.$name" | ||
| ) | ||
| } | ||
| } | ||
| srcDirectories().forEach { srcDir -> | ||
| srcDir | ||
|
|
@@ -112,42 +148,100 @@ fun changePackageName(owner: String, name: String) { | |
| * @param name The name of the repository, usually the project name. | ||
| */ | ||
| fun changeManifestFile(name: String) { | ||
| val capitalizedName = name.split("-", "_") | ||
| .joinToString("") { it.replaceFirstChar { char -> char.uppercaseChar() } } | ||
|
|
||
| // Update AndroidManifest.xml files | ||
| projectDir.walk() | ||
| // Update AndroidManifest.xml file | ||
| projectDir | ||
| .walk() | ||
| .filter { it.name == "AndroidManifest.xml" } | ||
| .forEach { manifestFile -> | ||
| manifestFile.replace( | ||
| oldValue = "android:name=\".app.TemplateApp\"", | ||
| newValue = "android:name=\".app.${capitalizedName}App\"" | ||
| newValue = "android:name=\".app.${name}App\"" | ||
| ) | ||
| manifestFile.replace( | ||
| oldValue = "android:theme=\"@style/Theme.ComposeAndroidTemplate.Starting\"", | ||
| newValue = "android:theme=\"@style/Theme.$name.Starting\"", | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| // Update strings.xml files | ||
| projectDir.walk() | ||
| /** | ||
| * Change the main application class file to reflect the new project name. | ||
| * @param name The name of the repository, usually the project name. | ||
| */ | ||
| fun changeAppClassFile(name: String) { | ||
| // Rename TemplateApp class file | ||
| srcDirectories() | ||
| .forEach { srcDir -> | ||
| srcDir | ||
| .walk() | ||
| .filter { it.isFile && it.name == "TemplateApp.kt" } | ||
| .forEach { templateAppFile -> | ||
| // Update class name inside the file | ||
| templateAppFile.replace( | ||
| oldValue = "class TemplateApp", newValue = "class ${name}App" | ||
| ) | ||
| templateAppFile.replace( | ||
| oldValue = "this@TemplateApp", newValue = "this@${name}App" | ||
| ) | ||
|
|
||
| // Rename the file itself | ||
| val newFile = File(templateAppFile.parent, "${name}App.kt") | ||
| templateAppFile.renameTo(newFile) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Change the Compose theme file to reflect the new project name. | ||
| * @param name The name of the repository, usually the project name. | ||
| */ | ||
| fun changeThemeFile(name: String) { | ||
| srcDirectories() | ||
| .forEach { srcDir -> | ||
| srcDir | ||
| .walk() | ||
| .filter { it.isFile && it.name == "Theme.kt" } | ||
| .forEach { themeFile -> | ||
| themeFile.replace( | ||
| oldValue = "ComposeAndroidTemplateTheme", newValue = "${name}Theme" | ||
| ) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Change the resource files such as themes.xml, strings.xml, and splash.xml. | ||
| * @param name The name of the repository, usually the project name. | ||
| */ | ||
| fun changeResourceFiles(name: String) { | ||
| // Update themes.xml file | ||
| projectDir | ||
| .walk() | ||
| .filter { it.name == "themes.xml" } | ||
| .forEach { themesFile -> | ||
| themesFile.replace( | ||
| oldValue = "Theme.ComposeAndroidTemplate", newValue = "Theme.$name" | ||
| ) | ||
| } | ||
|
|
||
| // Update strings.xml file | ||
| projectDir | ||
| .walk() | ||
| .filter { it.name == "strings.xml" } | ||
| .forEach { stringsFile -> | ||
| stringsFile.replace( | ||
| oldValue = "Compose Android Template", | ||
| newValue = name.split("-", "_") | ||
| .joinToString(" ") { it.replaceFirstChar { char -> char.uppercaseChar() } } | ||
| oldValue = "Compose Android Template", newValue = name | ||
|
CoderMP marked this conversation as resolved.
CoderMP marked this conversation as resolved.
|
||
| ) | ||
| } | ||
|
|
||
| // Rename TemplateApp class files | ||
| srcDirectories().forEach { srcDir -> | ||
| srcDir.walk() | ||
| .filter { it.isFile && it.name == "TemplateApp.kt" } | ||
| .forEach { templateAppFile -> | ||
| // Update class name inside the file | ||
| templateAppFile.replace("class TemplateApp", "class ${capitalizedName}App") | ||
| templateAppFile.replace("this@TemplateApp", "this@${capitalizedName}App") | ||
|
|
||
| // Rename the file itself | ||
| val newFile = File(templateAppFile.parent, "${capitalizedName}App.kt") | ||
| templateAppFile.renameTo(newFile) | ||
| } | ||
| } | ||
| // Update splash.xml file | ||
| projectDir | ||
| .walk() | ||
| .filter { it.name == "splash.xml" } | ||
| .forEach { splashFile -> | ||
| splashFile.replace( | ||
| oldValue = "Theme.ComposeAndroidTemplate.Starting", | ||
| newValue = "Theme.${name}.Starting" | ||
| ) | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.