mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-02-01 19:57:11 +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.view.ViewGroup;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.eehouse.android.xw4.DlgDelegate.Action;
|
import org.eehouse.android.xw4.DlgDelegate.Action;
|
||||||
|
@ -68,7 +71,6 @@ public class KnownPlayersDelegate extends DelegateBase {
|
||||||
case KNOWN_PLAYER_DELETE:
|
case KNOWN_PLAYER_DELETE:
|
||||||
String name = (String)params[0];
|
String name = (String)params[0];
|
||||||
XwJNI.kplr_deletePlayer( name );
|
XwJNI.kplr_deletePlayer( name );
|
||||||
mList.removeAllViews();
|
|
||||||
populateList();
|
populateList();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -133,10 +135,20 @@ public class KnownPlayersDelegate extends DelegateBase {
|
||||||
for ( String player : players ) {
|
for ( String player : players ) {
|
||||||
ViewGroup child = makePlayerElem( player );
|
ViewGroup child = makePlayerElem( player );
|
||||||
if ( null != child ) {
|
if ( null != child ) {
|
||||||
mList.addView( child );
|
|
||||||
mChildren.put( player, 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 );
|
ViewGroup child = mChildren.remove( oldName );
|
||||||
setName( child, newName );
|
setName( child, newName );
|
||||||
mChildren.put( newName, child );
|
mChildren.put( newName, child );
|
||||||
|
addInOrder();
|
||||||
}
|
}
|
||||||
|
|
||||||
private ViewGroup makePlayerElem( String player )
|
private ViewGroup makePlayerElem( String player )
|
||||||
|
|
|
@ -173,9 +173,12 @@ public class XwJNI {
|
||||||
|
|
||||||
public static String[] kplr_getPlayers()
|
public static String[] kplr_getPlayers()
|
||||||
{
|
{
|
||||||
return BuildConfig.HAVE_KNOWN_PLAYERS
|
String[] result = null;
|
||||||
? kplr_getPlayers( getJNI().m_ptrGlobals )
|
if ( BuildConfig.HAVE_KNOWN_PLAYERS ) {
|
||||||
: null;
|
result = kplr_getPlayers( getJNI().m_ptrGlobals );
|
||||||
|
Arrays.sort( result );
|
||||||
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean kplr_renamePlayer( String oldName, String newName )
|
public static boolean kplr_renamePlayer( String oldName, String newName )
|
||||||
|
|
Loading…
Add table
Reference in a new issue