Search in sources :

Example 1 with SavedDNA

use of com.sdsmdg.harjot.MusicDNA.models.SavedDNA 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)

Example 2 with SavedDNA

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

the class ViewSavedDnaRecyclerAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(MyViewHolder holder, int position) {
    SavedDNA dna = savedDNAs.get(position);
    if (dna.getType()) {
        imgLoader.DisplayImage(dna.getLocalPath(), holder.art);
        holder.title.setText(dna.getName());
        holder.artist.setText(dna.getArtist());
    } else {
        Picasso.with(ctx).load(dna.getTrackArtworkURL()).resize(100, 100).error(R.drawable.ic_default).placeholder(R.drawable.ic_default).into(holder.art);
        holder.title.setText(dna.getName());
        holder.artist.setText(dna.getArtist());
    }
    if (position == vsdFrag.getSelectedDNAnumber()) {
        holder.title.setTextColor(HomeActivity.themeColor);
    } else {
        holder.title.setTextColor(Color.parseColor("#FFFFFF"));
    }
}
Also used : SavedDNA(com.sdsmdg.harjot.MusicDNA.models.SavedDNA)

Aggregations

SavedDNA (com.sdsmdg.harjot.MusicDNA.models.SavedDNA)2 Bitmap (android.graphics.Bitmap)1 Handler (android.os.Handler)1 DefaultItemAnimator (android.support.v7.widget.DefaultItemAnimator)1 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 PopupMenu (android.support.v7.widget.PopupMenu)1 RecyclerView (android.support.v7.widget.RecyclerView)1 MenuItem (android.view.MenuItem)1 View (android.view.View)1 Button (android.widget.Button)1 CompoundButton (android.widget.CompoundButton)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 ShowcaseView (com.github.amlcurran.showcaseview.ShowcaseView)1 ViewTarget (com.github.amlcurran.showcaseview.targets.ViewTarget)1 HomeActivity (com.sdsmdg.harjot.MusicDNA.activities.HomeActivity)1 ClickItemTouchListener (com.sdsmdg.harjot.MusicDNA.clickitemtouchlistener.ClickItemTouchListener)1