From e7eb3d87cb04624a6799f048d4e5b410c4177d27 Mon Sep 17 00:00:00 2001 From: Raymond Lai Date: Tue, 20 Feb 2024 00:11:53 +0800 Subject: [PATCH] Fix UiPrefsFragmentTest failure by removing redundant languages at preference At ContextLocaleExt.kt, remove conflicting locales API 24 or above --- .../java/com/amaze/filemanager/utils/ContextLocaleExt.kt | 8 ++++++++ .../fragments/preferencefragments/UiPrefsFragmentTest.kt | 7 ++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/amaze/filemanager/utils/ContextLocaleExt.kt b/app/src/main/java/com/amaze/filemanager/utils/ContextLocaleExt.kt index 5ef6bdf387..e674f6ed43 100644 --- a/app/src/main/java/com/amaze/filemanager/utils/ContextLocaleExt.kt +++ b/app/src/main/java/com/amaze/filemanager/utils/ContextLocaleExt.kt @@ -21,6 +21,8 @@ package com.amaze.filemanager.utils import android.content.Context +import android.os.Build +import android.os.Build.VERSION_CODES.N import androidx.appcompat.app.AppCompatDelegate import androidx.core.os.LocaleListCompat import com.amaze.filemanager.R @@ -50,6 +52,12 @@ fun Context.getLocaleListFromXml(): LocaleListCompat { e.printStackTrace() } + // Remove locale tags that would produce same locale on Android N or above + if (Build.VERSION.SDK_INT >= N) { + tagsList.remove("id") + tagsList.remove("he") + } + return LocaleListCompat.forLanguageTags(tagsList.joinToString(",")) } diff --git a/app/src/test/java/com/amaze/filemanager/ui/fragments/preferencefragments/UiPrefsFragmentTest.kt b/app/src/test/java/com/amaze/filemanager/ui/fragments/preferencefragments/UiPrefsFragmentTest.kt index d974fb57fa..d4c6a42981 100644 --- a/app/src/test/java/com/amaze/filemanager/ui/fragments/preferencefragments/UiPrefsFragmentTest.kt +++ b/app/src/test/java/com/amaze/filemanager/ui/fragments/preferencefragments/UiPrefsFragmentTest.kt @@ -51,7 +51,12 @@ import kotlin.random.Random * Tests for [UiPrefsFragment]. */ @Config( - sdk = [Build.VERSION_CODES.KITKAT, Build.VERSION_CODES.P, Build.VERSION_CODES.R], + sdk = [ + Build.VERSION_CODES.KITKAT, + Build.VERSION_CODES.N, + Build.VERSION_CODES.P, + Build.VERSION_CODES.R + ], shadows = [ ShadowMultiDex::class, ShadowStorageManager::class,