fixed scrolling issues
This commit is contained in:
parent
a9b77a5ded
commit
7c2d662a19
1 changed files with 56 additions and 64 deletions
|
@ -3,36 +3,35 @@ 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) {
|
||||||
|
@ -52,43 +51,36 @@ public class AddToPlaylistDialog extends RoundedBottomSheetDialogFragment implem
|
||||||
|
|
||||||
@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,
|
||||||
|
@Nullable Bundle savedInstanceState) {
|
||||||
View layout = inflater.inflate(R.layout.dialog_add_to_playlist, container, false);
|
View layout = inflater.inflate(R.layout.dialog_add_to_playlist, container, false);
|
||||||
ButterKnife.bind(this, layout);
|
ButterKnife.bind(this, layout);
|
||||||
return 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
|
@Override
|
||||||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
||||||
super.onViewCreated(view, 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++) {
|
title.setTextColor(ThemeStore.textColorPrimary(getContext()));
|
||||||
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
|
|
||||||
final ArrayList<Song> songs = getArguments().getParcelableArrayList("songs");
|
final ArrayList<Song> songs = getArguments().getParcelableArrayList("songs");
|
||||||
|
playlists = PlaylistLoader.getAllPlaylists(getActivity()).blockingFirst();
|
||||||
|
|
||||||
if (songs == null) {
|
AddToPlaylist playlistAdapter = new AddToPlaylist(getActivity(), playlists,
|
||||||
return;
|
R.layout.item_playlist, songs, getDialog());
|
||||||
}
|
|
||||||
if (i == 0) {
|
playlist.setLayoutManager(new LinearLayoutManager(getContext()));
|
||||||
dismiss();
|
playlist.setItemAnimator(new DefaultItemAnimator());
|
||||||
CreatePlaylistDialog.create(songs)
|
playlist.setAdapter(playlistAdapter);
|
||||||
.show(getActivity().getSupportFragmentManager(), "ADD_TO_PLAYLIST");
|
|
||||||
} else {
|
|
||||||
dismiss();
|
|
||||||
PlaylistsUtil.addToPlaylist(getActivity(), songs, playlists.get(i - 1).id, true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue