Kore/app/src/main/java/org/xbmc/kore/ui/AbstractFragment.java

185 lines
5.4 KiB
Java
Raw Normal View History

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
/*
* 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.os.Bundle;
import androidx.annotation.Nullable;
import androidx.fragment.app.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
public class AbstractFragment extends Fragment {
private DataHolder dataHolder;
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 setDataHolder(DataHolder dataHolder) {
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
this.dataHolder = dataHolder;
Bundle bundle = getArguments();
if (bundle == null) {
setArguments(dataHolder.getBundle());
} else {
bundle.putAll(dataHolder.getBundle());
}
}
public DataHolder getDataHolder() {
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
return dataHolder;
}
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if( this.dataHolder == null ) {
this.dataHolder = new DataHolder(-1);
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
}
this.dataHolder.setBundle(getArguments());
}
public static class DataHolder {
static final String POSTER_TRANS_NAME = "POSTER_TRANS_NAME";
static final String BUNDLE_KEY_ID = "id";
static final String BUNDLE_KEY_TITLE = "title";
static final String BUNDLE_KEY_UNDERTITLE = "undertitle";
static final String BUNDLE_KEY_DESCRIPTION = "description";
static final String BUNDLE_KEY_DETAILS = "details";
static final String BUNDLE_KEY_POSTERURL = "poster";
static final String BUNDLE_KEY_FANARTURL = "fanart";
static final String BUNDLE_KEY_SQUAREPOSTER = "squareposter";
static final String BUNDLE_KEY_RATING = "rating";
static final String BUNDLE_KEY_MAXRATING = "maxrating";
static final String BUNDLE_KEY_VOTES = "votes";
private Bundle bundle;
private DataHolder() {}
public DataHolder(Bundle bundle) {
setBundle(bundle);
}
public DataHolder(int itemId) {
bundle = new Bundle();
bundle.putInt(BUNDLE_KEY_ID, itemId);
}
public void setBundle(Bundle bundle) {
this.bundle = bundle;
}
public void setPosterTransitionName(String posterTransitionName) {
bundle.putString(POSTER_TRANS_NAME, posterTransitionName);
}
public void setSquarePoster(boolean squarePoster) {
bundle.putBoolean(BUNDLE_KEY_SQUAREPOSTER, squarePoster);
}
public void setRating(double rating) {
bundle.putDouble(BUNDLE_KEY_RATING, rating);
}
public void setMaxRating(int maxRating) {
bundle.putInt(BUNDLE_KEY_MAXRATING, maxRating);
}
public void setVotes(int votes) {
bundle.putInt(BUNDLE_KEY_VOTES, votes);
}
public void setPosterUrl(String posterUrl) {
bundle.putString(BUNDLE_KEY_POSTERURL, posterUrl);
}
public void setTitle(String title) {
bundle.putString(BUNDLE_KEY_TITLE, title);
}
public void setUndertitle(String underTitle) {
bundle.putString(BUNDLE_KEY_UNDERTITLE, underTitle);
}
public void setDescription(String description) {
bundle.putString(BUNDLE_KEY_DESCRIPTION, description);
}
public void setDetails(String details) {
bundle.putString(BUNDLE_KEY_DETAILS, details);
}
public void setFanArtUrl(String fanArtUrl) {
bundle.putString(BUNDLE_KEY_FANARTURL, fanArtUrl);
}
public void setId(int id) {
bundle.putInt(BUNDLE_KEY_ID, id);
}
public String getPosterTransitionName() {
return bundle.getString(POSTER_TRANS_NAME);
}
public boolean getSquarePoster() {
return bundle.getBoolean(BUNDLE_KEY_SQUAREPOSTER);
}
public double getRating() {
return bundle.getDouble(BUNDLE_KEY_RATING);
}
public int getMaxRating() {
return bundle.getInt(BUNDLE_KEY_MAXRATING);
}
public int getVotes() {
return bundle.getInt(BUNDLE_KEY_VOTES);
}
public String getPosterUrl() {
return bundle.getString(BUNDLE_KEY_POSTERURL);
}
public String getTitle() {
return bundle.getString(BUNDLE_KEY_TITLE);
}
public String getUnderTitle() {
return bundle.getString(BUNDLE_KEY_UNDERTITLE);
}
public String getDescription() {
return bundle.getString(BUNDLE_KEY_DESCRIPTION);
}
public String getDetails() {
return bundle.getString(BUNDLE_KEY_DETAILS);
}
public String getFanArtUrl() {
return bundle.getString(BUNDLE_KEY_FANARTURL);
}
public int getId() {
return bundle.getInt(BUNDLE_KEY_ID);
}
public Bundle getBundle() {
return bundle;
}
}
}