code refactor

This commit is contained in:
h4h13 2018-07-30 22:54:37 +05:30
parent 8a731b5073
commit f386a2cf07
7 changed files with 1529 additions and 1478 deletions

View file

@ -1,36 +1,13 @@
package code.name.monkey.retromusic.dialogs; 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.os.Bundle;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.support.design.widget.BottomSheetDialogFragment;
import android.text.Html; import android.text.Html;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.TextView; import android.widget.TextView;
import java.util.ArrayList;
import butterknife.BindView; import butterknife.BindView;
import butterknife.ButterKnife; import butterknife.ButterKnife;
import butterknife.OnClick; 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.model.Song;
import code.name.monkey.retromusic.util.MusicUtil; import code.name.monkey.retromusic.util.MusicUtil;
import code.name.monkey.retromusic.views.RoundedBottomSheetDialogFragment; import code.name.monkey.retromusic.views.RoundedBottomSheetDialogFragment;
import java.util.ArrayList;
/**
* @author Karim Abou Zeid (kabouzeid), Aidan Follestad (afollestad)
*/
public class DeleteSongsDialog extends RoundedBottomSheetDialogFragment { public class DeleteSongsDialog extends RoundedBottomSheetDialogFragment {
@BindView(R.id.action_delete) @BindView(R.id.action_delete)
TextView delete; TextView delete;
@BindView(R.id.title) @BindView(R.id.title)
@ -69,12 +44,16 @@ public class DeleteSongsDialog extends RoundedBottomSheetDialogFragment {
@OnClick({R.id.action_cancel, R.id.action_delete}) @OnClick({R.id.action_cancel, R.id.action_delete})
void actions(View view) { void actions(View view) {
//noinspection ConstantConditions
final ArrayList<Song> songs = getArguments().getParcelableArrayList("songs"); final ArrayList<Song> songs = getArguments().getParcelableArrayList("songs");
switch (view.getId()) { switch (view.getId()) {
case R.id.action_delete: case R.id.action_delete:
if (getActivity() == null) if (getActivity() == null) {
return; return;
}
if (songs != null) {
MusicUtil.deleteTracks(getActivity(), songs); MusicUtil.deleteTracks(getActivity(), songs);
}
break; break;
default: default:
} }
@ -84,29 +63,30 @@ public class DeleteSongsDialog extends RoundedBottomSheetDialogFragment {
@Override @Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState); super.onViewCreated(view, savedInstanceState);
//noinspection unchecked //noinspection unchecked,ConstantConditions
final ArrayList<Song> songs = getArguments().getParcelableArrayList("songs"); final ArrayList<Song> songs = getArguments().getParcelableArrayList("songs");
int title; int title;
CharSequence content; CharSequence content;
if (songs != null && songs.size() > 1) { if (songs != null) {
if (songs.size() > 1) {
title = R.string.delete_songs_title; title = R.string.delete_songs_title;
content = Html.fromHtml(getString(R.string.delete_x_songs, songs.size())); content = Html.fromHtml(getString(R.string.delete_x_songs, songs.size()));
} else { } else {
title = R.string.delete_song_title; title = R.string.delete_song_title;
content = Html.fromHtml(getString(R.string.delete_song_x, songs.get(0).title)); content = Html.fromHtml(getString(R.string.delete_song_x, songs.get(0).title));
} }
this.title.setText(title); this.title.setText(title);
this.delete.setText(content); this.delete.setText(content);
} }
}
@Nullable @Nullable
@Override @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); View layout = inflater.inflate(R.layout.dialog_delete_songs, container, false);
ButterKnife.bind(this, layout); ButterKnife.bind(this, layout);
return layout; return layout;
} }
} }

View file

