Search in sources :

Example 6 with ClickItemTouchListener

use of com.sdsmdg.harjot.MusicDNA.clickitemtouchlistener.ClickItemTouchListener in project MusicDNA by harjot-oberai.

the class ViewArtistFragment method onViewCreated.

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    backBtn = (ImageView) view.findViewById(R.id.view_artist_back_btn);
    backBtn.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            getActivity().onBackPressed();
        }
    });
    backdrop = (ImageView) view.findViewById(R.id.artist_backdrop);
    imgLoader.DisplayImage(HomeActivity.tempArtist.getArtistSongs().get(0).getPath(), backdrop);
    fragTitle = (TextView) view.findViewById(R.id.artist_fragment_title);
    if (SplashActivity.tf4 != null)
        fragTitle.setTypeface(SplashActivity.tf4);
    artistTitle = (TextView) view.findViewById(R.id.artist_title);
    artistTitle.setText(HomeActivity.tempArtist.getName());
    artistTrackText = (TextView) view.findViewById(R.id.artist_tracks_text);
    int tmp = HomeActivity.tempArtist.getArtistSongs().size();
    String details1;
    if (tmp == 1) {
        details1 = "1 Song ";
    } else {
        details1 = tmp + " Songs ";
    }
    artistTrackText.setText(details1);
    addToQueueIcon = (ImageView) view.findViewById(R.id.add_artist_to_queue_icon);
    addToQueueIcon.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            mCallback.addArtistToQueue();
        }
    });
    bottomMarginLayout = view.findViewById(R.id.bottom_margin_layout);
    if (HomeActivity.isReloaded)
        bottomMarginLayout.getLayoutParams().height = 0;
    else
        bottomMarginLayout.getLayoutParams().height = CommonUtils.dpTopx(65, getContext());
    rv = (RecyclerView) view.findViewById(R.id.artist_songs_recycler);
    lAdapter = new LocalTrackRecyclerAdapter(HomeActivity.tempArtist.getArtistSongs(), getContext());
    LinearLayoutManager llManager = new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false);
    rv.setLayoutManager(llManager);
    rv.setItemAnimator(new DefaultItemAnimator());
    rv.setAdapter(lAdapter);
    rv.addOnItemTouchListener(new ClickItemTouchListener(rv) {

        @Override
        public boolean onClick(RecyclerView parent, View view, int position, long id) {
            LocalTrack track = HomeActivity.tempArtist.getArtistSongs().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.onArtistSongClick();
            return true;
        }

        @Override
        public boolean onLongClick(RecyclerView parent, View view, final int position, long id) {
            CustomLocalBottomSheetDialog localBottomSheetDialog = new CustomLocalBottomSheetDialog();
            localBottomSheetDialog.setPosition(position);
            localBottomSheetDialog.setLocalTrack(activity.tempArtist.getArtistSongs().get(position));
            localBottomSheetDialog.setFragment("Artist");
            localBottomSheetDialog.show(activity.getSupportFragmentManager(), "local_song_bottom_sheet");
            return true;
        }

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

        @Override
        public void onClick(View v) {
            HomeActivity.queue.getQueue().clear();
            for (int i = 0; i < HomeActivity.tempArtist.getArtistSongs().size(); i++) {
                UnifiedTrack ut = new UnifiedTrack(true, HomeActivity.tempArtist.getArtistSongs().get(i), null);
                HomeActivity.queue.getQueue().add(ut);
            }
            mCallback.onArtistPlayAll();
        }
    });
}
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) CustomLocalBottomSheetDialog(com.sdsmdg.harjot.MusicDNA.custombottomsheets.CustomLocalBottomSheetDialog) UnifiedTrack(com.sdsmdg.harjot.MusicDNA.models.UnifiedTrack) RecyclerView(android.support.v7.widget.RecyclerView) ClickItemTouchListener(com.sdsmdg.harjot.MusicDNA.clickitemtouchlistener.ClickItemTouchListener)

Example 7 with ClickItemTouchListener

use of com.sdsmdg.harjot.MusicDNA.clickitemtouchlistener.ClickItemTouchListener in project MusicDNA by harjot-oberai.

