Search in sources :

Example 36 with UnifiedTrack

use of com.sdsmdg.harjot.MusicDNA.models.UnifiedTrack in project MusicDNA by harjot-oberai.

the class FolderContentFragment method onViewCreated.

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    bottomMarginLayout = view.findViewById(R.id.bottom_margin_layout);
    if (HomeActivity.isReloaded)
        bottomMarginLayout.getLayoutParams().height = 0;
    else
        bottomMarginLayout.getLayoutParams().height = CommonUtils.dpTopx(65, getContext());
    fragmentTitle = (TextView) view.findViewById(R.id.folder_fragment_title);
    if (SplashActivity.tf4 != null)
        fragmentTitle.setTypeface(SplashActivity.tf4);
    title = (TextView) view.findViewById(R.id.folder_title);
    title.setText(HomeActivity.tempMusicFolder.getFolderName());
    songsText = (TextView) view.findViewById(R.id.folder_tracks_text);
    String s = "";
    if (HomeActivity.tempMusicFolder.getLocalTracks().size() > 1)
        s = "Songs";
    else
        s = "Song";
    songsText.setText(HomeActivity.tempMusicFolder.getLocalTracks().size() + " " + s);
    backBtn = (ImageView) view.findViewById(R.id.folder_content_back_btn);
    backBtn.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            getActivity().onBackPressed();
        }
    });
    addToQueueIcon = (ImageView) view.findViewById(R.id.add_folder_to_queue_icon);
    addToQueueIcon.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            mCallback.folderAddToQueue();
        }
    });
    backdrop = (ImageView) view.findViewById(R.id.folder_backdrop);
    LocalTrack lt = HomeActivity.tempFolderContent.get(0);
    imgLoader.DisplayImage(lt.getPath(), backdrop);
    folderContentRecycler = (RecyclerView) view.findViewById(R.id.folder_content_recycler);
    fContentAdapter = new LocalTrackRecyclerAdapter(HomeActivity.tempFolderContent, getContext());
    mLayoutManager2 = new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false);
    folderContentRecycler.setLayoutManager(mLayoutManager2);
    folderContentRecycler.setItemAnimator(new DefaultItemAnimator());
    folderContentRecycler.setAdapter(fContentAdapter);
    folderContentRecycler.addOnItemTouchListener(new ClickItemTouchListener(folderContentRecycler) {

        @Override
        public boolean onClick(RecyclerView parent, View view, int position, long id) {
            LocalTrack track = HomeActivity.tempMusicFolder.getLocalTracks().get(position);
            if (HomeActivity.queue.getQueue().size() == 0) {
                HomeActivity.queueCurrentIndex = 0;
                HomeActivity.queue.getQueue().add(new UnifiedTrack(true, track, null));
            } else if (HomeActivity.queueCurrentIndex == HomeActivity.queue.getQueue().size() - 1) {
                HomeActivity.queueCurrentIndex++;
                HomeActivity.queue.getQueue().add(new UnifiedTrack(true, track, null));
            } else if (HomeActivity.isReloaded) {
                HomeActivity.isReloaded = false;
                HomeActivity.queueCurrentIndex = HomeActivity.queue.getQueue().size();
                HomeActivity.queue.getQueue().add(new UnifiedTrack(true, track, null));
            } else {
                HomeActivity.queue.getQueue().add(++HomeActivity.queueCurrentIndex, new UnifiedTrack(true, track, null));
            }
            HomeActivity.localSelectedTrack = track;
            HomeActivity.streamSelected = false;
            HomeActivity.localSelected = true;
            HomeActivity.queueCall = false;
            HomeActivity.isReloaded = false;
            mCallback.onFolderContentItemClick(position);
            return true;
        }

        @Override
        public boolean onLongClick(RecyclerView parent, View view, final int position, long id) {
            UnifiedTrack ut = new UnifiedTrack(true, HomeActivity.tempMusicFolder.getLocalTracks().get(position), null);
            CustomGeneralBottomSheetDialog generalBottomSheetDialog = new CustomGeneralBottomSheetDialog();
            generalBottomSheetDialog.setPosition(position);
            generalBottomSheetDialog.setTrack(ut);
            generalBottomSheetDialog.setFragment("Folder");
            generalBottomSheetDialog.show(getActivity().getSupportFragmentManager(), "general_bottom_sheet_dialog");
            return true;
        }

        @Override
        public void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept) {
        }
    });
    playAllFAB = (FloatingActionButton) view.findViewById(R.id.folder_play_all_fab);
    playAllFAB.setBackgroundTintList(ColorStateList.valueOf(HomeActivity.themeColor));
    playAllFAB.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            mCallback.onFolderContentPlayAll();
        }
    });
}
Also used : LocalTrackRecyclerAdapter(com.sdsmdg.harjot.MusicDNA.fragments.LocalMusicFragments.LocalTrackRecyclerAdapter) LocalTrack(com.sdsmdg.harjot.MusicDNA.models.LocalTrack) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) DefaultItemAnimator(android.support.v7.widget.DefaultItemAnimator) CustomGeneralBottomSheetDialog(com.sdsmdg.harjot.MusicDNA.custombottomsheets.CustomGeneralBottomSheetDialog) UnifiedTrack(com.sdsmdg.harjot.MusicDNA.models.UnifiedTrack) RecyclerView(android.support.v7.widget.RecyclerView) ClickItemTouchListener(com.sdsmdg.harjot.MusicDNA.clickitemtouchlistener.ClickItemTouchListener)

Example 37 with UnifiedTrack

use of com.sdsmdg.harjot.MusicDNA.models.UnifiedTrack in project MusicDNA by harjot-oberai.

the class HomeActivity method onTrackSelected.

// //////////////////////////////////////////////////////////////////////////////////////////////
/*
     * Methods for playing selected songs
     * onTrackSelected -> Used to stream tracks from soundcloud
     * onLocalTrackSelected -> Used to play local songs
     */
public void onTrackSelected(int position) {
    isReloaded = false;
    HideBottomFakeToolbar();
    if (!queueCall) {
        CommonUtils.hideKeyboard(this);
        searchView.setQuery("", false);
        searchView.setIconified(true);
        new Thread(new CancelCall()).start();
        isPlayerVisible = true;
        PlayerFragment frag = playerFragment;
        android.support.v4.app.FragmentManager fm = getSupportFragmentManager();
        PlayerFragment newFragment = new PlayerFragment();
        if (frag == null) {
            playerFragment = newFragment;
            int flag = 0;
            for (int i = 0; i < favouriteTracks.getFavourite().size(); i++) {
                UnifiedTrack ut = favouriteTracks.getFavourite().get(i);
                if (!ut.getType() && ut.getStreamTrack().getTitle().equals(selectedTrack.getTitle())) {
                    flag = 1;
                    isFavourite = true;
                    break;
                }
            }
            if (flag == 0) {
                isFavourite = false;
            }
            playerFragment.localIsPlaying = false;
            playerFragment.track = selectedTrack;
            fm.beginTransaction().setCustomAnimations(R.anim.slide_up, R.anim.slide_down, R.anim.slide_up, R.anim.slide_down).add(R.id.player_frag_container, newFragment, "player").show(newFragment).addToBackStack(null).commitAllowingStateLoss();
        } else {
            if (playerFragment.track != null && !playerFragment.localIsPlaying && selectedTrack.getTitle() == playerFragment.track.getTitle()) {
            } else {
                int flag = 0;
                for (int i = 0; i < favouriteTracks.getFavourite().size(); i++) {
                    UnifiedTrack ut = favouriteTracks.getFavourite().get(i);
                    if (!ut.getType() && ut.getStreamTrack().getTitle().equals(selectedTrack.getTitle())) {
                        flag = 1;
                        isFavourite = true;
                        break;
                    }
                }
                if (flag == 0) {
                    isFavourite = false;
                }
                playerFragment.localIsPlaying = false;
                playerFragment.track = selectedTrack;
                frag.refresh();
            }
        }
        if (!isQueueVisible)
            showPlayer();
    } else {
        PlayerFragment frag = playerFragment;
        playerFragment.localIsPlaying = false;
        playerFragment.track = selectedTrack;
        int flag = 0;
        for (int i = 0; i < favouriteTracks.getFavourite().size(); i++) {
            UnifiedTrack ut = favouriteTracks.getFavourite().get(i);
            if (!ut.getType() && ut.getStreamTrack().getTitle().equals(selectedTrack.getTitle())) {
                flag = 1;
                isFavourite = true;
                break;
            }
        }
        if (flag == 0) {
            isFavourite = false;
        }
        frag.refresh();
    }
    if (playerFragment != null && playerFragment.snappyRecyclerView != null) {
        playerFragment.snappyRecyclerView.getAdapter().notifyDataSetChanged();
        playerFragment.snappyRecyclerView.setTransparency();
    }
    QueueFragment qFrag = (QueueFragment) fragMan.findFragmentByTag("queue");
    if (qFrag != null) {
        qFrag.updateQueueAdapter();
    }
    UnifiedTrack track = new UnifiedTrack(false, null, playerFragment.track);
    for (int i = 0; i < recentlyPlayed.getRecentlyPlayed().size(); i++) {
        if (!recentlyPlayed.getRecentlyPlayed().get(i).getType() && recentlyPlayed.getRecentlyPlayed().get(i).getStreamTrack().getTitle().equals(track.getStreamTrack().getTitle())) {
            recentlyPlayed.getRecentlyPlayed().remove(i);
            // rAdapter.notifyItemRemoved(i);
            break;
        }
    }
    recentlyPlayed.getRecentlyPlayed().add(0, track);
    if (recentlyPlayed.getRecentlyPlayed().size() > 50) {
        recentlyPlayed.getRecentlyPlayed().remove(50);
    }
    recentsRecycler.setVisibility(View.VISIBLE);
    recentsNothingText.setVisibility(View.INVISIBLE);
    continuePlayingList.clear();
    for (int i = 0; i < Math.min(10, recentlyPlayed.getRecentlyPlayed().size()); i++) {
        continuePlayingList.add(recentlyPlayed.getRecentlyPlayed().get(i));
    }
    rAdapter.notifyDataSetChanged();
    refreshHeaderImages();
    RecentsFragment rFrag = (RecentsFragment) fragMan.findFragmentByTag("recent");
    if (rFrag != null && rFrag.rtAdpater != null) {
        rFrag.rtAdpater.notifyDataSetChanged();
    }
}
Also used : UnifiedTrack(com.sdsmdg.harjot.MusicDNA.models.UnifiedTrack) RecentsFragment(com.sdsmdg.harjot.MusicDNA.fragments.RecentsFragment.RecentsFragment) QueueFragment(com.sdsmdg.harjot.MusicDNA.fragments.QueueFragment.QueueFragment) TextPaint(android.text.TextPaint) PlayerFragment(com.sdsmdg.harjot.MusicDNA.fragments.PlayerFragment.PlayerFragment)

