Skip to content
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

Added support for Android's per-app language setting. #4228

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
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
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@

package org.kiwix.kiwixmobile

import androidx.appcompat.app.AppCompatDelegate
import androidx.core.content.edit
import androidx.core.os.LocaleListCompat
import androidx.lifecycle.Lifecycle
import androidx.preference.PreferenceManager
import androidx.test.core.app.ActivityScenario
Expand All @@ -43,7 +45,6 @@ import org.kiwix.kiwixmobile.core.data.remote.ObjectBoxToLibkiwixMigrator
import org.kiwix.kiwixmobile.core.di.modules.DatabaseModule
import org.kiwix.kiwixmobile.core.page.bookmark.adapter.LibkiwixBookmarkItem
import org.kiwix.kiwixmobile.core.reader.ZimReaderSource
import org.kiwix.kiwixmobile.core.utils.LanguageUtils.Companion.handleLocaleChange
import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil
import org.kiwix.kiwixmobile.main.KiwixMainActivity
import org.kiwix.kiwixmobile.testutils.RetryRule
Expand Down Expand Up @@ -106,11 +107,7 @@ class ObjectBoxToLibkiwixMigratorTest : BaseActivityTest() {
activityScenario = ActivityScenario.launch(KiwixMainActivity::class.java).apply {
moveToState(Lifecycle.State.RESUMED)
onActivity {
handleLocaleChange(
it,
"en",
SharedPreferenceUtil(context)
)
AppCompatDelegate.setApplicationLocales(LocaleListCompat.forLanguageTags("en"))
it.navigate(R.id.libraryFragment)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
package org.kiwix.kiwixmobile

import android.content.Context
import androidx.appcompat.app.AppCompatDelegate
import androidx.core.content.edit
import androidx.core.os.LocaleListCompat
import androidx.lifecycle.Lifecycle
import androidx.preference.PreferenceManager
import androidx.room.Room
Expand Down Expand Up @@ -50,7 +52,6 @@ import org.kiwix.kiwixmobile.core.data.KiwixRoomDatabase
import org.kiwix.kiwixmobile.core.data.remote.ObjectBoxToRoomMigrator
import org.kiwix.kiwixmobile.core.di.modules.DatabaseModule
import org.kiwix.kiwixmobile.core.page.notes.adapter.NoteListItem
import org.kiwix.kiwixmobile.core.utils.LanguageUtils
import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil
import org.kiwix.kiwixmobile.main.KiwixMainActivity
import org.kiwix.kiwixmobile.testutils.TestUtils
Expand Down Expand Up @@ -85,11 +86,7 @@ class ObjectBoxToRoomMigratorTest {
ActivityScenario.launch(KiwixMainActivity::class.java).apply {
moveToState(Lifecycle.State.RESUMED)
onActivity {
LanguageUtils.handleLocaleChange(
it,
"en",
SharedPreferenceUtil(context)
)
AppCompatDelegate.setApplicationLocales(LocaleListCompat.forLanguageTags("en"))
it.navigate(R.id.libraryFragment)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ import org.hamcrest.CoreMatchers.containsString
import org.hamcrest.Matcher
import org.junit.Assert
import org.kiwix.kiwixmobile.BaseRobot
import org.kiwix.kiwixmobile.Findable.StringId.TextId
import org.kiwix.kiwixmobile.Findable.ViewId
import org.kiwix.kiwixmobile.R
import org.kiwix.kiwixmobile.core.R.string
Expand All @@ -68,7 +67,8 @@ class DownloadRobot : BaseRobot() {

fun waitForDataToLoad(retryCountForDataToLoad: Int = 10) {
try {
isVisible(TextId(string.your_languages))
pauseForBetterTestPerformance()
onView(withText(string.your_languages)).check(matches(isDisplayed()))
} catch (e: RuntimeException) {
if (retryCountForDataToLoad > 0) {
// refresh the data if there is "Swipe Down for Library" visible on the screen.
Expand All @@ -85,11 +85,11 @@ class DownloadRobot : BaseRobot() {
try {
onView(withText(string.swipe_down_for_library)).check(matches(isDisplayed()))
refreshOnlineList()
} catch (e: RuntimeException) {
} catch (e: Throwable) {
try {
// do nothing as currently downloading the online library.
onView(withId(R.id.onlineLibraryProgressLayout)).check(matches(isDisplayed()))
} catch (e: RuntimeException) {
} catch (e: Throwable) {
// if not visible try to get the online library.
refreshOnlineList()
}
Expand Down Expand Up @@ -189,7 +189,7 @@ class DownloadRobot : BaseRobot() {

private fun assertStopDownloadDialogDisplayed() {
pauseForBetterTestPerformance()
isVisible(TextId(string.confirm_stop_download_title))
testFlakyView({ onView(withText(string.confirm_stop_download_title)) })
}

private fun clickOnYesButton() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@
*/
package org.kiwix.kiwixmobile.download

import android.os.Build
import android.util.Log
import androidx.appcompat.app.AppCompatDelegate
import androidx.core.content.edit
import androidx.core.os.LocaleListCompat
import androidx.lifecycle.Lifecycle
import androidx.navigation.fragment.NavHostFragment
import androidx.preference.PreferenceManager
Expand Down Expand Up @@ -46,7 +49,6 @@ import org.junit.Test
import org.junit.runner.RunWith
import org.kiwix.kiwixmobile.BaseActivityTest
import org.kiwix.kiwixmobile.R
import org.kiwix.kiwixmobile.core.utils.LanguageUtils.Companion.handleLocaleChange
import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil
import org.kiwix.kiwixmobile.main.KiwixMainActivity
import org.kiwix.kiwixmobile.main.topLevel
Expand Down Expand Up @@ -108,11 +110,7 @@ class DownloadTest : BaseActivityTest() {
activityScenario = ActivityScenario.launch(KiwixMainActivity::class.java).apply {
moveToState(Lifecycle.State.RESUMED)
onActivity {
handleLocaleChange(
it,
"en",
SharedPreferenceUtil(context)
)
AppCompatDelegate.setApplicationLocales(LocaleListCompat.forLanguageTags("en"))
}
}
}
Expand Down Expand Up @@ -232,7 +230,11 @@ class DownloadTest : BaseActivityTest() {
"Couldn't find downloaded file ' Off the Grid ' Original Exception: ${e.message}"
)
}
LeakAssertions.assertNoLeaks()
if (Build.VERSION.SDK_INT != Build.VERSION_CODES.TIRAMISU) {
// Temporarily disabling leak checks on Android 13,
// as it is incorrectly detecting leaks in Android's internal classes.
LeakAssertions.assertNoLeaks()
}
}

@After
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
package org.kiwix.kiwixmobile.help

import android.os.Build
import androidx.appcompat.app.AppCompatDelegate
import androidx.core.os.LocaleListCompat
import androidx.lifecycle.Lifecycle
import androidx.test.core.app.ActivityScenario
import androidx.test.espresso.IdlingRegistry
Expand All @@ -31,7 +33,6 @@ import org.junit.Rule
import org.junit.Test
import org.kiwix.kiwixmobile.BaseActivityTest
import org.kiwix.kiwixmobile.R
import org.kiwix.kiwixmobile.core.utils.LanguageUtils.Companion.handleLocaleChange
import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil
import org.kiwix.kiwixmobile.main.KiwixMainActivity
import org.kiwix.kiwixmobile.testutils.RetryRule
Expand All @@ -54,13 +55,7 @@ class HelpFragmentTest : BaseActivityTest() {
activityScenario = ActivityScenario.launch(KiwixMainActivity::class.java).apply {
moveToState(Lifecycle.State.RESUMED)
onActivity {
handleLocaleChange(
it,
"en",
SharedPreferenceUtil(context).apply {
lastDonationPopupShownInMilliSeconds = System.currentTimeMillis()
}
)
AppCompatDelegate.setApplicationLocales(LocaleListCompat.forLanguageTags("en"))
}
}
}
Expand Down Expand Up @@ -91,7 +86,11 @@ class HelpFragmentTest : BaseActivityTest() {
clickOnHowToUpdateContent()
assertWhyCopyMoveFilesToAppPublicDirectoryIsNotVisible()
}
LeakAssertions.assertNoLeaks()
if (Build.VERSION.SDK_INT != Build.VERSION_CODES.TIRAMISU) {
// Temporarily disabling leak checks on Android 13,
// as it is incorrectly detecting leaks in Android's internal classes.
LeakAssertions.assertNoLeaks()
}
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@

package org.kiwix.kiwixmobile.initial.download

import androidx.appcompat.app.AppCompatDelegate
import androidx.core.content.edit
import androidx.core.os.LocaleListCompat
import androidx.lifecycle.Lifecycle
import androidx.preference.PreferenceManager
import androidx.test.core.app.ActivityScenario
Expand All @@ -41,7 +43,6 @@ import org.junit.Test
import org.junit.runner.RunWith
import org.kiwix.kiwixmobile.BaseActivityTest
import org.kiwix.kiwixmobile.R
import org.kiwix.kiwixmobile.core.utils.LanguageUtils.Companion.handleLocaleChange
import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil
import org.kiwix.kiwixmobile.main.KiwixMainActivity
import org.kiwix.kiwixmobile.nav.destination.library.library
Expand Down Expand Up @@ -93,11 +94,7 @@ class InitialDownloadTest : BaseActivityTest() {
activityScenario = ActivityScenario.launch(KiwixMainActivity::class.java).apply {
moveToState(Lifecycle.State.RESUMED)
onActivity {
handleLocaleChange(
it,
"en",
SharedPreferenceUtil(context)
)
AppCompatDelegate.setApplicationLocales(LocaleListCompat.forLanguageTags("en"))
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
*/
package org.kiwix.kiwixmobile.intro

import androidx.appcompat.app.AppCompatDelegate
import androidx.core.content.edit
import androidx.core.os.LocaleListCompat
import androidx.lifecycle.Lifecycle
import androidx.preference.PreferenceManager
import androidx.test.core.app.ActivityScenario
Expand All @@ -30,7 +32,6 @@ import org.junit.Rule
import org.junit.Test
import org.kiwix.kiwixmobile.BaseActivityTest
import org.kiwix.kiwixmobile.R
import org.kiwix.kiwixmobile.core.utils.LanguageUtils.Companion.handleLocaleChange
import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil
import org.kiwix.kiwixmobile.main.KiwixMainActivity
import org.kiwix.kiwixmobile.testutils.RetryRule
Expand Down Expand Up @@ -75,11 +76,7 @@ class IntroFragmentTest : BaseActivityTest() {
activityScenario = ActivityScenario.launch(KiwixMainActivity::class.java).apply {
moveToState(Lifecycle.State.RESUMED)
onActivity {
handleLocaleChange(
it,
"en",
SharedPreferenceUtil(context)
)
AppCompatDelegate.setApplicationLocales(LocaleListCompat.forLanguageTags("en"))
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ package org.kiwix.kiwixmobile.language

import android.Manifest
import android.app.Instrumentation
import androidx.appcompat.app.AppCompatDelegate
import androidx.core.content.edit
import androidx.core.os.LocaleListCompat
import androidx.lifecycle.Lifecycle
import androidx.preference.PreferenceManager
import androidx.test.core.app.ActivityScenario
Expand All @@ -34,7 +36,6 @@ import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.kiwix.kiwixmobile.core.utils.LanguageUtils.Companion.handleLocaleChange
import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil
import org.kiwix.kiwixmobile.main.KiwixMainActivity
import org.kiwix.kiwixmobile.testutils.RetryRule
Expand Down Expand Up @@ -89,11 +90,7 @@ class LanguageFragmentTest {
ActivityScenario.launch(KiwixMainActivity::class.java).apply {
moveToState(Lifecycle.State.RESUMED)
onActivity {
handleLocaleChange(
it,
"en",
SharedPreferenceUtil(instrumentation.targetContext.applicationContext)
)
AppCompatDelegate.setApplicationLocales(LocaleListCompat.forLanguageTags("en"))
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ import android.Manifest
import android.app.Instrumentation
import android.content.Context
import android.os.Build
import androidx.appcompat.app.AppCompatDelegate
import androidx.core.content.edit
import androidx.core.os.LocaleListCompat
import androidx.lifecycle.Lifecycle
import androidx.preference.PreferenceManager
import androidx.test.core.app.ActivityScenario
Expand All @@ -42,7 +44,6 @@ import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.kiwix.kiwixmobile.R
import org.kiwix.kiwixmobile.core.utils.LanguageUtils.Companion.handleLocaleChange
import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil
import org.kiwix.kiwixmobile.main.KiwixMainActivity
import org.kiwix.kiwixmobile.nav.destination.library.library
Expand Down Expand Up @@ -118,11 +119,7 @@ class LocalFileTransferTest {
activityScenario = ActivityScenario.launch(KiwixMainActivity::class.java).apply {
moveToState(Lifecycle.State.RESUMED)
onActivity {
handleLocaleChange(
it,
"en",
SharedPreferenceUtil(context)
)
AppCompatDelegate.setApplicationLocales(LocaleListCompat.forLanguageTags("en"))
}
}
StandardActions.closeDrawer()
Expand Down Expand Up @@ -151,11 +148,7 @@ class LocalFileTransferTest {
activityScenario = ActivityScenario.launch(KiwixMainActivity::class.java).apply {
moveToState(Lifecycle.State.RESUMED)
onActivity {
handleLocaleChange(
it,
"en",
SharedPreferenceUtil(context)
)
AppCompatDelegate.setApplicationLocales(LocaleListCompat.forLanguageTags("en"))
it.navigate(R.id.libraryFragment)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ package org.kiwix.kiwixmobile.localLibrary

import android.net.Uri
import android.os.Build
import androidx.appcompat.app.AppCompatDelegate
import androidx.core.content.edit
import androidx.core.os.LocaleListCompat
import androidx.documentfile.provider.DocumentFile
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.lifecycleScope
Expand All @@ -43,7 +45,6 @@ import org.kiwix.kiwixmobile.R
import org.kiwix.kiwixmobile.core.extensions.deleteFile
import org.kiwix.kiwixmobile.core.extensions.isFileExist
import org.kiwix.kiwixmobile.core.settings.StorageCalculator
import org.kiwix.kiwixmobile.core.utils.LanguageUtils
import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil
import org.kiwix.kiwixmobile.core.utils.dialog.AlertDialogShower
import org.kiwix.kiwixmobile.main.KiwixMainActivity
Expand Down Expand Up @@ -90,11 +91,7 @@ class CopyMoveFileHandlerTest : BaseActivityTest() {
moveToState(Lifecycle.State.RESUMED)
sharedPreferenceUtil = SharedPreferenceUtil(context)
onActivity {
LanguageUtils.handleLocaleChange(
it,
"en",
sharedPreferenceUtil
)
AppCompatDelegate.setApplicationLocales(LocaleListCompat.forLanguageTags("en"))
parentFile = File(sharedPreferenceUtil.prefStorage)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ import android.net.Uri
import android.os.Build
import android.provider.MediaStore
import android.util.Log
import androidx.appcompat.app.AppCompatDelegate
import androidx.core.content.edit
import androidx.core.os.LocaleListCompat
import androidx.lifecycle.Lifecycle
import androidx.preference.PreferenceManager
import androidx.test.core.app.ActivityScenario
Expand All @@ -46,7 +48,6 @@ import org.junit.jupiter.api.fail
import org.junit.runner.RunWith
import org.kiwix.kiwixmobile.BaseActivityTest
import org.kiwix.kiwixmobile.R
import org.kiwix.kiwixmobile.core.utils.LanguageUtils
import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil
import org.kiwix.kiwixmobile.main.KiwixMainActivity
import org.kiwix.kiwixmobile.testutils.RetryRule
Expand Down Expand Up @@ -91,11 +92,7 @@ class OpeningFilesFromStorageTest : BaseActivityTest() {
moveToState(Lifecycle.State.RESUMED)
sharedPreferenceUtil = SharedPreferenceUtil(context)
onActivity {
LanguageUtils.handleLocaleChange(
it,
"en",
sharedPreferenceUtil
)
AppCompatDelegate.setApplicationLocales(LocaleListCompat.forLanguageTags("en"))
}
}
}
Expand Down
Loading
Loading