Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

library browse: add tab 'random album' #832

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@ abstract class BrowseFragmentBase<T extends Item<T>> extends Fragment implements

public static final int GOTO_ARTIST = 5;

public static final int MAIN = 0;
// public static final int MAIN = 0;

public static final int PLAYLIST = 3;
// public static final int PLAYLIST = 3;

public static final int POPUP_COVER_BLACKLIST = 10;

Expand Down Expand Up @@ -136,9 +136,9 @@ abstract class BrowseFragmentBase<T extends Item<T>> extends Fragment implements

protected final List<T> mItems = new ArrayList<>();

final int mIrAdd;
protected final int mIrAdd;

final int mIrAdded;
protected final int mIrAdded;

/**
* This runnable is run in our {@link MPDAsyncWorker} thread.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,9 @@ public Fragment getItem(final int position) {
case LibraryTabsUtil.TAB_STREAMS:
fragment = getFragment(StreamsFragment.class);
break;
case LibraryTabsUtil.TAB_RANDOM:
fragment = getFragment(RandomBrowseFragment.class);
break;
default:
throw new IllegalStateException("getItem() called with invalid Item.");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Copyright (C) 2010-2016 The MPDroid 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 com.namelessdev.mpdroid.fragments;


import android.support.annotation.StringRes;
import android.util.Log;

import com.anpmech.mpd.exception.MPDException;
import com.anpmech.mpd.item.Album;
import com.namelessdev.mpdroid.R;

import java.io.IOException;
import java.util.List;
import java.util.Random;

public class RandomBrowseFragment extends SongsFragment {

private static final String TAG = "RandomBrowseFragment";

@Override
protected void asyncUpdate() {
try {
final List<Album> albums = mApp.getMPD().getAlbums(null, false, false);
mAlbum = !albums.isEmpty() ? albums.get(new Random().nextInt(albums.size())) : null;
} catch (final IOException | MPDException e) {
Log.e(TAG, "Failed to update.", e);
}

super.asyncUpdate();
}

@Override
public String getTitle() {
return mAlbum != null ? mAlbum.getName() : null;
}

@Override
@StringRes
public int getLoadingText() {
return R.string.loadingAlbum;
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.widget.AbsListView;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.ListAdapter;
Expand All @@ -84,33 +83,33 @@ public class SongsFragment extends BrowseFragment<Music> implements

private static final String TAG = "SongsFragment";

Album mAlbum;
protected Album mAlbum;

FloatingActionButton mAlbumMenu;
private FloatingActionButton mAlbumMenu;

ImageView mCoverArt;
private ImageView mCoverArt;

ProgressBar mCoverArtProgress;
private ProgressBar mCoverArtProgress;

CoverAsyncHelper mCoverHelper;
private CoverAsyncHelper mCoverHelper;

Bitmap mCoverThumbnailBitmap;
private Bitmap mCoverThumbnailBitmap;

boolean mFirstRefresh;
private boolean mFirstRefresh;

Handler mHandler;
private Handler mHandler;

TextView mHeaderAlbum;
private TextView mHeaderAlbum;

TextView mHeaderArtist;
private TextView mHeaderArtist;

TextView mHeaderInfo;
private TextView mHeaderInfo;

Toolbar mHeaderToolbar;
private Toolbar mHeaderToolbar;

View mTracksInfoContainer;
private View mTracksInfoContainer;

String mViewTransitionName;
private String mViewTransitionName;

private AlbumCoverDownloadListener mCoverArtListener;

Expand Down Expand Up @@ -185,10 +184,10 @@ public void run() {
}

@Override
public void asyncUpdate() {
protected void asyncUpdate() {
try {
if (getActivity() != null) {
replaceItems(mApp.getMPD().getSongs(mAlbum));
replaceItems(mAlbum != null ? mApp.getMPD().getSongs(mAlbum) : Collections.<Music>emptyList());
Collections.sort(mItems);
}
} catch (final IOException | MPDException e) {
Expand Down Expand Up @@ -343,23 +342,21 @@ public void onCreate(final Bundle savedInstanceState) {
}
}

@Override
protected int getLayoutResId() {
return R.layout.songs;
}

@Override
public View onCreateView(final LayoutInflater inflater, final ViewGroup container,
final Bundle savedInstanceState) {
final View view = inflater.inflate(R.layout.songs, container, false);
mList = (AbsListView) view.findViewById(R.id.list);
registerForContextMenu(mList);
mList.setOnItemClickListener(this);
final View view = super.onCreateView(inflater, container, savedInstanceState);

mList.setFastScrollEnabled(false);
if (mList instanceof ListView) {
((ListView) mList).setDivider(null);
}

mLoadingView = view.findViewById(R.id.loadingLayout);
mLoadingTextView = (TextView) view.findViewById(R.id.loadingText);
mNoResultView = view.findViewById(R.id.noResultLayout);
mLoadingTextView.setText(getLoadingText());

final View headerView = inflater.inflate(R.layout.song_header, mList, false);
mCoverArt = (ImageView) view.findViewById(R.id.albumCover);
if (mCoverArt != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ public final class LibraryTabsUtil {

public static final String TAB_STREAMS = "streams";

public static final String TAB_RANDOM = "random";

private static final MPDApplication APP = MPDApplication.getInstance();

private static final String LIBRARY_TABS_DELIMITER = "|";
Expand All @@ -50,7 +52,8 @@ public final class LibraryTabsUtil {
+ LIBRARY_TABS_DELIMITER + TAB_PLAYLISTS
+ LIBRARY_TABS_DELIMITER + TAB_STREAMS
+ LIBRARY_TABS_DELIMITER + TAB_FILES
+ LIBRARY_TABS_DELIMITER + TAB_GENRES;
+ LIBRARY_TABS_DELIMITER + TAB_GENRES
+ LIBRARY_TABS_DELIMITER + TAB_RANDOM;

private static final String LIBRARY_TABS_SETTINGS_KEY = "currentLibraryTabs";

Expand All @@ -63,6 +66,7 @@ public final class LibraryTabsUtil {
TABS.put(TAB_STREAMS, R.string.streams);
TABS.put(TAB_FILES, R.string.files);
TABS.put(TAB_GENRES, R.string.genres);
TABS.put(TAB_RANDOM, R.string.random);
}

private LibraryTabsUtil() {
Expand Down
2 changes: 2 additions & 0 deletions MPDroid/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
<string name="playlists">Playlists</string>
<string name="files">Files</string>
<string name="albums">Albums</string>
<string name="random">Random</string>
<string name="settings">Settings</string>
<string name="next">Next</string>
<string name="previous">Previous</string>
Expand All @@ -82,6 +83,7 @@
<string name="loading">Loading…</string>
<string name="loadingGenres">Loading genres…</string>
<string name="loadingAlbums">Loading albums…</string>
<string name="loadingAlbum">Loading album…</string>
<string name="loadingArtists">Loading artists…</string>
<string name="loadingSongs">Loading songs…</string>
<string name="loadingPlaylists">Loading playlists…</string>
Expand Down