Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
open-pull-requests-limit: 5
labels:
- "dependencies"
- "github-actions"
commit-message:
prefix: "ci"
include: "scope"
81 changes: 81 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
name: Lint

on:
push:
branches:
- main
- upstream-v7.0.0
pull_request:

jobs:
detekt:
name: Detekt (Kotlin)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: 17
distribution: temurin

- name: Make gradlew executable
run: chmod +x gradlew

- name: Run Detekt
continue-on-error: true
run: ./gradlew detekt --no-daemon --continue || true

- name: Upload Detekt SARIF
if: always()
uses: github/codeql-action/upload-sarif@v3
continue-on-error: true
with:
sarif_file: app/build/reports/detekt/detekt.sarif
category: detekt

spotless:
name: Spotless (formatting)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: 17
distribution: temurin

- name: Make gradlew executable
run: chmod +x gradlew

- name: Check Spotless
continue-on-error: true
run: ./gradlew spotlessCheck --no-daemon || true

android-lint:
name: Android Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: 17
distribution: temurin

- name: Make gradlew executable
run: chmod +x gradlew

- name: Run Android Lint
continue-on-error: true
run: ./gradlew :app:lintRelease --no-daemon || true

- name: Upload Lint report
if: always()
uses: actions/upload-artifact@v4
with:
name: android-lint-report
path: app/build/reports/lint-results-release.html
100 changes: 100 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
name: Release APK

on:
push:
tags:
- 'v*'
workflow_dispatch:
inputs:
tag_name:
description: 'Tag name to attach the APK to (e.g. v7.1.0)'
required: true
type: string

permissions:
contents: write

jobs:
build-release:
name: Build and publish APK
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: 17
distribution: temurin

- name: Setup Gradle
uses: gradle/actions/setup-gradle@v3
with:
develocity-injection-enabled: false
cache-read-only: true

- name: Make gradlew executable
run: chmod +x gradlew

- name: Build Release APK
env:
SKETCHUB_API_KEY: ${{ secrets.SKETCHUB_API_KEY }}
run: ./gradlew --no-build-cache --no-configuration-cache --no-daemon assembleRelease

- name: Resolve tag name
id: tag
shell: bash
# Workflow-dispatch input is funneled through an env var so a
# malicious tag_name cannot break out of the bash context.
env:
INPUT_TAG_NAME: ${{ inputs.tag_name }}
run: |
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
TAG_NAME="$INPUT_TAG_NAME"
else
TAG_NAME="${GITHUB_REF#refs/tags/}"
fi
# Refuse anything but a sensible release tag to belt-and-braces
# the env-var defence above.
if ! [[ "$TAG_NAME" =~ ^[A-Za-z0-9._-]+$ ]]; then
echo "::error::Refusing unsafe tag name: $TAG_NAME"
exit 1
fi
Comment thread
devin-ai-integration[bot] marked this conversation as resolved.
Resolved
echo "name=$TAG_NAME" >> "$GITHUB_OUTPUT"

- name: Rename APK with tag
shell: bash
env:
TAG_NAME: ${{ steps.tag.outputs.name }}
run: |
cd app/build/outputs/apk/release
if [[ -f app-release.apk ]]; then
mv app-release.apk "SketchwarePro-${TAG_NAME}.apk"
fi
ls -la

- name: Compute checksums
# Runs AFTER the rename so SHA256SUMS.txt references the final
# filename users will actually download from the release.
working-directory: app/build/outputs/apk/release
run: |
sha256sum *.apk > SHA256SUMS.txt
cat SHA256SUMS.txt

- name: Create or update GitHub Release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ steps.tag.outputs.name }}
name: Sketchware Pro ${{ steps.tag.outputs.name }}
generate_release_notes: true
fail_on_unmatched_files: false
files: |
app/build/outputs/apk/release/SketchwarePro-${{ steps.tag.outputs.name }}.apk
app/build/outputs/apk/release/SHA256SUMS.txt

- name: Upload APK as workflow artifact
uses: actions/upload-artifact@v4
with:
name: SketchwarePro-${{ steps.tag.outputs.name }}
path: app/build/outputs/apk/release/*
retention-days: 30
79 changes: 79 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,54 @@ def analyticsEnabled = secrets != null

apply plugin: "com.android.application"
apply plugin: "kotlin-android"
apply plugin: "io.gitlab.arturbosch.detekt"
apply plugin: "com.diffplug.spotless"

detekt {
config.from(files("$rootDir/config/detekt/detekt.yml"))
parallel = true
buildUponDefaultConfig = true
autoCorrect = false
source.setFrom(files("src/main/java"))
}

tasks.named("detekt").configure {
reports {
sarif.required.set(true)
html.required.set(true)
txt.required.set(false)
xml.required.set(false)
md.required.set(false)
}
// Detekt is informational only for now; remove ignoreFailures once
// the existing legacy code base is gradually cleaned up.
ignoreFailures = true
}

spotless {
kotlin {
target "src/main/java/**/*.kt", "src/test/java/**/*.kt"
targetExclude "src/main/java/a/**", "src/main/java/com/besome/**", "src/main/java/mod/agus/**", "src/main/java/kellinwood/**"
ktlint("1.3.1").editorConfigOverride([
"ktlint_standard_function-naming": "disabled",
"ktlint_standard_property-naming": "disabled",
"ktlint_standard_no-wildcard-imports": "disabled",
"ktlint_standard_filename": "disabled",
])
endWithNewline()
trimTrailingWhitespace()
}
kotlinGradle {
target "*.gradle.kts", "*.gradle"
ktlint("1.3.1")
}
format "misc", {
target "**/*.md", "**/*.gitignore", "**/*.yml", "**/*.yaml"
targetExclude "**/build/**", "**/.gradle/**"
trimTrailingWhitespace()
endWithNewline()
}
}

