use of io.github.ryanhoo.music.data.model.Folder in project StylishMusicPlayer by ryanhoo.
the class FileUtils method folderFromDir.
public static Folder folderFromDir(File dir) {
Folder folder = new Folder(dir.getName(), dir.getAbsolutePath());
List<Song> songs = musicFiles(dir);
folder.setSongs(songs);
folder.setNumOfSongs(songs.size());
return folder;
}
use of io.github.ryanhoo.music.data.model.Folder in project StylishMusicPlayer by ryanhoo.
the class FolderFragment method onAction.
// Adapter Callbacks
@Override
public void onAction(View actionView, final int position) {
final Folder folder = mAdapter.getItem(position);
PopupMenu actionMenu = new PopupMenu(getActivity(), actionView, Gravity.END | Gravity.BOTTOM);
actionMenu.inflate(R.menu.folders_action);
actionMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
switch(item.getItemId()) {
case R.id.menu_item_add_to_play_list:
new AddToPlayListDialogFragment().setCallback(new AddToPlayListDialogFragment.Callback() {
@Override
public void onPlayListSelected(PlayList playList) {
mPresenter.addFolderToPlayList(folder, playList);
}
}).show(getFragmentManager().beginTransaction(), "AddToPlayList");
break;
case R.id.menu_item_create_play_list:
PlayList playList = PlayList.fromFolder(folder);
EditPlayListDialogFragment.editPlayList(playList).setCallback(new EditPlayListDialogFragment.Callback() {
@Override
public void onCreated(PlayList playList) {
// Empty
}
@Override
public void onEdited(PlayList playList) {
mPresenter.createPlayList(playList);
}
}).show(getFragmentManager().beginTransaction(), "CreatePlayList");
break;
case R.id.menu_item_refresh:
mUpdateIndex = position;
mPresenter.refreshFolder(folder);
break;
case R.id.menu_item_delete:
mDeleteIndex = position;
mPresenter.deleteFolder(folder);
break;
}
return true;
}
});
actionMenu.show();
}
use of io.github.ryanhoo.music.data.model.Folder in project StylishMusicPlayer by ryanhoo.
the class FolderPresenter method addFolders.
@Override
public void addFolders(List<File> folders, final List<Folder> existedFolders) {
Subscription subscription = Observable.from(folders).filter(new Func1<File, Boolean>() {
@Override
public Boolean call(File file) {
for (Folder folder : existedFolders) {
if (file.getAbsolutePath().equals(folder.getPath())) {
return false;
}
}
return true;
}
}).flatMap(new Func1<File, Observable<Folder>>() {
@Override
public Observable<Folder> call(File file) {
Folder folder = new Folder();
folder.setName(file.getName());
folder.setPath(file.getAbsolutePath());
List<Song> musicFiles = FileUtils.musicFiles(file);
folder.setSongs(musicFiles);
folder.setNumOfSongs(musicFiles.size());
return Observable.just(folder);
}
}).toList().flatMap(new Func1<List<Folder>, Observable<List<Folder>>>() {
@Override
public Observable<List<Folder>> call(List<Folder> folders) {
return mRepository.create(folders);
}
}).doOnNext(new Action1<List<Folder>>() {
@Override
public void call(List<Folder> folders) {
Collections.sort(folders, new Comparator<Folder>() {
@Override
public int compare(Folder f1, Folder f2) {
return f1.getName().compareToIgnoreCase(f2.getName());
}
});
}
}).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Subscriber<List<Folder>>() {
@Override
public void onStart() {
mView.showLoading();
}
@Override
public void onCompleted() {
mView.hideLoading();
}
@Override
public void onError(Throwable e) {
mView.hideLoading();
mView.handleError(e);
}
@Override
public void onNext(List<Folder> allNewFolders) {
mView.onFoldersAdded(allNewFolders);
}
});
mSubscriptions.add(subscription);
}
use of io.github.ryanhoo.music.data.model.Folder in project StylishMusicPlayer by ryanhoo.
the class FolderPresenter method deleteFolder.
@Override
public void deleteFolder(Folder folder) {
Subscription subscription = mRepository.delete(folder).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Subscriber<Folder>() {
@Override
public void onStart() {
mView.showLoading();
}
@Override
public void onCompleted() {
mView.hideLoading();
}
@Override
public void onError(Throwable e) {
mView.hideLoading();
mView.handleError(e);
}
@Override
public void onNext(Folder folder) {
mView.onFolderDeleted(folder);
}
});
mSubscriptions.add(subscription);
}
Aggregations