make FirstRunDialog a DialogFragment

It was disappearing when the device rotated. Using the same
XWDialogFragment mechanism as everything else fixes that.
This commit is contained in:
Eric House 2017-05-25 19:56:12 -07:00
parent b6665a15c4
commit 7164ab92f6
3 changed files with 38 additions and 23 deletions

View file

@ -19,6 +19,7 @@
package org.eehouse.android.xw4; package org.eehouse.android.xw4;
import android.app.AlertDialog;
import android.app.Dialog; import android.app.Dialog;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface.OnClickListener; import android.content.DialogInterface.OnClickListener;
@ -47,8 +48,8 @@ public class AboutAlert extends XWDialogFragment {
@Override @Override
public Dialog onCreateDialog( Bundle sis ) public Dialog onCreateDialog( Bundle sis )
{ {
final Context context = getActivity(); Context context = getActivity();
final View view = LocUtils.inflate( context, R.layout.about_dlg ); View view = LocUtils.inflate( context, R.layout.about_dlg );
TextView vers = (TextView)view.findViewById( R.id.version_string ); TextView vers = (TextView)view.findViewById( R.id.version_string );
DateFormat df = DateFormat.getDateTimeInstance( DateFormat.FULL, DateFormat df = DateFormat.getDateTimeInstance( DateFormat.FULL,
@ -67,21 +68,23 @@ public class AboutAlert extends XWDialogFragment {
xlator.setVisibility( View.GONE ); xlator.setVisibility( View.GONE );
} }
return LocUtils.makeAlertBuilder( context ) AlertDialog.Builder builder = LocUtils.makeAlertBuilder( context )
.setIcon( R.drawable.icon48x48 ) .setIcon( R.drawable.icon48x48 )
.setTitle( R.string.app_name ) .setTitle( R.string.app_name )
.setView( view ) .setView( view )
.setNegativeButton( R.string.changes_button, .setPositiveButton( android.R.string.ok, null );
new OnClickListener() {
if ( context instanceof XWActivity ) {
final XWActivity activity = (XWActivity)context;
builder.setNegativeButton( R.string.changes_button, new OnClickListener() {
@Override @Override
public void onClick( DialogInterface dlg, public void onClick( DialogInterface dlg, int which ) {
int which ) activity.show( FirstRunDialog.newInstance() );
{
FirstRunDialog.show( context );
} }
} ) } );
.setPositiveButton( android.R.string.ok, null ) }
.create();
return builder.create();
} }
@Override @Override

View file

@ -20,8 +20,9 @@
package org.eehouse.android.xw4; package org.eehouse.android.xw4;
import android.app.AlertDialog; import android.app.Dialog;
import android.content.Context; import android.content.Context;
import android.os.Bundle;
import android.webkit.WebView; import android.webkit.WebView;
import android.webkit.WebViewClient; import android.webkit.WebViewClient;
@ -31,14 +32,23 @@ import org.eehouse.android.xw4.loc.LocUtils;
* similar feature in OpenSudoku, to whose author "Thanks". * similar feature in OpenSudoku, to whose author "Thanks".
*/ */
public class FirstRunDialog { public class FirstRunDialog extends XWDialogFragment {
public static void show( final Context context ) private static final String TAG = FirstRunDialog.class.getSimpleName();
public static FirstRunDialog newInstance()
{ {
final boolean showSurvey = !Utils.onFirstVersion( context ); return new FirstRunDialog();
}
@Override
public Dialog onCreateDialog( Bundle sis )
{
final Context context = getActivity();
// boolean showSurvey = !Utils.onFirstVersion( context );
// This won't support e.g mailto refs. Probably want to // This won't support e.g mailto refs. Probably want to
// launch the browser with an intent eventually. // launch the browser with an intent eventually.
final WebView view = new WebView( context ); WebView view = new WebView( context );
view.setWebViewClient( new WebViewClient() { view.setWebViewClient( new WebViewClient() {
private boolean m_loaded = false; private boolean m_loaded = false;
@Override @Override
@ -65,12 +75,14 @@ public class FirstRunDialog {
view.getSettings().setJavaScriptEnabled( true ); // for surveymonkey view.getSettings().setJavaScriptEnabled( true ); // for surveymonkey
view.loadUrl("file:///android_asset/changes.html"); view.loadUrl("file:///android_asset/changes.html");
LocUtils.makeAlertBuilder( context ) return LocUtils.makeAlertBuilder( context )
.setIcon(android.R.drawable.ic_menu_info_details) .setIcon(android.R.drawable.ic_menu_info_details)
.setTitle( R.string.changes_title ) .setTitle( R.string.changes_title )
.setView( view ) .setView( view )
.setPositiveButton( android.R.string.ok, null) .setPositiveButton( android.R.string.ok, null)
.create() .create();
.show();
} }
@Override
protected String getFragTag() { return TAG; }
} }

View file

@ -946,7 +946,7 @@ public class GamesListDelegate extends ListDelegateBase
if ( isUpgrade ) { if ( isUpgrade ) {
if ( !s_firstShown ) { if ( !s_firstShown ) {
if ( LocUtils.getCurLangCode( m_activity ).equals( "en" ) ) { if ( LocUtils.getCurLangCode( m_activity ).equals( "en" ) ) {
FirstRunDialog.show( m_activity ); show( FirstRunDialog.newInstance() );
} }
s_firstShown = true; s_firstShown = true;
} }