@ -15,13 +15,13 @@ import android.support.design.widget.Snackbar;
import android.support.v4.app.ActivityCompat; import android.support.v4.app.ActivityCompat;
import android.view.KeyEvent; import android.view.KeyEvent;
import android.view.View; import android.view.View;
import code.name.monkey.appthemehelper.ThemeStore; import code.name.monkey.appthemehelper.ThemeStore;
import code.name.monkey.retromusic.R; import code.name.monkey.retromusic.R;
import uk.co.chrisjenx.calligraphy.CalligraphyContextWrapper; import uk.co.chrisjenx.calligraphy.CalligraphyContextWrapper;
public abstract class AbsBaseActivity extends AbsThemeActivity { public abstract class AbsBaseActivity extends AbsThemeActivity {
public static final int PERMISSION_REQUEST = 100; public static final int PERMISSION_REQUEST = 100;
private boolean hadPermissions; private boolean hadPermissions;
private String[] permissions; private String[] permissions;
@ -38,8 +38,6 @@ public abstract class AbsBaseActivity extends AbsThemeActivity {
hadPermissions = hasPermissions(); hadPermissions = hasPermissions();
setPermissionDeniedMessage(null); setPermissionDeniedMessage(null);
} }
@Override @Override
@ -95,7 +93,8 @@ public abstract class AbsBaseActivity extends AbsThemeActivity {
} }
private String getPermissionDeniedMessage() { 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) { protected void setPermissionDeniedMessage(String message) {
@ -120,12 +119,14 @@ public abstract class AbsBaseActivity extends AbsThemeActivity {
} }
@Override @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); super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if (requestCode == PERMISSION_REQUEST) { if (requestCode == PERMISSION_REQUEST) {
for (int grantResult : grantResults) { for (int grantResult : grantResults) {
if (grantResult != PackageManager.PERMISSION_GRANTED) { 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 //User has deny from permission dialog
Snackbar.make(getSnackBarContainer(), getPermissionDeniedMessage(), Snackbar.make(getSnackBarContainer(), getPermissionDeniedMessage(),
Snackbar.LENGTH_INDEFINITE) Snackbar.LENGTH_INDEFINITE)

View file

@ -11,10 +11,6 @@ import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.ViewTreeObserver; import android.view.ViewTreeObserver;
import android.view.animation.PathInterpolator; import android.view.animation.PathInterpolator;
import com.sothree.slidinguppanel.SlidingUpPanelLayout;
import com.sothree.slidinguppanel.SlidingUpPanelLayout.PanelState;
import butterknife.BindView; import butterknife.BindView;
import butterknife.ButterKnife; import butterknife.ButterKnife;
import code.name.monkey.appthemehelper.ThemeStore; 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.PreferenceUtil;
import code.name.monkey.retromusic.util.ViewUtil; import code.name.monkey.retromusic.util.ViewUtil;
import code.name.monkey.retromusic.views.BottomNavigationViewEx; 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 public abstract class AbsSlidingMusicPanelActivity extends AbsMusicServiceActivity implements
SlidingUpPanelLayout.PanelSlideListener, SlidingUpPanelLayout.PanelSlideListener,
@ -253,8 +251,9 @@ public abstract class AbsSlidingMusicPanelActivity extends AbsMusicServiceActivi
|| currentNowPlayingScreen == NowPlayingScreen.PLAIN || currentNowPlayingScreen == NowPlayingScreen.PLAIN
|| currentNowPlayingScreen == NowPlayingScreen.SIMPLE || currentNowPlayingScreen == NowPlayingScreen.SIMPLE
|| currentNowPlayingScreen == NowPlayingScreen.NORMAL || currentNowPlayingScreen == NowPlayingScreen.NORMAL
|| currentNowPlayingScreen == NowPlayingScreen.ADAPTIVE) || currentNowPlayingScreen == NowPlayingScreen.ADAPTIVE
|| currentNowPlayingScreen == NowPlayingScreen.TINY); || currentNowPlayingScreen == NowPlayingScreen.TINY
|| currentNowPlayingScreen == NowPlayingScreen.MATERIAL));
} }
@Override @Override

View file

@ -25,21 +25,6 @@ import android.view.ViewGroup;
import android.webkit.MimeTypeMap; import android.webkit.MimeTypeMap;
import android.widget.PopupMenu; import android.widget.PopupMenu;
import android.widget.Toast; 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.BindView;
import butterknife.ButterKnife; import butterknife.ButterKnife;
import butterknife.Unbinder; 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.RetroColorUtil;
import code.name.monkey.retromusic.util.ViewUtil; import code.name.monkey.retromusic.util.ViewUtil;
import code.name.monkey.retromusic.views.BreadCrumbLayout; 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 public class FoldersFragment extends AbsMainActivityFragment implements
MainActivityFragmentCallbacks, MainActivityFragmentCallbacks,
@ -72,7 +69,8 @@ public class FoldersFragment extends AbsMainActivityFragment implements
AppBarLayout.OnOffsetChangedListener, LoaderManager.LoaderCallbacks<List<File>> { AppBarLayout.OnOffsetChangedListener, LoaderManager.LoaderCallbacks<List<File>> {
public static final String TAG = FoldersFragment.class.getSimpleName(); 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, "audio/*", MimeTypeMap.getSingleton()) ||
FileUtil.fileIsMimeType(file, "application/opus", MimeTypeMap.getSingleton()) || FileUtil.fileIsMimeType(file, "application/opus", MimeTypeMap.getSingleton()) ||
FileUtil.fileIsMimeType(file, "application/ogg", MimeTypeMap.getSingleton())); FileUtil.fileIsMimeType(file, "application/ogg", MimeTypeMap.getSingleton()));
@ -226,9 +224,12 @@ public class FoldersFragment extends AbsMainActivityFragment implements
appbar.setBackgroundColor(primaryColor); appbar.setBackgroundColor(primaryColor);
toolbar.setBackgroundColor(primaryColor); toolbar.setBackgroundColor(primaryColor);
//breadCrumbs.setBackgroundColor(primaryColor); //breadCrumbs.setBackgroundColor(primaryColor);
breadCrumbs.setActivatedContentColor(ToolbarContentTintHelper.toolbarTitleColor(getActivity(), primaryColor)); breadCrumbs.setActivatedContentColor(
breadCrumbs.setDeactivatedContentColor(ToolbarContentTintHelper.toolbarSubtitleColor(getActivity(), primaryColor)); ToolbarContentTintHelper.toolbarTitleColor(getActivity(), primaryColor));
appbar.addOnOffsetChangedListener((appBarLayout, verticalOffset) -> getMainActivity().setLightStatusbar(!ATHUtil.isWindowBackgroundDark(getContext()))); breadCrumbs.setDeactivatedContentColor(
ToolbarContentTintHelper.toolbarSubtitleColor(getActivity(), primaryColor));
appbar.addOnOffsetChangedListener((appBarLayout, verticalOffset) -> getMainActivity()
.setLightStatusbar(!ATHUtil.isWindowBackgroundDark(getContext())));
} }
private void setUpToolbar() { private void setUpToolbar() {
@ -244,13 +245,15 @@ public class FoldersFragment extends AbsMainActivityFragment implements
private void setUpRecyclerView() { private void setUpRecyclerView() {
//noinspection ConstantConditions //noinspection ConstantConditions
ViewUtil.setUpFastScrollRecyclerViewColor(getActivity(), recyclerView, ThemeStore.accentColor(getActivity())); ViewUtil.setUpFastScrollRecyclerViewColor(getActivity(), recyclerView,
ThemeStore.accentColor(getActivity()));
recyclerView.setLayoutManager(new LinearLayoutManager(getActivity())); recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
appbar.addOnOffsetChangedListener(this); appbar.addOnOffsetChangedListener(this);
} }
private void setUpAdapter() { 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() { adapter.registerAdapterDataObserver(new RecyclerView.AdapterDataObserver() {
@Override @Override
public void onChanged() { public void onChanged() {
@ -291,7 +294,9 @@ public class FoldersFragment extends AbsMainActivityFragment implements
@NonNull @NonNull
@Override @Override
public MaterialCab openCab(int menuRes, MaterialCab.Callback callback) { 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) cab = new MaterialCab(getMainActivity(), R.id.cab_stub)
.setMenu(menuRes) .setMenu(menuRes)
.setCloseDrawableRes(R.drawable.ic_close_white_24dp) .setCloseDrawableRes(R.drawable.ic_close_white_24dp)
@ -305,7 +310,8 @@ public class FoldersFragment extends AbsMainActivityFragment implements
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
super.onCreateOptionsMenu(menu, inflater); super.onCreateOptionsMenu(menu, inflater);
inflater.inflate(R.menu.menu_folders, menu); inflater.inflate(R.menu.menu_folders, menu);
ToolbarContentTintHelper.handleOnCreateOptionsMenu(getActivity(), toolbar, menu, ATHToolbarActivity.getToolbarBackgroundColor(toolbar)); ToolbarContentTintHelper.handleOnCreateOptionsMenu(getActivity(), toolbar, menu,
ATHToolbarActivity.getToolbarBackgroundColor(toolbar));
} }
@Override @Override
@ -327,13 +333,16 @@ public class FoldersFragment extends AbsMainActivityFragment implements
getActivity().onBackPressed(); getActivity().onBackPressed();
break; break;
case R.id.action_go_to_start_directory: 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; return true;
case R.id.action_scan: case R.id.action_scan:
BreadCrumbLayout.Crumb crumb = getActiveCrumb(); BreadCrumbLayout.Crumb crumb = getActiveCrumb();
if (crumb != null) { if (crumb != null) {
//noinspection Convert2MethodRef //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; return true;
} }
@ -346,7 +355,8 @@ public class FoldersFragment extends AbsMainActivityFragment implements
if (file.isDirectory()) { if (file.isDirectory()) {
setCrumb(new BreadCrumbLayout.Crumb(file), true); setCrumb(new BreadCrumbLayout.Crumb(file), true);
} else { } 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) -> { new ListSongsAsyncTask(getActivity(), file, (songs, extra) -> {
File file1 = (File) extra; File file1 = (File) extra;
int startIndex = -1; int startIndex = -1;
@ -360,19 +370,26 @@ public class FoldersFragment extends AbsMainActivityFragment implements
MusicPlayerRemote.openQueue(songs, startIndex, true); MusicPlayerRemote.openQueue(songs, startIndex, true);
} else { } else {
final File finalFile = file1; final File finalFile = file1;
Snackbar.make(coordinatorLayout, Html.fromHtml(String.format(getString(R.string.not_listed_in_media_store), file1.getName())), Snackbar.LENGTH_LONG) Snackbar.make(coordinatorLayout, Html.fromHtml(
.setAction(R.string.action_scan, v -> new ListPathsAsyncTask(getActivity(), paths -> scanPaths(paths)).execute(new ListPathsAsyncTask.LoadingInfo(finalFile, AUDIO_FILE_FILTER))) 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())) .setActionTextColor(ThemeStore.accentColor(getActivity()))
.show(); .show();
} }
}).execute(new ListSongsAsyncTask.LoadingInfo(toList(file.getParentFile()), fileFilter, getFileComparator())); }).execute(new ListSongsAsyncTask.LoadingInfo(toList(file.getParentFile()), fileFilter,
getFileComparator()));
} }
} }
@Override @Override
public void onMultipleItemAction(MenuItem item, ArrayList<File> files) { public void onMultipleItemAction(MenuItem item, ArrayList<File> files) {
final int itemId = item.getItemId(); 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) { 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_current_playing:
case R.id.action_add_to_playlist: case R.id.action_add_to_playlist:
case R.id.action_delete_from_device: 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; return true;
case R.id.action_set_as_start_directory: case R.id.action_set_as_start_directory:
PreferenceUtil.getInstance(getActivity()).setStartDirectory(file); 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; return true;
case R.id.action_scan: 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 true;
} }
return false; return false;
@ -424,10 +449,14 @@ public class FoldersFragment extends AbsMainActivityFragment implements
case R.id.action_details: case R.id.action_details:
case R.id.action_set_as_ringtone: case R.id.action_set_as_ringtone:
case R.id.action_delete_from_device: 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; return true;
case R.id.action_scan: 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 true;
} }
return false; return false;
@ -438,21 +467,26 @@ public class FoldersFragment extends AbsMainActivityFragment implements
@Override @Override
public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) { 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() { private void checkIsEmpty() {
if (empty != null) { 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) { private void scanPaths(@Nullable String[] toBeScanned) {
if (getActivity() == null) return; if (getActivity() == null) {
return;
}
if (toBeScanned == null || toBeScanned.length < 1) { if (toBeScanned == null || toBeScanned.length < 1) {
Toast.makeText(getActivity(), R.string.nothing_to_scan, Toast.LENGTH_SHORT).show(); Toast.makeText(getActivity(), R.string.nothing_to_scan, Toast.LENGTH_SHORT).show();
} else { } 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 static class AsyncFileLoader extends WrappedAsyncTaskLoader<List<File>> {
private WeakReference<FoldersFragment> fragmentWeakReference; private WeakReference<FoldersFragment> fragmentWeakReference;
public AsyncFileLoader(FoldersFragment foldersFragment) { 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 final Object extra;
private WeakReference<Context> contextWeakReference; private WeakReference<Context> contextWeakReference;
private WeakReference<OnSongsListedCallback> callbackWeakReference; private WeakReference<OnSongsListedCallback> callbackWeakReference;
public ListSongsAsyncTask(Context context, Object extra, OnSongsListedCallback callback) { ListSongsAsyncTask(Context context, Object extra, OnSongsListedCallback callback) {
super(context); super(context);
this.extra = extra; this.extra = extra;
contextWeakReference = new WeakReference<>(context); contextWeakReference = new WeakReference<>(context);
@ -534,14 +571,17 @@ public class FoldersFragment extends AbsMainActivityFragment implements
LoadingInfo info = params[0]; LoadingInfo info = params[0];
List<File> files = FileUtil.listFilesDeep(info.files, info.fileFilter); List<File> files = FileUtil.listFilesDeep(info.files, info.fileFilter);
if (isCancelled() || checkContextReference() == null || checkCallbackReference() == null) if (isCancelled() || checkContextReference() == null
|| checkCallbackReference() == null) {
return null; return null;
}
Collections.sort(files, info.fileComparator); Collections.sort(files, info.fileComparator);
Context context = checkContextReference(); Context context = checkContextReference();
if (isCancelled() || context == null || checkCallbackReference() == null) if (isCancelled() || context == null || checkCallbackReference() == null) {
return null; return null;
}
return FileUtil.matchFilesWithMediaStore(context, files).blockingFirst(); return FileUtil.matchFilesWithMediaStore(context, files).blockingFirst();
} catch (Exception e) { } catch (Exception e) {
@ -555,9 +595,10 @@ public class FoldersFragment extends AbsMainActivityFragment implements
protected void onPostExecute(ArrayList<Song> songs) { protected void onPostExecute(ArrayList<Song> songs) {
super.onPostExecute(songs); super.onPostExecute(songs);
OnSongsListedCallback callback = checkCallbackReference(); OnSongsListedCallback callback = checkCallbackReference();
if (songs != null && callback != null) if (songs != null && callback != null) {
callback.onSongsListed(songs, extra); callback.onSongsListed(songs, extra);
} }
}
private Context checkContextReference() { private Context checkContextReference() {
Context context = contextWeakReference.get(); Context context = contextWeakReference.get();
@ -576,15 +617,18 @@ public class FoldersFragment extends AbsMainActivityFragment implements
} }
public interface OnSongsListedCallback { public interface OnSongsListedCallback {
void onSongsListed(@NonNull ArrayList<Song> songs, Object extra); void onSongsListed(@NonNull ArrayList<Song> songs, Object extra);
} }
public static class LoadingInfo { static class LoadingInfo {
public final Comparator<File> fileComparator;
public final FileFilter fileFilter;
public final List<File> files;
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.fileComparator = fileComparator;
this.fileFilter = fileFilter; this.fileFilter = fileFilter;
this.files = files; 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; private WeakReference<OnPathsListedCallback> onPathsListedCallbackWeakReference;
public ListPathsAsyncTask(Context context, OnPathsListedCallback callback) { public ListPathsAsyncTask(Context context, OnPathsListedCallback callback) {
@ -609,7 +655,9 @@ public class FoldersFragment extends AbsMainActivityFragment implements
@Override @Override
protected String[] doInBackground(LoadingInfo... params) { protected String[] doInBackground(LoadingInfo... params) {
try { try {
if (isCancelled() || checkCallbackReference() == null) return null; if (isCancelled() || checkCallbackReference() == null) {
return null;
}
LoadingInfo info = params[0]; LoadingInfo info = params[0];
@ -618,14 +666,18 @@ public class FoldersFragment extends AbsMainActivityFragment implements
if (info.file.isDirectory()) { if (info.file.isDirectory()) {
List<File> files = FileUtil.listFilesDeep(info.file, info.fileFilter); 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()]; paths = new String[files.size()];
for (int i = 0; i < files.size(); i++) { for (int i = 0; i < files.size(); i++) {
File f = files.get(i); File f = files.get(i);
paths[i] = FileUtil.safeGetCanonicalPath(f); paths[i] = FileUtil.safeGetCanonicalPath(f);
if (isCancelled() || checkCallbackReference() == null) return null; if (isCancelled() || checkCallbackReference() == null) {
return null;
}
} }
} else { } else {
paths = new String[1]; paths = new String[1];
@ -658,12 +710,14 @@ public class FoldersFragment extends AbsMainActivityFragment implements
} }
public interface OnPathsListedCallback { public interface OnPathsListedCallback {
void onPathsListed(@NonNull String[] paths); void onPathsListed(@NonNull String[] paths);
} }
public static class LoadingInfo { public static class LoadingInfo {
public final File file; public final File file;
public final FileFilter fileFilter; final FileFilter fileFilter;
public LoadingInfo(File file, FileFilter fileFilter) { public LoadingInfo(File file, FileFilter fileFilter) {
this.file = file; 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> { private static abstract class ListingFilesDialogAsyncTask<Params, Progress, Result> extends
public ListingFilesDialogAsyncTask(Context context) { DialogAsyncTask<Params, Progress, Result> {
ListingFilesDialogAsyncTask(Context context) {
super(context); super(context);
} }

View file

@ -16,13 +16,6 @@ import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.TextView; 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.BindView;
import butterknife.ButterKnife; import butterknife.ButterKnife;
import butterknife.Unbinder; 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.base.AbsPlayerFragment;
import code.name.monkey.retromusic.ui.fragments.player.PlayerAlbumCoverFragment; import code.name.monkey.retromusic.ui.fragments.player.PlayerAlbumCoverFragment;
import code.name.monkey.retromusic.ui.fragments.player.normal.PlayerFragment; 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; import jp.wasabeef.glide.transformations.BlurTransformation;
/** /**
* @author Hemanth S (h4h13). * @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) @BindView(R.id.player_toolbar)
Toolbar toolbar; Toolbar toolbar;
@BindView(R.id.toolbar_container) @BindView(R.id.toolbar_container)
@ -193,6 +193,7 @@ public class BlurPlayerFragment extends AbsPlayerFragment implements PlayerAlbum
private void setUpPlayerToolbar() { private void setUpPlayerToolbar() {
toolbar.inflateMenu(R.menu.menu_player); toolbar.inflateMenu(R.menu.menu_player);
//noinspection ConstantConditions
toolbar.setNavigationOnClickListener(v -> getActivity().onBackPressed()); toolbar.setNavigationOnClickListener(v -> getActivity().onBackPressed());
toolbar.setOnMenuItemClickListener(this); toolbar.setOnMenuItemClickListener(this);
@ -205,7 +206,8 @@ public class BlurPlayerFragment extends AbsPlayerFragment implements PlayerAlbum
return; return;
} }
int blurAmount = PreferenceManager.getDefaultSharedPreferences(getContext()).getInt("blur_amount", 25); int blurAmount = PreferenceManager.getDefaultSharedPreferences(getContext())
.getInt("blur_amount", 25);
colorBackground.clearColorFilter(); colorBackground.clearColorFilter();
@ -255,7 +257,6 @@ public class BlurPlayerFragment extends AbsPlayerFragment implements PlayerAlbum
layoutManager = new LinearLayoutManager(getContext()); layoutManager = new LinearLayoutManager(getContext());
recyclerView.setLayoutManager(layoutManager); recyclerView.setLayoutManager(layoutManager);
recyclerView.setAdapter(wrappedAdapter); recyclerView.setAdapter(wrappedAdapter);
recyclerView.setItemAnimator(animator); recyclerView.setItemAnimator(animator);
@ -291,7 +292,8 @@ public class BlurPlayerFragment extends AbsPlayerFragment implements PlayerAlbum
private void updateQueue() { private void updateQueue() {
if (playingQueueAdapter != null) { if (playingQueueAdapter != null) {
playingQueueAdapter.swapDataSet(MusicPlayerRemote.getPlayingQueue(), MusicPlayerRemote.getPosition()); playingQueueAdapter
.swapDataSet(MusicPlayerRemote.getPlayingQueue(), MusicPlayerRemote.getPosition());
resetToCurrentPosition(); resetToCurrentPosition();
} }
} }

View file

@ -1,5 +1,7 @@
package code.name.monkey.retromusic.util; package code.name.monkey.retromusic.util;
import static code.name.monkey.retromusic.ui.activities.GenreDetailsActivity.EXTRA_GENRE_ID;
import android.app.Activity; import android.app.Activity;
import android.content.ActivityNotFoundException; import android.content.ActivityNotFoundException;
import android.content.Intent; import android.content.Intent;
@ -10,7 +12,6 @@ import android.support.v4.app.ActivityCompat;
import android.support.v4.app.ActivityOptionsCompat; import android.support.v4.app.ActivityOptionsCompat;
import android.support.v4.util.Pair; import android.support.v4.util.Pair;
import android.widget.Toast; import android.widget.Toast;
import code.name.monkey.retromusic.R; import code.name.monkey.retromusic.R;
import code.name.monkey.retromusic.helper.MusicPlayerRemote; import code.name.monkey.retromusic.helper.MusicPlayerRemote;
import code.name.monkey.retromusic.model.Genre; 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.GenreDetailsActivity;
import code.name.monkey.retromusic.ui.activities.LicenseActivity; import code.name.monkey.retromusic.ui.activities.LicenseActivity;
import code.name.monkey.retromusic.ui.activities.LyricsActivity; 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.PlayingQueueActivity;
import code.name.monkey.retromusic.ui.activities.PlaylistDetailActivity; import code.name.monkey.retromusic.ui.activities.PlaylistDetailActivity;
import code.name.monkey.retromusic.ui.activities.ProVersionActivity; 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.SettingsActivity;
import code.name.monkey.retromusic.ui.activities.UserInfoActivity; import code.name.monkey.retromusic.ui.activities.UserInfoActivity;
import static code.name.monkey.retromusic.ui.activities.GenreDetailsActivity.EXTRA_GENRE_ID;
public class NavigationUtil { 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 intent = new Intent(activity, AlbumDetailsActivity.class);
intent.putExtra(AlbumDetailsActivity.EXTRA_ALBUM_ID, i); intent.putExtra(AlbumDetailsActivity.EXTRA_ALBUM_ID, i);
//noinspection unchecked //noinspection unchecked
@ -41,11 +41,13 @@ public class NavigationUtil {
ActivityOptionsCompat.makeSceneTransitionAnimation(activity, sharedElements).toBundle()); 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 intent = new Intent(activity, ArtistDetailActivity.class);
intent.putExtra(ArtistDetailActivity.EXTRA_ARTIST_ID, i); intent.putExtra(ArtistDetailActivity.EXTRA_ARTIST_ID, i);
//noinspection unchecked //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) { public static void goToPlaylistNew(@NonNull Activity activity, Playlist playlist) {
@ -65,7 +67,8 @@ public class NavigationUtil {
private static void stockEqalizer(@NonNull Activity activity) { private static void stockEqalizer(@NonNull Activity activity) {
final int sessionId = MusicPlayerRemote.getAudioSessionId(); final int sessionId = MusicPlayerRemote.getAudioSessionId();
if (sessionId == AudioEffect.ERROR_BAD_VALUE) { 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 { } else {
try { try {
final Intent effects = new Intent(AudioEffect.ACTION_DISPLAY_AUDIO_EFFECT_CONTROL_PANEL); 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); effects.putExtra(AudioEffect.EXTRA_CONTENT_TYPE, AudioEffect.CONTENT_TYPE_MUSIC);
activity.startActivityForResult(effects, 0); activity.startActivityForResult(effects, 0);
} catch (@NonNull final ActivityNotFoundException notFound) { } 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();
} }
} }
} }

View file

@ -6,8 +6,8 @@ import android.os.Bundle;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.design.widget.BottomSheetDialog; import android.support.design.widget.BottomSheetDialog;
import android.support.design.widget.BottomSheetDialogFragment; import android.support.design.widget.BottomSheetDialogFragment;
import code.name.monkey.retromusic.R; import code.name.monkey.retromusic.R;
import code.name.monkey.retromusic.ui.activities.base.AbsThemeActivity;
import code.name.monkey.retromusic.util.PreferenceUtil; import code.name.monkey.retromusic.util.PreferenceUtil;
/** /**
@ -15,15 +15,24 @@ import code.name.monkey.retromusic.util.PreferenceUtil;
*/ */
@SuppressLint("RestrictedApi") @SuppressLint("RestrictedApi")
public class RoundedBottomSheetDialogFragment extends BottomSheetDialogFragment { public class RoundedBottomSheetDialogFragment extends BottomSheetDialogFragment {
@Override @Override
public int getTheme() { public int getTheme() {
//noinspection ConstantConditions //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 @NonNull
@Override @Override
public Dialog onCreateDialog(Bundle savedInstanceState) { public Dialog onCreateDialog(Bundle savedInstanceState) {
AbsThemeActivity absThemeActivity = (AbsThemeActivity) getActivity();
if (absThemeActivity != null) {
absThemeActivity.setLightNavigationBar(true);
Dialog dialog = new BottomSheetDialog(getContext(), getTheme());
}
//noinspection ConstantConditions //noinspection ConstantConditions
return new BottomSheetDialog(getContext(), getTheme()); return new BottomSheetDialog(getContext(), getTheme());
} }