v2.0.00
This commit is contained in:
parent
a8dfe106bb
commit
3d7ba2afc6
193 changed files with 3667 additions and 2662 deletions
|
@ -0,0 +1,123 @@
|
|||
package code.name.monkey.retromusic.util;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.support.v4.media.MediaBrowserCompat;
|
||||
import android.support.v4.media.MediaMetadataCompat;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import code.name.monkey.retromusic.BuildConfig;
|
||||
|
||||
public class MusicLibrary {
|
||||
private static final TreeMap<String, MediaMetadataCompat> music = new TreeMap<>();
|
||||
private static final HashMap<String, Integer> albumRes = new HashMap<>();
|
||||
private static final HashMap<String, Integer> musicRes = new HashMap<>();
|
||||
|
||||
public static String getRoot() {
|
||||
return "root";
|
||||
}
|
||||
|
||||
public static String getSongUri(String mediaId) {
|
||||
return "android.resource://" + BuildConfig.APPLICATION_ID + "/" + getMusicRes(mediaId);
|
||||
}
|
||||
|
||||
private static String getAlbumArtUri(String albumArtResName) {
|
||||
return "android.resource://" + BuildConfig.APPLICATION_ID + "/drawable/" + albumArtResName;
|
||||
}
|
||||
|
||||
private static int getMusicRes(String mediaId) {
|
||||
return musicRes.containsKey(mediaId) ? musicRes.get(mediaId) : 0;
|
||||
}
|
||||
|
||||
private static int getAlbumRes(String mediaId) {
|
||||
return albumRes.containsKey(mediaId) ? albumRes.get(mediaId) : 0;
|
||||
}
|
||||
|
||||
public static Bitmap getAlbumBitmap(Context ctx, String mediaId) {
|
||||
return BitmapFactory.decodeResource(ctx.getResources(), MusicLibrary.getAlbumRes(mediaId));
|
||||
}
|
||||
|
||||
public static List<MediaBrowserCompat.MediaItem> getMediaItems() {
|
||||
List<MediaBrowserCompat.MediaItem> result = new ArrayList<>();
|
||||
for (MediaMetadataCompat metadata : music.values()) {
|
||||
result.add(
|
||||
new MediaBrowserCompat.MediaItem(
|
||||
metadata.getDescription(), MediaBrowserCompat.MediaItem.FLAG_PLAYABLE));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static String getPreviousSong(String currentMediaId) {
|
||||
String prevMediaId = music.lowerKey(currentMediaId);
|
||||
if (prevMediaId == null) {
|
||||
prevMediaId = music.firstKey();
|
||||
}
|
||||
return prevMediaId;
|
||||
}
|
||||
|
||||
public static String getNextSong(String currentMediaId) {
|
||||
String nextMediaId = music.higherKey(currentMediaId);
|
||||
if (nextMediaId == null) {
|
||||
nextMediaId = music.firstKey();
|
||||
}
|
||||
return nextMediaId;
|
||||
}
|
||||
|
||||
public static MediaMetadataCompat getMetadata(Context ctx, String mediaId) {
|
||||
MediaMetadataCompat metadataWithoutBitmap = music.get(mediaId);
|
||||
Bitmap albumArt = getAlbumBitmap(ctx, mediaId);
|
||||
|
||||
// Since MediaMetadataCompat is immutable, we need to create a copy to set the album art.
|
||||
// We don't set it initially on all items so that they don't take unnecessary memory.
|
||||
MediaMetadataCompat.Builder builder = new MediaMetadataCompat.Builder();
|
||||
for (String key :
|
||||
new String[]{
|
||||
MediaMetadataCompat.METADATA_KEY_MEDIA_ID,
|
||||
MediaMetadataCompat.METADATA_KEY_ALBUM,
|
||||
MediaMetadataCompat.METADATA_KEY_ARTIST,
|
||||
MediaMetadataCompat.METADATA_KEY_GENRE,
|
||||
MediaMetadataCompat.METADATA_KEY_TITLE
|
||||
}) {
|
||||
builder.putString(key, metadataWithoutBitmap.getString(key));
|
||||
}
|
||||
builder.putLong(
|
||||
MediaMetadataCompat.METADATA_KEY_DURATION,
|
||||
metadataWithoutBitmap.getLong(MediaMetadataCompat.METADATA_KEY_DURATION));
|
||||
builder.putBitmap(MediaMetadataCompat.METADATA_KEY_ALBUM_ART, albumArt);
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
private static void createMediaMetadataCompat(
|
||||
String mediaId,
|
||||
String title,
|
||||
String artist,
|
||||
String album,
|
||||
String genre,
|
||||
long duration,
|
||||
int musicResId,
|
||||
int albumArtResId,
|
||||
String albumArtResName) {
|
||||
music.put(mediaId,
|
||||
new MediaMetadataCompat.Builder()
|
||||
.putString(MediaMetadataCompat.METADATA_KEY_MEDIA_ID, mediaId)
|
||||
.putString(MediaMetadataCompat.METADATA_KEY_ALBUM, album)
|
||||
.putString(MediaMetadataCompat.METADATA_KEY_ARTIST, artist)
|
||||
.putLong(MediaMetadataCompat.METADATA_KEY_DURATION, duration * 1000)
|
||||
.putString(MediaMetadataCompat.METADATA_KEY_GENRE, genre)
|
||||
.putString(
|
||||
MediaMetadataCompat.METADATA_KEY_ALBUM_ART_URI,
|
||||
getAlbumArtUri(albumArtResName))
|
||||
.putString(
|
||||
MediaMetadataCompat.METADATA_KEY_DISPLAY_ICON_URI,
|
||||
getAlbumArtUri(albumArtResName))
|
||||
.putString(MediaMetadataCompat.METADATA_KEY_TITLE, title)
|
||||
.build());
|
||||
albumRes.put(mediaId, albumArtResId);
|
||||
musicRes.put(mediaId, musicResId);
|
||||
}
|
||||
}
|
|
@ -7,6 +7,7 @@ import android.content.SharedPreferences.Editor;
|
|||
import android.content.res.TypedArray;
|
||||
import android.preference.PreferenceManager;
|
||||
|
||||
import com.google.android.material.bottomnavigation.LabelVisibilityMode;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonSyntaxException;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
|
@ -14,14 +15,18 @@ import com.google.gson.reflect.TypeToken;
|
|||
import java.io.File;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Objects;
|
||||
|
||||
import androidx.annotation.LayoutRes;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.StyleRes;
|
||||
import androidx.viewpager.widget.ViewPager;
|
||||
import code.name.monkey.retromusic.R;
|
||||
import code.name.monkey.retromusic.RetroApplication;
|
||||
import code.name.monkey.retromusic.helper.SortOrder;
|
||||
import code.name.monkey.retromusic.model.CategoryInfo;
|
||||
import code.name.monkey.retromusic.transform.CascadingPageTransformer;
|
||||
import code.name.monkey.retromusic.transform.NormalPageTransformer;
|
||||
import code.name.monkey.retromusic.ui.activities.MainActivity;
|
||||
import code.name.monkey.retromusic.ui.fragments.AlbumCoverStyle;
|
||||
import code.name.monkey.retromusic.ui.fragments.NowPlayingScreen;
|
||||
|
@ -53,9 +58,12 @@ public final class PreferenceUtil {
|
|||
public static final String ADAPTIVE_COLOR_APP = "adaptive_color_app";
|
||||
public static final String TOGGLE_SEPARATE_LINE = "toggle_separate_line";
|
||||
public static final String ALBUM_GRID_STYLE = "album_grid_style";
|
||||
public static final String HOME_ARTIST_GRID_STYLE = "home_artist_grid_style";
|
||||
public static final String ARTIST_GRID_STYLE = "artist_grid_style";
|
||||
public static final String TOGGLE_ADD_CONTROLS = "toggle_add_controls";
|
||||
public static final String ALBUM_COVER_STYLE = "album_cover_style";
|
||||
public static final String ALBUM_COVER_TRANSFORM = "album_cover_transform";
|
||||
public static final String TAB_TEXT_MODE = "tab_text_mode";
|
||||
private static final String GENRE_SORT_ORDER = "genre_sort_order";
|
||||
private static final String LIBRARY_CATEGORIES = "library_categories";
|
||||
private static final String LAST_PAGE = "last_start_page";
|
||||
|
@ -93,13 +101,10 @@ public final class PreferenceUtil {
|
|||
private static final String ALBUM_DETAIL_SONG_SORT_ORDER = "album_detail_song_sort_order";
|
||||
private static final String ARTIST_DETAIL_SONG_SORT_ORDER = "artist_detail_song_sort_order";
|
||||
private static final String LYRICS_OPTIONS = "lyrics_options";
|
||||
private static final String SAF_SDCARD_URI = "saf_sdcard_uri";
|
||||
private static final String DOCUMENT_TREE_URI = "document_tree_uri";
|
||||
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 TOGGLE_ANIMATIONS = "toggle_animations";
|
||||
private static final String TAG = "PreferenceUtil";
|
||||
private static final String LAST_KNOWN_LYRICS_TYPE = "LAST_KNOWN_LYRICS_TYPE";
|
||||
private static PreferenceUtil sInstance;
|
||||
private final SharedPreferences mPreferences;
|
||||
|
@ -705,12 +710,21 @@ public final class PreferenceUtil {
|
|||
return layoutRes;
|
||||
}
|
||||
|
||||
public void setAlbumGridStyle(int type) {
|
||||
mPreferences.edit().putInt(ALBUM_GRID_STYLE, type).apply();
|
||||
@LayoutRes
|
||||
public int getHomeGridStyle(Context context) {
|
||||
int pos = Integer.parseInt(mPreferences.getString(HOME_ARTIST_GRID_STYLE, "0"));
|
||||
TypedArray typedArray = context.getResources().obtainTypedArray(R.array.pref_home_grid_style_layout);
|
||||
int layoutRes = typedArray.getResourceId(pos, -1);
|
||||
typedArray.recycle();
|
||||
if (layoutRes == -1) {
|
||||
return R.layout.item_artist;
|
||||
}
|
||||
return layoutRes;
|
||||
}
|
||||
|
||||
|
||||
public int getArtistGridStyle(Context context) {
|
||||
int pos = Integer.parseInt(mPreferences.getString(ARTIST_GRID_STYLE, "0"));
|
||||
int pos = Integer.parseInt(Objects.requireNonNull(mPreferences.getString(ARTIST_GRID_STYLE, "0")));
|
||||
TypedArray typedArray = context.getResources().obtainTypedArray(R.array.pref_grid_style_layout);
|
||||
int layoutRes = typedArray.getResourceId(pos, -1);
|
||||
typedArray.recycle();
|
||||
|
@ -741,4 +755,30 @@ public final class PreferenceUtil {
|
|||
}
|
||||
|
||||
|
||||
public ViewPager.PageTransformer getAlbumCoverTransform(Context context) {
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
@LabelVisibilityMode
|
||||
public int getTabTitleMode() {
|
||||
int mode = Integer.parseInt(mPreferences.getString(TAB_TEXT_MODE, "1"));
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,12 +19,6 @@ import android.os.Build;
|
|||
import android.os.ResultReceiver;
|
||||
import android.provider.BaseColumns;
|
||||
import android.provider.MediaStore;
|
||||
import androidx.annotation.ColorInt;
|
||||
import androidx.annotation.DrawableRes;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.vectordrawable.graphics.drawable.VectorDrawableCompat;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.view.Display;
|
||||
import android.view.View;
|
||||
|
@ -40,6 +34,12 @@ import java.net.NetworkInterface;
|
|||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import androidx.annotation.ColorInt;
|
||||
import androidx.annotation.DrawableRes;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.vectordrawable.graphics.drawable.VectorDrawableCompat;
|
||||
import code.name.monkey.appthemehelper.ThemeStore;
|
||||
import code.name.monkey.appthemehelper.util.TintHelper;
|
||||
import code.name.monkey.retromusic.RetroApplication;
|
||||
|
@ -55,8 +55,7 @@ public class RetroUtil {
|
|||
}
|
||||
|
||||
public static Uri getAlbumArtUri(long paramInt) {
|
||||
return ContentUris
|
||||
.withAppendedId(Uri.parse("content://media/external/audio/albumart"), paramInt);
|
||||
return ContentUris.withAppendedId(Uri.parse("content://media/external/audio/albumart"), paramInt);
|
||||
}
|
||||
|
||||
public static String EncodeString(String string) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue