diff --git a/xwords4/android/XWords4/res/layout/studylist.xml b/xwords4/android/XWords4/res/layout/studylist.xml index daab666c8..83e591a1f 100644 --- a/xwords4/android/XWords4/res/layout/studylist.xml +++ b/xwords4/android/XWords4/res/layout/studylist.xml @@ -9,7 +9,6 @@ > + + diff --git a/xwords4/android/XWords4/res/values/strings.xml b/xwords4/android/XWords4/res/values/strings.xml index c85f7b9aa..d27363180 100644 --- a/xwords4/android/XWords4/res/values/strings.xml +++ b/xwords4/android/XWords4/res/values/strings.xml @@ -2204,18 +2204,17 @@ Rate Crosswords Google Play app not found - Add %s to study list - Enable study lists + Add %s to studylist + Enable studylists Offer to add to and display lists of words to remember - Study list… - Choose list language + Studylist… Copy to clipboard Clear all Are you sure you want to - remove all the words in this list?\n\n(This action cannot be - undone.) + delete this list?\n\n(This action cannot be undone.) %d word[s] copied + Studylist for %s diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardActivity.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardActivity.java index b3e84514f..7ea2340af 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardActivity.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardActivity.java @@ -804,6 +804,9 @@ public class BoardActivity extends XWActivity Utils.setItemVisible( menu, R.id.gamel_menu_checkmoves, false ); } + boolean enable = 0 < DBUtils.studyListLangs( this ).length; + Utils.setItemVisible( menu, R.id.games_menu_study, enable ); + return true; } // onPrepareOptionsMenu @@ -867,6 +870,9 @@ public class BoardActivity extends XWActivity case R.id.board_menu_tray: cmd = JNICmd.CMD_TOGGLE_TRAY; break; + case R.id.games_menu_study: + StudyList.launch( this, m_gi.dictLang ); + break; case R.id.board_menu_undo_current: cmd = JNICmd.CMD_UNDO_CUR; break; diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DlgDelegate.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DlgDelegate.java index d3381f765..096256408 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DlgDelegate.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DlgDelegate.java @@ -253,13 +253,9 @@ public class DlgDelegate { } } - public void launchLookup( String[] words, int lang, boolean forceList ) + public void launchLookup( String[] words, int lang, boolean noStudyOption ) { - Intent intent = new Intent( m_activity, LookupActivity.class ); - intent.putExtra( LookupActivity.WORDS, words ); - intent.putExtra( LookupActivity.LANG, lang ); - - m_activity.startActivity( intent ); + LookupActivity.launch( m_activity, words, lang, noStudyOption ); } public void startProgress( int id ) diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GamesList.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GamesList.java index 5f7dfbab4..e9b7afebf 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GamesList.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GamesList.java @@ -790,7 +790,7 @@ public class GamesList extends XWExpandableListActivity break; case R.id.games_menu_study: - StudyList.launch( this ); + StudyList.launch( this, StudyList.NO_LANG ); break; case R.id.games_menu_about: diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/LookupActivity.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/LookupActivity.java index 3d008e271..088690ce5 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/LookupActivity.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/LookupActivity.java @@ -20,6 +20,7 @@ package org.eehouse.android.xw4; +import android.app.Activity; import android.content.Context; import android.content.Intent; import android.content.res.Resources; @@ -41,6 +42,7 @@ public class LookupActivity extends XWListActivity public static final String WORDS = "WORDS"; public static final String LANG = "LANG"; + public static final String NOSTUDY = "NOSTUDY"; private static final String FORCELIST = "FORCELIST"; private static final String STATE = "STATE"; private static final String WORDINDEX = "WORDINDEX"; @@ -83,6 +85,9 @@ public class LookupActivity extends XWListActivity setLang( intent.getIntExtra( LANG, -1 ) ); m_forceList = intent.getBooleanExtra( FORCELIST, false ); m_studyOn = XWPrefs.getStudyEnabled( this ); + if ( m_studyOn ) { + m_studyOn = !intent.getBooleanExtra( NOSTUDY, false ); + } m_state = STATE_DONE; adjustState( 1 ); @@ -195,7 +200,9 @@ public class LookupActivity extends XWListActivity m_doneButton.setText( txt ); txt = Utils.format( this, R.string.add_to_studyf, m_words[m_wordIndex] ); - m_studyButton.setVisibility( View.VISIBLE ); + if ( m_studyOn ) { + m_studyButton.setVisibility( View.VISIBLE ); + } m_studyButton.setText( txt ); break; case STATE_LOOKUP: @@ -263,4 +270,15 @@ public class LookupActivity extends XWListActivity String title = Utils.format( this, R.string.pick_url_titlef, word ); m_summary.setText( title ); } + + public static void launch( Activity activity, String[] words, int lang, + boolean noStudyOption ) + { + Intent intent = new Intent( activity, LookupActivity.class ); + intent.putExtra( WORDS, words ); + intent.putExtra( LANG, lang ); + intent.putExtra( NOSTUDY, noStudyOption ); + + activity.startActivity( intent ); + } } diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/StudyList.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/StudyList.java index 134461313..23a343b02 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/StudyList.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/StudyList.java @@ -19,6 +19,7 @@ package org.eehouse.android.xw4; +import android.widget.ListView; import android.app.AlertDialog; import android.content.Context; import android.content.Intent; @@ -39,7 +40,10 @@ import junit.framework.Assert; public class StudyList extends XWListActivity implements OnItemSelectedListener { + public static final int NO_LANG = -1; + private static final int CLEAR_ACTION = 1; + private static final String START_LANG = "START_LANG"; private Spinner m_spinner; private int[] m_langCodes; @@ -54,7 +58,7 @@ public class StudyList extends XWListActivity setContentView( R.layout.studylist ); m_spinner = (Spinner)findViewById( R.id.pick_language ); - initOrFinish(); + initOrFinish( getIntent() ); } @Override @@ -101,7 +105,7 @@ public class StudyList extends XWListActivity switch ( id ) { case CLEAR_ACTION: DBUtils.studyListClear( this, m_langCodes[m_position] ); - initOrFinish(); + initOrFinish( null ); break; default: Assert.fail(); @@ -110,6 +114,13 @@ public class StudyList extends XWListActivity } } + @Override + public void onListItemClick( ListView lv, View view, int position, long id ) + { + String[] words = { m_words[position] }; + launchLookup( words, m_langCodes[m_position], true ); + } + ////////////////////////////////////////////////// // AdapterView.OnItemSelectedListener interface ////////////////////////////////////////////////// @@ -136,9 +147,13 @@ public class StudyList extends XWListActivity // adapter.sort(); setListAdapter( adapter ); + + String langName = DictLangCache.getLangNames( this )[lang]; + String title = getString( R.string.studylist_titlef, langName ); + setTitle( title ); } - private void initOrFinish() + private void initOrFinish( Intent startIntent ) { m_langCodes = DBUtils.studyListLangs( this ); if ( 0 == m_langCodes.length ) { @@ -148,10 +163,20 @@ public class StudyList extends XWListActivity m_position = 0; loadList(); } else { + int startLang = NO_LANG; + int startIndex = -1; + if ( null != startIntent ) { + startLang = startIntent.getIntExtra( START_LANG, NO_LANG ); + } + String[] names = DictLangCache.getLangNames( this ); String[] myNames = new String[m_langCodes.length]; for ( int ii = 0; ii < m_langCodes.length; ++ii ) { - myNames[ii] = names[m_langCodes[ii]]; + int lang = m_langCodes[ii]; + myNames[ii] = names[lang]; + if ( lang == startLang ) { + startIndex = ii; + } } ArrayAdapter adapter = new @@ -162,12 +187,18 @@ public class StudyList extends XWListActivity simple_spinner_dropdown_item ); m_spinner.setAdapter( adapter ); m_spinner.setOnItemSelectedListener( this ); + if ( -1 != startIndex ) { + m_spinner.setSelection( startIndex ); + } } } - public static void launch( Context context ) + public static void launch( Context context, int lang ) { Intent intent = new Intent( context, StudyList.class ); + if ( NO_LANG != lang ) { + intent.putExtra( START_LANG, lang ); + } context.startActivity( intent ); } diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWListActivity.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWListActivity.java index 3e54da2fd..a63412158 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWListActivity.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWListActivity.java @@ -168,16 +168,16 @@ public class XWListActivity extends ListActivity Assert.fail(); } + protected void launchLookup( String[] words, int lang, boolean noStudy ) + { + m_delegate.launchLookup( words, lang, noStudy ); + } + protected void launchLookup( String[] words, int lang ) { m_delegate.launchLookup( words, lang, false ); } - protected void launchLookup( String[] words, int lang, boolean forceList ) - { - m_delegate.launchLookup( words, lang, forceList ); - } - // MultiService.MultiEventListener interface public void eventOccurred( MultiService.MultiEvent event, final Object ... args )