the class ViewPlaylistFragment 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.playlist_fragment_title);
    if (SplashActivity.tf4 != null)
        fragmentTitle.setTypeface(SplashActivity.tf4);
    title = (TextView) view.findViewById(R.id.playlist_title);
    title.setText(HomeActivity.tempPlaylist.getPlaylistName());
    songsText = (TextView) view.findViewById(R.id.playlist_tracks_text);
    String s = "";
    if (HomeActivity.tempPlaylist.getSongList().size() > 1)
        s = "Songs";
    else
        s = "Song";
    songsText.setText(HomeActivity.tempPlaylist.getSongList().size() + " " + s);
    backBtn = (ImageView) view.findViewById(R.id.view_playlist_back_btn);
    backBtn.setOnClickListener(new View.OnClickListener() {

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

        @Override
        public void onClick(View v) {
            mCallback.playlistRename();
        }
    });
    addToQueueIcon = (ImageView) view.findViewById(R.id.add_playlist_to_queue_icon);
    addToQueueIcon.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            mCallback.playlistAddToQueue();
        }
    });
    backdrop = (ImageView) view.findViewById(R.id.playlist_backdrop);
    UnifiedTrack ut = HomeActivity.tempPlaylist.getSongList().get(0);
    if (ut.getType()) {
        LocalTrack lt = ut.getLocalTrack();
        imgLoader.DisplayImage(lt.getPath(), backdrop);
    } else {
        Track t = ut.getStreamTrack();
        Picasso.with(getContext()).load(t.getArtworkURL()).resize(100, 100).error(R.drawable.ic_default).placeholder(R.drawable.ic_default).into(backdrop);
    }
    playlistRecyler = (RecyclerView) view.findViewById(R.id.view_playlist_recycler);
    plAdapter = new PlaylistTrackAdapter(HomeActivity.tempPlaylist.getSongList(), this, getContext());
    mLayoutManager2 = new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false);
    playlistRecyler.setLayoutManager(mLayoutManager2);
    playlistRecyler.setItemAnimator(new DefaultItemAnimator());
    playlistRecyler.setAdapter(plAdapter);
    playlistRecyler.addOnItemTouchListener(new ClickItemTouchListener(playlistRecyler) {

        @Override
        public boolean onClick(RecyclerView parent, View view, int position, long id) {
            mCallback.onPlaylistItemClicked(position);
            return true;
        }

        @Override
        public boolean onLongClick(RecyclerView parent, View view, int position, long id) {
            return true;
        }

        @Override
        public void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept) {
        }
    });
    playAll = (FloatingActionButton) view.findViewById(R.id.play_all_fab);
    if (HomeActivity.tempPlaylist.getSongList().size() == 0) {
        playAll.setVisibility(View.GONE);
    }
    playAll.setBackgroundTintList(ColorStateList.valueOf(HomeActivity.themeColor));
    playAll.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            int size = HomeActivity.tempPlaylist.getSongList().size();
            HomeActivity.queue.getQueue().clear();
            for (int i = 0; i < size; i++) {
                HomeActivity.queue.addToQueue(HomeActivity.tempPlaylist.getSongList().get(i));
            }
            HomeActivity.queueCurrentIndex = 0;
            mCallback.onPlaylistPlayAll();
        }
    });
    ItemTouchHelper.Callback callback = new SimpleItemTouchHelperCallback(plAdapter);
    mItemTouchHelper = new ItemTouchHelper(callback);
    mItemTouchHelper.attachToRecyclerView(playlistRecyler);
}
Also used : SimpleItemTouchHelperCallback(com.sdsmdg.harjot.MusicDNA.itemtouchhelpers.SimpleItemTouchHelperCallback) 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) ItemTouchHelper(android.support.v7.widget.helper.ItemTouchHelper) UnifiedTrack(com.sdsmdg.harjot.MusicDNA.models.UnifiedTrack) RecyclerView(android.support.v7.widget.RecyclerView) ClickItemTouchListener(com.sdsmdg.harjot.MusicDNA.clickitemtouchlistener.ClickItemTouchListener) UnifiedTrack(com.sdsmdg.harjot.MusicDNA.models.UnifiedTrack) LocalTrack(com.sdsmdg.harjot.MusicDNA.models.LocalTrack) Track(com.sdsmdg.harjot.MusicDNA.models.Track)

