Giter VIP home page Giter VIP logo

Comments (18)

madcyph3r avatar madcyph3r commented on August 17, 2024
  1. This is not possible now. But it's on the todo list.
  2. I will add an option for this.
    For now make it like this:
        MaterialSection section = this.newSection("Master 1", new MasterFragment(), false, menu);
        section.setOnClickListener(new MaterialSectionOnClickListener() {
            @Override
            public void onClick(MaterialSection section, View v) {
                drawer.onClick(section, v); // call the default onClick function
                drawer.closeDrawer(); // close the drawer
            }
        });
  1. I added the new example under functionally. The newest version isn't online in the play store for now.

from advancedmaterialdrawer.

thevirus20 avatar thevirus20 commented on August 17, 2024

Hi,
Converted all the activities to fragment now but got another issue.
I am using SlidingTabs in first section with BACKPATTERN_BACK_TO_START_INDEX as BACKPATTERN, but when I press back from another section Fragment is not visible I get just tabs or some times both are gone blank screen comes.

What could be the cause?

from advancedmaterialdrawer.

madcyph3r avatar madcyph3r commented on August 17, 2024

I have no idea. I replace only the fragment. Maybe SlidingTabs saves some states, and there the problem comes from.

But it works right, if you press the section again and not the back button?

from advancedmaterialdrawer.

thevirus20 avatar thevirus20 commented on August 17, 2024

No, Section 1 loads tabs, then going to section 2 loads OK, clicking section 1 again everything blank.clicking section2 also blanks.

Even your fragmentintruction,dummyfragment are also gone in this process, so I dont think this is the issue with Slidingtabs(I mean one section loads cardview with dummyFrament, this also becomes blank, only card visible after navigating.)

So now After so much work in converting activities to fragment, I am stuck again , will need to be stick with new intent again?
Any better suggestion.

from advancedmaterialdrawer.

madcyph3r avatar madcyph3r commented on August 17, 2024

Post the link to the library. I will see what i can do.

from advancedmaterialdrawer.

thevirus20 avatar thevirus20 commented on August 17, 2024

I tried using these two libraries.

https://github.com/jpardogo/PagerSlidingTabStrip
https://github.com/neokree/MaterialTabs

I have first section1 using neokree tabs and going back to section1 from other section makes it blank sometimes even tabs are also gone.

package test;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import it.neokree.materialtabs.MaterialTab;
import it.neokree.materialtabs.MaterialTabHost;
import it.neokree.materialtabs.MaterialTabListener;


public class FragmentSectionTestTabs extends Fragment implements MaterialTabListener{

    MaterialTabHost tabHost;
    ViewPager pager;
    ViewPagerAdapter adapter;

    private String[] tabs = { "tab1", "tab2" };

    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.test,container, false);

        tabHost = (MaterialTabHost) view.findViewById(R.id.tabHost);
        pager = (ViewPager) view.findViewById(R.id.pager);

        // init view pager
        adapter = new ViewPagerAdapter(getFragmentManager());
        pager.setAdapter(adapter);
        pager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
            @Override
            public void onPageSelected(int position) {
                // when user do a swipe the selected tab change
                tabHost.setSelectedNavigationItem(position);

            }
        });

        // insert all tabs from pagerAdapter data
        for (int i = 0; i < adapter.getCount(); i++) {
            tabHost.addTab(
                    tabHost.newTab()
                            .setText(adapter.getPageTitle(i))
                            .setTabListener(this)
            );

        }
        return view;

    }

    @Override
    public void onTabSelected(MaterialTab tab) {
        pager.setCurrentItem(tab.getPosition());
    }

    @Override
    public void onTabReselected(MaterialTab tab) {

    }

    @Override
    public void onTabUnselected(MaterialTab tab) {

    }

    private class ViewPagerAdapter extends FragmentStatePagerAdapter {

        public ViewPagerAdapter(FragmentManager fm) {
            super(fm);

        }

        public Fragment getItem(int index) {
            return new FragmentInstruction();
        }

        @Override
        public int getCount() {
            return 2;
        }

        @Override
        public CharSequence getPageTitle(int position) {
            return tabs[position];
        }

    }
}

