mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-02-09 22:00:39 +01:00
switch not-again alerts to being fragments
Since associated DlgDelegate instance doesn't survive a rotation, needed to pipe results through a DlgClickNotify implementation on XWActivity that then dispatches in the DualpaneDelegate case to all visible fragments. I hope this turns out to work for all DlgClickNotify implementations as I switch them over. We'll see.
This commit is contained in:
parent
683eb8e14b
commit
796192380f
6 changed files with 214 additions and 31 deletions
|
@ -663,7 +663,7 @@ public class DelegateBase implements DlgClickNotify,
|
|||
break;
|
||||
default:
|
||||
DbgUtils.logd( TAG, "unhandled action %s", action.toString() );
|
||||
Assert.assertTrue( !BuildConfig.DEBUG );
|
||||
// Assert.assertTrue( !BuildConfig.DEBUG );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -391,9 +391,9 @@ public class DlgDelegate {
|
|||
case DIALOG_OKONLY:
|
||||
dialog = createOKDialog( state, dlgID );
|
||||
break;
|
||||
case DIALOG_NOTAGAIN:
|
||||
dialog = createNotAgainDialog( state, dlgID );
|
||||
break;
|
||||
// case DIALOG_NOTAGAIN:
|
||||
// dialog = createNotAgainDialog( state, dlgID );
|
||||
// break;
|
||||
case CONFIRM_THEN:
|
||||
dialog = createConfirmThenDialog( state, dlgID );
|
||||
break;
|
||||
|
@ -471,8 +471,9 @@ public class DlgDelegate {
|
|||
DlgState state = new DlgState( DlgID.DIALOG_NOTAGAIN )
|
||||
.setMsg( msg).setPrefsKey( prefsKey ).setAction( action )
|
||||
.setActionPair( more ).setParams( params );
|
||||
addState( state );
|
||||
showDialog( DlgID.DIALOG_NOTAGAIN );
|
||||
// addState( state );
|
||||
// showDialog( DlgID.DIALOG_NOTAGAIN );
|
||||
m_dlgt.show( NotAgainAlert.newInstance( state ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -640,33 +641,33 @@ public class DlgDelegate {
|
|||
return dialog;
|
||||
}
|
||||
|
||||
private Dialog createNotAgainDialog( final DlgState state, DlgID dlgID )
|
||||
{
|
||||
final NotAgainView naView = (NotAgainView)
|
||||
LocUtils.inflate( m_activity, R.layout.not_again_view );
|
||||
naView.setMessage( state.m_msg );
|
||||
final OnClickListener lstnr_p = mkCallbackClickListener( state, naView );
|
||||
// private Dialog createNotAgainDialog( final DlgState state, DlgID dlgID )
|
||||
// {
|
||||
// final NotAgainView naView = (NotAgainView)
|
||||
// LocUtils.inflate( m_activity, R.layout.not_again_view );
|
||||
// naView.setMessage( state.m_msg );
|
||||
// final OnClickListener lstnr_p = mkCallbackClickListener( state, naView );
|
||||
|
||||
AlertDialog.Builder builder = LocUtils.makeAlertBuilder( m_activity )
|
||||
.setTitle( R.string.newbie_title )
|
||||
.setView( naView )
|
||||
.setPositiveButton( android.R.string.ok, lstnr_p );
|
||||
// AlertDialog.Builder builder = LocUtils.makeAlertBuilder( m_activity )
|
||||
// .setTitle( R.string.newbie_title )
|
||||
// .setView( naView )
|
||||
// .setPositiveButton( android.R.string.ok, lstnr_p );
|
||||
|
||||
if ( null != state.m_pair ) {
|
||||
final ActionPair more = state.m_pair;
|
||||
OnClickListener lstnr = new OnClickListener() {
|
||||
public void onClick( DialogInterface dlg, int item ) {
|
||||
checkNotAgainCheck( state, naView );
|
||||
m_clickCallback.onPosButton( more.action, more.params );
|
||||
}
|
||||
};
|
||||
builder.setNegativeButton( more.buttonStr, lstnr );
|
||||
}
|
||||
// if ( null != state.m_pair ) {
|
||||
// final ActionPair more = state.m_pair;
|
||||
// OnClickListener lstnr = new OnClickListener() {
|
||||
// public void onClick( DialogInterface dlg, int item ) {
|
||||
// checkNotAgainCheck( state, naView );
|
||||
// m_clickCallback.onPosButton( more.action, more.params );
|
||||
// }
|
||||
// };
|
||||
// builder.setNegativeButton( more.buttonStr, lstnr );
|
||||
// }
|
||||
|
||||
Dialog dialog = builder.create();
|
||||
// Dialog dialog = builder.create();
|
||||
|
||||
return setCallbackDismissListener( dialog, state, dlgID );
|
||||
} // createNotAgainDialog
|
||||
// return setCallbackDismissListener( dialog, state, dlgID );
|
||||
// } // createNotAgainDialog
|
||||
|
||||
private Dialog createConfirmThenDialog( DlgState state, DlgID dlgID )
|
||||
{
|
||||
|
|
|
@ -29,6 +29,8 @@ import android.view.ContextMenu.ContextMenuInfo;
|
|||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
|
||||
import org.eehouse.android.xw4.DlgDelegate.Action;
|
||||
|
||||
public class DualpaneDelegate extends DelegateBase {
|
||||
private static final String TAG = DualpaneDelegate.class.getSimpleName();
|
||||
private Activity m_activity;
|
||||
|
@ -95,4 +97,13 @@ public class DualpaneDelegate extends DelegateBase {
|
|||
return main.dispatchOnContextItemSelected( item );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPosButton( Action action, Object[] params )
|
||||
{
|
||||
MainActivity main = (MainActivity)m_activity;
|
||||
XWFragment[] frags = main.getVisibleFragments();
|
||||
for ( XWFragment frag : frags ) {
|
||||
frag.getDelegate().onPosButton( action, params );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -356,7 +356,7 @@ public class MainActivity extends XWActivity
|
|||
return frag;
|
||||
}
|
||||
|
||||
private XWFragment[] getVisibleFragments()
|
||||
protected XWFragment[] getVisibleFragments()
|
||||
{
|
||||
int childCount = m_root.getChildCount();
|
||||
int count = Math.min( maxPanes(), childCount );
|
||||
|
|
|
@ -0,0 +1,140 @@
|
|||
/* -*- compile-command: "find-and-gradle.sh insXw4Debug"; -*- */
|
||||
/*
|
||||
* Copyright 2017 by Eric House (xwords@eehouse.org). All rights reserved.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
package org.eehouse.android.xw4;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface.OnClickListener;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.DialogFragment;
|
||||
import org.eehouse.android.xw4.DlgDelegate.Action;
|
||||
import org.eehouse.android.xw4.DlgDelegate.ActionPair;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
import org.eehouse.android.xw4.loc.LocUtils;
|
||||
|
||||
public class NotAgainAlert extends DialogFragment {
|
||||
private static final String TAG = NotAgainAlert.class.getSimpleName();
|
||||
private static final String STATE_KEY = "STATE_KEY";
|
||||
private DlgState m_state;
|
||||
|
||||
public static NotAgainAlert newInstance( DlgState state )
|
||||
{
|
||||
return new NotAgainAlert( state );
|
||||
}
|
||||
|
||||
public NotAgainAlert( DlgState state )
|
||||
{
|
||||
m_state = state;
|
||||
}
|
||||
|
||||
public NotAgainAlert() {}
|
||||
|
||||
@Override
|
||||
public Dialog onCreateDialog( Bundle sis )
|
||||
{
|
||||
final Context context = getActivity();
|
||||
|
||||
if ( null != sis ) {
|
||||
m_state = (DlgState)sis.getParcelable( STATE_KEY );
|
||||
}
|
||||
|
||||
final NotAgainView naView = (NotAgainView)
|
||||
LocUtils.inflate( context, R.layout.not_again_view );
|
||||
naView.setMessage( m_state.m_msg );
|
||||
// final OnClickListener lstnr_p = mkCallbackClickListener( state, naView );
|
||||
|
||||
AlertDialog.Builder builder = LocUtils.makeAlertBuilder( context )
|
||||
.setTitle( R.string.newbie_title )
|
||||
.setView( naView )
|
||||
.setPositiveButton( android.R.string.ok,
|
||||
mkCallbackClickListener( naView ) );
|
||||
|
||||
if ( null != m_state.m_pair ) {
|
||||
final ActionPair more = m_state.m_pair;
|
||||
OnClickListener lstnr = new OnClickListener() {
|
||||
public void onClick( DialogInterface dlg, int item ) {
|
||||
checkNotAgainCheck( m_state, naView );
|
||||
// m_clickCallback.onPosButton( more.action, more.params );
|
||||
}
|
||||
};
|
||||
builder.setNegativeButton( more.buttonStr, lstnr );
|
||||
}
|
||||
|
||||
Dialog dialog = builder.create();
|
||||
return dialog;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState( Bundle bundle )
|
||||
{
|
||||
super.onSaveInstanceState( bundle );
|
||||
bundle.putParcelable( STATE_KEY, m_state );
|
||||
}
|
||||
|
||||
// Belongs in superclass?
|
||||
private void checkNotAgainCheck( DlgState state, NotAgainView naView )
|
||||
{
|
||||
if ( null != naView && naView.getChecked() ) {
|
||||
DbgUtils.logd( TAG, "is checked" );
|
||||
if ( 0 != state.m_prefsKey ) {
|
||||
XWPrefs.setPrefsBoolean( getActivity(), m_state.m_prefsKey,
|
||||
true );
|
||||
} else if ( null != state.m_onNAChecked ) {
|
||||
m_state.m_onNAChecked.run();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private OnClickListener mkCallbackClickListener( final NotAgainView naView )
|
||||
{
|
||||
OnClickListener cbkOnClickLstnr;
|
||||
cbkOnClickLstnr = new OnClickListener() {
|
||||
public void onClick( DialogInterface dlg, int button ) {
|
||||
checkNotAgainCheck( m_state, naView );
|
||||
|
||||
Activity activity = getActivity();
|
||||
if ( Action.SKIP_CALLBACK != m_state.m_action
|
||||
&& activity instanceof XWActivity ) {
|
||||
XWActivity xwact = (XWActivity)activity;
|
||||
switch ( button ) {
|
||||
case AlertDialog.BUTTON_POSITIVE:
|
||||
xwact.onPosButton( m_state.m_action, m_state.m_params );
|
||||
break;
|
||||
case AlertDialog.BUTTON_NEGATIVE:
|
||||
xwact.onNegButton( m_state.m_action, m_state.m_params );
|
||||
break;
|
||||
default:
|
||||
DbgUtils.loge( TAG, "unexpected button %d",
|
||||
button );
|
||||
// ignore on release builds
|
||||
Assert.assertFalse( BuildConfig.DEBUG );
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
return cbkOnClickLstnr;
|
||||
}
|
||||
|
||||
}
|
|
@ -34,9 +34,12 @@ import android.view.View;
|
|||
import android.widget.ListAdapter;
|
||||
import android.widget.ListView;
|
||||
|
||||
import org.eehouse.android.xw4.DlgDelegate.Action;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
public class XWActivity extends FragmentActivity implements Delegator {
|
||||
public class XWActivity extends FragmentActivity
|
||||
implements Delegator, DlgDelegate.DlgClickNotify {
|
||||
private static final String TAG = XWActivity.class.getSimpleName();
|
||||
|
||||
private DelegateBase m_dlgt;
|
||||
|
@ -257,4 +260,32 @@ public class XWActivity extends FragmentActivity implements Delegator {
|
|||
{
|
||||
Assert.fail();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// DlgClickNotify interface
|
||||
////////////////////////////////////////////////////////////
|
||||
@Override
|
||||
public void onPosButton( Action action, Object[] params )
|
||||
{
|
||||
m_dlgt.onPosButton( action, params );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNegButton( Action action, Object[] params )
|
||||
{
|
||||
m_dlgt.onNegButton( action, params );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDismissed( Action action, Object[] params )
|
||||
{
|
||||
m_dlgt.onDismissed( action, params );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void inviteChoiceMade( Action action, InviteMeans means, Object[] params )
|
||||
{
|
||||
m_dlgt.inviteChoiceMade( action, means, params );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue