mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-22 07:28:16 +01:00
keep players in sorted order
Sorting in common/ is hard because there's not locale-aware sort available. Java should do the right thing so do it there.
This commit is contained in:
parent
0c7e9836e2
commit
574e50f235
2 changed files with 21 additions and 5 deletions
|
@ -30,7 +30,10 @@ import android.view.View;
|
|||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eehouse.android.xw4.DlgDelegate.Action;
|
||||
|
@ -68,7 +71,6 @@ public class KnownPlayersDelegate extends DelegateBase {
|
|||
case KNOWN_PLAYER_DELETE:
|
||||
String name = (String)params[0];
|
||||
XwJNI.kplr_deletePlayer( name );
|
||||
mList.removeAllViews();
|
||||
populateList();
|
||||
break;
|
||||
default:
|
||||
|
@ -133,10 +135,20 @@ public class KnownPlayersDelegate extends DelegateBase {
|
|||
for ( String player : players ) {
|
||||
ViewGroup child = makePlayerElem( player );
|
||||
if ( null != child ) {
|
||||
mList.addView( child );
|
||||
mChildren.put( player, child );
|
||||
}
|
||||
}
|
||||
addInOrder();
|
||||
}
|
||||
}
|
||||
|
||||
private void addInOrder()
|
||||
{
|
||||
mList.removeAllViews();
|
||||
List<String> names = new ArrayList<>(mChildren.keySet());
|
||||
Collections.sort(names);
|
||||
for ( String name : names ) {
|
||||
mList.addView( mChildren.get( name ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -157,6 +169,7 @@ public class KnownPlayersDelegate extends DelegateBase {
|
|||
ViewGroup child = mChildren.remove( oldName );
|
||||
setName( child, newName );
|
||||
mChildren.put( newName, child );
|
||||
addInOrder();
|
||||
}
|
||||
|
||||
private ViewGroup makePlayerElem( String player )
|
||||
|
|
|
@ -173,9 +173,12 @@ public class XwJNI {
|
|||
|
||||
public static String[] kplr_getPlayers()
|
||||
{
|
||||
return BuildConfig.HAVE_KNOWN_PLAYERS
|
||||
? kplr_getPlayers( getJNI().m_ptrGlobals )
|
||||
: null;
|
||||
String[] result = null;
|
||||
if ( BuildConfig.HAVE_KNOWN_PLAYERS ) {
|
||||
result = kplr_getPlayers( getJNI().m_ptrGlobals );
|
||||
Arrays.sort( result );
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static boolean kplr_renamePlayer( String oldName, String newName )
|
||||
|
|
Loading…
Reference in a new issue