DMCApps / NavigationFragment

The purpose of this manager is to work with the ViewPager, Tabs and Navigation drawer to handle a single stack flow of fragments on the screen. It makes use of a main Fragment as a container and presents and hides fragments within it as children.
MIT License
28 stars 8 forks source link

api or callback for the feature. #15

Closed jjhesk closed 8 years ago

jjhesk commented 8 years ago

what is callback or api for retrieve the previous fragment title? in case im using it for custom api for renaming the actionbar for the custom actionbar. I hope that there is a listen callback from SingleStackNavigationManagerFragment

DMCApps commented 8 years ago

There is no way to get the previous fragments title. There is only a setTitle method on the NavigationFragment. This is by design, I do not save the set title anywhere, it is just used on the ActionBar at the time of setting.

There is a way to get a fragment at a specific position in the stack though. You could then add a property yourself to save the title and then retrieve it from your specific fragment. This is a mock class to save the title (untested, just a thought of how to do it). You can then extend this class instead of NavigationFragment in your implementations

public class SavedTitleNavigationFragment extends NavigationFragment {

    private String mTitle;

    @Override
    public void setTitle(String title) {
        super.setTitle(title);
        mTitle = title;
    }

    public String getTitle() {
        return mTitle;
     }
}

Next when you want to get the title you can call the following from within your NavigationFragment

    /**
     * Access the fragment at the given index of the navigation stack.
     *
     * @return
     *      {@link INavigationFragment} that is on the top of the stack.
     */
    SavedTitleNavigationFragment titleFrag = (SavedTitleNavigationFragment)getNavigationManager().getFragmentAtIndex(/* Index of your fragment in the stack starting at 0 (Root Fragment) */);
titleFrag.getTitle();

Please let me know if this is helpful. There are no plans to add this to the navigation manager as a requirement because the NavigationFragment has no reason to save the title. Much like the ActionBar inner works, you need to set it every time you go to the page, hence the manager works much the same way.

jjhesk commented 8 years ago

ok. thats fair to keep it simple. I vote for this one. In my final solution I have take this whole thing in my custom tool bar that will able to record the history of all the titles.

DMCApps commented 8 years ago

Hey jjhesk,

I have actually added the getTitle() method on the NavigationFragment. It now saves the title given using setTitle(int resId) or setTitle(String title). I realize now that it is a great method to have when dealing with a ViewPager to get the top navigation fragment and get it's title on page change such that we can manage the title from the activity.

There are a few other changes to version 0.2.0.2. Please see the ReadMe. One of which is that setNavigationManager() is no longer needed. The manager will now look up the stack of parents until it finds a NavigationManagerFragment to use.