Converted PreferencUtil to Kotlin class

This commit is contained in:
Hemanth S 2020-05-23 14:57:55 +05:30
parent df225e179f
commit e9bd24872f
108 changed files with 1855 additions and 2099 deletions

View file

@ -67,8 +67,6 @@ object AppRater {
private fun showRateDialog(context: Context, editor: SharedPreferences.Editor) {
MaterialDialog(context)
.show {
cornerRadius(PreferenceUtil.getInstance(context).dialogCorner)
title(text = "Rate this App")
message(text = "If you enjoy using Retro Music, please take a moment to rate it. Thanks for your support!")
positiveButton(R.string.app_name) {

View file

@ -1,790 +0,0 @@
/*
* Copyright (c) 2019 Hemanth Savarala.
*
* Licensed under the GNU General Public License v3
*
* This is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by
* the Free Software Foundation either version 3 of the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*/
package code.name.monkey.retromusic.util;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import android.content.res.TypedArray;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.Uri;
import android.preference.PreferenceManager;
import androidx.annotation.LayoutRes;
import androidx.annotation.NonNull;
import androidx.annotation.StyleRes;
import androidx.viewpager.widget.ViewPager;
import com.google.android.material.bottomnavigation.LabelVisibilityMode;
import com.google.gson.Gson;
import com.google.gson.JsonSyntaxException;
import com.google.gson.reflect.TypeToken;
import java.io.File;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import code.name.monkey.retromusic.R;
import code.name.monkey.retromusic.fragments.AlbumCoverStyle;
import code.name.monkey.retromusic.fragments.NowPlayingScreen;
import code.name.monkey.retromusic.fragments.mainactivity.FoldersFragment;
import code.name.monkey.retromusic.helper.SortOrder.AlbumSongSortOrder;
import code.name.monkey.retromusic.model.CategoryInfo;
import code.name.monkey.retromusic.model.CategoryInfo.Category;
import code.name.monkey.retromusic.transform.CascadingPageTransformer;
import code.name.monkey.retromusic.transform.DepthTransformation;
import code.name.monkey.retromusic.transform.HingeTransformation;
import code.name.monkey.retromusic.transform.HorizontalFlipTransformation;
import code.name.monkey.retromusic.transform.NormalPageTransformer;
import code.name.monkey.retromusic.transform.VerticalFlipTransformation;
import code.name.monkey.retromusic.transform.VerticalStackTransformer;
import code.name.monkey.retromusic.util.theme.ThemeMode;
import static code.name.monkey.retromusic.helper.SortOrder.AlbumSortOrder;
import static code.name.monkey.retromusic.helper.SortOrder.ArtistAlbumSortOrder;
import static code.name.monkey.retromusic.helper.SortOrder.ArtistSongSortOrder;
import static code.name.monkey.retromusic.helper.SortOrder.ArtistSortOrder;
import static code.name.monkey.retromusic.helper.SortOrder.GenreSortOrder;
import static code.name.monkey.retromusic.helper.SortOrder.SongSortOrder;
public final class PreferenceUtil {
public static final String LIBRARY_CATEGORIES = "library_categories";
public static final String EXTRA_SONG_INFO = "extra_song_info";
public static final String DESATURATED_COLOR = "desaturated_color";
public static final String BLACK_THEME = "black_theme";
public static final String KEEP_SCREEN_ON = "keep_screen_on";
public static final String TOGGLE_HOME_BANNER = "toggle_home_banner";
public static final String NOW_PLAYING_SCREEN_ID = "now_playing_screen_id";
public static final String CAROUSEL_EFFECT = "carousel_effect";
public static final String COLORED_NOTIFICATION = "colored_notification";
public static final String CLASSIC_NOTIFICATION = "classic_notification";
public static final String GAPLESS_PLAYBACK = "gapless_playback";
public static final String ALBUM_ART_ON_LOCKSCREEN = "album_art_on_lockscreen";
public static final String BLURRED_ALBUM_ART = "blurred_album_art";
public static final String NEW_BLUR_AMOUNT = "new_blur_amount";
public static final String TOGGLE_HEADSET = "toggle_headset";
public static final String GENERAL_THEME = "general_theme";
public static final String CIRCULAR_ALBUM_ART = "circular_album_art";
public static final String USER_NAME = "user_name";
public static final String TOGGLE_FULL_SCREEN = "toggle_full_screen";
public static final String TOGGLE_VOLUME = "toggle_volume";
public static final String ROUND_CORNERS = "corner_window";
public static final String TOGGLE_GENRE = "toggle_genre";
public static final String PROFILE_IMAGE_PATH = "profile_image_path";
public static final String BANNER_IMAGE_PATH = "banner_image_path";
public static final String ADAPTIVE_COLOR_APP = "adaptive_color_app";
public static final String TOGGLE_SEPARATE_LINE = "toggle_separate_line";
public static final String HOME_ARTIST_GRID_STYLE = "home_artist_grid_style";
public static final String TOGGLE_ADD_CONTROLS = "toggle_add_controls";
public static final String ALBUM_COVER_STYLE = "album_cover_style_id";
public static final String ALBUM_COVER_TRANSFORM = "album_cover_transform";
public static final String TAB_TEXT_MODE = "tab_text_mode";
public static final String LANGUAGE_NAME = "language_name";
private static final String DIALOG_CORNER = "dialog_corner";
private static final String SLEEP_TIMER_FINISH_SONG = "sleep_timer_finish_song";
private static final String ALBUM_GRID_STYLE = "album_grid_style_home";
private static final String ARTIST_GRID_STYLE = "artist_grid_style_home";
private static final String SAF_SDCARD_URI = "saf_sdcard_uri";
private static final String SONG_SORT_ORDER = "song_sort_order";
private static final String SONG_GRID_SIZE = "song_grid_size";
private static final String GENRE_SORT_ORDER = "genre_sort_order";
private static final String LAST_PAGE = "last_start_page";
private static final String BLUETOOTH_PLAYBACK = "bluetooth_playback";
private static final String INITIALIZED_BLACKLIST = "initialized_blacklist";
private static final String ARTIST_SORT_ORDER = "artist_sort_order";
private static final String ARTIST_ALBUM_SORT_ORDER = "artist_album_sort_order";
private static final String ALBUM_SORT_ORDER = "album_sort_order";
private static final String ALBUM_SONG_SORT_ORDER = "album_song_sort_order";
private static final String ARTIST_SONG_SORT_ORDER = "artist_song_sort_order";
private static final String ALBUM_GRID_SIZE = "album_grid_size";
private static final String ALBUM_GRID_SIZE_LAND = "album_grid_size_land";
private static final String SONG_GRID_SIZE_LAND = "song_grid_size_land";
private static final String ARTIST_GRID_SIZE = "artist_grid_size";
private static final String ARTIST_GRID_SIZE_LAND = "artist_grid_size_land";
private static final String COLORED_APP_SHORTCUTS = "colored_app_shortcuts";
private static final String AUDIO_DUCKING = "audio_ducking";
private static final String LAST_ADDED_CUTOFF = "last_added_interval";
private static final String LAST_SLEEP_TIMER_VALUE = "last_sleep_timer_value";
private static final String NEXT_SLEEP_TIMER_ELAPSED_REALTIME = "next_sleep_timer_elapsed_real_time";
private static final String IGNORE_MEDIA_STORE_ARTWORK = "ignore_media_store_artwork";
private static final String LAST_CHANGELOG_VERSION = "last_changelog_version";
private static final String AUTO_DOWNLOAD_IMAGES_POLICY = "auto_download_images_policy";
private static final String START_DIRECTORY = "start_directory";
private static final String LOCK_SCREEN = "lock_screen";
private static final String ALBUM_DETAIL_SONG_SORT_ORDER = "album_detail_song_sort_order";
private static final String LYRICS_OPTIONS = "lyrics_tab_position";
private static final String CHOOSE_EQUALIZER = "choose_equalizer";
private static final String TOGGLE_SHUFFLE = "toggle_shuffle";
private static final String SONG_GRID_STYLE = "song_grid_style";
private static final String PAUSE_ON_ZERO_VOLUME = "pause_on_zero_volume";
private static final String FILTER_SONG = "filter_song";
private static final String EXPAND_NOW_PLAYING_PANEL = "expand_now_playing_panel";
private static PreferenceUtil sInstance;
private final SharedPreferences mPreferences;
private PreferenceUtil(@NonNull final Context context) {
mPreferences = PreferenceManager.getDefaultSharedPreferences(context);
}
@NonNull
public static PreferenceUtil getInstance(Context context) {
if (sInstance == null) {
sInstance = new PreferenceUtil(context);
}
return sInstance;
}
@StyleRes
public static int getThemeResFromPrefValue(@NonNull String themePrefValue) {
switch (themePrefValue) {
case "light":
return R.style.Theme_RetroMusic_Light;
case "dark":
default:
return R.style.Theme_RetroMusic;
}
}
public static boolean isAllowedToDownloadMetadata(@NonNull Context context) {
switch (getInstance(context).autoDownloadImagesPolicy()) {
case "always":
return true;
case "only_wifi":
final ConnectivityManager connectivityManager = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo netInfo = null;
if (connectivityManager != null) {
netInfo = connectivityManager.getActiveNetworkInfo();
}
return netInfo != null && netInfo.getType() == ConnectivityManager.TYPE_WIFI && netInfo
.isConnectedOrConnecting();
case "never":
default:
return false;
}
}
public final boolean albumArtOnLockscreen() {
return mPreferences.getBoolean(ALBUM_ART_ON_LOCKSCREEN, true);
}
public final boolean audioDucking() {
return mPreferences.getBoolean(AUDIO_DUCKING, true);
}
public final String autoDownloadImagesPolicy() {
return mPreferences.getString(AUTO_DOWNLOAD_IMAGES_POLICY, "only_wifi");
}
public boolean bluetoothSpeaker() {
return mPreferences.getBoolean(BLUETOOTH_PLAYBACK, false);
}
public final boolean blurredAlbumArt() {
return mPreferences.getBoolean(BLURRED_ALBUM_ART, false);
}
public boolean carouselEffect() {
return mPreferences.getBoolean(CAROUSEL_EFFECT, false);
}
public final boolean classicNotification() {
return mPreferences.getBoolean(CLASSIC_NOTIFICATION, false);
}
public final boolean coloredAppShortcuts() {
return mPreferences.getBoolean(COLORED_APP_SHORTCUTS, true);
}
public final boolean coloredNotification() {
return mPreferences.getBoolean(COLORED_NOTIFICATION, true);
}
public boolean desaturatedColor() {
return mPreferences.getBoolean(DESATURATED_COLOR, false);
}
public final boolean gaplessPlayback() {
return mPreferences.getBoolean(GAPLESS_PLAYBACK, false);
}
public boolean getAdaptiveColor() {
return mPreferences.getBoolean(ADAPTIVE_COLOR_APP, false);
}
public final AlbumCoverStyle getAlbumCoverStyle() {
int id = mPreferences.getInt(ALBUM_COVER_STYLE, 0);
for (AlbumCoverStyle albumCoverStyle : AlbumCoverStyle.values()) {
if (albumCoverStyle.getId() == id) {
return albumCoverStyle;
}
}
return AlbumCoverStyle.CARD;
}
public void setAlbumCoverStyle(AlbumCoverStyle albumCoverStyle) {
final SharedPreferences.Editor editor = mPreferences.edit();
editor.putInt(ALBUM_COVER_STYLE, albumCoverStyle.getId());
editor.apply();
}
public ViewPager.PageTransformer getAlbumCoverTransform() {
int style = Integer.parseInt(Objects.requireNonNull(mPreferences.getString(ALBUM_COVER_TRANSFORM, "0")));
switch (style) {
default:
case 0:
return new NormalPageTransformer();
case 1:
return new CascadingPageTransformer();
case 2:
return new DepthTransformation();
case 3:
return new HorizontalFlipTransformation();
case 4:
return new VerticalFlipTransformation();
case 5:
return new HingeTransformation();
case 6:
return new VerticalStackTransformer();
}
}
public String getAlbumDetailSongSortOrder() {
return mPreferences
.getString(ALBUM_DETAIL_SONG_SORT_ORDER, AlbumSongSortOrder.SONG_TRACK_LIST);
}
public void setAlbumDetailSongSortOrder(String sortOrder) {
Editor edit = this.mPreferences.edit();
edit.putString(ALBUM_DETAIL_SONG_SORT_ORDER, sortOrder);
edit.apply();
}
public final int getAlbumGridSize(@NonNull Context context) {
return mPreferences
.getInt(ALBUM_GRID_SIZE, context.getResources().getInteger(R.integer.default_grid_columns));
}
public final int getAlbumGridSizeLand(@NonNull Context context) {
return mPreferences
.getInt(ALBUM_GRID_SIZE_LAND, context.getResources().getInteger(R.integer.default_grid_columns_land));
}
@LayoutRes
public int getAlbumGridStyle() {
return mPreferences.getInt(ALBUM_GRID_STYLE, R.layout.item_grid);
}
public void setAlbumGridStyle(int layoutRes) {
mPreferences.edit()
.putInt(ALBUM_GRID_STYLE, layoutRes)
.apply();
}
public final String getAlbumSongSortOrder() {
return mPreferences
.getString(ALBUM_SONG_SORT_ORDER, AlbumSongSortOrder.SONG_TRACK_LIST);
}
public final String getArtistSongSortOrder() {
return mPreferences
.getString(ARTIST_SONG_SORT_ORDER, ArtistSongSortOrder.SONG_A_Z);
}
public final String getAlbumSortOrder() {
return mPreferences.getString(ALBUM_SORT_ORDER, AlbumSortOrder.ALBUM_A_Z);
}
public void setAlbumSortOrder(final String sortOrder) {
final SharedPreferences.Editor editor = mPreferences.edit();
editor.putString(ALBUM_SORT_ORDER, sortOrder);
editor.apply();
}
public final String getArtistAlbumSortOrder() {
return mPreferences.getString(ARTIST_ALBUM_SORT_ORDER, ArtistAlbumSortOrder.ALBUM_A_Z);
}
public final int getArtistGridSize(Context context) {
return mPreferences.getInt(ARTIST_GRID_SIZE,
context.getResources().getInteger(R.integer.default_list_artist_columns));
}
public final int getArtistGridSizeLand(Context context) {
return mPreferences.getInt(ARTIST_GRID_SIZE_LAND,
context.getResources().getInteger(R.integer.default_list_artist_columns_land));
}
@LayoutRes
public int getArtistGridStyle() {
return mPreferences.getInt(ARTIST_GRID_STYLE, R.layout.item_grid_circle);
}
public void setArtistGridStyle(@LayoutRes int artistGridStyle) {
mPreferences.edit().putInt(ARTIST_GRID_STYLE, artistGridStyle).apply();
}
public final String getArtistSortOrder() {
return mPreferences.getString(ARTIST_SORT_ORDER, ArtistSortOrder.ARTIST_A_Z);
}
public void setArtistSortOrder(final String sortOrder) {
final SharedPreferences.Editor editor = mPreferences.edit();
editor.putString(ARTIST_SORT_ORDER, sortOrder);
editor.apply();
}
public String getBannerImage() {
return mPreferences.getString(BANNER_IMAGE_PATH, "");
}
public String getBaseTheme() {
return mPreferences.getString(GENERAL_THEME, "auto");
}
@NonNull
public List<CategoryInfo> getDefaultLibraryCategoryInfos() {
List<CategoryInfo> defaultCategoryInfos = new ArrayList<>(8);
defaultCategoryInfos.add(new CategoryInfo(Category.HOME, true));
defaultCategoryInfos.add(new CategoryInfo(Category.SONGS, true));
defaultCategoryInfos.add(new CategoryInfo(Category.ALBUMS, true));
defaultCategoryInfos.add(new CategoryInfo(Category.ARTISTS, true));
defaultCategoryInfos.add(new CategoryInfo(Category.PLAYLISTS, true));
defaultCategoryInfos.add(new CategoryInfo(Category.GENRES, false));
defaultCategoryInfos.add(new CategoryInfo(Category.QUEUE, false));
defaultCategoryInfos.add(new CategoryInfo(Category.FOLDER, false));
return defaultCategoryInfos;
}
public float getDialogCorner() {
return mPreferences.getInt(DIALOG_CORNER, 16);
}
public int getFilterLength() {
return mPreferences.getInt(FILTER_SONG, 20);
}
public boolean getFullScreenMode() {
return mPreferences.getBoolean(TOGGLE_FULL_SCREEN, false);
}
@NonNull
public ThemeMode getGeneralThemeValue(boolean isSystemDark) {
String themeMode = mPreferences.getString(GENERAL_THEME, "auto");
if (isBlackMode() && isSystemDark) {
return ThemeMode.BLACK;
} else if (themeMode != null) {
if (isBlackMode() && themeMode.equals("dark")) {
return ThemeMode.BLACK;
} else {
switch (themeMode) {
case "light":
return ThemeMode.LIGHT;
case "dark":
return ThemeMode.DARK;
case "auto":
default:
return ThemeMode.AUTO;
}
}
}
return ThemeMode.AUTO;
}
public final String getGenreSortOrder() {
return mPreferences.getString(GENRE_SORT_ORDER, GenreSortOrder.GENRE_A_Z);
}
public boolean getHeadsetPlugged() {
return mPreferences.getBoolean(TOGGLE_HEADSET, false);
}
@LayoutRes
public int getHomeGridStyle(@NonNull Context context) {
String position = mPreferences.getString(HOME_ARTIST_GRID_STYLE, "0");
int pos = 0;
if (position != null) {
pos = Integer.parseInt(position);
}
TypedArray typedArray = context.getResources().obtainTypedArray(R.array.pref_home_grid_style_layout);
int layoutRes = typedArray.getResourceId(pos, 0);
typedArray.recycle();
if (layoutRes == 0) {
return R.layout.item_artist;
}
return layoutRes;
}
public long getLastAddedCutoff() {
final CalendarUtil calendarUtil = new CalendarUtil();
long interval = calendarUtil.getElapsedMonth();
String cutOff = mPreferences.getString(LAST_ADDED_CUTOFF, "this_month");
if (cutOff != null) {
switch (cutOff) {
case "today":
interval = calendarUtil.getElapsedToday();
break;
case "this_week":
interval = calendarUtil.getElapsedWeek();
break;
case "past_three_months":
interval = calendarUtil.getElapsedMonths(3);
break;
case "this_year":
interval = calendarUtil.getElapsedYear();
break;
case "this_month":
default:
interval = calendarUtil.getElapsedMonth();
break;
}
}
return (System.currentTimeMillis() - interval) / 1000;
}
public final int getLastChangelogVersion() {
return mPreferences.getInt(LAST_CHANGELOG_VERSION, -1);
}
public final int getLastPage() {
return mPreferences.getInt(LAST_PAGE, R.id.action_song);
}
public void setLastPage(final int value) {
final SharedPreferences.Editor editor = mPreferences.edit();
editor.putInt(LAST_PAGE, value);
editor.apply();
}
public int getLastSleepTimerValue() {
return mPreferences.getInt(LAST_SLEEP_TIMER_VALUE, 30);
}
public void setLastSleepTimerValue(final int value) {
final SharedPreferences.Editor editor = mPreferences.edit();
editor.putInt(LAST_SLEEP_TIMER_VALUE, value);
editor.apply();
}
@NonNull
public List<CategoryInfo> getLibraryCategoryInfos() {
String data = mPreferences.getString(LIBRARY_CATEGORIES, null);
if (data != null) {
Gson gson = new Gson();
Type collectionType = new TypeToken<List<CategoryInfo>>() {
}.getType();
try {
return gson.fromJson(data, collectionType);
} catch (JsonSyntaxException e) {
e.printStackTrace();
}
}
return getDefaultLibraryCategoryInfos();
}
public void setLibraryCategoryInfos(List<CategoryInfo> categories) {
Gson gson = new Gson();
Type collectionType = new TypeToken<List<CategoryInfo>>() {
}.getType();
final SharedPreferences.Editor editor = mPreferences.edit();
editor.putString(LIBRARY_CATEGORIES, gson.toJson(categories, collectionType));
editor.apply();
}
public boolean getLockScreen() {
return mPreferences.getBoolean(LOCK_SCREEN, false);
}
public int getLyricsOptions() {
return mPreferences.getInt(LYRICS_OPTIONS, 1);
}
public void setLyricsOptions(int i) {
mPreferences.edit().putInt(LYRICS_OPTIONS, i).apply();
}
public long getNextSleepTimerElapsedRealTime() {
return mPreferences.getLong(NEXT_SLEEP_TIMER_ELAPSED_REALTIME, -1);
}
public final NowPlayingScreen getNowPlayingScreen() {
int id = mPreferences.getInt(NOW_PLAYING_SCREEN_ID, 0);
for (NowPlayingScreen nowPlayingScreen : NowPlayingScreen.values()) {
if (nowPlayingScreen.getId() == id) {
return nowPlayingScreen;
}
}
return NowPlayingScreen.Adaptive;
}
@SuppressLint("CommitPrefEdits")
public void setNowPlayingScreen(NowPlayingScreen nowPlayingScreen) {
final SharedPreferences.Editor editor = mPreferences.edit();
editor.putInt(NOW_PLAYING_SCREEN_ID, nowPlayingScreen.getId());
editor.apply();
}
public final String getSAFSDCardUri() {
return mPreferences.getString(SAF_SDCARD_URI, "");
}
public final void setSAFSDCardUri(Uri uri) {
mPreferences.edit().putString(SAF_SDCARD_URI, uri.toString()).apply();
}
public String getSelectedEqualizer() {
return mPreferences.getString(CHOOSE_EQUALIZER, "system");
}
public boolean getSleepTimerFinishMusic() {
return mPreferences.getBoolean(SLEEP_TIMER_FINISH_SONG, false);
}
public void setSleepTimerFinishMusic(final boolean value) {
final SharedPreferences.Editor editor = mPreferences.edit();
editor.putBoolean(SLEEP_TIMER_FINISH_SONG, value);
editor.apply();
}
public final int getSongGridSize(Context context) {
return mPreferences
.getInt(SONG_GRID_SIZE, context.getResources().getInteger(R.integer.default_list_columns));
}
public final int getSongGridSizeLand(Context context) {
return mPreferences.getInt(SONG_GRID_SIZE_LAND,
context.getResources().getInteger(R.integer.default_list_columns_land));
}
public int getSongGridStyle() {
return mPreferences.getInt(SONG_GRID_STYLE, R.layout.item_list);
}
public void setSongGridStyle(int viewAs) {
mPreferences.edit().putInt(SONG_GRID_STYLE, viewAs).apply();
}
public final String getSongSortOrder() {
return mPreferences.getString(SONG_SORT_ORDER, SongSortOrder.SONG_A_Z);
}
public void setSongSortOrder(final String sortOrder) {
final SharedPreferences.Editor editor = mPreferences.edit();
editor.putString(SONG_SORT_ORDER, sortOrder);
editor.apply();
}
public final File getStartDirectory() {
String folderPath = FoldersFragment.getDefaultStartDirectory().getPath();
String file = mPreferences.getString(START_DIRECTORY, folderPath);
if (file != null) {
return new File(file);
}
return new File(FoldersFragment.getDefaultStartDirectory().getPath());
}
public void setStartDirectory(File file) {
final SharedPreferences.Editor editor = mPreferences.edit();
editor.putString(START_DIRECTORY, FileUtil.safeGetCanonicalPath(file));
editor.apply();
}
@LabelVisibilityMode
public int getTabTitleMode() {
String textMode = mPreferences.getString(TAB_TEXT_MODE, "1");
int mode = 0;
if (textMode != null) {
mode = Integer.parseInt(textMode);
}
switch (mode) {
default:
case 1:
return LabelVisibilityMode.LABEL_VISIBILITY_LABELED;
case 0:
return LabelVisibilityMode.LABEL_VISIBILITY_AUTO;
case 2:
return LabelVisibilityMode.LABEL_VISIBILITY_SELECTED;
case 3:
return LabelVisibilityMode.LABEL_VISIBILITY_UNLABELED;
}
}
public String getUserName() {
return mPreferences.getString(USER_NAME, "User");
}
public void setUserName(String name) {
mPreferences.edit().putString(USER_NAME, name).apply();
}
public boolean getVolumeToggle() {
return mPreferences.getBoolean(TOGGLE_VOLUME, false);
}
public final boolean ignoreMediaStoreArtwork() {
return mPreferences.getBoolean(IGNORE_MEDIA_STORE_ARTWORK, false);
}
public final boolean initializedBlacklist() {
return mPreferences.getBoolean(INITIALIZED_BLACKLIST, false);
}
private boolean isBlackMode() {
return mPreferences.getBoolean(BLACK_THEME, false);
}
public boolean isExtraControls() {
return mPreferences.getBoolean(TOGGLE_ADD_CONTROLS, false);
}
public final boolean isHomeBanner() {
return mPreferences.getBoolean(TOGGLE_HOME_BANNER, false);
}
public boolean isRoundCorners() {
return mPreferences.getBoolean(ROUND_CORNERS, false);
}
public boolean isScreenOnEnabled() {
return mPreferences.getBoolean(KEEP_SCREEN_ON, false);
}
public boolean isShuffleModeOn() {
return mPreferences.getBoolean(TOGGLE_SHUFFLE, false);
}
public boolean isSongInfo() {
return mPreferences.getBoolean(EXTRA_SONG_INFO, false);
}
public boolean pauseOnZeroVolume() {
return mPreferences.getBoolean(PAUSE_ON_ZERO_VOLUME, false);
}
public void registerOnSharedPreferenceChangedListener(
SharedPreferences.OnSharedPreferenceChangeListener sharedPreferenceChangeListener) {
mPreferences.registerOnSharedPreferenceChangeListener(sharedPreferenceChangeListener);
}
public void setAlbumGridSize(final int gridSize) {
final SharedPreferences.Editor editor = mPreferences.edit();
editor.putInt(ALBUM_GRID_SIZE, gridSize);
editor.apply();
}
public void setAlbumGridSizeLand(final int gridSize) {
final SharedPreferences.Editor editor = mPreferences.edit();
editor.putInt(ALBUM_GRID_SIZE_LAND, gridSize);
editor.apply();
}
public void setArtistGridSize(final int gridSize) {
final SharedPreferences.Editor editor = mPreferences.edit();
editor.putInt(ARTIST_GRID_SIZE, gridSize);
editor.apply();
}
public void setArtistGridSizeLand(final int gridSize) {
final SharedPreferences.Editor editor = mPreferences.edit();
editor.putInt(ARTIST_GRID_SIZE_LAND, gridSize);
editor.apply();
}
public void setBannerImagePath(String bannerImagePath) {
mPreferences.edit().putString(BANNER_IMAGE_PATH, bannerImagePath)
.apply();
}
public void setClassicNotification(final boolean value) {
final SharedPreferences.Editor editor = mPreferences.edit();
editor.putBoolean(CLASSIC_NOTIFICATION, value);
editor.apply();
}
public void setColoredAppShortcuts(final boolean value) {
final SharedPreferences.Editor editor = mPreferences.edit();
editor.putBoolean(COLORED_APP_SHORTCUTS, value);
editor.apply();
}
public final void setColoredNotification(boolean b) {
mPreferences.edit().putBoolean(COLORED_NOTIFICATION, b).apply();
}
public void setDesaturatedColor(boolean value) {
final SharedPreferences.Editor editor = mPreferences.edit();
editor.putBoolean(DESATURATED_COLOR, value);
editor.apply();
}
public void setInitializedBlacklist() {
final Editor editor = mPreferences.edit();
editor.putBoolean(INITIALIZED_BLACKLIST, true);
editor.apply();
}
public void setLastChangeLogVersion(int version) {
mPreferences.edit().putInt(LAST_CHANGELOG_VERSION, version).apply();
}
public void setNextSleepTimerElapsedRealtime(final long value) {
final SharedPreferences.Editor editor = mPreferences.edit();
editor.putLong(NEXT_SLEEP_TIMER_ELAPSED_REALTIME, value);
editor.apply();
}
public void setSongGridSize(final int gridSize) {
final SharedPreferences.Editor editor = mPreferences.edit();
editor.putInt(SONG_GRID_SIZE, gridSize);
editor.apply();
}
public void setSongGridSizeLand(final int gridSize) {
final SharedPreferences.Editor editor = mPreferences.edit();
editor.putInt(SONG_GRID_SIZE_LAND, gridSize);
editor.apply();
}
public void unregisterOnSharedPreferenceChangedListener(
@NonNull OnSharedPreferenceChangeListener sharedPreferenceChangeListener) {
mPreferences.unregisterOnSharedPreferenceChangeListener(sharedPreferenceChangeListener);
}
public boolean isExpandPanel() {
return mPreferences.getBoolean(EXPAND_NOW_PLAYING_PANEL, false);
}
public String getLanguageCode() {
return mPreferences.getString(LANGUAGE_NAME, "auto");
}
}

View file

@ -0,0 +1,552 @@
package code.name.monkey.retromusic.util
import android.content.SharedPreferences.OnSharedPreferenceChangeListener
import android.net.ConnectivityManager
import android.net.NetworkInfo
import androidx.core.content.ContextCompat
import androidx.core.content.edit
import androidx.preference.PreferenceManager
import androidx.viewpager.widget.ViewPager
import code.name.monkey.retromusic.*
import code.name.monkey.retromusic.extensions.getIntRes
import code.name.monkey.retromusic.extensions.getStringOrDefault
import code.name.monkey.retromusic.fragments.AlbumCoverStyle
import code.name.monkey.retromusic.fragments.NowPlayingScreen
import code.name.monkey.retromusic.fragments.mainactivity.FoldersFragment
import code.name.monkey.retromusic.helper.SortOrder.*
import code.name.monkey.retromusic.model.CategoryInfo
import code.name.monkey.retromusic.transform.*
import code.name.monkey.retromusic.util.theme.ThemeMode
import com.google.android.material.bottomnavigation.LabelVisibilityMode
import com.google.gson.Gson
import com.google.gson.JsonSyntaxException
import com.google.gson.reflect.TypeToken
import java.io.File
object PreferenceUtilKT {
private val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(App.getContext())
val defaultCategories = listOf(
CategoryInfo(CategoryInfo.Category.HOME, true),
CategoryInfo(CategoryInfo.Category.SONGS, true),
CategoryInfo(CategoryInfo.Category.ALBUMS, true),
CategoryInfo(CategoryInfo.Category.ARTISTS, true),
CategoryInfo(CategoryInfo.Category.PLAYLISTS, true),
CategoryInfo(CategoryInfo.Category.GENRES, false),
CategoryInfo(CategoryInfo.Category.QUEUE, false),
CategoryInfo(CategoryInfo.Category.FOLDER, false)
)
var libraryCategory: List<CategoryInfo>
get() {
val gson = Gson()
val collectionType = object : TypeToken<List<CategoryInfo>>() {}.type
val data = sharedPreferences.getStringOrDefault(
LIBRARY_CATEGORIES,
gson.toJson(defaultCategories, collectionType)
)
return try {
Gson().fromJson(data, collectionType)
} catch (e: JsonSyntaxException) {
e.printStackTrace()
return defaultCategories
}
}
set(value) {
val collectionType = object : TypeToken<List<CategoryInfo?>?>() {}.type
sharedPreferences.edit {
putString(LIBRARY_CATEGORIES, Gson().toJson(value, collectionType))
}
}
fun registerOnSharedPreferenceChangedListener(
changeListener: OnSharedPreferenceChangeListener
) {
sharedPreferences.registerOnSharedPreferenceChangeListener(changeListener)
}
fun unregisterOnSharedPreferenceChangedListener(
changeListener: OnSharedPreferenceChangeListener
) {
sharedPreferences.unregisterOnSharedPreferenceChangeListener(changeListener)
}
val baseTheme get() = sharedPreferences.getStringOrDefault(GENERAL_THEME, "auto")
fun getGeneralThemeValue(isSystemDark: Boolean): ThemeMode {
val themeMode: String =
sharedPreferences.getStringOrDefault(GENERAL_THEME, "auto")
return if (isBlackMode && isSystemDark) {
ThemeMode.BLACK
} else {
if (isBlackMode && themeMode == "dark") {
ThemeMode.BLACK
} else {
when (themeMode) {
"light" -> ThemeMode.LIGHT
"dark" -> ThemeMode.DARK
"auto" -> ThemeMode.AUTO
else -> ThemeMode.AUTO
}
}
}
}
val languageCode get() = sharedPreferences.getString(LANGUAGE_NAME, "auto")
var userName
get() = sharedPreferences.getString(USER_NAME, "User Name")
set(value) = sharedPreferences.edit {
putString(USER_NAME, value)
}
var safSdCardUri
get() = sharedPreferences.getStringOrDefault(SAF_SDCARD_URI, "")
set(value) = sharedPreferences.edit {
putString(SAF_SDCARD_URI, value)
}
val selectedEqualizer
get() = sharedPreferences.getStringOrDefault(
CHOOSE_EQUALIZER,
"system"
)
val autoDownloadImagesPolicy
get() = sharedPreferences.getStringOrDefault(
AUTO_DOWNLOAD_IMAGES_POLICY,
"only_wifi"
)
var albumDetailSongSortOrder
get() = sharedPreferences.getStringOrDefault(
ALBUM_DETAIL_SONG_SORT_ORDER,
AlbumSongSortOrder.SONG_TRACK_LIST
)
set(value) = sharedPreferences.edit { putString(ALBUM_DETAIL_SONG_SORT_ORDER, value) }
var songSortOrder
get() = sharedPreferences.getStringOrDefault(
SONG_SORT_ORDER,
SongSortOrder.SONG_A_Z
)
set(value) = sharedPreferences.edit {
putString(SONG_SORT_ORDER, value)
}
var albumSortOrder
get() = sharedPreferences.getStringOrDefault(
ALBUM_SORT_ORDER,
AlbumSortOrder.ALBUM_A_Z
)
set(value) = sharedPreferences.edit {
putString(ALBUM_SORT_ORDER, value)
}
var artistSortOrder
get() = sharedPreferences.getStringOrDefault(
ARTIST_SORT_ORDER,
AlbumSortOrder.ALBUM_A_Z
)
set(value) = sharedPreferences.edit {
putString(ARTIST_SORT_ORDER, value)
}
val albumSongSortOrder
get() = sharedPreferences.getStringOrDefault(
ALBUM_SONG_SORT_ORDER,
AlbumSongSortOrder.SONG_TRACK_LIST
)
val artistSongSortOrder
get() = sharedPreferences.getStringOrDefault(
ARTIST_SONG_SORT_ORDER,
AlbumSongSortOrder.SONG_TRACK_LIST
)
val artistAlbumSortOrder
get() = sharedPreferences.getStringOrDefault(
ARTIST_ALBUM_SORT_ORDER,
ArtistAlbumSortOrder.ALBUM_A_Z
)
val genreSortOrder
get() = sharedPreferences.getStringOrDefault(
GENRE_SORT_ORDER,
GenreSortOrder.GENRE_A_Z
)
val isIgnoreMediaStoreArtwork
get() = sharedPreferences.getBoolean(
IGNORE_MEDIA_STORE_ARTWORK,
false
)
val isVolumeVisibilityMode
get() = sharedPreferences.getBoolean(
TOGGLE_VOLUME, false
)
var isInitializedBlacklist
get() = sharedPreferences.getBoolean(
INITIALIZED_BLACKLIST, false
)
set(value) = sharedPreferences.edit {
putBoolean(INITIALIZED_BLACKLIST, value)
}
private val isBlackMode
get() = sharedPreferences.getBoolean(
BLACK_THEME, false
)
val isExtraControls
get() = sharedPreferences.getBoolean(
TOGGLE_ADD_CONTROLS, false
)
val isHomeBanner
get() = sharedPreferences.getBoolean(
TOGGLE_HOME_BANNER, false
)
var isClassicNotification
get() = sharedPreferences.getBoolean(CLASSIC_NOTIFICATION, false)
set(value) = sharedPreferences.edit { putBoolean(CLASSIC_NOTIFICATION, value) }
val isScreenOnEnabled get() = sharedPreferences.getBoolean(KEEP_SCREEN_ON, false)
val isShuffleModeOn get() = sharedPreferences.getBoolean(TOGGLE_SHUFFLE, false)
val isSongInfo get() = sharedPreferences.getBoolean(EXTRA_SONG_INFO, false)
val isPauseOnZeroVolume get() = sharedPreferences.getBoolean(PAUSE_ON_ZERO_VOLUME, false)
var isSleepTimerFinishMusic
get() = sharedPreferences.getBoolean(
SLEEP_TIMER_FINISH_SONG, false
)
set(value) = sharedPreferences.edit {
putBoolean(SLEEP_TIMER_FINISH_SONG, value)
}
val isExpandPanel get() = sharedPreferences.getBoolean(EXPAND_NOW_PLAYING_PANEL, false)
val isHeadsetPlugged
get() = sharedPreferences.getBoolean(
TOGGLE_HEADSET, false
)
val isAlbumArtOnLockScreen
get() = sharedPreferences.getBoolean(
ALBUM_ART_ON_LOCKSCREEN, false
)
val isAudioDucking
get() = sharedPreferences.getBoolean(
AUDIO_DUCKING, true
)
val isBluetoothSpeaker
get() = sharedPreferences.getBoolean(
BLUETOOTH_PLAYBACK, false
)
val isBlurredAlbumArt
get() = sharedPreferences.getBoolean(
BLURRED_ALBUM_ART, false
)
val isCarouselEffect
get() = sharedPreferences.getBoolean(
CAROUSEL_EFFECT, false
)
var isColoredAppShortcuts
get() = sharedPreferences.getBoolean(
COLORED_APP_SHORTCUTS, true
)
set(value) = sharedPreferences.edit {
putBoolean(COLORED_APP_SHORTCUTS, value)
}
var isColoredNotification
get() = sharedPreferences.getBoolean(
COLORED_NOTIFICATION, true
)
set(value) = sharedPreferences.edit {
putBoolean(COLORED_NOTIFICATION, value)
}
var isDesaturatedColor
get() = sharedPreferences.getBoolean(
DESATURATED_COLOR, false
)
set(value) = sharedPreferences.edit {
putBoolean(DESATURATED_COLOR, value)
}
val isGapLessPlayback
get() = sharedPreferences.getBoolean(
GAPLESS_PLAYBACK, false
)
val isAdaptiveColor
get() = sharedPreferences.getBoolean(
ADAPTIVE_COLOR_APP, false
)
val isFullScreenMode
get() = sharedPreferences.getBoolean(
TOGGLE_FULL_SCREEN, false
)
val isLockScreen get() = sharedPreferences.getBoolean(LOCK_SCREEN, false)
fun isAllowedToDownloadMetadata(): Boolean {
return when (autoDownloadImagesPolicy) {
"always" -> true
"only_wifi" -> {
val connectivityManager = ContextCompat.getSystemService(
App.getContext(),
ConnectivityManager::class.java
)
var netInfo: NetworkInfo? = null
if (connectivityManager != null) {
netInfo = connectivityManager.activeNetworkInfo
}
netInfo != null && netInfo.type == ConnectivityManager.TYPE_WIFI && netInfo.isConnectedOrConnecting
}
"never" -> false
else -> false
}
}
var lyricsOption
get() = sharedPreferences.getInt(LYRICS_OPTIONS, 1)
set(value) = sharedPreferences.edit {
putInt(LYRICS_OPTIONS, value)
}
var songGridStyle
get() = sharedPreferences.getInt(SONG_GRID_STYLE, R.layout.item_grid)
set(value) = sharedPreferences.edit {
putInt(SONG_GRID_STYLE, value)
}
var albumGridStyle
get() = sharedPreferences.getInt(ALBUM_GRID_STYLE, R.layout.item_grid)
set(value) = sharedPreferences.edit {
putInt(ALBUM_GRID_STYLE, value)
}
var artistGridStyle
get() = sharedPreferences.getInt(ARTIST_GRID_STYLE, R.layout.item_grid_circle)
set(value) = sharedPreferences.edit {
putInt(ARTIST_GRID_STYLE, value)
}
val filterLength get() = sharedPreferences.getInt(FILTER_SONG, 20)
var lastVersion
get() = sharedPreferences.getInt(LAST_CHANGELOG_VERSION, 0)
set(value) = sharedPreferences.edit {
putInt(LAST_CHANGELOG_VERSION, value)
}
var lastSleepTimerValue
get() = sharedPreferences.getInt(
LAST_SLEEP_TIMER_VALUE,
30
)
set(value) = sharedPreferences.edit {
putInt(LAST_SLEEP_TIMER_VALUE, value)
}
var lastPage
get() = sharedPreferences.getInt(LAST_PAGE, R.id.action_song)
set(value) = sharedPreferences.edit {
putInt(LAST_PAGE, value)
}
var nextSleepTimerElapsedRealTime
get() = sharedPreferences.getInt(
NEXT_SLEEP_TIMER_ELAPSED_REALTIME,
-1
)
set(value) = sharedPreferences.edit {
putInt(NEXT_SLEEP_TIMER_ELAPSED_REALTIME, value)
}
fun themeResFromPrefValue(themePrefValue: String): Int {
return when (themePrefValue) {
"light" -> R.style.Theme_RetroMusic_Light
"dark" -> R.style.Theme_RetroMusic
else -> R.style.Theme_RetroMusic
}
}
val homeGridStyle: Int
get() {
val position =
sharedPreferences.getStringOrDefault(
HOME_ARTIST_GRID_STYLE, "0"
).toInt()
val typedArray =
App.getContext().resources.obtainTypedArray(R.array.pref_home_grid_style_layout)
val layoutRes = typedArray.getResourceId(position, 0)
typedArray.recycle()
return if (layoutRes == 0) {
R.layout.item_artist
} else layoutRes
}
val tabTitleMode: Int
get() {
return when (sharedPreferences.getStringOrDefault(
TAB_TEXT_MODE, "1"
).toInt()) {
1 -> LabelVisibilityMode.LABEL_VISIBILITY_LABELED
0 -> LabelVisibilityMode.LABEL_VISIBILITY_AUTO
2 -> LabelVisibilityMode.LABEL_VISIBILITY_SELECTED
3 -> LabelVisibilityMode.LABEL_VISIBILITY_UNLABELED
else -> LabelVisibilityMode.LABEL_VISIBILITY_LABELED
}
}
var songGridSize
get() = sharedPreferences.getInt(
SONG_GRID_SIZE,
App.getContext().getIntRes(R.integer.default_grid_columns)
)
set(value) = sharedPreferences.edit {
putInt(SONG_GRID_SIZE, value)
}
var songGridSizeLand
get() = sharedPreferences.getInt(
SONG_GRID_SIZE_LAND,
App.getContext().getIntRes(R.integer.default_grid_columns_land)
)
set(value) = sharedPreferences.edit {
putInt(SONG_GRID_SIZE_LAND, value)
}
var albumGridSize: Int
get() = sharedPreferences.getInt(
ALBUM_GRID_SIZE,
App.getContext().getIntRes(R.integer.default_grid_columns)
)
set(value) = sharedPreferences.edit {
putInt(ALBUM_GRID_SIZE, value)
}
var albumGridSizeLand
get() = sharedPreferences.getInt(
ALBUM_GRID_SIZE_LAND,
App.getContext().getIntRes(R.integer.default_grid_columns_land)
)
set(value) = sharedPreferences.edit {
putInt(ALBUM_GRID_SIZE_LAND, value)
}
var artistGridSize
get() = sharedPreferences.getInt(
ARTIST_GRID_SIZE,
App.getContext().getIntRes(R.integer.default_grid_columns)
)
set(value) = sharedPreferences.edit {
putInt(ARTIST_GRID_SIZE, value)
}
var artistGridSizeLand
get() = sharedPreferences.getInt(
ALBUM_GRID_SIZE_LAND,
App.getContext().getIntRes(R.integer.default_grid_columns_land)
)
set(value) = sharedPreferences.edit {
putInt(ALBUM_GRID_SIZE_LAND, value)
}
var albumCoverStyle: AlbumCoverStyle
get() {
val id: Int = sharedPreferences.getInt(ALBUM_COVER_STYLE, 0)
for (albumCoverStyle in AlbumCoverStyle.values()) {
if (albumCoverStyle.id == id) {
return albumCoverStyle
}
}
return AlbumCoverStyle.CARD
}
set(value) = sharedPreferences.edit { putInt(ALBUM_COVER_STYLE, value.id) }
var nowPlayingScreen: NowPlayingScreen
get() {
val id: Int = sharedPreferences.getInt(NOW_PLAYING_SCREEN_ID, 0)
for (nowPlayingScreen in NowPlayingScreen.values()) {
if (nowPlayingScreen.id == id) {
return nowPlayingScreen
}
}
return NowPlayingScreen.Adaptive
}
set(value) = sharedPreferences.edit {
putInt(NOW_PLAYING_SCREEN_ID, value.id)
}
val albumCoverTransform: ViewPager.PageTransformer
get() {
val style = sharedPreferences.getStringOrDefault(
ALBUM_COVER_TRANSFORM,
"0"
).toInt()
return when (style) {
0 -> NormalPageTransformer()
1 -> CascadingPageTransformer()
2 -> DepthTransformation()
3 -> HorizontalFlipTransformation()
4 -> VerticalFlipTransformation()
5 -> HingeTransformation()
6 -> VerticalStackTransformer()
else -> NormalPageTransformer()
}
}
var startDirectory: File
get() {
val folderPath = FoldersFragment.getDefaultStartDirectory().path
val filePath: String = sharedPreferences.getStringOrDefault(START_DIRECTORY, folderPath)
return File(filePath) ?: File(FoldersFragment.getDefaultStartDirectory().path)
}
set(value) = sharedPreferences.edit {
putString(
START_DIRECTORY,
FileUtil.safeGetCanonicalPath(value)
)
}
val lastAddedCutoff: Long
get() {
val calendarUtil = CalendarUtil()
val interval =
when (sharedPreferences.getStringOrDefault(LAST_ADDED_CUTOFF, "this_month")) {
"today" -> calendarUtil.elapsedToday
"this_week" -> calendarUtil.elapsedWeek
"past_three_months" -> calendarUtil.getElapsedMonths(3)
"this_year" -> calendarUtil.elapsedYear
"this_month" -> calendarUtil.elapsedMonth
else -> calendarUtil.elapsedMonth
}
return (System.currentTimeMillis() - interval) / 1000
}
}

View file

@ -142,7 +142,7 @@ public class RetroUtil {
}
public static boolean isAllowedToDownloadMetadata(final @NonNull Context context) {
switch (PreferenceUtil.getInstance(context).autoDownloadImagesPolicy()) {
switch (PreferenceUtilKT.INSTANCE.getAutoDownloadImagesPolicy()) {
case "always":
return true;
case "only_wifi":

View file

@ -76,7 +76,6 @@ class RingtoneManager(val context: Context) {
fun getDialog(context: Context): MaterialDialog {
return MaterialDialog(context).show {
cornerRadius(PreferenceUtil.getInstance(context).dialogCorner)
title(R.string.dialog_title_set_ringtone)
message(R.string.dialog_message_set_ringtone)
positiveButton(android.R.string.ok) {

View file

@ -119,19 +119,19 @@ public class SAFUtil {
public static void saveTreeUri(Context context, Intent data) {
Uri uri = data.getData();
context.getContentResolver().takePersistableUriPermission(uri, Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);
PreferenceUtil.getInstance(context).setSAFSDCardUri(uri);
PreferenceUtilKT.INSTANCE.setSafSdCardUri(uri.toString());
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public static boolean isTreeUriSaved(Context context) {
return !TextUtils.isEmpty(PreferenceUtil.getInstance(context).getSAFSDCardUri());
return !TextUtils.isEmpty(PreferenceUtilKT.INSTANCE.getSafSdCardUri());
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public static boolean isSDCardAccessGranted(Context context) {
if (!isTreeUriSaved(context)) return false;
String sdcardUri = PreferenceUtil.getInstance(context).getSAFSDCardUri();
String sdcardUri = PreferenceUtilKT.INSTANCE.getSafSdCardUri();
List<UriPermission> perms = context.getContentResolver().getPersistedUriPermissions();
for (UriPermission perm : perms) {
@ -198,7 +198,7 @@ public class SAFUtil {
if (isTreeUriSaved(context)) {
List<String> pathSegments = new ArrayList<>(Arrays.asList(audio.getFile().getAbsolutePath().split("/")));
Uri sdcard = Uri.parse(PreferenceUtil.getInstance(context).getSAFSDCardUri());
Uri sdcard = Uri.parse(PreferenceUtilKT.INSTANCE.getSafSdCardUri());
uri = findDocument(DocumentFile.fromTreeUri(context, sdcard), pathSegments);
}
@ -271,7 +271,7 @@ public class SAFUtil {
if (isTreeUriSaved(context)) {
List<String> pathSegments = new ArrayList<>(Arrays.asList(path.split("/")));
Uri sdcard = Uri.parse(PreferenceUtil.getInstance(context).getSAFSDCardUri());
Uri sdcard = Uri.parse(PreferenceUtilKT.INSTANCE.getSafSdCardUri());
uri = findDocument(DocumentFile.fromTreeUri(context, sdcard), pathSegments);
}

View file

@ -1,13 +1,10 @@
package code.name.monkey.retromusic.util.theme
import android.content.Context
import android.content.res.Configuration
import android.os.PowerManager
import androidx.annotation.StyleRes
import androidx.appcompat.app.AppCompatDelegate
import code.name.monkey.retromusic.R
import code.name.monkey.retromusic.util.PreferenceUtil
import code.name.monkey.retromusic.util.theme.ThemeManager.isSystemDarkModeEnabled
import code.name.monkey.retromusic.extensions.generalThemeValue
import code.name.monkey.retromusic.util.theme.ThemeMode.*
object ThemeManager {
@ -30,19 +27,5 @@ object ThemeManager {
BLACK -> AppCompatDelegate.MODE_NIGHT_YES
AUTO -> AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM
}
fun isSystemDarkModeEnabled(context: Context): Boolean {
val isBatterySaverEnabled =
(context.getSystemService(Context.POWER_SERVICE) as PowerManager?)?.isPowerSaveMode
?: false
val isDarkModeEnabled =
(context.resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_YES
return isBatterySaverEnabled or isDarkModeEnabled
}
}
val Context.generalThemeValue: ThemeMode
get() {
return PreferenceUtil.getInstance(this).getGeneralThemeValue(isSystemDarkModeEnabled(this))
}