Search in sources :

Example 66 with DefaultItemAnimator

use of android.support.v7.widget.DefaultItemAnimator in project MusicDNA by harjot-oberai.

the class HomeActivity method updateStreamingList.

private void updateStreamingList(String query) {
    if (!isLocalVisible) {
        mWifi = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
        if ((settings.isStreamOnlyOnWifiEnabled() && mWifi.isConnected()) || (!settings.isStreamOnlyOnWifiEnabled())) {
            new Thread(new CancelCall()).start();
            if (!query.equals("")) {
                streamRecyclerContainer.setVisibility(View.VISIBLE);
                startLoadingIndicator();
                Retrofit client = new Retrofit.Builder().baseUrl(Config.API_URL).addConverterFactory(GsonConverterFactory.create()).build();
                StreamService ss = client.create(StreamService.class);
                call = ss.getTracks(query, 75);
                call.enqueue(new Callback<List<Track>>() {

                    @Override
                    public void onResponse(Call<List<Track>> call, Response<List<Track>> response) {
                        if (response.isSuccessful()) {
                            streamingTrackList = response.body();
                            sAdapter = new StreamTracksHorizontalAdapter(streamingTrackList, ctx);
                            LinearLayoutManager mLayoutManager = new LinearLayoutManager(ctx, LinearLayoutManager.HORIZONTAL, false);
                            soundcloudRecyclerView.setLayoutManager(mLayoutManager);
                            soundcloudRecyclerView.setItemAnimator(new DefaultItemAnimator());
                            soundcloudRecyclerView.setAdapter(sAdapter);
                            if (streamingTrackList.size() == 0) {
                                streamRecyclerContainer.setVisibility(GONE);
                            } else {
                                streamRecyclerContainer.setVisibility(View.VISIBLE);
                            }
                            stopLoadingIndicator();
                            (soundcloudRecyclerView.getAdapter()).notifyDataSetChanged();
                            StreamMusicFragment sFrag = (StreamMusicFragment) fragMan.findFragmentByTag("stream");
                            if (sFrag != null) {
                                sFrag.dataChanged();
                            }
                        } else {
                            stopLoadingIndicator();
                        }
                        Log.d("RETRO", response.body() + "");
                    }

                    @Override
                    public void onFailure(Call<List<Track>> call, Throwable t) {
                        Log.d("RETRO1", t.getMessage());
                    }
                });
            } else {
                stopLoadingIndicator();
                streamRecyclerContainer.setVisibility(GONE);
            }
        } else {
            stopLoadingIndicator();
            streamRecyclerContainer.setVisibility(GONE);
        }
    }
}
Also used : StreamService(com.sdsmdg.harjot.MusicDNA.interfaces.StreamService) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) DefaultItemAnimator(android.support.v7.widget.DefaultItemAnimator) StreamTracksHorizontalAdapter(com.sdsmdg.harjot.MusicDNA.adapters.horizontalrecycleradapters.StreamTracksHorizontalAdapter) StreamMusicFragment(com.sdsmdg.harjot.MusicDNA.fragments.StreamFragment.StreamMusicFragment) Retrofit(retrofit2.Retrofit) ColorStateList(android.content.res.ColorStateList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 67 with DefaultItemAnimator

use of android.support.v7.widget.DefaultItemAnimator 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 68 with DefaultItemAnimator

use of android.support.v7.widget.DefaultItemAnimator in project FlexibleAdapter by davideas.

the class FragmentViewPager method initializeRecyclerView.

private void initializeRecyclerView() {
    // Initialize Adapter and RecyclerView
    // Use of stableIds, I strongly suggest to implement 'item.hashCode()'
    mAdapter = new FlexibleAdapter<>(createList(50, 5), getActivity(), true);
    // Experimenting NEW features (v5.0.0)
    mAdapter.setAnimationOnScrolling(DatabaseConfiguration.animateOnScrolling);
    RecyclerView mRecyclerView = (RecyclerView) getView().findViewById(R.id.recycler_view);
    mRecyclerView.setLayoutManager(new SmoothScrollLinearLayoutManager(getActivity()));
    mRecyclerView.setAdapter(mAdapter);
    //Size of RV will not change
    mRecyclerView.setHasFixedSize(true);
    // NOTE: Use default item animator 'canReuseUpdatedViewHolder()' will return true if
    // a Payload is provided. FlexibleAdapter is actually sending Payloads onItemChange.
    mRecyclerView.setItemAnimator(new DefaultItemAnimator());
    // Add FastScroll to the RecyclerView, after the Adapter has been attached the RecyclerView!!!
    FastScroller fastScroller = (FastScroller) getView().findViewById(R.id.fast_scroller);
    mAdapter.setFastScroller(fastScroller, Utils.getColorAccent(getActivity()));
    mAdapter.toggleFastScroller();
    // Sticky Headers
    mAdapter.setDisplayHeadersAtStartUp(true).setStickyHeaders(true);
}
Also used : RecyclerView(android.support.v7.widget.RecyclerView) FastScroller(eu.davidea.fastscroller.FastScroller) SmoothScrollLinearLayoutManager(eu.davidea.flexibleadapter.common.SmoothScrollLinearLayoutManager) DefaultItemAnimator(android.support.v7.widget.DefaultItemAnimator)

Example 69 with DefaultItemAnimator

use of android.support.v7.widget.DefaultItemAnimator in project FlexibleAdapter by davideas.

the class FragmentInstagramHeaders method initializeRecyclerView.

@SuppressWarnings({ "unchecked", "ConstantConditions" })
private void initializeRecyclerView() {
    // Initialize Adapter and RecyclerView
    // true = it makes use of stableIds, I strongly suggest to implement 'item.hashCode()'
    mAdapter = new FlexibleAdapter<>(DatabaseService.getInstance().getDatabaseList(), getActivity(), true);
    mAdapter.addListener(getActivity()).setAnimationOnScrolling(true).setAnimationOnReverseScrolling(true);
    mRecyclerView = (RecyclerView) getView().findViewById(R.id.recycler_view);
    mRecyclerView.setLayoutManager(createNewLinearLayoutManager());
    mRecyclerView.setAdapter(mAdapter);
    //Size of RV will not change
    mRecyclerView.setHasFixedSize(true);
    // NOTE: Use default item animator 'canReuseUpdatedViewHolder()' will return true if
    // a Payload is provided. FlexibleAdapter is actually sending Payloads onItemChange.
    mRecyclerView.setItemAnimator(new DefaultItemAnimator());
    // Custom divider item decorator with 24dpi as empty space between sections
    mRecyclerView.addItemDecoration(new DividerItemDecoration(getActivity(), 0, 24));
    //Show Headers at startUp!
    mAdapter.setDisplayHeadersAtStartUp(true).setStickyHeaders(//Make headers sticky
    true).setEndlessScrollListener(this, new ProgressItem()).setEndlessScrollThreshold(//Default=1
    1);
    SwipeRefreshLayout swipeRefreshLayout = (SwipeRefreshLayout) getView().findViewById(R.id.swipeRefreshLayout);
    swipeRefreshLayout.setEnabled(true);
    mListener.onFragmentChange(swipeRefreshLayout, mRecyclerView, SelectableAdapter.MODE_IDLE);
}
Also used : DividerItemDecoration(eu.davidea.flexibleadapter.common.DividerItemDecoration) ProgressItem(eu.davidea.samples.flexibleadapter.items.ProgressItem) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout) DefaultItemAnimator(android.support.v7.widget.DefaultItemAnimator)

Example 70 with DefaultItemAnimator

use of android.support.v7.widget.DefaultItemAnimator in project FlexibleAdapter by davideas.

the class FragmentSelectionModes method initializeRecyclerView.

@SuppressWarnings({ "ConstantConditions", "NullableProblems" })
private void initializeRecyclerView(Bundle savedInstanceState) {
    //Get copy of the Database list
    List<AbstractFlexibleItem> items = DatabaseService.getInstance().getDatabaseList();
    // Initialize Adapter and RecyclerView
    // ExampleAdapter makes use of stableIds, I strongly suggest to implement 'item.hashCode()'
    mAdapter = new ExampleAdapter(items, getActivity());
    //This will rebind new item when refreshed
    mAdapter.setNotifyChangeOfUnfilteredItems(true).setMode(SelectableAdapter.MODE_SINGLE);
    // Experimenting NEW features (v5.0.0)
    mRecyclerView = (RecyclerView) getView().findViewById(R.id.recycler_view);
    mRecyclerView.setLayoutManager(createNewLinearLayoutManager());
    mRecyclerView.setAdapter(mAdapter);
    //Size of RV will not change
    mRecyclerView.setHasFixedSize(true);
    // NOTE: Use default item animator 'canReuseUpdatedViewHolder()' will return true if
    // a Payload is provided. FlexibleAdapter is actually sending Payloads onItemChange.
    mRecyclerView.setItemAnimator(new DefaultItemAnimator());
    // Divider item decorator with DrawOver enabled
    mRecyclerView.addItemDecoration(new DividerItemDecoration(getActivity(), R.drawable.divider).withDrawOver(true));
    mRecyclerView.postDelayed(new Runnable() {

        @Override
        public void run() {
            Snackbar.make(getView(), "Selection MODE_SINGLE is enabled", Snackbar.LENGTH_SHORT).show();
        }
    }, 1500L);
    // Add FastScroll to the RecyclerView, after the Adapter has been attached the RecyclerView!!!
    mAdapter.setFastScroller((FastScroller) getView().findViewById(R.id.fast_scroller), Utils.getColorAccent(getActivity()), (MainActivity) getActivity());
    SwipeRefreshLayout swipeRefreshLayout = (SwipeRefreshLayout) getView().findViewById(R.id.swipeRefreshLayout);
    swipeRefreshLayout.setEnabled(true);
    mListener.onFragmentChange(swipeRefreshLayout, mRecyclerView, SelectableAdapter.MODE_SINGLE);
    // Add 2 Scrollable Headers
    mAdapter.addUserLearnedSelection(savedInstanceState == null);
    mAdapter.addScrollableHeaderWithDelay(new ScrollableUseCaseItem(getString(R.string.selection_modes_use_case_title), getString(R.string.selection_modes_use_case_description)), 1100L, true);
}
Also used : ScrollableUseCaseItem(eu.davidea.samples.flexibleadapter.items.ScrollableUseCaseItem) AbstractFlexibleItem(eu.davidea.flexibleadapter.items.AbstractFlexibleItem) ExampleAdapter(eu.davidea.samples.flexibleadapter.ExampleAdapter) DividerItemDecoration(eu.davidea.flexibleadapter.common.DividerItemDecoration) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout) DefaultItemAnimator(android.support.v7.widget.DefaultItemAnimator)

Aggregations

DefaultItemAnimator (android.support.v7.widget.DefaultItemAnimator)103 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)72 RecyclerView (android.support.v7.widget.RecyclerView)63 View (android.view.View)55 TextView (android.widget.TextView)30 ImageView (android.widget.ImageView)25 ArrayList (java.util.ArrayList)16 ClickItemTouchListener (com.sdsmdg.harjot.MusicDNA.clickitemtouchlistener.ClickItemTouchListener)14 GridLayoutManager (android.support.v7.widget.GridLayoutManager)13 Toolbar (android.support.v7.widget.Toolbar)13 SwipeRefreshLayout (android.support.v4.widget.SwipeRefreshLayout)10 FastAdapter (com.mikepenz.fastadapter.FastAdapter)10 UnifiedTrack (com.sdsmdg.harjot.MusicDNA.models.UnifiedTrack)10 MaterializeBuilder (com.mikepenz.materialize.MaterializeBuilder)9 ItemTouchHelper (android.support.v7.widget.helper.ItemTouchHelper)8 LocalTrack (com.sdsmdg.harjot.MusicDNA.models.LocalTrack)8 DividerItemDecoration (de.madcyph3r.example.DividerItemDecoration)8 Button (android.widget.Button)7 Random (java.util.Random)6 Intent (android.content.Intent)5