Search in sources :

Example 11 with ClickItemTouchListener

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

the class StreamMusicFragment 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());
    lv = (RecyclerView) view.findViewById(R.id.trackList);
    adapter = new StreamTrackListAdapter(getContext(), HomeActivity.streamingTrackList);
    LinearLayoutManager 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) {
            Track track = HomeActivity.streamingTrackList.get(position);
            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.onTrackSelected(position);
            return true;
        }

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

        @Override
        public void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept) {
        }
    });
}
Also used : LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View) 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) Track(com.sdsmdg.harjot.MusicDNA.models.Track) UnifiedTrack(com.sdsmdg.harjot.MusicDNA.models.UnifiedTrack)

Example 12 with ClickItemTouchListener

use of com.sdsmdg.harjot.MusicDNA.clickitemtouchlistener.ClickItemTouchListener 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 13 with ClickItemTouchListener

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

the class FolderFragment method onViewCreated.

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

        @Override
        public void onClick(View v) {
            getActivity().onBackPressed();
        }
    });
    fragmentTitle = (TextView) view.findViewById(R.id.all_folder_fragment_title);
    if (SplashActivity.tf4 != null)
        fragmentTitle.setTypeface(SplashActivity.tf4);
    fragIcon = (ImageView) view.findViewById(R.id.all_folder_frag_icon);
    fragIcon.setImageTintList(ColorStateList.valueOf(HomeActivity.themeColor));
    initializeHeaderImages(view);
    bottomMarginLayout = view.findViewById(R.id.bottom_margin_layout);
    if (HomeActivity.isReloaded)
        bottomMarginLayout.getLayoutParams().height = 0;
    else
        bottomMarginLayout.getLayoutParams().height = CommonUtils.dpTopx(65, getContext());
    allFoldersRecycler = (RecyclerView) view.findViewById(R.id.all_folders_recycler);
    mfAdapter = new FolderRecyclerAdapter(HomeActivity.allMusicFolders.getMusicFolders(), getContext());
    mLayoutManager2 = new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false);
    allFoldersRecycler.setLayoutManager(mLayoutManager2);
    allFoldersRecycler.setItemAnimator(new DefaultItemAnimator());
    allFoldersRecycler.setAdapter(mfAdapter);
    allFoldersRecycler.addOnItemTouchListener(new ClickItemTouchListener(allFoldersRecycler) {

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

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

        @Override
        public void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept) {
        }
    });
}
Also used : RecyclerView(android.support.v7.widget.RecyclerView) ClickItemTouchListener(com.sdsmdg.harjot.MusicDNA.clickitemtouchlistener.ClickItemTouchListener) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) ImageView(android.widget.ImageView) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) View(android.view.View) DefaultItemAnimator(android.support.v7.widget.DefaultItemAnimator)

Example 14 with ClickItemTouchListener

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

the class ViewSavedDNA method onViewCreated.

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

        @Override
        public void onClick(View v) {
            getActivity().onBackPressed();
        }
    });
    fragmentTitle = (TextView) view.findViewById(R.id.view_saved_dna_fragment_title);
    if (SplashActivity.tf4 != null)
        fragmentTitle.setTypeface(SplashActivity.tf4);
    bottomMarginLayout = view.findViewById(R.id.bottom_margin_layout);
    if (HomeActivity.isReloaded)
        bottomMarginLayout.getLayoutParams().height = 0;
    else
        bottomMarginLayout.getLayoutParams().height = CommonUtils.dpTopx(65, getContext());
    mVisualizerView2 = (VisualizerView2) view.findViewById(R.id.saved_dna_visualizer);
    viewDnaRecycler = (RecyclerView) view.findViewById(R.id.saved_dna_recycler);
    noSavedContent = (LinearLayout) view.findViewById(R.id.no_saved_dnas);
    if (SplashActivity.tf4 != null)
        ((TextView) view.findViewById(R.id.no_saved_content_text)).setTypeface(SplashActivity.tf4);
    if (HomeActivity.savedDNAs == null || HomeActivity.savedDNAs.getSavedDNAs().size() == 0) {
        noSavedContent.setVisibility(View.VISIBLE);
        mVisualizerView2.setVisibility(View.INVISIBLE);
        viewDnaRecycler.setVisibility(View.INVISIBLE);
    } else {
        noSavedContent.setVisibility(View.GONE);
        mVisualizerView2.setVisibility(View.VISIBLE);
        viewDnaRecycler.setVisibility(View.VISIBLE);
    }
    if (HomeActivity.savedDNAs != null)
        vdAdapter = new ViewSavedDnaRecyclerAdapter(HomeActivity.savedDNAs.getSavedDNAs(), getContext(), this);
    else
        vdAdapter = new ViewSavedDnaRecyclerAdapter(new ArrayList<SavedDNA>(), getContext(), this);
    mLayoutManager2 = new LinearLayoutManager(getContext(), LinearLayoutManager.HORIZONTAL, false);
    viewDnaRecycler.setLayoutManager(mLayoutManager2);
    viewDnaRecycler.setItemAnimator(new DefaultItemAnimator());
    viewDnaRecycler.setAdapter(vdAdapter);
    final Handler handler = new Handler();
    handler.postDelayed(new Runnable() {

        @Override
        public void run() {
            if (HomeActivity.savedDNAs.getSavedDNAs().size() > 0) {
                SavedDNA dna = HomeActivity.savedDNAs.getSavedDNAs().get(selectedDNA);
                selectedDNA = 0;
                HomeActivity.tempSavedDNA = dna;
                Bitmap bmp = bitmapFromBase64String(dna.getBase64encodedBitmap());
                mVisualizerView2.setBmp(bmp);
                mVisualizerView2.update();
            }
        }
    }, 350);
    viewDnaRecycler.addOnItemTouchListener(new ClickItemTouchListener(viewDnaRecycler) {

        @Override
        public boolean onClick(RecyclerView parent, View view, int position, long id) {
            vdAdapter.notifyItemChanged(selectedDNA);
            selectedDNA = position;
            vdAdapter.notifyItemChanged(selectedDNA);
            SavedDNA dna = HomeActivity.savedDNAs.getSavedDNAs().get(position);
            selectedDNA = position;
            HomeActivity.tempSavedDNA = dna;
            Bitmap bmp = bitmapFromBase64String(dna.getBase64encodedBitmap());
            mVisualizerView2.setBmp(bmp);
            mVisualizerView2.update();
            return true;
        }

        @Override
        public boolean onLongClick(RecyclerView parent, View view, final int position, long id) {
            PopupMenu popup = new PopupMenu(getContext(), view);
            popup.getMenuInflater().inflate(R.menu.save_dna_popup, popup.getMenu());
            popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {

                @Override
                public boolean onMenuItemClick(MenuItem item) {
                    if (item.getTitle().equals("View")) {
                        vdAdapter.notifyItemChanged(selectedDNA);
                        selectedDNA = position;
                        vdAdapter.notifyItemChanged(selectedDNA);
                        SavedDNA dna = HomeActivity.savedDNAs.getSavedDNAs().get(position);
                        selectedDNA = position;
                        HomeActivity.tempSavedDNA = dna;
                        Bitmap bmp = bitmapFromBase64String(dna.getBase64encodedBitmap());
                        mVisualizerView2.setBmp(bmp);
                        mVisualizerView2.update();
                    } else if (item.getTitle().equals("Delete")) {
                        HomeActivity.savedDNAs.getSavedDNAs().remove(position);
                        vdAdapter.notifyItemRemoved(position);
                        if (position == selectedDNA) {
                            if (position > 0) {
                                selectedDNA = position - 1;
                            } else if (position == 0) {
                                if (HomeActivity.savedDNAs.getSavedDNAs().size() == 0) {
                                    noSavedContent.setVisibility(View.VISIBLE);
                                    new HomeActivity.SaveTheDNAs().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
                                    return true;
                                } else {
                                    selectedDNA = 0;
                                }
                            }
                            SavedDNA dna = HomeActivity.savedDNAs.getSavedDNAs().get(selectedDNA);
                            HomeActivity.tempSavedDNA = dna;
                            Bitmap bmp = bitmapFromBase64String(dna.getBase64encodedBitmap());
                            mVisualizerView2.setBmp(bmp);
                            mVisualizerView2.update();
                        }
                        new HomeActivity.SaveTheDNAs().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
                    }
                    return true;
                }
            });
            popup.show();
            return true;
        }

        @Override
        public void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept) {
        }
    });
    shareIcon = (ImageView) view.findViewById(R.id.share_icon);
    saveToStorageIcon = (ImageView) view.findViewById(R.id.save_to_storage_icon);
    shareIcon.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (HomeActivity.tempSavedDNA != null) {
                showDialog(1);
            }
        }
    });
    saveToStorageIcon.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (HomeActivity.tempSavedDNA != null) {
                showDialog(0);
            }
        }
    });
    Button mEndButton = new Button(getContext());
    mEndButton.setBackgroundColor(HomeActivity.themeColor);
    mEndButton.setTextColor(Color.WHITE);
    if (HomeActivity.savedDNAs.getSavedDNAs().size() > 0) {
        showCase = new ShowcaseView.Builder(getActivity()).blockAllTouches().singleShot(5).setStyle(R.style.CustomShowcaseTheme).useDecorViewAsParent().replaceEndButton(mEndButton).setContentTitlePaint(HomeActivity.tp).setTarget(new ViewTarget(R.id.visualizer_alt_showcase, getActivity())).setContentTitle("Saved DNAs").setContentText("View all your saved DNAs here").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:
                        showCase.setTarget(new ViewTarget(shareIcon.getId(), getActivity()));
                        showCase.setContentTitle("Share DNA");
                        showCase.setContentText("Share the DNA as an image with your friends");
                        showCase.setButtonPosition(HomeActivity.lps);
                        showCase.setButtonText("Next");
                        break;
                    case 2:
                        showCase.setTarget(new ViewTarget(saveToStorageIcon.getId(), getActivity()));
                        showCase.setContentTitle("Save DNA");
                        showCase.setContentText("Save the DNA as an image to your internal storage");
                        showCase.setButtonPosition(HomeActivity.lps);
                        showCase.setButtonText("Done");
                        break;
                    case 3:
                        showCase.hide();
                        break;
                }
            }
        });
    }
}
Also used : ViewTarget(com.github.amlcurran.showcaseview.targets.ViewTarget) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) DefaultItemAnimator(android.support.v7.widget.DefaultItemAnimator) Bitmap(android.graphics.Bitmap) Button(android.widget.Button) CompoundButton(android.widget.CompoundButton) ClickItemTouchListener(com.sdsmdg.harjot.MusicDNA.clickitemtouchlistener.ClickItemTouchListener) HomeActivity(com.sdsmdg.harjot.MusicDNA.activities.HomeActivity) SavedDNA(com.sdsmdg.harjot.MusicDNA.models.SavedDNA) Handler(android.os.Handler) MenuItem(android.view.MenuItem) ImageView(android.widget.ImageView) ShowcaseView(com.github.amlcurran.showcaseview.ShowcaseView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) RecyclerView(android.support.v7.widget.RecyclerView) ShowcaseView(com.github.amlcurran.showcaseview.ShowcaseView) PopupMenu(android.support.v7.widget.PopupMenu)

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