Example 8 with ClickItemTouchListener

use of com.sdsmdg.harjot.MusicDNA.clickitemtouchlistener.ClickItemTouchListener in project MusicDNA by harjot-oberai.

the class RecentsFragment method onViewCreated.

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    backBtn = (ImageView) view.findViewById(R.id.recents_back_btn);
    backBtn.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            getActivity().onBackPressed();
        }
    });
    fragIcon = (ImageView) view.findViewById(R.id.recents_frag_icon);
    fragIcon.setImageTintList(ColorStateList.valueOf(HomeActivity.themeColor));
    fragTitle = (TextView) view.findViewById(R.id.recents_fragment_title);
    if (SplashActivity.tf4 != null)
        fragTitle.setTypeface(SplashActivity.tf4);
    addToQueueIcon = (ImageView) view.findViewById(R.id.add_recents_to_queue_icon);
    addToQueueIcon.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            mCallback.addRecentsToQueue();
        }
    });
    backdrop = (ImageView) view.findViewById(R.id.recents_backdrop);
    if (HomeActivity.recentlyPlayed.getRecentlyPlayed().size() > 0) {
        UnifiedTrack ut = HomeActivity.recentlyPlayed.getRecentlyPlayed().get(0);
        if (ut.getType()) {
            LocalTrack lt = ut.getLocalTrack();
            imgLoader.DisplayImage(lt.getPath(), backdrop);
        } else {
            Track t = ut.getStreamTrack();
            Picasso.with(getContext()).load(t.getArtworkURL()).resize(100, 100).error(R.drawable.ic_default).placeholder(R.drawable.ic_default).into(backdrop);
        }
    }
    bottomMarginLayout = view.findViewById(R.id.bottom_margin_layout);
    if (HomeActivity.isReloaded)
        bottomMarginLayout.getLayoutParams().height = 0;
    else
        bottomMarginLayout.getLayoutParams().height = CommonUtils.dpTopx(65, getContext());
    noContent = (LinearLayout) view.findViewById(R.id.no_recents_content);
    recentRecycler = (RecyclerView) view.findViewById(R.id.view_recent_recycler);
    rtAdpater = new RecentsTrackAdapter(HomeActivity.recentlyPlayed.getRecentlyPlayed(), this, getContext());
    mLayoutManager2 = new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false);
    recentRecycler.setLayoutManager(mLayoutManager2);
    recentRecycler.setItemAnimator(new DefaultItemAnimator());
    recentRecycler.setAdapter(rtAdpater);
    recentRecycler.addOnItemTouchListener(new ClickItemTouchListener(recentRecycler) {

        @Override
        public boolean onClick(RecyclerView parent, View view, int position, long id) {
            UnifiedTrack ut = HomeActivity.recentlyPlayed.getRecentlyPlayed().get(position);
            boolean isRepeat = false;
            int pos = 0;
            for (int i = 0; i < HomeActivity.queue.getQueue().size(); i++) {
                UnifiedTrack ut1 = HomeActivity.queue.getQueue().get(i);
                if (ut1.getType() && ut.getType() && ut1.getLocalTrack().getTitle().equals(ut.getLocalTrack().getTitle())) {
                    isRepeat = true;
                    pos = i;
                    break;
                }
                if (!ut1.getType() && !ut.getType() && ut1.getStreamTrack().getTitle().equals(ut.getStreamTrack().getTitle())) {
                    isRepeat = true;
                    pos = i;
                    break;
                }
            }
            if (!isRepeat) {
                if (ut.getType()) {
                    LocalTrack track = ut.getLocalTrack();
                    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.onRecentItemClicked(true);
                } else {
                    Track track = ut.getStreamTrack();
                    if (HomeActivity.queue.getQueue().size() == 0) {
                        HomeActivity.queueCurrentIndex = 0;
                        HomeActivity.queue.getQueue().add(new UnifiedTrack(false, null, track));
                    } else if (HomeActivity.queueCurrentIndex == HomeActivity.queue.getQueue().size() - 1) {
                        HomeActivity.queueCurrentIndex++;
                        HomeActivity.queue.getQueue().add(new UnifiedTrack(false, null, track));
                    } else if (HomeActivity.isReloaded) {
                        HomeActivity.isReloaded = false;
                        HomeActivity.queueCurrentIndex = HomeActivity.queue.getQueue().size();
                        HomeActivity.queue.getQueue().add(new UnifiedTrack(false, null, track));
                    } else {
                        HomeActivity.queue.getQueue().add(++HomeActivity.queueCurrentIndex, new UnifiedTrack(false, null, track));
                    }
                    HomeActivity.selectedTrack = track;
                    HomeActivity.streamSelected = true;
                    HomeActivity.localSelected = false;
                    HomeActivity.queueCall = false;
                    HomeActivity.isReloaded = false;
                    mCallback.onRecentItemClicked(false);
                }
            } else {
                mCallback.onRecentFromQueue(pos);
            }
            return true;
        }

        @Override
        public boolean onLongClick(RecyclerView parent, View view, int position, long id) {
            if (position != -1) {
                final UnifiedTrack ut = HomeActivity.recentlyPlayed.getRecentlyPlayed().get(position);
                CustomGeneralBottomSheetDialog generalBottomSheetDialog = new CustomGeneralBottomSheetDialog();
                generalBottomSheetDialog.setPosition(position);
                generalBottomSheetDialog.setTrack(ut);
                generalBottomSheetDialog.setFragment("Recents");
                generalBottomSheetDialog.show(getActivity().getSupportFragmentManager(), "general_bottom_sheet_dialog");
            }
            return true;
        }

        @Override
        public void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept) {
        }
    });
    shuffleFab = (FloatingActionButton) view.findViewById(R.id.play_all_fab_recent);
    if (HomeActivity.recentlyPlayed != null && HomeActivity.recentlyPlayed.getRecentlyPlayed().size() > 0) {
        noContent.setVisibility(View.INVISIBLE);
        shuffleFab.setVisibility(View.VISIBLE);
    } else {
        noContent.setVisibility(View.VISIBLE);
        shuffleFab.setVisibility(View.INVISIBLE);
    }
    shuffleFab.setBackgroundTintList(ColorStateList.valueOf(HomeActivity.themeColor));
    shuffleFab.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (HomeActivity.recentlyPlayed.getRecentlyPlayed().size() > 0) {
                HomeActivity.queue.getQueue().clear();
                for (int i = 0; i < HomeActivity.recentlyPlayed.getRecentlyPlayed().size(); i++) {
                    HomeActivity.queue.getQueue().add(HomeActivity.recentlyPlayed.getRecentlyPlayed().get(i));
                }
                Random r = new Random();
                mCallback.onRecentFromQueue(r.nextInt(HomeActivity.queue.getQueue().size()));
            }
        }
    });
    ItemTouchHelper.Callback callback = new SimpleItemTouchHelperCallback(rtAdpater);
    mItemTouchHelper = new ItemTouchHelper(callback);
    mItemTouchHelper.attachToRecyclerView(recentRecycler);
}
Also used : SimpleItemTouchHelperCallback(com.sdsmdg.harjot.MusicDNA.itemtouchhelpers.SimpleItemTouchHelperCallback) 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) ItemTouchHelper(android.support.v7.widget.helper.ItemTouchHelper) Random(java.util.Random) UnifiedTrack(com.sdsmdg.harjot.MusicDNA.models.UnifiedTrack) RecyclerView(android.support.v7.widget.RecyclerView) ClickItemTouchListener(com.sdsmdg.harjot.MusicDNA.clickitemtouchlistener.ClickItemTouchListener) UnifiedTrack(com.sdsmdg.harjot.MusicDNA.models.UnifiedTrack) LocalTrack(com.sdsmdg.harjot.MusicDNA.models.LocalTrack) Track(com.sdsmdg.harjot.MusicDNA.models.Track)

