fix fragment exception launching after dict download

create queue of Runnables to be run only when Delegate is
visible (onResume() has been called and onPause() hasn't.)  When
missing dict finishes downloading, rather than immediately opening its
game, post a Runnable to do it that will be run only after the main
activity is ready to have fragment transactions committing again.
This commit is contained in:
Eric House 2016-07-20 08:58:34 -07:00
parent d3bd8047b1
commit 5b4e04bc5a
2 changed files with 20 additions and 1 deletions

View file

@ -38,6 +38,7 @@ import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.TextView;
import java.util.ArrayList;
import org.eehouse.android.xw4.DlgDelegate.Action;
import org.eehouse.android.xw4.DlgDelegate.ActionPair;
@ -58,6 +59,7 @@ public class DelegateBase implements DlgClickNotify,
private int m_layoutID;
private View m_rootView;
private boolean m_isVisible;
private ArrayList<Runnable> m_visibleProcs = new ArrayList<Runnable>();
public DelegateBase( Delegator delegator, Bundle bundle, int layoutID )
{
@ -116,6 +118,7 @@ public class DelegateBase implements DlgClickNotify,
{
m_isVisible = true;
XWService.setListener( this );
runIfVisible();
}
protected void onPause()
@ -274,6 +277,16 @@ public class DelegateBase implements DlgClickNotify,
return result;
}
private void runIfVisible()
{
if ( isVisible() ) {
for ( Runnable proc : m_visibleProcs ) {
post( proc );
}
m_visibleProcs.clear();
}
}
protected String getString( int resID, Object... params )
{
return LocUtils.getString( m_activity, resID, params );
@ -601,6 +614,12 @@ public class DelegateBase implements DlgClickNotify,
return false; // not handled
}
protected void runWhenActive( Runnable proc )
{
m_visibleProcs.add( proc );
runIfVisible();
}
//////////////////////////////////////////////////
// MultiService.MultiEventListener interface
//////////////////////////////////////////////////

View file

@ -1595,7 +1595,7 @@ public class GamesListDelegate extends ListDelegateBase
public void downloadFinished( String lang, String name,
final boolean success )
{
post( new Runnable() {
runWhenActive( new Runnable() {
public void run() {
boolean madeGame = false;
if ( success ) {