Skip to content

Commit

Permalink
apply locale override in downloader service
Browse files Browse the repository at this point in the history
  • Loading branch information
shadow578 committed Jul 30, 2021
1 parent db60c07 commit 5688dee
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
*
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -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<Uri> downloadDirectorySelectLauncher;

@Override
protected void attachBaseContext(Context newBase) {
super.attachBaseContext(LocaleUtil.wrapContext(newBase));
}

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -7,28 +7,22 @@
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}
*
* @param originalContext the original context to use as a base
* @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();

Expand Down

0 comments on commit 5688dee

Please sign in to comment.