fixed scrolling issues
This commit is contained in:
parent
a9b77a5ded
commit
7c2d662a19
1 changed files with 56 additions and 64 deletions
|
@ -3,92 +3,84 @@ package code.name.monkey.retromusic.dialogs;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.support.annotation.Nullable;
|
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.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.AdapterView;
|
|
||||||
import android.widget.ArrayAdapter;
|
|
||||||
import android.widget.ListView;
|
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import butterknife.BindView;
|
import butterknife.BindView;
|
||||||
import butterknife.ButterKnife;
|
import butterknife.ButterKnife;
|
||||||
|
import butterknife.OnClick;
|
||||||
|
import code.name.monkey.appthemehelper.ThemeStore;
|
||||||
import code.name.monkey.retromusic.R;
|
import code.name.monkey.retromusic.R;
|
||||||
import code.name.monkey.retromusic.loaders.PlaylistLoader;
|
import code.name.monkey.retromusic.loaders.PlaylistLoader;
|
||||||
import code.name.monkey.retromusic.model.Playlist;
|
import code.name.monkey.retromusic.model.Playlist;
|
||||||
import code.name.monkey.retromusic.model.Song;
|
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 code.name.monkey.retromusic.views.RoundedBottomSheetDialogFragment;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Karim Abou Zeid (kabouzeid), Aidan Follestad (afollestad)
|
* @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)
|
@BindView(R.id.playlists)
|
||||||
ListView playlist;
|
RecyclerView playlist;
|
||||||
@BindView(R.id.title)
|
@BindView(R.id.title)
|
||||||
TextView title;
|
TextView title;
|
||||||
List<Playlist> playlists;
|
ArrayList<Playlist> playlists;
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
public static AddToPlaylistDialog create(Song song) {
|
public static AddToPlaylistDialog create(Song song) {
|
||||||
ArrayList<Song> list = new ArrayList<>();
|
ArrayList<Song> list = new ArrayList<>();
|
||||||
list.add(song);
|
list.add(song);
|
||||||
return create(list);
|
return create(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
public static AddToPlaylistDialog create(ArrayList<Song> songs) {
|
public static AddToPlaylistDialog create(ArrayList<Song> songs) {
|
||||||
AddToPlaylistDialog dialog = new AddToPlaylistDialog();
|
AddToPlaylistDialog dialog = new AddToPlaylistDialog();
|
||||||
Bundle args = new Bundle();
|
Bundle args = new Bundle();
|
||||||
args.putParcelableArrayList("songs", songs);
|
args.putParcelableArrayList("songs", songs);
|
||||||
dialog.setArguments(args);
|
dialog.setArguments(args);
|
||||||
return dialog;
|
return dialog;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
|
||||||
View layout = inflater.inflate(R.layout.dialog_add_to_playlist, container, false);
|
@Nullable Bundle savedInstanceState) {
|
||||||
ButterKnife.bind(this, layout);
|
View layout = inflater.inflate(R.layout.dialog_add_to_playlist, container, false);
|
||||||
return layout;
|
ButterKnife.bind(this, layout);
|
||||||
}
|
return layout;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@SuppressWarnings("ConstantConditions")
|
||||||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
@OnClick(R.id.action_add_playlist)
|
||||||
super.onViewCreated(view, savedInstanceState);
|
void newPlaylist() {
|
||||||
ArrayAdapter<String> playlistAdapter = new ArrayAdapter<>(getActivity(), R.layout.simple_list_item);
|
final ArrayList<Song> songs = getArguments().getParcelableArrayList("songs");
|
||||||
playlists = PlaylistLoader.getAllPlaylists(getActivity()).blockingFirst();
|
CreatePlaylistDialog.create(songs)
|
||||||
playlistAdapter.add(getActivity().getResources().getString(R.string.action_new_playlist));
|
.show(getActivity().getSupportFragmentManager(), "ADD_TO_PLAYLIST");
|
||||||
|
dismiss();
|
||||||
|
}
|
||||||
|
|
||||||
for (int i = 1; i < playlists.size(); i++) {
|
@SuppressWarnings("ConstantConditions")
|
||||||
playlistAdapter.add(playlists.get(i - 1).name);
|
@Override
|
||||||
playlistAdapter.notifyDataSetChanged();
|
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
||||||
}
|
super.onViewCreated(view, savedInstanceState);
|
||||||
|
|
||||||
this.playlist.setAdapter(playlistAdapter);
|
title.setTextColor(ThemeStore.textColorPrimary(getContext()));
|
||||||
this.playlist.setOnItemClickListener(this);
|
final ArrayList<Song> songs = getArguments().getParcelableArrayList("songs");
|
||||||
}
|
playlists = PlaylistLoader.getAllPlaylists(getActivity()).blockingFirst();
|
||||||
|
|
||||||
@Override
|
AddToPlaylist playlistAdapter = new AddToPlaylist(getActivity(), playlists,
|
||||||
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
|
R.layout.item_playlist, songs, getDialog());
|
||||||
//noinspection unchecked
|
|
||||||
final ArrayList<Song> songs = getArguments().getParcelableArrayList("songs");
|
|
||||||
|
|
||||||
if (songs == null) {
|
playlist.setLayoutManager(new LinearLayoutManager(getContext()));
|
||||||
return;
|
playlist.setItemAnimator(new DefaultItemAnimator());
|
||||||
}
|
playlist.setAdapter(playlistAdapter);
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
Loading…
Reference in a new issue