fixed scrolling issues

This commit is contained in:
h4h13 2018-08-05 21:59:36 +05:30
parent a9b77a5ded
commit 7c2d662a19

View file

@ -3,36 +3,35 @@ package code.name.monkey.retromusic.dialogs;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import java.util.ArrayList;
import java.util.List;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import code.name.monkey.appthemehelper.ThemeStore;
import code.name.monkey.retromusic.R;
import code.name.monkey.retromusic.loaders.PlaylistLoader;
import code.name.monkey.retromusic.model.Playlist;
import code.name.monkey.retromusic.model.Song;
import code.name.monkey.retromusic.util.PlaylistsUtil;
import code.name.monkey.retromusic.ui.adapter.playlist.AddToPlaylist;
import code.name.monkey.retromusic.views.RoundedBottomSheetDialogFragment;
import java.util.ArrayList;
/**
* @author Karim Abou Zeid (kabouzeid), Aidan Follestad (afollestad)
*/
public class AddToPlaylistDialog extends RoundedBottomSheetDialogFragment implements AdapterView.OnItemClickListener {
public class AddToPlaylistDialog extends RoundedBottomSheetDialogFragment {
@BindView(R.id.playlists)
ListView playlist;
RecyclerView playlist;
@BindView(R.id.title)
TextView title;
List<Playlist> playlists;
ArrayList<Playlist> playlists;
@NonNull
public static AddToPlaylistDialog create(Song song) {
@ -52,43 +51,36 @@ public class AddToPlaylistDialog extends RoundedBottomSheetDialogFragment implem
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
@Nullable Bundle savedInstanceState) {
View layout = inflater.inflate(R.layout.dialog_add_to_playlist, container, false);
ButterKnife.bind(this, layout);
return layout;
}
@SuppressWarnings("ConstantConditions")
@OnClick(R.id.action_add_playlist)
void newPlaylist() {
final ArrayList<Song> songs = getArguments().getParcelableArrayList("songs");
CreatePlaylistDialog.create(songs)
.show(getActivity().getSupportFragmentManager(), "ADD_TO_PLAYLIST");
dismiss();
}
@SuppressWarnings("ConstantConditions")
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
ArrayAdapter<String> playlistAdapter = new ArrayAdapter<>(getActivity(), R.layout.simple_list_item);
playlists = PlaylistLoader.getAllPlaylists(getActivity()).blockingFirst();
playlistAdapter.add(getActivity().getResources().getString(R.string.action_new_playlist));
for (int i = 1; i < playlists.size(); i++) {
playlistAdapter.add(playlists.get(i - 1).name);
playlistAdapter.notifyDataSetChanged();
}
this.playlist.setAdapter(playlistAdapter);
this.playlist.setOnItemClickListener(this);
}
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
//noinspection unchecked
title.setTextColor(ThemeStore.textColorPrimary(getContext()));
final ArrayList<Song> songs = getArguments().getParcelableArrayList("songs");
playlists = PlaylistLoader.getAllPlaylists(getActivity()).blockingFirst();
if (songs == null) {
return;
}
if (i == 0) {
dismiss();
CreatePlaylistDialog.create(songs)
.show(getActivity().getSupportFragmentManager(), "ADD_TO_PLAYLIST");
} else {
dismiss();
PlaylistsUtil.addToPlaylist(getActivity(), songs, playlists.get(i - 1).id, true);
}
AddToPlaylist playlistAdapter = new AddToPlaylist(getActivity(), playlists,
R.layout.item_playlist, songs, getDialog());
playlist.setLayoutManager(new LinearLayoutManager(getContext()));
playlist.setItemAnimator(new DefaultItemAnimator());
playlist.setAdapter(playlistAdapter);
}
}