Skip to content

Commit 2b5cfce

Browse files
committed
Add new Technology Fragment and Intent
1 parent bc253b9 commit 2b5cfce

File tree

5 files changed

+286
-22
lines changed

5 files changed

+286
-22
lines changed

src/AndroidClient/techstacks/src/main/AndroidManifest.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@
1515
<category android:name="android.intent.category.LAUNCHER" />
1616
</intent-filter>
1717
</activity>
18+
<activity
19+
android:name=".TechnologyActivity"
20+
android:label="Technology" >
21+
<intent-filter>
22+
<action android:name="android.intent.action.VIEW" />
23+
<category android:name="android.intent.category.DEFAULT" />
24+
</intent-filter>
25+
</activity>
1826
</application>
1927

2028
</manifest>

src/AndroidClient/techstacks/src/main/java/servicestack/net/techstacks/MainActivity.java

Lines changed: 115 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package servicestack.net.techstacks;
22

3+
import android.content.Intent;
4+
import android.graphics.Bitmap;
35
import android.support.v7.app.ActionBarActivity;
46
import android.support.v7.app.ActionBar;
57
import android.support.v4.app.Fragment;
@@ -18,8 +20,10 @@
1820
import android.widget.AdapterView;
1921
import android.widget.ArrayAdapter;
2022
import android.widget.EditText;
23+
import android.widget.ImageView;
2124
import android.widget.ListView;
2225
import android.widget.Spinner;
26+
import android.widget.TextView;
2327

2428
import 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
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package servicestack.net.techstacks;
2+
3+
import android.app.Activity;
4+
import android.graphics.Bitmap;
5+
import android.os.Bundle;
6+
import android.widget.ImageView;
7+
import android.widget.TextView;
8+
9+
public class TechnologyActivity extends Activity implements App.AppDataListener {
10+
11+
@Override
12+
protected void onCreate(Bundle savedInstanceState) {
13+
super.onCreate(savedInstanceState);
14+
setContentView(R.layout.activity_technology);
15+
App.getData().addListener(this);
16+
17+
Bundle extras = getIntent().getExtras();
18+
App.getData().loadTechnology(extras.getString("slug"));
19+
}
20+
21+
public Activity getActivity(){
22+
return this;
23+
}
24+
25+
@Override
26+
public void onUpdate(App.AppData data, App.DataType dataType) {
27+
switch (dataType){
28+
case Technology:
29+
30+
dto.GetTechnologyResponse result = data.getTechnology();
31+
TextView lblName = (TextView) getActivity().findViewById(R.id.lblTechnologyName);
32+
if (lblName == null) return;
33+
lblName.setText(result.getTechnology().getName());
34+
35+
TextView lblVendor = (TextView) getActivity().findViewById(R.id.lblTechnologyVendor);
36+
if (lblVendor == null) return;
37+
lblVendor.setText(result.getTechnology().getVendorName());
38+
39+
TextView lblVendorUrl = (TextView) getActivity().findViewById(R.id.lblTechnologyVendorUrl);
40+
if (lblVendorUrl == null) return;
41+
lblVendorUrl.setText(result.getTechnology().getVendorUrl());
42+
43+
String logoUrl = result.getTechnology().getLogoUrl();
44+
if (logoUrl == null) return;
45+
final ImageView imgLogo = (ImageView) getActivity().findViewById(R.id.imgTechnologyLogo);
46+
if (imgLogo == null) return;
47+
48+
data.loadImage(logoUrl, new App.ImageResult() {
49+
@Override
50+
public void success(Bitmap img) {
51+
imgLogo.setImageBitmap(img);
52+
}
53+
});
54+
55+
break;
56+
}
57+
}
58+
59+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:orientation="vertical" android:layout_width="match_parent"
4+
android:layout_height="match_parent">
5+
6+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
7+
android:layout_width="fill_parent"
8+
android:layout_height="fill_parent"
9+
android:orientation="horizontal" >
10+
11+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
12+
android:layout_width="fill_parent"
13+
android:layout_height="fill_parent"
14+
android:orientation="vertical" >
15+
16+
<TextView
17+
android:id="@+id/lblTechnologyName"
18+
android:layout_width="wrap_content"
19+
android:layout_height="wrap_content"
20+
android:text="Name"/>
21+
22+
<TextView
23+
android:id="@+id/lblTechnologyVendor"
24+
android:layout_width="wrap_content"
25+
android:layout_height="wrap_content"
26+
android:text="Vendor"/>
27+
</LinearLayout>
28+
29+
<ImageView
30+
android:id="@+id/imgTechnologyLogo"
31+
android:layout_width="wrap_content"
32+
android:layout_height="wrap_content" />
33+
34+
</LinearLayout>
35+
36+
<TextView
37+
android:id="@+id/lblTechnologyVendorUrl"
38+
android:layout_width="wrap_content"
39+
android:layout_height="wrap_content"
40+
android:text="url.com"/>
41+
42+
<ListView
43+
android:id="@+id/listTechnologyTechStacks"
44+
android:layout_width="fill_parent"
45+
android:layout_height="wrap_content" />
46+
47+
</LinearLayout>

0 commit comments

Comments
 (0)