if (analyticsEnabled) {
apply plugin: "com.google.gms.google-services"
Expand Down Expand Up @@ -71,6 +119,16 @@ android {
buildConfig = true
}

testOptions {
unitTests {
// Lets unit tests call into Android classes that exist only as
// stubs in the SDK jar (e.g. android.util.Pair, android.text.TextUtils)
// by returning default values instead of throwing "Stub!" errors.
returnDefaultValues = true
includeAndroidResources = false
}
}

configurations.implementation {
exclude group: 'javax.inject', module: 'javax.inject'
exclude group: "org.jetbrains.kotlin", module: "kotlin-scripting-compiler-embeddable"
Expand Down Expand Up @@ -167,4 +225,25 @@ dependencies {
implementation "com.google.firebase:firebase-analytics"
implementation "com.google.firebase:firebase-messaging"
coreLibraryDesugaring "com.android.tools:desugar_jdk_libs_nio:2.1.5"

// ----- Test scaffolding (JUnit 5 + MockK + Truth) -----
testImplementation platform("org.junit:junit-bom:5.11.4")
testImplementation "org.junit.jupiter:junit-jupiter"
testRuntimeOnly "org.junit.platform:junit-platform-launcher"
testImplementation "org.junit.jupiter:junit-jupiter-params"
testImplementation "io.mockk:mockk:1.13.13"
testImplementation "com.google.truth:truth:1.4.4"
testImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-test:1.10.1"
testImplementation "androidx.arch.core:core-testing:2.2.0"

androidTestImplementation "androidx.test.ext:junit:1.2.1"
androidTestImplementation "androidx.test.espresso:espresso-core:3.6.1"
}

tasks.withType(Test).configureEach {
useJUnitPlatform()
testLogging {
events "passed", "skipped", "failed"
showStandardStreams = false
}
}
13 changes: 13 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,23 @@
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:largeHeap="true"
android:localeConfig="@xml/locales_config"
Comment thread
devin-ai-integration[bot] marked this conversation as resolved.
Resolved
android:supportsRtl="true"
android:requestLegacyExternalStorage="true"
android:theme="@style/Theme.SketchwarePro"
android:usesCleartextTraffic="true"
tools:targetApi="p">

<!-- Per-app language preferences (Android 13+ system UI, AppCompat 1.7+ for older). -->
<service
android:name="androidx.appcompat.app.AppLocalesMetadataHolderService"
android:enabled="false"
android:exported="false">
<meta-data
android:name="autoStoreLocales"
android:value="true" />
</service>

<activity
android:name=".activities.iconcreator.IconCreatorActivity"
android:exported="false"
Expand Down
1 change: 1 addition & 0 deletions app/src/main/java/pro/sketchware/SketchApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,6 @@ public void uncaughtException(@NonNull Thread thread, @NonNull Throwable throwab
});
super.onCreate();
ThemeManager.applyTheme(this, ThemeManager.getCurrentTheme(this));
ThemeManager.applyDynamicColorsIfEnabled(this);
}
}
63 changes: 63 additions & 0 deletions app/src/main/java/pro/sketchware/utility/locale/LocaleHelper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package pro.sketchware.utility.locale;

import android.content.Context;
import android.os.LocaleList;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatDelegate;
import androidx.core.os.LocaleListCompat;

import java.util.Locale;

/**
* Thin wrapper around {@link AppCompatDelegate} per-app language APIs introduced in
* AppCompat 1.6+. Together with the {@code AppLocalesMetadataHolderService} declared
* in the manifest with {@code autoStoreLocales=true}, the user's choice is persisted
* across app launches without us managing SharedPreferences manually.
*/
public final class LocaleHelper {

private LocaleHelper() {
}

/**
* Sets the application locale. Pass {@code null} or an empty tag to reset to the
* system default ("Use system language").
*/
public static void setAppLocale(@Nullable String bcp47Tag) {
if (bcp47Tag == null || bcp47Tag.isEmpty()) {
AppCompatDelegate.setApplicationLocales(LocaleListCompat.getEmptyLocaleList());
return;
}
AppCompatDelegate.setApplicationLocales(LocaleListCompat.forLanguageTags(bcp47Tag));
}

/**
* Returns the BCP-47 tag of the currently selected app locale, or empty string
* if the user follows the system default.
*/
@NonNull
public static String getCurrentTag() {
LocaleListCompat locales = AppCompatDelegate.getApplicationLocales();
if (locales.isEmpty()) {
return "";
}
Locale first = locales.get(0);
return first != null ? first.toLanguageTag() : "";
}

/**
* Convenience: returns the {@link Locale} actually being applied to UI (falls
* back to system default if no per-app override).
*/
@NonNull
public static Locale getEffectiveLocale(@NonNull Context context) {
LocaleListCompat locales = AppCompatDelegate.getApplicationLocales();
if (!locales.isEmpty() && locales.get(0) != null) {
return locales.get(0);
}
LocaleList sys = context.getResources().getConfiguration().getLocales();
return sys.isEmpty() ? Locale.getDefault() : sys.get(0);
}
}
Loading
Loading