test layout is same as neokree texttab layout except toolbar is removed from there.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <it.neokree.materialtabs.MaterialTabHost
        android:id="@+id/tabHost"
        android:layout_width="match_parent"
        android:layout_height="48dp"
        app:materialTabsPrimaryColor="#009688"
        app:accentColor="#ffc400"/>

    <android.support.v4.view.ViewPager
        android:id="@+id/pager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/tabHost" />

</RelativeLayout>

Please check thanks.

from advancedmaterialdrawer.

madcyph3r avatar madcyph3r commented on August 17, 2024

Sorry for the late response, i think i can test it tomorrow.

from advancedmaterialdrawer.

thevirus20 avatar thevirus20 commented on August 17, 2024

Thats OK., though I have completed my App but ran into new problem when using sliding menu.
I raised a issue there but got the solution to comment a method is SlidingMenu class.
Meanwhile I tried manipulating your lib because the issue I was getting, was related to custom fragment and If I replaced a fragment(using your section) then there was no issue.

So I came up with a solution that we can have a ghost section not visible in drawer and we can trigger its onClick like we do in jQuery using performClick() method available with View.

Anyway, but I think you should have a method in your lib to check if drawer is open or not.

public boolean isDrawerOpen(){
        return drawerLayout.isDrawerOpen(drawerViewGroup);
}

And yes, thanks for your time looking at bug related to SlidingTabs.
Thanks.

from advancedmaterialdrawer.

madcyph3r avatar madcyph3r commented on August 17, 2024

Thank you, I will add add a isDrawerOpen and isDrawerClose method.

from advancedmaterialdrawer.

tamsir avatar tamsir commented on August 17, 2024

Nice library madcyph3r.
I have a problem with the back button.
In my fragment a have this code

                FragmentTransaction t = fragment.getSupportFragmentManager().beginTransaction();
                FragmentDetailBoc detailBul = FragmentDetailBoc.newInstance(bulletins.get(getPosition()).getId());
                t.replace(R.id.conteneur, detailBul);
                t.addToBackStack(String.valueOf(FragmentCommuniques.newInstance()));
                t.commit();

And In the Main Activity I have

this.setBackPattern(MaterialNavigationDrawer.BACKPATTERN_LAST_SECTION);

to handle the back button.
But when I'm in FragmentDetailBoc and I click the back button I go to another fragment not in FragmentCommuniques.
Do you any idea for this problem?
Thanks.

from advancedmaterialdrawer.

thevirus20 avatar thevirus20 commented on August 17, 2024

The issue with SlidingTabs is actually with ViewPager restoring fragment.
So here is the solution.

//instead of
adapter = new ViewPagerAdapter(getFragmentManager());
//use
adapter = new ViewPagerAdapter(getChildFragmentManager()); 

and in your FragmentStatePagerAdapter override this method.

    @Override
    public void restoreState(Parcelable state, ClassLoader loader) {
        // just overiding this will take care of the rest.
       // no need to call super class method
    }

Thanks for your time though.
BTW, you completely skipped neokree's implemetation for master child navigation.
I need to add few method from there to make it work with onBackPressed also.
Anyway,
Thanks for everything you did.
Bye.

from advancedmaterialdrawer.

madcyph3r avatar madcyph3r commented on August 17, 2024

Yeah, i have forked it before. So it does not have the same methods for this kind of navigation.
Can i add your solution to the wiki with your credits?

from advancedmaterialdrawer.

thevirus20 avatar thevirus20 commented on August 17, 2024

