From 7164ab92f66e72db5c7d3bc8f9d9f8ba8d4a2733 Mon Sep 17 00:00:00 2001 From: Eric House Date: Thu, 25 May 2017 19:56:12 -0700 Subject: [PATCH] make FirstRunDialog a DialogFragment It was disappearing when the device rotated. Using the same XWDialogFragment mechanism as everything else fixes that. --- .../org/eehouse/android/xw4/AboutAlert.java | 31 ++++++++++--------- .../eehouse/android/xw4/FirstRunDialog.java | 28 ++++++++++++----- .../android/xw4/GamesListDelegate.java | 2 +- 3 files changed, 38 insertions(+), 23 deletions(-) diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/AboutAlert.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/AboutAlert.java index c4478326e..a64e659c0 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/AboutAlert.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/AboutAlert.java @@ -19,6 +19,7 @@ package org.eehouse.android.xw4; +import android.app.AlertDialog; import android.app.Dialog; import android.content.Context; import android.content.DialogInterface.OnClickListener; @@ -47,8 +48,8 @@ public class AboutAlert extends XWDialogFragment { @Override public Dialog onCreateDialog( Bundle sis ) { - final Context context = getActivity(); - final View view = LocUtils.inflate( context, R.layout.about_dlg ); + Context context = getActivity(); + View view = LocUtils.inflate( context, R.layout.about_dlg ); TextView vers = (TextView)view.findViewById( R.id.version_string ); DateFormat df = DateFormat.getDateTimeInstance( DateFormat.FULL, @@ -67,21 +68,23 @@ public class AboutAlert extends XWDialogFragment { xlator.setVisibility( View.GONE ); } - return LocUtils.makeAlertBuilder( context ) + AlertDialog.Builder builder = LocUtils.makeAlertBuilder( context ) .setIcon( R.drawable.icon48x48 ) .setTitle( R.string.app_name ) .setView( view ) - .setNegativeButton( R.string.changes_button, - new OnClickListener() { - @Override - public void onClick( DialogInterface dlg, - int which ) - { - FirstRunDialog.show( context ); - } - } ) - .setPositiveButton( android.R.string.ok, null ) - .create(); + .setPositiveButton( android.R.string.ok, null ); + + if ( context instanceof XWActivity ) { + final XWActivity activity = (XWActivity)context; + builder.setNegativeButton( R.string.changes_button, new OnClickListener() { + @Override + public void onClick( DialogInterface dlg, int which ) { + activity.show( FirstRunDialog.newInstance() ); + } + } ); + } + + return builder.create(); } @Override diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/FirstRunDialog.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/FirstRunDialog.java index 12d0865e2..ccc6d33a0 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/FirstRunDialog.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/FirstRunDialog.java @@ -20,8 +20,9 @@ package org.eehouse.android.xw4; -import android.app.AlertDialog; +import android.app.Dialog; import android.content.Context; +import android.os.Bundle; import android.webkit.WebView; import android.webkit.WebViewClient; @@ -31,14 +32,23 @@ import org.eehouse.android.xw4.loc.LocUtils; * similar feature in OpenSudoku, to whose author "Thanks". */ -public class FirstRunDialog { - public static void show( final Context context ) +public class FirstRunDialog extends XWDialogFragment { + 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 // launch the browser with an intent eventually. - final WebView view = new WebView( context ); + WebView view = new WebView( context ); view.setWebViewClient( new WebViewClient() { private boolean m_loaded = false; @Override @@ -65,12 +75,14 @@ public class FirstRunDialog { view.getSettings().setJavaScriptEnabled( true ); // for surveymonkey view.loadUrl("file:///android_asset/changes.html"); - LocUtils.makeAlertBuilder( context ) + return LocUtils.makeAlertBuilder( context ) .setIcon(android.R.drawable.ic_menu_info_details) .setTitle( R.string.changes_title ) .setView( view ) .setPositiveButton( android.R.string.ok, null) - .create() - .show(); + .create(); } + + @Override + protected String getFragTag() { return TAG; } } diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/GamesListDelegate.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/GamesListDelegate.java index 62cd00bb3..a257f387a 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/GamesListDelegate.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/GamesListDelegate.java @@ -946,7 +946,7 @@ public class GamesListDelegate extends ListDelegateBase if ( isUpgrade ) { if ( !s_firstShown ) { if ( LocUtils.getCurLangCode( m_activity ).equals( "en" ) ) { - FirstRunDialog.show( m_activity ); + show( FirstRunDialog.newInstance() ); } s_firstShown = true; }