Kore/app/src/main/java/org/xbmc/kore/ui/sections/audio/MusicActivity.java

242 lines
9.2 KiB
Java
Raw Normal View History

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.
*/
package org.xbmc.kore.ui.sections.audio;
2015-01-14 12:12:47 +01:00
import android.annotation.TargetApi;
import android.os.Bundle;
import android.view.MenuItem;
import androidx.fragment.app.Fragment;
import org.xbmc.kore.R;
Refactored AbstractDetailsFragment This introduces the MVC model to details fragments. It moves as much view and control code out of the concrete fragments into the abstract classes. * Added UML class and sequence diagrams under doc/diagrams to clarify the new setup * Introduces new abstract classes * AbstractFragment class to hold the DataHolder * AbstractInfoFragment class to display media information * AbstractAddtionalInfoFragment class to allow *InfoFragments to add additional UI elements and propagate refresh requests. See for an example TVShowInfoFragment which adds TVShowProgressFragment to display next episodes and season progression. * Introduces new RefreshItem class to encapsulate all refresh functionality from AbstractDetailsFragment * Introduces new SharedElementTransition utility class to encapsulate all shared element transition code * Introduces new CastFragment class to encapsulate all code for displaying casts reducing code duplication * Introduces DataHolder class to replace passing the ViewHolder from the *ListFragment to the *DetailsFragment or *InfoFragment * Refactored AbstractDetailsFragment into two classes: o AbstractDetailsFragment: for fragments requiring a tab bar o AbstractInfoFragment: for fragments showing media information We used to use <NAME>DetailsFragments for both fragments that show generic info about some media item and fragments that hold all details for some media item. For example, artist details showed artist info and used tabs to show artist albums and songs as well. Now Details fragments are used to show all details, Info fragments only show media item information like description, title, rating, etc. * Moved swiperefreshlayout code from AbstractCursorListFragment to AbstractListFragment
2016-12-30 09:27:24 +01:00
import org.xbmc.kore.ui.AbstractInfoFragment;
import org.xbmc.kore.ui.BaseMediaActivity;
import org.xbmc.kore.utils.LogUtils;
2015-01-14 12:12:47 +01:00
/**
* Controls the presentation of Music information (list, details)
* All the information is presented by specific fragments
*/
public class MusicActivity extends BaseMediaActivity
2015-01-14 12:12:47 +01:00
implements ArtistListFragment.OnArtistSelectedListener,
Refactored AbstractDetailsFragment This introduces the MVC model to details fragments. It moves as much view and control code out of the concrete fragments into the abstract classes. * Added UML class and sequence diagrams under doc/diagrams to clarify the new setup * Introduces new abstract classes * AbstractFragment class to hold the DataHolder * AbstractInfoFragment class to display media information * AbstractAddtionalInfoFragment class to allow *InfoFragments to add additional UI elements and propagate refresh requests. See for an example TVShowInfoFragment which adds TVShowProgressFragment to display next episodes and season progression. * Introduces new RefreshItem class to encapsulate all refresh functionality from AbstractDetailsFragment * Introduces new SharedElementTransition utility class to encapsulate all shared element transition code * Introduces new CastFragment class to encapsulate all code for displaying casts reducing code duplication * Introduces DataHolder class to replace passing the ViewHolder from the *ListFragment to the *DetailsFragment or *InfoFragment * Refactored AbstractDetailsFragment into two classes: o AbstractDetailsFragment: for fragments requiring a tab bar o AbstractInfoFragment: for fragments showing media information We used to use <NAME>DetailsFragments for both fragments that show generic info about some media item and fragments that hold all details for some media item. For example, artist details showed artist info and used tabs to show artist albums and songs as well. Now Details fragments are used to show all details, Info fragments only show media item information like description, title, rating, etc. * Moved swiperefreshlayout code from AbstractCursorListFragment to AbstractListFragment
2016-12-30 09:27:24 +01:00
AlbumListFragment.OnAlbumSelectedListener,
AudioGenresListFragment.OnAudioGenreSelectedListener,
MusicVideoListFragment.OnMusicVideoSelectedListener {
2015-01-14 12:12:47 +01:00
private static final String TAG = LogUtils.makeLogTag(MusicActivity.class);
public static final String ALBUMID = "album_id";
public static final String ALBUMTITLE = "album_title";
public static final String ARTISTID = "artist_id";
public static final String ARTISTNAME = "artist_name";
public static final String GENREID = "genre_id";
public static final String GENRETITLE = "genre_title";
public static final String MUSICVIDEOID = "music_video_id";
public static final String MUSICVIDEOTITLE = "music_video_title";
private int selectedAlbumId = -1;
private int selectedArtistId = -1;
private int selectedGenreId = -1;
private int selectedMusicVideoId = -1;
private String selectedAlbumTitle = null;
private String selectedArtistName = null;
private String selectedGenreTitle = null;
private String selectedMusicVideoTitle = null;
@Override
protected String getActionBarTitle() {
if (selectedAlbumTitle != null) {
return selectedAlbumTitle;
} else if (selectedArtistName != null) {
return selectedArtistName;
} else if (selectedGenreTitle != null) {
return selectedGenreTitle;
} else if (selectedMusicVideoTitle != null) {
return selectedMusicVideoTitle;
} else {
return getResources().getString(R.string.music);
}
}
@Override
protected Fragment createFragment() {
return new MusicListFragment();
}
2015-01-14 12:12:47 +01:00
@TargetApi(21)
@Override
protected void onCreate(Bundle savedInstanceState) {
if (savedInstanceState != null) {
2015-01-14 12:12:47 +01:00
selectedAlbumId = savedInstanceState.getInt(ALBUMID, -1);
selectedArtistId = savedInstanceState.getInt(ARTISTID, -1);
selectedGenreId = savedInstanceState.getInt(GENREID, -1);
selectedMusicVideoId = savedInstanceState.getInt(MUSICVIDEOID, -1);
selectedAlbumTitle = savedInstanceState.getString(ALBUMTITLE, null);
selectedArtistName = savedInstanceState.getString(ARTISTNAME, null);
selectedGenreTitle = savedInstanceState.getString(GENRETITLE, null);
selectedMusicVideoTitle = savedInstanceState.getString(MUSICVIDEOTITLE, null);
}
super.onCreate(savedInstanceState);
2015-01-14 12:12:47 +01:00
}
@Override
protected void onSaveInstanceState (Bundle outState) {
super.onSaveInstanceState(outState);
outState.putInt(ALBUMID, selectedAlbumId);
outState.putInt(ARTISTID, selectedArtistId);
outState.putInt(GENREID, selectedGenreId);
outState.putInt(MUSICVIDEOID, selectedMusicVideoId);
outState.putString(ALBUMTITLE, selectedAlbumTitle);
outState.putString(ARTISTNAME, selectedArtistName);
outState.putString(GENRETITLE, selectedGenreTitle);
outState.putString(MUSICVIDEOTITLE, selectedMusicVideoTitle);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
// Only respond to this if we are showing some details, which can be checked by
// checking if some id != -1, in which case we should go back to the previous
// fragment, which is the list.
// The default behaviour is handled by the nav drawer (open/close)
boolean respond = false;
2015-01-14 12:12:47 +01:00
if (selectedAlbumId != -1) {
selectedAlbumId = -1;
selectedAlbumTitle = null;
respond = true;
2015-01-14 12:12:47 +01:00
} else if (selectedArtistId != -1) {
selectedArtistId = -1;
selectedArtistName = null;
respond = true;
2015-01-14 12:12:47 +01:00
} else if (selectedGenreId != -1) {
selectedGenreId = -1;
selectedGenreTitle = null;
respond = true;
2015-01-14 12:12:47 +01:00
} else if (selectedMusicVideoId != -1) {
selectedMusicVideoId = -1;
selectedMusicVideoTitle = null;
respond = true;
}
if (respond) {
if (selectedArtistId == -1 &&
selectedGenreId == -1 &&
selectedMusicVideoId == -1) {
updateActionBar(getActionBarTitle(), false);
} else {
updateActionBar(getActionBarTitle(), true);
}
2015-01-14 12:12:47 +01:00
getSupportFragmentManager().popBackStack();
return true;
}
break;
default:
break;
}
return super.onOptionsItemSelected(item);
}
@Override
public void onBackPressed() {
// If we are showing episode or show details in portrait, clear selected and show action bar
if (selectedAlbumId != -1) {
selectedAlbumId = -1;
selectedAlbumTitle = null;
} else if (selectedArtistId != -1) {
selectedArtistId = -1;
selectedArtistName = null;
} else if (selectedGenreId != -1) {
selectedGenreId = -1;
selectedGenreTitle = null;
} else if (selectedMusicVideoId != -1) {
selectedMusicVideoId = -1;
selectedMusicVideoTitle = null;
}
if (selectedArtistId == -1 &&
selectedGenreId == -1 &&
selectedMusicVideoId == -1) {
updateActionBar(getActionBarTitle(), false);
} else {
updateActionBar(getActionBarTitle(), true);
}
super.onBackPressed();
2015-01-14 12:12:47 +01:00
}
@TargetApi(21)
Refactored AbstractDetailsFragment This introduces the MVC model to details fragments. It moves as much view and control code out of the concrete fragments into the abstract classes. * Added UML class and sequence diagrams under doc/diagrams to clarify the new setup * Introduces new abstract classes * AbstractFragment class to hold the DataHolder * AbstractInfoFragment class to display media information * AbstractAddtionalInfoFragment class to allow *InfoFragments to add additional UI elements and propagate refresh requests. See for an example TVShowInfoFragment which adds TVShowProgressFragment to display next episodes and season progression. * Introduces new RefreshItem class to encapsulate all refresh functionality from AbstractDetailsFragment * Introduces new SharedElementTransition utility class to encapsulate all shared element transition code * Introduces new CastFragment class to encapsulate all code for displaying casts reducing code duplication * Introduces DataHolder class to replace passing the ViewHolder from the *ListFragment to the *DetailsFragment or *InfoFragment * Refactored AbstractDetailsFragment into two classes: o AbstractDetailsFragment: for fragments requiring a tab bar o AbstractInfoFragment: for fragments showing media information We used to use <NAME>DetailsFragments for both fragments that show generic info about some media item and fragments that hold all details for some media item. For example, artist details showed artist info and used tabs to show artist albums and songs as well. Now Details fragments are used to show all details, Info fragments only show media item information like description, title, rating, etc. * Moved swiperefreshlayout code from AbstractCursorListFragment to AbstractListFragment
2016-12-30 09:27:24 +01:00
public void onArtistSelected(ArtistListFragment.ViewHolder vh) {
selectedArtistId = vh.dataHolder.getId();
selectedArtistName = vh.dataHolder.getTitle();
2015-01-14 12:12:47 +01:00
// Replace list fragment
Refactored AbstractDetailsFragment This introduces the MVC model to details fragments. It moves as much view and control code out of the concrete fragments into the abstract classes. * Added UML class and sequence diagrams under doc/diagrams to clarify the new setup * Introduces new abstract classes * AbstractFragment class to hold the DataHolder * AbstractInfoFragment class to display media information * AbstractAddtionalInfoFragment class to allow *InfoFragments to add additional UI elements and propagate refresh requests. See for an example TVShowInfoFragment which adds TVShowProgressFragment to display next episodes and season progression. * Introduces new RefreshItem class to encapsulate all refresh functionality from AbstractDetailsFragment * Introduces new SharedElementTransition utility class to encapsulate all shared element transition code * Introduces new CastFragment class to encapsulate all code for displaying casts reducing code duplication * Introduces DataHolder class to replace passing the ViewHolder from the *ListFragment to the *DetailsFragment or *InfoFragment * Refactored AbstractDetailsFragment into two classes: o AbstractDetailsFragment: for fragments requiring a tab bar o AbstractInfoFragment: for fragments showing media information We used to use <NAME>DetailsFragments for both fragments that show generic info about some media item and fragments that hold all details for some media item. For example, artist details showed artist info and used tabs to show artist albums and songs as well. Now Details fragments are used to show all details, Info fragments only show media item information like description, title, rating, etc. * Moved swiperefreshlayout code from AbstractCursorListFragment to AbstractListFragment
2016-12-30 09:27:24 +01:00
final ArtistDetailsFragment artistDetailsFragment = new ArtistDetailsFragment();
artistDetailsFragment.setDataHolder(vh.dataHolder);
vh.dataHolder.setSquarePoster(true);
showFragment(artistDetailsFragment, vh.artView, vh.dataHolder);
updateActionBar(selectedArtistName, true);
2015-01-14 12:12:47 +01:00
}
@TargetApi(21)
public void onAlbumSelected(AlbumListFragment.ViewHolder vh) {
Refactored AbstractDetailsFragment This introduces the MVC model to details fragments. It moves as much view and control code out of the concrete fragments into the abstract classes. * Added UML class and sequence diagrams under doc/diagrams to clarify the new setup * Introduces new abstract classes * AbstractFragment class to hold the DataHolder * AbstractInfoFragment class to display media information * AbstractAddtionalInfoFragment class to allow *InfoFragments to add additional UI elements and propagate refresh requests. See for an example TVShowInfoFragment which adds TVShowProgressFragment to display next episodes and season progression. * Introduces new RefreshItem class to encapsulate all refresh functionality from AbstractDetailsFragment * Introduces new SharedElementTransition utility class to encapsulate all shared element transition code * Introduces new CastFragment class to encapsulate all code for displaying casts reducing code duplication * Introduces DataHolder class to replace passing the ViewHolder from the *ListFragment to the *DetailsFragment or *InfoFragment * Refactored AbstractDetailsFragment into two classes: o AbstractDetailsFragment: for fragments requiring a tab bar o AbstractInfoFragment: for fragments showing media information We used to use <NAME>DetailsFragments for both fragments that show generic info about some media item and fragments that hold all details for some media item. For example, artist details showed artist info and used tabs to show artist albums and songs as well. Now Details fragments are used to show all details, Info fragments only show media item information like description, title, rating, etc. * Moved swiperefreshlayout code from AbstractCursorListFragment to AbstractListFragment
2016-12-30 09:27:24 +01:00
selectedAlbumId = vh.dataHolder.getId();
selectedAlbumTitle = vh.dataHolder.getTitle();
2015-01-14 12:12:47 +01:00
// Replace list fragment
Refactored AbstractDetailsFragment This introduces the MVC model to details fragments. It moves as much view and control code out of the concrete fragments into the abstract classes. * Added UML class and sequence diagrams under doc/diagrams to clarify the new setup * Introduces new abstract classes * AbstractFragment class to hold the DataHolder * AbstractInfoFragment class to display media information * AbstractAddtionalInfoFragment class to allow *InfoFragments to add additional UI elements and propagate refresh requests. See for an example TVShowInfoFragment which adds TVShowProgressFragment to display next episodes and season progression. * Introduces new RefreshItem class to encapsulate all refresh functionality from AbstractDetailsFragment * Introduces new SharedElementTransition utility class to encapsulate all shared element transition code * Introduces new CastFragment class to encapsulate all code for displaying casts reducing code duplication * Introduces DataHolder class to replace passing the ViewHolder from the *ListFragment to the *DetailsFragment or *InfoFragment * Refactored AbstractDetailsFragment into two classes: o AbstractDetailsFragment: for fragments requiring a tab bar o AbstractInfoFragment: for fragments showing media information We used to use <NAME>DetailsFragments for both fragments that show generic info about some media item and fragments that hold all details for some media item. For example, artist details showed artist info and used tabs to show artist albums and songs as well. Now Details fragments are used to show all details, Info fragments only show media item information like description, title, rating, etc. * Moved swiperefreshlayout code from AbstractCursorListFragment to AbstractListFragment
2016-12-30 09:27:24 +01:00
final AbstractInfoFragment albumInfoFragment = new AlbumInfoFragment();
vh.dataHolder.setSquarePoster(true);
albumInfoFragment.setDataHolder(vh.dataHolder);
2015-01-14 12:12:47 +01:00
showFragment(albumInfoFragment, vh.artView, vh.dataHolder);
2015-01-14 12:12:47 +01:00
updateActionBar(selectedAlbumTitle, true);
2015-01-14 12:12:47 +01:00
}
public void onAudioGenreSelected(int genreId, String genreTitle) {
selectedGenreId = genreId;
selectedGenreTitle = genreTitle;
// Replace list fragment
Refactored AbstractDetailsFragment This introduces the MVC model to details fragments. It moves as much view and control code out of the concrete fragments into the abstract classes. * Added UML class and sequence diagrams under doc/diagrams to clarify the new setup * Introduces new abstract classes * AbstractFragment class to hold the DataHolder * AbstractInfoFragment class to display media information * AbstractAddtionalInfoFragment class to allow *InfoFragments to add additional UI elements and propagate refresh requests. See for an example TVShowInfoFragment which adds TVShowProgressFragment to display next episodes and season progression. * Introduces new RefreshItem class to encapsulate all refresh functionality from AbstractDetailsFragment * Introduces new SharedElementTransition utility class to encapsulate all shared element transition code * Introduces new CastFragment class to encapsulate all code for displaying casts reducing code duplication * Introduces DataHolder class to replace passing the ViewHolder from the *ListFragment to the *DetailsFragment or *InfoFragment * Refactored AbstractDetailsFragment into two classes: o AbstractDetailsFragment: for fragments requiring a tab bar o AbstractInfoFragment: for fragments showing media information We used to use <NAME>DetailsFragments for both fragments that show generic info about some media item and fragments that hold all details for some media item. For example, artist details showed artist info and used tabs to show artist albums and songs as well. Now Details fragments are used to show all details, Info fragments only show media item information like description, title, rating, etc. * Moved swiperefreshlayout code from AbstractCursorListFragment to AbstractListFragment
2016-12-30 09:27:24 +01:00
AlbumListFragment albumListFragment = new AlbumListFragment();
albumListFragment.setGenre(genreId);
2015-01-14 12:12:47 +01:00
getSupportFragmentManager()
.beginTransaction()
.setCustomAnimations(R.anim.fragment_details_enter, 0, R.anim.fragment_list_popenter, 0)
.replace(R.id.fragment_container, albumListFragment)
.addToBackStack(null)
.commit();
updateActionBar(selectedGenreTitle, true);
2015-01-14 12:12:47 +01:00
}
@TargetApi(21)
public void onMusicVideoSelected(MusicVideoListFragment.ViewHolder vh) {
Refactored AbstractDetailsFragment This introduces the MVC model to details fragments. It moves as much view and control code out of the concrete fragments into the abstract classes. * Added UML class and sequence diagrams under doc/diagrams to clarify the new setup * Introduces new abstract classes * AbstractFragment class to hold the DataHolder * AbstractInfoFragment class to display media information * AbstractAddtionalInfoFragment class to allow *InfoFragments to add additional UI elements and propagate refresh requests. See for an example TVShowInfoFragment which adds TVShowProgressFragment to display next episodes and season progression. * Introduces new RefreshItem class to encapsulate all refresh functionality from AbstractDetailsFragment * Introduces new SharedElementTransition utility class to encapsulate all shared element transition code * Introduces new CastFragment class to encapsulate all code for displaying casts reducing code duplication * Introduces DataHolder class to replace passing the ViewHolder from the *ListFragment to the *DetailsFragment or *InfoFragment * Refactored AbstractDetailsFragment into two classes: o AbstractDetailsFragment: for fragments requiring a tab bar o AbstractInfoFragment: for fragments showing media information We used to use <NAME>DetailsFragments for both fragments that show generic info about some media item and fragments that hold all details for some media item. For example, artist details showed artist info and used tabs to show artist albums and songs as well. Now Details fragments are used to show all details, Info fragments only show media item information like description, title, rating, etc. * Moved swiperefreshlayout code from AbstractCursorListFragment to AbstractListFragment
2016-12-30 09:27:24 +01:00
selectedMusicVideoId = vh.dataHolder.getId();
selectedMusicVideoTitle = vh.dataHolder.getTitle();
2015-01-14 12:12:47 +01:00
// Replace list fragment
Refactored AbstractDetailsFragment This introduces the MVC model to details fragments. It moves as much view and control code out of the concrete fragments into the abstract classes. * Added UML class and sequence diagrams under doc/diagrams to clarify the new setup * Introduces new abstract classes * AbstractFragment class to hold the DataHolder * AbstractInfoFragment class to display media information * AbstractAddtionalInfoFragment class to allow *InfoFragments to add additional UI elements and propagate refresh requests. See for an example TVShowInfoFragment which adds TVShowProgressFragment to display next episodes and season progression. * Introduces new RefreshItem class to encapsulate all refresh functionality from AbstractDetailsFragment * Introduces new SharedElementTransition utility class to encapsulate all shared element transition code * Introduces new CastFragment class to encapsulate all code for displaying casts reducing code duplication * Introduces DataHolder class to replace passing the ViewHolder from the *ListFragment to the *DetailsFragment or *InfoFragment * Refactored AbstractDetailsFragment into two classes: o AbstractDetailsFragment: for fragments requiring a tab bar o AbstractInfoFragment: for fragments showing media information We used to use <NAME>DetailsFragments for both fragments that show generic info about some media item and fragments that hold all details for some media item. For example, artist details showed artist info and used tabs to show artist albums and songs as well. Now Details fragments are used to show all details, Info fragments only show media item information like description, title, rating, etc. * Moved swiperefreshlayout code from AbstractCursorListFragment to AbstractListFragment
2016-12-30 09:27:24 +01:00
final MusicVideoInfoFragment musicVideoInfoFragment = new MusicVideoInfoFragment();
vh.dataHolder.setSquarePoster(true);
musicVideoInfoFragment.setDataHolder(vh.dataHolder);
showFragment(musicVideoInfoFragment, vh.artView, vh.dataHolder);
2015-01-14 12:12:47 +01:00
updateActionBar(selectedMusicVideoTitle, true);
2015-01-14 12:12:47 +01:00
}
}