Removed unused methods
This commit is contained in:
parent
a3399e7aed
commit
3e1657d8eb
4 changed files with 8 additions and 145 deletions
|
@ -190,7 +190,6 @@
|
|||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
|
||||
<provider
|
||||
android:name=".misc.GenericFileProvider"
|
||||
android:authorities="${applicationId}.provider"
|
||||
|
|
|
@ -75,7 +75,6 @@ import code.name.monkey.retromusic.service.playback.Playback
|
|||
import code.name.monkey.retromusic.service.playback.Playback.PlaybackCallbacks
|
||||
import code.name.monkey.retromusic.util.MusicUtil.getMediaStoreAlbumCoverUri
|
||||
import code.name.monkey.retromusic.util.MusicUtil.getSongFileUri
|
||||
import code.name.monkey.retromusic.util.MusicUtil.isFavorite
|
||||
import code.name.monkey.retromusic.util.MusicUtil.toggleFavorite
|
||||
import code.name.monkey.retromusic.util.PackageValidator
|
||||
import code.name.monkey.retromusic.util.PreferenceUtil.crossFadeDuration
|
||||
|
@ -1413,17 +1412,6 @@ class MusicService : MediaBrowserServiceCompat(),
|
|||
)
|
||||
.build()
|
||||
)
|
||||
val favoriteIcon = if (isFavorite(
|
||||
applicationContext,
|
||||
currentSong
|
||||
)
|
||||
) R.drawable.ic_favorite else R.drawable.ic_favorite_border
|
||||
stateBuilder.addCustomAction(
|
||||
PlaybackStateCompat.CustomAction.Builder(
|
||||
TOGGLE_FAVORITE, getString(R.string.action_toggle_favorite), favoriteIcon
|
||||
)
|
||||
.build()
|
||||
)
|
||||
}
|
||||
|
||||
private fun setupMediaSession() {
|
||||
|
|
|
@ -22,10 +22,8 @@ import code.name.monkey.retromusic.extensions.getLong
|
|||
import code.name.monkey.retromusic.extensions.showToast
|
||||
import code.name.monkey.retromusic.helper.MusicPlayerRemote.removeFromQueue
|
||||
import code.name.monkey.retromusic.model.Artist
|
||||
import code.name.monkey.retromusic.model.Playlist
|
||||
import code.name.monkey.retromusic.model.Song
|
||||
import code.name.monkey.retromusic.model.lyrics.AbsSynchronizedLyrics
|
||||
import code.name.monkey.retromusic.repository.RealPlaylistRepository
|
||||
import code.name.monkey.retromusic.repository.Repository
|
||||
import code.name.monkey.retromusic.repository.SongRepository
|
||||
import code.name.monkey.retromusic.service.MusicService
|
||||
|
@ -265,7 +263,7 @@ object MusicUtil : KoinComponent {
|
|||
}
|
||||
|
||||
fun getSongFilePath(context: Context, uri: Uri): String {
|
||||
val projection = arrayOf(MediaStore.MediaColumns.DATA)
|
||||
val projection = arrayOf(Constants.DATA)
|
||||
context.contentResolver.query(uri, projection, null, null, null)?.use {
|
||||
if (it.moveToFirst()) {
|
||||
return it.getString(0)
|
||||
|
@ -335,48 +333,21 @@ object MusicUtil : KoinComponent {
|
|||
return false
|
||||
}
|
||||
|
||||
fun isFavorite(context: Context, song: Song): Boolean {
|
||||
return PlaylistsUtil
|
||||
.doPlaylistContains(context, getFavoritesPlaylist(context).id, song.id)
|
||||
}
|
||||
|
||||
fun isFavoritePlaylist(
|
||||
context: Context,
|
||||
playlist: Playlist
|
||||
): Boolean {
|
||||
return playlist.name == context.getString(R.string.favorites)
|
||||
}
|
||||
|
||||
val repository = get<Repository>()
|
||||
fun toggleFavorite(context: Context, song: Song) {
|
||||
GlobalScope.launch {
|
||||
val playlist: PlaylistEntity = repository.favoritePlaylist()
|
||||
if (playlist != null) {
|
||||
val songEntity = song.toSongEntity(playlist.playListId)
|
||||
val isFavorite = repository.isFavoriteSong(songEntity).isNotEmpty()
|
||||
if (isFavorite) {
|
||||
repository.removeSongFromPlaylist(songEntity)
|
||||
} else {
|
||||
repository.insertSongs(listOf(song.toSongEntity(playlist.playListId)))
|
||||
}
|
||||
val songEntity = song.toSongEntity(playlist.playListId)
|
||||
val isFavorite = repository.isFavoriteSong(songEntity).isNotEmpty()
|
||||
if (isFavorite) {
|
||||
repository.removeSongFromPlaylist(songEntity)
|
||||
} else {
|
||||
repository.insertSongs(listOf(song.toSongEntity(playlist.playListId)))
|
||||
}
|
||||
context.sendBroadcast(Intent(MusicService.FAVORITE_STATE_CHANGED))
|
||||
}
|
||||
}
|
||||
|
||||
private fun getFavoritesPlaylist(context: Context): Playlist {
|
||||
return RealPlaylistRepository(context.contentResolver).playlist(context.getString(R.string.favorites))
|
||||
}
|
||||
|
||||
private fun getOrCreateFavoritesPlaylist(context: Context): Playlist {
|
||||
return RealPlaylistRepository(context.contentResolver).playlist(
|
||||
PlaylistsUtil.createPlaylist(
|
||||
context,
|
||||
context.getString(R.string.favorites)
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
fun deleteTracks(
|
||||
activity: FragmentActivity,
|
||||
songs: List<Song>,
|
||||
|
@ -455,12 +426,11 @@ object MusicUtil : KoinComponent {
|
|||
activity.showToast(activity.getString(R.string.deleted_x_songs, songCount))
|
||||
callback?.run()
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun deleteTracks(context: Context, songs: List<Song>) {
|
||||
val projection = arrayOf(BaseColumns._ID, MediaStore.MediaColumns.DATA)
|
||||
val projection = arrayOf(BaseColumns._ID, Constants.DATA)
|
||||
val selection = StringBuilder()
|
||||
selection.append(BaseColumns._ID + " IN (")
|
||||
for (i in songs.indices) {
|
||||
|
|
|
@ -14,25 +14,13 @@
|
|||
|
||||
package code.name.monkey.retromusic.util;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.res.Configuration;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Point;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.NetworkInfo;
|
||||
import android.os.Build;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.view.Display;
|
||||
import android.view.View;
|
||||
import android.view.Window;
|
||||
import android.view.WindowManager;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
|
||||
import androidx.annotation.ColorInt;
|
||||
import androidx.annotation.DrawableRes;
|
||||
|
@ -51,29 +39,6 @@ import code.name.monkey.retromusic.App;
|
|||
|
||||
public class RetroUtil {
|
||||
|
||||
private static final int[] TEMP_ARRAY = new int[1];
|
||||
|
||||
private static final String SHOW_NAV_BAR_RES_NAME = "config_showNavigationBar";
|
||||
|
||||
public static int calculateNoOfColumns(@NonNull Context context) {
|
||||
DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
|
||||
float dpWidth = displayMetrics.widthPixels / displayMetrics.density;
|
||||
return (int) (dpWidth / 180);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public static Bitmap createBitmap(@NonNull Drawable drawable, float sizeMultiplier) {
|
||||
Bitmap bitmap =
|
||||
Bitmap.createBitmap(
|
||||
(int) (drawable.getIntrinsicWidth() * sizeMultiplier),
|
||||
(int) (drawable.getIntrinsicHeight() * sizeMultiplier),
|
||||
Bitmap.Config.ARGB_8888);
|
||||
Canvas c = new Canvas(bitmap);
|
||||
drawable.setBounds(0, 0, c.getWidth(), c.getHeight());
|
||||
drawable.draw(c);
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
public static String formatValue(float value) {
|
||||
String[] arr = {"", "K", "M", "B", "T", "P", "E"};
|
||||
int index = 0;
|
||||
|
@ -147,75 +112,16 @@ public class RetroUtil {
|
|||
return ResourcesCompat.getDrawable(res, resId, theme);
|
||||
}
|
||||
|
||||
public static void hideSoftKeyboard(@Nullable Activity activity) {
|
||||
if (activity != null) {
|
||||
View currentFocus = activity.getCurrentFocus();
|
||||
if (currentFocus != null) {
|
||||
InputMethodManager inputMethodManager =
|
||||
(InputMethodManager) activity.getSystemService(Activity.INPUT_METHOD_SERVICE);
|
||||
if (inputMethodManager != null) {
|
||||
inputMethodManager.hideSoftInputFromWindow(currentFocus.getWindowToken(), 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isAllowedToDownloadMetadata(final @NonNull Context context) {
|
||||
switch (PreferenceUtil.INSTANCE.getAutoDownloadImagesPolicy()) {
|
||||
case "always":
|
||||
return true;
|
||||
case "only_wifi":
|
||||
final ConnectivityManager connectivityManager =
|
||||
(ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
NetworkInfo netInfo = connectivityManager.getActiveNetworkInfo();
|
||||
return netInfo != null
|
||||
&& netInfo.getType() == ConnectivityManager.TYPE_WIFI
|
||||
&& netInfo.isConnectedOrConnecting();
|
||||
case "never":
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isLandscape() {
|
||||
return App.Companion.getContext().getResources().getConfiguration().orientation
|
||||
== Configuration.ORIENTATION_LANDSCAPE;
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
|
||||
public static boolean isRTL(@NonNull Context context) {
|
||||
Configuration config = context.getResources().getConfiguration();
|
||||
return config.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL;
|
||||
}
|
||||
|
||||
public static boolean isTablet() {
|
||||
return App.Companion.getContext().getResources().getConfiguration().smallestScreenWidthDp
|
||||
>= 600;
|
||||
}
|
||||
|
||||
public static void setAllowDrawUnderNavigationBar(Window window) {
|
||||
window.setNavigationBarColor(Color.TRANSPARENT);
|
||||
window
|
||||
.getDecorView()
|
||||
.setSystemUiVisibility(
|
||||
Build.VERSION.SDK_INT >= Build.VERSION_CODES.O
|
||||
? View.SYSTEM_UI_FLAG_LAYOUT_STABLE
|
||||
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
|
||||
| View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR
|
||||
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
|
||||
: View.SYSTEM_UI_FLAG_LAYOUT_STABLE
|
||||
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
|
||||
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
|
||||
}
|
||||
|
||||
public static void setAllowDrawUnderStatusBar(@NonNull Window window) {
|
||||
window
|
||||
.getDecorView()
|
||||
.setSystemUiVisibility(
|
||||
View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
|
||||
window.setStatusBarColor(Color.TRANSPARENT);
|
||||
}
|
||||
|
||||
public static String getIpAddress(boolean useIPv4) {
|
||||
try {
|
||||
List<NetworkInterface> interfaces =
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue