code refactor
This commit is contained in:
parent
8a731b5073
commit
f386a2cf07
7 changed files with 1529 additions and 1478 deletions
|
@ -1,36 +1,13 @@
|
|||
package code.name.monkey.retromusic.dialogs;
|
||||
|
||||
/*
|
||||
import android.app.Dialog;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v4.app.DialogFragment;
|
||||
import android.text.Html;
|
||||
|
||||
import com.afollestad.materialdialogs.DialogAction;
|
||||
import com.afollestad.materialdialogs.MaterialDialog;
|
||||
import code.name.monkey.retromusic.model.Song;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import code.name.monkey.retromusic.R;
|
||||
|
||||
import code.name.monkey.retromusic.util.MusicUtil;
|
||||
|
||||
*/
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.design.widget.BottomSheetDialogFragment;
|
||||
import android.text.Html;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import butterknife.OnClick;
|
||||
|
@ -38,12 +15,10 @@ import code.name.monkey.retromusic.R;
|
|||
import code.name.monkey.retromusic.model.Song;
|
||||
import code.name.monkey.retromusic.util.MusicUtil;
|
||||
import code.name.monkey.retromusic.views.RoundedBottomSheetDialogFragment;
|
||||
|
||||
/**
|
||||
* @author Karim Abou Zeid (kabouzeid), Aidan Follestad (afollestad)
|
||||
*/
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class DeleteSongsDialog extends RoundedBottomSheetDialogFragment {
|
||||
|
||||
@BindView(R.id.action_delete)
|
||||
TextView delete;
|
||||
@BindView(R.id.title)
|
||||
|
@ -69,12 +44,16 @@ public class DeleteSongsDialog extends RoundedBottomSheetDialogFragment {
|
|||
|
||||
@OnClick({R.id.action_cancel, R.id.action_delete})
|
||||
void actions(View view) {
|
||||
//noinspection ConstantConditions
|
||||
final ArrayList<Song> songs = getArguments().getParcelableArrayList("songs");
|
||||
switch (view.getId()) {
|
||||
case R.id.action_delete:
|
||||
if (getActivity() == null)
|
||||
if (getActivity() == null) {
|
||||
return;
|
||||
}
|
||||
if (songs != null) {
|
||||
MusicUtil.deleteTracks(getActivity(), songs);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
}
|
||||
|
@ -84,29 +63,30 @@ public class DeleteSongsDialog extends RoundedBottomSheetDialogFragment {
|
|||
@Override
|
||||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
//noinspection unchecked
|
||||
//noinspection unchecked,ConstantConditions
|
||||
final ArrayList<Song> songs = getArguments().getParcelableArrayList("songs");
|
||||
int title;
|
||||
CharSequence content;
|
||||
if (songs != null && songs.size() > 1) {
|
||||
if (songs != null) {
|
||||
if (songs.size() > 1) {
|
||||
title = R.string.delete_songs_title;
|
||||
content = Html.fromHtml(getString(R.string.delete_x_songs, songs.size()));
|
||||
} else {
|
||||
title = R.string.delete_song_title;
|
||||
content = Html.fromHtml(getString(R.string.delete_song_x, songs.get(0).title));
|
||||
}
|
||||
|
||||
this.title.setText(title);
|
||||
this.delete.setText(content);
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
|
||||
@Nullable Bundle savedInstanceState) {
|
||||
View layout = inflater.inflate(R.layout.dialog_delete_songs, container, false);
|
||||
ButterKnife.bind(this, layout);
|
||||
return layout;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -15,13 +15,13 @@ import android.support.design.widget.Snackbar;
|
|||
import android.support.v4.app.ActivityCompat;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.View;
|
||||
|
||||
import code.name.monkey.appthemehelper.ThemeStore;
|
||||
import code.name.monkey.retromusic.R;
|
||||
import uk.co.chrisjenx.calligraphy.CalligraphyContextWrapper;
|
||||
|
||||
|
||||
public abstract class AbsBaseActivity extends AbsThemeActivity {
|
||||
|
||||
public static final int PERMISSION_REQUEST = 100;
|
||||
private boolean hadPermissions;
|
||||
private String[] permissions;
|
||||
|
@ -38,8 +38,6 @@ public abstract class AbsBaseActivity extends AbsThemeActivity {
|
|||
hadPermissions = hasPermissions();
|
||||
|
||||
setPermissionDeniedMessage(null);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -95,7 +93,8 @@ public abstract class AbsBaseActivity extends AbsThemeActivity {
|
|||
}
|
||||
|
||||
private String getPermissionDeniedMessage() {
|
||||
return permissionDeniedMessage == null ? getString(R.string.permissions_denied) : permissionDeniedMessage;
|
||||
return permissionDeniedMessage == null ? getString(R.string.permissions_denied)
|
||||
: permissionDeniedMessage;
|
||||
}
|
||||
|
||||
protected void setPermissionDeniedMessage(String message) {
|
||||
|
@ -120,12 +119,14 @@ public abstract class AbsBaseActivity extends AbsThemeActivity {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
|
||||
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
|
||||
@NonNull int[] grantResults) {
|
||||
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
||||
if (requestCode == PERMISSION_REQUEST) {
|
||||
for (int grantResult : grantResults) {
|
||||
if (grantResult != PackageManager.PERMISSION_GRANTED) {
|
||||
if (ActivityCompat.shouldShowRequestPermissionRationale(AbsBaseActivity.this, Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
|
||||
if (ActivityCompat.shouldShowRequestPermissionRationale(AbsBaseActivity.this,
|
||||
Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
|
||||
//User has deny from permission dialog
|
||||
Snackbar.make(getSnackBarContainer(), getPermissionDeniedMessage(),
|
||||
Snackbar.LENGTH_INDEFINITE)
|
||||
|
|
|
@ -11,10 +11,6 @@ import android.view.View;
|
|||
import android.view.ViewGroup;
|
||||
import android.view.ViewTreeObserver;
|
||||
import android.view.animation.PathInterpolator;
|
||||
|
||||
import com.sothree.slidinguppanel.SlidingUpPanelLayout;
|
||||
import com.sothree.slidinguppanel.SlidingUpPanelLayout.PanelState;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import code.name.monkey.appthemehelper.ThemeStore;
|
||||
|
@ -39,6 +35,8 @@ import code.name.monkey.retromusic.ui.fragments.player.simple.SimplePlayerFragme
|
|||
import code.name.monkey.retromusic.util.PreferenceUtil;
|
||||
import code.name.monkey.retromusic.util.ViewUtil;
|
||||
import code.name.monkey.retromusic.views.BottomNavigationViewEx;
|
||||
import com.sothree.slidinguppanel.SlidingUpPanelLayout;
|
||||
import com.sothree.slidinguppanel.SlidingUpPanelLayout.PanelState;
|
||||
|
||||
public abstract class AbsSlidingMusicPanelActivity extends AbsMusicServiceActivity implements
|
||||
SlidingUpPanelLayout.PanelSlideListener,
|
||||
|
@ -253,8 +251,9 @@ public abstract class AbsSlidingMusicPanelActivity extends AbsMusicServiceActivi
|
|||
|| currentNowPlayingScreen == NowPlayingScreen.PLAIN
|
||||
|| currentNowPlayingScreen == NowPlayingScreen.SIMPLE
|
||||
|| currentNowPlayingScreen == NowPlayingScreen.NORMAL
|
||||
|| currentNowPlayingScreen == NowPlayingScreen.ADAPTIVE)
|
||||
|| currentNowPlayingScreen == NowPlayingScreen.TINY);
|
||||
|| currentNowPlayingScreen == NowPlayingScreen.ADAPTIVE
|
||||
|| currentNowPlayingScreen == NowPlayingScreen.TINY
|
||||
|| currentNowPlayingScreen == NowPlayingScreen.MATERIAL));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -25,21 +25,6 @@ import android.view.ViewGroup;
|
|||
import android.webkit.MimeTypeMap;
|
||||
import android.widget.PopupMenu;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.afollestad.materialcab.MaterialCab;
|
||||
import com.afollestad.materialdialogs.MaterialDialog;
|
||||
import com.simplecityapps.recyclerview_fastscroll.views.FastScrollRecyclerView;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileFilter;
|
||||
import java.io.IOException;
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import butterknife.Unbinder;
|
||||
|
@ -65,6 +50,18 @@ import code.name.monkey.retromusic.util.PreferenceUtil;
|
|||
import code.name.monkey.retromusic.util.RetroColorUtil;
|
||||
import code.name.monkey.retromusic.util.ViewUtil;
|
||||
import code.name.monkey.retromusic.views.BreadCrumbLayout;
|
||||
import com.afollestad.materialcab.MaterialCab;
|
||||
import com.afollestad.materialdialogs.MaterialDialog;
|
||||
import com.simplecityapps.recyclerview_fastscroll.views.FastScrollRecyclerView;
|
||||
import java.io.File;
|
||||
import java.io.FileFilter;
|
||||
import java.io.IOException;
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
public class FoldersFragment extends AbsMainActivityFragment implements
|
||||
MainActivityFragmentCallbacks,
|
||||
|
@ -72,7 +69,8 @@ public class FoldersFragment extends AbsMainActivityFragment implements
|
|||
AppBarLayout.OnOffsetChangedListener, LoaderManager.LoaderCallbacks<List<File>> {
|
||||
|
||||
public static final String TAG = FoldersFragment.class.getSimpleName();
|
||||
public static final FileFilter AUDIO_FILE_FILTER = file -> !file.isHidden() && (file.isDirectory() ||
|
||||
public static final FileFilter AUDIO_FILE_FILTER = file -> !file.isHidden() && (file.isDirectory()
|
||||
||
|
||||
FileUtil.fileIsMimeType(file, "audio/*", MimeTypeMap.getSingleton()) ||
|
||||
FileUtil.fileIsMimeType(file, "application/opus", MimeTypeMap.getSingleton()) ||
|
||||
FileUtil.fileIsMimeType(file, "application/ogg", MimeTypeMap.getSingleton()));
|
||||
|
@ -226,9 +224,12 @@ public class FoldersFragment extends AbsMainActivityFragment implements
|
|||
appbar.setBackgroundColor(primaryColor);
|
||||
toolbar.setBackgroundColor(primaryColor);
|
||||
//breadCrumbs.setBackgroundColor(primaryColor);
|
||||
breadCrumbs.setActivatedContentColor(ToolbarContentTintHelper.toolbarTitleColor(getActivity(), primaryColor));
|
||||
breadCrumbs.setDeactivatedContentColor(ToolbarContentTintHelper.toolbarSubtitleColor(getActivity(), primaryColor));
|
||||
appbar.addOnOffsetChangedListener((appBarLayout, verticalOffset) -> getMainActivity().setLightStatusbar(!ATHUtil.isWindowBackgroundDark(getContext())));
|
||||
breadCrumbs.setActivatedContentColor(
|
||||
ToolbarContentTintHelper.toolbarTitleColor(getActivity(), primaryColor));
|
||||
breadCrumbs.setDeactivatedContentColor(
|
||||
ToolbarContentTintHelper.toolbarSubtitleColor(getActivity(), primaryColor));
|
||||
appbar.addOnOffsetChangedListener((appBarLayout, verticalOffset) -> getMainActivity()
|
||||
.setLightStatusbar(!ATHUtil.isWindowBackgroundDark(getContext())));
|
||||
}
|
||||
|
||||
private void setUpToolbar() {
|
||||
|
@ -244,13 +245,15 @@ public class FoldersFragment extends AbsMainActivityFragment implements
|
|||
|
||||
private void setUpRecyclerView() {
|
||||
//noinspection ConstantConditions
|
||||
ViewUtil.setUpFastScrollRecyclerViewColor(getActivity(), recyclerView, ThemeStore.accentColor(getActivity()));
|
||||
ViewUtil.setUpFastScrollRecyclerViewColor(getActivity(), recyclerView,
|
||||
ThemeStore.accentColor(getActivity()));
|
||||
recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
|
||||
appbar.addOnOffsetChangedListener(this);
|
||||
}
|
||||
|
||||
private void setUpAdapter() {
|
||||
adapter = new SongFileAdapter(getMainActivity(), new LinkedList<File>(), R.layout.item_list, this, this);
|
||||
adapter = new SongFileAdapter(getMainActivity(), new LinkedList<File>(), R.layout.item_list,
|
||||
this, this);
|
||||
adapter.registerAdapterDataObserver(new RecyclerView.AdapterDataObserver() {
|
||||
@Override
|
||||
public void onChanged() {
|
||||
|
@ -291,7 +294,9 @@ public class FoldersFragment extends AbsMainActivityFragment implements
|
|||
@NonNull
|
||||
@Override
|
||||
public MaterialCab openCab(int menuRes, MaterialCab.Callback callback) {
|
||||
if (cab != null && cab.isActive()) cab.finish();
|
||||
if (cab != null && cab.isActive()) {
|
||||
cab.finish();
|
||||
}
|
||||
cab = new MaterialCab(getMainActivity(), R.id.cab_stub)
|
||||
.setMenu(menuRes)
|
||||
.setCloseDrawableRes(R.drawable.ic_close_white_24dp)
|
||||
|
@ -305,7 +310,8 @@ public class FoldersFragment extends AbsMainActivityFragment implements
|
|||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||
super.onCreateOptionsMenu(menu, inflater);
|
||||
inflater.inflate(R.menu.menu_folders, menu);
|
||||
ToolbarContentTintHelper.handleOnCreateOptionsMenu(getActivity(), toolbar, menu, ATHToolbarActivity.getToolbarBackgroundColor(toolbar));
|
||||
ToolbarContentTintHelper.handleOnCreateOptionsMenu(getActivity(), toolbar, menu,
|
||||
ATHToolbarActivity.getToolbarBackgroundColor(toolbar));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -327,13 +333,16 @@ public class FoldersFragment extends AbsMainActivityFragment implements
|
|||
getActivity().onBackPressed();
|
||||
break;
|
||||
case R.id.action_go_to_start_directory:
|
||||
setCrumb(new BreadCrumbLayout.Crumb(tryGetCanonicalFile(PreferenceUtil.getInstance(getActivity()).getStartDirectory())), true);
|
||||
setCrumb(new BreadCrumbLayout.Crumb(
|
||||
tryGetCanonicalFile(PreferenceUtil.getInstance(getActivity()).getStartDirectory())),
|
||||
true);
|
||||
return true;
|
||||
case R.id.action_scan:
|
||||
BreadCrumbLayout.Crumb crumb = getActiveCrumb();
|
||||
if (crumb != null) {
|
||||
//noinspection Convert2MethodRef
|
||||
new ListPathsAsyncTask(getActivity(), paths -> scanPaths(paths)).execute(new ListPathsAsyncTask.LoadingInfo(crumb.getFile(), AUDIO_FILE_FILTER));
|
||||
new ListPathsAsyncTask(getActivity(), paths -> scanPaths(paths))
|
||||
.execute(new ListPathsAsyncTask.LoadingInfo(crumb.getFile(), AUDIO_FILE_FILTER));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -346,7 +355,8 @@ public class FoldersFragment extends AbsMainActivityFragment implements
|
|||
if (file.isDirectory()) {
|
||||
setCrumb(new BreadCrumbLayout.Crumb(file), true);
|
||||
} else {
|
||||
FileFilter fileFilter = pathname -> !pathname.isDirectory() && AUDIO_FILE_FILTER.accept(pathname);
|
||||
FileFilter fileFilter = pathname -> !pathname.isDirectory() && AUDIO_FILE_FILTER
|
||||
.accept(pathname);
|
||||
new ListSongsAsyncTask(getActivity(), file, (songs, extra) -> {
|
||||
File file1 = (File) extra;
|
||||
int startIndex = -1;
|
||||
|
@ -360,19 +370,26 @@ public class FoldersFragment extends AbsMainActivityFragment implements
|
|||
MusicPlayerRemote.openQueue(songs, startIndex, true);
|
||||
} else {
|
||||
final File finalFile = file1;
|
||||
Snackbar.make(coordinatorLayout, Html.fromHtml(String.format(getString(R.string.not_listed_in_media_store), file1.getName())), Snackbar.LENGTH_LONG)
|
||||
.setAction(R.string.action_scan, v -> new ListPathsAsyncTask(getActivity(), paths -> scanPaths(paths)).execute(new ListPathsAsyncTask.LoadingInfo(finalFile, AUDIO_FILE_FILTER)))
|
||||
Snackbar.make(coordinatorLayout, Html.fromHtml(
|
||||
String.format(getString(R.string.not_listed_in_media_store), file1.getName())),
|
||||
Snackbar.LENGTH_LONG)
|
||||
.setAction(R.string.action_scan,
|
||||
v -> new ListPathsAsyncTask(getActivity(), paths -> scanPaths(paths))
|
||||
.execute(new ListPathsAsyncTask.LoadingInfo(finalFile, AUDIO_FILE_FILTER)))
|
||||
.setActionTextColor(ThemeStore.accentColor(getActivity()))
|
||||
.show();
|
||||
}
|
||||
}).execute(new ListSongsAsyncTask.LoadingInfo(toList(file.getParentFile()), fileFilter, getFileComparator()));
|
||||
}).execute(new ListSongsAsyncTask.LoadingInfo(toList(file.getParentFile()), fileFilter,
|
||||
getFileComparator()));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMultipleItemAction(MenuItem item, ArrayList<File> files) {
|
||||
final int itemId = item.getItemId();
|
||||
new ListSongsAsyncTask(getActivity(), null, (songs, extra) -> SongsMenuHelper.handleMenuClick(getActivity(), songs, itemId)).execute(new ListSongsAsyncTask.LoadingInfo(files, AUDIO_FILE_FILTER, getFileComparator()));
|
||||
new ListSongsAsyncTask(getActivity(), null,
|
||||
(songs, extra) -> SongsMenuHelper.handleMenuClick(getActivity(), songs, itemId))
|
||||
.execute(new ListSongsAsyncTask.LoadingInfo(files, AUDIO_FILE_FILTER, getFileComparator()));
|
||||
}
|
||||
|
||||
private ArrayList<File> toList(File file) {
|
||||
|
@ -397,14 +414,22 @@ public class FoldersFragment extends AbsMainActivityFragment implements
|
|||
case R.id.action_add_to_current_playing:
|
||||
case R.id.action_add_to_playlist:
|
||||
case R.id.action_delete_from_device:
|
||||
new ListSongsAsyncTask(getActivity(), null, (songs, extra) -> SongsMenuHelper.handleMenuClick(getActivity(), songs, itemId)).execute(new ListSongsAsyncTask.LoadingInfo(toList(file), AUDIO_FILE_FILTER, getFileComparator()));
|
||||
new ListSongsAsyncTask(getActivity(), null, (songs, extra) -> {
|
||||
if (!songs.isEmpty()) {
|
||||
SongsMenuHelper.handleMenuClick(getActivity(), songs, itemId);
|
||||
}
|
||||
}).execute(new ListSongsAsyncTask.LoadingInfo(toList(file), AUDIO_FILE_FILTER,
|
||||
getFileComparator()));
|
||||
return true;
|
||||
case R.id.action_set_as_start_directory:
|
||||
PreferenceUtil.getInstance(getActivity()).setStartDirectory(file);
|
||||
Toast.makeText(getActivity(), String.format(getString(R.string.new_start_directory), file.getPath()), Toast.LENGTH_SHORT).show();
|
||||
Toast.makeText(getActivity(),
|
||||
String.format(getString(R.string.new_start_directory), file.getPath()),
|
||||
Toast.LENGTH_SHORT).show();
|
||||
return true;
|
||||
case R.id.action_scan:
|
||||
new ListPathsAsyncTask(getActivity(), paths -> scanPaths(paths)).execute(new ListPathsAsyncTask.LoadingInfo(file, AUDIO_FILE_FILTER));
|
||||
new ListPathsAsyncTask(getActivity(), paths -> scanPaths(paths))
|
||||
.execute(new ListPathsAsyncTask.LoadingInfo(file, AUDIO_FILE_FILTER));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
@ -424,10 +449,14 @@ public class FoldersFragment extends AbsMainActivityFragment implements
|
|||
case R.id.action_details:
|
||||
case R.id.action_set_as_ringtone:
|
||||
case R.id.action_delete_from_device:
|
||||
new ListSongsAsyncTask(getActivity(), null, (songs, extra) -> SongMenuHelper.handleMenuClick(getActivity(), songs.get(0), itemId)).execute(new ListSongsAsyncTask.LoadingInfo(toList(file), AUDIO_FILE_FILTER, getFileComparator()));
|
||||
new ListSongsAsyncTask(getActivity(), null, (songs, extra) -> SongMenuHelper
|
||||
.handleMenuClick(getActivity(), songs.get(0), itemId)).execute(
|
||||
new ListSongsAsyncTask.LoadingInfo(toList(file), AUDIO_FILE_FILTER,
|
||||
getFileComparator()));
|
||||
return true;
|
||||
case R.id.action_scan:
|
||||
new ListPathsAsyncTask(getActivity(), paths -> scanPaths(paths)).execute(new ListPathsAsyncTask.LoadingInfo(file, AUDIO_FILE_FILTER));
|
||||
new ListPathsAsyncTask(getActivity(), paths -> scanPaths(paths))
|
||||
.execute(new ListPathsAsyncTask.LoadingInfo(file, AUDIO_FILE_FILTER));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
@ -438,21 +467,26 @@ public class FoldersFragment extends AbsMainActivityFragment implements
|
|||
|
||||
@Override
|
||||
public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
|
||||
container.setPadding(container.getPaddingLeft(), container.getPaddingTop(), container.getPaddingRight(), appbar.getTotalScrollRange() + verticalOffset);
|
||||
container.setPadding(container.getPaddingLeft(), container.getPaddingTop(),
|
||||
container.getPaddingRight(), appbar.getTotalScrollRange() + verticalOffset);
|
||||
}
|
||||
|
||||
private void checkIsEmpty() {
|
||||
if (empty != null) {
|
||||
empty.setVisibility(adapter == null || adapter.getItemCount() == 0 ? View.VISIBLE : View.GONE);
|
||||
empty
|
||||
.setVisibility(adapter == null || adapter.getItemCount() == 0 ? View.VISIBLE : View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
private void scanPaths(@Nullable String[] toBeScanned) {
|
||||
if (getActivity() == null) return;
|
||||
if (getActivity() == null) {
|
||||
return;
|
||||
}
|
||||
if (toBeScanned == null || toBeScanned.length < 1) {
|
||||
Toast.makeText(getActivity(), R.string.nothing_to_scan, Toast.LENGTH_SHORT).show();
|
||||
} else {
|
||||
MediaScannerConnection.scanFile(getActivity().getApplicationContext(), toBeScanned, null, new UpdateToastMediaScannerCompletionListener(getActivity(), toBeScanned));
|
||||
MediaScannerConnection.scanFile(getActivity().getApplicationContext(), toBeScanned, null,
|
||||
new UpdateToastMediaScannerCompletionListener(getActivity(), toBeScanned));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -482,6 +516,7 @@ public class FoldersFragment extends AbsMainActivityFragment implements
|
|||
}
|
||||
|
||||
private static class AsyncFileLoader extends WrappedAsyncTaskLoader<List<File>> {
|
||||
|
||||
private WeakReference<FoldersFragment> fragmentWeakReference;
|
||||
|
||||
public AsyncFileLoader(FoldersFragment foldersFragment) {
|
||||
|
@ -509,12 +544,14 @@ public class FoldersFragment extends AbsMainActivityFragment implements
|
|||
}
|
||||
}
|
||||
|
||||
private static class ListSongsAsyncTask extends ListingFilesDialogAsyncTask<ListSongsAsyncTask.LoadingInfo, Void, ArrayList<Song>> {
|
||||
private static class ListSongsAsyncTask extends
|
||||
ListingFilesDialogAsyncTask<ListSongsAsyncTask.LoadingInfo, Void, ArrayList<Song>> {
|
||||
|
||||
private final Object extra;
|
||||
private WeakReference<Context> contextWeakReference;
|
||||
private WeakReference<OnSongsListedCallback> callbackWeakReference;
|
||||
|
||||
public ListSongsAsyncTask(Context context, Object extra, OnSongsListedCallback callback) {
|
||||
ListSongsAsyncTask(Context context, Object extra, OnSongsListedCallback callback) {
|
||||
super(context);
|
||||
this.extra = extra;
|
||||
contextWeakReference = new WeakReference<>(context);
|
||||
|
@ -534,14 +571,17 @@ public class FoldersFragment extends AbsMainActivityFragment implements
|
|||
LoadingInfo info = params[0];
|
||||
List<File> files = FileUtil.listFilesDeep(info.files, info.fileFilter);
|
||||
|
||||
if (isCancelled() || checkContextReference() == null || checkCallbackReference() == null)
|
||||
if (isCancelled() || checkContextReference() == null
|
||||
|| checkCallbackReference() == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Collections.sort(files, info.fileComparator);
|
||||
|
||||
Context context = checkContextReference();
|
||||
if (isCancelled() || context == null || checkCallbackReference() == null)
|
||||
if (isCancelled() || context == null || checkCallbackReference() == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return FileUtil.matchFilesWithMediaStore(context, files).blockingFirst();
|
||||
} catch (Exception e) {
|
||||
|
@ -555,9 +595,10 @@ public class FoldersFragment extends AbsMainActivityFragment implements
|
|||
protected void onPostExecute(ArrayList<Song> songs) {
|
||||
super.onPostExecute(songs);
|
||||
OnSongsListedCallback callback = checkCallbackReference();
|
||||
if (songs != null && callback != null)
|
||||
if (songs != null && callback != null) {
|
||||
callback.onSongsListed(songs, extra);
|
||||
}
|
||||
}
|
||||
|
||||
private Context checkContextReference() {
|
||||
Context context = contextWeakReference.get();
|
||||
|
@ -576,15 +617,18 @@ public class FoldersFragment extends AbsMainActivityFragment implements
|
|||
}
|
||||
|
||||
public interface OnSongsListedCallback {
|
||||
|
||||
void onSongsListed(@NonNull ArrayList<Song> songs, Object extra);
|
||||
}
|
||||
|
||||
public static class LoadingInfo {
|
||||
public final Comparator<File> fileComparator;
|
||||
public final FileFilter fileFilter;
|
||||
public final List<File> files;
|
||||
static class LoadingInfo {
|
||||
|
||||
public LoadingInfo(@NonNull List<File> files, @NonNull FileFilter fileFilter, @NonNull Comparator<File> fileComparator) {
|
||||
final Comparator<File> fileComparator;
|
||||
final FileFilter fileFilter;
|
||||
final List<File> files;
|
||||
|
||||
LoadingInfo(@NonNull List<File> files, @NonNull FileFilter fileFilter,
|
||||
@NonNull Comparator<File> fileComparator) {
|
||||
this.fileComparator = fileComparator;
|
||||
this.fileFilter = fileFilter;
|
||||
this.files = files;
|
||||
|
@ -592,7 +636,9 @@ public class FoldersFragment extends AbsMainActivityFragment implements
|
|||
}
|
||||
}
|
||||
|
||||
public static class ListPathsAsyncTask extends ListingFilesDialogAsyncTask<ListPathsAsyncTask.LoadingInfo, String, String[]> {
|
||||
public static class ListPathsAsyncTask extends
|
||||
ListingFilesDialogAsyncTask<ListPathsAsyncTask.LoadingInfo, String, String[]> {
|
||||
|
||||
private WeakReference<OnPathsListedCallback> onPathsListedCallbackWeakReference;
|
||||
|
||||
public ListPathsAsyncTask(Context context, OnPathsListedCallback callback) {
|
||||
|
@ -609,7 +655,9 @@ public class FoldersFragment extends AbsMainActivityFragment implements
|
|||
@Override
|
||||
protected String[] doInBackground(LoadingInfo... params) {
|
||||
try {
|
||||
if (isCancelled() || checkCallbackReference() == null) return null;
|
||||
if (isCancelled() || checkCallbackReference() == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
LoadingInfo info = params[0];
|
||||
|
||||
|
@ -618,14 +666,18 @@ public class FoldersFragment extends AbsMainActivityFragment implements
|
|||
if (info.file.isDirectory()) {
|
||||
List<File> files = FileUtil.listFilesDeep(info.file, info.fileFilter);
|
||||
|
||||
if (isCancelled() || checkCallbackReference() == null) return null;
|
||||
if (isCancelled() || checkCallbackReference() == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
paths = new String[files.size()];
|
||||
for (int i = 0; i < files.size(); i++) {
|
||||
File f = files.get(i);
|
||||
paths[i] = FileUtil.safeGetCanonicalPath(f);
|
||||
|
||||
if (isCancelled() || checkCallbackReference() == null) return null;
|
||||
if (isCancelled() || checkCallbackReference() == null) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
paths = new String[1];
|
||||
|
@ -658,12 +710,14 @@ public class FoldersFragment extends AbsMainActivityFragment implements
|
|||
}
|
||||
|
||||
public interface OnPathsListedCallback {
|
||||
|
||||
void onPathsListed(@NonNull String[] paths);
|
||||
}
|
||||
|
||||
public static class LoadingInfo {
|
||||
|
||||
public final File file;
|
||||
public final FileFilter fileFilter;
|
||||
final FileFilter fileFilter;
|
||||
|
||||
public LoadingInfo(File file, FileFilter fileFilter) {
|
||||
this.file = file;
|
||||
|
@ -672,8 +726,10 @@ public class FoldersFragment extends AbsMainActivityFragment implements
|
|||
}
|
||||
}
|
||||
|
||||
private static abstract class ListingFilesDialogAsyncTask<Params, Progress, Result> extends DialogAsyncTask<Params, Progress, Result> {
|
||||
public ListingFilesDialogAsyncTask(Context context) {
|
||||
private static abstract class ListingFilesDialogAsyncTask<Params, Progress, Result> extends
|
||||
DialogAsyncTask<Params, Progress, Result> {
|
||||
|
||||
ListingFilesDialogAsyncTask(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
|
|
|
@ -16,13 +16,6 @@ import android.view.View;
|
|||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.h6ah4i.android.widget.advrecyclerview.animator.GeneralItemAnimator;
|
||||
import com.h6ah4i.android.widget.advrecyclerview.animator.RefactoredDefaultItemAnimator;
|
||||
import com.h6ah4i.android.widget.advrecyclerview.draggable.RecyclerViewDragDropManager;
|
||||
import com.h6ah4i.android.widget.advrecyclerview.utils.WrapperAdapterUtils;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import butterknife.Unbinder;
|
||||
|
@ -37,13 +30,20 @@ import code.name.monkey.retromusic.ui.adapter.song.PlayingQueueAdapter;
|
|||
import code.name.monkey.retromusic.ui.fragments.base.AbsPlayerFragment;
|
||||
import code.name.monkey.retromusic.ui.fragments.player.PlayerAlbumCoverFragment;
|
||||
import code.name.monkey.retromusic.ui.fragments.player.normal.PlayerFragment;
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.h6ah4i.android.widget.advrecyclerview.animator.GeneralItemAnimator;
|
||||
import com.h6ah4i.android.widget.advrecyclerview.animator.RefactoredDefaultItemAnimator;
|
||||
import com.h6ah4i.android.widget.advrecyclerview.draggable.RecyclerViewDragDropManager;
|
||||
import com.h6ah4i.android.widget.advrecyclerview.utils.WrapperAdapterUtils;
|
||||
import jp.wasabeef.glide.transformations.BlurTransformation;
|
||||
|
||||
/**
|
||||
* @author Hemanth S (h4h13).
|
||||
*/
|
||||
|
||||
public class BlurPlayerFragment extends AbsPlayerFragment implements PlayerAlbumCoverFragment.Callbacks {
|
||||
public class BlurPlayerFragment extends AbsPlayerFragment implements
|
||||
PlayerAlbumCoverFragment.Callbacks {
|
||||
|
||||
@BindView(R.id.player_toolbar)
|
||||
Toolbar toolbar;
|
||||
@BindView(R.id.toolbar_container)
|
||||
|
@ -193,6 +193,7 @@ public class BlurPlayerFragment extends AbsPlayerFragment implements PlayerAlbum
|
|||
|
||||
private void setUpPlayerToolbar() {
|
||||
toolbar.inflateMenu(R.menu.menu_player);
|
||||
//noinspection ConstantConditions
|
||||
toolbar.setNavigationOnClickListener(v -> getActivity().onBackPressed());
|
||||
toolbar.setOnMenuItemClickListener(this);
|
||||
|
||||
|
@ -205,7 +206,8 @@ public class BlurPlayerFragment extends AbsPlayerFragment implements PlayerAlbum
|
|||
return;
|
||||
}
|
||||
|
||||
int blurAmount = PreferenceManager.getDefaultSharedPreferences(getContext()).getInt("blur_amount", 25);
|
||||
int blurAmount = PreferenceManager.getDefaultSharedPreferences(getContext())
|
||||
.getInt("blur_amount", 25);
|
||||
|
||||
colorBackground.clearColorFilter();
|
||||
|
||||
|
@ -255,7 +257,6 @@ public class BlurPlayerFragment extends AbsPlayerFragment implements PlayerAlbum
|
|||
|
||||
layoutManager = new LinearLayoutManager(getContext());
|
||||
|
||||
|
||||
recyclerView.setLayoutManager(layoutManager);
|
||||
recyclerView.setAdapter(wrappedAdapter);
|
||||
recyclerView.setItemAnimator(animator);
|
||||
|
@ -291,7 +292,8 @@ public class BlurPlayerFragment extends AbsPlayerFragment implements PlayerAlbum
|
|||
|
||||
private void updateQueue() {
|
||||
if (playingQueueAdapter != null) {
|
||||
playingQueueAdapter.swapDataSet(MusicPlayerRemote.getPlayingQueue(), MusicPlayerRemote.getPosition());
|
||||
playingQueueAdapter
|
||||
.swapDataSet(MusicPlayerRemote.getPlayingQueue(), MusicPlayerRemote.getPosition());
|
||||
resetToCurrentPosition();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package code.name.monkey.retromusic.util;
|
||||
|
||||
import static code.name.monkey.retromusic.ui.activities.GenreDetailsActivity.EXTRA_GENRE_ID;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.ActivityNotFoundException;
|
||||
import android.content.Intent;
|
||||
|
@ -10,7 +12,6 @@ import android.support.v4.app.ActivityCompat;
|
|||
import android.support.v4.app.ActivityOptionsCompat;
|
||||
import android.support.v4.util.Pair;
|
||||
import android.widget.Toast;
|
||||
|
||||
import code.name.monkey.retromusic.R;
|
||||
import code.name.monkey.retromusic.helper.MusicPlayerRemote;
|
||||
import code.name.monkey.retromusic.model.Genre;
|
||||
|
@ -22,7 +23,6 @@ import code.name.monkey.retromusic.ui.activities.EqualizerActivity;
|
|||
import code.name.monkey.retromusic.ui.activities.GenreDetailsActivity;
|
||||
import code.name.monkey.retromusic.ui.activities.LicenseActivity;
|
||||
import code.name.monkey.retromusic.ui.activities.LyricsActivity;
|
||||
import code.name.monkey.retromusic.ui.activities.MainActivity;
|
||||
import code.name.monkey.retromusic.ui.activities.PlayingQueueActivity;
|
||||
import code.name.monkey.retromusic.ui.activities.PlaylistDetailActivity;
|
||||
import code.name.monkey.retromusic.ui.activities.ProVersionActivity;
|
||||
|
@ -30,10 +30,10 @@ import code.name.monkey.retromusic.ui.activities.SearchActivity;
|
|||
import code.name.monkey.retromusic.ui.activities.SettingsActivity;
|
||||
import code.name.monkey.retromusic.ui.activities.UserInfoActivity;
|
||||
|
||||
import static code.name.monkey.retromusic.ui.activities.GenreDetailsActivity.EXTRA_GENRE_ID;
|
||||
|
||||
public class NavigationUtil {
|
||||
public static void goToAlbum(@NonNull Activity activity, int i, @Nullable Pair... sharedElements) {
|
||||
|
||||
public static void goToAlbum(@NonNull Activity activity, int i,
|
||||
@Nullable Pair... sharedElements) {
|
||||
Intent intent = new Intent(activity, AlbumDetailsActivity.class);
|
||||
intent.putExtra(AlbumDetailsActivity.EXTRA_ALBUM_ID, i);
|
||||
//noinspection unchecked
|
||||
|
@ -41,11 +41,13 @@ public class NavigationUtil {
|
|||
ActivityOptionsCompat.makeSceneTransitionAnimation(activity, sharedElements).toBundle());
|
||||
}
|
||||
|
||||
public static void goToArtist(@NonNull Activity activity, int i, @Nullable Pair... sharedElements) {
|
||||
public static void goToArtist(@NonNull Activity activity, int i,
|
||||
@Nullable Pair... sharedElements) {
|
||||
Intent intent = new Intent(activity, ArtistDetailActivity.class);
|
||||
intent.putExtra(ArtistDetailActivity.EXTRA_ARTIST_ID, i);
|
||||
//noinspection unchecked
|
||||
ActivityCompat.startActivity(activity, intent, null);
|
||||
ActivityCompat.startActivity(activity, intent,
|
||||
ActivityOptionsCompat.makeSceneTransitionAnimation(activity, sharedElements).toBundle());
|
||||
}
|
||||
|
||||
public static void goToPlaylistNew(@NonNull Activity activity, Playlist playlist) {
|
||||
|
@ -65,7 +67,8 @@ public class NavigationUtil {
|
|||
private static void stockEqalizer(@NonNull Activity activity) {
|
||||
final int sessionId = MusicPlayerRemote.getAudioSessionId();
|
||||
if (sessionId == AudioEffect.ERROR_BAD_VALUE) {
|
||||
Toast.makeText(activity, activity.getResources().getString(R.string.no_audio_ID), Toast.LENGTH_LONG).show();
|
||||
Toast.makeText(activity, activity.getResources().getString(R.string.no_audio_ID),
|
||||
Toast.LENGTH_LONG).show();
|
||||
} else {
|
||||
try {
|
||||
final Intent effects = new Intent(AudioEffect.ACTION_DISPLAY_AUDIO_EFFECT_CONTROL_PANEL);
|
||||
|
@ -73,7 +76,8 @@ public class NavigationUtil {
|
|||
effects.putExtra(AudioEffect.EXTRA_CONTENT_TYPE, AudioEffect.CONTENT_TYPE_MUSIC);
|
||||
activity.startActivityForResult(effects, 0);
|
||||
} catch (@NonNull final ActivityNotFoundException notFound) {
|
||||
Toast.makeText(activity, activity.getResources().getString(R.string.no_equalizer), Toast.LENGTH_SHORT).show();
|
||||
Toast.makeText(activity, activity.getResources().getString(R.string.no_equalizer),
|
||||
Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,8 +6,8 @@ import android.os.Bundle;
|
|||
import android.support.annotation.NonNull;
|
||||
import android.support.design.widget.BottomSheetDialog;
|
||||
import android.support.design.widget.BottomSheetDialogFragment;
|
||||
|
||||
import code.name.monkey.retromusic.R;
|
||||
import code.name.monkey.retromusic.ui.activities.base.AbsThemeActivity;
|
||||
import code.name.monkey.retromusic.util.PreferenceUtil;
|
||||
|
||||
/**
|
||||
|
@ -15,15 +15,24 @@ import code.name.monkey.retromusic.util.PreferenceUtil;
|
|||
*/
|
||||
@SuppressLint("RestrictedApi")
|
||||
public class RoundedBottomSheetDialogFragment extends BottomSheetDialogFragment {
|
||||
|
||||
@Override
|
||||
public int getTheme() {
|
||||
//noinspection ConstantConditions
|
||||
return PreferenceUtil.getInstance(getContext()).getGeneralTheme() == R.style.Theme_RetroMusic_Light ? R.style.BottomSheetDialogTheme : R.style.BottomSheetDialogThemeDark;
|
||||
return
|
||||
PreferenceUtil.getInstance(getContext()).getGeneralTheme() == R.style.Theme_RetroMusic_Light
|
||||
? R.style.BottomSheetDialogTheme : R.style.BottomSheetDialogThemeDark;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
AbsThemeActivity absThemeActivity = (AbsThemeActivity) getActivity();
|
||||
if (absThemeActivity != null) {
|
||||
absThemeActivity.setLightNavigationBar(true);
|
||||
Dialog dialog = new BottomSheetDialog(getContext(), getTheme());
|
||||
|
||||
}
|
||||
//noinspection ConstantConditions
|
||||
return new BottomSheetDialog(getContext(), getTheme());
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue