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);
}
}
}
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;
}
}
});
}
}
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);
}
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);
}
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);
}
Aggregations