88import android .support .v4 .app .FragmentPagerAdapter ;
99import android .os .Bundle ;
1010import android .support .v4 .view .ViewPager ;
11+ import android .text .Editable ;
12+ import android .text .TextWatcher ;
1113import android .view .LayoutInflater ;
1214import android .view .Menu ;
1315import android .view .MenuItem ;
1416import android .view .View ;
1517import android .view .ViewGroup ;
1618import android .widget .AdapterView ;
1719import android .widget .ArrayAdapter ;
20+ import android .widget .EditText ;
1821import android .widget .ListView ;
1922import android .widget .Spinner ;
2023
2629
2730import static net .servicestack .client .Func .map ;
2831
29- import servicestack .net .techstacks .techstacksdtos .*;
32+ import servicestack .net .techstacks .dto .*;
3033
3134public class MainActivity extends ActionBarActivity implements ActionBar .TabListener {
3235
@@ -180,7 +183,6 @@ public static TopRatedFragment create(int sectionNumber) {
180183 @ Override
181184 public void onCreate (Bundle savedInstanceState ) {
182185 super .onCreate (savedInstanceState );
183-
184186 App .getData ().addListener (this );
185187 }
186188
@@ -191,12 +193,12 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
191193
192194 final View rootView = inflater .inflate (R .layout .fragment_top_rated , container , false );
193195
194- Spinner spinner = (Spinner )rootView .findViewById (R .id .spinner_category );
196+ Spinner spinner = (Spinner )rootView .findViewById (R .id .spinnerCategory );
195197 spinner .setOnItemSelectedListener (new AdapterView .OnItemSelectedListener () {
196198 @ Override
197199 public void onItemSelected (AdapterView <?> parent , View view , int position , long id ) {
198200 selectedCategory = App .getData ().getAppOverviewResponse ().getAllTiers ().get (position );
199- refreshTopTechnologies (App .getData (), (ListView ) rootView .findViewById (R .id .list_results ));
201+ refreshTopTechnologies (App .getData (), (ListView ) rootView .findViewById (R .id .listTopRated ));
200202 }
201203
202204 @ Override
@@ -211,13 +213,13 @@ public void onNothingSelected(AdapterView<?> parent) {
211213 Spinner getCategorySpinner (){
212214 if (getActivity () == null )
213215 return null ;
214- return (Spinner ) getActivity ().findViewById (R .id .spinner_category );
216+ return (Spinner ) getActivity ().findViewById (R .id .spinnerCategory );
215217 }
216218
217- ListView getResultsList (){
219+ ListView getTopRatedListView (){
218220 if (getActivity () == null )
219221 return null ;
220- return (ListView ) getActivity ().findViewById (R .id .list_results );
222+ return (ListView ) getActivity ().findViewById (R .id .listTopRated );
221223 }
222224
223225 @ Override
@@ -235,7 +237,7 @@ public String apply(Option option) {
235237 spinner .setAdapter (new ArrayAdapter <>(getActivity (), android .R .layout .simple_spinner_item , categories ));
236238 }
237239
238- ListView list = getResultsList ();
240+ ListView list = getTopRatedListView ();
239241 if (list != null ) {
240242 refreshTopTechnologies (data , list );
241243 }
@@ -263,7 +265,7 @@ public String apply(TechnologyInfo technologyInfo) {
263265 }
264266 }
265267
266- public static class TechStacksFragment extends Fragment {
268+ public static class TechStacksFragment extends Fragment implements App . AppDataListener {
267269 public static TechStacksFragment create (int sectionNumber ) {
268270 TechStacksFragment fragment = new TechStacksFragment ();
269271 Bundle args = new Bundle ();
@@ -272,12 +274,61 @@ public static TechStacksFragment create(int sectionNumber) {
272274 return fragment ;
273275 }
274276
277+ @ Override
278+ public void onCreate (Bundle savedInstanceState ) {
279+ super .onCreate (savedInstanceState );
280+ App .getData ().addListener (this );
281+ }
282+
275283 @ Override
276284 public View onCreateView (LayoutInflater inflater , ViewGroup container ,
277285 Bundle savedInstanceState ) {
278286 View rootView = inflater .inflate (R .layout .fragment_tech_stacks , container , false );
287+
288+ EditText txtSearch = (EditText )rootView .findViewById (R .id .searchTechStacks );
289+ txtSearch .addTextChangedListener (new TextWatcher () {
290+ @ Override
291+ public void onTextChanged (CharSequence s , int start , int before , int count ) {
292+ App .getData ().searchTechStacks (s .toString ());
293+ }
294+
295+ @ Override public void beforeTextChanged (CharSequence s , int start , int count , int after ) {}
296+ @ Override public void afterTextChanged (Editable s ) {}
297+ });
298+
279299 return rootView ;
280300 }
301+
302+ EditText getSearchTechStacks (){
303+ if (getActivity () == null )
304+ return null ;
305+ return (EditText ) getActivity ().findViewById (R .id .searchTechStacks );
306+ }
307+
308+ ListView getTechStacksListView (){
309+ if (getActivity () == null )
310+ return null ;
311+ return (ListView ) getActivity ().findViewById (R .id .listTechStacks );
312+ }
313+
314+ @ Override
315+ public void onUpdate (App .AppData data , App .DataType dataType ) {
316+ switch (dataType ) {
317+ case SearchTechStacks :
318+ ListView list = getTechStacksListView ();
319+ if (list != null ){
320+ ArrayList <TechnologyStack > searchResults = data .getSearchTechStacksResponse ().getResults ();
321+ ArrayList <String > results = map (searchResults , new Function <TechnologyStack , String >() {
322+ @ Override
323+ public String apply (TechnologyStack o ) {
324+ return o .getName ();
325+ }
326+ });
327+ list .setAdapter (new ArrayAdapter <>(getActivity (), android .R .layout .simple_list_item_1 , results ));
328+ }
329+ break ;
330+ }
331+ }
281332 }
282333
283334 public static class TechnologiesFragment extends Fragment {
0 commit comments