use of io.github.ryanhoo.music.data.model.Folder in project StylishMusicPlayer by ryanhoo.
the class PlayListDetailsActivity method onCreate.
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
Folder folder = getIntent().getParcelableExtra(EXTRA_FOLDER);
mPlayList = getIntent().getParcelableExtra(EXTRA_PLAY_LIST);
if (folder == null && mPlayList == null) {
Log.e(TAG, "onCreate: folder & play list can't be both null!");
finish();
}
if (folder != null) {
isFolder = true;
mPlayList = PlayList.fromFolder(folder);
}
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_play_list_details);
ButterKnife.bind(this);
supportActionBar(toolbar);
if (getSupportActionBar() != null) {
getSupportActionBar().setTitle(mPlayList.getName());
}
mAdapter = new SongAdapter(this, mPlayList.getSongs());
mAdapter.setActionCallback(this);
mAdapter.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(int position) {
RxBus.getInstance().post(new PlayListNowEvent(mPlayList, position));
}
});
recyclerView.setAdapter(mAdapter);
recyclerView.addItemDecoration(new DefaultDividerDecoration());
emptyView.setVisibility(mPlayList.getNumOfSongs() > 0 ? View.GONE : View.VISIBLE);
new PlayListDetailsPresenter(AppRepository.getInstance(), this).subscribe();
}
use of io.github.ryanhoo.music.data.model.Folder in project StylishMusicPlayer by ryanhoo.
the class FolderFragment method onViewCreated.
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
ButterKnife.bind(this, view);
mAdapter = new FolderAdapter(getActivity(), null);
mAdapter.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(int position) {
Folder folder = mAdapter.getItem(position);
startActivity(PlayListDetailsActivity.launchIntentForFolder(getActivity(), folder));
}
});
mAdapter.setAddFolderCallback(this);
recyclerView.setAdapter(mAdapter);
recyclerView.addItemDecoration(new DefaultDividerDecoration());
new FolderPresenter(AppRepository.getInstance(), this).subscribe();
}
use of io.github.ryanhoo.music.data.model.Folder in project StylishMusicPlayer by ryanhoo.
the class FolderPresenter method loadFolders.
@Override
public void loadFolders() {
Subscription subscription = mRepository.folders().subscribeOn(Schedulers.io()).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());
}
});
}
}).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> folders) {
mView.onFoldersLoaded(folders);
}
});
mSubscriptions.add(subscription);
}
use of io.github.ryanhoo.music.data.model.Folder in project StylishMusicPlayer by ryanhoo.
the class FolderPresenter method refreshFolder.
@Override
public void refreshFolder(final Folder folder) {
Subscription subscription = Observable.just(FileUtils.musicFiles(new File(folder.getPath()))).flatMap(new Func1<List<Song>, Observable<Folder>>() {
@Override
public Observable<Folder> call(List<Song> songs) {
folder.setSongs(songs);
folder.setNumOfSongs(songs.size());
return mRepository.update(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.onFolderUpdated(folder);
}
});
mSubscriptions.add(subscription);
}
use of io.github.ryanhoo.music.data.model.Folder in project StylishMusicPlayer by ryanhoo.
the class DBUtils method generateDefaultFolders.
public static List<Folder> generateDefaultFolders() {
List<Folder> defaultFolders = new ArrayList<>(3);
// File sdcardDir = Environment.getExternalStorageDirectory();
File downloadDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
File musicDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MUSIC);
// defaultFolders.add(FileUtils.folderFromDir(sdcardDir));
defaultFolders.add(FileUtils.folderFromDir(downloadDir));
defaultFolders.add(FileUtils.folderFromDir(musicDir));
return defaultFolders;
}
Aggregations