populate language chooser

This commit is contained in:
Eric House 2014-01-28 07:15:59 -08:00
parent 4421472391
commit 3f8e456db2
3 changed files with 35 additions and 6 deletions

View file

@ -1580,9 +1580,9 @@ public class DBUtils {
}
}
public static int studyListLangCount( Context context )
public static int[] studyListLangs( Context context )
{
int result = 0;
int[] result = null;
String groupBy = DBHelper.LANGUAGE;
String selection = null;//DBHelper.LANGUAGE;
String[] columns = { DBHelper.LANGUAGE };
@ -1591,12 +1591,19 @@ public class DBUtils {
synchronized( s_dbHelper ) {
SQLiteDatabase db = s_dbHelper.getReadableDatabase();
Cursor cursor = db.query( DBHelper.TABLE_NAME_STUDYLIST, columns,
selection, null, groupBy, null, null );
result = cursor.getCount();
null, null, groupBy, null, null );
int count = cursor.getCount();
result = new int[count];
if ( 0 < count ) {
int index = 0;
int colIndex = cursor.getColumnIndex( DBHelper.LANGUAGE );
while ( cursor.moveToNext() ) {
result[index++] = cursor.getInt(colIndex);
}
}
cursor.close();
db.close();
}
DbgUtils.logf( "studyListLangCount() => %d", result );
return result;
}

View file

@ -717,7 +717,8 @@ public class GamesList extends XWExpandableListActivity
enable = nothingSelected && Utils.isGooglePlayApp( this );
Utils.setItemVisible( menu, R.id.games_menu_rateme, enable );
enable = nothingSelected && 0 < DBUtils.studyListLangCount( this );
enable = nothingSelected &&
0 < DBUtils.studyListLangs( this ).length;
Utils.setItemVisible( menu, R.id.games_menu_study, enable );
m_menuPrepared = super.onPrepareOptionsMenu( menu );

View file

@ -19,10 +19,12 @@
package org.eehouse.android.xw4;
import android.view.View;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.widget.Spinner;
import android.widget.ArrayAdapter;
public class StudyList extends XWListActivity {
private Spinner mSpinner;
@ -35,7 +37,26 @@ public class StudyList extends XWListActivity {
setContentView( R.layout.studylist );
mSpinner = (Spinner)findViewById( R.id.pick_language );
int[] langs = DBUtils.studyListLangs( this );
if ( 0 == langs.length ) {
finish();
} else if ( 1 == langs.length ) {
mSpinner.setVisibility( View.GONE );
} else {
String[] names = DictLangCache.getLangNames( this );
String[] myNames = new String[langs.length];
for ( int ii = 0; ii < langs.length; ++ii ) {
myNames[ii] = names[langs[ii]];
}
ArrayAdapter<String> adapter = new
ArrayAdapter<String>( this,
android.R.layout.simple_spinner_item,
myNames );
adapter.setDropDownViewResource( android.R.layout.
simple_spinner_dropdown_item );
mSpinner.setAdapter( adapter );
}
}
public static void launch( Context context )