Example 38 with UnifiedTrack

use of com.sdsmdg.harjot.MusicDNA.models.UnifiedTrack in project MusicDNA by harjot-oberai.

the class HomeActivity method addRecentsToQueue.

@Override
public void addRecentsToQueue() {
    for (UnifiedTrack ut : recentlyPlayed.getRecentlyPlayed()) {
        queue.addToQueue(ut);
    }
    if (playerFragment != null && playerFragment.snappyRecyclerView != null) {
        playerFragment.snappyRecyclerView.getAdapter().notifyDataSetChanged();
        playerFragment.snappyRecyclerView.setTransparency();
    }
    Toast.makeText(ctx, "Added " + recentlyPlayed.getRecentlyPlayed().size() + " song(s) to queue", Toast.LENGTH_SHORT).show();
}
Also used : UnifiedTrack(com.sdsmdg.harjot.MusicDNA.models.UnifiedTrack)

Example 39 with UnifiedTrack

use of com.sdsmdg.harjot.MusicDNA.models.UnifiedTrack in project MusicDNA by harjot-oberai.

the class HomeActivity method playlistAddToQueue.

@Override
public void playlistAddToQueue() {
    Playlist pl = HomeActivity.allPlaylists.getPlaylists().get(tempPlaylistNumber);
    for (UnifiedTrack ut : pl.getSongList()) {
        HomeActivity.queue.addToQueue(ut);
    }
    if (playerFragment != null && playerFragment.snappyRecyclerView != null) {
        playerFragment.snappyRecyclerView.getAdapter().notifyDataSetChanged();
        playerFragment.snappyRecyclerView.setTransparency();
    }
    Toast.makeText(ctx, "Added " + pl.getSongList().size() + " song(s) to queue", Toast.LENGTH_SHORT).show();
}
Also used : Playlist(com.sdsmdg.harjot.MusicDNA.models.Playlist) UnifiedTrack(com.sdsmdg.harjot.MusicDNA.models.UnifiedTrack)

Example 40 with UnifiedTrack

use of com.sdsmdg.harjot.MusicDNA.models.UnifiedTrack in project MusicDNA by harjot-oberai.

the class HomeActivity method refreshHeaderImages.

public void refreshHeaderImages() {
    int numSongs = localTrackList.size();
    int numRecents = recentlyPlayed.getRecentlyPlayed().size();
    if (numRecents == 0) {
        if (numSongs == 0) {
            for (int i = 0; i < 10; i++) {
                imgLoader.DisplayImage(null, imgView[i]);
            }
        } else if (numSongs < 10) {
            for (int i = 0; i < numSongs; i++) {
                imgLoader.DisplayImage(localTrackList.get(i).getPath(), imgView[i]);
            }
            for (int i = numSongs; i < 10; i++) {
                imgLoader.DisplayImage(null, imgView[i]);
            }
        } else {
            for (int i = 0; i < 10; i++) {
                imgLoader.DisplayImage(localTrackList.get(i).getPath(), imgView[i]);
            }
        }
    } else if (numRecents < 10) {
        UnifiedTrack ut;
        for (int i = 0; i < numRecents; i++) {
            ut = recentlyPlayed.getRecentlyPlayed().get(i);
            if (ut.getType())
                imgLoader.DisplayImage(ut.getLocalTrack().getPath(), imgView[i]);
            else
                imgLoader.DisplayImage(ut.getStreamTrack().getArtworkURL(), imgView[i]);
        }
        for (int i = numRecents; i < Math.min(numRecents + numSongs, 10); i++) {
            imgLoader.DisplayImage(localTrackList.get(i - numRecents).getPath(), imgView[i]);
        }
        if (numRecents + numSongs < 10) {
            for (int i = numRecents + numSongs; i < 10; i++) {
                imgLoader.DisplayImage(null, imgView[i]);
            }
        }
    } else {
        UnifiedTrack ut;
        for (int i = 0; i < 10; i++) {
            ut = recentlyPlayed.getRecentlyPlayed().get(i);
            if (ut.getType())
                imgLoader.DisplayImage(ut.getLocalTrack().getPath(), imgView[i]);
            else
                imgLoader.DisplayImage(ut.getStreamTrack().getArtworkURL(), imgView[i]);
        }
    }
}
Also used : UnifiedTrack(com.sdsmdg.harjot.MusicDNA.models.UnifiedTrack) TextPaint(android.text.TextPaint)

Aggregations

UnifiedTrack (com.sdsmdg.harjot.MusicDNA.models.UnifiedTrack)51 LocalTrack (com.sdsmdg.harjot.MusicDNA.models.LocalTrack)25 RecyclerView (android.support.v7.widget.RecyclerView)17 View (android.view.View)17 Track (com.sdsmdg.harjot.MusicDNA.models.Track)16 ImageView (android.widget.ImageView)14 TextView (android.widget.TextView)14 DefaultItemAnimator (android.support.v7.widget.DefaultItemAnimator)11 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)11 ClickItemTouchListener (com.sdsmdg.harjot.MusicDNA.clickitemtouchlistener.ClickItemTouchListener)11 TextPaint (android.text.TextPaint)9 Playlist (com.sdsmdg.harjot.MusicDNA.models.Playlist)8 CustomLocalBottomSheetDialog (com.sdsmdg.harjot.MusicDNA.custombottomsheets.CustomLocalBottomSheetDialog)7 ShowcaseView (com.github.amlcurran.showcaseview.ShowcaseView)6 HomeActivity (com.sdsmdg.harjot.MusicDNA.activities.HomeActivity)6 CustomGeneralBottomSheetDialog (com.sdsmdg.harjot.MusicDNA.custombottomsheets.CustomGeneralBottomSheetDialog)6 Button (android.widget.Button)5 VisualizerView (com.sdsmdg.harjot.MusicDNA.visualizers.VisualizerView)4 Dialog (android.app.Dialog)3 Handler (android.os.Handler)3