11package servicestack .net .techstacks ;
22
3+ import android .content .Intent ;
4+ import android .graphics .Bitmap ;
35import android .support .v7 .app .ActionBarActivity ;
46import android .support .v7 .app .ActionBar ;
57import android .support .v4 .app .Fragment ;
1820import android .widget .AdapterView ;
1921import android .widget .ArrayAdapter ;
2022import android .widget .EditText ;
23+ import android .widget .ImageView ;
2124import android .widget .ListView ;
2225import android .widget .Spinner ;
26+ import android .widget .TextView ;
2327
2428import com .android .internal .util .Predicate ;
2529
@@ -193,7 +197,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
193197
194198 final View rootView = inflater .inflate (R .layout .fragment_top_rated , container , false );
195199
196- Spinner spinner = (Spinner )rootView .findViewById (R .id .spinnerCategory );
200+ Spinner spinner = (Spinner ) rootView .findViewById (R .id .spinnerCategory );
197201 spinner .setOnItemSelectedListener (new AdapterView .OnItemSelectedListener () {
198202 @ Override
199203 public void onItemSelected (AdapterView <?> parent , View view , int position , long id ) {
@@ -206,25 +210,37 @@ public void onNothingSelected(AdapterView<?> parent) {
206210 selectedCategory = null ;
207211 }
208212 });
213+ ListView list = (ListView ) rootView .findViewById (R .id .listTopRated );
214+ list .setOnItemClickListener (new AdapterView .OnItemClickListener () {
215+ @ Override
216+ public void onItemClick (AdapterView <?> parent , View view , int position , long id ) {
217+ TechnologyInfo result = getTopTechnologies (App .getData ()).get (position );
218+ Intent intent = new Intent (getActivity (), TechnologyActivity .class );
219+ intent .putExtra ("slug" , result .getSlug ());
220+ startActivity (intent );
221+ // getActivity().getSupportFragmentManager().beginTransaction()
222+ // .replace(R.id.pager, TechnologyFragment.create(result.getSlug())).commit();
223+ }
224+ });
209225
210226 return rootView ;
211227 }
212228
213- Spinner getCategorySpinner (){
229+ Spinner getCategorySpinner () {
214230 if (getActivity () == null )
215231 return null ;
216232 return (Spinner ) getActivity ().findViewById (R .id .spinnerCategory );
217233 }
218234
219- ListView getTopRatedListView (){
235+ ListView getTopRatedListView () {
220236 if (getActivity () == null )
221237 return null ;
222238 return (ListView ) getActivity ().findViewById (R .id .listTopRated );
223239 }
224240
225241 @ Override
226242 public void onUpdate (App .AppData data , App .DataType dataType ) {
227- switch (dataType ){
243+ switch (dataType ) {
228244 case AppOverview :
229245 Spinner spinner = getCategorySpinner ();
230246 if (spinner != null ) {
@@ -246,22 +262,26 @@ public String apply(Option option) {
246262 }
247263
248264 private void refreshTopTechnologies (App .AppData data , ListView list ) {
265+ ArrayList <String > topTechnologyNames = map (getTopTechnologies (data ), new Function <TechnologyInfo , String >() {
266+ @ Override
267+ public String apply (TechnologyInfo technologyInfo ) {
268+ return technologyInfo .getName () + " (" + technologyInfo .getStacksCount () + ")" ;
269+ }
270+ });
271+ list .setAdapter (new ArrayAdapter <>(getActivity (), android .R .layout .simple_list_item_1 , topTechnologyNames ));
272+ }
273+
274+ private ArrayList <TechnologyInfo > getTopTechnologies (App .AppData data ) {
249275 ArrayList <TechnologyInfo > topTechnologies = data .getAppOverviewResponse ().getTopTechnologies ();
250- if (selectedCategory != null && selectedCategory .getValue () != null ){
276+ if (selectedCategory != null && selectedCategory .getValue () != null ) {
251277 topTechnologies = filter (topTechnologies , new Predicate <TechnologyInfo >() {
252278 @ Override
253279 public boolean apply (TechnologyInfo tech ) {
254280 return tech .getTier () == selectedCategory .getValue ();
255281 }
256282 });
257283 }
258- ArrayList <String > topTechnologyNames = map (topTechnologies , new Function <TechnologyInfo , String >() {
259- @ Override
260- public String apply (TechnologyInfo technologyInfo ) {
261- return technologyInfo .getName () + " (" + technologyInfo .getStacksCount () + ")" ;
262- }
263- });
264- list .setAdapter (new ArrayAdapter <>(getActivity (), android .R .layout .simple_list_item_1 , topTechnologyNames ));
284+ return topTechnologies ;
265285 }
266286 }
267287
@@ -285,21 +305,26 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
285305 Bundle savedInstanceState ) {
286306 View rootView = inflater .inflate (R .layout .fragment_tech_stacks , container , false );
287307
288- EditText txtSearch = (EditText )rootView .findViewById (R .id .searchTechStacks );
308+ EditText txtSearch = (EditText ) rootView .findViewById (R .id .searchTechStacks );
289309 txtSearch .addTextChangedListener (new TextWatcher () {
290310 @ Override
291311 public void onTextChanged (CharSequence s , int start , int before , int count ) {
292312 App .getData ().searchTechStacks (s .toString ());
293313 }
294314
295- @ Override public void beforeTextChanged (CharSequence s , int start , int count , int after ) {}
296- @ Override public void afterTextChanged (Editable s ) {}
315+ @ Override
316+ public void beforeTextChanged (CharSequence s , int start , int count , int after ) {
317+ }
318+
319+ @ Override
320+ public void afterTextChanged (Editable s ) {
321+ }
297322 });
298323
299324 return rootView ;
300325 }
301326
302- ListView getListViewResults (){
327+ ListView getListViewResults () {
303328 if (getActivity () == null )
304329 return null ;
305330 return (ListView ) getActivity ().findViewById (R .id .listTechStacks );
@@ -310,7 +335,7 @@ public void onUpdate(App.AppData data, App.DataType dataType) {
310335 switch (dataType ) {
311336 case SearchTechStacks :
312337 ListView list = getListViewResults ();
313- if (list != null ){
338+ if (list != null ) {
314339 ArrayList <String > results = map (data .getSearchTechStacksResponse ().getResults (), new Function <TechnologyStack , String >() {
315340 @ Override
316341 public String apply (TechnologyStack o ) {
@@ -344,21 +369,26 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
344369 Bundle savedInstanceState ) {
345370 View rootView = inflater .inflate (R .layout .fragment_technologies , container , false );
346371
347- EditText txtSearch = (EditText )rootView .findViewById (R .id .searchTechnologies );
372+ EditText txtSearch = (EditText ) rootView .findViewById (R .id .searchTechnologies );
348373 txtSearch .addTextChangedListener (new TextWatcher () {
349374 @ Override
350375 public void onTextChanged (CharSequence s , int start , int before , int count ) {
351376 App .getData ().searchTechnologies (s .toString ());
352377 }
353378
354- @ Override public void beforeTextChanged (CharSequence s , int start , int count , int after ) {}
355- @ Override public void afterTextChanged (Editable s ) {}
379+ @ Override
380+ public void beforeTextChanged (CharSequence s , int start , int count , int after ) {
381+ }
382+
383+ @ Override
384+ public void afterTextChanged (Editable s ) {
385+ }
356386 });
357387
358388 return rootView ;
359389 }
360390
361- ListView getListViewResults (){
391+ ListView getListViewResults () {
362392 if (getActivity () == null )
363393 return null ;
364394 return (ListView ) getActivity ().findViewById (R .id .listTechnologies );
@@ -369,7 +399,7 @@ public void onUpdate(App.AppData data, App.DataType dataType) {
369399 switch (dataType ) {
370400 case SearchTechnologies :
371401 ListView list = getListViewResults ();
372- if (list != null ){
402+ if (list != null ) {
373403 ArrayList <String > results = map (data .getSearchTechnologiesResponse ().getResults (), new Function <Technology , String >() {
374404 @ Override
375405 public String apply (Technology o ) {
@@ -383,4 +413,67 @@ public String apply(Technology o) {
383413 }
384414 }
385415
416+ public static class TechnologyFragment extends Fragment implements App .AppDataListener {
417+ String slug ;
418+
419+ public static TechnologyFragment create (String slug ) {
420+ TechnologyFragment fragment = new TechnologyFragment ();
421+ Bundle args = new Bundle ();
422+ args .putString ("slug" , slug );
423+ fragment .setArguments (args );
424+ return fragment ;
425+ }
426+
427+ @ Override
428+ public void onCreate (Bundle savedInstanceState ) {
429+ super .onCreate (savedInstanceState );
430+ App .getData ().addListener (this );
431+ }
432+
433+ @ Override
434+ public View onCreateView (LayoutInflater inflater , ViewGroup container ,
435+ Bundle savedInstanceState ) {
436+
437+ App .getData ().loadTechnology (getArguments ().getString ("slug" ));
438+
439+ View rootView = inflater .inflate (R .layout .fragment_technology , container , false );
440+
441+ return rootView ;
442+ }
443+
444+ @ Override
445+ public void onUpdate (App .AppData data , App .DataType dataType ) {
446+ switch (dataType ){
447+ case Technology :
448+
449+ GetTechnologyResponse result = data .getTechnology ();
450+ TextView lblName = (TextView ) getActivity ().findViewById (R .id .lblTechnologyName );
451+ if (lblName == null ) return ;
452+ lblName .setText (result .getTechnology ().getName ());
453+
454+ TextView lblVendor = (TextView ) getActivity ().findViewById (R .id .lblTechnologyVendor );
455+ if (lblVendor == null ) return ;
456+ lblVendor .setText (result .getTechnology ().getVendorName ());
457+
458+ TextView lblVendorUrl = (TextView ) getActivity ().findViewById (R .id .lblTechnologyVendorUrl );
459+ if (lblVendorUrl == null ) return ;
460+ lblVendorUrl .setText (result .getTechnology ().getVendorUrl ());
461+
462+ String logoUrl = result .getTechnology ().getLogoUrl ();
463+ if (logoUrl == null ) return ;
464+ final ImageView imgLogo = (ImageView ) getActivity ().findViewById (R .id .imgTechnologyLogo );
465+ if (imgLogo == null ) return ;
466+
467+ data .loadImage (logoUrl , new App .ImageResult () {
468+ @ Override
469+ public void success (Bitmap img ) {
470+ imgLogo .setImageBitmap (img );
471+ }
472+ });
473+
474+ break ;
475+ }
476+ }
477+
478+ }
386479}
0 commit comments