Removed app context for PreferenceUtil class
This commit is contained in:
parent
5df5f6c93e
commit
2bbe39eab7
97 changed files with 397 additions and 456 deletions
|
@ -44,7 +44,7 @@ class CustomArtistImageUtil private constructor(context: Context) {
|
|||
}
|
||||
|
||||
fun setCustomArtistImage(artist: Artist, uri: Uri) {
|
||||
GlideApp.with(App.context)
|
||||
GlideApp.with(App.getContext())
|
||||
.asBitmap()
|
||||
.load(uri)
|
||||
.apply(RequestOptions()
|
||||
|
@ -57,7 +57,7 @@ class CustomArtistImageUtil private constructor(context: Context) {
|
|||
object : AsyncTask<Void, Void, Void>() {
|
||||
@SuppressLint("ApplySharedPref")
|
||||
override fun doInBackground(vararg params: Void): Void? {
|
||||
val dir = File(App.context.filesDir, FOLDER_NAME)
|
||||
val dir = File(App.getContext().filesDir, FOLDER_NAME)
|
||||
println(dir.absolutePath)
|
||||
if (!dir.exists()) {
|
||||
if (!dir.mkdirs()) { // create the folder
|
||||
|
@ -72,13 +72,13 @@ class CustomArtistImageUtil private constructor(context: Context) {
|
|||
succesful = ImageUtil.resizeBitmap(resource, 2048).compress(Bitmap.CompressFormat.JPEG, 100, os)
|
||||
os.close()
|
||||
} catch (e: IOException) {
|
||||
Toast.makeText(App.context, e.toString(), Toast.LENGTH_LONG).show()
|
||||
Toast.makeText(App.getContext(), e.toString(), Toast.LENGTH_LONG).show()
|
||||
}
|
||||
|
||||
if (succesful) {
|
||||
mPreferences.edit().putBoolean(getFileName(artist), true).commit()
|
||||
ArtistSignatureUtil.getInstance().updateArtistSignature(artist.name)
|
||||
App.context.contentResolver.notifyChange(Uri.parse("content://media"), null) // trigger media store changed to force artist image reload
|
||||
App.getContext().contentResolver.notifyChange(Uri.parse("content://media"), null) // trigger media store changed to force artist image reload
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
@ -93,7 +93,7 @@ class CustomArtistImageUtil private constructor(context: Context) {
|
|||
override fun doInBackground(vararg params: Void): Void? {
|
||||
mPreferences.edit().putBoolean(getFileName(artist), false).commit()
|
||||
ArtistSignatureUtil.getInstance().updateArtistSignature(artist.name)
|
||||
App.context.contentResolver.notifyChange(Uri.parse("content://media"), null) // trigger media store changed to force artist image reload
|
||||
App.getContext().contentResolver.notifyChange(Uri.parse("content://media"), null) // trigger media store changed to force artist image reload
|
||||
|
||||
val file = getFile(artist)
|
||||
if (!file.exists()) {
|
||||
|
@ -133,7 +133,7 @@ class CustomArtistImageUtil private constructor(context: Context) {
|
|||
|
||||
@JvmStatic
|
||||
fun getFile(artist: Artist): File {
|
||||
val dir = File(App.context.filesDir, FOLDER_NAME)
|
||||
val dir = File(App.getContext().filesDir, FOLDER_NAME)
|
||||
return File(dir, getFileName(artist))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -142,7 +142,8 @@ public final class PreferenceUtil {
|
|||
mPreferences = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
}
|
||||
|
||||
public static PreferenceUtil getInstance() {
|
||||
@NonNull
|
||||
public static PreferenceUtil getInstance(Context context) {
|
||||
if (sInstance == null) {
|
||||
sInstance = new PreferenceUtil(App.Companion.getContext());
|
||||
}
|
||||
|
|
|
@ -26,7 +26,6 @@ import android.graphics.Bitmap;
|
|||
import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Point;
|
||||
import android.graphics.drawable.BitmapDrawable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.NetworkInfo;
|
||||
|
@ -37,15 +36,10 @@ import android.provider.BaseColumns;
|
|||
import android.provider.MediaStore;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.view.Display;
|
||||
import android.view.KeyCharacterMap;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.View;
|
||||
import android.view.ViewConfiguration;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.Window;
|
||||
import android.view.WindowManager;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.FrameLayout;
|
||||
|
||||
import androidx.annotation.ColorInt;
|
||||
import androidx.annotation.DrawableRes;
|
||||
|
@ -197,8 +191,8 @@ public class RetroUtil {
|
|||
|
||||
public static Drawable getTintedDrawable(@DrawableRes int id) {
|
||||
return TintHelper
|
||||
.createTintedDrawable(ContextCompat.getDrawable(App.Companion.getInstance(), id),
|
||||
ThemeStore.Companion.accentColor(App.Companion.getInstance()));
|
||||
.createTintedDrawable(ContextCompat.getDrawable(App.Companion.getContext(), id),
|
||||
ThemeStore.Companion.accentColor(App.Companion.getContext()));
|
||||
}
|
||||
|
||||
@NonNull
|
||||
|
@ -218,7 +212,7 @@ public class RetroUtil {
|
|||
}
|
||||
|
||||
public static boolean isAllowedToDownloadMetadata(final @NonNull Context context) {
|
||||
switch (PreferenceUtil.getInstance().autoDownloadImagesPolicy()) {
|
||||
switch (PreferenceUtil.getInstance(context).autoDownloadImagesPolicy()) {
|
||||
case "always":
|
||||
return true;
|
||||
case "only_wifi":
|
||||
|
@ -291,10 +285,6 @@ public class RetroUtil {
|
|||
}
|
||||
}
|
||||
|
||||
public static void statusBarHeight(View statusBar) {
|
||||
statusBar.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, getStatusBarHeight()));
|
||||
}
|
||||
|
||||
public static int getStatusBarHeight() {
|
||||
int result = 0;
|
||||
int resourceId = App.Companion.getContext().getResources().getIdentifier("status_bar_height", "dimen", "android");
|
||||
|
@ -321,117 +311,4 @@ public class RetroUtil {
|
|||
window.getDecorView().setSystemUiVisibility(
|
||||
View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
|
||||
}
|
||||
|
||||
public static int getSoftButtonsBarSizePort(Activity activity) {
|
||||
// getRealMetrics is only available with API 17 and +
|
||||
DisplayMetrics metrics = new DisplayMetrics();
|
||||
activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);
|
||||
int usableHeight = metrics.heightPixels;
|
||||
activity.getWindowManager().getDefaultDisplay().getRealMetrics(metrics);
|
||||
int realHeight = metrics.heightPixels;
|
||||
if (realHeight > usableHeight)
|
||||
return realHeight - usableHeight;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static int getNavigationBarHeight(Activity activity) {
|
||||
/* int result = 0;
|
||||
int resourceId = App.getContext().getResources().getIdentifier("navigation_bar_height", "dimen", "android");
|
||||
if (resourceId > 0) {
|
||||
result = App.getContext().getResources().getDimensionPixelSize(resourceId);
|
||||
}
|
||||
return result;*/
|
||||
DisplayMetrics metrics = new DisplayMetrics();
|
||||
activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);
|
||||
int usableHeight = metrics.heightPixels;
|
||||
activity.getWindowManager().getDefaultDisplay().getRealMetrics(metrics);
|
||||
int realHeight = metrics.heightPixels;
|
||||
if (realHeight > usableHeight)
|
||||
if (PreferenceUtil.getInstance().getFullScreenMode()) {
|
||||
return 0;
|
||||
} else
|
||||
return realHeight - usableHeight;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static int getNavBarHeight(Context c) {
|
||||
int result = 0;
|
||||
boolean hasMenuKey = ViewConfiguration.get(c).hasPermanentMenuKey();
|
||||
boolean hasBackKey = KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_BACK);
|
||||
|
||||
if (!hasMenuKey && !hasBackKey) {
|
||||
//The device has a navigation bar
|
||||
Resources resources = c.getResources();
|
||||
|
||||
int orientation = resources.getConfiguration().orientation;
|
||||
int resourceId;
|
||||
if (isTablet(c)) {
|
||||
resourceId = resources.getIdentifier(orientation == Configuration.ORIENTATION_PORTRAIT ? "navigation_bar_height" : "navigation_bar_height_landscape", "dimen", "android");
|
||||
} else {
|
||||
resourceId = resources.getIdentifier(orientation == Configuration.ORIENTATION_PORTRAIT ? "navigation_bar_height" : "navigation_bar_width", "dimen", "android");
|
||||
}
|
||||
|
||||
if (resourceId > 0) {
|
||||
return resources.getDimensionPixelSize(resourceId);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
private static boolean isTablet(Context c) {
|
||||
return (c.getResources().getConfiguration().screenLayout
|
||||
& Configuration.SCREENLAYOUT_SIZE_MASK)
|
||||
>= Configuration.SCREENLAYOUT_SIZE_LARGE;
|
||||
}
|
||||
|
||||
private static boolean hasNavBar(Resources resources) {
|
||||
int id = resources.getIdentifier("config_showNavigationBar", "bool", "android");
|
||||
if (id > 0)
|
||||
return resources.getBoolean(id);
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
public static int getNavigationBarHeight(Resources resources) {
|
||||
if (!hasNavBar(resources))
|
||||
return 0;
|
||||
|
||||
int orientation = resources.getConfiguration().orientation;
|
||||
|
||||
//Only phone between 0-599 has navigationbar can move
|
||||
boolean isSmartphone = resources.getConfiguration().smallestScreenWidthDp < 600;
|
||||
if (isSmartphone && Configuration.ORIENTATION_LANDSCAPE == orientation)
|
||||
return 0;
|
||||
|
||||
int id = resources
|
||||
.getIdentifier(orientation == Configuration.ORIENTATION_PORTRAIT ? "navigation_bar_height" : "navigation_bar_height_landscape", "dimen", "android");
|
||||
if (id > 0)
|
||||
return resources.getDimensionPixelSize(id);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static boolean checkNavigationBarHeight() {
|
||||
Resources resources = App.Companion.getContext().getResources();
|
||||
int orientation = resources.getConfiguration().orientation;
|
||||
if (!hasNavBar(resources)) {
|
||||
return false;
|
||||
}
|
||||
boolean isSmartPhone = resources.getConfiguration().smallestScreenWidthDp < 600;
|
||||
if (isSmartPhone && Configuration.ORIENTATION_LANDSCAPE == orientation)
|
||||
return false;
|
||||
int id = resources
|
||||
.getIdentifier(orientation == Configuration.ORIENTATION_PORTRAIT ? "navigation_bar_height" : "navigation_bar_height_landscape", "dimen", "android");
|
||||
return id > 0;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public static Drawable resize(@NonNull Context context, @NonNull Drawable image) {
|
||||
Bitmap b = ((BitmapDrawable) image).getBitmap();
|
||||
Bitmap bitmapResized = Bitmap.createScaledBitmap(b, 50, 50, false);
|
||||
return new BitmapDrawable(context.getResources(), bitmapResized);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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().setSAFSDCardUri(uri);
|
||||
PreferenceUtil.getInstance(context).setSAFSDCardUri(uri);
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
|
||||
public static boolean isTreeUriSaved(Context context) {
|
||||
return !TextUtils.isEmpty(PreferenceUtil.getInstance().getSAFSDCardUri());
|
||||
return !TextUtils.isEmpty(PreferenceUtil.getInstance(context).getSAFSDCardUri());
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
|
||||
public static boolean isSDCardAccessGranted(Context context) {
|
||||
if (!isTreeUriSaved(context)) return false;
|
||||
|
||||
String sdcardUri = PreferenceUtil.getInstance().getSAFSDCardUri();
|
||||
String sdcardUri = PreferenceUtil.getInstance(context).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().getSAFSDCardUri());
|
||||
Uri sdcard = Uri.parse(PreferenceUtil.getInstance(context).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().getSAFSDCardUri());
|
||||
Uri sdcard = Uri.parse(PreferenceUtil.getInstance(context).getSAFSDCardUri());
|
||||
uri = findDocument(DocumentFile.fromTreeUri(context, sdcard), pathSegments);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue