use of android.support.v7.widget.helper.ItemTouchHelper 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);
}
use of android.support.v7.widget.helper.ItemTouchHelper 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);
}
use of android.support.v7.widget.helper.ItemTouchHelper in project T-MVP by north2016.
the class TabListActivity method initView.
@Override
public void initView() {
adapter = new RecyclerListAdapter();
mViewBinding.recyclerview.setHasFixedSize(true);
mViewBinding.recyclerview.setAdapter(adapter);
mItemTouchHelper = new ItemTouchHelper(new SimpleItemTouchHelperCallback());
mItemTouchHelper.attachToRecyclerView(mViewBinding.recyclerview);
}
use of android.support.v7.widget.helper.ItemTouchHelper in project apps-android-wikipedia by wikimedia.
the class ReadingListFragment method onCreateView.
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
super.onCreateView(inflater, container, savedInstanceState);
View view = inflater.inflate(R.layout.fragment_reading_list, container, false);
unbinder = ButterKnife.bind(this, view);
getAppCompatActivity().setSupportActionBar(toolbar);
getAppCompatActivity().getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getAppCompatActivity().getSupportActionBar().setTitle("");
appBarLayout.addOnOffsetChangedListener(appBarListener);
toolBarLayout.setCollapsedTitleTextColor(Color.WHITE);
ItemTouchHelper.Callback touchCallback = new SwipeableItemTouchHelperCallback(requireContext());
ItemTouchHelper itemTouchHelper = new ItemTouchHelper(touchCallback);
itemTouchHelper.attachToRecyclerView(recyclerView);
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
recyclerView.setAdapter(adapter);
recyclerView.addItemDecoration(new DrawableItemDecoration(requireContext(), R.attr.list_separator_drawable));
headerView = new ReadingListItemView(getContext());
headerView.setCallback(headerCallback);
headerView.setClickable(false);
headerView.setThumbnailVisible(false);
headerView.setTitleTextAppearance(R.style.ReadingListTitleTextAppearance);
readingListId = getArguments().getLong(EXTRA_READING_LIST_ID);
WikipediaApp.getInstance().getBus().register(eventBusMethods);
return view;
}
use of android.support.v7.widget.helper.ItemTouchHelper in project apps-android-wikipedia by wikimedia.
the class ConfigureFragment method setupRecyclerView.
private void setupRecyclerView() {
recyclerView.setHasFixedSize(true);
ConfigureItemAdapter adapter = new ConfigureItemAdapter();
recyclerView.setAdapter(adapter);
recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
recyclerView.addItemDecoration(new DrawableItemDecoration(getContext(), R.attr.list_separator_drawable));
itemTouchHelper = new ItemTouchHelper(new RearrangeableItemTouchHelperCallback(adapter));
itemTouchHelper.attachToRecyclerView(recyclerView);
}
Aggregations