Yes, of course.
And I made your example app to work with Master Child Navigation as Neokree does.(Will post those changes if you want, though not tested with custom fragment.and in multipane mode,hamburger is not shown, not even in his example.)
BTW I need to clear one more thing.
When you replace a fragment with new one, old one is removed. On back pressed,old one is recreated(and I assume that its not resumed but recreated, correct me if wrong) and Fragment Docs says that resuming a fragment will also start from onCreateView(). I am using volley lib to fetch data using server API call, so when fragment is recreated API is called again.
So my question is, is there a way to stop this?So that when i press back button, fragment should be visible(as it was before replacing) but should not call onCreateView again.

I am just asking what will happen if we just show,hide fragment. Is there something to deal with memory then?
What I mean is for BACKPATTERN_BACK_TO_START_INDEX we can check for its position and if it is startIndex(say 0) then just hide it and show other fragment(say 1) and then when user clicks on section 2, fragment 1 should be removed but fragment 0 should be hidden and after back pressed current fragment is removed and fragment 0 should be visible without call to onCreteView().
Your Thought on this?Effect on memory?

from advancedmaterialdrawer.

madcyph3r avatar madcyph3r commented on August 17, 2024

You can override the onBackPressed() mehtod and set a boolean for back pressed. If this boolean true, you doesn't run your code.

Like this:

    // In your activity
    private boolean loadSectionBackClick = false;    

    @Override
    public void onBackPressed() {
       loadSectionBackClick = true;
       super.onBackPressed(); // to start the choosen backpattern
   }

   // getter and setter
   public boolean isLoadSectionBackClick () {
       return loadSectionBackClick;
   }

  public void setLoadSectionBackClick (boolean loadSectionBackClick) {
       this.loadSectionBackClick = loadSectionBackClick;
   }

// your fragment:
      public void onCreateView(...) {
          boolean loadSectionBackClick = ((YourActivity) getActivity()).isLoadSectionBackClick();
          if(!loadSectionBackClick) {
               // your code for onCreateView 
          } else {
               ((YourActivity) getActivity()).setLoadSectionBackClick(false);
          }
      }

from advancedmaterialdrawer.

madcyph3r avatar madcyph3r commented on August 17, 2024

Can you post the changes for the master child navigation?

from advancedmaterialdrawer.

thevirus20 avatar thevirus20 commented on August 17, 2024

Sorry not checked before, sure will do it.
Should I paste here changes/ or complete java file?

from advancedmaterialdrawer.

thevirus20 avatar thevirus20 commented on August 17, 2024

Created a gist for you.

https://gist.github.com/thevirus20/755d255d6ee92d08b943

Changes done(As I saved this for myself so that after you update something I can make this changes for my project, no hard engineering just simple note for myself):

  • added isDrawerOpen()
  • added setCustomFragment(Fragment fragment, String title, MaterialSection section)
  • added 3 new var - Line 152
  • initialized them in initGlobalVars() - Line 282
  • added listener toolbarToggleListener
  • modified ActionBarDrawerToggle constructor with toolbar
  • added setToolbarNavigationClickListener in contructor
  • in loadmenuandFagment() added current fragment and title to child stack - line no 677
  • added afterFragmentSetted()
  • added setFragmentChild(Fragment fragment,String title)
  • added setFragment(Fragment fragment, String title, Fragment oldFragment)
  • added syncSectionsState()
  • added call to afterFragmentSetted in onCLick of section
  • added call to syncSectionsState
  • added closeDrawer() in else of section onClick
  • added else part for childfragment onBackPressed()
  • added check for close drawer onBackPressed
  • added setHomeAsUpIndicator(int) and setHomeAsUpIndicator(drawable)
  • uncommented allowArrowAnimation()
  • menu.clear() added in onPrepareOptionsMenu()
  • modified onOptionsItemSelected()
  • added if(actionBarToggle != null) in showActionBarMenuIcon()

One thing I found that, if using toolbar in actionBarToggle constructor, then your showActionBarMenuIcon() doesn't work , thats why added method setHomeAsUpIndicator(int).

Hope you can use it in your lib as base for this type of navigation.
Thanks.

from advancedmaterialdrawer.

thevirus20 avatar thevirus20 commented on August 17, 2024

Example Activity also updated on gist.

from advancedmaterialdrawer.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.