mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-07 05:24:46 +01:00
make sms enabling alert dialog-fragment-based
This commit is contained in:
parent
56dfef828d
commit
1de838171b
4 changed files with 111 additions and 127 deletions
|
@ -377,14 +377,12 @@ public class DlgDelegate {
|
|||
case DIALOG_NOTAGAIN:
|
||||
case CONFIRM_THEN:
|
||||
case INVITE_CHOICES_THEN:
|
||||
case DIALOG_ENABLESMS:
|
||||
Assert.assertFalse( BuildConfig.DEBUG );
|
||||
break;
|
||||
case DLG_DICTGONE:
|
||||
dialog = createDictGoneDialog();
|
||||
break;
|
||||
case DIALOG_ENABLESMS:
|
||||
dialog = createEnableSMSDialog( state, dlgID );
|
||||
break;
|
||||
default:
|
||||
DbgUtils.logd( TAG, "not creating %s", dlgID.toString() );
|
||||
break;
|
||||
|
@ -396,12 +394,10 @@ public class DlgDelegate {
|
|||
{
|
||||
switch( dlgId ) {
|
||||
case INVITE_CHOICES_THEN:
|
||||
case DIALOG_ENABLESMS:
|
||||
Assert.assertFalse( BuildConfig.DEBUG );
|
||||
// prepareInviteChoicesDialog( dialog );
|
||||
break;
|
||||
case DIALOG_ENABLESMS:
|
||||
prepareEnableSMSDialog( dialog );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -429,8 +425,8 @@ public class DlgDelegate {
|
|||
DlgState state = new DlgState( DlgID.DIALOG_ENABLESMS )
|
||||
.setAction( action )
|
||||
.setParams( params );
|
||||
addState( state );
|
||||
showDialog( DlgID.DIALOG_ENABLESMS );
|
||||
|
||||
m_dlgt.show( EnableSMSAlert.newInstance( state ) );
|
||||
}
|
||||
|
||||
private void showNotAgainDlgThen( String msg, int prefsKey,
|
||||
|
@ -604,120 +600,6 @@ public class DlgDelegate {
|
|||
return dialog;
|
||||
}
|
||||
|
||||
private Dialog createEnableSMSDialog( final DlgState state, DlgID dlgID )
|
||||
{
|
||||
final View layout = LocUtils.inflate( m_activity, R.layout.confirm_sms );
|
||||
|
||||
DialogInterface.OnClickListener lstnr =
|
||||
new DialogInterface.OnClickListener() {
|
||||
public void onClick( DialogInterface dlg, int item ) {
|
||||
Spinner reasons = (Spinner)
|
||||
layout.findViewById( R.id.confirm_sms_reasons );
|
||||
boolean enabled = 0 < reasons.getSelectedItemPosition();
|
||||
Assert.assertTrue( enabled );
|
||||
m_clickCallback.onPosButton( state.m_action, state.m_params );
|
||||
}
|
||||
};
|
||||
|
||||
Dialog dialog = LocUtils.makeAlertBuilder( m_activity )
|
||||
.setTitle( R.string.confirm_sms_title )
|
||||
.setView( layout )
|
||||
.setPositiveButton( R.string.button_enable, lstnr )
|
||||
.setNegativeButton( android.R.string.cancel, null )
|
||||
.create();
|
||||
return dialog;
|
||||
}
|
||||
|
||||
private void checkEnableButton( Dialog dialog, Spinner reasons )
|
||||
{
|
||||
boolean enabled = 0 < reasons.getSelectedItemPosition();
|
||||
AlertDialog adlg = (AlertDialog)dialog;
|
||||
Button button = adlg.getButton( AlertDialog.BUTTON_POSITIVE );
|
||||
button.setEnabled( enabled );
|
||||
}
|
||||
|
||||
private void prepareEnableSMSDialog( final Dialog dialog )
|
||||
{
|
||||
final Spinner reasons = (Spinner)
|
||||
dialog.findViewById( R.id.confirm_sms_reasons );
|
||||
|
||||
OnItemSelectedListener onItemSel = new OnItemSelectedListener() {
|
||||
public void onItemSelected( AdapterView<?> parent, View view,
|
||||
int position, long id )
|
||||
{
|
||||
checkEnableButton( dialog, reasons );
|
||||
}
|
||||
|
||||
public void onNothingSelected( AdapterView<?> parent ) {}
|
||||
};
|
||||
reasons.setOnItemSelectedListener( onItemSel );
|
||||
checkEnableButton( dialog, reasons );
|
||||
}
|
||||
|
||||
private OnClickListener mkCallbackClickListener( final DlgState state,
|
||||
final NotAgainView naView )
|
||||
{
|
||||
OnClickListener cbkOnClickLstnr;
|
||||
cbkOnClickLstnr = new OnClickListener() {
|
||||
public void onClick( DialogInterface dlg, int button ) {
|
||||
checkNotAgainCheck( state, naView );
|
||||
|
||||
if ( Action.SKIP_CALLBACK != state.m_action ) {
|
||||
switch ( button ) {
|
||||
case AlertDialog.BUTTON_POSITIVE:
|
||||
m_clickCallback.onPosButton( state.m_action,
|
||||
state.m_params );
|
||||
break;
|
||||
case AlertDialog.BUTTON_NEGATIVE:
|
||||
m_clickCallback.onNegButton( state.m_action,
|
||||
state.m_params );
|
||||
break;
|
||||
default:
|
||||
DbgUtils.loge( TAG, "unexpected button %d",
|
||||
button );
|
||||
// ignore on release builds
|
||||
Assert.assertFalse( BuildConfig.DEBUG );
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
return cbkOnClickLstnr;
|
||||
}
|
||||
|
||||
private void checkNotAgainCheck( DlgState state, NotAgainView naView )
|
||||
{
|
||||
if ( null != naView && naView.getChecked() ) {
|
||||
if ( 0 != state.m_prefsKey ) {
|
||||
XWPrefs.setPrefsBoolean( m_activity, state.m_prefsKey,
|
||||
true );
|
||||
} else if ( null != state.m_onNAChecked ) {
|
||||
XWActivity activity = (XWActivity)m_activity;
|
||||
activity.onPosButton( state.m_onNAChecked, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Dialog setCallbackDismissListener( final Dialog dialog,
|
||||
final DlgState state,
|
||||
DlgID dlgID )
|
||||
{
|
||||
final int id = dlgID.ordinal();
|
||||
DialogInterface.OnDismissListener cbkOnDismissLstnr
|
||||
= new DialogInterface.OnDismissListener() {
|
||||
public void onDismiss( DialogInterface di ) {
|
||||
dropState( state );
|
||||
if ( Action.SKIP_CALLBACK != state.m_action ) {
|
||||
m_clickCallback.onDismissed( state.m_action,
|
||||
state.m_params );
|
||||
}
|
||||
m_activity.removeDialog( id );
|
||||
}
|
||||
};
|
||||
|
||||
dialog.setOnDismissListener( cbkOnDismissLstnr );
|
||||
return dialog;
|
||||
}
|
||||
|
||||
private DlgState findForID( DlgID dlgID )
|
||||
{
|
||||
DlgState state = m_dlgStates.get( dlgID );
|
||||
|
|
|
@ -33,7 +33,6 @@ import org.eehouse.android.xw4.DlgDelegate.ActionPair;
|
|||
import junit.framework.Assert;
|
||||
|
||||
import org.eehouse.android.xw4.loc.LocUtils;
|
||||
import android.support.v4.app.DialogFragment;
|
||||
|
||||
/** Abstract superclass for Alerts that have moved from and are still created
|
||||
* inside DlgDelegate
|
||||
|
|
|
@ -0,0 +1,102 @@
|
|||
/* -*- 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.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.AdapterView.OnItemSelectedListener;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.Button;
|
||||
import android.widget.Spinner;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
import org.eehouse.android.xw4.loc.LocUtils;
|
||||
|
||||
public class EnableSMSAlert extends DlgDelegateAlert {
|
||||
private Spinner mSpinner;
|
||||
|
||||
public static EnableSMSAlert newInstance( DlgState state )
|
||||
{
|
||||
EnableSMSAlert result = new EnableSMSAlert();
|
||||
result.addStateArgument( state );
|
||||
return result;
|
||||
}
|
||||
|
||||
public EnableSMSAlert() {}
|
||||
|
||||
@Override
|
||||
public Dialog onCreateDialog( Bundle sis )
|
||||
{
|
||||
Context context = getActivity();
|
||||
final DlgState state = getState( sis );
|
||||
|
||||
View layout = LocUtils.inflate( context, R.layout.confirm_sms );
|
||||
mSpinner = (Spinner)layout.findViewById( R.id.confirm_sms_reasons );
|
||||
|
||||
OnItemSelectedListener onItemSel = new OnItemSelectedListener() {
|
||||
@Override
|
||||
public void onItemSelected( AdapterView<?> parent, View view,
|
||||
int position, long id ) {
|
||||
checkEnableButton( getDialog() );
|
||||
}
|
||||
@Override
|
||||
public void onNothingSelected( AdapterView<?> parent ) {}
|
||||
};
|
||||
mSpinner.setOnItemSelectedListener( onItemSel );
|
||||
|
||||
DialogInterface.OnClickListener lstnr =
|
||||
new DialogInterface.OnClickListener() {
|
||||
public void onClick( DialogInterface dlg, int item ) {
|
||||
Assert.assertTrue( 0 < mSpinner.getSelectedItemPosition() );
|
||||
XWActivity xwact = (XWActivity)getActivity();
|
||||
xwact.onPosButton( state.m_action, state.m_params );
|
||||
}
|
||||
};
|
||||
|
||||
AlertDialog dialog = LocUtils.makeAlertBuilder( context )
|
||||
.setTitle( R.string.confirm_sms_title )
|
||||
.setView( layout )
|
||||
.setPositiveButton( R.string.button_enable, lstnr )
|
||||
.setNegativeButton( android.R.string.cancel, null )
|
||||
.create();
|
||||
|
||||
dialog.setOnShowListener(new DialogInterface.OnShowListener() {
|
||||
@Override
|
||||
public void onShow(DialogInterface dialog) {
|
||||
checkEnableButton( (Dialog)dialog );
|
||||
}
|
||||
});
|
||||
|
||||
return dialog;
|
||||
}
|
||||
|
||||
private void checkEnableButton( Dialog dialog )
|
||||
{
|
||||
boolean enabled = 0 < mSpinner.getSelectedItemPosition();
|
||||
((AlertDialog)dialog)
|
||||
.getButton( AlertDialog.BUTTON_POSITIVE )
|
||||
.setEnabled( enabled );
|
||||
}
|
||||
}
|
|
@ -270,12 +270,13 @@ public class GameConfigDelegate extends DelegateBase
|
|||
}
|
||||
break;
|
||||
case CHANGE_CONN: {
|
||||
CommsConnTypeSet conTypes = (CommsConnTypeSet)params[0];
|
||||
LinearLayout layout = (LinearLayout)inflate( R.layout.conn_types_display );
|
||||
final ConnViaViewLayout items = (ConnViaViewLayout)
|
||||
layout.findViewById( R.id.conn_types );
|
||||
items.setActivity( m_activity );
|
||||
|
||||
items.configure( m_conTypes,
|
||||
items.configure( conTypes,
|
||||
new ConnViaViewLayout.CheckEnabledWarner() {
|
||||
public void warnDisabled( CommsConnType typ ) {
|
||||
switch( typ ) {
|
||||
|
@ -680,7 +681,7 @@ public class GameConfigDelegate extends DelegateBase
|
|||
break;
|
||||
|
||||
case ASKED_PHONE_STATE:
|
||||
showDialogFragment( DlgID.CHANGE_CONN );
|
||||
showDialogFragment( DlgID.CHANGE_CONN, m_conTypes );
|
||||
break;
|
||||
|
||||
default:
|
||||
|
@ -698,7 +699,7 @@ public class GameConfigDelegate extends DelegateBase
|
|||
showConnAfterCheck();
|
||||
break;
|
||||
case ASKED_PHONE_STATE:
|
||||
showDialogFragment( DlgID.CHANGE_CONN );
|
||||
showDialogFragment( DlgID.CHANGE_CONN, m_conTypes );
|
||||
break;
|
||||
default:
|
||||
handled = super.onNegButton( action, params );
|
||||
|
@ -775,7 +776,7 @@ public class GameConfigDelegate extends DelegateBase
|
|||
R.string.phone_state_rationale,
|
||||
Action.ASKED_PHONE_STATE, this );
|
||||
} else {
|
||||
showDialogFragment( DlgID.CHANGE_CONN );
|
||||
showDialogFragment( DlgID.CHANGE_CONN, m_conTypes );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue