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() ) {
scan();
} else {
updateListAdapter( sPersisted.pairs );
updateList( sPersisted.pairs );
}
}
@ -258,7 +258,7 @@ public class BTInviteDelegate extends InviteDelegate {
sPersisted.add( dev.getAddress(), dev.getName() );
store( m_activity );
updateListAdapter( sPersisted.pairs );
updateList( sPersisted.pairs );
tryEnable();
}
@ -335,7 +335,7 @@ public class BTInviteDelegate extends InviteDelegate {
store( m_activity );
clearChecked();
updateListAdapter( sPersisted.pairs );
updateList( sPersisted.pairs );
tryEnable();
break;
default:

View file

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

View file

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

View file

@ -129,6 +129,6 @@ public class WiDirInviteDelegate extends InviteDelegate
// 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
implements ListAdapter {
private static final String TAG = XWListAdapter.class.getSimpleName();
private int m_count;
public XWListAdapter() {

View file

@ -1,7 +1,11 @@
<?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"
>
<LinearLayout android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
@ -21,15 +25,15 @@
android:visibility="gone"
/>
<ListView android:id="@id/android:list"
<LinearLayout android:orientation="vertical"
android:id="@+id/invitees"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:drawSelectorOnTop="false"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="8dp"
/>
<TextView android:id="@android:id/empty"
<TextView android:id="@+id/empty"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="20dp"
@ -69,4 +73,5 @@
android:layout_height="wrap_content"
/>
</LinearLayout>
</LinearLayout>
</ScrollView>