Example 9 with ClickItemTouchListener

use of com.sdsmdg.harjot.MusicDNA.clickitemtouchlistener.ClickItemTouchListener in project MusicDNA by harjot-oberai.

the class NewPlaylistFragment method onViewCreated.

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    backBtn = (ImageView) view.findViewById(R.id.add_to_playlist_back_btn);
    backBtn.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            getActivity().onBackPressed();
        }
    });
    fragTitle = (TextView) view.findViewById(R.id.add_to_playlist_fragment_title);
    if (SplashActivity.tf4 != null)
        fragTitle.setTypeface(SplashActivity.tf4);
    savePlaylist = (FloatingActionButton) view.findViewById(R.id.save_playlist_fab);
    savePlaylist.setBackgroundTintList(ColorStateList.valueOf(HomeActivity.themeColor));
    savePlaylist.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            mCallback.onDone();
        }
    });
    bottomMarginLayout = view.findViewById(R.id.bottom_margin_layout);
    if (HomeActivity.isReloaded)
        bottomMarginLayout.getLayoutParams().height = 0;
    else
        bottomMarginLayout.getLayoutParams().height = CommonUtils.dpTopx(65, getContext());
    numberSelected = 0;
    HomeActivity.finalSelectedTracks.clear();
    atpAdapter.notifyDataSetChanged();
    clearSearchBtn = (ImageView) view.findViewById(R.id.clear_search_btn);
    clearSearchBtn.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            hideKeyboard();
            searchBox.setText("");
            finalList.clear();
            for (int i = 0; i < HomeActivity.localTrackList.size(); i++) {
                finalList.add(HomeActivity.localTrackList.get(i));
            }
            atpAdapter.notifyDataSetChanged();
        }
    });
    searchBox = (EditText) view.findViewById(R.id.add_to_playlist_search);
    searchBox.addTextChangedListener(new TextWatcher() {

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            if (s.toString().equals("")) {
                finalList.clear();
                for (int i = 0; i < HomeActivity.localTrackList.size(); i++) {
                    finalList.add(HomeActivity.localTrackList.get(i));
                }
            } else {
                finalList.clear();
                for (int i = 0; i < HomeActivity.localTrackList.size(); i++) {
                    LocalTrack lt = HomeActivity.localTrackList.get(i);
                    if (lt.getTitle().toLowerCase().contains(s.toString().trim().toLowerCase())) {
                        finalList.add(lt);
                    }
                }
            }
            atpAdapter.notifyDataSetChanged();
        }

        @Override
        public void afterTextChanged(Editable s) {
        }
    });
    numberSelectedSongs = (TextView) view.findViewById(R.id.number_selected_songs);
    clearText = (TextView) view.findViewById(R.id.clear_selected_songs_text);
    clearText.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            mCallback.onCancel();
            atpAdapter.notifyDataSetChanged();
            numberSelected = 0;
            numberSelectedSongs.setText(String.valueOf(numberSelected) + " selected");
        }
    });
    rv = (RecyclerView) view.findViewById(R.id.add_to_playlist_recycler);
    mLayoutManager2 = new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false);
    rv.setLayoutManager(mLayoutManager2);
    rv.setItemAnimator(new DefaultItemAnimator());
    rv.setAdapter(atpAdapter);
    rv.addOnItemTouchListener(new ClickItemTouchListener(rv) {

        @Override
        public boolean onClick(RecyclerView parent, View view, int position, long id) {
            LocalTrack lt = finalList.get(position);
            if (HomeActivity.finalSelectedTracks.contains(lt)) {
                HomeActivity.finalSelectedTracks.remove(lt);
                numberSelected--;
            } else {
                HomeActivity.finalSelectedTracks.add(lt);
                numberSelected++;
            }
            numberSelectedSongs.setText(String.valueOf(numberSelected) + " selected");
            CheckBox cb = (CheckBox) view.findViewById(R.id.is_selected_checkbox);
            cb.setChecked(!cb.isChecked());
            atpAdapter.notifyItemChanged(position);
            return false;
        }

        @Override
        public boolean onLongClick(RecyclerView parent, View view, int position, long id) {
            return false;
        }

        @Override
        public void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept) {
        }
    });
}
Also used : 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) CheckBox(android.widget.CheckBox) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) RecyclerView(android.support.v7.widget.RecyclerView) ClickItemTouchListener(com.sdsmdg.harjot.MusicDNA.clickitemtouchlistener.ClickItemTouchListener)

