mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-09 05:24:44 +01:00
wip: cleanup (not related to duplicate)
This commit is contained in:
parent
3a4a8baf70
commit
c211b95070
2 changed files with 28 additions and 30 deletions
|
@ -1460,9 +1460,15 @@ public class DBUtils {
|
||||||
m_lastMoveTime = 0;
|
m_lastMoveTime = 0;
|
||||||
m_count = count;
|
m_count = count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString()
|
||||||
|
{
|
||||||
|
return String.format( "GameGroupInfo: {name: %s}", m_name );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static HashMap<Long,GameGroupInfo> s_groupsCache = null;
|
private static Map<Long,GameGroupInfo> s_groupsCache = null;
|
||||||
|
|
||||||
private static void invalGroupsCache()
|
private static void invalGroupsCache()
|
||||||
{
|
{
|
||||||
|
@ -1513,11 +1519,10 @@ public class DBUtils {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Map of groups rowid (= summaries.groupid) to group info record
|
// Map of groups rowid (= summaries.groupid) to group info record
|
||||||
protected static HashMap<Long,GameGroupInfo> getGroups( Context context )
|
protected static Map<Long,GameGroupInfo> getGroups( Context context )
|
||||||
{
|
{
|
||||||
if ( null == s_groupsCache ) {
|
if ( null == s_groupsCache ) {
|
||||||
HashMap<Long,GameGroupInfo> result =
|
Map<Long,GameGroupInfo> result = new HashMap<>();
|
||||||
new HashMap<Long,GameGroupInfo>();
|
|
||||||
|
|
||||||
// Select all groups. For each group get the number of games in
|
// Select all groups. For each group get the number of games in
|
||||||
// that group. There should be a way to do that with one query
|
// that group. There should be a way to do that with one query
|
||||||
|
@ -1556,27 +1561,10 @@ public class DBUtils {
|
||||||
}
|
}
|
||||||
s_groupsCache = result;
|
s_groupsCache = result;
|
||||||
}
|
}
|
||||||
|
Log.d( TAG, "getGroups() => %s", s_groupsCache );
|
||||||
return s_groupsCache;
|
return s_groupsCache;
|
||||||
} // getGroups
|
} // getGroups
|
||||||
|
|
||||||
// public static void unhideTo( Context context, long groupID )
|
|
||||||
// {
|
|
||||||
// Assert.assertTrue( GROUPID_UNSPEC != groupID );
|
|
||||||
// initDB( context );
|
|
||||||
// synchronized( s_dbHelper ) {
|
|
||||||
// SQLiteDatabase db = s_dbHelper.getWritableDatabase();
|
|
||||||
// ContentValues values = new ContentValues();
|
|
||||||
// values.put( DBHelper.GROUPID, groupID );
|
|
||||||
// String selection = String.format( "%s = %d", DBHelper.GROUPID,
|
|
||||||
// GROUPID_UNSPEC );
|
|
||||||
// long result = db.update( DBHelper.TABLE_NAME_SUM,
|
|
||||||
// values, selection, null );
|
|
||||||
// db.close();
|
|
||||||
|
|
||||||
// notifyListeners( ROWID_NOTFOUND, true );
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
private static void readTurnInfo( SQLiteDatabase db, long groupID,
|
private static void readTurnInfo( SQLiteDatabase db, long groupID,
|
||||||
GameGroupInfo ggi )
|
GameGroupInfo ggi )
|
||||||
{
|
{
|
||||||
|
@ -1725,7 +1713,7 @@ public class DBUtils {
|
||||||
public static long getAnyGroup( Context context )
|
public static long getAnyGroup( Context context )
|
||||||
{
|
{
|
||||||
long result = GROUPID_UNSPEC;
|
long result = GROUPID_UNSPEC;
|
||||||
HashMap<Long,GameGroupInfo> groups = getGroups( context );
|
Map<Long,GameGroupInfo> groups = getGroups( context );
|
||||||
Iterator<Long> iter = groups.keySet().iterator();
|
Iterator<Long> iter = groups.keySet().iterator();
|
||||||
if ( iter.hasNext() ) {
|
if ( iter.hasNext() ) {
|
||||||
result = iter.next();
|
result = iter.next();
|
||||||
|
@ -1754,6 +1742,7 @@ public class DBUtils {
|
||||||
}
|
}
|
||||||
cursor.close();
|
cursor.close();
|
||||||
}
|
}
|
||||||
|
Log.d( TAG, "getGroup(%s) => %d", name, result );
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1761,8 +1750,7 @@ public class DBUtils {
|
||||||
{
|
{
|
||||||
long rowid = GROUPID_UNSPEC;
|
long rowid = GROUPID_UNSPEC;
|
||||||
if ( null != name && 0 < name.length() ) {
|
if ( null != name && 0 < name.length() ) {
|
||||||
HashMap<Long,GameGroupInfo> gameInfo = getGroups( context );
|
if ( null == getGroups( context ).get( name ) ) {
|
||||||
if ( null == gameInfo.get( name ) ) {
|
|
||||||
ContentValues values = new ContentValues();
|
ContentValues values = new ContentValues();
|
||||||
values.put( DBHelper.GROUPNAME, name );
|
values.put( DBHelper.GROUPNAME, name );
|
||||||
values.put( DBHelper.EXPANDED, 1 );
|
values.put( DBHelper.EXPANDED, 1 );
|
||||||
|
|
|
@ -43,6 +43,7 @@ import android.widget.EditText;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
import android.text.TextUtils;
|
||||||
|
|
||||||
import org.eehouse.android.xw4.DBUtils.GameChangeType;
|
import org.eehouse.android.xw4.DBUtils.GameChangeType;
|
||||||
import org.eehouse.android.xw4.DBUtils.GameGroupInfo;
|
import org.eehouse.android.xw4.DBUtils.GameGroupInfo;
|
||||||
|
@ -137,7 +138,7 @@ public class GamesListDelegate extends ListDelegateBase
|
||||||
GameListAdapter()
|
GameListAdapter()
|
||||||
{
|
{
|
||||||
super( new Class[] { GroupRec.class, GameRec.class } );
|
super( new Class[] { GroupRec.class, GameRec.class } );
|
||||||
m_groupPositions = checkPositions();
|
m_groupPositions = checkGroupPositions();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Object[] makeListData()
|
protected Object[] makeListData()
|
||||||
|
@ -310,7 +311,7 @@ public class GamesListDelegate extends ListDelegateBase
|
||||||
if ( null == m_groupPositions ||
|
if ( null == m_groupPositions ||
|
||||||
m_groupPositions.length != keys.size() ) {
|
m_groupPositions.length != keys.size() ) {
|
||||||
|
|
||||||
HashSet<Long> unused = new HashSet<Long>( keys );
|
HashSet<Long> unused = new HashSet<>( keys );
|
||||||
long[] newArray = new long[unused.size()];
|
long[] newArray = new long[unused.size()];
|
||||||
|
|
||||||
// First copy the existing values, in order
|
// First copy the existing values, in order
|
||||||
|
@ -342,6 +343,7 @@ public class GamesListDelegate extends ListDelegateBase
|
||||||
|
|
||||||
void moveGroup( long groupID, boolean moveUp )
|
void moveGroup( long groupID, boolean moveUp )
|
||||||
{
|
{
|
||||||
|
Log.d( TAG, "moveGroup(up=%b)", moveUp );
|
||||||
int src = getGroupPosition( groupID );
|
int src = getGroupPosition( groupID );
|
||||||
int dest = src + (moveUp ? -1 : 1);
|
int dest = src + (moveUp ? -1 : 1);
|
||||||
|
|
||||||
|
@ -538,14 +540,14 @@ public class GamesListDelegate extends ListDelegateBase
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private long[] checkPositions()
|
private long[] checkGroupPositions()
|
||||||
{
|
{
|
||||||
long[] result = XWPrefs.getGroupPositions( m_activity );
|
long[] result = XWPrefs.getGroupPositions( m_activity );
|
||||||
|
|
||||||
if ( null != result ) {
|
if ( null != result ) {
|
||||||
final Map<Long,GameGroupInfo> gameInfo =
|
final Map<Long,GameGroupInfo> groups =
|
||||||
DBUtils.getGroups( m_activity );
|
DBUtils.getGroups( m_activity );
|
||||||
Set<Long> posns = gameInfo.keySet();
|
Set<Long> posns = groups.keySet();
|
||||||
if ( result.length != posns.size() ) {
|
if ( result.length != posns.size() ) {
|
||||||
result = null;
|
result = null;
|
||||||
} else {
|
} else {
|
||||||
|
@ -557,6 +559,14 @@ public class GamesListDelegate extends ListDelegateBase
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( BuildConfig.DEBUG && null != result ) {
|
||||||
|
List<Long> list = new ArrayList<>();
|
||||||
|
for ( long ll : result ) {
|
||||||
|
list.add( ll );
|
||||||
|
}
|
||||||
|
Log.d( TAG, "checkGroupPositions() => %s", TextUtils.join(",", list ));
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
} // class GameListAdapter
|
} // class GameListAdapter
|
||||||
|
|
Loading…
Reference in a new issue