Skip to content

Commit d45a81f

Browse files
committed
Update TechStacks App using latest ServiceClient and dto's
1 parent d2dbf0c commit d45a81f

File tree

10 files changed

+133
-49
lines changed

10 files changed

+133
-49
lines changed

src/AndroidClient/android/android.iml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,10 @@
8686
</content>
8787
<orderEntry type="jdk" jdkName="Android API 21 Platform" jdkType="Android SDK" />
8888
<orderEntry type="sourceFolder" forTests="false" />
89-
<orderEntry type="library" exported="" name="gson-2.3.1" level="project" />
9089
<orderEntry type="library" exported="" name="appcompat-v7-21.0.3" level="project" />
91-
<orderEntry type="library" exported="" name="support-annotations-21.0.3" level="project" />
90+
<orderEntry type="library" exported="" name="gson-2.3.1" level="project" />
9291
<orderEntry type="library" exported="" name="support-v4-21.0.3" level="project" />
92+
<orderEntry type="library" exported="" name="support-annotations-21.0.3" level="project" />
9393
<orderEntry type="module" module-name="client" exported="" />
9494
</component>
9595
</module>

src/AndroidClient/app/app.iml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,10 @@
8585
</content>
8686
<orderEntry type="jdk" jdkName="Android API 21 Platform" jdkType="Android SDK" />
8787
<orderEntry type="sourceFolder" forTests="false" />
88-
<orderEntry type="library" exported="" name="gson-2.3.1" level="project" />
8988
<orderEntry type="library" exported="" name="appcompat-v7-21.0.3" level="project" />
90-
<orderEntry type="library" exported="" name="support-annotations-21.0.3" level="project" />
89+
<orderEntry type="library" exported="" name="gson-2.3.1" level="project" />
9190
<orderEntry type="library" exported="" name="support-v4-21.0.3" level="project" />
91+
<orderEntry type="library" exported="" name="support-annotations-21.0.3" level="project" />
9292
<orderEntry type="module" module-name="android" exported="" />
9393
</component>
9494
</module>

src/AndroidClient/client/build.gradle

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -92,26 +92,3 @@ dependencies {
9292
compile 'com.android.support:appcompat-v7:21.0.3'
9393
compile 'com.google.code.gson:gson:2.3.1'
9494
}
95-
96-
task sourcesJar(type: Jar) {
97-
from android.sourceSets.main.java.srcDirs
98-
classifier = 'sources'
99-
}
100-
101-
task javadoc(type: Javadoc) {
102-
source = android.sourceSets.main.java.srcDirs
103-
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
104-
}
105-
106-
task javadocJar(type: Jar, dependsOn: javadoc) {
107-
classifier = 'javadoc'
108-
from javadoc.destinationDir
109-
}
110-
artifacts {
111-
archives javadocJar
112-
archives sourcesJar
113-
}
114-
115-
task findConventions << {
116-
println project.getConvention()
117-
}

src/AndroidClient/client/client.iml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,10 @@
8686
</content>
8787
<orderEntry type="jdk" jdkName="Android API 21 Platform" jdkType="Android SDK" />
8888
<orderEntry type="sourceFolder" forTests="false" />
89-
<orderEntry type="library" exported="" name="gson-2.3.1" level="project" />
9089
<orderEntry type="library" exported="" name="appcompat-v7-21.0.3" level="project" />
91-
<orderEntry type="library" exported="" name="support-annotations-21.0.3" level="project" />
90+
<orderEntry type="library" exported="" name="gson-2.3.1" level="project" />
9291
<orderEntry type="library" exported="" name="support-v4-21.0.3" level="project" />
92+
<orderEntry type="library" exported="" name="support-annotations-21.0.3" level="project" />
9393
</component>
9494
</module>
9595

src/AndroidClient/techstacks/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,5 @@ dependencies {
2323
compile fileTree(dir: 'libs', include: ['*.jar'])
2424
compile 'com.android.support:appcompat-v7:21.0.3'
2525
compile project(':android')
26+
compile 'net.servicestack:android:0.0.1'
2627
}

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

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22

33
import net.servicestack.android.AndroidServiceClient;
44
import net.servicestack.client.AsyncResult;
5+
import net.servicestack.client.Utils;
56

6-
import servicestack.net.techstacks.techstacksdtos.*;
7+
import servicestack.net.techstacks.dto.*;
78

89
import java.util.ArrayList;
910

@@ -33,6 +34,7 @@ public static class AppData
3334

3435
ArrayList<AppDataListener> listeners = new ArrayList<>();
3536
AppOverviewResponse appOverviewResponse;
37+
QueryResponse<TechnologyStack> techStacksResponse;
3638