Example 10 with ClickItemTouchListener

use of com.sdsmdg.harjot.MusicDNA.clickitemtouchlistener.ClickItemTouchListener in project MusicDNA by harjot-oberai.

the class LocalMusicFragment 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());
    shuffleFab = (FloatingActionButton) view.findViewById(R.id.play_all_fab_local);
    if (HomeActivity.localTrackList.size() == 0) {
        shuffleFab.setVisibility(View.INVISIBLE);
    }
    shuffleFab.setBackgroundTintList(ColorStateList.valueOf(HomeActivity.themeColor));
    shuffleFab.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            HomeActivity.queue.getQueue().clear();
            for (int i = 0; i < HomeActivity.localTrackList.size(); i++) {
                UnifiedTrack ut = new UnifiedTrack(true, HomeActivity.localTrackList.get(i), null);
                HomeActivity.queue.getQueue().add(ut);
            }
            if (HomeActivity.queue.getQueue().size() > 0) {
                Random r = new Random();
                int tmp = r.nextInt(HomeActivity.queue.getQueue().size());
                HomeActivity.queueCurrentIndex = tmp;
                LocalTrack track = HomeActivity.localTrackList.get(tmp);
                HomeActivity.localSelectedTrack = track;
                HomeActivity.streamSelected = false;
                HomeActivity.localSelected = true;
                HomeActivity.queueCall = false;
                HomeActivity.isReloaded = false;
                mCallback.onLocalTrackSelected(-1);
            }
        }
    });
    lv = (RecyclerView) view.findViewById(R.id.localMusicList);
    adapter = new LocalTrackRecyclerAdapter(HomeActivity.finalLocalSearchResultList, getContext());
    mLayoutManager2 = new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false);
    lv.setLayoutManager(mLayoutManager2);
    lv.setItemAnimator(new DefaultItemAnimator());
    lv.setAdapter(adapter);
    lv.addOnItemTouchListener(new ClickItemTouchListener(lv) {

        @Override
        public boolean onClick(RecyclerView parent, View view, int position, long id) {
            if (position >= 0) {
                HomeActivity.queue.getQueue().clear();
                for (int i = 0; i < HomeActivity.localTrackList.size(); i++) {
                    UnifiedTrack ut = new UnifiedTrack(true, HomeActivity.localTrackList.get(i), null);
                    HomeActivity.queue.getQueue().add(ut);
                }
                HomeActivity.queueCurrentIndex = getPosition(HomeActivity.finalLocalSearchResultList.get(position));
                LocalTrack track = HomeActivity.finalLocalSearchResultList.get(position);
                HomeActivity.localSelectedTrack = track;
                HomeActivity.streamSelected = false;
                HomeActivity.localSelected = true;
                HomeActivity.queueCall = false;
                HomeActivity.isReloaded = false;
                mCallback.onLocalTrackSelected(-1);
            }
            return true;
        }

        @Override
        public boolean onLongClick(RecyclerView parent, View view, final int position, long id) {
            if (position >= 0) {
                CustomLocalBottomSheetDialog localBottomSheetDialog = new CustomLocalBottomSheetDialog();
                localBottomSheetDialog.setPosition(position);
                localBottomSheetDialog.setLocalTrack(activity.finalLocalSearchResultList.get(position));
                localBottomSheetDialog.show(activity.getSupportFragmentManager(), "local_song_bottom_sheet");
            }
            return true;
        }

        @Override
        public void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept) {
        }
    });
    Button mEndButton = new Button(getContext());
    mEndButton.setBackgroundColor(HomeActivity.themeColor);
    mEndButton.setTextColor(Color.WHITE);
    showCase = new ShowcaseView.Builder(getActivity()).blockAllTouches().singleShot(1).setStyle(R.style.CustomShowcaseTheme).useDecorViewAsParent().replaceEndButton(mEndButton).setContentTitlePaint(HomeActivity.tp).setTarget(new ViewTarget(R.id.songs_tab_alt_showcase, getActivity())).setContentTitle("All Songs").setContentText("All local Songs listed here.Click to Play.Long click for more options").build();
    showCase.setButtonText("Next");
    showCase.setButtonPosition(HomeActivity.lps);
    showCase.overrideButtonClick(new View.OnClickListener() {

        int count1 = 0;

        @Override
        public void onClick(View v) {
            count1++;
            switch(count1) {
                case 1:
                    RelativeLayout.LayoutParams lps = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
                    lps.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
                    lps.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
                    int margin = ((Number) (getResources().getDisplayMetrics().density * 12)).intValue();
                    lps.setMargins(margin, margin, margin, 5 + HomeActivity.navBarHeightSizeinDp);
                    showCase.setTarget(new ViewTarget(shuffleFab.getId(), getActivity()));
                    showCase.setContentTitle("Shuffle");
                    showCase.setContentText("Play all songs, shuffled randomly");
                    showCase.setButtonText("Done");
                    showCase.setButtonPosition(lps);
                    break;
                case 2:
                    showCase.hide();
                    break;
            }
        }
    });
}
Also used : LocalTrack(com.sdsmdg.harjot.MusicDNA.models.LocalTrack) ViewTarget(com.github.amlcurran.showcaseview.targets.ViewTarget) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) ShowcaseView(com.github.amlcurran.showcaseview.ShowcaseView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) DefaultItemAnimator(android.support.v7.widget.DefaultItemAnimator) CustomLocalBottomSheetDialog(com.sdsmdg.harjot.MusicDNA.custombottomsheets.CustomLocalBottomSheetDialog) Random(java.util.Random) Button(android.widget.Button) FloatingActionButton(android.support.design.widget.FloatingActionButton) UnifiedTrack(com.sdsmdg.harjot.MusicDNA.models.UnifiedTrack) RelativeLayout(android.widget.RelativeLayout) RecyclerView(android.support.v7.widget.RecyclerView) ClickItemTouchListener(com.sdsmdg.harjot.MusicDNA.clickitemtouchlistener.ClickItemTouchListener) ShowcaseView(com.github.amlcurran.showcaseview.ShowcaseView)

