diff --git a/app/src/main/java/io/github/shadow578/music_dl/downloader/DownloaderService.java b/app/src/main/java/io/github/shadow578/music_dl/downloader/DownloaderService.java index 1d0ad16..569340e 100644 --- a/app/src/main/java/io/github/shadow578/music_dl/downloader/DownloaderService.java +++ b/app/src/main/java/io/github/shadow578/music_dl/downloader/DownloaderService.java @@ -1,6 +1,7 @@ package io.github.shadow578.music_dl.downloader; import android.app.Notification; +import android.content.Context; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.util.Log; @@ -42,6 +43,7 @@ import io.github.shadow578.music_dl.db.model.TrackStatus; import io.github.shadow578.music_dl.downloader.wrapper.MP3agicWrapper; import io.github.shadow578.music_dl.downloader.wrapper.YoutubeDLWrapper; +import io.github.shadow578.music_dl.util.LocaleUtil; import io.github.shadow578.music_dl.util.Util; import io.github.shadow578.music_dl.util.notifications.NotificationChannels; import io.github.shadow578.music_dl.util.preferences.Prefs; @@ -152,6 +154,11 @@ public void onDestroy() { super.onDestroy(); } + @Override + protected void attachBaseContext(Context newBase) { + super.attachBaseContext(LocaleUtil.wrapContext(newBase)); + } + /** * check if the downloads directory is set and accessible * diff --git a/app/src/main/java/io/github/shadow578/music_dl/ui/base/BaseActivity.java b/app/src/main/java/io/github/shadow578/music_dl/ui/base/BaseActivity.java index b290406..19ccd59 100644 --- a/app/src/main/java/io/github/shadow578/music_dl/ui/base/BaseActivity.java +++ b/app/src/main/java/io/github/shadow578/music_dl/ui/base/BaseActivity.java @@ -1,5 +1,6 @@ package io.github.shadow578.music_dl.ui.base; +import android.content.Context; import android.content.Intent; import android.net.Uri; import android.os.Bundle; @@ -9,12 +10,14 @@ import androidx.activity.result.ActivityResultLauncher; import androidx.activity.result.contract.ActivityResultContracts; import androidx.annotation.Nullable; +import androidx.appcompat.app.AppCompatActivity; import androidx.documentfile.provider.DocumentFile; import java.util.Optional; import io.github.shadow578.music_dl.R; import io.github.shadow578.music_dl.downloader.DownloaderService; +import io.github.shadow578.music_dl.util.LocaleUtil; import io.github.shadow578.music_dl.util.preferences.Prefs; import io.github.shadow578.music_dl.util.storage.StorageHelper; import io.github.shadow578.music_dl.util.storage.StorageKey; @@ -23,13 +26,18 @@ * topmost base activity. this is to be extended when creating a new activity. * handles app- specific stuff */ -public class BaseActivity extends LocaleOverrideActivity { +public class BaseActivity extends AppCompatActivity { /** * result launcher for download directory select */ private ActivityResultLauncher downloadDirectorySelectLauncher; + @Override + protected void attachBaseContext(Context newBase) { + super.attachBaseContext(LocaleUtil.wrapContext(newBase)); + } + @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); diff --git a/app/src/main/java/io/github/shadow578/music_dl/ui/base/LocaleOverrideActivity.java b/app/src/main/java/io/github/shadow578/music_dl/util/LocaleUtil.java similarity index 75% rename from app/src/main/java/io/github/shadow578/music_dl/ui/base/LocaleOverrideActivity.java rename to app/src/main/java/io/github/shadow578/music_dl/util/LocaleUtil.java index 579cca4..e192b99 100644 --- a/app/src/main/java/io/github/shadow578/music_dl/ui/base/LocaleOverrideActivity.java +++ b/app/src/main/java/io/github/shadow578/music_dl/util/LocaleUtil.java @@ -1,4 +1,4 @@ -package io.github.shadow578.music_dl.ui.base; +package io.github.shadow578.music_dl.util; import android.content.Context; import android.content.ContextWrapper; @@ -7,20 +7,14 @@ import android.os.LocaleList; import androidx.annotation.NonNull; -import androidx.appcompat.app.AppCompatActivity; import io.github.shadow578.music_dl.LocaleOverride; import io.github.shadow578.music_dl.util.preferences.Prefs; /** - * a activity that overrides the locale using {@link Prefs#LocaleOverride} + * locale utility class */ -public class LocaleOverrideActivity extends AppCompatActivity { - @Override - protected void attachBaseContext(Context newBase) { - super.attachBaseContext(wrapContext(newBase)); - } - +public class LocaleUtil { /** * wrap the config to use the target locale from {@link Prefs#LocaleOverride} * @@ -28,7 +22,7 @@ protected void attachBaseContext(Context newBase) { * @return the (maybe) wrapped context with the target locale */ @NonNull - private Context wrapContext(@NonNull Context originalContext) { + public static Context wrapContext(@NonNull Context originalContext) { // get preference setting final LocaleOverride localeOverride = Prefs.LocaleOverride.get();