Search in sources :

Example 1 with Folder

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();
}
Also used : OnItemClickListener(io.github.ryanhoo.music.ui.base.adapter.OnItemClickListener) Folder(io.github.ryanhoo.music.data.model.Folder) PlayListNowEvent(io.github.ryanhoo.music.event.PlayListNowEvent) DefaultDividerDecoration(io.github.ryanhoo.music.ui.common.DefaultDividerDecoration)

Example 2 with Folder

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();
}
Also used : OnItemClickListener(io.github.ryanhoo.music.ui.base.adapter.OnItemClickListener) Folder(io.github.ryanhoo.music.data.model.Folder) DefaultDividerDecoration(io.github.ryanhoo.music.ui.common.DefaultDividerDecoration)

Example 3 with Folder

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);
}
Also used : List(java.util.List) PlayList(io.github.ryanhoo.music.data.model.PlayList) CompositeSubscription(rx.subscriptions.CompositeSubscription) Subscription(rx.Subscription) Folder(io.github.ryanhoo.music.data.model.Folder) Comparator(java.util.Comparator)

Example 4 with Folder

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);
}
Also used : Song(io.github.ryanhoo.music.data.model.Song) List(java.util.List) PlayList(io.github.ryanhoo.music.data.model.PlayList) CompositeSubscription(rx.subscriptions.CompositeSubscription) Subscription(rx.Subscription) Func1(rx.functions.Func1) Folder(io.github.ryanhoo.music.data.model.Folder) File(java.io.File)

Example 5 with Folder

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;
}
Also used : ArrayList(java.util.ArrayList) Folder(io.github.ryanhoo.music.data.model.Folder) File(java.io.File)

Aggregations

Folder (io.github.ryanhoo.music.data.model.Folder)9 PlayList (io.github.ryanhoo.music.data.model.PlayList)4 Subscription (rx.Subscription)4 CompositeSubscription (rx.subscriptions.CompositeSubscription)4 File (java.io.File)3 List (java.util.List)3 Song (io.github.ryanhoo.music.data.model.Song)2 OnItemClickListener (io.github.ryanhoo.music.ui.base.adapter.OnItemClickListener)2 DefaultDividerDecoration (io.github.ryanhoo.music.ui.common.DefaultDividerDecoration)2 Func1 (rx.functions.Func1)2 PopupMenu (android.support.v7.widget.PopupMenu)1 PlayListNowEvent (io.github.ryanhoo.music.event.PlayListNowEvent)1 AddToPlayListDialogFragment (io.github.ryanhoo.music.ui.playlist.AddToPlayListDialogFragment)1 EditPlayListDialogFragment (io.github.ryanhoo.music.ui.playlist.EditPlayListDialogFragment)1 ArrayList (java.util.ArrayList)1 Comparator (java.util.Comparator)1 Observable (rx.Observable)1 Action1 (rx.functions.Action1)1