Aggregations

DefaultItemAnimator (android.support.v7.widget.DefaultItemAnimator)14 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)14 RecyclerView (android.support.v7.widget.RecyclerView)14 View (android.view.View)14 ClickItemTouchListener (com.sdsmdg.harjot.MusicDNA.clickitemtouchlistener.ClickItemTouchListener)14 ImageView (android.widget.ImageView)12 TextView (android.widget.TextView)12 UnifiedTrack (com.sdsmdg.harjot.MusicDNA.models.UnifiedTrack)10 LocalTrack (com.sdsmdg.harjot.MusicDNA.models.LocalTrack)8 ItemTouchHelper (android.support.v7.widget.helper.ItemTouchHelper)4 Button (android.widget.Button)4 ShowcaseView (com.github.amlcurran.showcaseview.ShowcaseView)4 ViewTarget (com.github.amlcurran.showcaseview.targets.ViewTarget)4 SimpleItemTouchHelperCallback (com.sdsmdg.harjot.MusicDNA.itemtouchhelpers.SimpleItemTouchHelperCallback)4 Track (com.sdsmdg.harjot.MusicDNA.models.Track)4 MenuItem (android.view.MenuItem)3 CustomGeneralBottomSheetDialog (com.sdsmdg.harjot.MusicDNA.custombottomsheets.CustomGeneralBottomSheetDialog)3 CustomLocalBottomSheetDialog (com.sdsmdg.harjot.MusicDNA.custombottomsheets.CustomLocalBottomSheetDialog)3 LocalTrackRecyclerAdapter (com.sdsmdg.harjot.MusicDNA.fragments.LocalMusicFragments.LocalTrackRecyclerAdapter)3 Handler (android.os.Handler)2