Introduces BaseMediaActivity (#374)

* BaseMediaActivity enforces a common layout which allows us to more
     easily add new common UI elements
   * All activities that allow browsing media should extend BaseMediaActivity
     Currently CastActivity is the only exception.
This commit is contained in:
Martijn Brekhof 2017-04-21 19:39:55 +02:00 committed by Synced Synapse
parent db7d689c3a
commit 6afaa60d74
7 changed files with 359 additions and 682 deletions

View File

@ -0,0 +1,189 @@
/*
* Copyright 2017 Martijn Brekhof. 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;
import android.annotation.TargetApi;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.transition.TransitionInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.Window;
import android.widget.ImageView;
import org.xbmc.kore.R;
import org.xbmc.kore.Settings;
import org.xbmc.kore.ui.generic.NavigationDrawerFragment;
import org.xbmc.kore.ui.sections.remote.RemoteActivity;
import org.xbmc.kore.utils.LogUtils;
import org.xbmc.kore.utils.SharedElementTransition;
import org.xbmc.kore.utils.UIUtils;
import org.xbmc.kore.utils.Utils;
public abstract class BaseMediaActivity extends AppCompatActivity {
private static final String TAG = LogUtils.makeLogTag(BaseMediaActivity.class);
private static final String NAVICON_ISARROW = "navstate";
private static final String ACTIONBAR_TITLE = "actionbartitle";
private NavigationDrawerFragment navigationDrawerFragment;
private SharedElementTransition sharedElementTransition = new SharedElementTransition();
private boolean drawerIndicatorIsArrow;
protected abstract String getActionBarTitle();
protected abstract Fragment createFragment();
@Override
@TargetApi(21)
protected void onCreate(Bundle savedInstanceState) {
// Request transitions on lollipop
if (Utils.isLollipopOrLater()) {
getWindow().requestFeature(Window.FEATURE_CONTENT_TRANSITIONS);
}
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
setTheme(UIUtils.getThemeResourceId(
prefs.getString(Settings.KEY_PREF_THEME, Settings.DEFAULT_PREF_THEME)));
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_generic_media);
// Set up the drawer.
navigationDrawerFragment = (NavigationDrawerFragment)getSupportFragmentManager()
.findFragmentById(R.id.navigation_drawer);
navigationDrawerFragment.setUp(R.id.navigation_drawer, (DrawerLayout) findViewById(R.id.drawer_layout));
Toolbar toolbar = (Toolbar)findViewById(R.id.default_toolbar);
setSupportActionBar(toolbar);
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
if (savedInstanceState != null) {
updateActionBar(savedInstanceState.getString(ACTIONBAR_TITLE),
savedInstanceState.getBoolean(NAVICON_ISARROW));
} else {
updateActionBar(getActionBarTitle(), false);
}
}
String fragmentTitle = getActionBarTitle();
Fragment fragment = getSupportFragmentManager().findFragmentById(R.id.fragment_container);
if (fragment == null) {
fragment = createFragment();
if (Utils.isLollipopOrLater()) {
fragment.setExitTransition(null);
fragment.setReenterTransition(TransitionInflater
.from(this)
.inflateTransition(android.R.transition.fade));
}
getSupportFragmentManager()
.beginTransaction()
.add(R.id.fragment_container, fragment, fragmentTitle)
.commit();
}
if (Utils.isLollipopOrLater()) {
sharedElementTransition.setupExitTransition(this, fragment);
}
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putBoolean(NAVICON_ISARROW, drawerIndicatorIsArrow);
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
CharSequence title = actionBar.getTitle();
if (title != null) {
outState.putString(ACTIONBAR_TITLE, title.toString());
}
}
}
public boolean getDrawerIndicatorIsArrow() {
return drawerIndicatorIsArrow;
}
/**
* Sets the title and drawer indicator of the toolbar
* @param title
* @param showArrowIndicator true if the toolbar should show the back arrow indicator,
* false if it should show the drawer icon
*/
protected void updateActionBar(String title, boolean showArrowIndicator) {
if (showArrowIndicator != drawerIndicatorIsArrow) {
navigationDrawerFragment.animateDrawerToggle(showArrowIndicator);
drawerIndicatorIsArrow = showArrowIndicator;
}
ActionBar actionBar = getSupportActionBar();
if (actionBar != null)
actionBar.setTitle(title);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.media_info, menu);
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_show_remote:
Intent launchIntent = new Intent(this, RemoteActivity.class)
.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
startActivity(launchIntent);
return true;
default:
break;
}
return super.onOptionsItemSelected(item);
}
@TargetApi(21)
protected void showFragment(AbstractFragment fragment, ImageView sharedImageView, AbstractFragment.DataHolder dataHolder) {
FragmentTransaction fragTrans = getSupportFragmentManager().beginTransaction();
// Set up transitions
if (Utils.isLollipopOrLater()) {
dataHolder.setPosterTransitionName(sharedImageView.getTransitionName());
sharedElementTransition.setupEnterTransition(this, fragTrans, fragment, sharedImageView);
} else {
fragTrans.setCustomAnimations(R.anim.fragment_details_enter, 0,
R.anim.fragment_list_popenter, 0);
}
fragTrans.replace(R.id.fragment_container, fragment, getActionBarTitle())
.addToBackStack(null)
.commit();
dataHolder.getBundle().putBoolean(NAVICON_ISARROW, true);
}
}

View File

