fix invite dialogs for landscape layout

Scrolling's needed in some cases, and you can't easily put a ListView
inside a ScrollView. So replace the ListView with a LinearLayout whose
contents I manage manually, and wrap the whole layout in a ScrollView.
This commit is contained in:
Eric House 2019-04-04 21:26:24 -07:00
parent 054ac325bb
commit c5efeb283a
7 changed files with 144 additions and 169 deletions

View file

@ -148,7 +148,7 @@ public class BTInviteDelegate extends InviteDelegate {
if ( sPersisted.empty() ) { if ( sPersisted.empty() ) {
scan(); scan();
} else { } else {
updateListAdapter( sPersisted.pairs ); updateList( sPersisted.pairs );
} }
} }
@ -258,7 +258,7 @@ public class BTInviteDelegate extends InviteDelegate {
sPersisted.add( dev.getAddress(), dev.getName() ); sPersisted.add( dev.getAddress(), dev.getName() );
store( m_activity ); store( m_activity );
updateListAdapter( sPersisted.pairs ); updateList( sPersisted.pairs );
tryEnable(); tryEnable();
} }
@ -335,7 +335,7 @@ public class BTInviteDelegate extends InviteDelegate {
store( m_activity ); store( m_activity );
clearChecked(); clearChecked();
updateListAdapter( sPersisted.pairs ); updateList( sPersisted.pairs );
tryEnable(); tryEnable();
break; break;
default: default:

View file

@ -31,6 +31,7 @@ import android.widget.ArrayAdapter;
import android.widget.Button; import android.widget.Button;
import android.widget.CheckBox; import android.widget.CheckBox;
import android.widget.CompoundButton; import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.FrameLayout; import android.widget.FrameLayout;
import android.widget.ListView; import android.widget.ListView;
@ -49,7 +50,7 @@ import java.util.Set;
import org.eehouse.android.xw4.DBUtils.SentInvitesInfo; import org.eehouse.android.xw4.DBUtils.SentInvitesInfo;
abstract class InviteDelegate extends ListDelegateBase abstract class InviteDelegate extends DelegateBase
implements View.OnClickListener, implements View.OnClickListener,
ViewGroup.OnHierarchyChangeListener { ViewGroup.OnHierarchyChangeListener {
private static final String TAG = InviteDelegate.class.getSimpleName(); private static final String TAG = InviteDelegate.class.getSimpleName();
@ -93,9 +94,8 @@ abstract class InviteDelegate extends ListDelegateBase
protected String m_lastDev; protected String m_lastDev;
protected Button m_inviteButton; protected Button m_inviteButton;
private Activity m_activity; private Activity m_activity;
private ListView m_lv; private LinearLayout m_lv;
private TextView m_ev; private TextView m_ev;
private InviteItemsAdapter m_adapter;
protected Map<InviterItem, Integer> m_counts; protected Map<InviterItem, Integer> m_counts;
protected Set<InviterItem> m_checked; protected Set<InviterItem> m_checked;
private boolean m_setChecked; private boolean m_setChecked;
@ -145,8 +145,8 @@ abstract class InviteDelegate extends ListDelegateBase
extraView.setVisibility( View.VISIBLE ); extraView.setVisibility( View.VISIBLE );
} }
m_lv = (ListView)findViewById( android.R.id.list ); m_lv = (LinearLayout)findViewById( R.id.invitees );
m_ev = (TextView)findViewById( android.R.id.empty ); m_ev = (TextView)findViewById( R.id.empty );
if ( null != m_lv && null != m_ev && 0 != emptyMsgId ) { if ( null != m_lv && null != m_ev && 0 != emptyMsgId ) {
m_ev.setText( getString( emptyMsgId ) ); m_ev.setText( getString( emptyMsgId ) );
m_lv.setOnHierarchyChangeListener( this ); m_lv.setOnHierarchyChangeListener( this );
@ -183,17 +183,19 @@ abstract class InviteDelegate extends ListDelegateBase
tryEnable(); tryEnable();
} }
protected void updateListAdapter( List<? extends InviterItem> items ) protected void updateList( List<? extends InviterItem> items )
{ {
updateListAdapter( R.layout.two_strs_item, items ); updateList( R.layout.two_strs_item, items );
} }
protected void updateListAdapter( int itemId, protected void updateList( int itemId, List<? extends InviterItem> items )
List<? extends InviterItem> items )
{ {
updateChecked( items ); updateChecked( items );
m_adapter = new InviteItemsAdapter( itemId, items );
setListAdapter( m_adapter ); m_lv.removeAllViews();
for ( InviterItem item : items ) {
m_lv.addView( makeViewFor( itemId, item ) );
}
} }
protected void listSelected( InviterItem[] selected, String[] devs ) protected void listSelected( InviterItem[] selected, String[] devs )
@ -244,10 +246,13 @@ abstract class InviteDelegate extends ListDelegateBase
//////////////////////////////////////// ////////////////////////////////////////
// ViewGroup.OnHierarchyChangeListener // ViewGroup.OnHierarchyChangeListener
//////////////////////////////////////// ////////////////////////////////////////
@Override
public void onChildViewAdded( View parent, View child ) public void onChildViewAdded( View parent, View child )
{ {
showEmptyIfEmpty(); showEmptyIfEmpty();
} }
@Override
public void onChildViewRemoved( View parent, View child ) public void onChildViewRemoved( View parent, View child )
{ {
showEmptyIfEmpty(); showEmptyIfEmpty();
@ -255,8 +260,8 @@ abstract class InviteDelegate extends ListDelegateBase
private void showEmptyIfEmpty() private void showEmptyIfEmpty()
{ {
m_ev.setVisibility( 0 == m_lv.getChildCount() int count = m_lv.getChildCount();
? View.VISIBLE : View.GONE ); m_ev.setVisibility( 0 == count ? View.VISIBLE : View.GONE );
} }
protected void tryEnable() protected void tryEnable()
@ -297,46 +302,17 @@ abstract class InviteDelegate extends ListDelegateBase
} }
} }
private InviteItemsAdapter getAdapter() private View makeViewFor( int itemID, final InviterItem item )
{ {
return m_adapter;
}
private class InviteItemsAdapter extends XWListAdapter {
private InviterItem[] m_items;
private int m_itemId;
public InviteItemsAdapter( int itemID, List<? extends InviterItem> items )
{
super( null == items? 0 : items.size() );
m_itemId = itemID;
if ( null != items ) {
m_items = items.toArray( new InviterItem[items.size()] );
}
// m_items = new LinearLayout[getCount()];
}
public InviterItem[] getItems() { return m_items; }
// public String[] getAddrs() { return m_devAddrs; }
@Override
public Object getItem( int position ) { return m_items[position]; }
@Override
public View getView( final int position, View convertView,
ViewGroup parent )
{
final InviterItem item = m_items[position];
final LinearLayout layout = (LinearLayout) final LinearLayout layout = (LinearLayout)
inflate( R.layout.inviter_item_frame ); inflate( R.layout.inviter_item_frame );
CheckBox box = (CheckBox)layout.findViewById( R.id.inviter_check ); CheckBox box = (CheckBox)layout.findViewById( R.id.inviter_check );
// Give subclass a chance to install and populate its view // Give subclass a chance to install and populate its view
FrameLayout frame = (FrameLayout)layout.findViewById( R.id.frame ); FrameLayout frame = (FrameLayout)layout.findViewById( R.id.frame );
View child = inflate( m_itemId ); View child = inflate( itemID );
frame.addView( child ); frame.addView( child );
onChildAdded( child, m_items[position] ); onChildAdded( child, item );
m_counts.put( item, 1 ); m_counts.put( item, 1 );
if ( XWPrefs.getCanInviteMulti( m_activity ) && 1 < m_nMissing ) { if ( XWPrefs.getCanInviteMulti( m_activity ) && 1 < m_nMissing ) {
@ -364,8 +340,8 @@ abstract class InviteDelegate extends ListDelegateBase
} ); } );
} }
CompoundButton.OnCheckedChangeListener listener = box.setOnCheckedChangeListener( new OnCheckedChangeListener() {
new CompoundButton.OnCheckedChangeListener() { @Override
public void onCheckedChanged( CompoundButton buttonView, public void onCheckedChanged( CompoundButton buttonView,
boolean isChecked ) { boolean isChecked ) {
if ( !isChecked ) { if ( !isChecked ) {
@ -375,15 +351,12 @@ abstract class InviteDelegate extends ListDelegateBase
m_checked.add( item ); m_checked.add( item );
} else { } else {
m_checked.remove( item ); m_checked.remove( item );
// // User's now making changes; don't check new views
// m_setChecked = false;
} }
onItemChecked( item, isChecked ); onItemChecked( item, isChecked );
tryEnable(); tryEnable();
} }
}; } );
box.setOnCheckedChangeListener( listener );
if ( m_setChecked || m_checked.contains( item ) ) { if ( m_setChecked || m_checked.contains( item ) ) {
box.setChecked( true ); box.setChecked( true );
@ -391,11 +364,7 @@ abstract class InviteDelegate extends ListDelegateBase
m_lastDev = null; m_lastDev = null;
box.setChecked( true ); box.setChecked( true );
} }
return layout; return layout;
} }
public String getAddr( CheckBox box ) { return (String)box.getTag(); }
public String getName( CheckBox box ) { return box.getText().toString(); }
}
} }

View file

@ -463,7 +463,7 @@ public class RelayInviteDelegate extends InviteDelegate {
}); });
addSelf(); addSelf();
updateListAdapter( m_devIDRecs ); updateList( m_devIDRecs );
tryEnable(); tryEnable();
} }

View file

@ -302,7 +302,7 @@ public class SMSInviteDelegate extends InviteDelegate {
} }
}); });
updateListAdapter( m_phoneRecs ); updateList( m_phoneRecs );
tryEnable(); tryEnable();
} }

View file

@ -129,6 +129,6 @@ public class WiDirInviteDelegate extends InviteDelegate
// names[ii] = m_macsToName.get(mac); // names[ii] = m_macsToName.get(mac);
} }
updateListAdapter( pairs ); updateList( pairs );
} }
} }

View file

@ -28,6 +28,7 @@ import android.widget.ListAdapter;
*/ */
public abstract class XWListAdapter extends BaseAdapter public abstract class XWListAdapter extends BaseAdapter
implements ListAdapter { implements ListAdapter {
private static final String TAG = XWListAdapter.class.getSimpleName();
private int m_count; private int m_count;
public XWListAdapter() { public XWListAdapter() {

View file

@ -1,7 +1,11 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" android:orientation="vertical"
>
<LinearLayout android:orientation="vertical"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:layout_height="fill_parent"
> >
@ -21,15 +25,15 @@
android:visibility="gone" android:visibility="gone"
/> />
<ListView android:id="@id/android:list" <LinearLayout android:orientation="vertical"
android:id="@+id/invitees"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:layout_height="wrap_content"
android:drawSelectorOnTop="false"
android:layout_weight="1" android:layout_weight="1"
android:padding="8dp" android:padding="8dp"
/> />
<TextView android:id="@android:id/empty" <TextView android:id="@+id/empty"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:padding="20dp" android:padding="20dp"
@ -70,3 +74,4 @@
/> />
</LinearLayout> </LinearLayout>
</ScrollView>