- Connect ListenBrainz with a user token (checked), disconnect, send now - Listens carry MusicBrainz ids, ISRC, disc, tags, release artist read from the file - Last.fm: dead sessions sign out and keep the queue; rejected data is dropped; >14-day-old scrobbles dropped; recording MBID sent - Each service flushes on its own Co-Authored-By: Claude Opus 5.5 <[email protected]>
2196 lines
103 KiB
Java
2196 lines
103 KiB
Java
package com.mulberry.player;
|
||
|
||
import android.app.Activity;
|
||
import android.app.Dialog;
|
||
import android.content.ComponentName;
|
||
import android.content.DialogInterface;
|
||
import android.content.Intent;
|
||
import android.content.ServiceConnection;
|
||
import android.content.res.ColorStateList;
|
||
import android.content.res.Configuration;
|
||
import android.graphics.Typeface;
|
||
import android.graphics.drawable.ColorDrawable;
|
||
import android.graphics.drawable.Drawable;
|
||
import android.graphics.drawable.GradientDrawable;
|
||
import android.media.MediaMetadataRetriever;
|
||
import android.net.Uri;
|
||
import android.os.Build;
|
||
import android.os.Bundle;
|
||
import android.os.IBinder;
|
||
import android.os.PowerManager;
|
||
import android.text.Editable;
|
||
import android.text.TextWatcher;
|
||
import android.view.GestureDetector;
|
||
import android.view.MotionEvent;
|
||
import android.view.View;
|
||
import android.view.Window;
|
||
import android.view.WindowInsets;
|
||
import android.view.animation.PathInterpolator;
|
||
import android.widget.CheckBox;
|
||
import android.widget.EditText;
|
||
import android.widget.FrameLayout;
|
||
import android.widget.HorizontalScrollView;
|
||
import android.widget.ImageView;
|
||
import android.widget.LinearLayout;
|
||
import android.widget.ListAdapter;
|
||
import android.widget.ListView;
|
||
import android.widget.RadioButton;
|
||
import android.widget.RadioGroup;
|
||
import android.widget.ScrollView;
|
||
import android.widget.TextView;
|
||
import android.widget.Toast;
|
||
import java.util.ArrayList;
|
||
import java.util.Collections;
|
||
import java.util.Comparator;
|
||
import java.util.Iterator;
|
||
import java.util.List;
|
||
import java.util.Locale;
|
||
import org.jaudiotagger.tag.id3.framebody.FrameBodyCOMM;
|
||
|
||
/* JADX INFO: loaded from: classes.dex */
|
||
public class MainActivity extends Activity implements MusicService.Listener, Library.Listener, Playlists.Listener {
|
||
static MainActivity CURRENT = null;
|
||
static final int REQ_EXPORT_ALL = 12;
|
||
static final int REQ_EXPORT_ONE = 11;
|
||
static final int REQ_IMPORT = 10;
|
||
static final int REQ_PERMS = 1;
|
||
static final int REQ_TAGS = 20;
|
||
BassShapeView bassShape;
|
||
View bottomBar;
|
||
TextView emptyMsg;
|
||
Playlists.PL exportPl;
|
||
Lists.GroupAdapter groupAdapter;
|
||
int insetBottom;
|
||
int insetTop;
|
||
ListView libList;
|
||
int libTab;
|
||
View libraryPage;
|
||
int listBottom;
|
||
LinearLayout mini;
|
||
TextView miniArtist;
|
||
CookieView miniCookie;
|
||
PlayButton miniPlay;
|
||
WavySeekBar miniSeek;
|
||
TextView miniTitle;
|
||
LinearLayout nav;
|
||
FrameLayout pages;
|
||
Runnable pendingPlay;
|
||
LinearLayout plBox;
|
||
NowPlaying player;
|
||
View playlistsPage;
|
||
FrameLayout root;
|
||
EditText search;
|
||
SettingsPage settingsPage;
|
||
Lists.SongAdapter songAdapter;
|
||
MusicService svc;
|
||
LinearLayout tabs;
|
||
final List<View> stack = new ArrayList();
|
||
int page = 0;
|
||
String sortMode = "title";
|
||
String exportFmt = "m3u8";
|
||
boolean exportReplace = true;
|
||
final List<View> navItems = new ArrayList();
|
||
final ServiceConnection conn = new ServiceConnection() { // from class: com.mulberry.player.MainActivity.1
|
||
@Override // android.content.ServiceConnection
|
||
public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
|
||
MainActivity.this.svc = ((MusicService.LocalBinder) iBinder).service();
|
||
MainActivity.this.svc.addListener(MainActivity.this);
|
||
MainActivity.this.player.bindService(MainActivity.this.svc);
|
||
MainActivity.this.miniCookie.setService(MainActivity.this.svc);
|
||
MainActivity.this.bassShape.setService(MainActivity.this.svc);
|
||
MainActivity.this.onTrackChanged();
|
||
MainActivity.this.onQueueChanged();
|
||
if (MainActivity.this.pendingPlay != null) {
|
||
Runnable runnable = MainActivity.this.pendingPlay;
|
||
MainActivity.this.pendingPlay = null;
|
||
runnable.run();
|
||
}
|
||
}
|
||
|
||
@Override // android.content.ServiceConnection
|
||
public void onServiceDisconnected(ComponentName componentName) {
|
||
MainActivity.this.svc = null;
|
||
}
|
||
};
|
||
final Runnable uiTick = new Runnable() { // from class: com.mulberry.player.MainActivity.2
|
||
@Override // java.lang.Runnable
|
||
public void run() {
|
||
if (MainActivity.this.svc != null) {
|
||
if (MainActivity.this.player.open) {
|
||
MainActivity.this.player.tick();
|
||
}
|
||
if (MainActivity.this.mini.getVisibility() == 0) {
|
||
MainActivity.this.miniSeek.set(MainActivity.this.svc.position(), MainActivity.this.svc.duration());
|
||
}
|
||
}
|
||
App.MAIN.postDelayed(this, 500L);
|
||
}
|
||
};
|
||
final Runnable searchTask = new Runnable() { // from class: com.mulberry.player.MainActivity.21
|
||
@Override // java.lang.Runnable
|
||
public void run() {
|
||
MainActivity.this.fillLibrary();
|
||
}
|
||
};
|
||
final Lists.SongClick songClick = new Lists.SongClick() { // from class: com.mulberry.player.MainActivity.29
|
||
@Override // com.mulberry.player.Lists.SongClick
|
||
public void click(List<Song> list, final int i) {
|
||
final ArrayList arrayList = new ArrayList(list);
|
||
MainActivity.this.withService(new Runnable() { // from class: com.mulberry.player.MainActivity.29.1
|
||
@Override // java.lang.Runnable
|
||
public void run() {
|
||
MainActivity.this.svc.playList(arrayList, i);
|
||
}
|
||
});
|
||
}
|
||
|
||
@Override // com.mulberry.player.Lists.SongClick
|
||
public void longClick(List<Song> list, int i, View view) {
|
||
MainActivity.this.songMenu(list.get(i), null, -1);
|
||
}
|
||
};
|
||
final Lists.GroupClick groupClick = new Lists.GroupClick() { // from class: com.mulberry.player.MainActivity.30
|
||
@Override // com.mulberry.player.Lists.GroupClick
|
||
public void click(Library.Group group) {
|
||
MainActivity.this.openGroup(group.title, group.subtitle, group.songs, MainActivity.this.libTab == 1, null);
|
||
}
|
||
|
||
@Override // com.mulberry.player.Lists.GroupClick
|
||
public void longClick(Library.Group group) {
|
||
MainActivity.this.groupMenu(group.title, group.songs);
|
||
}
|
||
};
|
||
|
||
interface TextCb {
|
||
void ok(String str);
|
||
}
|
||
|
||
@Override // android.app.Activity
|
||
protected void onCreate(Bundle bundle) {
|
||
int i;
|
||
super.onCreate(bundle);
|
||
CURRENT = this;
|
||
Window window = getWindow();
|
||
window.setStatusBarColor(0);
|
||
window.setNavigationBarColor(0);
|
||
View decorView = window.getDecorView();
|
||
if (App.I.palette.dark) {
|
||
i = 0;
|
||
} else {
|
||
i = (Build.VERSION.SDK_INT >= 26 ? 16 : 0) | 8192 /* SYSTEM_UI_FLAG_LIGHT_STATUS_BAR */;
|
||
}
|
||
decorView.setSystemUiVisibility(i | 1792);
|
||
this.libTab = App.I.prefs.getInt(Prefs.LIB_TAB, 0);
|
||
build();
|
||
App.I.library.addListener(this);
|
||
Playlists.addListener(this);
|
||
bindService(new Intent(this, (Class<?>) MusicService.class), this.conn, 1);
|
||
if (App.I.library.loaded) {
|
||
fillLibrary();
|
||
}
|
||
if (hasAudioPermission()) {
|
||
startLibrary();
|
||
} else {
|
||
requestPerms();
|
||
}
|
||
handleIntent(getIntent());
|
||
}
|
||
|
||
@Override // android.app.Activity
|
||
protected void onNewIntent(Intent intent) {
|
||
super.onNewIntent(intent);
|
||
setIntent(intent);
|
||
handleIntent(intent);
|
||
}
|
||
|
||
@Override // android.app.Activity
|
||
protected void onResume() {
|
||
super.onResume();
|
||
App.MAIN.removeCallbacks(this.uiTick);
|
||
App.MAIN.post(this.uiTick);
|
||
if (this.settingsPage == null || this.page != 2 || !this.stack.isEmpty()) {
|
||
return;
|
||
}
|
||
this.settingsPage.refresh();
|
||
}
|
||
|
||
@Override // android.app.Activity
|
||
protected void onPause() {
|
||
super.onPause();
|
||
App.MAIN.removeCallbacks(this.uiTick);
|
||
}
|
||
|
||
@Override // android.app.Activity
|
||
protected void onDestroy() {
|
||
App.I.library.removeListener(this);
|
||
Playlists.removeListener(this);
|
||
if (this.svc != null) {
|
||
this.svc.removeListener(this);
|
||
}
|
||
try {
|
||
unbindService(this.conn);
|
||
} catch (Exception e) {
|
||
}
|
||
if (CURRENT == this) {
|
||
CURRENT = null;
|
||
}
|
||
super.onDestroy();
|
||
}
|
||
|
||
@Override // android.app.Activity, android.content.ComponentCallbacks
|
||
public void onConfigurationChanged(Configuration configuration) {
|
||
super.onConfigurationChanged(configuration);
|
||
Palette palette = App.I.palette;
|
||
Integer numDominant = null;
|
||
if (this.svc != null && this.svc.art() != null && "album".equals(App.I.prefs.getStr(Prefs.COLOR_SOURCE, "system"))) {
|
||
numDominant = Palette.dominant(this.svc.art());
|
||
}
|
||
App.I.palette = Palette.build(this, numDominant);
|
||
if (palette.dark == App.I.palette.dark) {
|
||
Ui.recolor();
|
||
} else {
|
||
recreate();
|
||
}
|
||
}
|
||
|
||
void withService(Runnable runnable) {
|
||
MusicService.ensureStarted(this);
|
||
if (this.svc == null) {
|
||
this.pendingPlay = runnable;
|
||
} else {
|
||
runnable.run();
|
||
}
|
||
}
|
||
|
||
public static void toast(final String str) {
|
||
App.ui(new Runnable() { // from class: com.mulberry.player.MainActivity.3
|
||
@Override // java.lang.Runnable
|
||
public void run() {
|
||
Toast.makeText(App.I, str, 0).show();
|
||
}
|
||
});
|
||
}
|
||
|
||
boolean hasAudioPermission() {
|
||
return checkSelfPermission(Build.VERSION.SDK_INT >= 33 ? "android.permission.READ_MEDIA_AUDIO" : "android.permission.READ_EXTERNAL_STORAGE") == 0;
|
||
}
|
||
|
||
void requestPerms() {
|
||
ArrayList arrayList = new ArrayList();
|
||
if (Build.VERSION.SDK_INT >= 33) {
|
||
arrayList.add("android.permission.READ_MEDIA_AUDIO");
|
||
arrayList.add("android.permission.POST_NOTIFICATIONS");
|
||
} else {
|
||
arrayList.add("android.permission.READ_EXTERNAL_STORAGE");
|
||
if (Build.VERSION.SDK_INT <= 28) {
|
||
arrayList.add("android.permission.WRITE_EXTERNAL_STORAGE");
|
||
}
|
||
}
|
||
requestPermissions((String[]) arrayList.toArray(new String[0]), 1);
|
||
}
|
||
|
||
@Override // android.app.Activity
|
||
public void onRequestPermissionsResult(int i, String[] strArr, int[] iArr) {
|
||
if (i == 1) {
|
||
if (hasAudioPermission()) {
|
||
startLibrary();
|
||
maybeAskBattery();
|
||
} else {
|
||
this.emptyMsg.setText("Mulberry needs access to your music.\nTap here to allow it.");
|
||
this.emptyMsg.setVisibility(0);
|
||
}
|
||
}
|
||
}
|
||
|
||
void startLibrary() {
|
||
App.I.library.startObserving();
|
||
App.I.library.refresh();
|
||
this.emptyMsg.setText("Scanning your music…");
|
||
}
|
||
|
||
void maybeAskBattery() {
|
||
if (!App.I.prefs.getBool("asked_battery", false)) {
|
||
App.I.prefs.setBool("asked_battery", true);
|
||
PowerManager powerManager = (PowerManager) getSystemService("power");
|
||
if (powerManager != null && !powerManager.isIgnoringBatteryOptimizations(getPackageName())) {
|
||
Ui.show(Ui.dialog(this).setTitle("Keep playing in the background?").setMessage("Some phones stop music apps in the background to save battery. Allow Mulberry to run unrestricted so playback, the notification and widgets keep working.").setPositiveButton("Allow", new DialogInterface.OnClickListener() { // from class: com.mulberry.player.MainActivity.4
|
||
@Override // android.content.DialogInterface.OnClickListener
|
||
public void onClick(DialogInterface dialogInterface, int i) {
|
||
MainActivity.this.requestBatteryExemption();
|
||
}
|
||
}).setNegativeButton("Not now", (DialogInterface.OnClickListener) null));
|
||
}
|
||
}
|
||
}
|
||
|
||
void requestBatteryExemption() {
|
||
try {
|
||
startActivity(new Intent("android.settings.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS", Uri.parse("package:" + getPackageName())));
|
||
} catch (Exception e) {
|
||
try {
|
||
startActivity(new Intent("android.settings.IGNORE_BATTERY_OPTIMIZATION_SETTINGS"));
|
||
} catch (Exception e2) {
|
||
}
|
||
}
|
||
}
|
||
|
||
void requestAllFiles() {
|
||
if (Build.VERSION.SDK_INT >= 30) {
|
||
try {
|
||
startActivity(new Intent("android.settings.MANAGE_APP_ALL_FILES_ACCESS_PERMISSION", Uri.parse("package:" + getPackageName())));
|
||
return;
|
||
} catch (Exception e) {
|
||
try {
|
||
startActivity(new Intent("android.settings.MANAGE_ALL_FILES_ACCESS_PERMISSION"));
|
||
return;
|
||
} catch (Exception e2) {
|
||
return;
|
||
}
|
||
}
|
||
}
|
||
requestPerms();
|
||
}
|
||
|
||
void build() {
|
||
this.root = new FrameLayout(this);
|
||
Ui.plain(this.root, 6);
|
||
this.pages = new FrameLayout(this);
|
||
this.root.addView(this.pages, new FrameLayout.LayoutParams(-1, -1));
|
||
this.libraryPage = buildLibrary();
|
||
this.playlistsPage = buildPlaylists();
|
||
this.settingsPage = new SettingsPage(this);
|
||
this.pages.addView(this.libraryPage);
|
||
this.pages.addView(this.playlistsPage);
|
||
this.pages.addView(this.settingsPage);
|
||
LinearLayout linearLayoutCol = Ui.col(this);
|
||
this.mini = buildMini();
|
||
linearLayoutCol.addView(this.mini);
|
||
this.nav = buildNav();
|
||
linearLayoutCol.addView(this.nav);
|
||
this.root.addView(linearLayoutCol, Ui.flp(-1, -2, 80));
|
||
this.bottomBar = linearLayoutCol;
|
||
linearLayoutCol.addOnLayoutChangeListener(new View.OnLayoutChangeListener() { // from class: com.mulberry.player.MainActivity.5
|
||
@Override // android.view.View.OnLayoutChangeListener
|
||
public void onLayoutChange(View view, int i, int i2, int i3, int i4, int i5, int i6, int i7, int i8) {
|
||
if (i2 != i6 || i4 != i8) {
|
||
int i9 = i4 - i2;
|
||
MainActivity.this.setListBottom(Ui.dp(MainActivity.this, 12.0f) + i9);
|
||
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) MainActivity.this.bassShape.getLayoutParams();
|
||
layoutParams.bottomMargin = i9 + Ui.dp(MainActivity.this, 8.0f);
|
||
layoutParams.leftMargin = Ui.dp(MainActivity.this, 14.0f);
|
||
MainActivity.this.bassShape.setLayoutParams(layoutParams);
|
||
}
|
||
}
|
||
});
|
||
this.bassShape = new BassShapeView(this);
|
||
this.bassShape.setOnClickListener(new View.OnClickListener() { // from class: com.mulberry.player.MainActivity.6
|
||
@Override // android.view.View.OnClickListener
|
||
public void onClick(View view) {
|
||
MainActivity.this.openPlayer();
|
||
}
|
||
});
|
||
this.root.addView(this.bassShape, Ui.flp(Ui.dp(this, 64.0f), Ui.dp(this, 64.0f), 8388691));
|
||
this.player = new NowPlaying(this);
|
||
this.player.setVisibility(8);
|
||
this.root.addView(this.player, new FrameLayout.LayoutParams(-1, -1));
|
||
this.root.setOnApplyWindowInsetsListener(new View.OnApplyWindowInsetsListener() { // from class: com.mulberry.player.MainActivity.7
|
||
@Override // android.view.View.OnApplyWindowInsetsListener
|
||
public WindowInsets onApplyWindowInsets(View view, WindowInsets windowInsets) {
|
||
MainActivity.this.insetTop = windowInsets.getSystemWindowInsetTop();
|
||
MainActivity.this.insetBottom = windowInsets.getSystemWindowInsetBottom();
|
||
MainActivity.this.applyInsets();
|
||
return windowInsets.consumeSystemWindowInsets();
|
||
}
|
||
});
|
||
setContentView(this.root);
|
||
showPage(0, false);
|
||
updateBassShape();
|
||
}
|
||
|
||
void applyInsets() {
|
||
this.nav.setPadding(0, Ui.dp(this, 8.0f), 0, Ui.dp(this, 8.0f) + this.insetBottom);
|
||
this.player.setPadding(0, this.insetTop, 0, this.insetBottom);
|
||
for (int i = 0; i < this.pages.getChildCount(); i++) {
|
||
this.pages.getChildAt(i).setPadding(0, this.insetTop, 0, 0);
|
||
}
|
||
Iterator<View> it = this.stack.iterator();
|
||
while (it.hasNext()) {
|
||
it.next().setPadding(0, this.insetTop, 0, 0);
|
||
}
|
||
}
|
||
|
||
void setListBottom(int i) {
|
||
this.listBottom = i;
|
||
if (this.libList != null) {
|
||
this.libList.setPadding(this.libList.getPaddingLeft(), this.libList.getPaddingTop(), this.libList.getPaddingRight(), i);
|
||
}
|
||
if (this.plBox != null) {
|
||
this.plBox.setPadding(this.plBox.getPaddingLeft(), this.plBox.getPaddingTop(), this.plBox.getPaddingRight(), i);
|
||
}
|
||
this.settingsPage.setBottomPad(i);
|
||
Iterator<View> it = this.stack.iterator();
|
||
while (it.hasNext()) {
|
||
ListView listView = (ListView) it.next().findViewWithTag("list");
|
||
if (listView != null) {
|
||
listView.setPadding(0, listView.getPaddingTop(), 0, i);
|
||
}
|
||
}
|
||
}
|
||
|
||
void updateBassShape() {
|
||
this.bassShape.setVisibility(App.I.prefs.getBool(Prefs.BASS_SHAPE, false) && Spectrum.enabled() ? 0 : 8);
|
||
}
|
||
|
||
LinearLayout buildNav() {
|
||
LinearLayout linearLayoutRow = Ui.row(this);
|
||
Ui.plain(linearLayoutRow, 8);
|
||
String[] strArr = {"Library", "Playlists", "Settings"};
|
||
int[] iArr = {R.drawable.ic_library_music, R.drawable.ic_queue_music, R.drawable.ic_settings};
|
||
for (int i0 = 0; i0 < 3; i0++) {
|
||
final int i = i0;
|
||
LinearLayout linearLayoutCol = Ui.col(this);
|
||
linearLayoutCol.setGravity(17);
|
||
FrameLayout frameLayout = new FrameLayout(this);
|
||
frameLayout.addView(Ui.icon(this, iArr[i], 12, 24), Ui.flp(Ui.dp(this, 24.0f), Ui.dp(this, 24.0f), 17));
|
||
linearLayoutCol.addView(frameLayout, new LinearLayout.LayoutParams(Ui.dp(this, 64.0f), Ui.dp(this, 32.0f)));
|
||
TextView textViewSingle = Ui.single(this, strArr[i], 12.0f, 12, true);
|
||
textViewSingle.setPadding(0, Ui.dp(this, 4.0f), 0, 0);
|
||
textViewSingle.setGravity(17);
|
||
linearLayoutCol.addView(textViewSingle, new LinearLayout.LayoutParams(-2, -2));
|
||
linearLayoutCol.setOnClickListener(new View.OnClickListener() { // from class: com.mulberry.player.MainActivity.8
|
||
@Override // android.view.View.OnClickListener
|
||
public void onClick(View view) {
|
||
MainActivity.this.showPage(i, true);
|
||
}
|
||
});
|
||
linearLayoutRow.addView(linearLayoutCol, Ui.lpw(-2, 1.0f));
|
||
this.navItems.add(linearLayoutCol);
|
||
}
|
||
return linearLayoutRow;
|
||
}
|
||
|
||
void styleNav() {
|
||
int i = 0;
|
||
while (i < this.navItems.size()) {
|
||
LinearLayout linearLayout = (LinearLayout) this.navItems.get(i);
|
||
FrameLayout frameLayout = (FrameLayout) linearLayout.getChildAt(0);
|
||
ImageView imageView = (ImageView) frameLayout.getChildAt(0);
|
||
TextView textView = (TextView) linearLayout.getChildAt(1);
|
||
boolean z = i == this.page;
|
||
frameLayout.setBackground(z ? Ui.round(Ui.c(4), Ui.dpf(this, 16.0f)) : null);
|
||
imageView.setImageTintList(ColorStateList.valueOf(Ui.c(z ? 5 : 12)));
|
||
textView.setTextColor(Ui.c(z ? 11 : 12));
|
||
if (z && !App.lowPower()) {
|
||
frameLayout.setScaleX(0.6f);
|
||
frameLayout.animate().scaleX(1.0f).setDuration(260L).setInterpolator(new PathInterpolator(0.2f, 0.0f, 0.0f, 1.0f)).start();
|
||
}
|
||
i++;
|
||
}
|
||
}
|
||
|
||
void showPage(int i, boolean z) {
|
||
while (!this.stack.isEmpty()) {
|
||
popDetail(false);
|
||
}
|
||
this.page = i;
|
||
View[] viewArr = {this.libraryPage, this.playlistsPage, this.settingsPage};
|
||
for (int i2 = 0; i2 < viewArr.length; i2++) {
|
||
View view = viewArr[i2];
|
||
if (i2 == i) {
|
||
view.setVisibility(0);
|
||
if (z && !App.lowPower()) {
|
||
view.setAlpha(0.0f);
|
||
view.setTranslationY(Ui.dp(this, 16.0f));
|
||
view.animate().alpha(1.0f).translationY(0.0f).setDuration(220L).setInterpolator(new PathInterpolator(0.2f, 0.0f, 0.0f, 1.0f)).start();
|
||
}
|
||
} else {
|
||
view.setVisibility(8);
|
||
}
|
||
}
|
||
if (i == 1) {
|
||
rebuildPlaylists();
|
||
}
|
||
if (i == 2) {
|
||
this.settingsPage.refresh();
|
||
}
|
||
styleNav();
|
||
}
|
||
|
||
LinearLayout buildMini() {
|
||
final LinearLayout linearLayoutCol = Ui.col(this);
|
||
linearLayoutCol.setPadding(Ui.dp(this, 8.0f), Ui.dp(this, 8.0f), Ui.dp(this, 10.0f), Ui.dp(this, 2.0f));
|
||
Ui.themed(linearLayoutCol, new Ui.Paint() { // from class: com.mulberry.player.MainActivity.9
|
||
@Override // com.mulberry.player.Ui.Paint
|
||
public void apply() {
|
||
GradientDrawable gradientDrawable = new GradientDrawable(GradientDrawable.Orientation.LEFT_RIGHT, new int[]{Palette.mixC(Ui.c(9), Ui.c(2), 0.45f), Ui.c(9)});
|
||
gradientDrawable.setCornerRadius(Ui.dpf(MainActivity.this, 30.0f));
|
||
linearLayoutCol.setBackground(Ui.ripple(gradientDrawable, Ui.c(11), Ui.round(-1, Ui.dpf(MainActivity.this, 30.0f))));
|
||
linearLayoutCol.setElevation(Ui.dpf(MainActivity.this, 6.0f));
|
||
}
|
||
});
|
||
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(-1, -2);
|
||
int iDp = Ui.dp(this, 10.0f);
|
||
layoutParams.rightMargin = iDp;
|
||
layoutParams.leftMargin = iDp;
|
||
layoutParams.bottomMargin = Ui.dp(this, 8.0f);
|
||
linearLayoutCol.setLayoutParams(layoutParams);
|
||
LinearLayout linearLayoutRow = Ui.row(this);
|
||
this.miniCookie = new CookieView(this);
|
||
this.miniCookie.small = true;
|
||
linearLayoutRow.addView(this.miniCookie, new LinearLayout.LayoutParams(Ui.dp(this, 70.0f), Ui.dp(this, 70.0f)));
|
||
LinearLayout linearLayoutCol2 = Ui.col(this);
|
||
linearLayoutCol2.setPadding(Ui.dp(this, 10.0f), 0, Ui.dp(this, 6.0f), 0);
|
||
this.miniTitle = Ui.single(this, FrameBodyCOMM.DEFAULT, 16.5f, 11, true);
|
||
this.miniTitle.setTypeface(Typeface.create("sans-serif", 1));
|
||
this.miniArtist = Ui.single(this, FrameBodyCOMM.DEFAULT, 13.5f, 0, true);
|
||
linearLayoutCol2.addView(this.miniTitle);
|
||
linearLayoutCol2.addView(this.miniArtist);
|
||
linearLayoutRow.addView(linearLayoutCol2, Ui.lpw(-2, 1.0f));
|
||
this.miniPlay = new PlayButton(this);
|
||
this.miniPlay.setOnClickListener(new View.OnClickListener() { // from class: com.mulberry.player.MainActivity.10
|
||
@Override // android.view.View.OnClickListener
|
||
public void onClick(View view) {
|
||
MainActivity.this.togglePlay();
|
||
}
|
||
});
|
||
linearLayoutRow.addView(this.miniPlay, new LinearLayout.LayoutParams(Ui.dp(this, 66.0f), Ui.dp(this, 50.0f)));
|
||
linearLayoutRow.addView(Ui.iconButton(this, R.drawable.ic_skip_next_fill, 11, 46, new View.OnClickListener() { // from class: com.mulberry.player.MainActivity.11
|
||
@Override // android.view.View.OnClickListener
|
||
public void onClick(View view) {
|
||
if (MainActivity.this.svc != null) {
|
||
MainActivity.this.svc.next();
|
||
}
|
||
}
|
||
}));
|
||
linearLayoutCol.addView(linearLayoutRow);
|
||
this.miniSeek = new WavySeekBar(this);
|
||
this.miniSeek.heightDp = 26;
|
||
this.miniSeek.setOnSeek(new WavySeekBar.OnSeek() { // from class: com.mulberry.player.MainActivity.12
|
||
@Override // com.mulberry.player.WavySeekBar.OnSeek
|
||
public void seek(float f) {
|
||
if (MainActivity.this.svc != null) {
|
||
MainActivity.this.svc.seek((long) (MainActivity.this.svc.duration() * f));
|
||
}
|
||
}
|
||
|
||
@Override // com.mulberry.player.WavySeekBar.OnSeek
|
||
public void dragging(float f) {
|
||
}
|
||
});
|
||
linearLayoutCol.addView(this.miniSeek, Ui.lp(-1, -2));
|
||
final GestureDetector gestureDetector = new GestureDetector(this, new GestureDetector.SimpleOnGestureListener() { // from class: com.mulberry.player.MainActivity.13
|
||
@Override // android.view.GestureDetector.SimpleOnGestureListener, android.view.GestureDetector.OnGestureListener
|
||
public boolean onDown(MotionEvent motionEvent) {
|
||
return true;
|
||
}
|
||
|
||
@Override // android.view.GestureDetector.SimpleOnGestureListener, android.view.GestureDetector.OnGestureListener
|
||
public boolean onSingleTapUp(MotionEvent motionEvent) {
|
||
MainActivity.this.openPlayer();
|
||
return true;
|
||
}
|
||
|
||
@Override // android.view.GestureDetector.SimpleOnGestureListener, android.view.GestureDetector.OnGestureListener
|
||
public boolean onFling(MotionEvent motionEvent, MotionEvent motionEvent2, float f, float f2) {
|
||
if (motionEvent == null || MainActivity.this.svc == null) {
|
||
return false;
|
||
}
|
||
float x = motionEvent2.getX() - motionEvent.getX();
|
||
float y = motionEvent2.getY() - motionEvent.getY();
|
||
if (Math.abs(x) <= Math.abs(y) || Math.abs(x) <= Ui.dp(MainActivity.this, 60.0f)) {
|
||
if (y >= (-Ui.dp(MainActivity.this, 40.0f))) {
|
||
return false;
|
||
}
|
||
MainActivity.this.openPlayer();
|
||
return true;
|
||
}
|
||
if (x < 0.0f) {
|
||
MainActivity.this.svc.next();
|
||
} else {
|
||
MainActivity.this.svc.prev();
|
||
}
|
||
if (!App.lowPower()) {
|
||
MainActivity.this.mini.setTranslationX(x < 0.0f ? -Ui.dp(MainActivity.this, 40.0f) : Ui.dp(MainActivity.this, 40.0f));
|
||
MainActivity.this.mini.setAlpha(0.4f);
|
||
MainActivity.this.mini.animate().translationX(0.0f).alpha(1.0f).setDuration(260L).setInterpolator(new PathInterpolator(0.2f, 0.0f, 0.0f, 1.0f)).start();
|
||
}
|
||
return true;
|
||
}
|
||
});
|
||
linearLayoutRow.setOnTouchListener(new View.OnTouchListener() { // from class: com.mulberry.player.MainActivity.14
|
||
@Override // android.view.View.OnTouchListener
|
||
public boolean onTouch(View view, MotionEvent motionEvent) {
|
||
return gestureDetector.onTouchEvent(motionEvent);
|
||
}
|
||
});
|
||
linearLayoutCol.setVisibility(8);
|
||
return linearLayoutCol;
|
||
}
|
||
|
||
View buildLibrary() {
|
||
LinearLayout linearLayoutCol = Ui.col(this);
|
||
LinearLayout linearLayoutRow = Ui.row(this);
|
||
linearLayoutRow.setPadding(Ui.dp(this, 20.0f), Ui.dp(this, 14.0f), Ui.dp(this, 10.0f), Ui.dp(this, 6.0f));
|
||
linearLayoutRow.addView(Ui.title(this, "Library"), Ui.lpw(-2, 1.0f));
|
||
linearLayoutRow.addView(Ui.iconButton(this, R.drawable.ic_sort, 12, 44, new View.OnClickListener() { // from class: com.mulberry.player.MainActivity.15
|
||
@Override // android.view.View.OnClickListener
|
||
public void onClick(View view) {
|
||
MainActivity.this.sortMenu();
|
||
}
|
||
}));
|
||
linearLayoutRow.addView(Ui.pill(this, R.drawable.ic_shuffle, "Shuffle", true, new View.OnClickListener() { // from class: com.mulberry.player.MainActivity.16
|
||
@Override // android.view.View.OnClickListener
|
||
public void onClick(View view) {
|
||
final ArrayList arrayList = new ArrayList(App.I.library.songs);
|
||
if (!arrayList.isEmpty()) {
|
||
MainActivity.this.withService(new Runnable() { // from class: com.mulberry.player.MainActivity.16.1
|
||
@Override // java.lang.Runnable
|
||
public void run() {
|
||
MainActivity.this.svc.playShuffled(arrayList);
|
||
}
|
||
});
|
||
}
|
||
}
|
||
}));
|
||
linearLayoutCol.addView(linearLayoutRow);
|
||
LinearLayout linearLayoutRow2 = Ui.row(this);
|
||
linearLayoutRow2.setPadding(Ui.dp(this, 16.0f), 0, Ui.dp(this, 16.0f), Ui.dp(this, 8.0f));
|
||
this.search = Ui.field(this, "Search songs, artists, albums", FrameBodyCOMM.DEFAULT);
|
||
this.search.setSingleLine(true);
|
||
this.search.setCompoundDrawablePadding(Ui.dp(this, 10.0f));
|
||
this.search.setCompoundDrawablesRelativeWithIntrinsicBounds(tinted(R.drawable.ic_search, 12, 20), (Drawable) null, (Drawable) null, (Drawable) null);
|
||
Ui.themed(this.search, new Ui.Paint() { // from class: com.mulberry.player.MainActivity.17
|
||
@Override // com.mulberry.player.Ui.Paint
|
||
public void apply() {
|
||
MainActivity.this.search.setBackground(Ui.round(Ui.c(9), Ui.dpf(MainActivity.this, 28.0f)));
|
||
}
|
||
});
|
||
this.search.addTextChangedListener(new TextWatcher() { // from class: com.mulberry.player.MainActivity.18
|
||
@Override // android.text.TextWatcher
|
||
public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {
|
||
}
|
||
|
||
@Override // android.text.TextWatcher
|
||
public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
|
||
}
|
||
|
||
@Override // android.text.TextWatcher
|
||
public void afterTextChanged(Editable editable) {
|
||
App.MAIN.removeCallbacks(MainActivity.this.searchTask);
|
||
App.MAIN.postDelayed(MainActivity.this.searchTask, 180L);
|
||
}
|
||
});
|
||
linearLayoutRow2.addView(this.search, Ui.lpw(-2, 1.0f));
|
||
linearLayoutCol.addView(linearLayoutRow2);
|
||
HorizontalScrollView horizontalScrollView = new HorizontalScrollView(this);
|
||
horizontalScrollView.setHorizontalScrollBarEnabled(false);
|
||
this.tabs = Ui.row(this);
|
||
this.tabs.setPadding(Ui.dp(this, 14.0f), 0, Ui.dp(this, 14.0f), Ui.dp(this, 6.0f));
|
||
String[] strArr = {"Songs", "Albums", "Artists", "Folders"};
|
||
for (int i0 = 0; i0 < strArr.length; i0++) {
|
||
final int i = i0;
|
||
TextView textViewSingle = Ui.single(this, strArr[i], 14.0f, 11, true);
|
||
textViewSingle.setPadding(Ui.dp(this, 16.0f), Ui.dp(this, 8.0f), Ui.dp(this, 16.0f), Ui.dp(this, 8.0f));
|
||
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(-2, -2);
|
||
layoutParams.rightMargin = Ui.dp(this, 8.0f);
|
||
textViewSingle.setOnClickListener(new View.OnClickListener() { // from class: com.mulberry.player.MainActivity.19
|
||
@Override // android.view.View.OnClickListener
|
||
public void onClick(View view) {
|
||
MainActivity.this.libTab = i;
|
||
App.I.prefs.setInt(Prefs.LIB_TAB, i);
|
||
MainActivity.this.styleTabs();
|
||
MainActivity.this.fillLibrary();
|
||
MainActivity.this.libList.setSelection(0);
|
||
}
|
||
});
|
||
this.tabs.addView(textViewSingle, layoutParams);
|
||
}
|
||
horizontalScrollView.addView(this.tabs);
|
||
linearLayoutCol.addView(horizontalScrollView);
|
||
FrameLayout frameLayout = new FrameLayout(this);
|
||
this.libList = Lists.list(this);
|
||
this.libList.setPadding(Ui.dp(this, 6.0f), 0, Ui.dp(this, 6.0f), Ui.dp(this, 140.0f));
|
||
this.songAdapter = new Lists.SongAdapter(this, this.songClick);
|
||
this.groupAdapter = new Lists.GroupAdapter(this, this.groupClick);
|
||
frameLayout.addView(this.libList, new FrameLayout.LayoutParams(-1, -1));
|
||
this.emptyMsg = Ui.text(this, "Scanning your music…", 15.0f, 12, false);
|
||
this.emptyMsg.setGravity(17);
|
||
this.emptyMsg.setPadding(Ui.dp(this, 32.0f), 0, Ui.dp(this, 32.0f), Ui.dp(this, 120.0f));
|
||
this.emptyMsg.setOnClickListener(new View.OnClickListener() { // from class: com.mulberry.player.MainActivity.20
|
||
@Override // android.view.View.OnClickListener
|
||
public void onClick(View view) {
|
||
if (MainActivity.this.hasAudioPermission()) {
|
||
return;
|
||
}
|
||
MainActivity.this.openAppSettingsOrAsk();
|
||
}
|
||
});
|
||
frameLayout.addView(this.emptyMsg, new FrameLayout.LayoutParams(-1, -1));
|
||
linearLayoutCol.addView(frameLayout, Ui.lp(-1, 0));
|
||
((LinearLayout.LayoutParams) frameLayout.getLayoutParams()).weight = 1.0f;
|
||
styleTabs();
|
||
return linearLayoutCol;
|
||
}
|
||
|
||
void openAppSettingsOrAsk() {
|
||
if (shouldShowRequestPermissionRationale(Build.VERSION.SDK_INT >= 33 ? "android.permission.READ_MEDIA_AUDIO" : "android.permission.READ_EXTERNAL_STORAGE") || !App.I.prefs.getBool("asked_perm", false)) {
|
||
App.I.prefs.setBool("asked_perm", true);
|
||
requestPerms();
|
||
} else {
|
||
startActivity(new Intent("android.settings.APPLICATION_DETAILS_SETTINGS", Uri.parse("package:" + getPackageName())));
|
||
}
|
||
}
|
||
|
||
Drawable tinted(int i, int i2, int i3) {
|
||
Drawable drawableMutate = getDrawable(i).mutate();
|
||
drawableMutate.setTint(Ui.c(i2));
|
||
drawableMutate.setBounds(0, 0, Ui.dp(this, i3), Ui.dp(this, i3));
|
||
return drawableMutate;
|
||
}
|
||
|
||
void styleTabs() {
|
||
int i = 0;
|
||
while (i < this.tabs.getChildCount()) {
|
||
TextView textView = (TextView) this.tabs.getChildAt(i);
|
||
boolean z = i == this.libTab;
|
||
textView.setBackground(z ? Ui.round(Ui.c(4), Ui.dpf(this, 18.0f)) : strokeChip());
|
||
textView.setTextColor(Ui.c(z ? 5 : 12));
|
||
i++;
|
||
}
|
||
}
|
||
|
||
Drawable strokeChip() {
|
||
GradientDrawable gradientDrawableRound = Ui.round(0, Ui.dpf(this, 18.0f));
|
||
gradientDrawableRound.setStroke(Ui.dp(this, 1.0f), Ui.c(14));
|
||
return gradientDrawableRound;
|
||
}
|
||
|
||
void fillLibrary() {
|
||
int i;
|
||
List<Library.Group> list;
|
||
String str;
|
||
Library library = App.I.library;
|
||
String strTrim = this.search.getText().toString().trim();
|
||
if (strTrim.length() > 0) {
|
||
this.libList.setAdapter((ListAdapter) this.songAdapter);
|
||
this.songAdapter.numbers = false;
|
||
this.songAdapter.set(library.search(strTrim));
|
||
this.emptyMsg.setVisibility(this.songAdapter.getCount() != 0 ? 8 : 0);
|
||
this.emptyMsg.setText("Nothing matches “" + strTrim + "”");
|
||
return;
|
||
}
|
||
if (this.libTab == 0) {
|
||
ArrayList arrayList = new ArrayList(library.songs);
|
||
sortSongs(arrayList);
|
||
this.songAdapter.numbers = false;
|
||
if (this.libList.getAdapter() != this.songAdapter) {
|
||
this.libList.setAdapter((ListAdapter) this.songAdapter);
|
||
}
|
||
this.songAdapter.set(arrayList);
|
||
} else {
|
||
Lists.GroupAdapter groupAdapter = this.groupAdapter;
|
||
if (this.libTab == 1) {
|
||
i = R.drawable.ic_album;
|
||
} else {
|
||
i = this.libTab == 2 ? R.drawable.ic_artist : R.drawable.ic_folder;
|
||
}
|
||
groupAdapter.icon = i;
|
||
this.libList.setAdapter((ListAdapter) this.groupAdapter);
|
||
Lists.GroupAdapter groupAdapter2 = this.groupAdapter;
|
||
if (this.libTab == 1) {
|
||
list = library.albums;
|
||
} else {
|
||
list = this.libTab == 2 ? library.artists : library.folders;
|
||
}
|
||
groupAdapter2.set(list);
|
||
}
|
||
boolean zIsEmpty = library.songs.isEmpty();
|
||
this.emptyMsg.setVisibility(zIsEmpty ? 0 : 8);
|
||
if (zIsEmpty) {
|
||
TextView textView = this.emptyMsg;
|
||
if (hasAudioPermission()) {
|
||
str = library.loaded ? "No music found.\nCopy songs to your phone (Music or Download folder) and they'll show up here." : "Scanning your music…";
|
||
} else {
|
||
str = "Mulberry needs access to your music.\nTap here to allow it.";
|
||
}
|
||
textView.setText(str);
|
||
}
|
||
}
|
||
|
||
void sortSongs(List<Song> list) {
|
||
Comparator<Song> comparator;
|
||
if ("artist".equals(this.sortMode)) {
|
||
comparator = new Comparator<Song>() { // from class: com.mulberry.player.MainActivity.22
|
||
@Override // java.util.Comparator
|
||
public int compare(Song song, Song song2) {
|
||
int iCompareToIgnoreCase = song.displayArtist().compareToIgnoreCase(song2.displayArtist());
|
||
if (iCompareToIgnoreCase == 0) {
|
||
int iCompareToIgnoreCase2 = song.album.compareToIgnoreCase(song2.album);
|
||
return iCompareToIgnoreCase2 == 0 ? song.track - song2.track : iCompareToIgnoreCase2;
|
||
}
|
||
return iCompareToIgnoreCase;
|
||
}
|
||
};
|
||
} else if ("added".equals(this.sortMode)) {
|
||
comparator = new Comparator<Song>() { // from class: com.mulberry.player.MainActivity.23
|
||
@Override // java.util.Comparator
|
||
public int compare(Song song, Song song2) {
|
||
return Long.compare(song2.dateAdded, song.dateAdded);
|
||
}
|
||
};
|
||
} else if ("year".equals(this.sortMode)) {
|
||
comparator = new Comparator<Song>() { // from class: com.mulberry.player.MainActivity.24
|
||
@Override // java.util.Comparator
|
||
public int compare(Song song, Song song2) {
|
||
return song2.year - song.year;
|
||
}
|
||
};
|
||
} else {
|
||
comparator = "duration".equals(this.sortMode) ? new Comparator<Song>() { // from class: com.mulberry.player.MainActivity.25
|
||
@Override // java.util.Comparator
|
||
public int compare(Song song, Song song2) {
|
||
return Long.compare(song2.duration, song.duration);
|
||
}
|
||
} : new Comparator<Song>() { // from class: com.mulberry.player.MainActivity.26
|
||
@Override // java.util.Comparator
|
||
public int compare(Song song, Song song2) {
|
||
return song.displayTitle().compareToIgnoreCase(song2.displayTitle());
|
||
}
|
||
};
|
||
}
|
||
Collections.sort(list, comparator);
|
||
}
|
||
|
||
void sortMenu() {
|
||
ArrayList arrayList = new ArrayList();
|
||
for (final String[] strArr : new String[][]{new String[]{"title", "Title"}, new String[]{"artist", "Artist"}, new String[]{"added", "Recently added"}, new String[]{"year", "Year"}, new String[]{"duration", "Length"}}) {
|
||
arrayList.add(new Lists.Item(strArr[0].equals(this.sortMode) ? R.drawable.ic_check : R.drawable.ic_sort, strArr[1], new Runnable() { // from class: com.mulberry.player.MainActivity.27
|
||
@Override // java.lang.Runnable
|
||
public void run() {
|
||
MainActivity.this.sortMode = strArr[0];
|
||
MainActivity.this.libTab = 0;
|
||
MainActivity.this.styleTabs();
|
||
MainActivity.this.fillLibrary();
|
||
}
|
||
}));
|
||
}
|
||
arrayList.add(new Lists.Item(R.drawable.ic_refresh, "Rescan library", new Runnable() { // from class: com.mulberry.player.MainActivity.28
|
||
@Override // java.lang.Runnable
|
||
public void run() {
|
||
App.I.library.refresh();
|
||
MainActivity.toast("Rescanning…");
|
||
}
|
||
}));
|
||
Lists.sheet(this, "Sort songs by", null, arrayList);
|
||
}
|
||
|
||
@Override // com.mulberry.player.Library.Listener
|
||
public void onLibraryChanged() {
|
||
fillLibrary();
|
||
if (this.page == 1) {
|
||
rebuildPlaylists();
|
||
}
|
||
if (this.svc == null || !this.svc.queue().isEmpty()) {
|
||
return;
|
||
}
|
||
onTrackChanged();
|
||
}
|
||
|
||
void songMenu(final Song song, final Playlists.PL pl, final int i) {
|
||
ArrayList arrayList = new ArrayList();
|
||
final List listSingletonList = Collections.singletonList(song);
|
||
arrayList.add(new Lists.Item(R.drawable.ic_queue_play_next, "Play next", new Runnable() { // from class: com.mulberry.player.MainActivity.31
|
||
@Override // java.lang.Runnable
|
||
public void run() {
|
||
MainActivity.this.withService(new Runnable() { // from class: com.mulberry.player.MainActivity.31.1
|
||
@Override // java.lang.Runnable
|
||
public void run() {
|
||
MainActivity.this.svc.playNext(listSingletonList);
|
||
MainActivity.toast("Plays next");
|
||
}
|
||
});
|
||
}
|
||
}));
|
||
arrayList.add(new Lists.Item(R.drawable.ic_queue_music, "Add to queue", new Runnable() { // from class: com.mulberry.player.MainActivity.32
|
||
@Override // java.lang.Runnable
|
||
public void run() {
|
||
MainActivity.this.withService(new Runnable() { // from class: com.mulberry.player.MainActivity.32.1
|
||
@Override // java.lang.Runnable
|
||
public void run() {
|
||
MainActivity.this.svc.enqueue(listSingletonList);
|
||
MainActivity.toast("Added to queue");
|
||
}
|
||
});
|
||
}
|
||
}));
|
||
arrayList.add(new Lists.Item(R.drawable.ic_playlist_add, "Add to playlist…", new Runnable() { // from class: com.mulberry.player.MainActivity.33
|
||
@Override // java.lang.Runnable
|
||
public void run() {
|
||
MainActivity.this.addToPlaylist(listSingletonList);
|
||
}
|
||
}));
|
||
arrayList.add(new Lists.Item(R.drawable.ic_edit, "Edit tags…", new Runnable() { // from class: com.mulberry.player.MainActivity.34
|
||
@Override // java.lang.Runnable
|
||
public void run() {
|
||
MainActivity.this.editTags(listSingletonList);
|
||
}
|
||
}));
|
||
arrayList.add(new Lists.Item(R.drawable.ic_cloud_download, "Fetch tags (MusicBrainz)", new Runnable() { // from class: com.mulberry.player.MainActivity.35
|
||
@Override // java.lang.Runnable
|
||
public void run() {
|
||
TagEditorActivity.open(MainActivity.this, listSingletonList, 1);
|
||
}
|
||
}));
|
||
final boolean zFav = PlayStats.fav(song);
|
||
arrayList.add(new Lists.Item(zFav ? R.drawable.ic_favorite_fill : R.drawable.ic_favorite, zFav ? "Remove from favourites" : "Add to favourites", new Runnable() { // from class: com.mulberry.player.MainActivity.36
|
||
@Override // java.lang.Runnable
|
||
public void run() {
|
||
PlayStats.setFav(song, !zFav);
|
||
if (MainActivity.this.svc != null) {
|
||
MainActivity.this.svc.refreshUi();
|
||
}
|
||
}
|
||
}));
|
||
if (song.album.length() > 0) {
|
||
arrayList.add(new Lists.Item(R.drawable.ic_album, "Go to album", new Runnable() { // from class: com.mulberry.player.MainActivity.37
|
||
@Override // java.lang.Runnable
|
||
public void run() {
|
||
MainActivity.this.goToAlbum(song);
|
||
}
|
||
}));
|
||
}
|
||
if (song.displayArtist().length() > 0) {
|
||
arrayList.add(new Lists.Item(R.drawable.ic_artist, "Go to artist", new Runnable() { // from class: com.mulberry.player.MainActivity.38
|
||
@Override // java.lang.Runnable
|
||
public void run() {
|
||
MainActivity.this.goToArtist(song);
|
||
}
|
||
}));
|
||
}
|
||
if (pl != null) {
|
||
arrayList.add(new Lists.Item(R.drawable.ic_expand_more, "Move down", new Runnable() { // from class: com.mulberry.player.MainActivity.39
|
||
@Override // java.lang.Runnable
|
||
public void run() {
|
||
Playlists.move(pl, i, i + 1);
|
||
MainActivity.this.refreshTopDetail();
|
||
}
|
||
}));
|
||
arrayList.add(new Lists.Item(R.drawable.ic_drag_indicator, "Move up", new Runnable() { // from class: com.mulberry.player.MainActivity.40
|
||
@Override // java.lang.Runnable
|
||
public void run() {
|
||
Playlists.move(pl, i, i - 1);
|
||
MainActivity.this.refreshTopDetail();
|
||
}
|
||
}));
|
||
arrayList.add(new Lists.Item(R.drawable.ic_delete, "Remove from playlist", new Runnable() { // from class: com.mulberry.player.MainActivity.41
|
||
@Override // java.lang.Runnable
|
||
public void run() {
|
||
Playlists.removeAt(pl, i);
|
||
MainActivity.this.refreshTopDetail();
|
||
}
|
||
}));
|
||
}
|
||
arrayList.add(new Lists.Item(R.drawable.ic_link, "Share", new Runnable() { // from class: com.mulberry.player.MainActivity.42
|
||
@Override // java.lang.Runnable
|
||
public void run() {
|
||
MainActivity.this.share(song);
|
||
}
|
||
}));
|
||
arrayList.add(new Lists.Item(R.drawable.ic_info, "Details", new Runnable() { // from class: com.mulberry.player.MainActivity.43
|
||
@Override // java.lang.Runnable
|
||
public void run() {
|
||
TagEditorActivity.open(MainActivity.this, listSingletonList, 0);
|
||
}
|
||
}));
|
||
Lists.sheet(this, song.displayTitle(), song.displayArtist(), arrayList);
|
||
}
|
||
|
||
void groupMenu(String str, List<Song> list) {
|
||
ArrayList arrayList = new ArrayList();
|
||
final ArrayList arrayList2 = new ArrayList(list);
|
||
arrayList.add(new Lists.Item(R.drawable.ic_play_arrow_fill, "Play", new Runnable() { // from class: com.mulberry.player.MainActivity.44
|
||
@Override // java.lang.Runnable
|
||
public void run() {
|
||
MainActivity.this.withService(new Runnable() { // from class: com.mulberry.player.MainActivity.44.1
|
||
@Override // java.lang.Runnable
|
||
public void run() {
|
||
MainActivity.this.svc.playList(arrayList2, 0);
|
||
}
|
||
});
|
||
}
|
||
}));
|
||
arrayList.add(new Lists.Item(R.drawable.ic_shuffle, "Shuffle", new Runnable() { // from class: com.mulberry.player.MainActivity.45
|
||
@Override // java.lang.Runnable
|
||
public void run() {
|
||
MainActivity.this.withService(new Runnable() { // from class: com.mulberry.player.MainActivity.45.1
|
||
@Override // java.lang.Runnable
|
||
public void run() {
|
||
MainActivity.this.svc.playShuffled(arrayList2);
|
||
}
|
||
});
|
||
}
|
||
}));
|
||
arrayList.add(new Lists.Item(R.drawable.ic_queue_play_next, "Play next", new Runnable() { // from class: com.mulberry.player.MainActivity.46
|
||
@Override // java.lang.Runnable
|
||
public void run() {
|
||
MainActivity.this.withService(new Runnable() { // from class: com.mulberry.player.MainActivity.46.1
|
||
@Override // java.lang.Runnable
|
||
public void run() {
|
||
MainActivity.this.svc.playNext(arrayList2);
|
||
}
|
||
});
|
||
}
|
||
}));
|
||
arrayList.add(new Lists.Item(R.drawable.ic_queue_music, "Add to queue", new Runnable() { // from class: com.mulberry.player.MainActivity.47
|
||
@Override // java.lang.Runnable
|
||
public void run() {
|
||
MainActivity.this.withService(new Runnable() { // from class: com.mulberry.player.MainActivity.47.1
|
||
@Override // java.lang.Runnable
|
||
public void run() {
|
||
MainActivity.this.svc.enqueue(arrayList2);
|
||
}
|
||
});
|
||
}
|
||
}));
|
||
arrayList.add(new Lists.Item(R.drawable.ic_playlist_add, "Add to playlist…", new Runnable() { // from class: com.mulberry.player.MainActivity.48
|
||
@Override // java.lang.Runnable
|
||
public void run() {
|
||
MainActivity.this.addToPlaylist(arrayList2);
|
||
}
|
||
}));
|
||
arrayList.add(new Lists.Item(R.drawable.ic_edit, "Edit tags (" + arrayList2.size() + " songs)…", new Runnable() { // from class: com.mulberry.player.MainActivity.49
|
||
@Override // java.lang.Runnable
|
||
public void run() {
|
||
MainActivity.this.editTags(arrayList2);
|
||
}
|
||
}));
|
||
arrayList.add(new Lists.Item(R.drawable.ic_cloud_download, "Fetch tags for all (MusicBrainz)", new Runnable() { // from class: com.mulberry.player.MainActivity.50
|
||
@Override // java.lang.Runnable
|
||
public void run() {
|
||
TagEditorActivity.open(MainActivity.this, arrayList2, 3);
|
||
}
|
||
}));
|
||
Lists.sheet(this, str, arrayList2.size() + " songs", arrayList);
|
||
}
|
||
|
||
void editTags(List<Song> list) {
|
||
ArrayList arrayList = new ArrayList();
|
||
for (Song song : list) {
|
||
if (Tagger.canTag(this, song)) {
|
||
arrayList.add(song);
|
||
}
|
||
}
|
||
if (arrayList.isEmpty()) {
|
||
toast("These files can't be tagged (supported: MP3, M4A, AAC, FLAC, OGG, Opus, WMA, WAV, AIFF)");
|
||
return;
|
||
}
|
||
if (arrayList.size() < list.size()) {
|
||
toast((list.size() - arrayList.size()) + " file(s) skipped — format can't be tagged");
|
||
}
|
||
TagEditorActivity.open(this, arrayList, 0);
|
||
}
|
||
|
||
void share(Song song) {
|
||
try {
|
||
Intent intent = new Intent("android.intent.action.SEND");
|
||
intent.setType((song.mime == null || song.mime.length() <= 0) ? "audio/*" : song.mime);
|
||
intent.putExtra("android.intent.extra.STREAM", song.toUri());
|
||
intent.putExtra("android.intent.extra.TEXT", song.displayArtist() + " – " + song.displayTitle());
|
||
intent.addFlags(1);
|
||
startActivity(Intent.createChooser(intent, "Share"));
|
||
} catch (Exception e) {
|
||
toast("Can't share this file");
|
||
}
|
||
}
|
||
|
||
void goToAlbum(Song song) {
|
||
for (Library.Group group : App.I.library.albums) {
|
||
Iterator<Song> it = group.songs.iterator();
|
||
while (it.hasNext()) {
|
||
if (it.next().key().equals(song.key())) {
|
||
closePlayer();
|
||
openGroup(group.title, group.subtitle, group.songs, true, null);
|
||
return;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
void goToArtist(Song song) {
|
||
for (Library.Group group : App.I.library.artists) {
|
||
Iterator<Song> it = group.songs.iterator();
|
||
while (it.hasNext()) {
|
||
if (it.next().key().equals(song.key())) {
|
||
closePlayer();
|
||
openGroup(group.title, group.subtitle, group.songs, false, null);
|
||
return;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
void addToPlaylist(final List<Song> list) {
|
||
List<Playlists.PL> listAll = Playlists.all();
|
||
ArrayList arrayList = new ArrayList();
|
||
arrayList.add(new Lists.Item(R.drawable.ic_add, "New playlist…", new Runnable() { // from class: com.mulberry.player.MainActivity.51
|
||
@Override // java.lang.Runnable
|
||
public void run() {
|
||
MainActivity.this.askText("New playlist", "Name", FrameBodyCOMM.DEFAULT, new TextCb() { // from class: com.mulberry.player.MainActivity.51.1
|
||
@Override // com.mulberry.player.MainActivity.TextCb
|
||
public void ok(String str) {
|
||
Playlists.create(str, list);
|
||
MainActivity.toast("Created “" + str + "”");
|
||
}
|
||
});
|
||
}
|
||
}));
|
||
for (final Playlists.PL pl : listAll) {
|
||
arrayList.add(new Lists.Item(R.drawable.ic_queue_music, pl.name, new Runnable() { // from class: com.mulberry.player.MainActivity.52
|
||
@Override // java.lang.Runnable
|
||
public void run() {
|
||
Playlists.add(pl, list);
|
||
MainActivity.toast("Added to “" + pl.name + "”");
|
||
}
|
||
}));
|
||
}
|
||
Lists.sheet(this, "Add to playlist", list.size() + (list.size() == 1 ? " song" : " songs"), arrayList);
|
||
}
|
||
|
||
void askText(String str, String str2, String str3, final TextCb textCb) {
|
||
final EditText editTextField = Ui.field(this, str2, str3);
|
||
editTextField.setSingleLine(true);
|
||
FrameLayout frameLayout = new FrameLayout(this);
|
||
frameLayout.setPadding(Ui.dp(this, 22.0f), Ui.dp(this, 8.0f), Ui.dp(this, 22.0f), 0);
|
||
frameLayout.addView(editTextField);
|
||
Ui.show(Ui.dialog(this).setTitle(str).setView(frameLayout).setPositiveButton("OK", new DialogInterface.OnClickListener() { // from class: com.mulberry.player.MainActivity.53
|
||
@Override // android.content.DialogInterface.OnClickListener
|
||
public void onClick(DialogInterface dialogInterface, int i) {
|
||
String strTrim = editTextField.getText().toString().trim();
|
||
if (strTrim.length() > 0) {
|
||
textCb.ok(strTrim);
|
||
}
|
||
}
|
||
}).setNegativeButton("Cancel", (DialogInterface.OnClickListener) null));
|
||
}
|
||
|
||
void openGroup(String str, String str2, final List<Song> list, boolean z, final Playlists.PL pl) {
|
||
long j;
|
||
LinearLayout linearLayoutCol = Ui.col(this);
|
||
Ui.plain(linearLayoutCol, 6);
|
||
linearLayoutCol.setClickable(true);
|
||
linearLayoutCol.setPadding(0, this.insetTop, 0, 0);
|
||
LinearLayout linearLayoutRow = Ui.row(this);
|
||
linearLayoutRow.setPadding(Ui.dp(this, 6.0f), Ui.dp(this, 6.0f), Ui.dp(this, 10.0f), 0);
|
||
linearLayoutRow.addView(Ui.iconButton(this, R.drawable.ic_arrow_back, 11, 44, new View.OnClickListener() { // from class: com.mulberry.player.MainActivity.54
|
||
@Override // android.view.View.OnClickListener
|
||
public void onClick(View view) {
|
||
MainActivity.this.popDetail(true);
|
||
}
|
||
}));
|
||
linearLayoutRow.addView(new View(this), Ui.lpw(1, 1.0f));
|
||
linearLayoutRow.addView(Ui.iconButton(this, R.drawable.ic_more_vert, 11, 44, new View.OnClickListener() { // from class: com.mulberry.player.MainActivity.55
|
||
@Override // android.view.View.OnClickListener
|
||
public void onClick(View view) {
|
||
if (pl == null) {
|
||
MainActivity.this.groupMenu(MainActivity.this.currentTitle(), list);
|
||
} else {
|
||
MainActivity.this.playlistMenu(pl);
|
||
}
|
||
}
|
||
}));
|
||
linearLayoutCol.addView(linearLayoutRow);
|
||
LinearLayout linearLayoutRow2 = Ui.row(this);
|
||
linearLayoutRow2.setPadding(Ui.dp(this, 20.0f), Ui.dp(this, 4.0f), Ui.dp(this, 20.0f), Ui.dp(this, 12.0f));
|
||
if (!list.isEmpty()) {
|
||
ImageView imageViewCoverView = Lists.coverView(this, 112, 28.0f);
|
||
Lists.bindCover(imageViewCoverView, list.get(0), 400);
|
||
linearLayoutRow2.addView(imageViewCoverView);
|
||
}
|
||
LinearLayout linearLayoutCol2 = Ui.col(this);
|
||
linearLayoutCol2.setPadding(Ui.dp(this, 16.0f), 0, 0, 0);
|
||
TextView textViewText = Ui.text(this, str, 24.0f, 11, true);
|
||
textViewText.setMaxLines(3);
|
||
textViewText.setTag("title");
|
||
linearLayoutCol2.addView(textViewText);
|
||
if (str2 == null) {
|
||
str2 = list.size() + " songs";
|
||
}
|
||
linearLayoutCol2.addView(Ui.single(this, str2, 14.0f, 12, false));
|
||
long j2 = 0;
|
||
Iterator<Song> it = list.iterator();
|
||
while (true) {
|
||
j = j2;
|
||
if (!it.hasNext()) {
|
||
break;
|
||
} else {
|
||
j2 = it.next().duration + j;
|
||
}
|
||
}
|
||
linearLayoutCol2.addView(Ui.single(this, Draw.time(j), 13.0f, 12, false));
|
||
linearLayoutRow2.addView(linearLayoutCol2, Ui.lpw(-2, 1.0f));
|
||
linearLayoutCol.addView(linearLayoutRow2);
|
||
LinearLayout linearLayoutRow3 = Ui.row(this);
|
||
linearLayoutRow3.setPadding(Ui.dp(this, 20.0f), 0, Ui.dp(this, 20.0f), Ui.dp(this, 8.0f));
|
||
linearLayoutRow3.addView(Ui.pill(this, R.drawable.ic_play_arrow_fill, "Play", true, new View.OnClickListener() { // from class: com.mulberry.player.MainActivity.56
|
||
@Override // android.view.View.OnClickListener
|
||
public void onClick(View view) {
|
||
final ArrayList arrayList = new ArrayList(list);
|
||
if (!arrayList.isEmpty()) {
|
||
MainActivity.this.withService(new Runnable() { // from class: com.mulberry.player.MainActivity.56.1
|
||
@Override // java.lang.Runnable
|
||
public void run() {
|
||
if (MainActivity.this.svc.shuffle()) {
|
||
MainActivity.this.svc.setShuffle(false);
|
||
}
|
||
MainActivity.this.svc.playList(arrayList, 0);
|
||
}
|
||
});
|
||
}
|
||
}
|
||
}));
|
||
linearLayoutRow3.addView(Ui.space(this, 10));
|
||
linearLayoutRow3.addView(Ui.pill(this, R.drawable.ic_shuffle, "Shuffle", false, new View.OnClickListener() { // from class: com.mulberry.player.MainActivity.57
|
||
@Override // android.view.View.OnClickListener
|
||
public void onClick(View view) {
|
||
final ArrayList arrayList = new ArrayList(list);
|
||
if (!arrayList.isEmpty()) {
|
||
MainActivity.this.withService(new Runnable() { // from class: com.mulberry.player.MainActivity.57.1
|
||
@Override // java.lang.Runnable
|
||
public void run() {
|
||
MainActivity.this.svc.playShuffled(arrayList);
|
||
}
|
||
});
|
||
}
|
||
}
|
||
}));
|
||
linearLayoutCol.addView(linearLayoutRow3);
|
||
ListView list2 = Lists.list(this);
|
||
list2.setTag("list");
|
||
list2.setPadding(Ui.dp(this, 6.0f), 0, Ui.dp(this, 6.0f), this.listBottom);
|
||
Lists.SongAdapter songAdapter = new Lists.SongAdapter(this, new Lists.SongClick() { // from class: com.mulberry.player.MainActivity.58
|
||
@Override // com.mulberry.player.Lists.SongClick
|
||
public void click(List<Song> list3, final int i) {
|
||
final ArrayList arrayList = new ArrayList(list3);
|
||
MainActivity.this.withService(new Runnable() { // from class: com.mulberry.player.MainActivity.58.1
|
||
@Override // java.lang.Runnable
|
||
public void run() {
|
||
MainActivity.this.svc.playList(arrayList, i);
|
||
}
|
||
});
|
||
}
|
||
|
||
@Override // com.mulberry.player.Lists.SongClick
|
||
public void longClick(List<Song> list3, int i, View view) {
|
||
MainActivity.this.songMenu(list3.get(i), pl, i);
|
||
}
|
||
});
|
||
songAdapter.numbers = z;
|
||
songAdapter.playing = this.svc == null ? null : this.svc.current();
|
||
songAdapter.set(new ArrayList(pl != null ? pl.songs : list));
|
||
list2.setAdapter((ListAdapter) songAdapter);
|
||
linearLayoutCol.addView(list2, Ui.lp(-1, 0));
|
||
((LinearLayout.LayoutParams) list2.getLayoutParams()).weight = 1.0f;
|
||
linearLayoutCol.setTag(R.id.detail_adapter, songAdapter);
|
||
if (pl != null) {
|
||
linearLayoutCol.setTag(R.id.detail_pl, pl);
|
||
}
|
||
pushDetail(linearLayoutCol);
|
||
}
|
||
|
||
String currentTitle() {
|
||
TextView textView;
|
||
return (this.stack.isEmpty() || (textView = (TextView) this.stack.get(this.stack.size() + (-1)).findViewWithTag("title")) == null) ? FrameBodyCOMM.DEFAULT : textView.getText().toString();
|
||
}
|
||
|
||
void refreshTopDetail() {
|
||
for (View view : this.stack) {
|
||
Object tag = view.getTag(R.id.detail_adapter);
|
||
if (tag instanceof Lists.SongAdapter) {
|
||
Lists.SongAdapter songAdapter = (Lists.SongAdapter) tag;
|
||
songAdapter.playing = this.svc == null ? null : this.svc.current();
|
||
Object tag2 = view.getTag(R.id.detail_pl);
|
||
if (tag2 instanceof Playlists.PL) {
|
||
songAdapter.set(new ArrayList(((Playlists.PL) tag2).songs));
|
||
} else {
|
||
songAdapter.notifyDataSetChanged();
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
void pushDetail(View view) {
|
||
this.pages.addView(view, new FrameLayout.LayoutParams(-1, -1));
|
||
this.stack.add(view);
|
||
if (!App.lowPower()) {
|
||
view.setTranslationX(Ui.dp(this, 60.0f));
|
||
view.setAlpha(0.0f);
|
||
view.animate().translationX(0.0f).alpha(1.0f).setDuration(240L).setInterpolator(new PathInterpolator(0.2f, 0.0f, 0.0f, 1.0f)).start();
|
||
}
|
||
}
|
||
|
||
void popDetail(boolean z) {
|
||
if (!this.stack.isEmpty()) {
|
||
final View viewRemove = this.stack.remove(this.stack.size() - 1);
|
||
if (z && !App.lowPower()) {
|
||
viewRemove.animate().translationX(Ui.dp(this, 60.0f)).alpha(0.0f).setDuration(180L).withEndAction(new Runnable() { // from class: com.mulberry.player.MainActivity.59
|
||
@Override // java.lang.Runnable
|
||
public void run() {
|
||
MainActivity.this.pages.removeView(viewRemove);
|
||
}
|
||
}).start();
|
||
} else {
|
||
this.pages.removeView(viewRemove);
|
||
}
|
||
}
|
||
}
|
||
|
||
@Override // android.app.Activity
|
||
public void onBackPressed() {
|
||
if (!this.player.open) {
|
||
if (this.stack.isEmpty()) {
|
||
if (this.search.getText().length() <= 0 || this.page != 0) {
|
||
if (this.page == 0) {
|
||
moveTaskToBack(true);
|
||
return;
|
||
} else {
|
||
showPage(0, true);
|
||
return;
|
||
}
|
||
}
|
||
this.search.setText(FrameBodyCOMM.DEFAULT);
|
||
return;
|
||
}
|
||
popDetail(true);
|
||
return;
|
||
}
|
||
closePlayer();
|
||
}
|
||
|
||
View buildPlaylists() {
|
||
ScrollView scrollView = new ScrollView(this);
|
||
scrollView.setClipToPadding(false);
|
||
this.plBox = Ui.col(this);
|
||
this.plBox.setPadding(Ui.dp(this, 12.0f), 0, Ui.dp(this, 12.0f), Ui.dp(this, 140.0f));
|
||
scrollView.addView(this.plBox);
|
||
return scrollView;
|
||
}
|
||
|
||
@Override // com.mulberry.player.Playlists.Listener
|
||
public void onPlaylistsChanged() {
|
||
if (this.page == 1) {
|
||
rebuildPlaylists();
|
||
}
|
||
refreshTopDetail();
|
||
}
|
||
|
||
void rebuildPlaylists() {
|
||
this.plBox.removeAllViews();
|
||
LinearLayout linearLayoutRow = Ui.row(this);
|
||
linearLayoutRow.setPadding(Ui.dp(this, 8.0f), Ui.dp(this, 14.0f), 0, Ui.dp(this, 10.0f));
|
||
linearLayoutRow.addView(Ui.title(this, "Playlists"), Ui.lpw(-2, 1.0f));
|
||
this.plBox.addView(linearLayoutRow);
|
||
HorizontalScrollView horizontalScrollView = new HorizontalScrollView(this);
|
||
horizontalScrollView.setHorizontalScrollBarEnabled(false);
|
||
LinearLayout linearLayoutRow2 = Ui.row(this);
|
||
linearLayoutRow2.setPadding(Ui.dp(this, 6.0f), 0, Ui.dp(this, 6.0f), Ui.dp(this, 12.0f));
|
||
linearLayoutRow2.addView(Ui.pill(this, R.drawable.ic_add, "New", true, new View.OnClickListener() { // from class: com.mulberry.player.MainActivity.60
|
||
@Override // android.view.View.OnClickListener
|
||
public void onClick(View view) {
|
||
MainActivity.this.askText("New playlist", "Name", FrameBodyCOMM.DEFAULT, new TextCb() { // from class: com.mulberry.player.MainActivity.60.1
|
||
@Override // com.mulberry.player.MainActivity.TextCb
|
||
public void ok(String str) {
|
||
Playlists.create(str, null);
|
||
}
|
||
});
|
||
}
|
||
}));
|
||
linearLayoutRow2.addView(Ui.space(this, 8));
|
||
linearLayoutRow2.addView(Ui.pill(this, R.drawable.ic_download, "Import", false, new View.OnClickListener() { // from class: com.mulberry.player.MainActivity.61
|
||
@Override // android.view.View.OnClickListener
|
||
public void onClick(View view) {
|
||
MainActivity.this.importPlaylist();
|
||
}
|
||
}));
|
||
linearLayoutRow2.addView(Ui.space(this, 8));
|
||
linearLayoutRow2.addView(Ui.pill(this, R.drawable.ic_upload, "Export all", false, new View.OnClickListener() { // from class: com.mulberry.player.MainActivity.62
|
||
@Override // android.view.View.OnClickListener
|
||
public void onClick(View view) {
|
||
MainActivity.this.exportAllDialog();
|
||
}
|
||
}));
|
||
linearLayoutRow2.addView(Ui.space(this, 8));
|
||
linearLayoutRow2.addView(Ui.pill(this, R.drawable.ic_save, "Save queue", false, new View.OnClickListener() { // from class: com.mulberry.player.MainActivity.63
|
||
@Override // android.view.View.OnClickListener
|
||
public void onClick(View view) {
|
||
if (MainActivity.this.svc != null && !MainActivity.this.svc.queue().isEmpty()) {
|
||
MainActivity.this.askText("Save queue as playlist", "Name", "Queue", new TextCb() { // from class: com.mulberry.player.MainActivity.63.1
|
||
@Override // com.mulberry.player.MainActivity.TextCb
|
||
public void ok(String str) {
|
||
Playlists.create(str, new ArrayList(MainActivity.this.svc.queue()));
|
||
}
|
||
});
|
||
} else {
|
||
MainActivity.toast("The queue is empty");
|
||
}
|
||
}
|
||
}));
|
||
horizontalScrollView.addView(linearLayoutRow2);
|
||
this.plBox.addView(horizontalScrollView);
|
||
this.plBox.addView(section("Smart playlists"));
|
||
List<Song> list = App.I.library.songs;
|
||
smart(R.drawable.ic_favorite_fill, "Favourites", PlayStats.favourites(list));
|
||
smart(R.drawable.ic_trending_up, "Most played", PlayStats.mostPlayed(list, 100));
|
||
smart(R.drawable.ic_history, "Recently played", PlayStats.recentlyPlayed(list, 100));
|
||
smart(R.drawable.ic_auto_awesome, "Recently added", PlayStats.recentlyAdded(list, 100));
|
||
smart(R.drawable.ic_visibility, "Never played", PlayStats.neverPlayed(list));
|
||
List<Playlists.PL> listAll = Playlists.all();
|
||
this.plBox.addView(section(listAll.isEmpty() ? "Your playlists — none yet" : "Your playlists"));
|
||
for (final Playlists.PL pl : listAll) {
|
||
LinearLayout linearLayoutPlRow = plRow(R.drawable.ic_queue_music, pl.name, pl.songs.size() + " songs", false);
|
||
linearLayoutPlRow.setOnClickListener(new View.OnClickListener() { // from class: com.mulberry.player.MainActivity.64
|
||
@Override // android.view.View.OnClickListener
|
||
public void onClick(View view) {
|
||
MainActivity.this.openGroup(pl.name, pl.songs.size() + " songs", pl.songs, false, pl);
|
||
}
|
||
});
|
||
linearLayoutPlRow.setOnLongClickListener(new View.OnLongClickListener() { // from class: com.mulberry.player.MainActivity.65
|
||
@Override // android.view.View.OnLongClickListener
|
||
public boolean onLongClick(View view) {
|
||
MainActivity.this.playlistMenu(pl);
|
||
return true;
|
||
}
|
||
});
|
||
this.plBox.addView(linearLayoutPlRow);
|
||
}
|
||
this.plBox.setPadding(this.plBox.getPaddingLeft(), this.plBox.getPaddingTop(), this.plBox.getPaddingRight(), this.listBottom);
|
||
}
|
||
|
||
TextView section(String str) {
|
||
TextView textViewSingle = Ui.single(this, str, 14.0f, 0, true);
|
||
textViewSingle.setPadding(Ui.dp(this, 10.0f), Ui.dp(this, 14.0f), 0, Ui.dp(this, 6.0f));
|
||
return textViewSingle;
|
||
}
|
||
|
||
void smart(int i, final String str, final List<Song> list) {
|
||
LinearLayout linearLayoutPlRow = plRow(i, str, list.size() + " songs", true);
|
||
linearLayoutPlRow.setOnClickListener(new View.OnClickListener() { // from class: com.mulberry.player.MainActivity.66
|
||
@Override // android.view.View.OnClickListener
|
||
public void onClick(View view) {
|
||
MainActivity.this.openGroup(str, list.size() + " songs", list, false, null);
|
||
}
|
||
});
|
||
linearLayoutPlRow.setOnLongClickListener(new View.OnLongClickListener() { // from class: com.mulberry.player.MainActivity.67
|
||
@Override // android.view.View.OnLongClickListener
|
||
public boolean onLongClick(View view) {
|
||
MainActivity.this.groupMenu(str, list);
|
||
return true;
|
||
}
|
||
});
|
||
this.plBox.addView(linearLayoutPlRow);
|
||
}
|
||
|
||
LinearLayout plRow(int i, String str, String str2, boolean z) {
|
||
LinearLayout linearLayoutRow = Ui.row(this);
|
||
linearLayoutRow.setPadding(Ui.dp(this, 8.0f), Ui.dp(this, 8.0f), Ui.dp(this, 8.0f), Ui.dp(this, 8.0f));
|
||
Ui.clickable(linearLayoutRow, 18.0f);
|
||
ImageView imageViewIcon = Ui.icon(this, i, z ? 11 : 5, 52);
|
||
int iDp = Ui.dp(this, 14.0f);
|
||
imageViewIcon.setPadding(iDp, iDp, iDp, iDp);
|
||
imageViewIcon.setBackground(Ui.round(Ui.c(z ? 16 : 4), Ui.dpf(this, 16.0f)));
|
||
linearLayoutRow.addView(imageViewIcon);
|
||
LinearLayout linearLayoutCol = Ui.col(this);
|
||
linearLayoutCol.setPadding(Ui.dp(this, 14.0f), 0, 0, 0);
|
||
linearLayoutCol.addView(Ui.single(this, str, 16.0f, 11, true));
|
||
linearLayoutCol.addView(Ui.single(this, str2, 13.0f, 12, false));
|
||
linearLayoutRow.addView(linearLayoutCol, Ui.lpw(-2, 1.0f));
|
||
return linearLayoutRow;
|
||
}
|
||
|
||
void playlistMenu(final Playlists.PL pl) {
|
||
ArrayList arrayList = new ArrayList();
|
||
arrayList.add(new Lists.Item(R.drawable.ic_play_arrow_fill, "Play", new Runnable() { // from class: com.mulberry.player.MainActivity.68
|
||
@Override // java.lang.Runnable
|
||
public void run() {
|
||
final ArrayList arrayList2 = new ArrayList(pl.songs);
|
||
if (!arrayList2.isEmpty()) {
|
||
MainActivity.this.withService(new Runnable() { // from class: com.mulberry.player.MainActivity.68.1
|
||
@Override // java.lang.Runnable
|
||
public void run() {
|
||
MainActivity.this.svc.playList(arrayList2, 0);
|
||
}
|
||
});
|
||
}
|
||
}
|
||
}));
|
||
arrayList.add(new Lists.Item(R.drawable.ic_queue_music, "Add to queue", new Runnable() { // from class: com.mulberry.player.MainActivity.69
|
||
@Override // java.lang.Runnable
|
||
public void run() {
|
||
final ArrayList arrayList2 = new ArrayList(pl.songs);
|
||
if (!arrayList2.isEmpty()) {
|
||
MainActivity.this.withService(new Runnable() { // from class: com.mulberry.player.MainActivity.69.1
|
||
@Override // java.lang.Runnable
|
||
public void run() {
|
||
MainActivity.this.svc.enqueue(arrayList2);
|
||
}
|
||
});
|
||
}
|
||
}
|
||
}));
|
||
arrayList.add(new Lists.Item(R.drawable.ic_edit, "Rename", new Runnable() { // from class: com.mulberry.player.MainActivity.70
|
||
@Override // java.lang.Runnable
|
||
public void run() {
|
||
MainActivity.this.askText("Rename playlist", "Name", pl.name, new TextCb() { // from class: com.mulberry.player.MainActivity.70.1
|
||
@Override // com.mulberry.player.MainActivity.TextCb
|
||
public void ok(String str) {
|
||
Playlists.rename(pl, str);
|
||
}
|
||
});
|
||
}
|
||
}));
|
||
arrayList.add(new Lists.Item(R.drawable.ic_upload, "Export…", new Runnable() { // from class: com.mulberry.player.MainActivity.71
|
||
@Override // java.lang.Runnable
|
||
public void run() {
|
||
MainActivity.this.exportOne(pl);
|
||
}
|
||
}));
|
||
arrayList.add(new Lists.Item(R.drawable.ic_label, "Edit tags of all songs…", new Runnable() { // from class: com.mulberry.player.MainActivity.72
|
||
@Override // java.lang.Runnable
|
||
public void run() {
|
||
MainActivity.this.editTags(new ArrayList(pl.songs));
|
||
}
|
||
}));
|
||
arrayList.add(new Lists.Item(R.drawable.ic_delete, "Delete playlist", new Runnable() { // from class: com.mulberry.player.MainActivity.73
|
||
@Override // java.lang.Runnable
|
||
public void run() {
|
||
Ui.show(Ui.dialog(MainActivity.this).setTitle("Delete “" + pl.name + "”?").setMessage("The songs themselves are not deleted.").setPositiveButton("Delete", new DialogInterface.OnClickListener() { // from class: com.mulberry.player.MainActivity.73.1
|
||
@Override // android.content.DialogInterface.OnClickListener
|
||
public void onClick(DialogInterface dialogInterface, int i) {
|
||
Playlists.delete(pl);
|
||
MainActivity.this.popDetail(true);
|
||
}
|
||
}).setNegativeButton("Cancel", (DialogInterface.OnClickListener) null));
|
||
}
|
||
}));
|
||
Lists.sheet(this, pl.name, pl.songs.size() + " songs", arrayList);
|
||
}
|
||
|
||
void importPlaylist() {
|
||
Intent intent = new Intent("android.intent.action.OPEN_DOCUMENT");
|
||
intent.addCategory("android.intent.category.OPENABLE");
|
||
intent.setType("*/*");
|
||
intent.putExtra("android.intent.extra.MIME_TYPES", new String[]{"audio/x-mpegurl", "audio/mpegurl", "application/vnd.apple.mpegurl", "audio/x-scpls", "application/octet-stream", "text/plain"});
|
||
intent.putExtra("android.intent.extra.ALLOW_MULTIPLE", true);
|
||
try {
|
||
startActivityForResult(intent, 10);
|
||
} catch (Exception e) {
|
||
toast("No file picker available");
|
||
}
|
||
}
|
||
|
||
void doImport(final Uri uri) {
|
||
App.IO.execute(new Runnable() { // from class: com.mulberry.player.MainActivity.74
|
||
@Override // java.lang.Runnable
|
||
public void run() {
|
||
try {
|
||
final Playlists.Parsed parsedImportUri = Playlists.importUri(MainActivity.this, uri);
|
||
App.ui(new Runnable() { // from class: com.mulberry.player.MainActivity.74.1
|
||
@Override // java.lang.Runnable
|
||
public void run() {
|
||
if (!parsedImportUri.songs.isEmpty()) {
|
||
Playlists.create(parsedImportUri.name, parsedImportUri.songs);
|
||
MainActivity.toast("Imported “" + parsedImportUri.name + "”: " + parsedImportUri.songs.size() + " songs" + (parsedImportUri.missing > 0 ? ", " + parsedImportUri.missing + " not found" : FrameBodyCOMM.DEFAULT));
|
||
} else {
|
||
MainActivity.toast("No songs from “" + parsedImportUri.name + "” were found on this phone");
|
||
}
|
||
}
|
||
});
|
||
} catch (Exception e) {
|
||
MainActivity.toast("Import failed: " + e.getMessage());
|
||
}
|
||
}
|
||
});
|
||
}
|
||
|
||
void exportOne(final Playlists.PL pl) {
|
||
final String[] strArr = {"m3u8", "m3u", "pls"};
|
||
Ui.show(Ui.dialog(this).setTitle("Export “" + pl.name + "” as").setItems(new String[]{"M3U8 (UTF-8, recommended)", "M3U", "PLS"}, new DialogInterface.OnClickListener() { // from class: com.mulberry.player.MainActivity.75
|
||
@Override // android.content.DialogInterface.OnClickListener
|
||
public void onClick(DialogInterface dialogInterface, int i) {
|
||
MainActivity.this.exportPl = pl;
|
||
MainActivity.this.exportFmt = strArr[i];
|
||
Intent intent = new Intent("android.intent.action.CREATE_DOCUMENT");
|
||
intent.addCategory("android.intent.category.OPENABLE");
|
||
intent.setType("pls".equals(MainActivity.this.exportFmt) ? "audio/x-scpls" : "audio/x-mpegurl");
|
||
intent.putExtra("android.intent.extra.TITLE", Playlists.safeName(pl.name) + "." + MainActivity.this.exportFmt);
|
||
try {
|
||
MainActivity.this.startActivityForResult(intent, 11);
|
||
} catch (Exception e) {
|
||
MainActivity.toast("No file picker available");
|
||
}
|
||
}
|
||
}));
|
||
}
|
||
|
||
void exportAllDialog() {
|
||
if (!Playlists.all().isEmpty()) {
|
||
LinearLayout linearLayoutCol = Ui.col(this);
|
||
linearLayoutCol.setPadding(Ui.dp(this, 24.0f), Ui.dp(this, 8.0f), Ui.dp(this, 24.0f), 0);
|
||
linearLayoutCol.addView(Ui.text(this, "File type", 14.0f, 12, true));
|
||
final RadioGroup radioGroup = new RadioGroup(this);
|
||
String[] strArr = {"M3U8 (UTF-8, recommended)", "M3U", "PLS"};
|
||
final String[] strArr2 = {"m3u8", "m3u", "pls"};
|
||
for (int i = 0; i < 3; i++) {
|
||
RadioButton radioButton = new RadioButton(this);
|
||
radioButton.setText(strArr[i]);
|
||
radioButton.setId(i + 1000);
|
||
radioButton.setTextColor(Ui.c(11));
|
||
radioButton.setButtonTintList(ColorStateList.valueOf(Ui.c(0)));
|
||
radioGroup.addView(radioButton);
|
||
}
|
||
radioGroup.check(1000);
|
||
linearLayoutCol.addView(radioGroup);
|
||
final CheckBox checkBox = new CheckBox(this);
|
||
checkBox.setText("Replace files that already exist");
|
||
checkBox.setChecked(true);
|
||
checkBox.setTextColor(Ui.c(11));
|
||
checkBox.setButtonTintList(ColorStateList.valueOf(Ui.c(0)));
|
||
linearLayoutCol.addView(checkBox);
|
||
linearLayoutCol.addView(Ui.text(this, "Songs are written with full paths, so the lists open in Mulberry on other phones and PCs too.", 13.0f, 12, false));
|
||
Ui.show(Ui.dialog(this).setTitle("Export all playlists").setView(linearLayoutCol).setPositiveButton("Choose folder", new DialogInterface.OnClickListener() { // from class: com.mulberry.player.MainActivity.76
|
||
@Override // android.content.DialogInterface.OnClickListener
|
||
public void onClick(DialogInterface dialogInterface, int i2) {
|
||
MainActivity.this.exportFmt = strArr2[Math.max(0, radioGroup.getCheckedRadioButtonId() - 1000)];
|
||
MainActivity.this.exportReplace = checkBox.isChecked();
|
||
try {
|
||
MainActivity.this.startActivityForResult(new Intent("android.intent.action.OPEN_DOCUMENT_TREE"), 12);
|
||
} catch (Exception e) {
|
||
MainActivity.toast("No folder picker available");
|
||
}
|
||
}
|
||
}).setNegativeButton("Cancel", (DialogInterface.OnClickListener) null));
|
||
return;
|
||
}
|
||
toast("No playlists to export");
|
||
}
|
||
|
||
@Override // android.app.Activity
|
||
protected void onActivityResult(int i, int i2, final Intent intent) {
|
||
super.onActivityResult(i, i2, intent);
|
||
if (i2 == -1 && intent != null) {
|
||
if (i == 10) {
|
||
if (intent.getClipData() != null) {
|
||
for (int i3 = 0; i3 < intent.getClipData().getItemCount(); i3++) {
|
||
doImport(intent.getClipData().getItemAt(i3).getUri());
|
||
}
|
||
return;
|
||
}
|
||
if (intent.getData() != null) {
|
||
doImport(intent.getData());
|
||
return;
|
||
}
|
||
return;
|
||
}
|
||
if (i == 11 && this.exportPl != null && intent.getData() != null) {
|
||
final Playlists.PL pl = this.exportPl;
|
||
App.IO.execute(new Runnable() { // from class: com.mulberry.player.MainActivity.77
|
||
@Override // java.lang.Runnable
|
||
public void run() {
|
||
try {
|
||
Playlists.writeTo(MainActivity.this, intent.getData(), pl, MainActivity.this.exportFmt);
|
||
MainActivity.toast("Exported “" + pl.name + "”");
|
||
} catch (Exception e) {
|
||
MainActivity.toast("Export failed: " + e.getMessage());
|
||
}
|
||
}
|
||
});
|
||
} else if (i == 12 && intent.getData() != null) {
|
||
final Uri data = intent.getData();
|
||
try {
|
||
getContentResolver().takePersistableUriPermission(data, 3);
|
||
} catch (Exception e) {
|
||
}
|
||
App.IO.execute(new Runnable() { // from class: com.mulberry.player.MainActivity.78
|
||
@Override // java.lang.Runnable
|
||
public void run() {
|
||
try {
|
||
int iExportAll = Playlists.exportAll(MainActivity.this, data, MainActivity.this.exportFmt, MainActivity.this.exportReplace);
|
||
MainActivity.toast("Exported " + iExportAll + " playlist" + (iExportAll == 1 ? FrameBodyCOMM.DEFAULT : "s"));
|
||
} catch (Exception e2) {
|
||
MainActivity.toast("Export failed: " + e2.getMessage());
|
||
}
|
||
}
|
||
});
|
||
}
|
||
}
|
||
}
|
||
|
||
void openPlayer() {
|
||
if (this.svc != null && this.svc.current() != null) {
|
||
this.player.updateTrack();
|
||
this.player.animateOpen(true);
|
||
this.mini.setVisibility(4);
|
||
}
|
||
}
|
||
|
||
void closePlayer() {
|
||
if (this.player.open) {
|
||
this.player.animateOpen(false);
|
||
this.mini.setVisibility((this.svc == null || this.svc.current() == null) ? 8 : 0);
|
||
}
|
||
}
|
||
|
||
void togglePlay() {
|
||
withService(new Runnable() { // from class: com.mulberry.player.MainActivity.79
|
||
@Override // java.lang.Runnable
|
||
public void run() {
|
||
MainActivity.this.svc.toggle();
|
||
}
|
||
});
|
||
}
|
||
|
||
void toggleFav() {
|
||
if (this.svc != null && this.svc.current() != null) {
|
||
Song songCurrent = this.svc.current();
|
||
boolean z = !PlayStats.fav(songCurrent);
|
||
PlayStats.setFav(songCurrent, z);
|
||
if (z && LastFm.anyOn()) {
|
||
LastFm.love(songCurrent, true);
|
||
}
|
||
this.svc.refreshUi();
|
||
this.player.updateTrack();
|
||
}
|
||
}
|
||
|
||
void playerMenu() {
|
||
if (this.svc != null && this.svc.current() != null) {
|
||
final Song songCurrent = this.svc.current();
|
||
ArrayList arrayList = new ArrayList();
|
||
arrayList.add(new Lists.Item(R.drawable.ic_playlist_add, "Add to playlist…", new Runnable() { // from class: com.mulberry.player.MainActivity.80
|
||
@Override // java.lang.Runnable
|
||
public void run() {
|
||
MainActivity.this.addToPlaylist(Collections.singletonList(songCurrent));
|
||
}
|
||
}));
|
||
arrayList.add(new Lists.Item(R.drawable.ic_edit, "Edit tags…", new Runnable() { // from class: com.mulberry.player.MainActivity.81
|
||
@Override // java.lang.Runnable
|
||
public void run() {
|
||
MainActivity.this.editTags(Collections.singletonList(songCurrent));
|
||
}
|
||
}));
|
||
arrayList.add(new Lists.Item(R.drawable.ic_album, "Go to album", new Runnable() { // from class: com.mulberry.player.MainActivity.82
|
||
@Override // java.lang.Runnable
|
||
public void run() {
|
||
MainActivity.this.goToAlbum(songCurrent);
|
||
}
|
||
}));
|
||
arrayList.add(new Lists.Item(R.drawable.ic_artist, "Go to artist", new Runnable() { // from class: com.mulberry.player.MainActivity.83
|
||
@Override // java.lang.Runnable
|
||
public void run() {
|
||
MainActivity.this.goToArtist(songCurrent);
|
||
}
|
||
}));
|
||
arrayList.add(new Lists.Item(R.drawable.ic_history, "Sleep timer", new Runnable() { // from class: com.mulberry.player.MainActivity.84
|
||
@Override // java.lang.Runnable
|
||
public void run() {
|
||
MainActivity.this.sleepTimer();
|
||
}
|
||
}));
|
||
if (LastFm.anyOn()) {
|
||
arrayList.add(new Lists.Item(R.drawable.ic_favorite, LastFm.enabled() ? "Love on Last.fm" : "Love on ListenBrainz", new Runnable() { // from class: com.mulberry.player.MainActivity.85
|
||
@Override // java.lang.Runnable
|
||
public void run() {
|
||
LastFm.love(songCurrent, true);
|
||
MainActivity.toast("Loved");
|
||
}
|
||
}));
|
||
}
|
||
arrayList.add(new Lists.Item(R.drawable.ic_link, "Share", new Runnable() { // from class: com.mulberry.player.MainActivity.86
|
||
@Override // java.lang.Runnable
|
||
public void run() {
|
||
MainActivity.this.share(songCurrent);
|
||
}
|
||
}));
|
||
arrayList.add(new Lists.Item(R.drawable.ic_stop_fill, "Stop & close", new Runnable() { // from class: com.mulberry.player.MainActivity.87
|
||
@Override // java.lang.Runnable
|
||
public void run() {
|
||
MainActivity.this.closePlayer();
|
||
MainActivity.this.svc.stopAndQuit();
|
||
}
|
||
}));
|
||
Lists.sheet(this, songCurrent.displayTitle(), songCurrent.displayArtist(), arrayList);
|
||
}
|
||
}
|
||
|
||
void lyricsMenu() {
|
||
int i = R.drawable.ic_check;
|
||
String str = App.I.prefs.getStr(Prefs.LYRICS_SOURCE, "auto");
|
||
final boolean bool = App.I.prefs.getBool(Prefs.LYRICS_PLAIN, false);
|
||
ArrayList arrayList = new ArrayList();
|
||
for (final String[] strArr : new String[][]{new String[]{"auto", "Auto (synced first, local last)"}, new String[]{"lrclib", "LRCLIB"}, new String[]{"netease", "NetEase"}, new String[]{"local", "Local .lrc / embedded"}}) {
|
||
arrayList.add(new Lists.Item(strArr[0].equals(str) ? R.drawable.ic_check : R.drawable.ic_lyrics, strArr[1], new Runnable() { // from class: com.mulberry.player.MainActivity.88
|
||
@Override // java.lang.Runnable
|
||
public void run() {
|
||
App.I.prefs.setStr(Prefs.LYRICS_SOURCE, strArr[0]);
|
||
if (MainActivity.this.svc != null) {
|
||
MainActivity.this.svc.reloadLyrics(false);
|
||
}
|
||
}
|
||
}));
|
||
}
|
||
if (!bool) {
|
||
i = R.drawable.ic_text_snippet;
|
||
}
|
||
arrayList.add(new Lists.Item(i, "Plain text (no timing)", new Runnable() { // from class: com.mulberry.player.MainActivity.89
|
||
@Override // java.lang.Runnable
|
||
public void run() {
|
||
App.I.prefs.setBool(Prefs.LYRICS_PLAIN, !bool);
|
||
if (MainActivity.this.svc != null) {
|
||
MainActivity.this.svc.reloadLyrics(false);
|
||
}
|
||
}
|
||
}));
|
||
arrayList.add(new Lists.Item(R.drawable.ic_refresh, "Search again", new Runnable() { // from class: com.mulberry.player.MainActivity.90
|
||
@Override // java.lang.Runnable
|
||
public void run() {
|
||
if (MainActivity.this.svc != null) {
|
||
MainActivity.this.svc.reloadLyrics(true);
|
||
}
|
||
}
|
||
}));
|
||
arrayList.add(new Lists.Item(R.drawable.ic_edit, "Edit / save lyrics…", new Runnable() { // from class: com.mulberry.player.MainActivity.91
|
||
@Override // java.lang.Runnable
|
||
public void run() {
|
||
if (MainActivity.this.svc != null && MainActivity.this.svc.current() != null) {
|
||
TagEditorActivity.open(MainActivity.this, Collections.singletonList(MainActivity.this.svc.current()), 2);
|
||
}
|
||
}
|
||
}));
|
||
Lists.sheet(this, "Lyrics source", null, arrayList);
|
||
}
|
||
|
||
void sleepTimer() {
|
||
if (this.svc != null) {
|
||
long jSleepRemaining = this.svc.sleepRemaining();
|
||
String str = jSleepRemaining > 0 ? "Stops in " + Draw.time(jSleepRemaining) : jSleepRemaining < 0 ? "Stops after this song" : "Off";
|
||
ArrayList arrayList = new ArrayList();
|
||
for (final int i : new int[]{10, 15, 30, 45, 60, 90}) {
|
||
arrayList.add(new Lists.Item(R.drawable.ic_history, i + " minutes", new Runnable() { // from class: com.mulberry.player.MainActivity.92
|
||
@Override // java.lang.Runnable
|
||
public void run() {
|
||
MainActivity.this.svc.sleepIn(i);
|
||
MainActivity.toast("Sleep timer: " + i + " min");
|
||
}
|
||
}));
|
||
}
|
||
arrayList.add(new Lists.Item(R.drawable.ic_music_note, "End of this song", new Runnable() { // from class: com.mulberry.player.MainActivity.93
|
||
@Override // java.lang.Runnable
|
||
public void run() {
|
||
MainActivity.this.svc.sleepAtEndOfTrack();
|
||
MainActivity.toast("Stops after this song");
|
||
}
|
||
}));
|
||
arrayList.add(new Lists.Item(R.drawable.ic_close, "Turn off", new Runnable() { // from class: com.mulberry.player.MainActivity.94
|
||
@Override // java.lang.Runnable
|
||
public void run() {
|
||
MainActivity.this.svc.sleepIn(0);
|
||
MainActivity.toast("Sleep timer off");
|
||
}
|
||
}));
|
||
Lists.sheet(this, "Sleep timer", str, arrayList);
|
||
}
|
||
}
|
||
|
||
void showQueue() {
|
||
if (this.svc != null) {
|
||
final Dialog dialog = new Dialog(this);
|
||
dialog.requestWindowFeature(1);
|
||
LinearLayout linearLayoutCol = Ui.col(this);
|
||
Lists.GradientBg(linearLayoutCol, this);
|
||
linearLayoutCol.setPadding(Ui.dp(this, 6.0f), Ui.dp(this, 14.0f), Ui.dp(this, 6.0f), Ui.dp(this, 10.0f));
|
||
LinearLayout linearLayoutRow = Ui.row(this);
|
||
linearLayoutRow.setPadding(Ui.dp(this, 14.0f), 0, Ui.dp(this, 6.0f), Ui.dp(this, 6.0f));
|
||
linearLayoutRow.addView(Ui.single(this, "Up next · " + this.svc.queue().size() + " songs", 17.0f, 11, true), Ui.lpw(-2, 1.0f));
|
||
linearLayoutRow.addView(Ui.iconButton(this, R.drawable.ic_save, 12, 40, new View.OnClickListener() { // from class: com.mulberry.player.MainActivity.95
|
||
@Override // android.view.View.OnClickListener
|
||
public void onClick(View view) {
|
||
dialog.dismiss();
|
||
MainActivity.this.askText("Save queue as playlist", "Name", "Queue", new TextCb() { // from class: com.mulberry.player.MainActivity.95.1
|
||
@Override // com.mulberry.player.MainActivity.TextCb
|
||
public void ok(String str) {
|
||
Playlists.create(str, new ArrayList(MainActivity.this.svc.queue()));
|
||
MainActivity.toast("Saved");
|
||
}
|
||
});
|
||
}
|
||
}));
|
||
linearLayoutRow.addView(Ui.iconButton(this, R.drawable.ic_clear_all, 12, 40, new View.OnClickListener() { // from class: com.mulberry.player.MainActivity.96
|
||
@Override // android.view.View.OnClickListener
|
||
public void onClick(View view) {
|
||
dialog.dismiss();
|
||
MainActivity.this.closePlayer();
|
||
MainActivity.this.svc.clearQueue();
|
||
}
|
||
}));
|
||
linearLayoutCol.addView(linearLayoutRow);
|
||
ListView list = Lists.list(this);
|
||
Lists.SongAdapter[] songAdapterArr = new Lists.SongAdapter[1];
|
||
songAdapterArr[0] = new Lists.SongAdapter(this, new AnonymousClass97(songAdapterArr));
|
||
songAdapterArr[0].playing = this.svc.current();
|
||
songAdapterArr[0].set(new ArrayList(this.svc.queue()));
|
||
list.setAdapter((ListAdapter) songAdapterArr[0]);
|
||
linearLayoutCol.addView(list, new LinearLayout.LayoutParams(-1, (int) (getResources().getDisplayMetrics().heightPixels * 0.62f)));
|
||
list.setSelection(Math.max(0, this.svc.index() - 1));
|
||
dialog.setContentView(linearLayoutCol);
|
||
Window window = dialog.getWindow();
|
||
if (window != null) {
|
||
window.setBackgroundDrawable(new ColorDrawable(0));
|
||
window.setGravity(80);
|
||
window.setLayout(-1, -2);
|
||
window.setWindowAnimations(android.R.style.Animation_InputMethod);
|
||
}
|
||
dialog.show();
|
||
}
|
||
}
|
||
|
||
/* JADX INFO: renamed from: com.mulberry.player.MainActivity$97, reason: invalid class name */
|
||
class AnonymousClass97 implements Lists.SongClick {
|
||
final /* synthetic */ Lists.SongAdapter[] val$holder;
|
||
|
||
AnonymousClass97(Lists.SongAdapter[] songAdapterArr) {
|
||
this.val$holder = songAdapterArr;
|
||
}
|
||
|
||
@Override // com.mulberry.player.Lists.SongClick
|
||
public void click(List<Song> list, int i) {
|
||
MainActivity.this.svc.jump(i);
|
||
this.val$holder[0].playing = MainActivity.this.svc.current();
|
||
this.val$holder[0].notifyDataSetChanged();
|
||
}
|
||
|
||
@Override // com.mulberry.player.Lists.SongClick
|
||
public void longClick(List<Song> list, final int i, View view) {
|
||
final Song song = list.get(i);
|
||
ArrayList arrayList = new ArrayList();
|
||
arrayList.add(new Lists.Item(R.drawable.ic_play_arrow_fill, "Play now", new Runnable() { // from class: com.mulberry.player.MainActivity.97.1
|
||
@Override // java.lang.Runnable
|
||
public void run() {
|
||
MainActivity.this.svc.jump(i);
|
||
AnonymousClass97.this.refresh();
|
||
}
|
||
}));
|
||
arrayList.add(new Lists.Item(R.drawable.ic_drag_indicator, "Move up", new Runnable() { // from class: com.mulberry.player.MainActivity.97.2
|
||
@Override // java.lang.Runnable
|
||
public void run() {
|
||
MainActivity.this.svc.move(i, i - 1);
|
||
AnonymousClass97.this.refresh();
|
||
}
|
||
}));
|
||
arrayList.add(new Lists.Item(R.drawable.ic_expand_more, "Move down", new Runnable() { // from class: com.mulberry.player.MainActivity.97.3
|
||
@Override // java.lang.Runnable
|
||
public void run() {
|
||
MainActivity.this.svc.move(i, i + 1);
|
||
AnonymousClass97.this.refresh();
|
||
}
|
||
}));
|
||
arrayList.add(new Lists.Item(R.drawable.ic_queue_play_next, "Play after current", new Runnable() { // from class: com.mulberry.player.MainActivity.97.4
|
||
@Override // java.lang.Runnable
|
||
public void run() {
|
||
MainActivity.this.svc.move(i, (i > MainActivity.this.svc.index() ? 1 : 0) + MainActivity.this.svc.index());
|
||
AnonymousClass97.this.refresh();
|
||
}
|
||
}));
|
||
arrayList.add(new Lists.Item(R.drawable.ic_delete, "Remove from queue", new Runnable() { // from class: com.mulberry.player.MainActivity.97.5
|
||
@Override // java.lang.Runnable
|
||
public void run() {
|
||
MainActivity.this.svc.removeAt(i);
|
||
AnonymousClass97.this.refresh();
|
||
}
|
||
}));
|
||
arrayList.add(new Lists.Item(R.drawable.ic_edit, "Edit tags…", new Runnable() { // from class: com.mulberry.player.MainActivity.97.6
|
||
@Override // java.lang.Runnable
|
||
public void run() {
|
||
MainActivity.this.editTags(Collections.singletonList(song));
|
||
}
|
||
}));
|
||
Lists.sheet(MainActivity.this, song.displayTitle(), song.displayArtist(), arrayList);
|
||
}
|
||
|
||
void refresh() {
|
||
this.val$holder[0].playing = MainActivity.this.svc.current();
|
||
this.val$holder[0].set(new ArrayList(MainActivity.this.svc.queue()));
|
||
}
|
||
}
|
||
|
||
@Override // com.mulberry.player.MusicService.Listener
|
||
public void onTrackChanged() {
|
||
if (this.svc != null) {
|
||
Song songCurrent = this.svc.current();
|
||
boolean z = songCurrent != null;
|
||
if (!this.player.open) {
|
||
this.mini.setVisibility(z ? 0 : 8);
|
||
}
|
||
applyInsets();
|
||
if (z) {
|
||
this.miniTitle.setText(songCurrent.displayTitle());
|
||
this.miniArtist.setText(songCurrent.displayArtist());
|
||
this.miniCookie.setCover(this.svc.art());
|
||
this.miniSeek.set(this.svc.position(), this.svc.duration());
|
||
}
|
||
this.songAdapter.playing = songCurrent;
|
||
this.songAdapter.notifyDataSetChanged();
|
||
refreshTopDetail();
|
||
if ("album".equals(App.I.prefs.getStr(Prefs.COLOR_SOURCE, "system"))) {
|
||
Ui.recolor();
|
||
}
|
||
if (this.player.open) {
|
||
this.player.updateTrack();
|
||
}
|
||
if (this.player.open && !z) {
|
||
closePlayer();
|
||
}
|
||
onStateChanged();
|
||
}
|
||
}
|
||
|
||
@Override // com.mulberry.player.MusicService.Listener
|
||
public void onStateChanged() {
|
||
if (this.svc != null) {
|
||
this.miniPlay.setPlaying(this.svc.isPlaying() || this.svc.isLoading());
|
||
this.miniCookie.setPlaying(this.svc.isPlaying());
|
||
this.miniSeek.setPlaying(this.svc.isPlaying());
|
||
this.bassShape.setPlaying(this.svc.isPlaying());
|
||
if (this.player.open) {
|
||
this.player.updateState();
|
||
}
|
||
}
|
||
}
|
||
|
||
@Override // com.mulberry.player.MusicService.Listener
|
||
public void onQueueChanged() {
|
||
refreshTopDetail();
|
||
}
|
||
|
||
@Override // com.mulberry.player.MusicService.Listener
|
||
public void onLyrics() {
|
||
if (this.player.open) {
|
||
this.player.updateLyrics();
|
||
}
|
||
}
|
||
|
||
void handleIntent(Intent intent) {
|
||
if (intent != null) {
|
||
if (intent.getBooleanExtra("open_player", false)) {
|
||
intent.removeExtra("open_player");
|
||
App.MAIN.postDelayed(new Runnable() { // from class: com.mulberry.player.MainActivity.98
|
||
@Override // java.lang.Runnable
|
||
public void run() {
|
||
MainActivity.this.openPlayer();
|
||
}
|
||
}, 300L);
|
||
return;
|
||
}
|
||
if ("android.intent.action.VIEW".equals(intent.getAction()) && intent.getData() != null) {
|
||
final Uri data = intent.getData();
|
||
String type = intent.getType() == null ? FrameBodyCOMM.DEFAULT : intent.getType();
|
||
String lowerCase = Playlists.displayName(this, data).toLowerCase(Locale.ROOT);
|
||
intent.setAction(null);
|
||
if (type.contains("mpegurl") || type.contains("scpls") || lowerCase.endsWith(".m3u") || lowerCase.endsWith(".m3u8") || lowerCase.endsWith(".pls")) {
|
||
doImport(data);
|
||
showPage(1, false);
|
||
return;
|
||
}
|
||
final Song song = new Song();
|
||
song.uri = data.toString();
|
||
song.title = Playlists.displayName(this, data);
|
||
int iLastIndexOf = song.title.lastIndexOf(46);
|
||
if (iLastIndexOf > 0) {
|
||
song.title = song.title.substring(0, iLastIndexOf);
|
||
}
|
||
song.mime = type;
|
||
if ("file".equals(data.getScheme())) {
|
||
song.path = data.getPath();
|
||
Song songByPath = App.I.library.byPath(song.path);
|
||
if (songByPath != null) {
|
||
playOpened(songByPath);
|
||
return;
|
||
}
|
||
}
|
||
App.IO.execute(new Runnable() { // from class: com.mulberry.player.MainActivity.99
|
||
@Override // java.lang.Runnable
|
||
public void run() {
|
||
MediaMetadataRetriever mediaMetadataRetriever = new MediaMetadataRetriever();
|
||
try {
|
||
mediaMetadataRetriever.setDataSource(MainActivity.this, data);
|
||
String strExtractMetadata = mediaMetadataRetriever.extractMetadata(7);
|
||
String strExtractMetadata2 = mediaMetadataRetriever.extractMetadata(2);
|
||
String strExtractMetadata3 = mediaMetadataRetriever.extractMetadata(1);
|
||
String strExtractMetadata4 = mediaMetadataRetriever.extractMetadata(9);
|
||
if (strExtractMetadata != null && strExtractMetadata.length() > 0) {
|
||
song.title = strExtractMetadata;
|
||
}
|
||
if (strExtractMetadata2 != null) {
|
||
song.artist = strExtractMetadata2;
|
||
}
|
||
if (strExtractMetadata3 != null) {
|
||
song.album = strExtractMetadata3;
|
||
}
|
||
if (strExtractMetadata4 != null) {
|
||
song.duration = Long.parseLong(strExtractMetadata4);
|
||
}
|
||
try {
|
||
mediaMetadataRetriever.release();
|
||
} catch (Exception e) {
|
||
}
|
||
} catch (Exception e2) {
|
||
try {
|
||
mediaMetadataRetriever.release();
|
||
} catch (Exception e3) {
|
||
}
|
||
} catch (Throwable th) {
|
||
try {
|
||
mediaMetadataRetriever.release();
|
||
} catch (Exception e4) {
|
||
}
|
||
throw th;
|
||
}
|
||
App.ui(new Runnable() { // from class: com.mulberry.player.MainActivity.99.1
|
||
@Override // java.lang.Runnable
|
||
public void run() {
|
||
MainActivity.this.playOpened(song);
|
||
}
|
||
});
|
||
}
|
||
});
|
||
}
|
||
}
|
||
}
|
||
|
||
void playOpened(final Song song) {
|
||
withService(new Runnable() { // from class: com.mulberry.player.MainActivity.100
|
||
@Override // java.lang.Runnable
|
||
public void run() {
|
||
MainActivity.this.svc.playList(Collections.singletonList(song), 0);
|
||
App.MAIN.postDelayed(new Runnable() { // from class: com.mulberry.player.MainActivity.100.1
|
||
@Override // java.lang.Runnable
|
||
public void run() {
|
||
MainActivity.this.openPlayer();
|
||
}
|
||
}, 400L);
|
||
}
|
||
});
|
||
}
|
||
|
||
static void tagsEdited() {
|
||
MusicService musicService = MusicService.INSTANCE;
|
||
if (musicService != null) {
|
||
musicService.songEdited();
|
||
}
|
||
App.I.library.refresh();
|
||
MainActivity mainActivity = CURRENT;
|
||
if (mainActivity != null) {
|
||
mainActivity.songAdapter.notifyDataSetChanged();
|
||
mainActivity.groupAdapter.notifyDataSetChanged();
|
||
mainActivity.refreshTopDetail();
|
||
}
|
||
}
|
||
}
|