@ -19,77 +19,47 @@ import android.annotation.TargetApi;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBar;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.text.TextUtils;
import android.view.MenuItem;
import android.view.Window;
import org.xbmc.kore.R;
import org.xbmc.kore.ui.AbstractFragment;
import org.xbmc.kore.ui.BaseActivity;
import org.xbmc.kore.ui.generic.NavigationDrawerFragment;
import org.xbmc.kore.ui.BaseMediaActivity;
import org.xbmc.kore.ui.sections.remote.RemoteActivity;
import org.xbmc.kore.utils.LogUtils;
import org.xbmc.kore.utils.SharedElementTransition;
import org.xbmc.kore.utils.Utils;
/**
* Controls the presentation of Addons information (list, details)
* All the information is presented by specific fragments
*/
public class AddonsActivity extends BaseActivity
public class AddonsActivity extends BaseMediaActivity
implements AddonListFragment.OnAddonSelectedListener {
private static final String TAG = LogUtils.makeLogTag(AddonsActivity.class);
public static final String ADDONID = "addon_id";
public static final String ADDONTITLE = "addon_title";
public static final String LISTFRAGMENT_TAG = "addonlist";
private String selectedAddonId;
private String selectedAddonTitle;
private NavigationDrawerFragment navigationDrawerFragment;
@Override
protected Fragment createFragment() {
return new AddonListFragment();
}
private SharedElementTransition sharedElementTransition = new SharedElementTransition();
@Override
protected String getActionBarTitle() {
return TextUtils.isEmpty(selectedAddonTitle) ? getResources().getString(R.string.addons)
: selectedAddonTitle;
}
@TargetApi(21)
@Override
protected void onCreate(Bundle savedInstanceState) {
// Request transitions on lollipop
if (Utils.isLollipopOrLater()) {
getWindow().requestFeature(Window.FEATURE_CONTENT_TRANSITIONS);
}
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_generic_media);
// Set up the drawer.
navigationDrawerFragment = (NavigationDrawerFragment)getSupportFragmentManager()
.findFragmentById(R.id.navigation_drawer);
navigationDrawerFragment.setUp(R.id.navigation_drawer, (DrawerLayout) findViewById(R.id.drawer_layout));
Fragment fragment;
if (savedInstanceState == null) {
fragment = new AddonListContainerFragment();
getSupportFragmentManager()
.beginTransaction()
.add(R.id.fragment_container, fragment, LISTFRAGMENT_TAG)
.commit();
} else {
fragment = getSupportFragmentManager().findFragmentByTag(LISTFRAGMENT_TAG);
if (savedInstanceState != null) {
selectedAddonId = savedInstanceState.getString(ADDONID, null);
selectedAddonTitle = savedInstanceState.getString(ADDONTITLE, null);
}
if (Utils.isLollipopOrLater()) {
sharedElementTransition.setupExitTransition(this, fragment);
}
setupActionBar(selectedAddonTitle);
super.onCreate(savedInstanceState);
}
@Override
@ -99,15 +69,6 @@ public class AddonsActivity extends BaseActivity
outState.putString(ADDONTITLE, selectedAddonTitle);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// if (!navigationDrawerFragment.isDrawerOpen()) {
// getMenuInflater().inflate(R.menu.media_info, menu);
// }
getMenuInflater().inflate(R.menu.media_info, menu);
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
@ -124,7 +85,7 @@ public class AddonsActivity extends BaseActivity
if (selectedAddonId != null) {
selectedAddonId = null;
selectedAddonTitle = null;
setupActionBar(null);
updateActionBar(getActionBarTitle(), false);
getSupportFragmentManager().popBackStack();
return true;
}
@ -142,34 +103,11 @@ public class AddonsActivity extends BaseActivity
if (selectedAddonId != null) {
selectedAddonId = null;
selectedAddonTitle = null;
setupActionBar(null);
updateActionBar(getActionBarTitle(), false);
}
super.onBackPressed();
}
private boolean drawerIndicatorIsArrow = false;
private void setupActionBar(String addonTitle) {
Toolbar toolbar = (Toolbar)findViewById(R.id.default_toolbar);
setSupportActionBar(toolbar);
ActionBar actionBar = getSupportActionBar();
if (actionBar == null) return;
actionBar.setDisplayHomeAsUpEnabled(true);
if (addonTitle != null) {
if (!drawerIndicatorIsArrow) {
navigationDrawerFragment.animateDrawerToggle(true);
drawerIndicatorIsArrow = true;
}
actionBar.setTitle(addonTitle);
} else {
if (drawerIndicatorIsArrow) {
navigationDrawerFragment.animateDrawerToggle(false);
drawerIndicatorIsArrow = false;
}
actionBar.setTitle(R.string.addons);
}
}
/**
* Callback from list fragment when a addon is selected.
* Switch fragment in portrait
@ -191,21 +129,8 @@ public class AddonsActivity extends BaseActivity
vh.dataHolder.setSquarePoster(true);
vh.dataHolder.setPosterTransitionName(vh.artView.getTransitionName());
FragmentTransaction fragTrans = getSupportFragmentManager().beginTransaction();
showFragment(addonDetailsFragment, vh.artView, vh.dataHolder);
// Set up transitions
if (Utils.isLollipopOrLater()) {
sharedElementTransition.setupEnterTransition(this, fragTrans, addonDetailsFragment,
vh.artView);
} else {
fragTrans.setCustomAnimations(R.anim.fragment_details_enter, 0,
R.anim.fragment_list_popenter, 0);
}
fragTrans.replace(R.id.fragment_container, addonDetailsFragment)
.addToBackStack(null)
.commit();
setupActionBar(selectedAddonTitle);
updateActionBar(getActionBarTitle(), true);
}
}

View File

@ -16,30 +16,20 @@
package org.xbmc.kore.ui.sections.audio;
import android.annotation.TargetApi;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBar;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import org.xbmc.kore.R;
import org.xbmc.kore.ui.AbstractInfoFragment;
import org.xbmc.kore.ui.BaseActivity;
import org.xbmc.kore.ui.generic.NavigationDrawerFragment;
import org.xbmc.kore.ui.sections.remote.RemoteActivity;
import org.xbmc.kore.ui.BaseMediaActivity;
import org.xbmc.kore.utils.LogUtils;
import org.xbmc.kore.utils.SharedElementTransition;
import org.xbmc.kore.utils.Utils;
/**
* Controls the presentation of Music information (list, details)
* All the information is presented by specific fragments
*/
public class MusicActivity extends BaseActivity
public class MusicActivity extends BaseMediaActivity
implements ArtistListFragment.OnArtistSelectedListener,
AlbumListFragment.OnAlbumSelectedListener,
AudioGenresListFragment.OnAudioGenreSelectedListener,
@ -54,7 +44,6 @@ public class MusicActivity extends BaseActivity
public static final String GENRETITLE = "genre_title";
public static final String MUSICVIDEOID = "music_video_id";
public static final String MUSICVIDEOTITLE = "music_video_title";
public static final String LISTFRAGMENT_TAG = "musiclist";
private int selectedAlbumId = -1;
private int selectedArtistId = -1;
@ -65,33 +54,30 @@ public class MusicActivity extends BaseActivity
private String selectedGenreTitle = null;
private String selectedMusicVideoTitle = null;
private NavigationDrawerFragment navigationDrawerFragment;
private SharedElementTransition sharedElementTransition = new SharedElementTransition();
@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();
}
@TargetApi(21)
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_generic_media);
// Set up the drawer.
navigationDrawerFragment = (NavigationDrawerFragment) getSupportFragmentManager()
.findFragmentById(R.id.navigation_drawer);
navigationDrawerFragment.setUp(R.id.navigation_drawer, (DrawerLayout) findViewById(R.id.drawer_layout));
Fragment fragment;
if (savedInstanceState == null) {
fragment = new MusicListFragment();
getSupportFragmentManager()
.beginTransaction()
.add(R.id.fragment_container, fragment, LISTFRAGMENT_TAG)
.commit();
} else {
fragment = getSupportFragmentManager().findFragmentByTag(LISTFRAGMENT_TAG);
if (savedInstanceState != null) {
selectedAlbumId = savedInstanceState.getInt(ALBUMID, -1);
selectedArtistId = savedInstanceState.getInt(ARTISTID, -1);
selectedGenreId = savedInstanceState.getInt(GENREID, -1);
@ -101,17 +87,7 @@ public class MusicActivity extends BaseActivity
selectedGenreTitle = savedInstanceState.getString(GENRETITLE, null);
selectedMusicVideoTitle = savedInstanceState.getString(MUSICVIDEOTITLE, null);
}
if (Utils.isLollipopOrLater()) {
sharedElementTransition.setupExitTransition(this, fragment);
}
setupActionBar(selectedAlbumTitle, selectedArtistName, selectedGenreTitle, selectedMusicVideoTitle);
// // Setup system bars and content padding, allowing averlap with the bottom bar
// setupSystemBarsColors();
// UIUtils.setPaddingForSystemBars(this, findViewById(R.id.fragment_container), true, true, true);
// UIUtils.setPaddingForSystemBars(this, findViewById(R.id.drawer_layout), true, true, true);
super.onCreate(savedInstanceState);
}
@Override
@ -127,51 +103,40 @@ public class MusicActivity extends BaseActivity
outState.putString(MUSICVIDEOTITLE, selectedMusicVideoTitle);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// if (!navigationDrawerFragment.isDrawerOpen()) {
// getMenuInflater().inflate(R.menu.media_info, menu);
// }
getMenuInflater().inflate(R.menu.media_info, menu);
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_show_remote:
// Starts remote
Intent launchIntent = new Intent(this, RemoteActivity.class)
.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
startActivity(launchIntent);
return true;
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;
if (selectedAlbumId != -1) {
selectedAlbumId = -1;
selectedAlbumTitle = null;
setupActionBar(null, selectedArtistName, selectedGenreTitle, selectedMusicVideoTitle);
getSupportFragmentManager().popBackStack();
return true;
respond = true;
} else if (selectedArtistId != -1) {
selectedArtistId = -1;
selectedArtistName = null;
setupActionBar(selectedAlbumTitle, null, selectedGenreTitle, selectedMusicVideoTitle);
getSupportFragmentManager().popBackStack();
return true;
respond = true;
} else if (selectedGenreId != -1) {
selectedGenreId = -1;
selectedGenreTitle = null;
setupActionBar(selectedAlbumTitle, selectedArtistName, null, selectedMusicVideoTitle);
getSupportFragmentManager().popBackStack();
return true;
respond = true;
} else if (selectedMusicVideoId != -1) {
selectedMusicVideoId = -1;
selectedMusicVideoTitle = null;
setupActionBar(selectedAlbumTitle, selectedArtistName, selectedGenreTitle, null);
respond = true;
}
if (respond) {
if (selectedArtistId == -1 &&
selectedGenreId == -1 &&
selectedMusicVideoId == -1) {
updateActionBar(getActionBarTitle(), false);
} else {
updateActionBar(getActionBarTitle(), true);
}
getSupportFragmentManager().popBackStack();
return true;
}
@ -189,59 +154,27 @@ public class MusicActivity extends BaseActivity
if (selectedAlbumId != -1) {
selectedAlbumId = -1;
selectedAlbumTitle = null;
setupActionBar(null, selectedArtistName, selectedGenreTitle, selectedMusicVideoTitle);
} else if (selectedArtistId != -1) {
selectedArtistId = -1;
selectedArtistName = null;
setupActionBar(selectedAlbumTitle, null, selectedGenreTitle, selectedMusicVideoTitle);
} else if (selectedGenreId != -1) {
selectedGenreId = -1;
selectedGenreTitle = null;
setupActionBar(selectedAlbumTitle, selectedArtistName, null, selectedMusicVideoTitle);
} else if (selectedMusicVideoId != -1) {
selectedMusicVideoId = -1;
selectedMusicVideoTitle = null;
setupActionBar(selectedAlbumTitle, selectedArtistName, selectedGenreTitle, null);
}
if (selectedArtistId == -1 &&
selectedGenreId == -1 &&
selectedMusicVideoId == -1) {
updateActionBar(getActionBarTitle(), false);
} else {
updateActionBar(getActionBarTitle(), true);
}
super.onBackPressed();
}
private boolean drawerIndicatorIsArrow = false;
private void setupActionBar(String albumTitle, String artistName, String genreTitle,
String musicVideoTitle) {
Toolbar toolbar = (Toolbar)findViewById(R.id.default_toolbar);
setSupportActionBar(toolbar);
ActionBar actionBar = getSupportActionBar();
if (actionBar == null) return;
actionBar.setDisplayHomeAsUpEnabled(true);
if (albumTitle != null) {
actionBar.setTitle(albumTitle);
} else if (artistName != null) {
actionBar.setTitle(artistName);
} else if (genreTitle != null) {
actionBar.setTitle(genreTitle);
} else if (musicVideoTitle != null) {
actionBar.setTitle(musicVideoTitle);
} else {
actionBar.setTitle(R.string.music);
}
if ((albumTitle != null) || (artistName != null) || (genreTitle != null) || (musicVideoTitle != null)) {
if (!drawerIndicatorIsArrow) {
navigationDrawerFragment.animateDrawerToggle(true);
drawerIndicatorIsArrow = true;
}
} else {
if (drawerIndicatorIsArrow) {
navigationDrawerFragment.animateDrawerToggle(false);
drawerIndicatorIsArrow = false;
}
}
}
@TargetApi(21)
public void onArtistSelected(ArtistListFragment.ViewHolder vh) {
selectedArtistId = vh.dataHolder.getId();
@ -252,22 +185,9 @@ public class MusicActivity extends BaseActivity
artistDetailsFragment.setDataHolder(vh.dataHolder);
vh.dataHolder.setSquarePoster(true);
FragmentTransaction fragTrans = getSupportFragmentManager().beginTransaction();
// Setup animations
if (Utils.isLollipopOrLater()) {
vh.dataHolder.setPosterTransitionName(vh.artView.getTransitionName());
sharedElementTransition.setupEnterTransition(this, fragTrans, artistDetailsFragment,
vh.artView);
} else {
fragTrans.setCustomAnimations(R.anim.fragment_details_enter, 0, R.anim.fragment_list_popenter, 0);
}
showFragment(artistDetailsFragment, vh.artView, vh.dataHolder);
fragTrans.replace(R.id.fragment_container, artistDetailsFragment)
.addToBackStack(null)
.commit();
navigationDrawerFragment.animateDrawerToggle(true);
setupActionBar(null, selectedArtistName, null, null);
updateActionBar(selectedArtistName, true);
}
@TargetApi(21)
@ -279,21 +199,10 @@ public class MusicActivity extends BaseActivity
final AbstractInfoFragment albumInfoFragment = new AlbumInfoFragment();
vh.dataHolder.setSquarePoster(true);
albumInfoFragment.setDataHolder(vh.dataHolder);
FragmentTransaction fragTrans = getSupportFragmentManager().beginTransaction();
// Set up transitions
if (Utils.isLollipopOrLater()) {
vh.dataHolder.setPosterTransitionName(vh.artView.getTransitionName());
sharedElementTransition.setupEnterTransition(this, fragTrans, albumInfoFragment, vh.artView);
} else {
fragTrans.setCustomAnimations(R.anim.fragment_details_enter, 0,
R.anim.fragment_list_popenter, 0);
}
showFragment(albumInfoFragment, vh.artView, vh.dataHolder);
fragTrans.replace(R.id.fragment_container, albumInfoFragment)
.addToBackStack(null)
.commit();
setupActionBar(selectedAlbumTitle, null, null, null);
updateActionBar(selectedAlbumTitle, true);
}
public void onAudioGenreSelected(int genreId, String genreTitle) {
@ -310,7 +219,8 @@ public class MusicActivity extends BaseActivity
.replace(R.id.fragment_container, albumListFragment)
.addToBackStack(null)
.commit();
setupActionBar(null, null, genreTitle, null);
updateActionBar(selectedGenreTitle, true);
}
@TargetApi(21)
@ -323,20 +233,8 @@ public class MusicActivity extends BaseActivity
vh.dataHolder.setSquarePoster(true);
musicVideoInfoFragment.setDataHolder(vh.dataHolder);
FragmentTransaction fragTrans = getSupportFragmentManager().beginTransaction();
showFragment(musicVideoInfoFragment, vh.artView, vh.dataHolder);
// Set up transitions
if (Utils.isLollipopOrLater()) {
vh.dataHolder.setPosterTransitionName(vh.artView.getTransitionName());
sharedElementTransition.setupEnterTransition(this, fragTrans, musicVideoInfoFragment, vh.artView);
} else {
fragTrans.setCustomAnimations(R.anim.fragment_details_enter, 0,
R.anim.fragment_list_popenter, 0);
}
fragTrans.replace(R.id.fragment_container, musicVideoInfoFragment)
.addToBackStack(null)
.commit();
setupActionBar(null, null, null, selectedMusicVideoTitle);
updateActionBar(selectedMusicVideoTitle, true);
}
}

View File

@ -15,30 +15,25 @@
*/
package org.xbmc.kore.ui.sections.file;
import android.annotation.TargetApi;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBar;
import android.support.v7.widget.Toolbar;
import android.transition.TransitionInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.Window;
import android.support.v4.app.Fragment;
import org.xbmc.kore.R;
import org.xbmc.kore.ui.BaseActivity;
import org.xbmc.kore.ui.generic.NavigationDrawerFragment;
import org.xbmc.kore.ui.BaseMediaActivity;
import org.xbmc.kore.ui.OnBackPressedListener;
import org.xbmc.kore.ui.sections.remote.RemoteActivity;
import org.xbmc.kore.utils.Utils;
/**
* Handles listing of files fragments
*/
public class FileActivity extends BaseActivity {
public class FileActivity extends BaseMediaActivity {
@Override
protected String getActionBarTitle() {
return getString(R.string.file_browser);
}
private NavigationDrawerFragment navigationDrawerFragment;
@Override
protected Fragment createFragment() {
return new FileListFragment();
}
OnBackPressedListener fragmentBackListener;
@ -46,61 +41,6 @@ public class FileActivity extends BaseActivity {
fragmentBackListener = listener;
}
@TargetApi(21)
@Override
protected void onCreate(Bundle savedInstanceState) {
// Request transitions on lollipop
if (Utils.isLollipopOrLater()) {
getWindow().requestFeature(Window.FEATURE_CONTENT_TRANSITIONS);
}
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_generic_media);
// Set up the drawer.
navigationDrawerFragment = (NavigationDrawerFragment)getSupportFragmentManager()
.findFragmentById(R.id.navigation_drawer);
navigationDrawerFragment.setUp(R.id.navigation_drawer, (DrawerLayout) findViewById(R.id.drawer_layout));
if (savedInstanceState == null) {
FileListFragment fileListFragment = new FileListFragment();
// Setup animations
if (Utils.isLollipopOrLater()) {
fileListFragment.setExitTransition(null);
fileListFragment.setReenterTransition(TransitionInflater
.from(this)
.inflateTransition(android.R.transition.fade));
}
getSupportFragmentManager()
.beginTransaction()
.add(R.id.fragment_container, fileListFragment)
.commit();
}
setupActionBar(getString(R.string.file_browser));
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.media_info, menu);
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_show_remote:
// Starts remote
Intent launchIntent = new Intent(this, RemoteActivity.class)
.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
startActivity(launchIntent);
return true;
default:
break;
}
return super.onOptionsItemSelected(item);
}
@Override
public void onBackPressed() {
// tell fragment to move up one directory
@ -111,17 +51,5 @@ public class FileActivity extends BaseActivity {
}
}
private void setupActionBar(String title) {
Toolbar toolbar = (Toolbar)findViewById(R.id.default_toolbar);
setSupportActionBar(toolbar);
ActionBar actionBar = getSupportActionBar();
if (actionBar == null) return;
actionBar.setDisplayHomeAsUpEnabled(true);
navigationDrawerFragment.setDrawerIndicatorEnabled(true);
actionBar.setTitle(title);
}
}

View File

@ -16,79 +16,45 @@
package org.xbmc.kore.ui.sections.video;
import android.annotation.TargetApi;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBar;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.view.Window;
import org.xbmc.kore.R;
import org.xbmc.kore.ui.BaseActivity;
import org.xbmc.kore.ui.generic.NavigationDrawerFragment;
import org.xbmc.kore.ui.sections.remote.RemoteActivity;
import org.xbmc.kore.ui.BaseMediaActivity;
import org.xbmc.kore.utils.LogUtils;
import org.xbmc.kore.utils.SharedElementTransition;
import org.xbmc.kore.utils.Utils;
/**
* Controls the presentation of Movies information (list, details)
* All the information is presented by specific fragments
*/
public class MoviesActivity extends BaseActivity
public class MoviesActivity extends BaseMediaActivity
implements MovieListFragment.OnMovieSelectedListener {
private static final String TAG = LogUtils.makeLogTag(MoviesActivity.class);
public static final String MOVIEID = "movie_id";
public static final String MOVIETITLE = "movie_title";
public static final String LISTFRAGMENT_TAG = "movielist";
private int selectedMovieId = -1;
private String selectedMovieTitle;
private NavigationDrawerFragment navigationDrawerFragment;
@Override
protected String getActionBarTitle() {
return (selectedMovieTitle != null) ? selectedMovieTitle : getString(R.string.movies);
}
private SharedElementTransition sharedElementTransition = new SharedElementTransition();
@Override
protected Fragment createFragment() {
return new MovieListFragment();
}
@TargetApi(21)
@Override
protected void onCreate(Bundle savedInstanceState) {
// Request transitions on lollipop
if (Utils.isLollipopOrLater()) {
getWindow().requestFeature(Window.FEATURE_CONTENT_TRANSITIONS);
}
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_generic_media);
// Set up the drawer.
navigationDrawerFragment = (NavigationDrawerFragment)getSupportFragmentManager()
.findFragmentById(R.id.navigation_drawer);
navigationDrawerFragment.setUp(R.id.navigation_drawer, (DrawerLayout) findViewById(R.id.drawer_layout));
Fragment fragment;
if (savedInstanceState == null) {
fragment = new MovieListFragment();
getSupportFragmentManager()
.beginTransaction()
.add(R.id.fragment_container, fragment, LISTFRAGMENT_TAG)
.commit();
} else {
fragment = getSupportFragmentManager().findFragmentByTag(LISTFRAGMENT_TAG);
if (savedInstanceState != null) {
selectedMovieId = savedInstanceState.getInt(MOVIEID, -1);
selectedMovieTitle = savedInstanceState.getString(MOVIETITLE, null);
}
if (Utils.isLollipopOrLater()) {
sharedElementTransition.setupExitTransition(this, fragment);
}
setupActionBar(selectedMovieTitle);
super.onCreate(savedInstanceState);
}
@Override
@ -98,24 +64,9 @@ public class MoviesActivity extends BaseActivity
outState.putString(MOVIETITLE, selectedMovieTitle);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// if (!navigationDrawerFragment.isDrawerOpen()) {
// getMenuInflater().inflate(R.menu.media_info, menu);
// }
getMenuInflater().inflate(R.menu.media_info, menu);
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_show_remote:
// Starts remote
Intent launchIntent = new Intent(this, RemoteActivity.class)
.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
startActivity(launchIntent);
return true;
case android.R.id.home:
// Only respond to this if we are showing the movie details in portrait mode,
// which can be checked by checking if selected movie != -1, in which case we
@ -123,7 +74,7 @@ public class MoviesActivity extends BaseActivity
if (selectedMovieId != -1) {
selectedMovieId = -1;
selectedMovieTitle = null;
setupActionBar(null);
updateActionBar(getActionBarTitle(), false);
getSupportFragmentManager().popBackStack();
return true;
}
@ -141,35 +92,12 @@ public class MoviesActivity extends BaseActivity
if (selectedMovieId != -1) {
selectedMovieId = -1;
selectedMovieTitle = null;
setupActionBar(null);
updateActionBar(getActionBarTitle(), false);
}
super.onBackPressed();
}
private boolean drawerIndicatorIsArrow = false;
private void setupActionBar(String movieTitle) {
Toolbar toolbar = (Toolbar)findViewById(R.id.default_toolbar);
setSupportActionBar(toolbar);
ActionBar actionBar = getSupportActionBar();
if (actionBar == null) return;
actionBar.setDisplayHomeAsUpEnabled(true);
if (movieTitle != null) {
if (!drawerIndicatorIsArrow) {
navigationDrawerFragment.animateDrawerToggle(true);
drawerIndicatorIsArrow = true;
}
actionBar.setTitle(movieTitle);
} else {
if (drawerIndicatorIsArrow) {
navigationDrawerFragment.animateDrawerToggle(false);
drawerIndicatorIsArrow = false;
}
actionBar.setTitle(R.string.movies);
}
}
/**
* Callback from movielist fragment when a movie is selected.
* Switch fragment in portrait
@ -183,21 +111,8 @@ public class MoviesActivity extends BaseActivity
final MovieInfoFragment movieInfoFragment = new MovieInfoFragment();
movieInfoFragment.setDataHolder(vh.dataHolder);
FragmentTransaction fragTrans = getSupportFragmentManager().beginTransaction();
showFragment(movieInfoFragment, vh.artView, vh.dataHolder);
// Set up transitions
if (Utils.isLollipopOrLater()) {
vh.dataHolder.setPosterTransitionName(vh.artView.getTransitionName());
sharedElementTransition.setupEnterTransition(this, fragTrans, movieInfoFragment,
vh.artView);
} else {
fragTrans.setCustomAnimations(R.anim.fragment_details_enter, 0,
R.anim.fragment_list_popenter, 0);
}
fragTrans.replace(R.id.fragment_container, movieInfoFragment)
.addToBackStack(null)
.commit();
setupActionBar(selectedMovieTitle);
updateActionBar(selectedMovieTitle, true);
}
}

View File

@ -16,21 +16,14 @@
package org.xbmc.kore.ui.sections.video;
import android.annotation.TargetApi;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBar;
import android.support.v7.widget.Toolbar;
import android.transition.TransitionInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.Window;
import org.xbmc.kore.R;
import org.xbmc.kore.ui.BaseActivity;
import org.xbmc.kore.ui.generic.NavigationDrawerFragment;
import org.xbmc.kore.ui.sections.remote.RemoteActivity;
import org.xbmc.kore.ui.BaseMediaActivity;
import org.xbmc.kore.utils.LogUtils;
import org.xbmc.kore.utils.Utils;
@ -38,7 +31,7 @@ import org.xbmc.kore.utils.Utils;
* Controls the presentation of Live TV/Radio and recordings information (list, details)
* All the information is presented by specific fragments
*/
public class PVRActivity extends BaseActivity
public class PVRActivity extends BaseMediaActivity
implements PVRChannelsListFragment.OnPVRChannelSelectedListener {
private static final String TAG = LogUtils.makeLogTag(PVRActivity.class);
@ -56,56 +49,31 @@ public class PVRActivity extends BaseActivity
private int selectedChannelGroupId = -1;
private String selectedChannelGroupTitle = null;
private NavigationDrawerFragment navigationDrawerFragment;
@Override
protected String getActionBarTitle() {
if ( selectedChannelTitle != null ) {
return selectedChannelTitle;
} else if ( selectedChannelGroupTitle != null ) {
return selectedChannelGroupTitle;
}
return getString(R.string.pvr);
}
@Override
protected Fragment createFragment() {
return new PVRListFragment();
}
@TargetApi(21)
@Override
protected void onCreate(Bundle savedInstanceState) {
// Request transitions on lollipop
if (Utils.isLollipopOrLater()) {
getWindow().requestFeature(Window.FEATURE_CONTENT_TRANSITIONS);
}
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_generic_media);
// Set up the drawer.
navigationDrawerFragment = (NavigationDrawerFragment)getSupportFragmentManager()
.findFragmentById(R.id.navigation_drawer);
navigationDrawerFragment.setUp(R.id.navigation_drawer, (DrawerLayout) findViewById(R.id.drawer_layout));
if (savedInstanceState == null) {
PVRListFragment pvrListFragment = new PVRListFragment();
// Setup animations
if (Utils.isLollipopOrLater()) {
pvrListFragment.setExitTransition(null);
pvrListFragment.setReenterTransition(TransitionInflater
.from(this)
.inflateTransition(android.R.transition.fade));
}
getSupportFragmentManager()
.beginTransaction()
.add(R.id.fragment_container, pvrListFragment, LISTFRAGMENTTAG)
.commit();
} else {
if (savedInstanceState != null) {
selectedChannelId = savedInstanceState.getInt(CHANNELID, -1);
selectedChannelTitle = savedInstanceState.getString(CHANNELTITLE, null);
selectedChannelGroupId = savedInstanceState.getInt(CHANNELGROUPID, -1);
selectedChannelGroupTitle = savedInstanceState.getString(CHANNELGROUPTITLE, null);
}
setupActionBar(selectedChannelGroupTitle, selectedChannelTitle);
}
@Override
public void onResume() {
super.onResume();
}
@Override
public void onPause() {
super.onPause();
super.onCreate(savedInstanceState);
}
@Override
@ -118,33 +86,21 @@ public class PVRActivity extends BaseActivity
outState.putString(CHANNELGROUPTITLE, selectedChannelGroupTitle);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.media_info, menu);
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_show_remote:
// Starts remote
Intent launchIntent = new Intent(this, RemoteActivity.class)
.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
startActivity(launchIntent);
return true;
case android.R.id.home:
// If showing detail view, back up to list
if (selectedChannelId != -1) {
selectedChannelId = -1;
selectedChannelTitle = null;
setupActionBar(selectedChannelGroupTitle, null);
updateActionBar(getActionBarTitle(), true);
getSupportFragmentManager().popBackStack();
return true;
} else if (selectedChannelGroupId != -1) {
selectedChannelGroupId = -1;
selectedChannelGroupTitle = null;
setupActionBar(null, null);
updateActionBar(getActionBarTitle(), false);
PVRListFragment fragment = (PVRListFragment)getSupportFragmentManager().findFragmentByTag(LISTFRAGMENTTAG);
if (fragment != null) {
@ -167,12 +123,12 @@ public class PVRActivity extends BaseActivity
if (selectedChannelId != -1) {
selectedChannelId = -1;
selectedChannelTitle = null;
setupActionBar(selectedChannelGroupTitle, null);
updateActionBar(getActionBarTitle(), true);
} else {
if (selectedChannelGroupId != -1) {
selectedChannelGroupId = -1;
selectedChannelGroupTitle = null;
setupActionBar(null, null);
updateActionBar(getActionBarTitle(), true);
}
PVRListFragment fragment = (PVRListFragment)getSupportFragmentManager().findFragmentByTag(LISTFRAGMENTTAG);
if (fragment != null) {
@ -183,31 +139,6 @@ public class PVRActivity extends BaseActivity
super.onBackPressed();
}
private boolean drawerIndicatorIsArrow = false;
private void setupActionBar(String channelGroupTitle, String channelTitle) {
Toolbar toolbar = (Toolbar)findViewById(R.id.default_toolbar);
setSupportActionBar(toolbar);
ActionBar actionBar = getSupportActionBar();
if (actionBar == null) return;
actionBar.setDisplayHomeAsUpEnabled(true);
if ((channelTitle != null) || (channelGroupTitle != null)) {
if (!drawerIndicatorIsArrow) {
navigationDrawerFragment.animateDrawerToggle(true);
drawerIndicatorIsArrow = true;
}
actionBar.setTitle(channelTitle == null? channelGroupTitle : channelTitle);
} else {
if (drawerIndicatorIsArrow) {
navigationDrawerFragment.animateDrawerToggle(false);
drawerIndicatorIsArrow = false;
}
actionBar.setTitle(R.string.pvr);
}
}
/**
* Callback from list fragment when the channel guide should be displayed.
* Setup action bar and repolace list fragment
@ -237,7 +168,7 @@ public class PVRActivity extends BaseActivity
fragTrans.replace(R.id.fragment_container, pvrEPGFragment)
.addToBackStack(null)
.commit();
setupActionBar(selectedChannelGroupTitle, selectedChannelTitle);
updateActionBar(getActionBarTitle(), true);
}
/**
@ -250,6 +181,6 @@ public class PVRActivity extends BaseActivity
selectedChannelGroupId = channelGroupId;
selectedChannelGroupTitle = channelGroupTitle;
setupActionBar(selectedChannelGroupTitle, selectedChannelTitle);
updateActionBar(getActionBarTitle(), true);
}
}

View File

@ -16,32 +16,24 @@
package org.xbmc.kore.ui.sections.video;
import android.annotation.TargetApi;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBar;
import android.support.v7.widget.Toolbar;
import android.transition.TransitionInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.Window;
import org.xbmc.kore.R;
import org.xbmc.kore.ui.AbstractFragment;
import org.xbmc.kore.ui.AbstractInfoFragment;
import org.xbmc.kore.ui.BaseActivity;
import org.xbmc.kore.ui.generic.NavigationDrawerFragment;
import org.xbmc.kore.ui.sections.remote.RemoteActivity;
import org.xbmc.kore.ui.BaseMediaActivity;
import org.xbmc.kore.utils.LogUtils;
import org.xbmc.kore.utils.SharedElementTransition;
import org.xbmc.kore.utils.Utils;
/**
* Controls the presentation of TV Shows information (list, details)
* All the information is presented by specific fragments
*/
public class TVShowsActivity extends BaseActivity
public class TVShowsActivity extends BaseMediaActivity
implements TVShowListFragment.OnTVShowSelectedListener,
TVShowProgressFragment.TVShowProgressActionListener,
TVShowEpisodeListFragment.OnEpisodeSelectedListener {
@ -52,7 +44,6 @@ public class TVShowsActivity extends BaseActivity
public static final String EPISODEID = "episode_id";
public static final String SEASON = "season";
public static final String SEASONTITLE = "season_title";
public static final String LISTFRAGMENT_TAG = "tvshowlist";
private int selectedTVShowId = -1;
private String selectedTVShowTitle = null;
@ -60,53 +51,28 @@ public class TVShowsActivity extends BaseActivity
private String selectedSeasonTitle = null;
private int selectedEpisodeId = -1;
private SharedElementTransition sharedElementTransition = new SharedElementTransition();
@Override
protected String getActionBarTitle() {
return (selectedSeasonTitle != null) ? selectedSeasonTitle :
(selectedTVShowTitle != null) ? selectedTVShowTitle : getString(R.string.tv_shows);
}
private NavigationDrawerFragment navigationDrawerFragment;
@Override
protected Fragment createFragment() {
return new TVShowListFragment();
}
@TargetApi(21)
@Override
protected void onCreate(Bundle savedInstanceState) {
// Request transitions on lollipop
if (Utils.isLollipopOrLater()) {
getWindow().requestFeature(Window.FEATURE_CONTENT_TRANSITIONS);
}
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_generic_media);
// Set up the drawer.
navigationDrawerFragment = (NavigationDrawerFragment) getSupportFragmentManager()
.findFragmentById(R.id.navigation_drawer);
navigationDrawerFragment.setUp(R.id.navigation_drawer, (DrawerLayout) findViewById(R.id.drawer_layout));
Fragment fragment;
if (savedInstanceState == null) {
fragment = new TVShowListFragment();
getSupportFragmentManager()
.beginTransaction()
.add(R.id.fragment_container, fragment, LISTFRAGMENT_TAG)
.commit();
} else {
fragment = getSupportFragmentManager().findFragmentByTag(LISTFRAGMENT_TAG);
if (savedInstanceState != null) {
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);
}
if (Utils.isLollipopOrLater()) {
sharedElementTransition.setupExitTransition(this, fragment);
}
setupActionBar(selectedTVShowTitle);
// // Setup system bars and content padding, allowing averlap with the bottom bar
// setupSystemBarsColors();
// UIUtils.setPaddingForSystemBars(this, findViewById(R.id.fragment_container), true, true, true);
// UIUtils.setPaddingForSystemBars(this, findViewById(R.id.drawer_layout), true, true, true);
super.onCreate(savedInstanceState);
}
@Override
@ -119,50 +85,15 @@ public class TVShowsActivity extends BaseActivity
outState.putString(SEASONTITLE, selectedSeasonTitle);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// if (!navigationDrawerFragment.isDrawerOpen()) {
// getMenuInflater().inflate(R.menu.media_info, menu);
// }
getMenuInflater().inflate(R.menu.media_info, menu);
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_show_remote:
// Starts remote
Intent launchIntent = new Intent(this, RemoteActivity.class)
.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
startActivity(launchIntent);
return true;
case android.R.id.home:
// Only respond to this if we are showing the episodeor show details in portrait
// mode, which can be checked by checking if selected movie != -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)
if (selectedEpisodeId != -1) {
selectedEpisodeId = -1;
getSupportFragmentManager().popBackStack();
if (selectedSeason != -1)
setupActionBar(selectedSeasonTitle);
else
setupActionBar(selectedTVShowTitle);
return true;
} else if (selectedSeason != -1) {
selectedSeason = -1;
getSupportFragmentManager().popBackStack();
setupActionBar(selectedTVShowTitle);
return true;
} else if (selectedTVShowId != -1) {
selectedTVShowId = -1;
selectedTVShowTitle = null;
setupActionBar(null);
if (getDrawerIndicatorIsArrow()) {
getSupportFragmentManager().popBackStack();
updateActionBar();
return true;
}
break;
default:
break;
}
@ -172,47 +103,10 @@ public class TVShowsActivity extends BaseActivity
@Override
public void onBackPressed() {
// If we are showing episode or show details in portrait, clear selected and show action bar
if (selectedEpisodeId != -1) {
selectedEpisodeId = -1;
if (selectedSeason != -1)
setupActionBar(selectedSeasonTitle);
else
setupActionBar(selectedTVShowTitle);
} else if (selectedSeason != -1) {
selectedSeason = -1;
setupActionBar(selectedTVShowTitle);
} else if (selectedTVShowId != -1) {
selectedTVShowId = -1;
selectedTVShowTitle = null;
setupActionBar(null);
}
updateActionBar();
super.onBackPressed();
}
private boolean drawerIndicatorIsArrow = false;
private void setupActionBar(String title) {
Toolbar toolbar = (Toolbar)findViewById(R.id.default_toolbar);
setSupportActionBar(toolbar);
ActionBar actionBar = getSupportActionBar();
if (actionBar == null) return;
actionBar.setDisplayHomeAsUpEnabled(true);
if (title != null) {
if (!drawerIndicatorIsArrow) {
navigationDrawerFragment.animateDrawerToggle(true);
drawerIndicatorIsArrow = true;
}
actionBar.setTitle(title);
} else {
if (drawerIndicatorIsArrow) {
navigationDrawerFragment.animateDrawerToggle(false);
drawerIndicatorIsArrow = false;
}
actionBar.setTitle(R.string.tv_shows);
}
}
/**
* Callback from tvshows list fragment when a show is selected.
* Switch fragment in portrait
@ -226,21 +120,8 @@ public class TVShowsActivity extends BaseActivity
// Replace list fragment
final TVShowInfoFragment tvshowDetailsFragment = new TVShowInfoFragment();
tvshowDetailsFragment.setDataHolder(vh.dataHolder);
FragmentTransaction fragTrans = getSupportFragmentManager().beginTransaction();
// Set up transitions
if (Utils.isLollipopOrLater()) {
vh.dataHolder.setPosterTransitionName(vh.artView.getTransitionName());
sharedElementTransition.setupEnterTransition(this, fragTrans, tvshowDetailsFragment, vh.artView);
} else {
fragTrans.setCustomAnimations(R.anim.fragment_details_enter, 0, R.anim.fragment_list_popenter, 0);
}
fragTrans.replace(R.id.fragment_container, tvshowDetailsFragment)
.addToBackStack(null)
.commit();
setupActionBar(selectedTVShowTitle);
showFragment(tvshowDetailsFragment, vh.artView, vh.dataHolder);
updateActionBar(selectedTVShowTitle, true);
}
/**
@ -261,7 +142,7 @@ public class TVShowsActivity extends BaseActivity
.addToBackStack(null)
.commit();
selectedSeasonTitle = String.format(getString(R.string.season_number), seasonId);
setupActionBar(selectedSeasonTitle);
updateActionBar(selectedSeasonTitle, true);
}
/**
@ -276,21 +157,8 @@ public class TVShowsActivity extends BaseActivity
TVShowEpisodeInfoFragment fragment = new TVShowEpisodeInfoFragment();
fragment.setDataHolder(dh);
fragment.setTvshowId(tvshowId);
FragmentTransaction fragTrans = getSupportFragmentManager().beginTransaction();
// Set up transitions
if (Utils.isLollipopOrLater()) {
fragment.setEnterTransition(
TransitionInflater.from(this).inflateTransition(R.transition.media_details));
fragment.setReturnTransition(null);
} else {
fragTrans.setCustomAnimations(R.anim.fragment_details_enter, 0, R.anim.fragment_list_popenter, 0);
}
fragTrans.replace(R.id.fragment_container, fragment)
.addToBackStack(null)
.commit();
setupActionBar(selectedTVShowTitle);
startFragment(fragment);
updateActionBar(selectedTVShowTitle, true);
}
/**
@ -300,11 +168,16 @@ public class TVShowsActivity extends BaseActivity
public void onEpisodeSelected(int tvshowId,
TVShowEpisodeListFragment.ViewHolder viewHolder) {
selectedEpisodeId = viewHolder.dataHolder.getId();
// Replace list fragment
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
FragmentTransaction fragTrans = getSupportFragmentManager().beginTransaction();
// Set up transitions
@ -319,6 +192,24 @@ public class TVShowsActivity extends BaseActivity
fragTrans.replace(R.id.fragment_container, fragment)
.addToBackStack(null)
.commit();
setupActionBar(selectedTVShowTitle);
}
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);
}
}
}