3739
public AppData addListener(AppDataListener callback){
3840
if (!listeners.contains(callback)){
@@ -65,9 +67,36 @@ public void success(AppOverviewResponse response){
6567
return this;
6668
}
6769

70+
String lastTechStacksQuery = null;
71+
72+
public AppData searchTechStacks(final String query){
73+
if (techStacksResponse != null && Utils.equals(query,lastTechStacksQuery)){
74+
onUpdate(DataType.SearchTechStacks);
75+
}
76+
77+
lastTechStacksQuery = query;
78+
client.getAsync(new FindTechStacks(),
79+
Utils.createMap("NameContains",query,"DescriptionContains",query),
80+
new AsyncResult<QueryResponse<TechnologyStack>>() {
81+
@Override
82+
public void success(QueryResponse<TechnologyStack> response) {
83+
if (Utils.equals(query,lastTechStacksQuery)){
84+
techStacksResponse = response;
85+
onUpdate(DataType.SearchTechStacks);
86+
}
87+
}
88+
});
89+
90+
return this;
91+
}
92+
6893
public AppOverviewResponse getAppOverviewResponse(){
6994
return appOverviewResponse;
7095
}
96+
97+
public QueryResponse<TechnologyStack> getSearchTechStacksResponse() {
98+
return techStacksResponse;
99+
}
71100
}
72101

73102
public static interface AppDataListener
@@ -78,6 +107,7 @@ public static interface AppDataListener
78107
public static enum DataType
79108
{
80109
AppOverview,
110+
SearchTechStacks,
81111
}
82112

83113

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

Lines changed: 60 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,16 @@
88
import android.support.v4.app.FragmentPagerAdapter;
99
import android.os.Bundle;
1010
import android.support.v4.view.ViewPager;
11+
import android.text.Editable;
12+
import android.text.TextWatcher;
1113
import android.view.LayoutInflater;
1214
import android.view.Menu;
1315
import android.view.MenuItem;
1416
import android.view.View;
1517
import android.view.ViewGroup;
1618
import android.widget.AdapterView;
1719
import android.widget.ArrayAdapter;
20+
import android.widget.EditText;
1821
import android.widget.ListView;
1922
import android.widget.Spinner;
2023

@@ -26,7 +29,7 @@
2629

2730
import static net.servicestack.client.Func.map;
2831

29-
import servicestack.net.techstacks.techstacksdtos.*;
32+
import servicestack.net.techstacks.dto.*;
3033

3134
public 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 {

src/AndroidClient/techstacks/src/main/res/layout/fragment_tech_stacks.xml

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,21 @@
66
android:paddingBottom="@dimen/activity_vertical_margin"
77
tools:context=".MainActivity$TechStacksFragment">
88

9-
<TextView android:id="@+id/section_label"
10-
android:layout_width="wrap_content"
11-
android:layout_height="wrap_content"
12-
android:text="TechStacks"/>
9+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
10+
android:layout_width="fill_parent"
11+
android:layout_height="fill_parent"
12+
android:orientation="vertical" >
1313

14+
<EditText android:id="@+id/searchTechStacks"
15+
android:layout_width="fill_parent"
16+
android:layout_height="wrap_content"
17+
android:hint="Search"
18+
android:inputType="textFilter"/>
19+
20+
<ListView
21+
android:id="@+id/listTechStacks"
22+
android:layout_width="fill_parent"
23+
android:layout_height="wrap_content" />
24+
25+
</LinearLayout>
1426
</RelativeLayout>

src/AndroidClient/techstacks/src/main/res/layout/fragment_technologies.xml

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,22 @@
66
android:paddingBottom="@dimen/activity_vertical_margin"
77
tools:context=".MainActivity$TechnologiesFragment">
88

9-
<TextView android:id="@+id/section_label"
10-
android:layout_width="wrap_content"
11-
android:layout_height="wrap_content"
12-
android:text="Technologies"/>
9+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
10+
android:layout_width="fill_parent"
11+
android:layout_height="fill_parent"
12+
android:orientation="vertical" >
13+
14+
<EditText android:id="@+id/searchTechnologies"
15+
android:layout_width="fill_parent"
16+
android:layout_height="wrap_content"
17+
android:hint="Search"
18+
android:inputType="textFilter"/>
19+
20+
<ListView
21+
android:id="@+id/listTechnologies"
22+
android:layout_width="fill_parent"
23+
android:layout_height="wrap_content" />
24+
25+
</LinearLayout>
1326

1427
</RelativeLayout>

src/AndroidClient/techstacks/src/main/res/layout/fragment_top_rated.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414
<Spinner
1515
android:layout_width="wrap_content"
1616
android:layout_height="wrap_content"
17-
android:id="@+id/spinner_category"
17+
android:id="@+id/spinnerCategory"
1818
android:layout_alignParentStart="true" />
1919

2020
<ListView
21-
android:id="@+id/list_results"
21+
android:id="@+id/listTopRated"
2222
android:layout_width="wrap_content"
2323
android:layout_height="wrap_content" />
2424

0 commit comments

Comments
 (0)