mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2024-12-30 10:26:58 +01:00
use new loc db to save translation data (per locale) across boots.
This commit is contained in:
parent
47ea2b8b62
commit
6b59093d84
4 changed files with 79 additions and 1 deletions
|
@ -1745,6 +1745,66 @@ public class DBUtils {
|
|||
studyListClear( context, lang, null );
|
||||
}
|
||||
|
||||
public static void saveXlations( Context context, String locale,
|
||||
HashMap<String, String> data )
|
||||
{
|
||||
if ( null != data && 0 < data.size() ) {
|
||||
Iterator<String> iter = data.keySet().iterator();
|
||||
|
||||
initDB( context );
|
||||
synchronized( s_dbHelper ) {
|
||||
SQLiteDatabase db = s_dbHelper.getWritableDatabase();
|
||||
|
||||
while ( iter.hasNext() ) {
|
||||
String key = iter.next();
|
||||
String value = data.get( key );
|
||||
|
||||
String selection = String.format( "%s = '%s'",
|
||||
DBHelper.KEY,
|
||||
key );
|
||||
ContentValues values = new ContentValues();
|
||||
values.put( DBHelper.XLATION, value);
|
||||
values.put( DBHelper.LOCALE, locale);
|
||||
long result = db.update( DBHelper.TABLE_NAME_LOC,
|
||||
values, selection, null );
|
||||
if ( 0 == result ) {
|
||||
values.put( DBHelper.KEY, key );
|
||||
db.insert( DBHelper.TABLE_NAME_LOC, null, values );
|
||||
}
|
||||
}
|
||||
db.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static HashMap<String, String> getXlations( Context context,
|
||||
String locale )
|
||||
{
|
||||
HashMap<String, String> result = new HashMap<String, String>();
|
||||
|
||||
String selection = String.format( "%s = '%s'", DBHelper.LOCALE,
|
||||
locale );
|
||||
String[] columns = { DBHelper.KEY, DBHelper.XLATION };
|
||||
|
||||
initDB( context );
|
||||
synchronized( s_dbHelper ) {
|
||||
SQLiteDatabase db = s_dbHelper.getReadableDatabase();
|
||||
Cursor cursor = db.query( DBHelper.TABLE_NAME_LOC, columns,
|
||||
selection, null, null, null, null );
|
||||
int keyIndex = cursor.getColumnIndex( DBHelper.KEY );
|
||||
int valueIndex = cursor.getColumnIndex( DBHelper.XLATION );
|
||||
while ( cursor.moveToNext() ) {
|
||||
String key = cursor.getString( keyIndex );
|
||||
String value = cursor.getString( valueIndex );
|
||||
result.put( key, value );
|
||||
}
|
||||
cursor.close();
|
||||
db.close();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private static void copyGameDB( Context context, boolean toSDCard )
|
||||
{
|
||||
String name = DBHelper.getDBName();
|
||||
|
|
|
@ -33,4 +33,10 @@ public class LocActivity extends ListActivity {
|
|||
m_dlgt = new LocDelegate( this, savedInstanceState );
|
||||
} // onCreate
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
if ( !m_dlgt.onBackPressed() ) {
|
||||
super.onBackPressed();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,6 +39,12 @@ public class LocDelegate extends DelegateBase {
|
|||
init( savedInstanceState );
|
||||
}
|
||||
|
||||
protected boolean onBackPressed()
|
||||
{
|
||||
LocUtils.saveData( m_activity );
|
||||
return false;
|
||||
}
|
||||
|
||||
private void init( Bundle savedInstanceState )
|
||||
{
|
||||
m_activity.setContentView( R.layout.loc_main );
|
||||
|
|
|
@ -33,6 +33,7 @@ import junit.framework.Assert;
|
|||
|
||||
import org.eehouse.android.xw4.R;
|
||||
import org.eehouse.android.xw4.DbgUtils;
|
||||
import org.eehouse.android.xw4.DBUtils;
|
||||
|
||||
public class LocUtils {
|
||||
// Keep this in sync with gen_loc_ids.py and what's used in the menu.xml
|
||||
|
@ -115,6 +116,11 @@ public class LocUtils {
|
|||
return result;
|
||||
}
|
||||
|
||||
public static void saveData( Context context )
|
||||
{
|
||||
DBUtils.saveXlations( context, "te_ST", s_xlations );
|
||||
}
|
||||
|
||||
private static void xlateMenu( final Activity activity, Menu menu,
|
||||
int depth )
|
||||
{
|
||||
|
@ -161,7 +167,7 @@ public class LocUtils {
|
|||
private static void loadXlations( Context context )
|
||||
{
|
||||
if ( null == s_xlations ) {
|
||||
s_xlations = new HashMap<String, String>();
|
||||
s_xlations = DBUtils.getXlations( context, "te_ST" );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue