diff --git a/_meta.json b/_meta.json index a624d3e..8c31462 100644 --- a/_meta.json +++ b/_meta.json @@ -2,6 +2,7 @@ "old_package": "dev.mfm.app", "new_package": "dev.mfm.app", "name": "AppLate", + "details": "An opensource android template", "version_name": "1.0.0", "version_code": "1" } diff --git a/app/src/main/res/drawable/icon.webp b/app/src/main/res/drawable/icon.webp new file mode 100644 index 0000000..02bb707 Binary files /dev/null and b/app/src/main/res/drawable/icon.webp differ diff --git a/app/src/main/res/drawable/theme.webp b/app/src/main/res/drawable/theme.webp new file mode 100644 index 0000000..b3ed8c0 Binary files /dev/null and b/app/src/main/res/drawable/theme.webp differ diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 52436b7..5dff053 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -22,12 +22,12 @@ + android:layout_gravity="center" /> @@ -51,7 +51,6 @@ android:layout_height="wrap_content" android:text="@string/app_details" android:textAppearance="?attr/textAppearanceBody1" - android:fontFamily="sans-serif" android:lineSpacingExtra="4dp" android:layout_marginTop="8dp" android:paddingHorizontal="24dp" diff --git a/init.py b/init.py index 5a9a9bf..220626c 100644 --- a/init.py +++ b/init.py @@ -7,6 +7,7 @@ def load_metadata(meta_file): """Load metadata from the JSON file.""" with open(meta_file, 'r') as file: return json.load(file) + def replace_in_file(file_path, replacements): """Replace text in a file based on a dictionary of replacements.""" with open(file_path, 'r') as file: @@ -15,6 +16,8 @@ def replace_in_file(file_path, replacements): content = content.replace(old, new) with open(file_path, 'w') as file: file.write(content) + print(f"Updated file: {file_path}") + def rename_package_path(base_path, old_package, new_package): """Rename the package directory path.""" old_path = os.path.join(base_path, *old_package.split('.')) @@ -24,50 +27,73 @@ def rename_package_path(base_path, old_package, new_package): print(f"Renamed package path from {old_path} to {new_path}.") else: print(f"Old package path {old_path} does not exist!") -def update_gradle_file(gradle_file, app_name, version_name, version_code, new_package): + +def update_gradle_file(gradle_file, app_name, details, version_name, version_code, new_package): """Update the app's Gradle build file.""" replacements = { "$(name)": app_name, + "$(details)": details, "$(version_name)": version_name, "$(version_code)": version_code, "$(application_id)": new_package } replace_in_file(gradle_file, replacements) - print(f"Updated Gradle file: {gradle_file}.") -def update_app_name(strings_xml_path, app_name): - """Update the app_name in the strings.xml file.""" + +def update_strings_xml(strings_xml_path, app_name, details): + """Update the app_name and app_details in the strings.xml file.""" if not os.path.exists(strings_xml_path): print(f"strings.xml not found at: {strings_xml_path}") return + with open(strings_xml_path, 'r') as file: content = file.read() - updated_content = re.sub( - r'()(.*?)()', - rf'\1{app_name}\3', - content - ) + + # Replace placeholders dynamically + updated_content = re.sub(r'()(.*?)()', rf'\1{app_name}\3', content) + updated_content = re.sub(r'()(.*?)()', rf'\1{details}\3', updated_content) + with open(strings_xml_path, 'w') as file: file.write(updated_content) - print(f"Updated app_name to '{app_name}' in strings.xml.") + print(f"Updated app_name to '{app_name}' and app_details to '{details}' in strings.xml.") + def process_android_project(meta_file_path): """Process the Android project to update package name, app name, and Gradle configuration.""" metadata = load_metadata(meta_file_path) + + # Ensure required keys exist in the metadata + required_keys = ["old_package", "new_package", "name", "details", "version_name", "version_code"] + for key in required_keys: + if key not in metadata: + print(f"Error: Missing key '{key}' in metadata file.") + return + old_package = metadata["old_package"] new_package = metadata["new_package"] app_name = metadata["name"] + details = metadata["details"] version_name = metadata["version_name"] version_code = metadata["version_code"] + app_src_main_java = "app/src/main/java/" gradle_file = "app/build.gradle" strings_xml_path = "app/src/main/res/values/strings.xml" + + # Update package name in Java/Kotlin files for root, _, files in os.walk(app_src_main_java): for file in files: if file.endswith(".java") or file.endswith(".kt"): file_path = os.path.join(root, file) replace_in_file(file_path, {f"package {old_package}": f"package {new_package}"}) + + # Rename package directories rename_package_path(app_src_main_java, old_package, new_package) - update_gradle_file(gradle_file, app_name, version_name, version_code, new_package) - update_app_name(strings_xml_path, app_name) + + # Update Gradle build file + update_gradle_file(gradle_file, app_name, details, version_name, version_code, new_package) + + # Update strings.xml + update_strings_xml(strings_xml_path, app_name, details) + print("Project renaming complete!") if __name__ == "__main__":