Kore/app/src/main/java/org/xbmc/kore/ui/sections/video/TVShowsActivity.java

217 lines
7.8 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.video;
2015-01-14 12:12:47 +01:00
import android.annotation.TargetApi;
import android.os.Bundle;
import android.transition.TransitionInflater;
import android.view.MenuItem;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentTransaction;
import org.xbmc.kore.R;
import org.xbmc.kore.ui.AbstractFragment;
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;
import org.xbmc.kore.utils.Utils;
2015-01-14 12:12:47 +01:00
/**
* Controls the presentation of TV Shows information (list, details)
* All the information is presented by specific fragments
*/
public class TVShowsActivity extends BaseMediaActivity
2015-01-14 12:12:47 +01:00
implements TVShowListFragment.OnTVShowSelectedListener,
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
TVShowProgressFragment.TVShowProgressActionListener,
TVShowEpisodeListFragment.OnEpisodeSelectedListener {
2015-01-14 12:12:47 +01:00
private static final String TAG = LogUtils.makeLogTag(TVShowsActivity.class);
public static final String TVSHOWID = "tvshow_id";
public static final String TVSHOWTITLE = "tvshow_title";
public static final String EPISODEID = "episode_id";
public static final String SEASON = "season";
public static final String SEASONTITLE = "season_title";
2015-01-14 12:12:47 +01:00
private int selectedTVShowId = -1;
private String selectedTVShowTitle = null;
private int selectedSeason = -1;
private String selectedSeasonTitle = null;
2015-01-14 12:12:47 +01:00
private int selectedEpisodeId = -1;
@Override
protected String getActionBarTitle() {
return (selectedSeasonTitle != null) ? selectedSeasonTitle :
(selectedTVShowTitle != null) ? selectedTVShowTitle : getString(R.string.tv_shows);
}
@Override
protected Fragment createFragment() {
return new TVShowListFragment();
}
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
selectedTVShowId = savedInstanceState.getInt(TVSHOWID, -1);
selectedTVShowTitle = savedInstanceState.getString(TVSHOWTITLE, null);
selectedEpisodeId = savedInstanceState.getInt(EPISODEID, -1);
selectedSeason = savedInstanceState.getInt(SEASON, -1);
selectedSeasonTitle = savedInstanceState.getString(SEASONTITLE, null);
2015-01-14 12:12:47 +01:00
}
super.onCreate(savedInstanceState);
2015-01-14 12:12:47 +01:00
}
@Override
protected void onSaveInstanceState (Bundle outState) {
super.onSaveInstanceState(outState);
outState.putInt(TVSHOWID, selectedTVShowId);
outState.putString(TVSHOWTITLE, selectedTVShowTitle);
outState.putInt(EPISODEID, selectedEpisodeId);
outState.putInt(SEASON, selectedSeason);
outState.putString(SEASONTITLE, selectedSeasonTitle);
2015-01-14 12:12:47 +01:00
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
if (getDrawerIndicatorIsArrow()) {
2015-01-14 12:12:47 +01:00
getSupportFragmentManager().popBackStack();
updateActionBar();
2015-01-14 12:12:47 +01:00
return true;
}
default:
break;
}
return super.onOptionsItemSelected(item);
}
@Override
public void onBackPressed() {
updateActionBar();
2015-01-14 12:12:47 +01:00
super.onBackPressed();
}
/**
* Callback from tvshows list fragment when a show is selected.
* Switch fragment in portrait
* @param vh view holder
2015-01-14 12:12:47 +01:00
*/
@TargetApi(21)
public void onTVShowSelected(TVShowListFragment.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
selectedTVShowId = vh.dataHolder.getId();
selectedTVShowTitle = 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 TVShowInfoFragment tvshowDetailsFragment = new TVShowInfoFragment();
tvshowDetailsFragment.setDataHolder(vh.dataHolder);
showFragment(tvshowDetailsFragment, vh.artView, vh.dataHolder);
updateActionBar(selectedTVShowTitle, true);
}
/**
* Callback from tvshow details when a season is selected
* @param tvshowId tv show id
* @param seasonId season number
*/
public void onSeasonSelected(int tvshowId, int seasonId) {
selectedSeason = seasonId;
// Replace fragment
TVShowEpisodeListFragment fragment =
TVShowEpisodeListFragment.newInstance(selectedTVShowId, seasonId);
getSupportFragmentManager()
.beginTransaction()
.setCustomAnimations(R.anim.fragment_details_enter, 0, R.anim.fragment_list_popenter, 0)
.replace(R.id.fragment_container, fragment)
2015-01-14 12:12:47 +01:00
.addToBackStack(null)
.commit();
selectedSeasonTitle = String.format(getString(R.string.season_number), seasonId);
updateActionBar(selectedSeasonTitle, true);
2015-01-14 12:12:47 +01:00
}
/**
* Callback from tvshow details when a episode is selected
*/
@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 onNextEpisodeSelected(int tvshowId,
AbstractInfoFragment.DataHolder dh) {
selectedEpisodeId = dh.getId();
// 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
TVShowEpisodeInfoFragment fragment = new TVShowEpisodeInfoFragment();
fragment.setDataHolder(dh);
fragment.setTvshowId(tvshowId);
startFragment(fragment);
updateActionBar(selectedTVShowTitle, true);
}
2015-01-14 12:12:47 +01:00
/**
* Callback from tvshow episodes list when a episode is selected
*/
@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 onEpisodeSelected(int tvshowId,
TVShowEpisodeListFragment.ViewHolder viewHolder) {
selectedEpisodeId = viewHolder.dataHolder.getId();
TVShowEpisodeInfoFragment fragment = new TVShowEpisodeInfoFragment();
fragment.setDataHolder(viewHolder.dataHolder);
fragment.setTvshowId(tvshowId);
startFragment(fragment);
updateActionBar(selectedTVShowTitle, true);
}
@TargetApi(21)
private void startFragment(AbstractFragment fragment) {
// Replace list fragment
2015-01-14 12:12:47 +01:00
FragmentTransaction fragTrans = getSupportFragmentManager().beginTransaction();
// Set up transitions
if (Utils.isLollipopOrLater()) {
fragment.setEnterTransition(
TransitionInflater.from(this).inflateTransition(R.transition.media_details));
2015-01-14 12:12:47 +01:00
fragment.setReturnTransition(null);
} else {
fragTrans.setCustomAnimations(R.anim.fragment_details_enter, 0, R.anim.fragment_list_popenter, 0);
2015-01-14 12:12:47 +01:00
}
fragTrans.replace(R.id.fragment_container, fragment)
.addToBackStack(null)
.commit();
2015-01-14 12:12:47 +01:00
}
private void updateActionBar() {
if (selectedEpisodeId != -1) {
selectedEpisodeId = -1;
if (selectedSeason != -1)
updateActionBar(selectedSeasonTitle, true);
else
updateActionBar(selectedTVShowTitle, true);
} else if (selectedSeason != -1) {
selectedSeason = -1;
selectedSeasonTitle = null;
updateActionBar(selectedTVShowTitle, true);
} else if (selectedTVShowId != -1) {
selectedTVShowId = -1;
selectedTVShowTitle = null;
updateActionBar(getActionBarTitle(), false);
}
}
2015-01-14 12:12:47 +01:00
}