diff --git a/.github/workflows/android.yml b/.github/workflows/android.yml index 60f877a..da3b139 100644 --- a/.github/workflows/android.yml +++ b/.github/workflows/android.yml @@ -13,10 +13,10 @@ jobs: steps: - uses: actions/checkout@v2 - - name: set up JDK 1.8 + - name: set up JDK 15 uses: actions/setup-java@v1 with: - java-version: 1.8 + java-version: 15 - name: Grant execute permission for gradlew run: chmod +x gradlew @@ -29,10 +29,10 @@ jobs: steps: - uses: actions/checkout@v2 - - name: set up JDK 1.8 + - name: set up JDK 15 uses: actions/setup-java@v1 with: - java-version: 1.8 + java-version: 15 - name: Grant execute permission for gradlew run: chmod +x gradlew @@ -84,9 +84,9 @@ jobs: --type instrumentation --app app-debug/app-debug.apk --test app-debug-androidTest/app-debug-androidTest.apk - --device model=flame,version=30,locale=en,orientation=portrait - --device model=crownlte,version=28,locale=en,orientation=portrait + --device model=redfin,version=30,locale=en,orientation=portrait + --device model=greatlteks,version=28,locale=en,orientation=portrait --device model=OnePlus3T,version=26,locale=en,orientation=portrait --device model=HWMHA,version=24,locale=en,orientation=portrait --device model=grandppltedx,version=23,locale=en,orientation=portrait - --device model=Nexus5,version=21,locale=en,orientation=portrait" + --device model=hwALE-H,version=21,locale=en,orientation=portrait" diff --git a/CHANGELOG.md b/CHANGELOG.md index 952f01f..7e879ba 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,19 @@ Release Notes ==== +1.2.11 +-- +* [Bug] Bug fixed [#105](https://github.com/akexorcist/Localization/pull/105) [#118](https://github.com/akexorcist/Localization/pull/118) [#114](https://github.com/akexorcist/Localization/pull/114) [#118](https://github.com/akexorcist/Localization/pull/118) +* [PR] [#125](https://github.com/akexorcist/Localization/pull/125) - Fix WebView crashing on Android 5 +* Update Gradle and dependencies version + * Compile SDK Version 31 + * Target SDK Version 31 + * Kotlin : 1.6.10 + * Gradle : 7.0.2 + * Gradle Plugin : 4.2.2 + * Activity KTX : 1.4.0 + * AndroidX AppCompat 1.4.0 + 1.2.10 -- * [Bug] Bug fixed [#105](https://github.com/akexorcist/Localization/issues/105) [#103](https://github.com/akexorcist/Localization/issues/103) [#92](https://github.com/akexorcist/Localization/issues/92) diff --git a/MIGRATE_TO_ANDROIDX.md b/MIGRATE_TO_ANDROIDX.md new file mode 100644 index 0000000..1fe49ac --- /dev/null +++ b/MIGRATE_TO_ANDROIDX.md @@ -0,0 +1,33 @@ +# Migrate to AndroidX +Since AndroidX supports per-app language preferences for backward compatibility. Please migrate this library to AndroidX for more stability, compatibility, and longer supports from Google team. + +* AppCompat `1.6.0-alpha03` or higher is required (see [AppCompat release notes](https://developer.android.com/jetpack/androidx/releases/appcompat)) +* Remove `LocalizationApplicationDelegate` from Application class +* Replace `LocalizationActivity` with `AppCompatActivity` or remove `LocalizationActivityDelegate` from your custom Activity +* Replace `setLanguage(language)` with `AppCompatDelegate.setApplicationLocales()` +```kotlin +val locales = LocaleListCompat.forLanguageTags(language) +AppCompatDelegate.setApplicationLocales(locales) +``` +* Remove `toLocalizedContext()` and use original Context +* Remove `LocalizationServiceDelegate` from Service class +* Add `androidx.appcompat.app.AppLocalesMetadataHolderService` as `` in Android Manifest (see [Support Android 12 and lower](https://developer.android.com/about/versions/13/features/app-languages#android12-impl)) +```xml + + + + + + + + +``` +* Remove this library from your project (`implementation 'com.akexorcist:localization:'`) +* Test your app + +For more information about per-app language preferences, see [Per-app language preferences](https://developer.android.com/about/versions/13/features/app-languages) diff --git a/README.md b/README.md index a696afb..fe02409 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,9 @@ ![Minimum SDK Version](https://img.shields.io/badge/minSdkVersion-14-brightgreen) [![Workflow Status](https://github.com/akexorcist/Android-Localization/actions/workflows/android.yml/badge.svg)](https://github.com/akexorcist/Localization/actions) +Discontinued +==== +Since Google announced Android 13 with per-app language preferences supports. This feature also backport to older Android version with AndroidX. So there's no reason to contribute this library anymore. For more stability, compatibility, and longer supports from Google team, please migrate to AndroidX. See [Migrate to AndroidX guide](./MIGRATE_TO_ANDROIDX.md). Localization Library ==== @@ -40,12 +43,12 @@ allprojects { Gradle ```groovy -implementation 'com.akexorcist:localization:1.2.10' +implementation 'com.akexorcist:localization:1.2.11' ``` (Optional) You can exclude `androidx.appcompat:appcompat`, if your project does not use AppCompat. ```groovy -implementation ('com.akexorcist:localization:1.2.10') { +implementation ('com.akexorcist:localization:1.2.11') { exclude group: 'androidx.core', module: 'core' } ``` @@ -57,7 +60,7 @@ Custom application class which extends from `LocalizationApplication` is require ```kotlin class MainApplication: LocalizationApplication() { /* ... */ - override fun getDefaultLanguage() = Locale.ENGLISH + override fun getDefaultLanguage(context: Context) = Locale.ENGLISH } ``` diff --git a/app/build.gradle b/app/build.gradle index 60ae514..f35ca1f 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -29,38 +29,38 @@ android { } compileOptions { - sourceCompatibility JavaVersion.VERSION_1_8 - targetCompatibility JavaVersion.VERSION_1_8 + sourceCompatibility project.targetJavaVersion + targetCompatibility project.targetJavaVersion } kotlinOptions { - jvmTarget = '1.8' + jvmTarget = project.targetJavaVersion.toString() } buildFeatures { - viewBinding = true + viewBinding true } testOptions { - animationsDisabled = true + animationsDisabled true } } dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" - implementation 'androidx.appcompat:appcompat:1.2.0' + implementation 'androidx.appcompat:appcompat:1.4.0' implementation 'androidx.viewpager:viewpager:1.0.0' implementation 'androidx.preference:preference-ktx:1.1.1' implementation "androidx.viewpager2:viewpager2:1.0.0" - implementation "com.google.dagger:hilt-android:2.33-beta" - kapt "com.google.dagger:hilt-compiler:2.33-beta" + implementation 'com.google.dagger:hilt-android:2.40.4' + kapt 'com.google.dagger:hilt-compiler:2.40.4' - androidTestImplementation 'androidx.test:runner:1.3.0' - androidTestImplementation 'androidx.test:rules:1.3.0' - androidTestImplementation 'androidx.test.ext:junit:1.1.2' - androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' - androidTestImplementation 'androidx.test.espresso:espresso-web:3.3.0' + androidTestImplementation 'androidx.test:runner:1.4.0' + androidTestImplementation 'androidx.test:rules:1.4.0' + androidTestImplementation 'androidx.test.ext:junit:1.1.3' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' + androidTestImplementation 'androidx.test.espresso:espresso-web:3.4.0' androidTestImplementation 'androidx.test.uiautomator:uiautomator:2.2.0' androidTestImplementation 'com.agoda.kakao:kakao:2.4.0' diff --git a/app/src/androidTest/java/com/akexorcist/localizationapp/DialogWebViewTest.kt b/app/src/androidTest/java/com/akexorcist/localizationapp/DialogWebViewTest.kt index de888d6..05f1fab 100644 --- a/app/src/androidTest/java/com/akexorcist/localizationapp/DialogWebViewTest.kt +++ b/app/src/androidTest/java/com/akexorcist/localizationapp/DialogWebViewTest.kt @@ -27,20 +27,46 @@ class DialogWebViewTest { @Test fun dialogAndWebView() { + // Italy onScreen { buttonDialogWebView { scrollTo() click() } } - Thread.sleep(1000L) + onScreen { + buttonChangeLanguage { click() } + } + onScreen { + buttonItalian { click() } + } onScreen { buttonShowWebsite { click() } } onScreen { + webViewContent { + withElement(Locator.ID, "content") { + hasText(ExpectedContent.HELLO_WORLD_ITALIAN) + } + } + buttonBack { click() } + } + onScreen { buttonBack { click() } } + onScreen { + textViewTitle { + hasText(ExpectedContent.HELLO_WORLD_ITALIAN) + } + } + // American + onScreen { + buttonDialogWebView { + scrollTo() + click() + } + } onScreen { buttonChangeLanguage { click() } } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 2d1da1d..3316e98 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -10,30 +10,61 @@ android:label="@string/app_name" android:supportsRtl="true" android:theme="@style/AppTheme"> - + - - - - - - - - + + + + + + + + - - - - - - + + + + + + = Build.VERSION_CODES.JELLY_BEAN_MR1) { - applyOverrideConfiguration(localizationDelegate.updateConfigurationLocale(newBase)) - super.attachBaseContext(newBase) - } else { - super.attachBaseContext(localizationDelegate.attachBaseContext(newBase)) - } + super.attachBaseContext(delegateBaseContext(newBase)) + } + + /** + * Get a base context for [attachBaseContext]. You can override this function to wrap this + * context by using ContextWrapper. For example, if your project use ViewPump from + * `io.github.inflationx:viewpump` module ([ViewPump](https://github.com/InflationX/ViewPump)), + * you can override this method to wrap this context with `ViewPumpContextWrapper`. + * ```Kotlin + * override fun delegateBaseContext(context: Context): Context { + * val localizedContext: Context = super.delegateBaseContext(context) + * return ViewPumpContextWrapper.wrap(localizedContext) + * } + * ``` + * @param context a new base context from [attachBaseContext] parameter. + * @return a new base context. By default, it will return + * [LocalizationActivityDelegate.attachBaseContext] + */ + @CallSuper + open fun delegateBaseContext(context: Context): Context { + return localizationDelegate.attachBaseContext(context) } override fun getBaseContext(): Context { diff --git a/localization/src/main/java/com/akexorcist/localizationactivity/ui/LocalizationApplication.kt b/localization/src/main/java/com/akexorcist/localizationactivity/ui/LocalizationApplication.kt index 8cc7f00..f37d1ed 100644 --- a/localization/src/main/java/com/akexorcist/localizationactivity/ui/LocalizationApplication.kt +++ b/localization/src/main/java/com/akexorcist/localizationactivity/ui/LocalizationApplication.kt @@ -28,5 +28,5 @@ abstract class LocalizationApplication : Application() { return localizationDelegate.getResources(this, super.getResources()) } - abstract fun getDefaultLanguage(base: Context): Locale + abstract fun getDefaultLanguage(context: Context): Locale }