2015-01-14 12:12:47 +01:00
|
|
|
/*
|
|
|
|
* Copyright 2015 Synced Synapse. All rights reserved.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
2016-12-20 21:47:24 +01:00
|
|
|
package org.xbmc.kore.ui.sections.audio;
|
2015-01-14 12:12:47 +01:00
|
|
|
|
|
|
|
import android.app.Activity;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.res.Resources;
|
|
|
|
import android.database.Cursor;
|
|
|
|
import android.net.Uri;
|
|
|
|
import android.provider.BaseColumns;
|
|
|
|
import android.support.v4.content.CursorLoader;
|
|
|
|
import android.text.TextUtils;
|
|
|
|
import android.view.LayoutInflater;
|
|
|
|
import android.view.MenuItem;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
|
|
|
import android.widget.CursorAdapter;
|
|
|
|
import android.widget.ImageView;
|
2015-07-28 15:26:37 +02:00
|
|
|
import android.widget.PopupMenu;
|
2015-01-14 12:12:47 +01:00
|
|
|
import android.widget.TextView;
|
|
|
|
|
2015-03-09 22:35:18 +01:00
|
|
|
import org.xbmc.kore.R;
|
|
|
|
import org.xbmc.kore.host.HostInfo;
|
|
|
|
import org.xbmc.kore.host.HostManager;
|
2015-07-28 15:26:37 +02:00
|
|
|
import org.xbmc.kore.jsonrpc.type.PlaylistType;
|
2015-03-09 22:35:18 +01:00
|
|
|
import org.xbmc.kore.provider.MediaContract;
|
2016-04-21 10:27:49 +02:00
|
|
|
import org.xbmc.kore.service.library.LibrarySyncService;
|
2016-12-20 21:47:24 +01:00
|
|
|
import org.xbmc.kore.ui.AbstractCursorListFragment;
|
2015-03-09 22:35:18 +01:00
|
|
|
import org.xbmc.kore.utils.LogUtils;
|
2015-09-03 20:18:45 +02:00
|
|
|
import org.xbmc.kore.utils.MediaPlayerUtils;
|
2015-03-09 22:35:18 +01:00
|
|
|
import org.xbmc.kore.utils.UIUtils;
|
2015-01-14 12:12:47 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Fragment that presents the album genres list
|
|
|
|
*/
|
2016-03-18 16:58:15 +01:00
|
|
|
public class AudioGenresListFragment extends AbstractCursorListFragment {
|
2015-01-14 12:12:47 +01:00
|
|
|
private static final String TAG = LogUtils.makeLogTag(AudioGenresListFragment.class);
|
|
|
|
|
|
|
|
public interface OnAudioGenreSelectedListener {
|
|
|
|
public void onAudioGenreSelected(int genreId, String genreTitle);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Activity listener
|
|
|
|
private OnAudioGenreSelectedListener listenerActivity;
|
|
|
|
|
2015-10-14 00:05:50 +02:00
|
|
|
@Override
|
|
|
|
protected String getListSyncType() { return LibrarySyncService.SYNC_ALL_MUSIC; }
|
|
|
|
|
2015-01-14 12:12:47 +01:00
|
|
|
@Override
|
2016-03-14 20:10:59 +01:00
|
|
|
protected void onListItemClicked(View view) {
|
|
|
|
// Get the movie id from the tag
|
|
|
|
ViewHolder tag = (ViewHolder) view.getTag();
|
|
|
|
// Notify the activity
|
|
|
|
listenerActivity.onAudioGenreSelected(tag.genreId, tag.genreTitle);
|
2015-08-22 20:03:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected CursorAdapter createAdapter() {
|
|
|
|
return new AudioGenresAdapter(getActivity());
|
|
|
|
}
|
2015-01-14 12:12:47 +01:00
|
|
|
|
2015-08-22 20:03:09 +02:00
|
|
|
@Override
|
|
|
|
protected CursorLoader createCursorLoader() {
|
|
|
|
HostInfo hostInfo = HostManager.getInstance(getActivity()).getHostInfo();
|
|
|
|
Uri uri = MediaContract.AudioGenres.buildAudioGenresListUri(hostInfo != null ? hostInfo.getId() : -1);
|
2015-01-14 12:12:47 +01:00
|
|
|
|
2015-08-22 20:03:09 +02:00
|
|
|
String selection = null;
|
|
|
|
String selectionArgs[] = null;
|
|
|
|
String searchFilter = getSearchFilter();
|
|
|
|
if (!TextUtils.isEmpty(searchFilter)) {
|
|
|
|
selection = MediaContract.AudioGenres.TITLE + " LIKE ?";
|
|
|
|
selectionArgs = new String[] {"%" + searchFilter + "%"};
|
|
|
|
}
|
|
|
|
|
|
|
|
return new CursorLoader(getActivity(), uri,
|
|
|
|
AudioGenreListQuery.PROJECTION, selection, selectionArgs, AudioGenreListQuery.SORT);
|
2015-01-14 12:12:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onAttach(Activity activity) {
|
|
|
|
super.onAttach(activity);
|
|
|
|
try {
|
|
|
|
listenerActivity = (OnAudioGenreSelectedListener) activity;
|
|
|
|
} catch (ClassCastException e) {
|
|
|
|
throw new ClassCastException(activity.toString() + " must implement OnAudioGenreSelectedListener");
|
|
|
|
}
|
2016-03-14 20:10:59 +01:00
|
|
|
setSupportsSearch(true);
|
2015-01-14 12:12:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onDetach() {
|
|
|
|
super.onDetach();
|
|
|
|
listenerActivity = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Audio genres list query parameters.
|
|
|
|
*/
|
2016-09-23 20:08:22 +02:00
|
|
|
public interface AudioGenreListQuery {
|
2015-01-14 12:12:47 +01:00
|
|
|
String[] PROJECTION = {
|
|
|
|
BaseColumns._ID,
|
|
|
|
MediaContract.AudioGenres.GENREID,
|
|
|
|
MediaContract.AudioGenres.TITLE,
|
|
|
|
MediaContract.AudioGenres.THUMBNAIL,
|
|
|
|
};
|
|
|
|
|
|
|
|
String SORT = MediaContract.AudioGenres.TITLE + " ASC";
|
|
|
|
|
|
|
|
final int ID = 0;
|
|
|
|
final int GENREID = 1;
|
|
|
|
final int TITLE = 2;
|
|
|
|
final int THUMBNAIL = 3;
|
|
|
|
}
|
|
|
|
|
2015-07-28 15:26:37 +02:00
|
|
|
private class AudioGenresAdapter extends CursorAdapter {
|
2015-01-14 12:12:47 +01:00
|
|
|
|
|
|
|
private HostManager hostManager;
|
|
|
|
private int artWidth, artHeight;
|
|
|
|
|
|
|
|
public AudioGenresAdapter(Context context) {
|
|
|
|
super(context, null, false);
|
|
|
|
this.hostManager = HostManager.getInstance(context);
|
|
|
|
|
|
|
|
// Get the art dimensions
|
|
|
|
Resources resources = context.getResources();
|
|
|
|
artWidth = (int)(resources.getDimension(R.dimen.audiogenrelist_art_width) /
|
|
|
|
UIUtils.IMAGE_RESIZE_FACTOR);
|
|
|
|
artHeight = (int)(resources.getDimension(R.dimen.audiogenrelist_art_heigth) /
|
|
|
|
UIUtils.IMAGE_RESIZE_FACTOR);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** {@inheritDoc} */
|
|
|
|
@Override
|
|
|
|
public View newView(Context context, final Cursor cursor, ViewGroup parent) {
|
|
|
|
final View view = LayoutInflater.from(context)
|
|
|
|
.inflate(R.layout.grid_item_audio_genre, parent, false);
|
|
|
|
|
|
|
|
// Setup View holder pattern
|
|
|
|
ViewHolder viewHolder = new ViewHolder();
|
|
|
|
viewHolder.titleView = (TextView)view.findViewById(R.id.title);
|
|
|
|
viewHolder.artView = (ImageView)view.findViewById(R.id.art);
|
|
|
|
|
|
|
|
view.setTag(viewHolder);
|
|
|
|
return view;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** {@inheritDoc} */
|
|
|
|
@Override
|
|
|
|
public void bindView(View view, Context context, Cursor cursor) {
|
|
|
|
final ViewHolder viewHolder = (ViewHolder)view.getTag();
|
|
|
|
|
|
|
|
viewHolder.genreId = cursor.getInt(AudioGenreListQuery.GENREID);
|
|
|
|
viewHolder.genreTitle = cursor.getString(AudioGenreListQuery.TITLE);
|
|
|
|
|
|
|
|
viewHolder.titleView.setText(viewHolder.genreTitle);
|
|
|
|
|
|
|
|
String thumbnail = cursor.getString(AudioGenreListQuery.THUMBNAIL);
|
|
|
|
UIUtils.loadImageWithCharacterAvatar(context, hostManager,
|
|
|
|
thumbnail, viewHolder.genreTitle,
|
|
|
|
viewHolder.artView, artWidth, artHeight);
|
2015-07-28 15:26:37 +02:00
|
|
|
|
|
|
|
// For the popupmenu
|
|
|
|
ImageView contextMenu = (ImageView)view.findViewById(R.id.list_context_menu);
|
|
|
|
contextMenu.setTag(viewHolder);
|
|
|
|
contextMenu.setOnClickListener(genrelistItemMenuClickListener);
|
2015-01-14 12:12:47 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* View holder pattern
|
|
|
|
*/
|
|
|
|
private static class ViewHolder {
|
|
|
|
TextView titleView;
|
|
|
|
ImageView artView;
|
|
|
|
|
|
|
|
int genreId;
|
|
|
|
String genreTitle;
|
|
|
|
}
|
2015-07-28 15:26:37 +02:00
|
|
|
|
|
|
|
private View.OnClickListener genrelistItemMenuClickListener = new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(final View v) {
|
|
|
|
final ViewHolder viewHolder = (ViewHolder)v.getTag();
|
|
|
|
|
|
|
|
final PlaylistType.Item playListItem = new PlaylistType.Item();
|
|
|
|
playListItem.genreid = viewHolder.genreId;
|
|
|
|
|
|
|
|
final PopupMenu popupMenu = new PopupMenu(getActivity(), v);
|
|
|
|
popupMenu.getMenuInflater().inflate(R.menu.musiclist_item, popupMenu.getMenu());
|
|
|
|
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onMenuItemClick(MenuItem item) {
|
|
|
|
switch (item.getItemId()) {
|
|
|
|
case R.id.action_play:
|
2015-09-03 20:18:45 +02:00
|
|
|
MediaPlayerUtils.play(AudioGenresListFragment.this, playListItem);
|
2015-07-28 15:26:37 +02:00
|
|
|
return true;
|
|
|
|
case R.id.action_queue:
|
2016-01-29 23:15:02 +01:00
|
|
|
MediaPlayerUtils.queue(AudioGenresListFragment.this, playListItem, PlaylistType.GetPlaylistsReturnType.AUDIO);
|
2015-07-28 15:26:37 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
popupMenu.show();
|
|
|
|
}
|
|
|
|
};
|
2015-01-14 12:12:47 +01:00
|
|
|
}
|