derive context from menu that's triggered from it rather than trying

to set it from onResume() calls.
This commit is contained in:
Eric House 2014-05-16 22:05:48 -07:00
parent 3c4ed7de46
commit dfbb1bae71
4 changed files with 28 additions and 38 deletions

View file

@ -61,15 +61,11 @@ public class DelegateBase implements DlgDelegate.DlgClickNotify,
public boolean onPrepareOptionsMenu( Menu menu ) { return false; }
public boolean onOptionsItemSelected( MenuItem item ) { return false; }
protected void onStart() {}
protected void onResume() {}
protected void onPause() {}
protected void onStop() {}
protected void onDestroy() {}
protected void onResume()
{
LocUtils.setLatestContext( m_activity );
}
// public boolean onOptionsItemSelected( MenuItem item )
// {
// }

View file

@ -90,7 +90,8 @@ public class LocDelegate extends ListDelegateBase
m_filterBy.setOnItemSelectedListener( this );
LocSearcher.Pair[] pairs = LocUtils.makePairs( m_activity );
m_searcher = new LocSearcher( m_activity, pairs );
String contextName = getIntent().getStringExtra( LocUtils.CONTEXT_NAME );
m_searcher = new LocSearcher( m_activity, pairs, contextName );
makeNewAdapter();
}

View file

@ -33,6 +33,8 @@ import org.eehouse.android.xw4.DbgUtils;
public class LocSearcher {
private String m_contextName;
private interface FilterFunc {
public boolean passes( Context context, Pair pair );
}
@ -77,10 +79,11 @@ public class LocSearcher {
private Pair[] m_matchingPairs;
private String m_lastTerm;
public LocSearcher( Context context, Pair pairs[] )
public LocSearcher( Context context, Pair pairs[], String contextName )
{
m_pairs = m_filteredPairs = m_matchingPairs = pairs;
m_context = context;
m_contextName = contextName;
}
protected void start( int position )
@ -93,10 +96,10 @@ public class LocSearcher {
if ( SHOW_BYS.LOC_FILTERS_ALL == showBy ) {
m_filteredPairs = m_pairs;
} else {
FilterFunc proc = s_falseProc;
FilterFunc proc = null;
switch ( showBy ) {
case LOC_FILTERS_SCREEN:
proc = s_screenProc;
proc = new ScreenFilter( m_contextName );
break;
case LOC_FILTERS_MENU:
proc = s_menuProc;
@ -158,24 +161,22 @@ public class LocSearcher {
}
};
private static FilterFunc s_screenProc = new FilterFunc() {
public boolean passes( Context context, Pair pair ) {
return LocUtils.inLatestScreen( pair.getKey() );
}
};
private static FilterFunc s_menuProc = new FilterFunc() {
public boolean passes( Context context, Pair pair ) {
return LocUtils.inLatestMenu( pair.getKey() );
}
};
// Remove later
private static FilterFunc s_falseProc = new FilterFunc() {
public boolean passes( Context context, Pair pair ) {
return false;
}
};
private static class ScreenFilter implements FilterFunc {
private String m_contextName;
public ScreenFilter( String contextName )
{
m_contextName = contextName;
}
public boolean passes( Context context, Pair pair )
{
return LocUtils.inLatestScreen( pair.getKey(), m_contextName );
}
}
}

View file

@ -68,6 +68,7 @@ import org.eehouse.android.xw4.Utils;
import org.eehouse.android.xw4.XWPrefs;
public class LocUtils {
public static final String CONTEXT_NAME = "CONTEXT_NAME";
private static final int FMT_LEN = 4;
private static final String k_LOCALE = "locale";
private static final String k_XLATEVERS = "xlatevers";
@ -81,8 +82,6 @@ public class LocUtils {
private static WeakReference<Menu> s_latestMenuRef;
private static HashMap<WeakReference<Menu>, HashSet<String> > s_menuSets
= new HashMap<WeakReference<Menu>, HashSet<String> >();
private static String s_latestContextName;
private static String s_newContextName;
private static HashMap<String, HashSet<String> > s_contextSets
= new HashMap<String, HashSet<String> >();
@ -95,14 +94,6 @@ public class LocUtils {
s_enabled = null;
}
public static void setLatestContext( Context context )
{
String newName = context.getClass().getName();
s_latestContextName = s_newContextName;
s_newContextName = newName;
DbgUtils.logf( "setLatestContext(%s): now %s", newName, s_latestContextName );
}
public static View inflate( Context context, int resID )
{
LayoutInflater factory = LayoutInflater.from( context );
@ -416,6 +407,8 @@ public class LocUtils {
Intent intent =
new Intent( activity, LocActivity.class );
intent.putExtra( CONTEXT_NAME,
activity.getClass().getName() );
activity.startActivity( intent );
return true;
}
@ -583,14 +576,13 @@ public class LocUtils {
return result;
}
public static boolean inLatestScreen( String key )
public static boolean inLatestScreen( String key, String contextName )
{
boolean result = false;
Assert.assertNotNull( s_latestContextName );
HashSet<String> keys = s_contextSets.get( s_latestContextName );
Assert.assertNotNull( keys ); // failing
result = keys.contains( key );
// DbgUtils.logf( "inLatestScreen(%s [in %s])=>%b", key, s_latestContextName, result );
HashSet<String> keys = s_contextSets.get( contextName );
if ( null != keys ) {
result = keys.contains( key );
}
return result;
}