/*
* Copyright (C) 2012 Andrew Neal
* Copyright (C) 2014 The CyanogenMod Project
- * Licensed under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with the
- * License. You may obtain a copy of the License at
- * http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law
- * or agreed to in writing, software distributed under the License is
- * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the specific language
- * governing permissions and limitations under the License.
+ * Copyright (C) 2019 The LineageOS Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
*/
package org.lineageos.eleven.model;
+import android.support.annotation.NonNull;
import android.text.TextUtils;
+import java.util.Comparator;
+
/**
* A class that represents a playlist.
*
mSongCount = songCount;
}
- /**
- * {@inheritDoc}
- */
@Override
public int hashCode() {
final int prime = 31;
return result;
}
- /**
- * {@inheritDoc}
- */
@Override
public boolean equals(final Object obj) {
if (this == obj) {
return TextUtils.equals(mPlaylistName, other.mPlaylistName);
}
- /**
- * {@inheritDoc}
- */
+ @NonNull
@Override
public String toString() {
- return mPlaylistName;
+ return "Playlist[playlistId=" + mPlaylistId
+ + ", playlistName=" + mPlaylistName
+ + ", songCount=" + mSongCount
+ + "]";
}
/**
public boolean isSmartPlaylist() {
return mPlaylistId < 0;
}
+
+ public static class IgnoreCaseComparator implements Comparator<Playlist> {
+ @Override
+ public int compare(Playlist p1, Playlist p2) {
+ return p1.mPlaylistName.compareToIgnoreCase(p2.mPlaylistName);
+ }
+ }
}
/*
* Copyright (C) 2012 Andrew Neal
* Copyright (C) 2014 The CyanogenMod Project
- * Licensed under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with the
- * License. You may obtain a copy of the License at
- * http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law
- * or agreed to in writing, software distributed under the License is
- * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the specific language
- * governing permissions and limitations under the License.
+ * Copyright (C) 2019 The LineageOS Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
*/
package org.lineageos.eleven.ui.fragments;
import android.os.Bundle;
+import android.support.annotation.NonNull;
import android.support.v4.app.Fragment;
import android.support.v4.app.LoaderManager.LoaderCallbacks;
import android.support.v4.content.Loader;
import org.lineageos.eleven.widgets.IPopupMenuCallback;
import org.lineageos.eleven.widgets.LoadingEmptyContainer;
+import java.util.Collections;
+import java.util.Iterator;
import java.util.List;
/**
* Empty constructor as per the {@link Fragment} documentation
*/
public PlaylistFragment() {
+ // empty
}
@Override
return PagerAdapter.MusicFragments.PLAYLIST.ordinal();
}
- /**
- * {@inheritDoc}
- */
@Override
public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Create the adapter
mAdapter = new PlaylistAdapter(getActivity());
- mAdapter.setPopupMenuClickedListener(new IPopupMenuCallback.IListener() {
- @Override
- public void onPopupMenuClicked(View v, int position) {
- mPopupMenuHelper.showPopupMenu(v, position);
- }
- });
+ mAdapter.setPopupMenuClickedListener((v, position) -> mPopupMenuHelper.showPopupMenu(v, position));
}
- /**
- * {@inheritDoc}
- */
@Override
- public View onCreateView(final LayoutInflater inflater, final ViewGroup container,
+ public View onCreateView(@NonNull final LayoutInflater inflater, final ViewGroup container,
final Bundle savedInstanceState) {
// The View for the fragment's UI
- final ViewGroup rootView = (ViewGroup)inflater.inflate(R.layout.list_base, null);
+ final ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.list_base, container, false);
// Initialize the list
- mListView = (ListView)rootView.findViewById(R.id.list_base);
+ mListView = rootView.findViewById(R.id.list_base);
// Set the data behind the grid
mListView.setAdapter(mAdapter);
// Release any references to the recycled Views
// Play the selected song
mListView.setOnItemClickListener(this);
// Setup the loading and empty state
- mLoadingEmptyContainer =
- (LoadingEmptyContainer)rootView.findViewById(R.id.loading_empty_container);
+ mLoadingEmptyContainer = rootView.findViewById(R.id.loading_empty_container);
mListView.setEmptyView(mLoadingEmptyContainer);
// Register the music status listener
((BaseActivity)getActivity()).removeMusicStateListenerListener(this);
}
-
- /**
- * {@inheritDoc}
- */
@Override
public void onActivityCreated(final Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
initLoader(null, this);
}
- /**
- * {@inheritDoc}
- */
@Override
public void onItemClick(final AdapterView<?> parent, final View view, final int position,
final long id) {
}
}
- /**
- * {@inheritDoc}
- */
+ @NonNull
@Override
public Loader<List<Playlist>> onCreateLoader(final int id, final Bundle args) {
// show the loading progress bar
return new PlaylistLoader(getActivity());
}
- /**
- * {@inheritDoc}
- */
@Override
- public void onLoadFinished(final Loader<List<Playlist>> loader, final List<Playlist> data) {
- // Check for any errors
+ public void onLoadFinished(@NonNull final Loader<List<Playlist>> loader, final List<Playlist> data) {
if (data.isEmpty()) {
mLoadingEmptyContainer.showNoResults();
return;
}
- // Start fresh
+ // Start fresh, fill adapter with new data and create cache
mAdapter.unload();
- // Add the data to the adpater
+
+ // iterate through playlist list and add "smart playlists" first
+ final Iterator<Playlist> playlistIterator = data.listIterator();
+ while (playlistIterator.hasNext()) {
+ final Playlist playlist = playlistIterator.next();
+ if (playlist.mSongCount < 0) {
+ mAdapter.add(playlist);
+ playlistIterator.remove();
+ }
+ }
+
+ // after the "smart playlists" are added, sort and add remaining playlists
+ Collections.sort(data, new Playlist.IgnoreCaseComparator());
for (final Playlist playlist : data) {
mAdapter.add(playlist);
}
- // Build the cache
+
mAdapter.buildCache();
}
- /**
- * {@inheritDoc}
- */
@Override
- public void onLoaderReset(final Loader<List<Playlist>> loader) {
+ public void onLoaderReset(@NonNull final Loader<List<Playlist>> loader) {
// Clear the data in the adapter
mAdapter.unload();
}
- /**
- * {@inheritDoc}
- */
@Override
public void restartLoader() {
restartLoader(null, this);
restartLoader();
}
- /**
- * {@inheritDoc}
- */
@Override
public void onMetaChanged() {
// Nothing to do