diff --git a/.github/workflows/android.yml b/.github/workflows/android.yml index 60f877a..bb2c12e 100644 --- a/.github/workflows/android.yml +++ b/.github/workflows/android.yml @@ -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/README.md b/README.md index a696afb..95f97eb 100644 --- a/README.md +++ b/README.md @@ -57,7 +57,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..98b650c 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -29,12 +29,12 @@ 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 { @@ -49,7 +49,7 @@ android { 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" 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 }