save commit id in fragment

This commit is contained in:
Eric House 2017-08-29 07:03:52 -07:00
parent 270df00692
commit bb4c5502c8
2 changed files with 9 additions and 4 deletions

View file

@ -453,14 +453,14 @@ public class MainActivity extends XWActivity
return frag; return frag;
} }
private void addFragmentImpl( Fragment fragment, Bundle bundle, private void addFragmentImpl( XWFragment fragment, Bundle bundle,
String parentName ) String parentName )
{ {
fragment.setArguments( bundle ); fragment.setArguments( bundle );
addFragmentImpl( fragment, parentName ); addFragmentImpl( fragment, parentName );
} }
private void addFragmentImpl( final Fragment fragment, private void addFragmentImpl( final XWFragment fragment,
final String parentName ) final String parentName )
{ {
if ( m_safeToCommit ) { if ( m_safeToCommit ) {
@ -497,7 +497,7 @@ public class MainActivity extends XWActivity
} }
} }
private void safeAddFragment( Fragment fragment, String parentName ) private void safeAddFragment( XWFragment fragment, String parentName )
{ {
Assert.assertTrue( m_safeToCommit ); Assert.assertTrue( m_safeToCommit );
String newName = fragment.getClass().getSimpleName(); String newName = fragment.getClass().getSimpleName();
@ -505,10 +505,11 @@ public class MainActivity extends XWActivity
popUnneeded( fm, newName, parentName ); popUnneeded( fm, newName, parentName );
fm.beginTransaction() int ID = fm.beginTransaction()
.add( R.id.main_container, fragment, newName ) .add( R.id.main_container, fragment, newName )
.addToBackStack( newName ) .addToBackStack( newName )
.commit(); .commit();
fragment.setCommitID( ID );
// Don't do this. It causes an exception if e.g. from fragment.start() // Don't do this. It causes an exception if e.g. from fragment.start()
// I wind up launching another fragment and calling into this code // I wind up launching another fragment and calling into this code
// again. If I need executePendingTransactions() I'm doing something // again. If I need executePendingTransactions() I'm doing something

View file

@ -45,6 +45,7 @@ abstract class XWFragment extends Fragment implements Delegator {
private DelegateBase m_dlgt; private DelegateBase m_dlgt;
private String m_parentName; private String m_parentName;
private boolean m_hasOptionsMenu = false; private boolean m_hasOptionsMenu = false;
private int m_commitID;
private static Set<XWFragment> sActiveFrags = new HashSet<XWFragment>(); private static Set<XWFragment> sActiveFrags = new HashSet<XWFragment>();
public static XWFragment findOwnsView( View view ) public static XWFragment findOwnsView( View view )
@ -75,6 +76,9 @@ abstract class XWFragment extends Fragment implements Delegator {
return m_parentName; return m_parentName;
} }
public void setCommitID( int id ) { m_commitID = id; }
public int getCommitID() { return m_commitID; }
protected void onCreate( DelegateBase dlgt, Bundle sis, boolean hasOptionsMenu ) protected void onCreate( DelegateBase dlgt, Bundle sis, boolean hasOptionsMenu )
{ {
m_hasOptionsMenu = hasOptionsMenu; m_hasOptionsMenu = hasOptionsMenu;